examples/simple-alternate-routing.cc
changeset 2494 1c69ea12779c
parent 2230 9f13ac3291e0
child 2502 50d0da37f02f
equal deleted inserted replaced
2493:2cd8723ece97 2494:1c69ea12779c
    41 
    41 
    42 #include "ns3/command-line.h"
    42 #include "ns3/command-line.h"
    43 #include "ns3/default-value.h"
    43 #include "ns3/default-value.h"
    44 #include "ns3/ptr.h"
    44 #include "ns3/ptr.h"
    45 #include "ns3/random-variable.h"
    45 #include "ns3/random-variable.h"
       
    46 #include "ns3/config.h"
       
    47 #include "ns3/uinteger.h"
    46 
    48 
    47 #include "ns3/simulator.h"
    49 #include "ns3/simulator.h"
    48 #include "ns3/nstime.h"
    50 #include "ns3/nstime.h"
    49 #include "ns3/data-rate.h"
    51 #include "ns3/data-rate.h"
    50 
    52 
   103 
   105 
   104   // The below Bind command tells the queue factory which class to
   106   // The below Bind command tells the queue factory which class to
   105   // instantiate, when the queue factory is invoked in the topology code
   107   // instantiate, when the queue factory is invoked in the topology code
   106   DefaultValue::Bind ("Queue", "DropTailQueue");
   108   DefaultValue::Bind ("Queue", "DropTailQueue");
   107 
   109 
   108   DefaultValue::Bind ("OnOffApplicationPacketSize", "210");
   110   Config::SetDefault ("OnOffApplication::PacketSize", Uinteger (210));
   109   DefaultValue::Bind ("OnOffApplicationDataRate", "300b/s");
   111   Config::SetDefault ("OnOffApplication::DataRate", MakeDataRate ("300b/s"));
   110 
   112 
   111   // The below metric, if set to 3 or higher, will cause packets between
   113   // The below metric, if set to 3 or higher, will cause packets between
   112   // n1 and n3 to take the 2-hop route through n2
   114   // n1 and n3 to take the 2-hop route through n2
   113   // 
   115   // 
   114   // Additionally, we plumb this metric into the default value / command 
   116   // Additionally, we plumb this metric into the default value / command 
   180   // Create the OnOff application to send UDP datagrams 
   182   // Create the OnOff application to send UDP datagrams 
   181   NS_LOG_INFO ("Create Application.");
   183   NS_LOG_INFO ("Create Application.");
   182   uint16_t port = 9;   // Discard port (RFC 863)
   184   uint16_t port = 9;   // Discard port (RFC 863)
   183 
   185 
   184   // Create a flow from n3 to n1, starting at time 1.1 seconds
   186   // Create a flow from n3 to n1, starting at time 1.1 seconds
   185   Ptr<OnOffApplication> ooff = CreateObject<OnOffApplication> (
   187   Ptr<OnOffApplication> ooff = 
   186     n3, 
   188     CreateObjectWith<OnOffApplication> (
   187     InetSocketAddress ("10.1.1.1", port),
   189                                         "Node", n3, 
   188     "Udp",
   190                                         "Remote", Address (InetSocketAddress ("10.1.1.1", port)),
   189     ConstantVariable (1), 
   191                                         "Protocol", TypeId::LookupByName ("Udp"),
   190     ConstantVariable (0));
   192                                         "OnTime", ConstantVariable (1), 
       
   193                                         "OffTime", ConstantVariable (0));
       
   194   n3->AddApplication (ooff);
   191   // Start the application
   195   // Start the application
   192   ooff->Start (Seconds (1.1));
   196   ooff->Start (Seconds (1.1));
   193   ooff->Stop (Seconds (10.0));
   197   ooff->Stop (Seconds (10.0));
   194 
   198 
   195   // Create a packet sink to receive these packets
   199   // Create a packet sink to receive these packets
   196   Ptr<PacketSink> sink = CreateObject<PacketSink> (
   200   Ptr<PacketSink> sink = 
   197     n1, 
   201     CreateObjectWith<PacketSink> (
   198     InetSocketAddress (Ipv4Address::GetAny (), port), 
   202                                   "Node", n1, 
   199     "Udp");
   203                                   "Remote", Address (InetSocketAddress (Ipv4Address::GetAny (), port)), 
       
   204                                   "Protocol", TypeId::LookupByName ("Udp"));
       
   205   n1->AddApplication (sink);
   200   // Start the sink
   206   // Start the sink
   201   sink->Start (Seconds (1.1));
   207   sink->Start (Seconds (1.1));
   202   sink->Stop (Seconds (10.0));
   208   sink->Stop (Seconds (10.0));
   203 
   209 
   204   // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   210   // Configure tracing of all enqueue, dequeue, and NetDevice receive events