add PacketSinks, change port number to UDP discard port, fix comment on onoff-application, delete logic for setting a default route
authorTom Henderson <tomh@tomh.org>
Fri, 14 Sep 2007 15:57:49 -0700
changeset 1512 0445a24ada26
parent 1511 e312e4df2221
child 1513 d16f6fd70397
add PacketSinks, change port number to UDP discard port, fix comment on onoff-application, delete logic for setting a default route
examples/csma-broadcast.cc
--- a/examples/csma-broadcast.cc	Fri Sep 14 15:46:04 2007 -0700
+++ b/examples/csma-broadcast.cc	Fri Sep 14 15:57:49 2007 -0700
@@ -24,8 +24,8 @@
 //       |     |       
 //     ==========
 //
-//   n0 originates UDP broadcast to 255.255.255.255, which is replicated 
-//   and received on both n1 and n2
+//   n0 originates UDP broadcast to 255.255.255.255/discard port, which 
+//   is replicated and received on both n1 and n2
 
 #include <iostream>
 #include <fstream>
@@ -56,6 +56,7 @@
 #include "ns3/socket.h"
 #include "ns3/ipv4-route.h"
 #include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
 
 using namespace ns3;
 
@@ -87,10 +88,10 @@
   LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
   LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
   LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
+  // Enable the below logging command to see the packets being received
   LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
-  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
-  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
 #endif
+
   // Set up some default values for the simulation.  Use the Bind()
   // technique to tell the system what subclass of Queue to use,
   // and what the queue limit is
@@ -145,31 +146,41 @@
   CsmaIpv4Topology::AddIpv4Address (
       n2, n2ifIndex, Ipv4Address("192.168.1.2"), Ipv4Mask("255.255.255.0"));
 
-  // XXX Is this the right thing to do?
-  //
-  // The OnOff application uses a connected socket.  This socket needs to be
-  // able to figure out which interface to use as the source address for
-  // packets.  When there's one interface, this isn't too hard, but node zero
-  // has two interfaces, and limited broadcasts will be sent out both of those
-  // interfaces.  We need to provide some way to disambiguate the choice.
-  // If we supply a default route, the specified interface will be chosen.
-
-  Ptr<Ipv4> ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
-  ipv4->SetDefaultRoute ("192.168.1.3", n0ifIndex0);
+  // RFC 863 discard port indicates packet should be thrown away
+  // by the system.  We allow this silent discard to be overridden
+  // by the PacketSink application.
+  uint16_t discard_port = 9;
 
   // Create the OnOff application to send UDP datagrams of size
-  // 210 bytes at a rate of 448 Kb/s
-  // from n0 to n1
+  // 512 bytes (default) at a rate of 500 Kb/s (default) from n0
   NS_LOG_INFO ("Create Applications.");
   Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
     n0, 
-    InetSocketAddress ("255.255.255.255", 80), 
+    InetSocketAddress ("255.255.255.255", discard_port), 
     "Udp",
     ConstantVariable(1), 
     ConstantVariable(0));
   // Start the application
   ooff->Start(Seconds(1.0));
   ooff->Stop (Seconds(10.0));
+  
+  // Create an optional packet sink to receive these packets
+  Ptr<PacketSink> sink = Create<PacketSink> (
+    n1,
+    InetSocketAddress (Ipv4Address::GetAny (), discard_port),
+    "Udp");
+  // Start the sink
+  sink->Start (Seconds (1.0));
+  sink->Stop (Seconds (10.0));
+
+  // Create an optional packet sink to receive these packets
+  sink = Create<PacketSink> (
+    n2,
+    InetSocketAddress (Ipv4Address::GetAny (), discard_port),
+    "Udp");
+  // Start the sink
+  sink->Start (Seconds (1.0));
+  sink->Stop (Seconds (10.0));
 
   NS_LOG_INFO ("Configure Tracing.");
   // Configure tracing of all enqueue, dequeue, and NetDevice receive events