examples/simple-point-to-point.cc
changeset 2592 3ebf97150166
parent 2577 5b41cb5c3fcf
child 2600 6c389d0c717d
equal deleted inserted replaced
2591:83a605082fb6 2592:3ebf97150166
   134   // Create the OnOff application to send UDP datagrams of size
   134   // Create the OnOff application to send UDP datagrams of size
   135   // 210 bytes at a rate of 448 Kb/s
   135   // 210 bytes at a rate of 448 Kb/s
   136   NS_LOG_INFO ("Create Applications.");
   136   NS_LOG_INFO ("Create Applications.");
   137   uint16_t port = 9;   // Discard port (RFC 863)
   137   uint16_t port = 9;   // Discard port (RFC 863)
   138   Ptr<OnOffApplication> ooff = 
   138   Ptr<OnOffApplication> ooff = 
   139     CreateObjectWith<OnOffApplication> (
   139     CreateObject<OnOffApplication> (
   140                                         "Node", n0, 
   140                                         "Node", n0, 
   141                                         "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
   141                                         "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
   142                                         "Protocol", TypeId::LookupByName ("Udp"),
   142                                         "Protocol", TypeId::LookupByName ("Udp"),
   143                                         "OnTime", ConstantVariable(1), 
   143                                         "OnTime", ConstantVariable(1), 
   144                                         "OffTime", ConstantVariable(0));
   144                                         "OffTime", ConstantVariable(0));
   146   // Start the application
   146   // Start the application
   147   ooff->Start (Seconds(1.0));
   147   ooff->Start (Seconds(1.0));
   148 
   148 
   149   // Create an optional packet sink to receive these packets
   149   // Create an optional packet sink to receive these packets
   150   Ptr<PacketSink> sink = 
   150   Ptr<PacketSink> sink = 
   151     CreateObjectWith<PacketSink> (
   151     CreateObject<PacketSink> (
   152                                   "Node", n3,
   152                                   "Node", n3,
   153                                   "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   153                                   "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   154                                   "Protocol", TypeId::LookupByName ("Udp"));
   154                                   "Protocol", TypeId::LookupByName ("Udp"));
   155   n3->AddApplication (sink);
   155   n3->AddApplication (sink);
   156   // Start the sink
   156   // Start the sink
   157   sink->Start (Seconds (1.0));
   157   sink->Start (Seconds (1.0));
   158 
   158 
   159   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   159   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   160   ooff = CreateObjectWith<OnOffApplication> (
   160   ooff = CreateObject<OnOffApplication> (
   161                                              "Node", n3, 
   161                                              "Node", n3, 
   162                                              "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
   162                                              "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
   163                                              "Protocol", TypeId::LookupByName ("Udp"),
   163                                              "Protocol", TypeId::LookupByName ("Udp"),
   164                                              "OnTime", ConstantVariable(1), 
   164                                              "OnTime", ConstantVariable(1), 
   165                                              "OffTime", ConstantVariable(0));
   165                                              "OffTime", ConstantVariable(0));
   166   n3->AddApplication (ooff);
   166   n3->AddApplication (ooff);
   167   // Start the application
   167   // Start the application
   168   ooff->Start(Seconds(1.1));
   168   ooff->Start(Seconds(1.1));
   169 
   169 
   170   // Create a packet sink to receive these packets
   170   // Create a packet sink to receive these packets
   171   sink = CreateObjectWith<PacketSink> (
   171   sink = CreateObject<PacketSink> (
   172                                        "Node", n1,
   172                                        "Node", n1,
   173                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   173                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   174                                        "Protocol", TypeId::LookupByName ("Udp"));
   174                                        "Protocol", TypeId::LookupByName ("Udp"));
   175   n1->AddApplication (sink);
   175   n1->AddApplication (sink);
   176   // Start the sink
   176   // Start the sink
   178 
   178 
   179   // TCP
   179   // TCP
   180   // Create a file transfer from n0 to n3, starting at time 1.2
   180   // Create a file transfer from n0 to n3, starting at time 1.2
   181   uint16_t servPort = 500;
   181   uint16_t servPort = 500;
   182 
   182 
   183   ooff = CreateObjectWith<OnOffApplication> (
   183   ooff = CreateObject<OnOffApplication> (
   184                                              "Node", n0, 
   184                                              "Node", n0, 
   185                                              "Remote", Address (InetSocketAddress ("10.1.3.2", servPort)), 
   185                                              "Remote", Address (InetSocketAddress ("10.1.3.2", servPort)), 
   186                                              "Protocol", TypeId::LookupByName ("Tcp"),
   186                                              "Protocol", TypeId::LookupByName ("Tcp"),
   187                                              "OnTime", ConstantVariable(1), 
   187                                              "OnTime", ConstantVariable(1), 
   188                                              "OffTime", ConstantVariable(0));
   188                                              "OffTime", ConstantVariable(0));
   190   // Start the application
   190   // Start the application
   191   ooff->Start (Seconds(1.2));
   191   ooff->Start (Seconds(1.2));
   192   ooff->Stop (Seconds(1.35));
   192   ooff->Stop (Seconds(1.35));
   193 
   193 
   194   // Create a packet sink to receive these TCP packets
   194   // Create a packet sink to receive these TCP packets
   195   sink = CreateObjectWith<PacketSink> (
   195   sink = CreateObject<PacketSink> (
   196                                        "Node", n3,
   196                                        "Node", n3,
   197                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
   197                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
   198                                        "Protocol", TypeId::LookupByName ("Tcp"));
   198                                        "Protocol", TypeId::LookupByName ("Tcp"));
   199   n3->AddApplication (sink);
   199   n3->AddApplication (sink);
   200   sink->Start (Seconds (1.2));
   200   sink->Start (Seconds (1.2));