examples/csma-packet-socket.cc
changeset 2600 6c389d0c717d
parent 2592 3ebf97150166
child 2602 d9262bff6df2
equal deleted inserted replaced
2599:fcc1728eb669 2600:6c389d0c717d
    60 NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
    60 NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
    61 
    61 
    62 static Ptr<CsmaNetDevice>
    62 static Ptr<CsmaNetDevice>
    63 CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
    63 CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
    64 {
    64 {
    65   Ptr<CsmaNetDevice> device = CreateObject<CsmaNetDevice> ("Node", node, 
    65   Ptr<CsmaNetDevice> device = CreateObject<CsmaNetDevice> ("Address", Mac48Address::Allocate (),
    66                                                            "Address", Mac48Address::Allocate (),
       
    67                                                            "EncapsulationMode", String ("Llc"));
    66                                                            "EncapsulationMode", String ("Llc"));
    68   node->AddDevice (device);
    67   node->AddDevice (device);
    69   device->Attach (channel);
    68   device->Attach (channel);
    70   Ptr<Queue> queue = CreateObject<DropTailQueue> ();
    69   Ptr<Queue> queue = CreateObject<DropTailQueue> ();
    71   device->AddQueue (queue);
    70   device->AddQueue (queue);
   139   // Create the OnOff application to send raw datagrams of size
   138   // Create the OnOff application to send raw datagrams of size
   140   // 210 bytes at a rate of 448 Kb/s
   139   // 210 bytes at a rate of 448 Kb/s
   141   // from n0 to n1
   140   // from n0 to n1
   142   NS_LOG_INFO ("Create Applications.");
   141   NS_LOG_INFO ("Create Applications.");
   143   Ptr<OnOffApplication> ooff = 
   142   Ptr<OnOffApplication> ooff = 
   144     CreateObject<OnOffApplication> (
   143     CreateObject<OnOffApplication> ("Remote", Address (n0ToN1),
   145                                         "Node", n0, 
   144                                     "Protocol", TypeId::LookupByName ("Packet"),
   146                                         "Remote", Address (n0ToN1),
   145                                     "OnTime", ConstantVariable(1), 
   147                                         "Protocol", TypeId::LookupByName ("Packet"),
   146                                     "OffTime", ConstantVariable(0));
   148                                         "OnTime", ConstantVariable(1), 
       
   149                                         "OffTime", ConstantVariable(0));
       
   150   n0->AddApplication (ooff);
   147   n0->AddApplication (ooff);
   151   // Start the application
   148   // Start the application
   152   ooff->Start(Seconds(1.0));
   149   ooff->Start(Seconds(1.0));
   153   ooff->Stop (Seconds(10.0));
   150   ooff->Stop (Seconds(10.0));
   154 
   151 
   155   // Create a similar flow from n3 to n0, starting at time 1.1 seconds
   152   // Create a similar flow from n3 to n0, starting at time 1.1 seconds
   156   ooff = CreateObject<OnOffApplication> (
   153   ooff = CreateObject<OnOffApplication> ("Remote", Address (n3ToN0),
   157                                              "Node", n3, 
   154                                          "Protocol", TypeId::LookupByName ("Packet"),
   158                                              "Remote", Address (n3ToN0),
   155                                          "OnTime", ConstantVariable(1), 
   159                                              "Protocol", TypeId::LookupByName ("Packet"),
   156                                          "OffTime", ConstantVariable(0));
   160                                              "OnTime", ConstantVariable(1), 
       
   161                                              "OffTime", ConstantVariable(0));
       
   162   n3->AddApplication (ooff);
   157   n3->AddApplication (ooff);
   163   // Start the application
   158   // Start the application
   164   ooff->Start(Seconds(1.1));
   159   ooff->Start(Seconds(1.1));
   165   ooff->Stop (Seconds(10.0));
   160   ooff->Stop (Seconds(10.0));
   166  
   161