examples/csma-packet-socket.cc
changeset 2965 4b28e9740e3b
parent 2890 172baa5960ff
child 3026 4ef834f6b67d
equal deleted inserted replaced
2964:4e8cb1577144 2965:4b28e9740e3b
    68   PacketSocketHelper packetSocket;
    68   PacketSocketHelper packetSocket;
    69   packetSocket.Install (c);
    69   packetSocket.Install (c);
    70 
    70 
    71   // create the shared medium used by all csma devices.
    71   // create the shared medium used by all csma devices.
    72   NS_LOG_INFO ("Create channels.");
    72   NS_LOG_INFO ("Create channels.");
    73   Ptr<CsmaChannel> channel = CreateObject<CsmaChannel> ("BitRate", DataRate(5000000), 
    73   Ptr<CsmaChannel> channel = CreateObject<CsmaChannel> ("BitRate", DataRateValue (DataRate(5000000)), 
    74                                                         "Delay", MilliSeconds(2));
    74                                                         "Delay", TimeValue (MilliSeconds(2)));
    75 
    75 
    76   // use a helper function to connect our nodes to the shared channel.
    76   // use a helper function to connect our nodes to the shared channel.
    77   NS_LOG_INFO ("Build Topology.");
    77   NS_LOG_INFO ("Build Topology.");
    78   CsmaHelper csma;
    78   CsmaHelper csma;
    79   csma.SetDeviceParameter ("EncapsulationMode", String ("Llc"));
    79   csma.SetDeviceParameter ("EncapsulationMode", StringValue ("Llc"));
    80   NetDeviceContainer devs = csma.Install (c, channel);
    80   NetDeviceContainer devs = csma.Install (c, channel);
    81 
    81 
    82   NS_LOG_INFO ("Create Applications.");
    82   NS_LOG_INFO ("Create Applications.");
    83   // Create the OnOff application to send raw datagrams
    83   // Create the OnOff application to send raw datagrams
    84   PacketSocketAddress socket;
    84   PacketSocketAddress socket;
    85   socket.SetSingleDevice(devs.Get (0)->GetIfIndex ());
    85   socket.SetSingleDevice(devs.Get (0)->GetIfIndex ());
    86   socket.SetPhysicalAddress (devs.Get (1)->GetAddress ());
    86   socket.SetPhysicalAddress (devs.Get (1)->GetAddress ());
    87   socket.SetProtocol (2);
    87   socket.SetProtocol (2);
    88   OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
    88   OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
    89   onoff.SetAttribute ("OnTime", ConstantVariable (1.0));
    89   onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
    90   onoff.SetAttribute ("OffTime", ConstantVariable (0.0));
    90   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
    91 
    91 
    92   ApplicationContainer apps = onoff.Install (c.Get (0));
    92   ApplicationContainer apps = onoff.Install (c.Get (0));
    93   apps.Start (Seconds (1.0));
    93   apps.Start (Seconds (1.0));
    94   apps.Stop (Seconds (10.0));
    94   apps.Stop (Seconds (10.0));
    95   
    95   
    96   socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
    96   socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
    97   socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
    97   socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
    98   socket.SetProtocol (3);
    98   socket.SetProtocol (3);
    99   onoff.SetAttribute ("Remote", Address (socket));
    99   onoff.SetAttribute ("Remote", AddressValue (socket));
   100   onoff.SetAttribute ("OffTime", ConstantVariable (0.0));
   100   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
   101   apps = onoff.Install (c.Get (3));
   101   apps = onoff.Install (c.Get (3));
   102   apps.Start (Seconds (1.0));
   102   apps.Start (Seconds (1.0));
   103   apps.Stop (Seconds (10.0));
   103   apps.Stop (Seconds (10.0));
   104  
   104  
   105   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   105   // Configure tracing of all enqueue, dequeue, and NetDevice receive events