examples/simple-error-model.cc
changeset 2592 3ebf97150166
parent 2577 5b41cb5c3fcf
child 2600 6c389d0c717d
equal deleted inserted replaced
2591:83a605082fb6 2592:3ebf97150166
   141   // Create the OnOff application to send UDP datagrams of size
   141   // Create the OnOff application to send UDP datagrams of size
   142   // 210 bytes at a rate of 448 Kb/s
   142   // 210 bytes at a rate of 448 Kb/s
   143   NS_LOG_INFO ("Create Applications.");
   143   NS_LOG_INFO ("Create Applications.");
   144   uint16_t port = 9;   // Discard port (RFC 863)
   144   uint16_t port = 9;   // Discard port (RFC 863)
   145   Ptr<OnOffApplication> ooff = 
   145   Ptr<OnOffApplication> ooff = 
   146     CreateObjectWith<OnOffApplication> (
   146     CreateObject<OnOffApplication> (
   147                                         "Node", n0, 
   147                                         "Node", n0, 
   148                                         "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
   148                                         "Remote", Address (InetSocketAddress ("10.1.3.2", port)), 
   149                                         "Protocol", TypeId::LookupByName ("Udp"),
   149                                         "Protocol", TypeId::LookupByName ("Udp"),
   150                                         "OnTime", ConstantVariable(1), 
   150                                         "OnTime", ConstantVariable(1), 
   151                                         "OffTime", ConstantVariable(0));
   151                                         "OffTime", ConstantVariable(0));
   153   // Start the application
   153   // Start the application
   154   ooff->Start(Seconds(1.0));
   154   ooff->Start(Seconds(1.0));
   155   ooff->Stop (Seconds(10.0));
   155   ooff->Stop (Seconds(10.0));
   156 
   156 
   157   // Create an optional packet sink to receive these packets
   157   // Create an optional packet sink to receive these packets
   158   Ptr<PacketSink> sink = CreateObjectWith<PacketSink> (
   158   Ptr<PacketSink> sink = CreateObject<PacketSink> (
   159                                                        "Node", n3,
   159                                                        "Node", n3,
   160                                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   160                                                        "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   161                                                        "Protocol", TypeId::LookupByName ("Udp"));
   161                                                        "Protocol", TypeId::LookupByName ("Udp"));
   162   n3->AddApplication (sink);
   162   n3->AddApplication (sink);
   163   // Start the sink
   163   // Start the sink
   164   sink->Start (Seconds (1.0));
   164   sink->Start (Seconds (1.0));
   165   sink->Stop (Seconds (10.0));
   165   sink->Stop (Seconds (10.0));
   166 
   166 
   167   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   167   // Create a similar flow from n3 to n1, starting at time 1.1 seconds
   168   ooff = CreateObjectWith<OnOffApplication> (
   168   ooff = CreateObject<OnOffApplication> (
   169                                          "Node", n3, 
   169                                          "Node", n3, 
   170                                          "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
   170                                          "Remote", Address (InetSocketAddress ("10.1.2.1", port)), 
   171                                          "Protocol", TypeId::LookupByName ("Udp"),
   171                                          "Protocol", TypeId::LookupByName ("Udp"),
   172                                          "OnTime", ConstantVariable(1), 
   172                                          "OnTime", ConstantVariable(1), 
   173                                          "OffTime", ConstantVariable(0));
   173                                          "OffTime", ConstantVariable(0));
   175   // Start the application
   175   // Start the application
   176   ooff->Start(Seconds(1.1));
   176   ooff->Start(Seconds(1.1));
   177   ooff->Stop (Seconds(10.0));
   177   ooff->Stop (Seconds(10.0));
   178 
   178 
   179   // Create a packet sink to receive these packets
   179   // Create a packet sink to receive these packets
   180   sink = CreateObjectWith<PacketSink> (
   180   sink = CreateObject<PacketSink> (
   181                                    "Node", n1,
   181                                    "Node", n1,
   182                                    "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   182                                    "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   183                                    "Protocol", TypeId::LookupByName ("Udp"));
   183                                    "Protocol", TypeId::LookupByName ("Udp"));
   184   n1->AddApplication (sink);
   184   n1->AddApplication (sink);
   185   // Start the sink
   185   // Start the sink
   203   // pointers
   203   // pointers
   204   Ptr<PointToPointNetDevice> nd3 = PointToPointTopology::GetNetDevice
   204   Ptr<PointToPointNetDevice> nd3 = PointToPointTopology::GetNetDevice
   205     (n3, channel2);
   205     (n3, channel2);
   206   // Create an ErrorModel based on the implementation (constructor)
   206   // Create an ErrorModel based on the implementation (constructor)
   207   // specified by the default classId
   207   // specified by the default classId
   208   Ptr<RateErrorModel> em = CreateObjectWith<RateErrorModel> ("RanVar", UniformVariable (0.0, 1.0),
   208   Ptr<RateErrorModel> em = CreateObject<RateErrorModel> ("RanVar", UniformVariable (0.0, 1.0),
   209                                                              "Rate", Double (0.001));
   209                                                              "Rate", Double (0.001));
   210   nd3->AddReceiveErrorModel (em);
   210   nd3->AddReceiveErrorModel (em);
   211 
   211 
   212   // Now, let's use the ListErrorModel and explicitly force a loss
   212   // Now, let's use the ListErrorModel and explicitly force a loss
   213   // of the packets with pkt-uids = 11 and 17 on node 2, device 0
   213   // of the packets with pkt-uids = 11 and 17 on node 2, device 0