diff --git a/examples/csma-multicast.cc b/examples/csma-multicast.cc index 3af6fc937..ae4c3c4cf 100644 --- a/examples/csma-multicast.cc +++ b/examples/csma-multicast.cc @@ -16,31 +16,27 @@ // Network topology // -// n0 n1 n2 n3 -// | | | | -// ===================== +// Lan1 +// =========== +// | | | +// n0 n1 n2 n3 n4 +// | | | +// =========== +// Lan0 // -// - CBR/UDP flows from n0 to n1, and from n3 to n0 -// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. -// (i.e., DataRate of 448,000 bps) -// - DropTail queues -// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" - -#include -#include -#include -#include +// - Multicast source is at node n0; +// - Multicast forwarded by node n2 onto LAN1; +// - Nodes n0, n1, n2, n3, and n4 receive the multicast frame. +// - Node n4 listens for the data (actual listener not yet implementted) #include "ns3/command-line.h" #include "ns3/default-value.h" #include "ns3/ptr.h" #include "ns3/random-variable.h" #include "ns3/debug.h" - #include "ns3/simulator.h" #include "ns3/nstime.h" #include "ns3/data-rate.h" - #include "ns3/ascii-trace.h" #include "ns3/pcap-trace.h" #include "ns3/internet-node.h" @@ -58,15 +54,18 @@ using namespace ns3; -NS_DEBUG_COMPONENT_DEFINE ("Me"); +NS_DEBUG_COMPONENT_DEFINE ("CsmaMulticast"); int main (int argc, char *argv[]) { - // Users may find it convenient to turn on explicit debugging - // for selected modules; the below lines suggest how to do this +// +// Users may find it convenient to turn on explicit debugging +// for selected modules; the below lines suggest how to do this +// #if 0 - DebugComponentEnable("Me"); + DebugComponentEnable("CsmaMulticast"); + DebugComponentEnable("Object"); DebugComponentEnable("Queue"); DebugComponentEnable("DropTailQueue"); @@ -86,105 +85,182 @@ main (int argc, char *argv[]) DebugComponentEnable("Ipv4LoopbackInterface"); #endif - DebugComponentEnable("Me"); + DebugComponentEnable("UdpSocket"); + DebugComponentEnable("UdpL4Protocol"); + DebugComponentEnable("Ipv4L3Protocol"); + DebugComponentEnable("Ipv4StaticRouting"); + DebugComponentEnable("Ipv4Interface"); + DebugComponentEnable("ArpIpv4Interface"); + DebugComponentEnable("Ipv4LoopbackInterface"); + + DebugComponentEnable("CsmaMulticast"); DebugComponentEnable("CsmaChannel"); DebugComponentEnable("CsmaNetDevice"); - DebugComponentEnable("UdpL4Protocol"); - - // 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 - - // The below Bind command tells the queue factory which class to - // instantiate, when the queue factory is invoked in the topology code +// +// Set up default values for the simulation. Use the DefaultValue::Bind() +// technique to tell the system what subclass of Queue to use. The Bind +// command command tells the queue factory which class to instantiate when the +// queue factory is invoked in the topology code +// DefaultValue::Bind ("Queue", "DropTailQueue"); - - // Allow the user to override any of the defaults and the above - // Bind()s at run-time, via command-line arguments +// +// Allow the user to override any of the defaults and the above Bind() at +// run-time, via command-line arguments +// CommandLine::Parse (argc, argv); - - // Here, we will explicitly create four nodes. In more sophisticated - // topologies, we could configure a node factory. +// +// Explicitly create the nodes required by the topology (shown above). +// NS_DEBUG("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); + Ptr n4 = Create (); NS_DEBUG("Create channels."); - // We create the channels first without any IP addressing information - Ptr channel0 = +// +// Explicitly create the channels required by the topology (shown above). +// + Ptr lan0 = + CsmaTopology::CreateCsmaChannel( + DataRate(5000000), MilliSeconds(2)); + + Ptr lan1 = CsmaTopology::CreateCsmaChannel( DataRate(5000000), MilliSeconds(2)); NS_DEBUG("Build Topology."); - uint32_t netDeviceNumberNode0 = CsmaIpv4Topology::AddIpv4CsmaNode (n0, - channel0, Eui48Address("10:54:23:54:23:50")); - uint32_t netDeviceNumberNode1 = CsmaIpv4Topology::AddIpv4CsmaNode (n1, - channel0, Eui48Address("10:54:23:54:23:51")); - uint32_t netDeviceNumberNode2 = CsmaIpv4Topology::AddIpv4CsmaNode (n2, - channel0, Eui48Address("10:54:23:54:23:52")); - uint32_t netDeviceNumberNode3 = CsmaIpv4Topology::AddIpv4CsmaNode (n3, - channel0, Eui48Address("10:54:23:54:23:53")); +// +// Now fill out the topology by creating the net devices required to connect +// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will +// create a net device, add a MAC address (in memory of the pink flamingo) and +// connect the net device to a nodes and also to a channel. the +// AddIpv4CsmaNetDevice method returns a net device index for the net device +// created on the node. Interpret nd0 as the net device we created for node +// zero. Interpret nd2Lan0 as the net device we created for node two to +// connect to Lan0. +// + uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan0, + Eui48Address("08:00:2e:00:00:00")); + uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0, + Eui48Address("08:00:2e:00:00:01")); + uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan0, + Eui48Address("08:00:2e:00:00:02")); - NS_DEBUG ("netDeviceNumberNode0 = " << netDeviceNumberNode0); - NS_DEBUG ("netDeviceNumberNode1 = " << netDeviceNumberNode1); - NS_DEBUG ("netDeviceNumberNode2 = " << netDeviceNumberNode2); - NS_DEBUG ("netDeviceNumberNode3 = " << netDeviceNumberNode3); + uint32_t nd2Lan1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, + Eui48Address("08:00:2e:00:00:00")); + uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, + Eui48Address("08:00:2e:00:00:01")); + uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1, + Eui48Address("08:00:2e:00:00:02")); - // Later, we add IP addresses. + NS_DEBUG ("nd0 = " << nd0); + NS_DEBUG ("nd1 = " << nd1); + NS_DEBUG ("nd2Lan0 = " << nd2Lan0); + NS_DEBUG ("nd2Lan1 = " << nd2Lan1); + NS_DEBUG ("nd3 = " << nd3); + NS_DEBUG ("nd4 = " << nd3); +// +// We've got the "hardware" in place. Now we need to add IP addresses. +// NS_DEBUG("Assign IP Addresses."); - // XXX BUGBUG - // Need a better way to get the interface index. The point-to-point topology - // as implemented can't return the index since it creates interfaces on both - // sides (i.e., AddIpv4Addresses, not AddIpv4Address). Need a method on - // Ipv4 to find the interface index corresponding to a given ipv4 address. - uint32_t ifIndexNode0 = CsmaIpv4Topology::AddIpv4Address (n0, - netDeviceNumberNode0, Ipv4Address ("10.1.1.1"), - Ipv4Mask ("255.255.255.0")); +// +// XXX BUGBUG +// Need a better way to get the interface index. The point-to-point topology +// as implemented can't return the index since it creates interfaces on both +// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a +// method on Ipv4 to find the interface index corresponding to a given ipv4 +// address. +// +// First, assign IP addresses to the net devices and associated interfaces +// on Lan0. The AddIpv4Address method returns an Ipv4 interface index. +// Interpret ifIndexNd0 as the interface index to use to reference the +// net device we created on node zero when coming in from the Ipv4 interface. +// Net device numbers and interface indices are distinct. Interpret +// ifIndexNd2Lan0 as the interface index to use to reference the +// net device we created that connects node two to lan zero. +// + uint32_t ifIndexNd0 = CsmaIpv4Topology::AddIpv4Address (n0, nd0, + Ipv4Address ("10.1.1.1"), Ipv4Mask ("255.255.255.0")); - uint32_t ifIndexNode1 = CsmaIpv4Topology::AddIpv4Address (n1, - netDeviceNumberNode1, Ipv4Address ("10.1.1.2"), - Ipv4Mask ("255.255.255.0")); + uint32_t ifIndexNd1 = CsmaIpv4Topology::AddIpv4Address (n1, nd1, + Ipv4Address ("10.1.1.2"), Ipv4Mask ("255.255.255.0")); - uint32_t ifIndexNode2 = CsmaIpv4Topology::AddIpv4Address (n2, - netDeviceNumberNode2, Ipv4Address ("10.1.1.3"), - Ipv4Mask ("255.255.255.0")); - - uint32_t ifIndexNode3 = CsmaIpv4Topology::AddIpv4Address (n3, - netDeviceNumberNode3, Ipv4Address ("10.1.1.4"), - Ipv4Mask ("255.255.255.0")); + uint32_t ifIndexNd2Lan0 = CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan0, + Ipv4Address ("10.1.1.3"), Ipv4Mask ("255.255.255.0")); +// +// Assign IP addresses to the net devices and associated interfaces on Lan1 +// + uint32_t ifIndexNd2Lan1 = CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan1, + Ipv4Address ("10.1.2.1"), Ipv4Mask ("255.255.255.0")); - NS_DEBUG ("ifIndexNode0 = " << ifIndexNode0); - NS_DEBUG ("ifIndexNode1 = " << ifIndexNode1); - NS_DEBUG ("ifIndexNode2 = " << ifIndexNode2); - NS_DEBUG ("ifIndexNode3 = " << ifIndexNode3); + uint32_t ifIndexNd3 = CsmaIpv4Topology::AddIpv4Address (n3, nd1, + Ipv4Address ("10.1.2.2"), Ipv4Mask ("255.255.255.0")); - // Configure multicasting + uint32_t ifIndexNd4 = CsmaIpv4Topology::AddIpv4Address (n4, nd4, + Ipv4Address ("10.1.2.3"), Ipv4Mask ("255.255.255.0")); + + NS_DEBUG ("ifIndexNd0 = " << ifIndexNd0); + NS_DEBUG ("ifIndexNd1 = " << ifIndexNd1); + NS_DEBUG ("ifIndexNd2Lan0 = " << ifIndexNd2Lan0); + NS_DEBUG ("ifIndexNd2Lan1 = " << ifIndexNd2Lan1); + NS_DEBUG ("ifIndexNd3 = " << ifIndexNd3); + NS_DEBUG ("ifIndexNd4 = " << ifIndexNd4); NS_DEBUG("Configure multicasting."); +// +// Now we can configure multicasting. As described above, the multicast +// source is at node zero, which we assigned the IP address of 10.1.1.1 +// earlier. We need to define a multicast group to send packets to. This +// can be any multicast address from 224.0.0.0 through 239.255.255.255 +// (avoiding the reserved routing protocol addresses). We just pick a +// convenient number. +// Ipv4Address multicastSource ("10.1.1.1"); Ipv4Address multicastGroup ("225.0.0.0"); - +// +// We are going to manually configure multicast routing. This means telling +// node two that it should expect multicast data coming from IP address +// 10.1.1.1 over its IP interface connected to Lan0. These are called +// multicastSource and ifIndexNd2Lan0 respectively. When node two receives +// these packets, they should be forwarded out the interface that connects it +// to Lan1 which is called ifIndexNd2Lan1. All we need to do is to call the +// AddMulticastRoute method on node two's Ipv4 interface and provide this +// information. (Note: the vector of output interfaces is in case there are +// multiple net devices on a node). +// Ptr ipv4; - ipv4 = n0->QueryInterface (Ipv4::iid); + ipv4 = n2->QueryInterface (Ipv4::iid); std::vector outputInterfaces (1); - outputInterfaces[0] = ifIndexNode0; + outputInterfaces[0] = ifIndexNd2Lan1; - ipv4->AddMulticastRoute (multicastSource, multicastGroup, 0, + ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexNd2Lan0, outputInterfaces); +// +// We also need to explain to the node zero forwarding code that when it sees +// a packet destined for the multicast group it needs to send it out its +// one and only interface. The 0xffffffff in the call means that the input +// interface qualification is not applicable in this case (the packet has +// not been received over an interface, it has been created locally). +// + ipv4 = n0->QueryInterface (Ipv4::iid); - ipv4 = n1->QueryInterface (Ipv4::iid); - // ipv4->JoinMulticastGroup (multicastSource, multicastGroup); + outputInterfaces[0] = ifIndexNd0;; - ipv4 = n2->QueryInterface (Ipv4::iid); - // ipv4->JoinMulticastGroup (multicastSource, multicastGroup); - - ipv4 = n3->QueryInterface (Ipv4::iid); - // ipv4->JoinMulticastGroup (multicastSource, multicastGroup); - - // Create the OnOff application to send UDP datagrams - // from n0 to the multicast group + ipv4->AddMulticastRoute (multicastSource, multicastGroup, 0xffffffff, + outputInterfaces); +// +// As described above, node four will be the only node listening for the +// multicast data. To enable forwarding bits up the protocol stack, we need +// to tell the stack to join the multicast group. +// + ipv4 = n4->QueryInterface (Ipv4::iid); + ipv4->JoinMulticastGroup (multicastSource, multicastGroup); +// +// Create an OnOff application to send UDP datagrams from node zero to the +// multicast group (node four will be listening). +// NS_DEBUG("Create Applications."); Ptr ooff = Create ( n0, @@ -192,27 +268,33 @@ main (int argc, char *argv[]) "Udp", ConstantVariable(1), ConstantVariable(0), - DataRate ("128b/s"), + DataRate ("255b/s"), 128); - // Start the application +// +// Tell the application when to start and stop. +// ooff->Start(Seconds(1.)); ooff->Stop (Seconds(10.)); - - // Configure tracing of all enqueue, dequeue, and NetDevice receive events - // Trace output will be sent to the csma-one-subnet.tr file +// +// Configure tracing of all enqueue, dequeue, and NetDevice receive events. +// Trace output will be sent to the file "csma-multicast.tr" +// NS_DEBUG("Configure Tracing."); AsciiTrace asciitrace ("csma-multicast.tr"); asciitrace.TraceAllNetDeviceRx (); asciitrace.TraceAllQueues (); - - // Also configure some tcpdump traces; each interface will be traced - // The output files will be named - // simple-point-to-point.pcap-- - // and can be read by the "tcpdump -r" command (use "-tt" option to - // display timestamps correctly) +// +// Also configure some tcpdump traces; each interface will be traced. +// The output files will be named: +// csma-multicast.pcap-- +// and can be read by the "tcpdump -r" command (use "-tt" option to +// display timestamps correctly) +// PcapTrace pcaptrace ("csma-multicast.pcap"); pcaptrace.TraceAllIp (); - +// +// Now, do the actual simulation. +// NS_DEBUG("Run Simulation."); Simulator::Run (); Simulator::Destroy (); diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc index 033a0135d..b7926c0db 100644 --- a/examples/csma-one-subnet.cc +++ b/examples/csma-one-subnet.cc @@ -14,35 +14,25 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// Port of ns-2/tcl/ex/simple.tcl to ns-3 -// // Network topology // // n0 n1 n2 n3 // | | | | -// ===================== +// ================= +// LAN // -// - CBR/UDP flows from n0 to n1, and from n3 to n0 -// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. -// (i.e., DataRate of 448,000 bps) +// - CBR/UDP flows from n0 to n1 and from n3 to n0 // - DropTail queues // - Tracing of queues and packet receptions to file "csma-one-subnet.tr" -#include -#include -#include -#include - #include "ns3/command-line.h" #include "ns3/default-value.h" #include "ns3/ptr.h" #include "ns3/random-variable.h" #include "ns3/debug.h" - #include "ns3/simulator.h" #include "ns3/nstime.h" #include "ns3/data-rate.h" - #include "ns3/ascii-trace.h" #include "ns3/pcap-trace.h" #include "ns3/internet-node.h" @@ -60,15 +50,18 @@ using namespace ns3; -NS_DEBUG_COMPONENT_DEFINE ("Me"); +NS_DEBUG_COMPONENT_DEFINE ("CsmaOneSubnet"); int main (int argc, char *argv[]) { - // Users may find it convenient to turn on explicit debugging - // for selected modules; the below lines suggest how to do this +// +// Users may find it convenient to turn on explicit debugging +// for selected modules; the below lines suggest how to do this +// #if 0 - DebugComponentEnable("Me"); + DebugComponentEnable("CsmaOneSubnet"); + DebugComponentEnable("Object"); DebugComponentEnable("Queue"); DebugComponentEnable("DropTailQueue"); @@ -88,71 +81,90 @@ main (int argc, char *argv[]) DebugComponentEnable("Ipv4LoopbackInterface"); #endif - DebugComponentEnable("Me"); - DebugComponentEnable("OnOffApplication"); - DebugComponentEnable("UdpSocket"); - DebugComponentEnable("UdpL4Protocol"); - DebugComponentEnable("Ipv4L3Protocol"); - DebugComponentEnable("Ipv4StaticRouting"); - DebugComponentEnable("CsmaNetDevice"); - DebugComponentEnable("CsmaChannel"); - DebugComponentEnable("Ipv4Interface"); - DebugComponentEnable("ArpIpv4Interface"); - DebugComponentEnable("Ipv4LoopbackInterface"); - - // 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 - - // The below Bind command tells the queue factory which class to - // instantiate, when the queue factory is invoked in the topology code +// +// Set up default values for the simulation. Use the DefaultValue::Bind() +// technique to tell the system what subclass of Queue to use. The Bind +// command command tells the queue factory which class to instantiate when the +// queue factory is invoked in the topology code +// DefaultValue::Bind ("Queue", "DropTailQueue"); - - // Allow the user to override any of the defaults and the above - // Bind()s at run-time, via command-line arguments +// +// Allow the user to override any of the defaults and the above Bind() at +// run-time, via command-line arguments +// CommandLine::Parse (argc, argv); - - // Here, we will explicitly create four nodes. In more sophisticated - // topologies, we could configure a node factory. +// +// Explicitly create the nodes required by the topology (shown above). +// NS_DEBUG("Create nodes."); Ptr n0 = Create (); Ptr n1 = Create (); Ptr n2 = Create (); Ptr n3 = Create (); - // We create the channels first without any IP addressing information NS_DEBUG("Create channels."); - Ptr channel0 = - CsmaTopology::CreateCsmaChannel( - DataRate(5000000), MilliSeconds(2)); +// +// Explicitly create the channels required by the topology (shown above). +// + Ptr lan = CsmaTopology::CreateCsmaChannel( + DataRate(5000000), MilliSeconds(2)); NS_DEBUG("Build Topology."); - uint32_t n0ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel0, - Eui48Address("10:54:23:54:23:50")); - uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n1, channel0, - Eui48Address("10:54:23:54:23:51")); - uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channel0, - Eui48Address("10:54:23:54:23:52")); - uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channel0, - Eui48Address("10:54:23:54:23:53")); +// +// Now fill out the topology by creating the net devices required to connect +// the nodes to the channels and hooking them up. AddIpv4CsmaNetDevice will +// create a net device, add a MAC address (in memory of the pink flamingo) and +// connect the net device to a nodes and also to a channel. the +// AddIpv4CsmaNetDevice method returns a net device index for the net device +// created on the node. Interpret nd0 as the net device we created for node +// zero. +// + uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, + Eui48Address("08:00:2e:00:00:00")); - // Later, we add IP addresses. + uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, + Eui48Address("08:00:2e:00:00:01")); + + uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, + Eui48Address("08:00:2e:00:00:02")); + + uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, + Eui48Address("08:00:2e:00:00:03")); + + NS_DEBUG ("nd0 = " << nd0); + NS_DEBUG ("nd1 = " << nd1); + NS_DEBUG ("nd2 = " << nd2); + NS_DEBUG ("nd3 = " << nd3); +// +// We've got the "hardware" in place. Now we need to add IP addresses. +// NS_DEBUG("Assign IP Addresses."); - CsmaIpv4Topology::AddIpv4Address ( - n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")); +// +// XXX BUGBUG +// Need a better way to get the interface index. The point-to-point topology +// as implemented can't return the index since it creates interfaces on both +// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address). We need a +// method on Ipv4 to find the interface index corresponding to a given ipv4 +// address. +// +// Assign IP addresses to the net devices and associated interfaces +// on the lan. The AddIpv4Address method returns an Ipv4 interface index +// which we do not need here. +// + CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"), + Ipv4Mask("255.255.255.0")); - CsmaIpv4Topology::AddIpv4Address ( - n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0")); + CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"), + Ipv4Mask("255.255.255.0")); - CsmaIpv4Topology::AddIpv4Address ( - n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0")); + CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"), + Ipv4Mask("255.255.255.0")); - CsmaIpv4Topology::AddIpv4Address ( - n3, n3ifIndex, Ipv4Address("10.1.1.4"), Ipv4Mask("255.255.255.0")); - - // Create the OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s - // from n0 to n1 + CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), + Ipv4Mask("255.255.255.0")); +// +// Create an OnOff application to send UDP datagrams from node zero to node 1. +// NS_DEBUG("Create Applications."); Ptr ooff = Create ( n0, @@ -160,36 +172,43 @@ main (int argc, char *argv[]) "Udp", ConstantVariable(1), ConstantVariable(0)); - // Start the application +// +// Tell the application when to start and stop. +// ooff->Start(Seconds(1.0)); ooff->Stop (Seconds(10.0)); - - // Create a similar flow from n3 to n0, starting at time 1.1 seconds +// +// Create a similar flow from n3 to n0, starting at time 1.1 seconds +// ooff = Create ( n3, InetSocketAddress ("10.1.1.1", 80), "Udp", ConstantVariable(1), ConstantVariable(0)); - // Start the application + ooff->Start(Seconds(1.1)); ooff->Stop (Seconds(10.0)); - - // Configure tracing of all enqueue, dequeue, and NetDevice receive events - // Trace output will be sent to the csma-one-subnet.tr file - NS_DEBUG("Configure Tracing."); +// +// Configure tracing of all enqueue, dequeue, and NetDevice receive events. +// Trace output will be sent to the file "csma-one-subnet.tr" +// + NS_DEBUG("Configure Tracing."); AsciiTrace asciitrace ("csma-one-subnet.tr"); asciitrace.TraceAllNetDeviceRx (); asciitrace.TraceAllQueues (); - - // Also configure some tcpdump traces; each interface will be traced - // The output files will be named - // simple-point-to-point.pcap-- - // and can be read by the "tcpdump -r" command (use "-tt" option to - // display timestamps correctly) +// +// Also configure some tcpdump traces; each interface will be traced. +// The output files will be named: +// csma-one-subnet.pcap-- +// and can be read by the "tcpdump -r" command (use "-tt" option to +// display timestamps correctly) +// PcapTrace pcaptrace ("csma-one-subnet.pcap"); pcaptrace.TraceAllIp (); - +// +// Now, do the actual simulation. +// NS_DEBUG("Run Simulation."); Simulator::Run (); Simulator::Destroy (); diff --git a/examples/mixed-global-routing.cc b/examples/mixed-global-routing.cc index b3017e029..07dcdcaad 100644 --- a/examples/mixed-global-routing.cc +++ b/examples/mixed-global-routing.cc @@ -128,13 +128,13 @@ int main (int argc, char *argv[]) CsmaTopology::CreateCsmaChannel( DataRate(5000000), MilliSeconds(2)); - uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channelc0, + uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, channelc0, Eui48Address("10:54:23:54:23:50")); - uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channelc0, + uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, channelc0, Eui48Address("10:54:23:54:23:51")); - uint32_t n4ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n4, channelc0, + uint32_t n4ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, channelc0, Eui48Address("10:54:23:54:23:52")); - uint32_t n5ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n5, channelc0, + uint32_t n5ifIndex = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n5, channelc0, Eui48Address("10:54:23:54:23:53")); // Later, we add IP addresses. diff --git a/src/devices/csma/csma-ipv4-topology.cc b/src/devices/csma/csma-ipv4-topology.cc index ff36b5502..80aa1c10a 100644 --- a/src/devices/csma/csma-ipv4-topology.cc +++ b/src/devices/csma/csma-ipv4-topology.cc @@ -35,19 +35,20 @@ namespace ns3 { uint32_t -CsmaIpv4Topology::AddIpv4CsmaNode(Ptr n1, - Ptr ch, - Eui48Address addr) +CsmaIpv4Topology::AddIpv4CsmaNetDevice( + Ptr node, + Ptr channel, + Eui48Address addr) { Ptr q = Queue::CreateDefault (); // assume full-duplex - Ptr nd0 = Create (n1, addr, - ns3::CsmaNetDevice::IP_ARP, - true, true); - nd0->AddQueue(q); - nd0->Attach (ch); - return nd0->GetIfIndex (); + Ptr nd = Create (node, addr, + ns3::CsmaNetDevice::IP_ARP, true, true); + + nd->AddQueue(q); + nd->Attach (channel); + return nd->GetIfIndex (); } diff --git a/src/devices/csma/csma-ipv4-topology.h b/src/devices/csma/csma-ipv4-topology.h index ca4aa982b..8ee60a9df 100644 --- a/src/devices/csma/csma-ipv4-topology.h +++ b/src/devices/csma/csma-ipv4-topology.h @@ -61,9 +61,9 @@ public: * * \return ifIndex of the device */ - static uint32_t AddIpv4CsmaNode( Ptr n1, - Ptr ch, - Eui48Address addr); + static uint32_t AddIpv4CsmaNetDevice(Ptr node, + Ptr channel, + Eui48Address addr); /** * \param n1 Node to be attached to the Csma channel