From 7bf7f4bbe5c554396a53b650d1c19e31e290e59c Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Fri, 14 Sep 2007 15:57:49 -0700 Subject: [PATCH] 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 | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/examples/csma-broadcast.cc b/examples/csma-broadcast.cc index 84efdd4f1..acd09e07b 100644 --- a/examples/csma-broadcast.cc +++ b/examples/csma-broadcast.cc @@ -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 #include @@ -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 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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 = n0->QueryInterface (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 ooff = Create ( 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 sink = Create ( + 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 ( + 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