--- a/examples/csma-bridge-one-hop.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,237 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// bridge1 The node named bridge1 (node 5 in the nodelist)
-// ------------------ has three CMSA net devices that are bridged
-// CSMA CSMA CSMA together using a BridgeNetDevice.
-// | | |
-// | | | The bridge node talks over three CSMA channels
-// | | |
-// CSMA CSMA CSMA to three other CSMA net devices
-// ---- ---- ----
-// n0 n1 n2 Node two acts as a router and talks to another
-// ---- bridge that connects the remaining nodes.
-// CSMA
-// |
-// n3 n4 |
-// ---- ---- |
-// CSMA CSMA |
-// | | |
-// | | |
-// | | |
-// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist)
-// ------------------ has three CMSA net devices that are bridged
-// bridge2 together using a BridgeNetDevice.
-//
-// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes
-// with three net devices:
-//
-// n0 n1 (n0 = 10.1.1.2)
-// | | (n1 = 10.1.1.3) Note odd addressing
-// ----------- (n2 = 10.1.1.1)
-// | bridge1 | <- n5
-// -----------
-// |
-// router <- n2
-// |
-// -----------
-// | bridge2 | <- n6
-// ----------- (n2 = 10.1.2.1)
-// | | (n3 = 10.1.2.2)
-// n3 n4 (n4 = 10.1.2.3)
-//
-// So, this example shows two broadcast domains, each interconnected by a bridge
-// with a router node (n2) interconnecting the layer-2 broadcast domains
-//
-// It is meant to mirror somewhat the csma-bridge example but adds another
-// bridged link separated by a router.
-//
-// - CBR/UDP flows from n0 (10.1.1.2) to n1 (10.1.1.3) and from n3 (10.1.2.2) to n0 (10.1.1.3)
-// - DropTail queues
-// - Global static routing
-// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
-
-#include <iostream>
-#include <fstream>
-
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/core-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/bridge-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample");
-
-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
- //
-#if 0
- LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO);
-#endif
-
- //
- // Allow the user to override any of the defaults and the above Bind() at
- // run-time, via command-line arguments
- //
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- //
- // Explicitly create the nodes required by the topology (shown above).
- //
- NS_LOG_INFO ("Create nodes.");
-
- Ptr<Node> n0 = CreateObject<Node> ();
- Ptr<Node> n1 = CreateObject<Node> ();
- Ptr<Node> n2 = CreateObject<Node> ();
- Ptr<Node> n3 = CreateObject<Node> ();
- Ptr<Node> n4 = CreateObject<Node> ();
-
- Ptr<Node> bridge1 = CreateObject<Node> ();
- Ptr<Node> bridge2 = CreateObject<Node> ();
-
- NS_LOG_INFO ("Build Topology");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
-
- // Create the csma links, from each terminal to the bridge
- // This will create six network devices; we'll keep track separately
- // of the devices on and off the bridge respectively, for later configuration
- NetDeviceContainer topLanDevices;
- NetDeviceContainer topBridgeDevices;
-
- // It is easier to iterate the nodes in C++ if we put them into a container
- NodeContainer topLan (n2, n0, n1);
-
- for (int i = 0; i < 3; i++)
- {
- // install a csma channel between the ith toplan node and the bridge node
- NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
- topLanDevices.Add (link.Get (0));
- topBridgeDevices.Add (link.Get (1));
- }
-
- //
- // Now, Create the bridge netdevice, which will do the packet switching. The
- // bridge lives on the node bridge1 and bridges together the topBridgeDevices
- // which are the three CSMA net devices on the node in the diagram above.
- //
- BridgeHelper bridge;
- bridge.Install (bridge1, topBridgeDevices);
-
- // Add internet stack to the router nodes
- NodeContainer routerNodes (n0, n1, n2, n3, n4);
- InternetStackHelper internet;
- internet.Install (routerNodes);
-
- // Repeat for bottom bridged LAN
- NetDeviceContainer bottomLanDevices;
- NetDeviceContainer bottomBridgeDevices;
- NodeContainer bottomLan (n2, n3, n4);
- for (int i = 0; i < 3; i++)
- {
- NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2));
- bottomLanDevices.Add (link.Get (0));
- bottomBridgeDevices.Add (link.Get (1));
- }
- bridge.Install (bridge2, bottomBridgeDevices);
-
- // We've got the "hardware" in place. Now we need to add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4.Assign (topLanDevices);
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- ipv4.Assign (bottomLanDevices);
-
- //
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes. We excuse the bridge nodes from having to serve as
- // routers, since they don't even have internet stacks on them.
- //
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- //
- // Create an OnOff application to send UDP datagrams from node zero to node 1.
- //
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer app = onoff.Install (n0);
- // Start the application
- app.Start (Seconds (1.0));
- app.Stop (Seconds (10.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- ApplicationContainer sink1 = sink.Install (n1);
- sink1.Start (Seconds (1.0));
- sink1.Stop (Seconds (10.0));
-
- //
- // Create a similar flow from n3 to n0, starting at time 1.1 seconds
- //
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
- ApplicationContainer app2 = onoff.Install (n3);
- app2.Start (Seconds (1.1));
- app2.Stop (Seconds (10.0));
-
- ApplicationContainer sink2 = sink.Install (n0);
- sink2.Start (Seconds (1.1));
- sink2.Stop (Seconds (10.0));
-
- //
- // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
- // Trace output will be sent to the file "csma-bridge-one-hop.tr"
- //
- NS_LOG_INFO ("Configure Tracing.");
- std::ofstream ascii;
- ascii.open ("csma-bridge-one-hop.tr");
- CsmaHelper::EnableAsciiAll (ascii);
-
- //
- // Also configure some tcpdump traces; each interface will be traced.
- // The output files will be named:
- // csma-bridge-<nodeId>-<interfaceId>.pcap
- // and can be read by the "tcpdump -r" command (use "-tt" option to
- // display timestamps correctly)
- //
- CsmaHelper::EnablePcapAll ("csma-bridge-one-hop", false);
-
- //
- // Now, do the actual simulation.
- //
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-bridge.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// n0 n1
-// | |
-// ----------
-// | Switch |
-// ----------
-// | |
-// n2 n3
-//
-//
-// - CBR/UDP flows from n0 to n1 and from n3 to n0
-// - DropTail queues
-// - Tracing of queues and packet receptions to file "csma-bridge.tr"
-
-#include <iostream>
-#include <fstream>
-
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/core-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/bridge-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaBridgeExample");
-
-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
- //
-#if 0
- LogComponentEnable ("CsmaBridgeExample", LOG_LEVEL_INFO);
-#endif
-
- //
- // Allow the user to override any of the defaults and the above Bind() at
- // run-time, via command-line arguments
- //
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- //
- // Explicitly create the nodes required by the topology (shown above).
- //
- NS_LOG_INFO ("Create nodes.");
- NodeContainer terminals;
- terminals.Create (4);
-
- NodeContainer csmaSwitch;
- csmaSwitch.Create (1);
-
- NS_LOG_INFO ("Build Topology");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
-
- // Create the csma links, from each terminal to the switch
-
- NetDeviceContainer terminalDevices;
- NetDeviceContainer switchDevices;
-
- for (int i = 0; i < 4; i++)
- {
- NetDeviceContainer link = csma.Install (NodeContainer (terminals.Get (i), csmaSwitch));
- terminalDevices.Add (link.Get (0));
- switchDevices.Add (link.Get (1));
- }
-
- // Create the bridge netdevice, which will do the packet switching
- Ptr<Node> switchNode = csmaSwitch.Get (0);
- BridgeHelper bridge;
- bridge.Install (switchNode, switchDevices);
-
- // Add internet stack to the terminals
- InternetStackHelper internet;
- internet.Install (terminals);
-
- // We've got the "hardware" in place. Now we need to add IP addresses.
- //
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4.Assign (terminalDevices);
-
- //
- // Create an OnOff application to send UDP datagrams from node zero to node 1.
- //
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer app = onoff.Install (terminals.Get (0));
- // Start the application
- app.Start (Seconds (1.0));
- app.Stop (Seconds (10.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- app = sink.Install (terminals.Get (1));
- app.Start (Seconds (0.0));
-
- //
- // Create a similar flow from n3 to n0, starting at time 1.1 seconds
- //
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));
- app = onoff.Install (terminals.Get (3));
- app.Start (Seconds (1.1));
- app.Stop (Seconds (10.0));
-
- app = sink.Install (terminals.Get (0));
- app.Start (Seconds (0.0));
-
-
- //
- // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
- // Trace output will be sent to the file "csma-bridge.tr"
- //
- NS_LOG_INFO ("Configure Tracing.");
- std::ofstream ascii;
- ascii.open ("csma-bridge.tr");
- CsmaHelper::EnableAsciiAll (ascii);
-
- //
- // Also configure some tcpdump traces; each interface will be traced.
- // The output files will be named:
- // csma-bridge-<nodeId>-<interfaceId>.pcap
- // and can be read by the "tcpdump -r" command (use "-tt" option to
- // display timestamps correctly)
- //
- CsmaHelper::EnablePcapAll ("csma-bridge", false);
-
- //
- // Now, do the actual simulation.
- //
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-bridge.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-# /*
-# * This program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License version 2 as
-# * published by the Free Software Foundation
-# *
-# * This program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with this program; if not, write to the Free Software
-# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-# */
-
-# Network topology
-#
-# n0 n1
-# | |
-# ----------
-# | Switch |
-# ----------
-# | |
-# n2 n3
-#
-#
-# - CBR/UDP flows from n0 to n1 and from n3 to n0
-# - DropTail queues
-# - Tracing of queues and packet receptions to file "csma-bridge.tr"
-
-import ns3
-
-
-def main(argv):
-
- #
- # Allow the user to override any of the defaults and the above Bind() at
- # run-time, via command-line arguments
- #
- cmd = ns3.CommandLine()
- cmd.Parse(argv)
-
- #
- # Explicitly create the nodes required by the topology(shown above).
- #
- #print "Create nodes."
- terminals = ns3.NodeContainer()
- terminals.Create(4)
-
- csmaSwitch = ns3.NodeContainer()
- csmaSwitch.Create(1)
-
- #print "Build Topology"
- csma = ns3.CsmaHelper()
- csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
- csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
-
- # Create the csma links, from each terminal to the switch
-
- terminalDevices = ns3.NetDeviceContainer()
- switchDevices = ns3.NetDeviceContainer()
-
- for i in range(4):
- link = csma.Install(ns3.NodeContainer(ns3.NodeContainer(terminals.Get(i)), csmaSwitch))
- terminalDevices.Add(link.Get(0))
- switchDevices.Add(link.Get(1))
-
- # Create the bridge netdevice, which will do the packet switching
- switchNode = csmaSwitch.Get(0)
- bridgeDevice = ns3.BridgeNetDevice()
- switchNode.AddDevice(bridgeDevice)
-
- for portIter in range(switchDevices.GetN()):
- bridgeDevice.AddBridgePort(switchDevices.Get(portIter))
-
- # Add internet stack to the terminals
- internet = ns3.InternetStackHelper()
- internet.Install(terminals)
-
- # We've got the "hardware" in place. Now we need to add IP addresses.
- #
- #print "Assign IP Addresses."
- ipv4 = ns3.Ipv4AddressHelper()
- ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
- ipv4.Assign(terminalDevices)
-
- #
- # Create an OnOff application to send UDP datagrams from node zero to node 1.
- #
- #print "Create Applications."
- port = 9 # Discard port(RFC 863)
-
- onoff = ns3.OnOffHelper("ns3::UdpSocketFactory",
- ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.2"), port)))
- onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
- onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
-
- app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
- # Start the application
- app.Start(ns3.Seconds(1.0))
- app.Stop(ns3.Seconds(10.0))
-
- # Create an optional packet sink to receive these packets
- sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
- ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)))
- app = sink.Install(ns3.NodeContainer(terminals.Get(1)))
- app.Start(ns3.Seconds(0.0))
-
- #
- # Create a similar flow from n3 to n0, starting at time 1.1 seconds
- #
- onoff.SetAttribute("Remote",
- ns3.AddressValue(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
- app = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
- app.Start(ns3.Seconds(1.1))
- app.Stop(ns3.Seconds(10.0))
-
- app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
- app.Start(ns3.Seconds(0.0))
-
- #
- # Configure tracing of all enqueue, dequeue, and NetDevice receive events.
- # Trace output will be sent to the file "csma-bridge.tr"
- #
- #print "Configure Tracing."
- #std.ofstream ascii
- #ascii.open("csma-bridge.tr")
- #CsmaHelper.EnableAsciiAll(ascii)
-
- #
- # Also configure some tcpdump traces; each interface will be traced.
- # The output files will be named:
- # csma-bridge.pcap-<nodeId>-<interfaceId>
- # and can be read by the "tcpdump -r" command(use "-tt" option to
- # display timestamps correctly)
- #
- ns3.CsmaHelper.EnablePcapAll("csma-bridge", False)
-
- #
- # Now, do the actual simulation.
- #
- #print "Run Simulation."
- ns3.Simulator.Run()
- ns3.Simulator.Destroy()
- #print "Done."
-
-
-
-if __name__ == '__main__':
- import sys
- main(sys.argv)
-
--- a/examples/csma-broadcast.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-//
-// Example of the sending of a datagram to a broadcast address
-//
-// Network topology
-// ==============
-// | |
-// n0 n1 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>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaBroadcastExample");
-
-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
-#if 0
- LogComponentEnable ("CsmaBroadcastExample", LOG_LEVEL_INFO);
-#endif
- LogComponentEnable ("CsmaBroadcastExample", LOG_PREFIX_TIME);
-
- // Allow the user to override any of the defaults and the above
- // Bind()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (3);
- NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1));
- NodeContainer c1 = NodeContainer (c.Get (0), c.Get (2));
-
- NS_LOG_INFO ("Build Topology.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(2)));
-
- NetDeviceContainer n0 = csma.Install (c0);
- NetDeviceContainer n1 = csma.Install (c1);
-
- InternetStackHelper internet;
- internet.Install (c);
-
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.0.0", "255.255.255.0");
- ipv4.Assign (n0);
- ipv4.SetBase ("192.168.1.0", "255.255.255.0");
- ipv4.Assign (n1);
-
-
- // RFC 863 discard port ("9") indicates packet should be thrown away
- // by the system. We allow this silent discard to be overridden
- // by the PacketSink application.
- uint16_t port = 9;
-
- // Create the OnOff application to send UDP datagrams of size
- // 512 bytes (default) at a rate of 500 Kb/s (default) from n0
- NS_LOG_INFO ("Create Applications.");
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer app = onoff.Install (c0.Get (0));
- // Start the application
- app.Start (Seconds (1.0));
- app.Stop (Seconds (10.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- app = sink.Install (c0.Get (1));
- app.Add (sink.Install (c1.Get (1)));
- app.Start (Seconds (1.0));
- app.Stop (Seconds (10.0));
-
- // Also configure some tcpdump traces; each interface will be traced
- // The output files will be named
- // csma-broadcast-<nodeId>-<interfaceId>.pcap
- // and can be read by the "tcpdump -tt -r" command
- CsmaHelper::EnablePcapAll ("csma-broadcast", false);
- std::ofstream ascii;
- ascii.open ("csma-broadcast.tr", std::ios_base::binary | std::ios_base::out);
- CsmaHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-multicast.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// Lan1
-// ===========
-// | | |
-// n0 n1 n2 n3 n4
-// | | |
-// ===========
-// Lan0
-//
-// - 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
-
-#include <iostream>
-#include <fstream>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
-
-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
- //
- // LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
-
- //
- // Set up default values for the simulation.
- //
- // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header)
- Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix"));
-
- // Allow the user to override any of the defaults at
- // run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (5);
- // We will later want two subcontainers of these nodes, for the two LANs
- NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
- NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
-
- NS_LOG_INFO ("Build Topology.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
-
- // We will use these NetDevice containers later, for IP addressing
- NetDeviceContainer nd0 = csma.Install (c0); // First LAN
- NetDeviceContainer nd1 = csma.Install (c1); // Second LAN
-
- NS_LOG_INFO ("Add IP Stack.");
- InternetStackHelper internet;
- internet.Install (c);
-
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4Addr;
- ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4Addr.Assign (nd0);
- ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0");
- ipv4Addr.Assign (nd1);
-
- NS_LOG_INFO ("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).
- //
-
- Ipv4Address multicastSource ("10.1.1.1");
- Ipv4Address multicastGroup ("225.1.2.4");
-
- // Now, we will set up multicast routing. We need to do three things:
- // 1) Configure a (static) multicast route on node n2
- // 2) Set up a default multicast route on the sender n0
- // 3) Have node n4 join the multicast group
- // We have a helper that can help us with static multicast
- Ipv4StaticRoutingHelper multicast;
-
- // 1) Configure a (static) multicast route on node n2 (multicastRouter)
- Ptr<Node> multicastRouter = c.Get (2); // The node in question
- Ptr<NetDevice> inputIf = nd0.Get (2); // The input NetDevice
- NetDeviceContainer outputDevices; // A container of output NetDevices
- outputDevices.Add (nd1.Get (0)); // (we only need one NetDevice here)
-
- multicast.AddMulticastRoute (multicastRouter, multicastSource,
- multicastGroup, inputIf, outputDevices);
-
- // 2) Set up a default multicast route on the sender n0
- Ptr<Node> sender = c.Get (0);
- Ptr<NetDevice> senderIf = nd0.Get(0);
- multicast.SetDefaultMulticastRoute (sender, senderIf);
-
- //
- // Create an OnOff application to send UDP datagrams from node zero to the
- // multicast group (node four will be listening).
- //
- NS_LOG_INFO ("Create Applications.");
-
- uint16_t multicastPort = 9; // Discard port (RFC 863)
-
- // Configure a multicast packet generator that generates a packet
- // every few seconds
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (multicastGroup, multicastPort)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s")));
- onoff.SetAttribute ("PacketSize", UintegerValue (128));
-
- ApplicationContainer srcC = onoff.Install (c0.Get (0));
-
- //
- // Tell the application when to start and stop.
- //
- srcC.Start(Seconds(1.));
- srcC.Stop (Seconds(10.));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny(), multicastPort));
-
- ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4
- // Start the sink
- sinkC.Start (Seconds (1.0));
- sinkC.Stop (Seconds (10.0));
-
- //
- // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
- NS_LOG_INFO ("Configure Tracing.");
- //
- // Ascii trace output will be sent to the file "csma-multicast.tr"
- //
- std::ofstream ascii;
- ascii.open ("csma-multicast.tr",std::ios_base::binary | std::ios_base::out);
- CsmaHelper::EnableAsciiAll (ascii);
-
- // Also configure some tcpdump traces; each interface will be traced.
- // The output files will be named:
- // csma-multicast-<nodeId>-<interfaceId>.pcap
- // and can be read by the "tcpdump -r" command (use "-tt" option to
- // display timestamps correctly)
- CsmaHelper::EnablePcapAll ("csma-multicast", false);
- //
- // Now, do the actual simulation.
- //
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-one-subnet.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// n0 n1 n2 n3
-// | | | |
-// =================
-// LAN
-//
-// - 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 <iostream>
-#include <fstream>
-
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/core-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample");
-
-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
-//
-#if 0
- LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
-#endif
-//
-// Allow the user to override any of the defaults and the above Bind() at
-// run-time, via command-line arguments
-//
- CommandLine cmd;
- cmd.Parse (argc, argv);
-//
-// Explicitly create the nodes required by the topology (shown above).
-//
- NS_LOG_INFO ("Create nodes.");
- NodeContainer nodes;
- nodes.Create (4);
-
- NS_LOG_INFO ("Build Topology");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
-//
-// Now fill out the topology by creating the net devices required to connect
-// the nodes to the channels and hooking them up.
-//
- NetDeviceContainer devices = csma.Install (nodes);
-
- InternetStackHelper internet;
- internet.Install (nodes);
-
-// We've got the "hardware" in place. Now we need to add IP addresses.
-//
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
-
-//
-// Create an OnOff application to send UDP datagrams from node zero to node 1.
-//
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (interfaces.GetAddress (1), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer app = onoff.Install (nodes.Get (0));
- // Start the application
- app.Start (Seconds (1.0));
- app.Stop (Seconds (10.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- app = sink.Install (nodes.Get (1));
- app.Start (Seconds (0.0));
-
-//
-// Create a similar flow from n3 to n0, starting at time 1.1 seconds
-//
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (interfaces.GetAddress (0), port)));
- app = onoff.Install (nodes.Get (3));
- app.Start(Seconds (1.1));
- app.Stop (Seconds (10.0));
-
- app = sink.Install (nodes.Get (0));
- app.Start (Seconds (0.0));
-
-//
-// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
-// Trace output will be sent to the file "csma-one-subnet.tr"
-//
- NS_LOG_INFO ("Configure Tracing.");
- std::ofstream ascii;
- ascii.open ("csma-one-subnet.tr", std::ios_base::binary | std::ios_base::out);
- CsmaHelper::EnableAsciiAll (ascii);
-//
-// Also configure some tcpdump traces; each interface will be traced.
-// The output files will be named:
-// csma-one-subnet-<nodeId>-<interfaceId>.pcap
-// and can be read by the "tcpdump -r" command (use "-tt" option to
-// display timestamps correctly)
-//
- CsmaHelper::EnablePcapAll ("csma-one-subnet", false);
-//
-// Now, do the actual simulation.
-//
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-packet-socket.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * 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
-// | | | |
-// =====================
-//
-// - 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 <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
-
-std::ofstream g_os;
-
-static void
-SinkRx (std::string path, Ptr<const Packet> p, const Address &address)
-{
- g_os << p->GetSize () << std::endl;
-}
-
-int
-main (int argc, char *argv[])
-{
-#if 0
- LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- g_os.open ("csma-packet-socket-sink.tr",std::ios_base::binary | std::ios_base::out);
-
- // Here, we will explicitly create four nodes.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer nodes;
- nodes.Create (4);
-
- PacketSocketHelper packetSocket;
- packetSocket.Install (nodes);
-
- // create the shared medium used by all csma devices.
- NS_LOG_INFO ("Create channels.");
- Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> (
- "DataRate", DataRateValue (DataRate(5000000)),
- "Delay", TimeValue (MilliSeconds(2)));
-
- // use a helper function to connect our nodes to the shared channel.
- NS_LOG_INFO ("Build Topology.");
- CsmaHelper csma;
- csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
- NetDeviceContainer devs = csma.Install (nodes, channel);
-
- NS_LOG_INFO ("Create Applications.");
- // Create the OnOff application to send raw datagrams
- PacketSocketAddress socket;
- socket.SetSingleDevice(devs.Get (0)->GetIfIndex ());
- socket.SetPhysicalAddress (devs.Get (1)->GetAddress ());
- socket.SetProtocol (2);
- OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
- ApplicationContainer apps = onoff.Install (nodes.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
- socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
- socket.SetProtocol (3);
- onoff.SetAttribute ("Remote", AddressValue (socket));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
- apps = onoff.Install (nodes.Get (3));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory",
- socket);
- apps = sink.Install (nodes.Get (0));
- apps.Start (Seconds (0.0));
- apps.Stop (Seconds (20.0));
-
- Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
- MakeCallback (&SinkRx));
-
- // Configure tracing of all enqueue, dequeue, and NetDevice receive events
- // Trace output will be sent to the csma-packet-socket.tr file
- NS_LOG_INFO ("Configure Tracing.");
- std::ofstream os;
- os.open ("csma-packet-socket.tr", std::ios_base::binary | std::ios_base::out);
- csma.EnableAsciiAll (os);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- g_os.close ();
-
- return 0;
-}
--- a/examples/csma-ping.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * 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
-// | | | |
-// =====================
-//
-// - 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 <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaPingExample");
-
-static void SinkRx (Ptr<const Packet> p, const Address &ad)
-{
- //std::cout << *p << std::endl;
-}
-
-static void PingRtt (std::string context, Time rtt)
-{
- //std::cout << context << " " << rtt << std::endl;
-}
-
-int
-main (int argc, char *argv[])
-{
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
-
- // connect all our nodes to a shared channel.
- NS_LOG_INFO ("Build Topology.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
- NetDeviceContainer devs = csma.Install (c);
-
- // add an ip stack to all nodes.
- NS_LOG_INFO ("Add ip stack.");
- InternetStackHelper ipStack;
- ipStack.Install (c);
-
- // assign ip addresses
- NS_LOG_INFO ("Assign ip addresses.");
- Ipv4AddressHelper ip;
- ip.SetBase ("192.168.1.0", "255.255.255.0");
- Ipv4InterfaceContainer addresses = ip.Assign (devs);
-
- // setup global router
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- NS_LOG_INFO ("Create Source");
- Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
- InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
- OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000)));
- onoff.SetAttribute ("PacketSize", UintegerValue (1200));
-
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- NS_LOG_INFO ("Create Sink.");
- PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
- apps = sink.Install (c.Get (3));
- apps.Start (Seconds (0.0));
- apps.Stop (Seconds (11.0));
-
- NS_LOG_INFO ("Create pinger");
- V4PingHelper ping = V4PingHelper (addresses.GetAddress (2));
- NodeContainer pingers;
- pingers.Add (c.Get (0));
- pingers.Add (c.Get (1));
- pingers.Add (c.Get (3));
- apps = ping.Install (pingers);
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (5.0));
-
- NS_LOG_INFO ("Configure Tracing.");
- // first, pcap tracing in non-promiscuous mode
- csma.EnablePcapAll ("csma-ping", false);
-
- // then, print what the packet sink receives.
- Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
- MakeCallback (&SinkRx));
- // finally, print the ping rtts.
- Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
- MakeCallback (&PingRtt));
-
- Packet::EnablePrinting ();
-
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-raw-ip-socket.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,117 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * 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
-// | | | |
-// =====================
-//
-// - 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 <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
-
-static void SinkRx (Ptr<const Packet> p, const Address &ad)
-{
- //std::cout << *p << std::endl;
-}
-
-int
-main (int argc, char *argv[])
-{
-#if 0
- LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
-
- // connect all our nodes to a shared channel.
- NS_LOG_INFO ("Build Topology.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
- NetDeviceContainer devs = csma.Install (c);
-
- // add an ip stack to all nodes.
- NS_LOG_INFO ("Add ip stack.");
- InternetStackHelper ipStack;
- ipStack.Install (c);
-
- // assign ip addresses
- NS_LOG_INFO ("Assign ip addresses.");
- Ipv4AddressHelper ip;
- ip.SetBase ("192.168.1.0", "255.255.255.0");
- Ipv4InterfaceContainer addresses = ip.Assign (devs);
-
- NS_LOG_INFO ("Create Source");
- Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
- InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
- OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
- onoff.SetAttribute ("PacketSize", UintegerValue (1200));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- NS_LOG_INFO ("Create Sink.");
- PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
- apps = sink.Install (c.Get (3));
- apps.Start (Seconds (0.0));
- apps.Stop (Seconds (11.0));
-
- NS_LOG_INFO ("Configure Tracing.");
- // first, pcap tracing in non-promiscuous mode
- csma.EnablePcapAll ("csma-raw-ip-socket", false);
- // then, print what the packet sink receives.
- Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
- MakeCallback (&SinkRx));
-
- Packet::EnablePrinting ();
-
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/csma-star.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/csma-module.h"
-
-// Network topology (default)
-//
-// n2 + + n3 .
-// | ... |\ /| ... | .
-// ======= \ / ======= .
-// CSMA \ / CSMA .
-// \ / .
-// n1 +--- n0 ---+ n4 .
-// | ... | / \ | ... | .
-// ======= / \ ======= .
-// CSMA / \ CSMA .
-// / \ .
-// n6 + + n5 .
-// | ... | | ... | .
-// ======= ======= .
-// CSMA CSMA .
-//
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("CsmaStar");
-
-int
-main (int argc, char *argv[])
-{
-
- //
- // Set up some default values for the simulation.
- //
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
-
- // ??? try and stick 15kb/s into the data rate
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
-
- //
- // Default number of nodes in the star. Overridable by command line argument.
- //
- uint32_t nNodes = 7;
-
- CommandLine cmd;
- cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer hubNode;
- NodeContainer spokeNodes;
- hubNode.Create (1);
- Ptr<Node> hub = hubNode.Get (0);
- spokeNodes.Create (nNodes - 1);
-
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
- csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
-
- NS_LOG_INFO ("Build star topology.");
- NetDeviceContainer hubDevices, spokeDevices;
- csma.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
-
- NodeContainer fillNodes;
-
- //
- // Just to be nasy, hang some more nodes off of the CSMA channel for each
- // spoke, so that there are a total of 16 nodes on each channel. Stash
- // all of these new devices into a container.
- //
- NetDeviceContainer fillDevices;
-
- uint32_t nFill = 14;
- for (uint32_t i = 0; i < spokeDevices.GetN (); ++i)
- {
- Ptr<Channel> channel = spokeDevices.Get (i)->GetChannel ();
- Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
- NodeContainer newNodes;
- NetDeviceContainer newDevices;
- newNodes.Create (nFill);
- fillNodes.Add (newNodes);
- fillDevices.Add (csma.Install (newNodes, csmaChannel));
- }
-
- NS_LOG_INFO ("Install internet stack on all nodes.");
- InternetStackHelper internet;
- internet.Install (NodeContainer (hubNode, spokeNodes, fillNodes));
-
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper address;
-
- //
- // Assign IPv4 interfaces and IP addresses to the devices we previously
- // created. Keep track of the resulting addresses, one for the addresses
- // of the hub node, and one for addresses on the spoke nodes. Despite the
- // name of the class (Ipv4InterfaceContainer), what is visible to clients
- // is really the address not the interface.
- //
- Ipv4InterfaceContainer hubAddresses;
- Ipv4InterfaceContainer spokeAddresses;
-
- for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
- {
- std::ostringstream subnet;
- subnet << "10.1." << i << ".0";
- NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ());
- address.SetBase (subnet.str ().c_str (), "255.255.255.0");
- hubAddresses.Add (address.Assign (hubDevices.Get (i)));
- spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
- //
- // We assigned addresses to the logical hub and the first "drop" of the
- // CSMA network that acts as the spoke, but we also have a number of fill
- // devices (nFill) also hanging off the CSMA network. We have got to
- // assign addresses to them as well. We put all of the fill devices into
- // a single device container, so the first nFill devices are associated
- // with the channel connected to spokeDevices.Get (0), the second nFill
- // devices afe associated with the channel connected to spokeDevices.Get (1)
- // etc.
- //
- for (uint32_t j = 0; j < nFill; ++j)
- {
- address.Assign (fillDevices.Get (i * nFill + j));
- }
- }
-
- NS_LOG_INFO ("Create applications.");
- //
- // Create a packet sink on the star "hub" to receive packets.
- //
- uint16_t port = 50000;
- Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
- PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
- ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
- hubApp.Start (Seconds (1.0));
- hubApp.Stop (Seconds (10.0));
-
- //
- // Create OnOff applications to send TCP to the hub, one on each spoke node.
- //
- OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
- onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer spokeApps;
-
- for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
- {
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
- onOffHelper.SetAttribute ("Remote", remoteAddress);
- spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
- }
-
- spokeApps.Start (Seconds (1.0));
- spokeApps.Stop (Seconds (10.0));
-
- //
- // Because we are evil, we also add OnOff applications to send TCP to the hub
- // from the fill devices on each CSMA link. The first nFill nodes in the
- // fillNodes container are on the CSMA network talking to the zeroth device
- // on the hub node. The next nFill nodes are on the CSMA network talking to
- // the first device on the hub node, etc. So the ith fillNode is associated
- // with the hub address found on the (i / nFill)th device on the hub node.
- //
- ApplicationContainer fillApps;
-
- for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
- {
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i / nFill), port));
- onOffHelper.SetAttribute ("Remote", remoteAddress);
- fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
- }
-
- fillApps.Start (Seconds (1.0));
- fillApps.Stop (Seconds (10.0));
-
- NS_LOG_INFO ("Enable static global routing.");
- //
- // Turn on global static routing so we can actually be routed across the star.
- //
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- NS_LOG_INFO ("Enable pcap tracing.");
- //
- // Do pcap tracing on all devices on all nodes.
- //
- CsmaHelper::EnablePcapAll ("csma-star", false);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-bridge-one-hop.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,237 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// bridge1 The node named bridge1 (node 5 in the nodelist)
+// ------------------ has three CMSA net devices that are bridged
+// CSMA CSMA CSMA together using a BridgeNetDevice.
+// | | |
+// | | | The bridge node talks over three CSMA channels
+// | | |
+// CSMA CSMA CSMA to three other CSMA net devices
+// ---- ---- ----
+// n0 n1 n2 Node two acts as a router and talks to another
+// ---- bridge that connects the remaining nodes.
+// CSMA
+// |
+// n3 n4 |
+// ---- ---- |
+// CSMA CSMA |
+// | | |
+// | | |
+// | | |
+// CSMA CSMA CSMA The node named bridge2 (node 6 in the nodelist)
+// ------------------ has three CMSA net devices that are bridged
+// bridge2 together using a BridgeNetDevice.
+//
+// Or, more abstractly, recognizing that bridge 1 and bridge 2 are nodes
+// with three net devices:
+//
+// n0 n1 (n0 = 10.1.1.2)
+// | | (n1 = 10.1.1.3) Note odd addressing
+// ----------- (n2 = 10.1.1.1)
+// | bridge1 | <- n5
+// -----------
+// |
+// router <- n2
+// |
+// -----------
+// | bridge2 | <- n6
+// ----------- (n2 = 10.1.2.1)
+// | | (n3 = 10.1.2.2)
+// n3 n4 (n4 = 10.1.2.3)
+//
+// So, this example shows two broadcast domains, each interconnected by a bridge
+// with a router node (n2) interconnecting the layer-2 broadcast domains
+//
+// It is meant to mirror somewhat the csma-bridge example but adds another
+// bridged link separated by a router.
+//
+// - CBR/UDP flows from n0 (10.1.1.2) to n1 (10.1.1.3) and from n3 (10.1.2.2) to n0 (10.1.1.3)
+// - DropTail queues
+// - Global static routing
+// - Tracing of queues and packet receptions to file "csma-bridge-one-hop.tr"
+
+#include <iostream>
+#include <fstream>
+
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/bridge-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaBridgeOneHopExample");
+
+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
+ //
+#if 0
+ LogComponentEnable ("CsmaBridgeOneHopExample", LOG_LEVEL_INFO);
+#endif
+
+ //
+ // Allow the user to override any of the defaults and the above Bind() at
+ // run-time, via command-line arguments
+ //
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ //
+ // Explicitly create the nodes required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create nodes.");
+
+ Ptr<Node> n0 = CreateObject<Node> ();
+ Ptr<Node> n1 = CreateObject<Node> ();
+ Ptr<Node> n2 = CreateObject<Node> ();
+ Ptr<Node> n3 = CreateObject<Node> ();
+ Ptr<Node> n4 = CreateObject<Node> ();
+
+ Ptr<Node> bridge1 = CreateObject<Node> ();
+ Ptr<Node> bridge2 = CreateObject<Node> ();
+
+ NS_LOG_INFO ("Build Topology");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+
+ // Create the csma links, from each terminal to the bridge
+ // This will create six network devices; we'll keep track separately
+ // of the devices on and off the bridge respectively, for later configuration
+ NetDeviceContainer topLanDevices;
+ NetDeviceContainer topBridgeDevices;
+
+ // It is easier to iterate the nodes in C++ if we put them into a container
+ NodeContainer topLan (n2, n0, n1);
+
+ for (int i = 0; i < 3; i++)
+ {
+ // install a csma channel between the ith toplan node and the bridge node
+ NetDeviceContainer link = csma.Install (NodeContainer (topLan.Get (i), bridge1));
+ topLanDevices.Add (link.Get (0));
+ topBridgeDevices.Add (link.Get (1));
+ }
+
+ //
+ // Now, Create the bridge netdevice, which will do the packet switching. The
+ // bridge lives on the node bridge1 and bridges together the topBridgeDevices
+ // which are the three CSMA net devices on the node in the diagram above.
+ //
+ BridgeHelper bridge;
+ bridge.Install (bridge1, topBridgeDevices);
+
+ // Add internet stack to the router nodes
+ NodeContainer routerNodes (n0, n1, n2, n3, n4);
+ InternetStackHelper internet;
+ internet.Install (routerNodes);
+
+ // Repeat for bottom bridged LAN
+ NetDeviceContainer bottomLanDevices;
+ NetDeviceContainer bottomBridgeDevices;
+ NodeContainer bottomLan (n2, n3, n4);
+ for (int i = 0; i < 3; i++)
+ {
+ NetDeviceContainer link = csma.Install (NodeContainer (bottomLan.Get (i), bridge2));
+ bottomLanDevices.Add (link.Get (0));
+ bottomBridgeDevices.Add (link.Get (1));
+ }
+ bridge.Install (bridge2, bottomBridgeDevices);
+
+ // We've got the "hardware" in place. Now we need to add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4.Assign (topLanDevices);
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ ipv4.Assign (bottomLanDevices);
+
+ //
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes. We excuse the bridge nodes from having to serve as
+ // routers, since they don't even have internet stacks on them.
+ //
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ //
+ // Create an OnOff application to send UDP datagrams from node zero to node 1.
+ //
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address ("10.1.1.3"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer app = onoff.Install (n0);
+ // Start the application
+ app.Start (Seconds (1.0));
+ app.Stop (Seconds (10.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ ApplicationContainer sink1 = sink.Install (n1);
+ sink1.Start (Seconds (1.0));
+ sink1.Stop (Seconds (10.0));
+
+ //
+ // Create a similar flow from n3 to n0, starting at time 1.1 seconds
+ //
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
+ ApplicationContainer app2 = onoff.Install (n3);
+ app2.Start (Seconds (1.1));
+ app2.Stop (Seconds (10.0));
+
+ ApplicationContainer sink2 = sink.Install (n0);
+ sink2.Start (Seconds (1.1));
+ sink2.Stop (Seconds (10.0));
+
+ //
+ // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+ // Trace output will be sent to the file "csma-bridge-one-hop.tr"
+ //
+ NS_LOG_INFO ("Configure Tracing.");
+ std::ofstream ascii;
+ ascii.open ("csma-bridge-one-hop.tr");
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ //
+ // Also configure some tcpdump traces; each interface will be traced.
+ // The output files will be named:
+ // csma-bridge-<nodeId>-<interfaceId>.pcap
+ // and can be read by the "tcpdump -r" command (use "-tt" option to
+ // display timestamps correctly)
+ //
+ CsmaHelper::EnablePcapAll ("csma-bridge-one-hop", false);
+
+ //
+ // Now, do the actual simulation.
+ //
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-bridge.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,166 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1
+// | |
+// ----------
+// | Switch |
+// ----------
+// | |
+// n2 n3
+//
+//
+// - CBR/UDP flows from n0 to n1 and from n3 to n0
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "csma-bridge.tr"
+
+#include <iostream>
+#include <fstream>
+
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/bridge-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaBridgeExample");
+
+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
+ //
+#if 0
+ LogComponentEnable ("CsmaBridgeExample", LOG_LEVEL_INFO);
+#endif
+
+ //
+ // Allow the user to override any of the defaults and the above Bind() at
+ // run-time, via command-line arguments
+ //
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ //
+ // Explicitly create the nodes required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer terminals;
+ terminals.Create (4);
+
+ NodeContainer csmaSwitch;
+ csmaSwitch.Create (1);
+
+ NS_LOG_INFO ("Build Topology");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+
+ // Create the csma links, from each terminal to the switch
+
+ NetDeviceContainer terminalDevices;
+ NetDeviceContainer switchDevices;
+
+ for (int i = 0; i < 4; i++)
+ {
+ NetDeviceContainer link = csma.Install (NodeContainer (terminals.Get (i), csmaSwitch));
+ terminalDevices.Add (link.Get (0));
+ switchDevices.Add (link.Get (1));
+ }
+
+ // Create the bridge netdevice, which will do the packet switching
+ Ptr<Node> switchNode = csmaSwitch.Get (0);
+ BridgeHelper bridge;
+ bridge.Install (switchNode, switchDevices);
+
+ // Add internet stack to the terminals
+ InternetStackHelper internet;
+ internet.Install (terminals);
+
+ // We've got the "hardware" in place. Now we need to add IP addresses.
+ //
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4.Assign (terminalDevices);
+
+ //
+ // Create an OnOff application to send UDP datagrams from node zero to node 1.
+ //
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer app = onoff.Install (terminals.Get (0));
+ // Start the application
+ app.Start (Seconds (1.0));
+ app.Stop (Seconds (10.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ app = sink.Install (terminals.Get (1));
+ app.Start (Seconds (0.0));
+
+ //
+ // Create a similar flow from n3 to n0, starting at time 1.1 seconds
+ //
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (Ipv4Address ("10.1.1.1"), port)));
+ app = onoff.Install (terminals.Get (3));
+ app.Start (Seconds (1.1));
+ app.Stop (Seconds (10.0));
+
+ app = sink.Install (terminals.Get (0));
+ app.Start (Seconds (0.0));
+
+
+ //
+ // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+ // Trace output will be sent to the file "csma-bridge.tr"
+ //
+ NS_LOG_INFO ("Configure Tracing.");
+ std::ofstream ascii;
+ ascii.open ("csma-bridge.tr");
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ //
+ // Also configure some tcpdump traces; each interface will be traced.
+ // The output files will be named:
+ // csma-bridge-<nodeId>-<interfaceId>.pcap
+ // and can be read by the "tcpdump -r" command (use "-tt" option to
+ // display timestamps correctly)
+ //
+ CsmaHelper::EnablePcapAll ("csma-bridge", false);
+
+ //
+ // Now, do the actual simulation.
+ //
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-bridge.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,152 @@
+# /*
+# * This program is free software; you can redistribute it and/or modify
+# * it under the terms of the GNU General Public License version 2 as
+# * published by the Free Software Foundation
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# * GNU General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public License
+# * along with this program; if not, write to the Free Software
+# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# */
+
+# Network topology
+#
+# n0 n1
+# | |
+# ----------
+# | Switch |
+# ----------
+# | |
+# n2 n3
+#
+#
+# - CBR/UDP flows from n0 to n1 and from n3 to n0
+# - DropTail queues
+# - Tracing of queues and packet receptions to file "csma-bridge.tr"
+
+import ns3
+
+
+def main(argv):
+
+ #
+ # Allow the user to override any of the defaults and the above Bind() at
+ # run-time, via command-line arguments
+ #
+ cmd = ns3.CommandLine()
+ cmd.Parse(argv)
+
+ #
+ # Explicitly create the nodes required by the topology(shown above).
+ #
+ #print "Create nodes."
+ terminals = ns3.NodeContainer()
+ terminals.Create(4)
+
+ csmaSwitch = ns3.NodeContainer()
+ csmaSwitch.Create(1)
+
+ #print "Build Topology"
+ csma = ns3.CsmaHelper()
+ csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
+ csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
+
+ # Create the csma links, from each terminal to the switch
+
+ terminalDevices = ns3.NetDeviceContainer()
+ switchDevices = ns3.NetDeviceContainer()
+
+ for i in range(4):
+ link = csma.Install(ns3.NodeContainer(ns3.NodeContainer(terminals.Get(i)), csmaSwitch))
+ terminalDevices.Add(link.Get(0))
+ switchDevices.Add(link.Get(1))
+
+ # Create the bridge netdevice, which will do the packet switching
+ switchNode = csmaSwitch.Get(0)
+ bridgeDevice = ns3.BridgeNetDevice()
+ switchNode.AddDevice(bridgeDevice)
+
+ for portIter in range(switchDevices.GetN()):
+ bridgeDevice.AddBridgePort(switchDevices.Get(portIter))
+
+ # Add internet stack to the terminals
+ internet = ns3.InternetStackHelper()
+ internet.Install(terminals)
+
+ # We've got the "hardware" in place. Now we need to add IP addresses.
+ #
+ #print "Assign IP Addresses."
+ ipv4 = ns3.Ipv4AddressHelper()
+ ipv4.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
+ ipv4.Assign(terminalDevices)
+
+ #
+ # Create an OnOff application to send UDP datagrams from node zero to node 1.
+ #
+ #print "Create Applications."
+ port = 9 # Discard port(RFC 863)
+
+ onoff = ns3.OnOffHelper("ns3::UdpSocketFactory",
+ ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.2"), port)))
+ onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
+ onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
+
+ app = onoff.Install(ns3.NodeContainer(terminals.Get(0)))
+ # Start the application
+ app.Start(ns3.Seconds(1.0))
+ app.Stop(ns3.Seconds(10.0))
+
+ # Create an optional packet sink to receive these packets
+ sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
+ ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port)))
+ app = sink.Install(ns3.NodeContainer(terminals.Get(1)))
+ app.Start(ns3.Seconds(0.0))
+
+ #
+ # Create a similar flow from n3 to n0, starting at time 1.1 seconds
+ #
+ onoff.SetAttribute("Remote",
+ ns3.AddressValue(ns3.InetSocketAddress(ns3.Ipv4Address("10.1.1.1"), port)))
+ app = onoff.Install(ns3.NodeContainer(terminals.Get(3)))
+ app.Start(ns3.Seconds(1.1))
+ app.Stop(ns3.Seconds(10.0))
+
+ app = sink.Install(ns3.NodeContainer(terminals.Get(0)))
+ app.Start(ns3.Seconds(0.0))
+
+ #
+ # Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+ # Trace output will be sent to the file "csma-bridge.tr"
+ #
+ #print "Configure Tracing."
+ #std.ofstream ascii
+ #ascii.open("csma-bridge.tr")
+ #CsmaHelper.EnableAsciiAll(ascii)
+
+ #
+ # Also configure some tcpdump traces; each interface will be traced.
+ # The output files will be named:
+ # csma-bridge.pcap-<nodeId>-<interfaceId>
+ # and can be read by the "tcpdump -r" command(use "-tt" option to
+ # display timestamps correctly)
+ #
+ ns3.CsmaHelper.EnablePcapAll("csma-bridge", False)
+
+ #
+ # Now, do the actual simulation.
+ #
+ #print "Run Simulation."
+ ns3.Simulator.Run()
+ ns3.Simulator.Destroy()
+ #print "Done."
+
+
+
+if __name__ == '__main__':
+ import sys
+ main(sys.argv)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-broadcast.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,123 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+//
+// Example of the sending of a datagram to a broadcast address
+//
+// Network topology
+// ==============
+// | |
+// n0 n1 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>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaBroadcastExample");
+
+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
+#if 0
+ LogComponentEnable ("CsmaBroadcastExample", LOG_LEVEL_INFO);
+#endif
+ LogComponentEnable ("CsmaBroadcastExample", LOG_PREFIX_TIME);
+
+ // Allow the user to override any of the defaults and the above
+ // Bind()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (3);
+ NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1));
+ NodeContainer c1 = NodeContainer (c.Get (0), c.Get (2));
+
+ NS_LOG_INFO ("Build Topology.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(2)));
+
+ NetDeviceContainer n0 = csma.Install (c0);
+ NetDeviceContainer n1 = csma.Install (c1);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.0.0", "255.255.255.0");
+ ipv4.Assign (n0);
+ ipv4.SetBase ("192.168.1.0", "255.255.255.0");
+ ipv4.Assign (n1);
+
+
+ // RFC 863 discard port ("9") indicates packet should be thrown away
+ // by the system. We allow this silent discard to be overridden
+ // by the PacketSink application.
+ uint16_t port = 9;
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 512 bytes (default) at a rate of 500 Kb/s (default) from n0
+ NS_LOG_INFO ("Create Applications.");
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address ("255.255.255.255"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer app = onoff.Install (c0.Get (0));
+ // Start the application
+ app.Start (Seconds (1.0));
+ app.Stop (Seconds (10.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ app = sink.Install (c0.Get (1));
+ app.Add (sink.Install (c1.Get (1)));
+ app.Start (Seconds (1.0));
+ app.Stop (Seconds (10.0));
+
+ // Also configure some tcpdump traces; each interface will be traced
+ // The output files will be named
+ // csma-broadcast-<nodeId>-<interfaceId>.pcap
+ // and can be read by the "tcpdump -tt -r" command
+ CsmaHelper::EnablePcapAll ("csma-broadcast", false);
+ std::ofstream ascii;
+ ascii.open ("csma-broadcast.tr", std::ios_base::binary | std::ios_base::out);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-multicast.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,181 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// Lan1
+// ===========
+// | | |
+// n0 n1 n2 n3 n4
+// | | |
+// ===========
+// Lan0
+//
+// - 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
+
+#include <iostream>
+#include <fstream>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
+
+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
+ //
+ // LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
+
+ //
+ // Set up default values for the simulation.
+ //
+ // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header)
+ Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix"));
+
+ // Allow the user to override any of the defaults at
+ // run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (5);
+ // We will later want two subcontainers of these nodes, for the two LANs
+ NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
+ NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
+
+ NS_LOG_INFO ("Build Topology.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+
+ // We will use these NetDevice containers later, for IP addressing
+ NetDeviceContainer nd0 = csma.Install (c0); // First LAN
+ NetDeviceContainer nd1 = csma.Install (c1); // Second LAN
+
+ NS_LOG_INFO ("Add IP Stack.");
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4Addr;
+ ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4Addr.Assign (nd0);
+ ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0");
+ ipv4Addr.Assign (nd1);
+
+ NS_LOG_INFO ("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).
+ //
+
+ Ipv4Address multicastSource ("10.1.1.1");
+ Ipv4Address multicastGroup ("225.1.2.4");
+
+ // Now, we will set up multicast routing. We need to do three things:
+ // 1) Configure a (static) multicast route on node n2
+ // 2) Set up a default multicast route on the sender n0
+ // 3) Have node n4 join the multicast group
+ // We have a helper that can help us with static multicast
+ Ipv4StaticRoutingHelper multicast;
+
+ // 1) Configure a (static) multicast route on node n2 (multicastRouter)
+ Ptr<Node> multicastRouter = c.Get (2); // The node in question
+ Ptr<NetDevice> inputIf = nd0.Get (2); // The input NetDevice
+ NetDeviceContainer outputDevices; // A container of output NetDevices
+ outputDevices.Add (nd1.Get (0)); // (we only need one NetDevice here)
+
+ multicast.AddMulticastRoute (multicastRouter, multicastSource,
+ multicastGroup, inputIf, outputDevices);
+
+ // 2) Set up a default multicast route on the sender n0
+ Ptr<Node> sender = c.Get (0);
+ Ptr<NetDevice> senderIf = nd0.Get(0);
+ multicast.SetDefaultMulticastRoute (sender, senderIf);
+
+ //
+ // Create an OnOff application to send UDP datagrams from node zero to the
+ // multicast group (node four will be listening).
+ //
+ NS_LOG_INFO ("Create Applications.");
+
+ uint16_t multicastPort = 9; // Discard port (RFC 863)
+
+ // Configure a multicast packet generator that generates a packet
+ // every few seconds
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (multicastGroup, multicastPort)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s")));
+ onoff.SetAttribute ("PacketSize", UintegerValue (128));
+
+ ApplicationContainer srcC = onoff.Install (c0.Get (0));
+
+ //
+ // Tell the application when to start and stop.
+ //
+ srcC.Start(Seconds(1.));
+ srcC.Stop (Seconds(10.));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny(), multicastPort));
+
+ ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4
+ // Start the sink
+ sinkC.Start (Seconds (1.0));
+ sinkC.Stop (Seconds (10.0));
+
+ //
+ // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+ NS_LOG_INFO ("Configure Tracing.");
+ //
+ // Ascii trace output will be sent to the file "csma-multicast.tr"
+ //
+ std::ofstream ascii;
+ ascii.open ("csma-multicast.tr",std::ios_base::binary | std::ios_base::out);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ // Also configure some tcpdump traces; each interface will be traced.
+ // The output files will be named:
+ // csma-multicast-<nodeId>-<interfaceId>.pcap
+ // and can be read by the "tcpdump -r" command (use "-tt" option to
+ // display timestamps correctly)
+ CsmaHelper::EnablePcapAll ("csma-multicast", false);
+ //
+ // Now, do the actual simulation.
+ //
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-one-subnet.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,140 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+// - 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 <iostream>
+#include <fstream>
+
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaOneSubnetExample");
+
+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
+//
+#if 0
+ LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
+#endif
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer nodes;
+ nodes.Create (4);
+
+ NS_LOG_INFO ("Build Topology");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+//
+// Now fill out the topology by creating the net devices required to connect
+// the nodes to the channels and hooking them up.
+//
+ NetDeviceContainer devices = csma.Install (nodes);
+
+ InternetStackHelper internet;
+ internet.Install (nodes);
+
+// We've got the "hardware" in place. Now we need to add IP addresses.
+//
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
+
+//
+// Create an OnOff application to send UDP datagrams from node zero to node 1.
+//
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (interfaces.GetAddress (1), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer app = onoff.Install (nodes.Get (0));
+ // Start the application
+ app.Start (Seconds (1.0));
+ app.Stop (Seconds (10.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ app = sink.Install (nodes.Get (1));
+ app.Start (Seconds (0.0));
+
+//
+// Create a similar flow from n3 to n0, starting at time 1.1 seconds
+//
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (interfaces.GetAddress (0), port)));
+ app = onoff.Install (nodes.Get (3));
+ app.Start(Seconds (1.1));
+ app.Stop (Seconds (10.0));
+
+ app = sink.Install (nodes.Get (0));
+ app.Start (Seconds (0.0));
+
+//
+// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
+// Trace output will be sent to the file "csma-one-subnet.tr"
+//
+ NS_LOG_INFO ("Configure Tracing.");
+ std::ofstream ascii;
+ ascii.open ("csma-one-subnet.tr", std::ios_base::binary | std::ios_base::out);
+ CsmaHelper::EnableAsciiAll (ascii);
+//
+// Also configure some tcpdump traces; each interface will be traced.
+// The output files will be named:
+// csma-one-subnet-<nodeId>-<interfaceId>.pcap
+// and can be read by the "tcpdump -r" command (use "-tt" option to
+// display timestamps correctly)
+//
+ CsmaHelper::EnablePcapAll ("csma-one-subnet", false);
+//
+// Now, do the actual simulation.
+//
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-packet-socket.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * 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
+// | | | |
+// =====================
+//
+// - 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 <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
+
+std::ofstream g_os;
+
+static void
+SinkRx (std::string path, Ptr<const Packet> p, const Address &address)
+{
+ g_os << p->GetSize () << std::endl;
+}
+
+int
+main (int argc, char *argv[])
+{
+#if 0
+ LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ g_os.open ("csma-packet-socket-sink.tr",std::ios_base::binary | std::ios_base::out);
+
+ // Here, we will explicitly create four nodes.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer nodes;
+ nodes.Create (4);
+
+ PacketSocketHelper packetSocket;
+ packetSocket.Install (nodes);
+
+ // create the shared medium used by all csma devices.
+ NS_LOG_INFO ("Create channels.");
+ Ptr<CsmaChannel> channel = CreateObjectWithAttributes<CsmaChannel> (
+ "DataRate", DataRateValue (DataRate(5000000)),
+ "Delay", TimeValue (MilliSeconds(2)));
+
+ // use a helper function to connect our nodes to the shared channel.
+ NS_LOG_INFO ("Build Topology.");
+ CsmaHelper csma;
+ csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
+ NetDeviceContainer devs = csma.Install (nodes, channel);
+
+ NS_LOG_INFO ("Create Applications.");
+ // Create the OnOff application to send raw datagrams
+ PacketSocketAddress socket;
+ socket.SetSingleDevice(devs.Get (0)->GetIfIndex ());
+ socket.SetPhysicalAddress (devs.Get (1)->GetAddress ());
+ socket.SetProtocol (2);
+ OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
+ ApplicationContainer apps = onoff.Install (nodes.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ socket.SetSingleDevice (devs.Get (3)->GetIfIndex ());
+ socket.SetPhysicalAddress (devs.Get (0)->GetAddress ());
+ socket.SetProtocol (3);
+ onoff.SetAttribute ("Remote", AddressValue (socket));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
+ apps = onoff.Install (nodes.Get (3));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ PacketSinkHelper sink = PacketSinkHelper ("ns3::PacketSocketFactory",
+ socket);
+ apps = sink.Install (nodes.Get (0));
+ apps.Start (Seconds (0.0));
+ apps.Stop (Seconds (20.0));
+
+ Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
+ MakeCallback (&SinkRx));
+
+ // Configure tracing of all enqueue, dequeue, and NetDevice receive events
+ // Trace output will be sent to the csma-packet-socket.tr file
+ NS_LOG_INFO ("Configure Tracing.");
+ std::ofstream os;
+ os.open ("csma-packet-socket.tr", std::ios_base::binary | std::ios_base::out);
+ csma.EnableAsciiAll (os);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ g_os.close ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-ping.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,136 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * 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
+// | | | |
+// =====================
+//
+// - 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 <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaPingExample");
+
+static void SinkRx (Ptr<const Packet> p, const Address &ad)
+{
+ //std::cout << *p << std::endl;
+}
+
+static void PingRtt (std::string context, Time rtt)
+{
+ //std::cout << context << " " << rtt << std::endl;
+}
+
+int
+main (int argc, char *argv[])
+{
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+
+ // connect all our nodes to a shared channel.
+ NS_LOG_INFO ("Build Topology.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
+ NetDeviceContainer devs = csma.Install (c);
+
+ // add an ip stack to all nodes.
+ NS_LOG_INFO ("Add ip stack.");
+ InternetStackHelper ipStack;
+ ipStack.Install (c);
+
+ // assign ip addresses
+ NS_LOG_INFO ("Assign ip addresses.");
+ Ipv4AddressHelper ip;
+ ip.SetBase ("192.168.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer addresses = ip.Assign (devs);
+
+ // setup global router
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+ NS_LOG_INFO ("Create Source");
+ Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
+ InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
+ OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (15000)));
+ onoff.SetAttribute ("PacketSize", UintegerValue (1200));
+
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Create Sink.");
+ PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (0.0));
+ apps.Stop (Seconds (11.0));
+
+ NS_LOG_INFO ("Create pinger");
+ V4PingHelper ping = V4PingHelper (addresses.GetAddress (2));
+ NodeContainer pingers;
+ pingers.Add (c.Get (0));
+ pingers.Add (c.Get (1));
+ pingers.Add (c.Get (3));
+ apps = ping.Install (pingers);
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (5.0));
+
+ NS_LOG_INFO ("Configure Tracing.");
+ // first, pcap tracing in non-promiscuous mode
+ csma.EnablePcapAll ("csma-ping", false);
+
+ // then, print what the packet sink receives.
+ Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
+ MakeCallback (&SinkRx));
+ // finally, print the ping rtts.
+ Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::V4Ping/Rtt",
+ MakeCallback (&PingRtt));
+
+ Packet::EnablePrinting ();
+
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-raw-ip-socket.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,117 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * 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
+// | | | |
+// =====================
+//
+// - 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 <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
+
+static void SinkRx (Ptr<const Packet> p, const Address &ad)
+{
+ //std::cout << *p << std::endl;
+}
+
+int
+main (int argc, char *argv[])
+{
+#if 0
+ LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+
+ // connect all our nodes to a shared channel.
+ NS_LOG_INFO ("Build Topology.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ csma.SetDeviceAttribute ("EncapsulationMode", StringValue ("Llc"));
+ NetDeviceContainer devs = csma.Install (c);
+
+ // add an ip stack to all nodes.
+ NS_LOG_INFO ("Add ip stack.");
+ InternetStackHelper ipStack;
+ ipStack.Install (c);
+
+ // assign ip addresses
+ NS_LOG_INFO ("Assign ip addresses.");
+ Ipv4AddressHelper ip;
+ ip.SetBase ("192.168.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer addresses = ip.Assign (devs);
+
+ NS_LOG_INFO ("Create Source");
+ Config::SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", StringValue ("2"));
+ InetSocketAddress dst = InetSocketAddress (addresses.GetAddress (3));
+ OnOffHelper onoff = OnOffHelper ("ns3::Ipv4RawSocketFactory", dst);
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1.0)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0.0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
+ onoff.SetAttribute ("PacketSize", UintegerValue (1200));
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Create Sink.");
+ PacketSinkHelper sink = PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst);
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (0.0));
+ apps.Stop (Seconds (11.0));
+
+ NS_LOG_INFO ("Configure Tracing.");
+ // first, pcap tracing in non-promiscuous mode
+ csma.EnablePcapAll ("csma-raw-ip-socket", false);
+ // then, print what the packet sink receives.
+ Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
+ MakeCallback (&SinkRx));
+
+ Packet::EnablePrinting ();
+
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/csma-star.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,212 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/csma-module.h"
+
+// Network topology (default)
+//
+// n2 + + n3 .
+// | ... |\ /| ... | .
+// ======= \ / ======= .
+// CSMA \ / CSMA .
+// \ / .
+// n1 +--- n0 ---+ n4 .
+// | ... | / \ | ... | .
+// ======= / \ ======= .
+// CSMA / \ CSMA .
+// / \ .
+// n6 + + n5 .
+// | ... | | ... | .
+// ======= ======= .
+// CSMA CSMA .
+//
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("CsmaStar");
+
+int
+main (int argc, char *argv[])
+{
+
+ //
+ // Set up some default values for the simulation.
+ //
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
+
+ // ??? try and stick 15kb/s into the data rate
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
+
+ //
+ // Default number of nodes in the star. Overridable by command line argument.
+ //
+ uint32_t nNodes = 7;
+
+ CommandLine cmd;
+ cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer hubNode;
+ NodeContainer spokeNodes;
+ hubNode.Create (1);
+ Ptr<Node> hub = hubNode.Get (0);
+ spokeNodes.Create (nNodes - 1);
+
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
+ csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
+
+ NS_LOG_INFO ("Build star topology.");
+ NetDeviceContainer hubDevices, spokeDevices;
+ csma.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
+
+ NodeContainer fillNodes;
+
+ //
+ // Just to be nasy, hang some more nodes off of the CSMA channel for each
+ // spoke, so that there are a total of 16 nodes on each channel. Stash
+ // all of these new devices into a container.
+ //
+ NetDeviceContainer fillDevices;
+
+ uint32_t nFill = 14;
+ for (uint32_t i = 0; i < spokeDevices.GetN (); ++i)
+ {
+ Ptr<Channel> channel = spokeDevices.Get (i)->GetChannel ();
+ Ptr<CsmaChannel> csmaChannel = channel->GetObject<CsmaChannel> ();
+ NodeContainer newNodes;
+ NetDeviceContainer newDevices;
+ newNodes.Create (nFill);
+ fillNodes.Add (newNodes);
+ fillDevices.Add (csma.Install (newNodes, csmaChannel));
+ }
+
+ NS_LOG_INFO ("Install internet stack on all nodes.");
+ InternetStackHelper internet;
+ internet.Install (NodeContainer (hubNode, spokeNodes, fillNodes));
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper address;
+
+ //
+ // Assign IPv4 interfaces and IP addresses to the devices we previously
+ // created. Keep track of the resulting addresses, one for the addresses
+ // of the hub node, and one for addresses on the spoke nodes. Despite the
+ // name of the class (Ipv4InterfaceContainer), what is visible to clients
+ // is really the address not the interface.
+ //
+ Ipv4InterfaceContainer hubAddresses;
+ Ipv4InterfaceContainer spokeAddresses;
+
+ for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ {
+ std::ostringstream subnet;
+ subnet << "10.1." << i << ".0";
+ NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ());
+ address.SetBase (subnet.str ().c_str (), "255.255.255.0");
+ hubAddresses.Add (address.Assign (hubDevices.Get (i)));
+ spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
+ //
+ // We assigned addresses to the logical hub and the first "drop" of the
+ // CSMA network that acts as the spoke, but we also have a number of fill
+ // devices (nFill) also hanging off the CSMA network. We have got to
+ // assign addresses to them as well. We put all of the fill devices into
+ // a single device container, so the first nFill devices are associated
+ // with the channel connected to spokeDevices.Get (0), the second nFill
+ // devices afe associated with the channel connected to spokeDevices.Get (1)
+ // etc.
+ //
+ for (uint32_t j = 0; j < nFill; ++j)
+ {
+ address.Assign (fillDevices.Get (i * nFill + j));
+ }
+ }
+
+ NS_LOG_INFO ("Create applications.");
+ //
+ // Create a packet sink on the star "hub" to receive packets.
+ //
+ uint16_t port = 50000;
+ Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
+ ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
+ hubApp.Start (Seconds (1.0));
+ hubApp.Stop (Seconds (10.0));
+
+ //
+ // Create OnOff applications to send TCP to the hub, one on each spoke node.
+ //
+ OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
+ onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer spokeApps;
+
+ for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ {
+ AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
+ }
+
+ spokeApps.Start (Seconds (1.0));
+ spokeApps.Stop (Seconds (10.0));
+
+ //
+ // Because we are evil, we also add OnOff applications to send TCP to the hub
+ // from the fill devices on each CSMA link. The first nFill nodes in the
+ // fillNodes container are on the CSMA network talking to the zeroth device
+ // on the hub node. The next nFill nodes are on the CSMA network talking to
+ // the first device on the hub node, etc. So the ith fillNode is associated
+ // with the hub address found on the (i / nFill)th device on the hub node.
+ //
+ ApplicationContainer fillApps;
+
+ for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
+ {
+ AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i / nFill), port));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
+ }
+
+ fillApps.Start (Seconds (1.0));
+ fillApps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Enable static global routing.");
+ //
+ // Turn on global static routing so we can actually be routed across the star.
+ //
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ NS_LOG_INFO ("Enable pcap tracing.");
+ //
+ // Do pcap tracing on all devices on all nodes.
+ //
+ CsmaHelper::EnablePcapAll ("csma-star", false);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/csma/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,29 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('csma-one-subnet', ['csma', 'internet-stack'])
+ obj.source = 'csma-one-subnet.cc'
+
+ obj = bld.create_ns3_program('csma-bridge', ['bridge', 'csma', 'internet-stack'])
+ obj.source = 'csma-bridge.cc'
+
+ obj = bld.create_ns3_program('csma-bridge-one-hop', ['bridge', 'csma', 'internet-stack'])
+ obj.source = 'csma-bridge-one-hop.cc'
+
+ obj = bld.create_ns3_program('csma-broadcast', ['csma', 'internet-stack'])
+ obj.source = 'csma-broadcast.cc'
+
+ obj = bld.create_ns3_program('csma-packet-socket', ['csma', 'internet-stack'])
+ obj.source = 'csma-packet-socket.cc'
+
+ obj = bld.create_ns3_program('csma-multicast', ['csma', 'internet-stack'])
+ obj.source = 'csma-multicast.cc'
+
+ obj = bld.create_ns3_program('csma-star', ['csma', 'internet-stack'])
+ obj.source = 'csma-star.cc'
+
+ obj = bld.create_ns3_program('csma-raw-ip-socket', ['csma', 'internet-stack'])
+ obj.source = 'csma-raw-ip-socket.cc'
+
+ obj = bld.create_ns3_program('csma-ping', ['csma', 'internet-stack', 'v4ping'])
+ obj.source = 'csma-ping.cc'
--- a/examples/dynamic-global-routing.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Contributed by: Luis Cortes (cortes@gatech.edu)
- */
-
-
-// This script exercises global routing code in a mixed point-to-point
-// and csma/cd environment
-//
-// Network topology
-//
-// n0
-// \ p-p
-// \ (shared csma/cd)
-// n2 -------------------------n3
-// / | |
-// / p-p n4 n5 ---------- n6
-// n1 p-p
-// | |
-// ----------------------------------------
-// p-p
-//
-// - at time 1 CBR/UDP flow from n1 to n6's IP address on the n5/n6 link
-// - at time 10, start similar flow from n1 to n6's address on the n1/n6 link
-//
-// Order of events
-// At pre-simulation time, configure global routes. Shortest path from
-// n1 to n6 is via the direct point-to-point link
-// At time 1s, start CBR traffic flow from n1 to n6
-// At time 2s, set the n1 point-to-point interface to down. Packets
-// will start to be dropped
-// At time 3s, call RecomputeRoutingTables() and traffic will
-// start flowing again on the alternate path
-// At time 4s, re-enable the n1/n6 interface to up. Will not change routing
-// At time 5s, call RecomputeRoutingTables() and traffic will start flowing
-// again on the original path
-// At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this
-// keeps the point-to-point link "up" from n1's perspective). Packets
-// will traverse the link and be dropped at n6 upon receipt. These drops
-// are not visible in the pcap trace but in the ascii trace.
-// At time 7s, call RecomputeRoutingTables() and traffic will flow again
-// through the path n1-n2-n5-n6
-// At time 8s, bring the interface back up.
-// At time 9s, call RecomputeRoutingTables() and traffic will flow again
-// through the path n1-n6
-// At time 10s, stop the first flow.
-// At time 11s, start a new flow, but to n6's other IP address (the one
-// on the n1/n6 p2p link)
-// At time 12s, bring the n1 interface down between n1 and n6. Packets
-// will start to be dropped
-// At time 13s, call RecomputeRoutingTables() and traffic will
-// start flowing again on the alternate path
-// At time 14s, re-enable the n1/n6 interface to up. This will change
-// routing back to n1-n6 since the interface up notification will cause
-// a new local interface route, at higher priority than global routing
-// At time 15s, call RecomputeRoutingTables(), but there is no effect
-// since global routing is lower in priority than static routing
-// At time 16s, stop the second flow.
-
-// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("DynamicGlobalRoutingExample");
-
-int
-main (int argc, char *argv[])
-{
- // Allow the user to override any of the defaults and the above
- // Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (7);
- NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
- NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
- NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6));
- NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
- NetDeviceContainer d1d6 = p2p.Install (n1n6);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer d5d6 = p2p.Install (n5n6);
-
- // We create the channels first without any IP addressing information
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
- csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d2345 = csma.Install (n2345);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
-
- ipv4.SetBase ("10.250.1.0", "255.255.255.0");
- ipv4.Assign (d2345);
-
- ipv4.SetBase ("172.16.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- InetSocketAddress (i5i6.GetAddress (1), port));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", StringValue ("2kbps"));
- onoff.SetAttribute ("PacketSize", UintegerValue (50));
-
- ApplicationContainer apps = onoff.Install (c.Get (1));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a second OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- OnOffHelper onoff2 ("ns3::UdpSocketFactory",
- InetSocketAddress (i1i6.GetAddress (1), port));
- onoff2.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff2.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff2.SetAttribute ("DataRate", StringValue ("2kbps"));
- onoff2.SetAttribute ("PacketSize", UintegerValue (50));
-
- ApplicationContainer apps2 = onoff2.Install (c.Get (1));
- apps2.Start (Seconds (11.0));
- apps2.Stop (Seconds (16.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (6));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- PacketSinkHelper sink2 ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps2 = sink2.Install (c.Get (6));
- apps2.Start (Seconds (11.0));
- apps2.Stop (Seconds (16.0));
-
-
- std::ofstream ascii;
- ascii.open ("dynamic-global-routing.tr", std::ios_base::binary | std::ios_base::out);
- PointToPointHelper::EnablePcapAll ("dynamic-global-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
- CsmaHelper::EnablePcapAll ("dynamic-global-routing", false);
- CsmaHelper::EnableAsciiAll (ascii);
- InternetStackHelper::EnableAsciiAll (ascii);
-
- Ptr<Node> n1 = c.Get (1);
- Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
- // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
- // then the next p2p is numbered 2
- uint32_t ipv4ifIndex1 = 2;
-
- Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
- Simulator::Schedule (Seconds (3),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
- Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
- Simulator::Schedule (Seconds (5),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
-
- Ptr<Node> n6 = c.Get (6);
- Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
- // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
- // then the next p2p is numbered 2
- uint32_t ipv4ifIndex6 = 2;
- Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
- Simulator::Schedule (Seconds (7),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
- Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
- Simulator::Schedule (Seconds (9),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
-
- Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
- Simulator::Schedule (Seconds (13),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
- Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
- Simulator::Schedule (Seconds (15),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/emu-ping.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Allow ns-3 to ping a real host somewhere, using emulation mode
-//
-// ------------
-// | node n0 |
-// | |
-// | --- |
-// | | | |
-// | |emu| |
-// | | | |
-// | --- |
-// | | |
-// ----|-------
-// |
-// (device on host system, set to promiscuous mode)
-// |
-// --------- (Internet) -------
-//
-// To use this example:
-// 1) You need to decide on a physical device on your real system, and either
-// overwrite the hard-configured device name below (eth0) or pass this
-// device name in as a command-line argument
-// 2) The host device must be set to promiscuous mode
-// (e.g. "sudo ifconfig eth0 promisc")
-// 3) Be aware that ns-3 will generate a fake mac address, and that in
-// some enterprise networks, this may be considered bad form to be
-// sending packets out of your device with "unauthorized" mac addresses
-// 4) You will need to assign an IP address to the ns-3 simulation node that
-// is consistent with the subnet that is active on the host device's link.
-// That is, you will have to assign an IP address to the ns-3 node as if
-// it were on your real subnet. Search for "Ipv4Address localIp" and
-// replace the string "1.2.3.4" with a valid IP address.
-// 5) You will need to configure a default route in the ns-3 node to tell it
-// how to get off of your subnet. One thing you could do is a
-// 'netstat -rn' command and find the IP address of the default gateway
-// on your host. Search for "Ipv4Address gateway" and replace the string
-// "1.2.3.4" string with the gateway IP address.
-
-#include "ns3/abort.h"
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/emu-module.h"
-#include "ns3/v4ping-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("PingEmulationExample");
-
-static void
-PingRtt (std::string context, Time rtt)
-{
- NS_LOG_UNCOND ("Received Response with RTT = " << rtt);
-}
-
-int
-main (int argc, char *argv[])
-{
- NS_LOG_INFO ("Ping Emulation Example");
-
- std::string deviceName ("eth0");
- std::string remote ("208.77.188.166"); // example.com
-
- //
- // Allow the user to override any of the defaults at run-time, via
- // command-line arguments
- //
- CommandLine cmd;
- cmd.AddValue("deviceName", "Device name", deviceName);
- cmd.AddValue("remote", "Remote IP address (dotted decimal only please)", remote);
- cmd.Parse (argc, argv);
-
- Ipv4Address remoteIp (remote.c_str ());
- Ipv4Address localIp ("1.2.3.4");
- NS_ABORT_MSG_IF (localIp == "1.2.3.4", "You must change the local IP address before running this example");
-
- Ipv4Mask localMask ("255.255.255.0");
-
- //
- // Since we are using a real piece of hardware we need to use the realtime
- // simulator.
- //
- GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
-
- //
- // Since we are going to be talking to real-world machines, we need to enable
- // calculation of checksums in our protocols.
- //
- GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
-
- //
- // In such a simple topology, the use of the helper API can be a hindrance
- // so we drop down into the low level API and do it manually.
- //
- // First we need a single node.
- //
- NS_LOG_INFO ("Create Node");
- Ptr<Node> node = CreateObject<Node> ();
-
- //
- // Create an emu device, allocate a MAC address and point the device to the
- // Linux device name. The device needs a transmit queueing discipline so
- // create a droptail queue and give it to the device. Finally, "install"
- // the device into the node.
- //
- // Do understand that the ns-3 allocated MAC address will be sent out over
- // your network since the emu net device will spoof it. By default, this
- // address will have an Organizationally Unique Identifier (OUI) of zero.
- // The Internet Assigned Number Authority IANA
- //
- // http://www.iana.org/assignments/ethernet-numbers
- //
- // reports that this OUI is unassigned, and so should not conflict with
- // real hardware on your net. It may raise all kinds of red flags in a
- // real environment to have packets from a device with an obviously bogus
- // OUI flying around. Be aware.
- //
- NS_LOG_INFO ("Create Device");
- Ptr<EmuNetDevice> device = CreateObject<EmuNetDevice> ();
- device->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));
- device->SetAttribute ("DeviceName", StringValue (deviceName));
-
- Ptr<Queue> queue = CreateObject<DropTailQueue> ();
- device->SetQueue (queue);
- node->AddDevice (device);
-
- //
- // Add a default internet stack to the node. This gets us the ns-3 versions
- // of ARP, IPv4, ICMP, UDP and TCP.
- //
- NS_LOG_INFO ("Add Internet Stack");
- InternetStackHelper internetStackHelper;
- internetStackHelper.Install (node);
-
- NS_LOG_INFO ("Create IPv4 Interface");
- Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
- uint32_t interface = ipv4->AddInterface (device);
- Ipv4InterfaceAddress address = Ipv4InterfaceAddress (localIp, localMask);
- ipv4->AddAddress (interface, address);
- ipv4->SetMetric (interface, 1);
- ipv4->SetUp (interface);
-
- //
- // When the ping appliation sends its ICMP packet, it will happily send it
- // down the ns-3 protocol stack. We set the IP address of the destination
- // to the address corresponding to example.com above. This address is off
- // our local network so we have got to provide some kind of default route
- // to ns-3 to be able to get that ICMP packet forwarded off of our network.
- //
- // You have got to provide an IP address of a real host that you can send
- // real packets to and have them forwarded off of your local network. One
- // thing you could do is a 'netstat -rn' command and find the IP address of
- // the default gateway on your host and add it below, replacing the
- // "1.2.3.4" string.
- //
- Ipv4Address gateway ("1.2.3.4");
- NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");
-
- Ipv4StaticRoutingHelper ipv4RoutingHelper;
- Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
- staticRouting->SetDefaultRoute (gateway, interface);
-
- //
- // Create the ping application. This application knows how to send
- // ICMP echo requests. Setting up the packet sink manually is a bit
- // of a hassle and since there is no law that says we cannot mix the
- // helper API with the low level API, let's just use the helper.
- //
- NS_LOG_INFO ("Create V4Ping Appliation");
- Ptr<V4Ping> app = CreateObject<V4Ping> ();
- app->SetAttribute ("Remote", Ipv4AddressValue (remoteIp));
- node->AddApplication (app);
- app->Start (Seconds (1.0));
- app->Stop (Seconds (5.0));
-
- //
- // Give the application a name. This makes life much easier when constructing
- // config paths.
- //
- Names::Add ("app", app);
-
- //
- // Hook a trace to print something when the response comes back.
- //
- Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));
-
- //
- // Enable a promiscuous pcap trace to see what is coming and going on our device.
- //
- EmuHelper::EnablePcap ("emu-ping", device, true);
-
- //
- // Now, do the actual emulation.
- //
- NS_LOG_INFO ("Run Emulation.");
- Simulator::Stop (Seconds (5.0));
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/emu-udp-echo.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// Normally, the use case for emulated net devices is in collections of
-// small simulations that connect to the outside world through specific
-// interfaces. For example, one could construct a number of virtual
-// machines and connect them via a host-only network. To use the emulated
-// net device, you would need to set all of the host-only interfaces in
-// promiscuous mode and provide an appropriate device name (search for "eth1"
-// below). One could also use the emulated net device in a testbed situation
-// where the host on which the simulation is running has a specific interface
-// of interested. You would also need to set this specific interface into
-// promiscuous mode and provide an appropriate device name.
-//
-// This philosophy carries over to this simple example.
-//
-// We don't assume any special configuration and all of the ns-3 emulated net
-// devices will actually talk to the same underlying OS device. We rely on
-// the fact that the OS will deliver copies of our packets to the other ns-3
-// net devices since we operate in promiscuous mode.
-//
-// Packets will be sent out over the device, but we use MAC spoofing. The
-// MAC addresses will be generated using the Organizationally Unique Identifier
-// (OUI) 00:00:00 as a base. This vendor code is not assigned to any
-// organization and so should not conflict with any real hardware. We'll use
-// the first n of these addresses, where n is the number of nodes, in this
-// simualtion. It is up to you to determine that using these MAC addresses is
-// okay on your network and won't conflict with anything else (including another
-// simulation using emu devices) on your network. Once you have made this
-// determination, you need to put the interface you chose into promiscuous mode.
-// We don't do it for you since you need to think about it first.
-//
-// This simulation uses the real-time simulator and so will consume ten seconds
-// of real time.
-//
-// By default, we create the following topology
-//
-// n0 n1 n2 n3
-// | | | |
-// -----------------
-// "eth1"
-//
-// - UDP flows from n0 to n1 and back
-// - DropTail queues
-// - Tracing of queues and packet receptions to file "udp-echo.tr"
-// - pcap tracing on all devices
-//
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/emu-helper.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("EmulatedUdpEchoExample");
-
-int
-main (int argc, char *argv[])
-{
- std::string deviceName ("eth1");
- uint32_t nNodes = 4;
-
- //
- // Allow the user to override any of the defaults at run-time, via command-line
- // arguments
- //
- CommandLine cmd;
- cmd.AddValue("deviceName", "device name", deviceName);
- cmd.AddValue("nNodes", "number of nodes to create (>= 2)", nNodes);
- cmd.Parse (argc, argv);
-
- GlobalValue::Bind ("SimulatorImplementationType",
- StringValue ("ns3::RealtimeSimulatorImpl"));
-
- //
- // need at least two nodes
- //
- nNodes = nNodes < 2 ? 2 : nNodes;
-
- //
- // Explicitly create the nodes required by the topology (shown above).
- //
- NS_LOG_INFO ("Create nodes.");
- NodeContainer n;
- n.Create (nNodes);
-
- InternetStackHelper internet;
- internet.Install (n);
-
- //
- // Explicitly create the channels required by the topology (shown above).
- //
- NS_LOG_INFO ("Create channels.");
- EmuHelper emu;
- emu.SetAttribute ("DeviceName", StringValue (deviceName));
- NetDeviceContainer d = emu.Install (n);
-
- //
- // We've got the "hardware" in place. Now we need to add IP addresses.
- //
- Ipv4AddressHelper ipv4;
- NS_LOG_INFO ("Assign IP Addresses.");
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i = ipv4.Assign (d);
-
- //
- // Create a UdpEchoServer application on node one.
- //
- NS_LOG_INFO ("Create Applications.");
- UdpEchoServerHelper server (9);
- ApplicationContainer apps = server.Install (n.Get(1));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- //
- // Create a UdpEchoClient application to send UDP datagrams from node zero to node one.
- //
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 1;
- Time interPacketInterval = Seconds (1.);
- UdpEchoClientHelper client (i.GetAddress (1), 9);
- client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- client.SetAttribute ("Interval", TimeValue (interPacketInterval));
- client.SetAttribute ("PacketSize", UintegerValue (packetSize));
- apps = client.Install (n.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("emu-udp-echo.tr");
- EmuHelper::EnablePcapAll ("emu-udp-echo", true);
-
- //
- // Now, do the actual simulation.
- //
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/emulation/emu-ping.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,216 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Allow ns-3 to ping a real host somewhere, using emulation mode
+//
+// ------------
+// | node n0 |
+// | |
+// | --- |
+// | | | |
+// | |emu| |
+// | | | |
+// | --- |
+// | | |
+// ----|-------
+// |
+// (device on host system, set to promiscuous mode)
+// |
+// --------- (Internet) -------
+//
+// To use this example:
+// 1) You need to decide on a physical device on your real system, and either
+// overwrite the hard-configured device name below (eth0) or pass this
+// device name in as a command-line argument
+// 2) The host device must be set to promiscuous mode
+// (e.g. "sudo ifconfig eth0 promisc")
+// 3) Be aware that ns-3 will generate a fake mac address, and that in
+// some enterprise networks, this may be considered bad form to be
+// sending packets out of your device with "unauthorized" mac addresses
+// 4) You will need to assign an IP address to the ns-3 simulation node that
+// is consistent with the subnet that is active on the host device's link.
+// That is, you will have to assign an IP address to the ns-3 node as if
+// it were on your real subnet. Search for "Ipv4Address localIp" and
+// replace the string "1.2.3.4" with a valid IP address.
+// 5) You will need to configure a default route in the ns-3 node to tell it
+// how to get off of your subnet. One thing you could do is a
+// 'netstat -rn' command and find the IP address of the default gateway
+// on your host. Search for "Ipv4Address gateway" and replace the string
+// "1.2.3.4" string with the gateway IP address.
+
+#include "ns3/abort.h"
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/emu-module.h"
+#include "ns3/v4ping-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("PingEmulationExample");
+
+static void
+PingRtt (std::string context, Time rtt)
+{
+ NS_LOG_UNCOND ("Received Response with RTT = " << rtt);
+}
+
+int
+main (int argc, char *argv[])
+{
+ NS_LOG_INFO ("Ping Emulation Example");
+
+ std::string deviceName ("eth0");
+ std::string remote ("208.77.188.166"); // example.com
+
+ //
+ // Allow the user to override any of the defaults at run-time, via
+ // command-line arguments
+ //
+ CommandLine cmd;
+ cmd.AddValue("deviceName", "Device name", deviceName);
+ cmd.AddValue("remote", "Remote IP address (dotted decimal only please)", remote);
+ cmd.Parse (argc, argv);
+
+ Ipv4Address remoteIp (remote.c_str ());
+ Ipv4Address localIp ("1.2.3.4");
+ NS_ABORT_MSG_IF (localIp == "1.2.3.4", "You must change the local IP address before running this example");
+
+ Ipv4Mask localMask ("255.255.255.0");
+
+ //
+ // Since we are using a real piece of hardware we need to use the realtime
+ // simulator.
+ //
+ GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
+
+ //
+ // Since we are going to be talking to real-world machines, we need to enable
+ // calculation of checksums in our protocols.
+ //
+ GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
+
+ //
+ // In such a simple topology, the use of the helper API can be a hindrance
+ // so we drop down into the low level API and do it manually.
+ //
+ // First we need a single node.
+ //
+ NS_LOG_INFO ("Create Node");
+ Ptr<Node> node = CreateObject<Node> ();
+
+ //
+ // Create an emu device, allocate a MAC address and point the device to the
+ // Linux device name. The device needs a transmit queueing discipline so
+ // create a droptail queue and give it to the device. Finally, "install"
+ // the device into the node.
+ //
+ // Do understand that the ns-3 allocated MAC address will be sent out over
+ // your network since the emu net device will spoof it. By default, this
+ // address will have an Organizationally Unique Identifier (OUI) of zero.
+ // The Internet Assigned Number Authority IANA
+ //
+ // http://www.iana.org/assignments/ethernet-numbers
+ //
+ // reports that this OUI is unassigned, and so should not conflict with
+ // real hardware on your net. It may raise all kinds of red flags in a
+ // real environment to have packets from a device with an obviously bogus
+ // OUI flying around. Be aware.
+ //
+ NS_LOG_INFO ("Create Device");
+ Ptr<EmuNetDevice> device = CreateObject<EmuNetDevice> ();
+ device->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));
+ device->SetAttribute ("DeviceName", StringValue (deviceName));
+
+ Ptr<Queue> queue = CreateObject<DropTailQueue> ();
+ device->SetQueue (queue);
+ node->AddDevice (device);
+
+ //
+ // Add a default internet stack to the node. This gets us the ns-3 versions
+ // of ARP, IPv4, ICMP, UDP and TCP.
+ //
+ NS_LOG_INFO ("Add Internet Stack");
+ InternetStackHelper internetStackHelper;
+ internetStackHelper.Install (node);
+
+ NS_LOG_INFO ("Create IPv4 Interface");
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ uint32_t interface = ipv4->AddInterface (device);
+ Ipv4InterfaceAddress address = Ipv4InterfaceAddress (localIp, localMask);
+ ipv4->AddAddress (interface, address);
+ ipv4->SetMetric (interface, 1);
+ ipv4->SetUp (interface);
+
+ //
+ // When the ping appliation sends its ICMP packet, it will happily send it
+ // down the ns-3 protocol stack. We set the IP address of the destination
+ // to the address corresponding to example.com above. This address is off
+ // our local network so we have got to provide some kind of default route
+ // to ns-3 to be able to get that ICMP packet forwarded off of our network.
+ //
+ // You have got to provide an IP address of a real host that you can send
+ // real packets to and have them forwarded off of your local network. One
+ // thing you could do is a 'netstat -rn' command and find the IP address of
+ // the default gateway on your host and add it below, replacing the
+ // "1.2.3.4" string.
+ //
+ Ipv4Address gateway ("1.2.3.4");
+ NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");
+
+ Ipv4StaticRoutingHelper ipv4RoutingHelper;
+ Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
+ staticRouting->SetDefaultRoute (gateway, interface);
+
+ //
+ // Create the ping application. This application knows how to send
+ // ICMP echo requests. Setting up the packet sink manually is a bit
+ // of a hassle and since there is no law that says we cannot mix the
+ // helper API with the low level API, let's just use the helper.
+ //
+ NS_LOG_INFO ("Create V4Ping Appliation");
+ Ptr<V4Ping> app = CreateObject<V4Ping> ();
+ app->SetAttribute ("Remote", Ipv4AddressValue (remoteIp));
+ node->AddApplication (app);
+ app->Start (Seconds (1.0));
+ app->Stop (Seconds (5.0));
+
+ //
+ // Give the application a name. This makes life much easier when constructing
+ // config paths.
+ //
+ Names::Add ("app", app);
+
+ //
+ // Hook a trace to print something when the response comes back.
+ //
+ Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));
+
+ //
+ // Enable a promiscuous pcap trace to see what is coming and going on our device.
+ //
+ EmuHelper::EnablePcap ("emu-ping", device, true);
+
+ //
+ // Now, do the actual emulation.
+ //
+ NS_LOG_INFO ("Run Emulation.");
+ Simulator::Stop (Seconds (5.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/emulation/emu-udp-echo.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,157 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// Normally, the use case for emulated net devices is in collections of
+// small simulations that connect to the outside world through specific
+// interfaces. For example, one could construct a number of virtual
+// machines and connect them via a host-only network. To use the emulated
+// net device, you would need to set all of the host-only interfaces in
+// promiscuous mode and provide an appropriate device name (search for "eth1"
+// below). One could also use the emulated net device in a testbed situation
+// where the host on which the simulation is running has a specific interface
+// of interested. You would also need to set this specific interface into
+// promiscuous mode and provide an appropriate device name.
+//
+// This philosophy carries over to this simple example.
+//
+// We don't assume any special configuration and all of the ns-3 emulated net
+// devices will actually talk to the same underlying OS device. We rely on
+// the fact that the OS will deliver copies of our packets to the other ns-3
+// net devices since we operate in promiscuous mode.
+//
+// Packets will be sent out over the device, but we use MAC spoofing. The
+// MAC addresses will be generated using the Organizationally Unique Identifier
+// (OUI) 00:00:00 as a base. This vendor code is not assigned to any
+// organization and so should not conflict with any real hardware. We'll use
+// the first n of these addresses, where n is the number of nodes, in this
+// simualtion. It is up to you to determine that using these MAC addresses is
+// okay on your network and won't conflict with anything else (including another
+// simulation using emu devices) on your network. Once you have made this
+// determination, you need to put the interface you chose into promiscuous mode.
+// We don't do it for you since you need to think about it first.
+//
+// This simulation uses the real-time simulator and so will consume ten seconds
+// of real time.
+//
+// By default, we create the following topology
+//
+// n0 n1 n2 n3
+// | | | |
+// -----------------
+// "eth1"
+//
+// - UDP flows from n0 to n1 and back
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "udp-echo.tr"
+// - pcap tracing on all devices
+//
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/emu-helper.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("EmulatedUdpEchoExample");
+
+int
+main (int argc, char *argv[])
+{
+ std::string deviceName ("eth1");
+ uint32_t nNodes = 4;
+
+ //
+ // Allow the user to override any of the defaults at run-time, via command-line
+ // arguments
+ //
+ CommandLine cmd;
+ cmd.AddValue("deviceName", "device name", deviceName);
+ cmd.AddValue("nNodes", "number of nodes to create (>= 2)", nNodes);
+ cmd.Parse (argc, argv);
+
+ GlobalValue::Bind ("SimulatorImplementationType",
+ StringValue ("ns3::RealtimeSimulatorImpl"));
+
+ //
+ // need at least two nodes
+ //
+ nNodes = nNodes < 2 ? 2 : nNodes;
+
+ //
+ // Explicitly create the nodes required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer n;
+ n.Create (nNodes);
+
+ InternetStackHelper internet;
+ internet.Install (n);
+
+ //
+ // Explicitly create the channels required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create channels.");
+ EmuHelper emu;
+ emu.SetAttribute ("DeviceName", StringValue (deviceName));
+ NetDeviceContainer d = emu.Install (n);
+
+ //
+ // We've got the "hardware" in place. Now we need to add IP addresses.
+ //
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (d);
+
+ //
+ // Create a UdpEchoServer application on node one.
+ //
+ NS_LOG_INFO ("Create Applications.");
+ UdpEchoServerHelper server (9);
+ ApplicationContainer apps = server.Install (n.Get(1));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ //
+ // Create a UdpEchoClient application to send UDP datagrams from node zero to node one.
+ //
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 1;
+ Time interPacketInterval = Seconds (1.);
+ UdpEchoClientHelper client (i.GetAddress (1), 9);
+ client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ client.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ client.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ apps = client.Install (n.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("emu-udp-echo.tr");
+ EmuHelper::EnablePcapAll ("emu-udp-echo", true);
+
+ //
+ // Now, do the actual simulation.
+ //
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/emulation/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/emulation/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,10 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ env = bld.env_of_name('default')
+ if env['ENABLE_EMU']:
+ obj = bld.create_ns3_program('emu-udp-echo', ['emu', 'internet-stack'])
+ obj.source = 'emu-udp-echo.cc'
+
+ obj = bld.create_ns3_program('emu-ping', ['emu', 'internet-stack'])
+ obj.source = 'emu-ping.cc'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/error-model/simple-error-model.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,178 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ns-2 simple.tcl script (ported from ns-2)
+ * Originally authored by Steve McCanne, 12/19/1996
+ */
+
+// Port of ns-2/tcl/ex/simple.tcl to ns-3
+//
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 -------------------------n3
+// /
+// / 5 Mb/s, 2ms
+// n1
+//
+// - all links are point-to-point links with indicated one-way BW/delay
+// - CBR/UDP flows from n0 to n3, and from n3 to n1
+// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
+// - 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
+// "simple-error-model.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample");
+
+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
+#if 0
+ LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
+#endif
+
+
+ // Set a few attributes
+ Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01));
+ Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT"));
+
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s")));
+
+
+ // Allow the user to override any of the defaults and the above
+ // Bind()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+ NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
+ NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (5000000)));
+ p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (1500000)));
+ p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
+ NetDeviceContainer d3d2 = p2p.Install (n3n2);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
+
+ NS_LOG_INFO ("Use global routing.");
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (i3i2.GetAddress (1), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0)));
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start(Seconds(1.0));
+ apps.Stop (Seconds(10.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (2));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a similar flow from n3 to n1, starting at time 1.1 seconds
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
+ apps = onoff.Install (c.Get (3));
+ apps.Start(Seconds(1.1));
+ apps.Stop (Seconds(10.0));
+
+ // Create a packet sink to receive these packets
+ sink.SetAttribute ("Local",
+ AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ //
+ // Error model
+ //
+ // Create an ErrorModel based on the implementation (constructor)
+ // specified by the default classId
+ Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)),
+ "ErrorRate", DoubleValue (0.001));
+ d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
+
+ // Now, let's use the ListErrorModel and explicitly force a loss
+ // of the packets with pkt-uids = 11 and 17 on node 2, device 0
+ std::list<uint32_t> sampleList;
+ sampleList.push_back (11);
+ sampleList.push_back (17);
+ // This time, we'll explicitly create the error model we want
+ Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> ();
+ pem->SetList (sampleList);
+ d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem));
+
+ std::ofstream ascii;
+ ascii.open ("simple-error-model.tr");
+ PointToPointHelper::EnablePcapAll ("simple-error-model");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/error-model/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/error-model/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,5 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('simple-error-model', ['point-to-point', 'internet-stack'])
+ obj.source = 'simple-error-model.cc'
--- a/examples/first.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
-
- int
-main (int argc, char *argv[])
-{
- LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
-
- NodeContainer nodes;
- nodes.Create (2);
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NetDeviceContainer devices;
- devices = pointToPoint.Install (nodes);
-
- InternetStackHelper stack;
- stack.Install (nodes);
-
- Ipv4AddressHelper address;
- address.SetBase ("10.1.1.0", "255.255.255.0");
-
- Ipv4InterfaceContainer interfaces = address.Assign (devices);
-
- UdpEchoServerHelper echoServer (9);
-
- ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
-
- UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
- ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
-
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
--- a/examples/first.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,55 +0,0 @@
-# /*
-# * This program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License version 2 as
-# * published by the Free Software Foundation;
-# *
-# * This program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with this program; if not, write to the Free Software
-# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-# */
-
-import ns3
-
-ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
-ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)
-
-nodes = ns3.NodeContainer()
-nodes.Create(2)
-
-pointToPoint = ns3.PointToPointHelper()
-pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps"))
-pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms"))
-
-devices = pointToPoint.Install(nodes)
-
-stack = ns3.InternetStackHelper()
-stack.Install(nodes)
-
-address = ns3.Ipv4AddressHelper()
-address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
-
-interfaces = address.Assign (devices);
-
-echoServer = ns3.UdpEchoServerHelper(9)
-
-serverApps = echoServer.Install(nodes.Get(1))
-serverApps.Start(ns3.Seconds(1.0))
-serverApps.Stop(ns3.Seconds(10.0))
-
-echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
-echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
-echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds (1.0)))
-echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
-
-clientApps = echoClient.Install(nodes.Get(0))
-clientApps.Start(ns3.Seconds(2.0))
-clientApps.Stop(ns3.Seconds(10.0))
-
-ns3.Simulator.Run()
-ns3.Simulator.Destroy()
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/flowmon/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/flowmon/wifi-olsr-flowmon.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,171 @@
+# -*- Mode: Python; -*-
+# Copyright (c) 2009 INESC Porto
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Authors: Gustavo Carneiro <gjc@inescporto.pt>
+
+import sys
+import ns3
+
+DISTANCE = 150 # (m)
+NUM_NODES_SIDE = 3
+
+def main(argv):
+
+ cmd = ns3.CommandLine()
+
+ cmd.NumNodesSide = None
+ cmd.AddValue("NumNodesSide", "Grid side number of nodes (total number of nodes will be this number squared)")
+
+ cmd.Results = None
+ cmd.AddValue("Results", "Write XML results to file")
+
+ cmd.Plot = None
+ cmd.AddValue("Plot", "Plot the results using the matplotlib python module")
+
+ cmd.Parse(argv)
+
+ wifi = ns3.WifiHelper.Default()
+ wifiMac = ns3.NqosWifiMacHelper.Default()
+ wifiPhy = ns3.YansWifiPhyHelper.Default()
+ wifiChannel = ns3.YansWifiChannelHelper.Default()
+ wifiPhy.SetChannel(wifiChannel.Create())
+ ssid = ns3.Ssid("wifi-default")
+ wifi.SetRemoteStationManager("ns3::ArfWifiManager")
+ wifiMac.SetType ("ns3::AdhocWifiMac", "Ssid", ns3.SsidValue(ssid))
+
+ internet = ns3.InternetStackHelper()
+ list_routing = ns3.Ipv4ListRoutingHelper()
+ olsr_routing = ns3.OlsrHelper()
+ static_routing = ns3.Ipv4StaticRoutingHelper()
+ list_routing.Add(static_routing, 0)
+ list_routing.Add(olsr_routing, 100)
+ internet.SetRoutingHelper(list_routing)
+
+ ipv4Addresses = ns3.Ipv4AddressHelper()
+ ipv4Addresses.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
+
+ port = 9 # Discard port(RFC 863)
+ onOffHelper = ns3.OnOffHelper("ns3::UdpSocketFactory",
+ ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.0.0.1"), port)))
+ onOffHelper.SetAttribute("DataRate", ns3.DataRateValue(ns3.DataRate("100kbps")))
+ onOffHelper.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
+ onOffHelper.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
+
+ addresses = []
+ nodes = []
+
+ if cmd.NumNodesSide is None:
+ num_nodes_side = NUM_NODES_SIDE
+ else:
+ num_nodes_side = int(cmd.NumNodesSide)
+
+ for xi in range(num_nodes_side):
+ for yi in range(num_nodes_side):
+
+ node = ns3.Node()
+ nodes.append(node)
+
+ internet.Install(ns3.NodeContainer(node))
+
+ mobility = ns3.ConstantPositionMobilityModel()
+ mobility.SetPosition(ns3.Vector(xi*DISTANCE, yi*DISTANCE, 0))
+ node.AggregateObject(mobility)
+
+ devices = wifi.Install(wifiPhy, wifiMac, node)
+ ipv4_interfaces = ipv4Addresses.Assign(devices)
+ addresses.append(ipv4_interfaces.GetAddress(0))
+
+ for i, node in enumerate(nodes):
+ destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)]
+ #print i, destaddr
+ onOffHelper.SetAttribute("Remote", ns3.AddressValue(ns3.InetSocketAddress(destaddr, port)))
+ app = onOffHelper.Install(ns3.NodeContainer(node))
+ app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))
+
+ #internet.EnablePcapAll("wifi-olsr")
+ flowmon_helper = ns3.FlowMonitorHelper()
+ #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31)))
+ monitor = flowmon_helper.InstallAll()
+ monitor.SetAttribute("DelayBinWidth", ns3.DoubleValue(0.001))
+ monitor.SetAttribute("JitterBinWidth", ns3.DoubleValue(0.001))
+ monitor.SetAttribute("PacketSizeBinWidth", ns3.DoubleValue(20))
+
+ ns3.Simulator.Stop(ns3.Seconds(44.0))
+ ns3.Simulator.Run()
+
+ def print_stats(os, st):
+ print >> os, " Tx Bytes: ", st.txBytes
+ print >> os, " Rx Bytes: ", st.rxBytes
+ print >> os, " Tx Packets: ", st.txPackets
+ print >> os, " Rx Packets: ", st.rxPackets
+ print >> os, " Lost Packets: ", st.lostPackets
+ if st.rxPackets > 0:
+ print >> os, " Mean{Delay}: ", (st.delaySum.GetSeconds() / st.rxPackets)
+ print >> os, " Mean{Jitter}: ", (st.jitterSum.GetSeconds() / (st.rxPackets-1))
+ print >> os, " Mean{Hop Count}: ", float(st.timesForwarded) / st.rxPackets + 1
+
+ if 0:
+ print >> os, "Delay Histogram"
+ for i in range(st.delayHistogram.GetNBins () ):
+ print >> os, " ",i,"(", st.delayHistogram.GetBinStart (i), "-", \
+ st.delayHistogram.GetBinEnd (i), "): ", st.delayHistogram.GetBinCount (i)
+ print >> os, "Jitter Histogram"
+ for i in range(st.jitterHistogram.GetNBins () ):
+ print >> os, " ",i,"(", st.jitterHistogram.GetBinStart (i), "-", \
+ st.jitterHistogram.GetBinEnd (i), "): ", st.jitterHistogram.GetBinCount (i)
+ print >> os, "PacketSize Histogram"
+ for i in range(st.packetSizeHistogram.GetNBins () ):
+ print >> os, " ",i,"(", st.packetSizeHistogram.GetBinStart (i), "-", \
+ st.packetSizeHistogram.GetBinEnd (i), "): ", st.packetSizeHistogram.GetBinCount (i)
+
+ for reason, drops in enumerate(st.packetsDropped):
+ print " Packets dropped by reason %i: %i" % (reason, drops)
+ #for reason, drops in enumerate(st.bytesDropped):
+ # print "Bytes dropped by reason %i: %i" % (reason, drops)
+
+ monitor.CheckForLostPackets()
+ classifier = flowmon_helper.GetClassifier()
+
+ if cmd.Results is None:
+ for flow_id, flow_stats in monitor.GetFlowStats():
+ t = classifier.FindFlow(flow_id)
+ proto = {6: 'TCP', 17: 'UDP'} [t.protocol]
+ print "FlowID: %i (%s %s/%s --> %s/%i)" % \
+ (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort)
+ print_stats(sys.stdout, flow_stats)
+ else:
+ print monitor.SerializeToXmlFile(cmd.Results, True, True)
+
+
+ if cmd.Plot is not None:
+ import pylab
+ delays = []
+ for flow_id, flow_stats in monitor.GetFlowStats():
+ tupl = classifier.FindFlow(flow_id)
+ if tupl.protocol == 17 and tupl.sourcePort == 698:
+ continue
+ delays.append(flow_stats.delaySum.GetSeconds() / flow_stats.rxPackets)
+ pylab.hist(delays, 20)
+ pylab.xlabel("Delay (s)")
+ pylab.ylabel("Number of Flows")
+ pylab.show()
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/flowmon/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,4 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ pass
--- a/examples/global-injection-slash32.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-// Test program for this 3-router scenario, using global routing
-//
-// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/csma-net-device.h"
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/ipv4-static-routing.h"
-#include "ns3/ipv4-global-routing.h"
-#include "ns3/ipv4-list-routing.h"
-#include "ns3/ipv4-routing-table-entry.h"
-#include "ns3/global-router-interface.h"
-
-using namespace ns3;
-using std::cout;
-
-NS_LOG_COMPONENT_DEFINE ("GlobalRouterInjectionTest");
-
-int
-main (int argc, char *argv[])
-{
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- Ptr<Node> nA = CreateObject<Node> ();
- Ptr<Node> nB = CreateObject<Node> ();
- Ptr<Node> nC = CreateObject<Node> ();
-
- NodeContainer c = NodeContainer (nA, nB, nC);
-
- InternetStackHelper internet;
-
- // Point-to-point links
- NodeContainer nAnB = NodeContainer (nA, nB);
- NodeContainer nBnC = NodeContainer (nB, nC);
-
- internet.Install (nAnB);
- Ipv4ListRoutingHelper staticonly;
- Ipv4ListRoutingHelper staticRouting;
- staticonly.Add(staticRouting, 0);
- internet.SetRoutingHelper(staticonly);
- internet.Install(NodeContainer(nC));
-
- // We create the channels first without any IP addressing information
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer dAdB = p2p.Install (nAnB);
-
- NetDeviceContainer dBdC = p2p.Install (nBnC);;
-
- Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
- deviceA->SetAddress (Mac48Address::Allocate ());
- nA->AddDevice (deviceA);
-
- Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
- deviceC->SetAddress (Mac48Address::Allocate ());
- nC->AddDevice (deviceC);
-
- // Later, we add IP addresses.
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.252");
- Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
-
- ipv4.SetBase ("10.1.1.4", "255.255.255.252");
- Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
-
- Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
- Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
- Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
-
- int32_t ifIndexA = ipv4A->AddInterface (deviceA);
- int32_t ifIndexC = ipv4C->AddInterface (deviceC);
-
- Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
- ipv4A->AddAddress (ifIndexA, ifInAddrA);
- ipv4A->SetMetric (ifIndexA, 1);
- ipv4A->SetUp (ifIndexA);
-
- Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
- ipv4C->AddAddress (ifIndexC, ifInAddrC);
- ipv4C->SetMetric (ifIndexC, 1);
- ipv4C->SetUp (ifIndexC);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
-
- // Populate routing tables for nodes nA and nB
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- // Inject global routes from Node B, including transit network...
- Ptr<GlobalRouter> globalRouterB = nB->GetObject<GlobalRouter> ();
- globalRouterB->InjectRoute ("10.1.1.4", "255.255.255.252");
- // ...and the host in network "C"
- globalRouterB->InjectRoute ("192.168.1.1", "255.255.255.255");
-
- Ipv4GlobalRoutingHelper::RecomputeRoutingTables();
- // In addition, nB needs a static route to nC so it knows what to do with stuff
- // going to 192.168.1.1
- Ipv4StaticRoutingHelper ipv4RoutingHelper;
- Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting(ipv4B);
- staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"),2);
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
- ApplicationContainer apps = onoff.Install (nA);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (nC);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("global-routing-injection32.tr", std::ios_base::binary | std::ios_base::out);
- PointToPointHelper::EnablePcapAll ("global-routing-injection32");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/global-routing-slash32.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-// Test program for this 3-router scenario, using global routing
-//
-// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/csma-net-device.h"
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("GlobalRouterSlash32Test");
-
-int
-main (int argc, char *argv[])
-{
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- Ptr<Node> nA = CreateObject<Node> ();
- Ptr<Node> nB = CreateObject<Node> ();
- Ptr<Node> nC = CreateObject<Node> ();
-
- NodeContainer c = NodeContainer (nA, nB, nC);
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // Point-to-point links
- NodeContainer nAnB = NodeContainer (nA, nB);
- NodeContainer nBnC = NodeContainer (nB, nC);
-
- // We create the channels first without any IP addressing information
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer dAdB = p2p.Install (nAnB);
-
- NetDeviceContainer dBdC = p2p.Install (nBnC);;
-
- Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
- deviceA->SetAddress (Mac48Address::Allocate ());
- nA->AddDevice (deviceA);
-
- Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
- deviceC->SetAddress (Mac48Address::Allocate ());
- nC->AddDevice (deviceC);
-
- // Later, we add IP addresses.
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.252");
- Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
-
- ipv4.SetBase ("10.1.1.4", "255.255.255.252");
- Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
-
- Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
- Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
-
- int32_t ifIndexA = ipv4A->AddInterface (deviceA);
- int32_t ifIndexC = ipv4C->AddInterface (deviceC);
-
- Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
- ipv4A->AddAddress (ifIndexA, ifInAddrA);
- ipv4A->SetMetric (ifIndexA, 1);
- ipv4A->SetUp (ifIndexA);
-
- Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
- ipv4C->AddAddress (ifIndexC, ifInAddrC);
- ipv4C->SetMetric (ifIndexC, 1);
- ipv4C->SetUp (ifIndexC);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
- ApplicationContainer apps = onoff.Install (nA);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (nC);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("global-routing-slash32.tr", std::ios_base::binary | std::ios_base::out);
- PointToPointHelper::EnablePcapAll ("global-routing-slash32");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/hello-simulator.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/core-module.h"
-
-NS_LOG_COMPONENT_DEFINE ("HelloSimulator");
-
-using namespace ns3;
-
- int
-main (int argc, char *argv[])
-{
- NS_LOG_UNCOND ("Hello Simulator");
-}
--- a/examples/icmpv6-redirect.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Strasbourg University
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: David Gross <david.gross@eturs.u-strasbg.fr>
- */
-
-// Network topology
-//
-// STA2
-// |
-// |
-// R1 R2
-// | |
-// | |
-// ------------
-// |
-// |
-// STA 1
-//
-// - Initial configuration :
-// - STA1 default route : R1
-// - R1 static route to STA2 : R2
-// - STA2 default route : R2
-// - STA1 send Echo Request to STA2 using its default route to R1
-// - R1 receive Echo Request from STA1, and forward it to R2
-// - R1 send an ICMPv6 Redirection to STA1 with Target STA2 and Destination R2
-// - Next Echo Request from STA1 to STA2 are directly sent to R2
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-#include "ns3/ipv6-routing-table-entry.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("Icmpv6RedirectExample");
-
-/**
- * \class StackHelper
- * \brief Helper to set or get some IPv6 information about nodes.
- */
-class StackHelper
-{
- public:
- /**
- * \brief Print the routing table.
- * \param n the node
- */
- inline void PrintRoutingTable (Ptr<Node>& n)
- {
- Ptr<Ipv6StaticRouting> routing = 0;
- Ipv6StaticRoutingHelper routingHelper;
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
- uint32_t nbRoutes = 0;
- Ipv6RoutingTableEntry route;
-
- routing = routingHelper.GetStaticRouting (ipv6);
-
- std::cout << "Routing table of " << n << " : " << std::endl;
- std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
-
- nbRoutes = routing->GetNRoutes ();
- for(uint32_t i = 0 ; i < nbRoutes ; i++)
- {
- route = routing->GetRoute (i);
- std::cout << route.GetDest () << "\t"
- << route.GetGateway () << "\t"
- << route.GetInterface () << "\t"
- << route.GetPrefixToUse () << "\t"
- << std::endl;
- }
- }
-
- /**
- * \brief Add an host route.
- * \param n node
- * \param dst destination address
- * \param nextHop next hop for destination
- * \param interface output interface
- */
- inline void AddHostRouteTo (Ptr<Node>& n, Ipv6Address dst, Ipv6Address nextHop, uint32_t interface)
- {
- Ptr<Ipv6StaticRouting> routing = 0;
- Ipv6StaticRoutingHelper routingHelper;
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
-
- routing = routingHelper.GetStaticRouting (ipv6);
- routing->AddHostRouteTo (dst, nextHop, interface);
- }
-};
-
-
-int main (int argc, char **argv)
-{
-#if 0
- LogComponentEnable ("Icmpv6RedirectExample", LOG_LEVEL_INFO);
- LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_INFO);
- LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
- LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
- LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
- LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- Ptr<Node> sta1 = CreateObject<Node> ();
- Ptr<Node> r1 = CreateObject<Node> ();
- Ptr<Node> r2 = CreateObject<Node> ();
- Ptr<Node> sta2 = CreateObject<Node> ();
- NodeContainer net1(sta1, r1, r2);
- NodeContainer net2(r2, sta2);
- NodeContainer all(sta1, r1, r2, sta2);
-
- StackHelper stackHelper;
-
- InternetStackHelper internetv6;
- internetv6.Install (all);
-
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue(5000000));
- csma.SetChannelAttribute ("Delay", TimeValue(MilliSeconds (2)));
- NetDeviceContainer ndc1 = csma.Install (net1);
- NetDeviceContainer ndc2 = csma.Install (net2);
-
- NS_LOG_INFO ("Assign IPv6 Addresses.");
- Ipv6AddressHelper ipv6;
-
- ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
- Ipv6InterfaceContainer iic1 = ipv6.Assign (ndc1);
- iic1.SetRouter (2, true);
- iic1.SetRouter (1, true);
-
- ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
- Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
- iic2.SetRouter (0, true);
-
- stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 1), iic1.GetInterfaceIndex (1));
-
- Simulator::Schedule(Seconds(0.0), &StackHelper::PrintRoutingTable, &stackHelper, r1);
- Simulator::Schedule(Seconds(3.0), &StackHelper::PrintRoutingTable, &stackHelper, sta1);
-
- NS_LOG_INFO ("Create Applications.");
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 5;
- Time interPacketInterval = Seconds (1.);
- Ping6Helper ping6;
-
- ping6.SetLocal (iic1.GetAddress(0, 1));
- ping6.SetRemote (iic2.GetAddress(1, 1));
- ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- ping6.SetAttribute ("Interval", TimeValue(interPacketInterval));
- ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
- ApplicationContainer apps = ping6.Install (sta1);
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("icmpv6-redirect.tr");
- CsmaHelper::EnablePcapAll ("icmpv6-redirect", true);
- CsmaHelper::EnableAsciiAll (ascii);
-
- /* Now, do the actual simulation. */
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/icmpv6-redirect.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 Strasbourg University
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: David Gross <david.gross@eturs.u-strasbg.fr>
+ */
+
+// Network topology
+//
+// STA2
+// |
+// |
+// R1 R2
+// | |
+// | |
+// ------------
+// |
+// |
+// STA 1
+//
+// - Initial configuration :
+// - STA1 default route : R1
+// - R1 static route to STA2 : R2
+// - STA2 default route : R2
+// - STA1 send Echo Request to STA2 using its default route to R1
+// - R1 receive Echo Request from STA1, and forward it to R2
+// - R1 send an ICMPv6 Redirection to STA1 with Target STA2 and Destination R2
+// - Next Echo Request from STA1 to STA2 are directly sent to R2
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+#include "ns3/ipv6-routing-table-entry.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("Icmpv6RedirectExample");
+
+/**
+ * \class StackHelper
+ * \brief Helper to set or get some IPv6 information about nodes.
+ */
+class StackHelper
+{
+ public:
+ /**
+ * \brief Print the routing table.
+ * \param n the node
+ */
+ inline void PrintRoutingTable (Ptr<Node>& n)
+ {
+ Ptr<Ipv6StaticRouting> routing = 0;
+ Ipv6StaticRoutingHelper routingHelper;
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+ uint32_t nbRoutes = 0;
+ Ipv6RoutingTableEntry route;
+
+ routing = routingHelper.GetStaticRouting (ipv6);
+
+ std::cout << "Routing table of " << n << " : " << std::endl;
+ std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
+
+ nbRoutes = routing->GetNRoutes ();
+ for(uint32_t i = 0 ; i < nbRoutes ; i++)
+ {
+ route = routing->GetRoute (i);
+ std::cout << route.GetDest () << "\t"
+ << route.GetGateway () << "\t"
+ << route.GetInterface () << "\t"
+ << route.GetPrefixToUse () << "\t"
+ << std::endl;
+ }
+ }
+
+ /**
+ * \brief Add an host route.
+ * \param n node
+ * \param dst destination address
+ * \param nextHop next hop for destination
+ * \param interface output interface
+ */
+ inline void AddHostRouteTo (Ptr<Node>& n, Ipv6Address dst, Ipv6Address nextHop, uint32_t interface)
+ {
+ Ptr<Ipv6StaticRouting> routing = 0;
+ Ipv6StaticRoutingHelper routingHelper;
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+
+ routing = routingHelper.GetStaticRouting (ipv6);
+ routing->AddHostRouteTo (dst, nextHop, interface);
+ }
+};
+
+
+int main (int argc, char **argv)
+{
+#if 0
+ LogComponentEnable ("Icmpv6RedirectExample", LOG_LEVEL_INFO);
+ LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_INFO);
+ LogComponentEnable("Ipv6L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv6StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable("Ipv6Interface", LOG_LEVEL_ALL);
+ LogComponentEnable("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable("NdiscCache", LOG_LEVEL_ALL);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ Ptr<Node> sta1 = CreateObject<Node> ();
+ Ptr<Node> r1 = CreateObject<Node> ();
+ Ptr<Node> r2 = CreateObject<Node> ();
+ Ptr<Node> sta2 = CreateObject<Node> ();
+ NodeContainer net1(sta1, r1, r2);
+ NodeContainer net2(r2, sta2);
+ NodeContainer all(sta1, r1, r2, sta2);
+
+ StackHelper stackHelper;
+
+ InternetStackHelper internetv6;
+ internetv6.Install (all);
+
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue(5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue(MilliSeconds (2)));
+ NetDeviceContainer ndc1 = csma.Install (net1);
+ NetDeviceContainer ndc2 = csma.Install (net2);
+
+ NS_LOG_INFO ("Assign IPv6 Addresses.");
+ Ipv6AddressHelper ipv6;
+
+ ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
+ Ipv6InterfaceContainer iic1 = ipv6.Assign (ndc1);
+ iic1.SetRouter (2, true);
+ iic1.SetRouter (1, true);
+
+ ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
+ Ipv6InterfaceContainer iic2 = ipv6.Assign (ndc2);
+ iic2.SetRouter (0, true);
+
+ stackHelper.AddHostRouteTo (r1, iic2.GetAddress (1, 1), iic1.GetAddress (2, 1), iic1.GetInterfaceIndex (1));
+
+ Simulator::Schedule(Seconds(0.0), &StackHelper::PrintRoutingTable, &stackHelper, r1);
+ Simulator::Schedule(Seconds(3.0), &StackHelper::PrintRoutingTable, &stackHelper, sta1);
+
+ NS_LOG_INFO ("Create Applications.");
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 5;
+ Time interPacketInterval = Seconds (1.);
+ Ping6Helper ping6;
+
+ ping6.SetLocal (iic1.GetAddress(0, 1));
+ ping6.SetRemote (iic2.GetAddress(1, 1));
+ ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ ping6.SetAttribute ("Interval", TimeValue(interPacketInterval));
+ ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ ApplicationContainer apps = ping6.Install (sta1);
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("icmpv6-redirect.tr");
+ CsmaHelper::EnablePcapAll ("icmpv6-redirect", true);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ /* Now, do the actual simulation. */
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/ping6.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008-2009 Strasbourg University
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
+ */
+
+// Network topology
+//
+// n0 n1
+// | |
+// =================
+// LAN
+//
+// - ICMPv6 echo request flows from n0 to n1 and back with ICMPv6 echo reply
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "ping6.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("Ping6Example");
+
+int main (int argc, char **argv)
+{
+#if 0
+ LogComponentEnable ("Ping6Example", LOG_LEVEL_INFO);
+ LogComponentEnable ("Ipv6EndPointDemux", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6ListRouting", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
+ LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
+ LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer n;
+ n.Create (4);
+
+ /* Install IPv4/IPv6 stack */
+ InternetStackHelper internetv6;
+ internetv6.SetIpv4StackInstall (false);
+ internetv6.Install (n);
+
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer d = csma.Install (n);
+
+ Ipv6AddressHelper ipv6;
+ NS_LOG_INFO ("Assign IPv6 Addresses.");
+ Ipv6InterfaceContainer i = ipv6.Assign (d);
+
+ NS_LOG_INFO ("Create Applications.");
+
+ /* Create a Ping6 application to send ICMPv6 echo request from node zero to
+ * all-nodes (ff02::1).
+ */
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 5;
+ Time interPacketInterval = Seconds (1.);
+ Ping6Helper ping6;
+
+/*
+ ping6.SetLocal (i.GetAddress (0, 1));
+ ping6.SetRemote (i.GetAddress (1, 1));
+*/
+ ping6.SetIfIndex (i.GetInterfaceIndex (0));
+ ping6.SetRemote (Ipv6Address::GetAllNodesMulticast ());
+
+ ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ ApplicationContainer apps = ping6.Install (n.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("ping6.tr");
+ CsmaHelper::EnablePcapAll (std::string ("ping6"), true);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/radvd-two-prefix.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,221 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 Strasbourg University
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: David Gross <gdavid.devel@gmail.com>
+ * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
+ */
+
+// Network topology
+// //
+// // n0 R n1
+// // | _ |
+// // ====|_|====
+// // router
+// // - R sends RA to n0's subnet (2001:1::/64 and 2001:ABCD::/64);
+// // - R interface to n0 has two addresses with following prefixes 2001:1::/64 and 2001:ABCD::/64;
+// // - R sends RA to n1's subnet (2001:2::/64);
+// // - n0 ping6 n1.
+// //
+// // - Tracing of queues and packet receptions to file "radvd-two-prefix.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+#include "ns3/ipv6-routing-table-entry.h"
+#include "ns3/radvd.h"
+#include "ns3/radvd-interface.h"
+#include "ns3/radvd-prefix.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("RadvdExample");
+
+/**
+ * \class StackHelper
+ * \brief Helper to set or get some IPv6 information about nodes.
+ */
+class StackHelper
+{
+ public:
+ /**
+ * \brief Add an address to a IPv6 node.
+ * \param n node
+ * \param interface interface index
+ * \param address IPv6 address to add
+ */
+ inline void AddAddress (Ptr<Node>& n, uint32_t interface, Ipv6Address address)
+ {
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+ ipv6->AddAddress (interface, address);
+ }
+
+ /**
+ * \brief Print the routing table.
+ * \param n the node
+ */
+ inline void PrintRoutingTable (Ptr<Node>& n)
+ {
+ Ptr<Ipv6StaticRouting> routing = 0;
+ Ipv6StaticRoutingHelper routingHelper;
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+ uint32_t nbRoutes = 0;
+ Ipv6RoutingTableEntry route;
+
+ routing = routingHelper.GetStaticRouting (ipv6);
+
+ std::cout << "Routing table of " << n << " : " << std::endl;
+ std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
+
+ nbRoutes = routing->GetNRoutes ();
+ for (uint32_t i = 0 ; i < nbRoutes ; i++)
+ {
+ route = routing->GetRoute (i);
+ std::cout << route.GetDest () << "\t"
+ << route.GetGateway () << "\t"
+ << route.GetInterface () << "\t"
+ << route.GetPrefixToUse () << "\t"
+ << std::endl;
+ }
+ }
+};
+
+int main (int argc, char** argv)
+{
+#if 0
+ LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
+ LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
+ LogComponentEnable ("RadvdApplication", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ Ptr<Node> n0 = CreateObject<Node> ();
+ Ptr<Node> r = CreateObject<Node> ();
+ Ptr<Node> n1 = CreateObject<Node> ();
+
+ NodeContainer net1 (n0, r);
+ NodeContainer net2 (r, n1);
+ NodeContainer all (n0, r, n1);
+ StackHelper stackHelper;
+
+ NS_LOG_INFO ("Create IPv6 Internet Stack");
+ InternetStackHelper internetv6;
+ internetv6.Install (all);
+
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer d1 = csma.Install (net1); /* n0 - R */
+ NetDeviceContainer d2 = csma.Install (net2); /* R - n1 */
+
+ NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
+ Ipv6AddressHelper ipv6;
+
+ /* first subnet */
+ ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
+ NetDeviceContainer tmp;
+ tmp.Add (d1.Get (0)); /* n0 */
+ Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (tmp); /* n0 interface */
+
+ NetDeviceContainer tmp2;
+ tmp2.Add (d1.Get (1)); /* R */
+ Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
+ iicr1.SetRouter (0, true);
+ iic1.Add (iicr1);
+
+ /* add another IPv6 address for second prefix advertised on first subnet */
+ stackHelper.AddAddress (r, iic1.GetInterfaceIndex (1), Ipv6Address ("2001:ABCD::2"));
+
+ /* second subnet R - n1 */
+ ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
+ NetDeviceContainer tmp3;
+ tmp3.Add (d2.Get (0)); /* R */
+ Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
+ iicr2.SetRouter (0, true);
+
+ NetDeviceContainer tmp4;
+ tmp4.Add (d2.Get (1)); /* n1 */
+ Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (tmp4);
+ iic2.Add (iicr2);
+
+ /* radvd configuration */
+ Ipv6Address prefix ("2001:ABCD::0"); /* create the prefix */
+ Ipv6Address prefixBis ("2001:1::0"); /* create the prefix */
+ Ipv6Address prefix2 ("2001:2::0"); /* create the prefix */
+ uint32_t indexRouter = iic1.GetInterfaceIndex (1); /* R interface (n0 - R) */
+ uint32_t indexRouter2 = iic2.GetInterfaceIndex (1); /* R interface (R - n1) */
+ Ptr<Radvd> radvd = CreateObject<Radvd> ();
+ Ptr<RadvdInterface> routerInterface = Create<RadvdInterface> (indexRouter, 2000, 1000);
+ Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix> (prefix, 64, 3, 5);
+ Ptr<RadvdPrefix> routerPrefixBis = Create<RadvdPrefix> (prefixBis, 64, 3, 5);
+ Ptr<RadvdInterface> routerInterface2 = Create<RadvdInterface> (indexRouter2, 2000, 1000);
+ Ptr<RadvdPrefix> routerPrefix2 = Create<RadvdPrefix> (prefix2, 64, 3, 5);
+
+ /* first interface advertise two prefixes (2001:1::/64 and 2001:ABCD::/64) */
+ /* prefix is added in the inverse order in packet */
+ routerInterface->AddPrefix (routerPrefix);
+ routerInterface->AddPrefix (routerPrefixBis);
+ routerInterface2->AddPrefix (routerPrefix2);
+ radvd->AddConfiguration (routerInterface);
+ radvd->AddConfiguration (routerInterface2);
+
+ r->AddApplication (radvd);
+ radvd->Start (Seconds (1.0));
+ radvd->Stop (Seconds (2.0));
+
+ /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 8;
+ Time interPacketInterval = Seconds (1.);
+ Ping6Helper ping6;
+
+ /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
+ ping6.SetRemote (Ipv6Address ("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
+ ping6.SetIfIndex (iic1.GetInterfaceIndex (0));
+
+ ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ ApplicationContainer apps = ping6.Install (net1.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (9.0));
+
+ /* RA should be received, two prefixes + routes + default route should be present */
+ Simulator::Schedule (Seconds (2.0), &StackHelper::PrintRoutingTable, &stackHelper, n0);
+ /* at the end, RA addresses and routes should be cleared */
+ Simulator::Schedule (Seconds (10.0), &StackHelper::PrintRoutingTable, &stackHelper, n0);
+
+ std::ofstream ascii;
+ ascii.open ("radvd-two-prefix.tr");
+ CsmaHelper::EnablePcapAll (std::string ("radvd-two-prefix"), true);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/radvd.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,156 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 Strasbourg University
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: David Gross <gdavid.devel@gmail.com>
+ * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
+ */
+
+// Network topology
+// //
+// // n0 R n1
+// // | _ |
+// // ====|_|====
+// // router
+// // - R sends RA to n0's subnet (2001:1::/64);
+// // - R sends RA to n1's subnet (2001:2::/64);
+// // - n0 ping6 n1.
+// //
+// // - Tracing of queues and packet receptions to file "radvd.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+#include "ns3/radvd.h"
+#include "ns3/radvd-interface.h"
+#include "ns3/radvd-prefix.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("RadvdExample");
+
+int main (int argc, char** argv)
+{
+#if 0
+ LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
+ LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
+ LogComponentEnable ("RadvdApplication", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ Ptr<Node> n0 = CreateObject<Node> ();
+ Ptr<Node> r = CreateObject<Node> ();
+ Ptr<Node> n1 = CreateObject<Node> ();
+
+ NodeContainer net1 (n0, r);
+ NodeContainer net2 (r, n1);
+ NodeContainer all (n0, r, n1);
+
+ NS_LOG_INFO ("Create IPv6 Internet Stack");
+ InternetStackHelper internetv6;
+ internetv6.Install (all);
+
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer d1 = csma.Install (net1); /* n0 - R */
+ NetDeviceContainer d2 = csma.Install (net2); /* R - n1 */
+
+ NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
+ Ipv6AddressHelper ipv6;
+
+ /* first subnet */
+ ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
+ NetDeviceContainer tmp;
+ tmp.Add (d1.Get (0)); /* n0 */
+ Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (tmp); /* n0 interface */
+
+ NetDeviceContainer tmp2;
+ tmp2.Add (d1.Get (1)); /* R */
+ Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
+ iicr1.SetRouter (0, true);
+ iic1.Add (iicr1);
+
+ /* second subnet R - n1 */
+ ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
+ NetDeviceContainer tmp3;
+ tmp3.Add (d2.Get (0)); /* R */
+ Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
+ iicr2.SetRouter (0, true);
+
+ NetDeviceContainer tmp4;
+ tmp4.Add (d2.Get (1)); /* n1 */
+ Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (tmp4);
+ iic2.Add (iicr2);
+
+ /* radvd configuration */
+ Ipv6Address prefix ("2001:1::0"); /* create the prefix */
+ Ipv6Address prefix2 ("2001:2::0"); /* create the prefix */
+ uint32_t indexRouter = iic1.GetInterfaceIndex (1); /* R interface (n0 - R) */
+ uint32_t indexRouter2 = iic2.GetInterfaceIndex (1); /* R interface (R - n1) */
+ Ptr<Radvd> radvd = CreateObject<Radvd> ();
+ Ptr<RadvdInterface> routerInterface = Create<RadvdInterface> (indexRouter, 5000, 1000);
+ Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix> (prefix, 64, 3, 5);
+ Ptr<RadvdInterface> routerInterface2 = Create<RadvdInterface> (indexRouter2, 5000, 1000);
+ Ptr<RadvdPrefix> routerPrefix2 = Create<RadvdPrefix> (prefix2, 64, 3, 5);
+
+ routerInterface->AddPrefix (routerPrefix);
+ routerInterface2->AddPrefix (routerPrefix2);
+ radvd->AddConfiguration (routerInterface);
+ radvd->AddConfiguration (routerInterface2);
+
+ r->AddApplication (radvd);
+ radvd->Start (Seconds (1.0));
+ radvd->Stop (Seconds (10.0));
+
+ /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 5;
+ Time interPacketInterval = Seconds (1.);
+ Ping6Helper ping6;
+
+ /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
+ ping6.SetRemote (Ipv6Address ("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
+ ping6.SetIfIndex (iic1.GetInterfaceIndex (0));
+
+ ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ ApplicationContainer apps = ping6.Install (net1.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (7.0));
+
+ std::ofstream ascii;
+ ascii.open ("radvd.tr");
+ CsmaHelper::EnablePcapAll (std::string ("radvd"), true);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/test-ipv6.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008 Louis Pasteur University / Telecom Bretagne
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Angelos Chatzipapas <Angelos.CHATZIPAPAS@enst-bretagne.fr> /
+ * <chatzipa@ceid.upatras.gr>
+ */
+
+#include "ns3/log.h"
+#include "ns3/ipv6-address.h"
+#include "ns3/node.h"
+#include "ns3/mac48-address.h"
+
+NS_LOG_COMPONENT_DEFINE ("TestIpv6");
+
+using namespace ns3;
+
+int
+main (int argc, char *argv[])
+{
+ LogComponentEnable ("TestIpv6", LOG_LEVEL_ALL);
+
+ NS_LOG_INFO ("Test Ipv6");
+
+ Mac48Address m_addresses[10];
+
+ m_addresses[0] = ("00:00:00:00:00:01");
+ m_addresses[1] = ("00:00:00:00:00:02");
+ m_addresses[2] = ("00:00:00:00:00:03");
+ m_addresses[3] = ("00:00:00:00:00:04");
+ m_addresses[4] = ("00:00:00:00:00:05");
+ m_addresses[5] = ("00:00:00:00:00:06");
+ m_addresses[6] = ("00:00:00:00:00:07");
+ m_addresses[7] = ("00:00:00:00:00:08");
+ m_addresses[8] = ("00:00:00:00:00:09");
+ m_addresses[9] = ("00:00:00:00:00:10");
+
+ Ipv6Address prefix1 ("2001:1::");
+ NS_LOG_INFO ("prefix = " << prefix1);
+ for (uint32_t i = 0; i < 10 ; ++i)
+ {
+ NS_LOG_INFO ("address = " << m_addresses[i]);
+ Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix1);
+ NS_LOG_INFO ("address = " << ipv6address);
+ }
+
+ Ipv6Address prefix2 ("2002:1:1::");
+
+ NS_LOG_INFO ("prefix = " << prefix2);
+ for (uint32_t i = 0; i < 10 ; ++i)
+ {
+ Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix2);
+ NS_LOG_INFO ("address = " << ipv6address);
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/ipv6/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,17 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('icmpv6-redirect', ['csma', 'internet-stack'])
+ obj.source = 'icmpv6-redirect.cc'
+
+ obj = bld.create_ns3_program('ping6', ['csma', 'internet-stack'])
+ obj.source = 'ping6.cc'
+
+ obj = bld.create_ns3_program('radvd', ['csma', 'internet-stack'])
+ obj.source = 'radvd.cc'
+
+ obj = bld.create_ns3_program('radvd-two-prefix', ['csma', 'internet-stack'])
+ obj.source = 'radvd-two-prefix.cc'
+
+ obj = bld.create_ns3_program('test-ipv6', ['point-to-point', 'internet-stack'])
+ obj.source = 'test-ipv6.cc'
--- a/examples/mesh.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,251 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008,2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Kirill Andreev <andreev@iitp.ru>
- *
- *
- * By default this script creates m_xSize * m_ySize square grid topology with
- * IEEE802.11s stack installed at each node with peering management
- * and HWMP protocol.
- * The side of the square cell is defined by m_step parameter.
- * When topology is created, UDP ping is installed to opposite corners
- * by diagonals. packet size of the UDP ping and interval between two
- * successive packets is configurable.
- *
- * m_xSize * step
- * |<--------->|
- * step
- * |<--->|
- * * --- * --- * <---Ping sink _
- * | \ | / | ^
- * | \ | / | |
- * * --- * --- * m_ySize * step |
- * | / | \ | |
- * | / | \ | |
- * * --- * --- * _
- * ^ Ping source
- *
- * See also MeshTest::Configure to read more about configurable
- * parameters.
- */
-
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/global-routing-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/mesh-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/mesh-helper.h"
-
-#include <iostream>
-#include <sstream>
-#include <fstream>
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
-class MeshTest
-{
- public:
- /// Init test
- MeshTest ();
- /// Configure test from command line arguments
- void Configure (int argc, char ** argv);
- /// Run test
- int Run ();
- private:
- int m_xSize;
- int m_ySize;
- double m_step;
- double m_randomStart;
- double m_totalTime;
- double m_packetInterval;
- uint16_t m_packetSize;
- uint32_t m_nIfaces;
- bool m_chan;
- bool m_pcap;
- std::string m_stack;
- std::string m_root;
- /// List of network nodes
- NodeContainer nodes;
- /// List of all mesh point devices
- NetDeviceContainer meshDevices;
- //Addresses of interfaces:
- Ipv4InterfaceContainer interfaces;
- // MeshHelper. Report is not static methods
- MeshHelper mesh;
- private:
- /// Create nodes and setup their mobility
- void CreateNodes ();
- /// Install internet m_stack on nodes
- void InstallInternetStack ();
- /// Install applications
- void InstallApplication ();
- /// Print mesh devices diagnostics
- void Report ();
-};
-MeshTest::MeshTest () :
- m_xSize (3),
- m_ySize (3),
- m_step (100.0),
- m_randomStart (0.1),
- m_totalTime (100.0),
- m_packetInterval (0.1),
- m_packetSize (1024),
- m_nIfaces (1),
- m_chan (true),
- m_pcap (false),
- m_stack ("ns3::Dot11sStack"),
- m_root ("ff:ff:ff:ff:ff:ff")
-{
-}
-void
-MeshTest::Configure (int argc, char *argv[])
-{
- CommandLine cmd;
- cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", m_xSize);
- cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize);
- cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]", m_step);
- /*
- * As soon as starting node means that it sends a beacon,
- * simultaneous start is not good.
- */
- cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", m_randomStart);
- cmd.AddValue ("time", "Simulation time, seconds [100 s]", m_totalTime);
- cmd.AddValue ("packet-interval", "Interval between packets in UDP ping, seconds [0.001 s]", m_packetInterval);
- cmd.AddValue ("packet-size", "Size of packets in UDP ping", m_packetSize);
- cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh point. [1]", m_nIfaces);
- cmd.AddValue ("channels", "Use different frequency channels for different interfaces. [0]", m_chan);
- cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", m_pcap);
- cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default", m_stack);
- cmd.AddValue ("root", "Mac address of root mesh point in HWMP", m_root);
-
- cmd.Parse (argc, argv);
- NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize);
- NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
-}
-void
-MeshTest::CreateNodes ()
-{
- /*
- * Create m_ySize*m_xSize stations to form a grid topology
- */
- nodes.Create (m_ySize*m_xSize);
- // Configure YansWifiChannel
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
- /*
- * Create mesh helper and set stack installer to it
- * Stack installer creates all needed protocols and install them to
- * mesh point device
- */
- mesh = MeshHelper::Default ();
- mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
- if (m_chan)
- {
- mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
- }
- else
- {
- mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
- }
- mesh.SetMacType ("RandomStart", TimeValue (Seconds(m_randomStart)));
- // Set number of interfaces - default is single-interface mesh point
- mesh.SetNumberOfInterfaces (m_nIfaces);
- // Install protocols and return container if MeshPointDevices
- meshDevices = mesh.Install (wifiPhy, nodes);
- // Setup mobility - static grid topology
- MobilityHelper mobility;
- mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (0.0),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (m_step),
- "DeltaY", DoubleValue (m_step),
- "GridWidth", UintegerValue (m_xSize),
- "LayoutType", StringValue ("RowFirst"));
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.Install (nodes);
- if (m_pcap)
- wifiPhy.EnablePcapAll (std::string ("mp-"));
-}
-void
-MeshTest::InstallInternetStack ()
-{
- InternetStackHelper internetStack;
- internetStack.Install (nodes);
- Ipv4AddressHelper address;
- address.SetBase ("10.1.1.0", "255.255.255.0");
- interfaces = address.Assign (meshDevices);
-}
-void
-MeshTest::InstallApplication ()
-{
- UdpEchoServerHelper echoServer (9);
- ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
- serverApps.Start (Seconds (0.0));
- serverApps.Stop (Seconds (m_totalTime));
- UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(m_totalTime*(1/m_packetInterval))));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (m_packetInterval)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
- ApplicationContainer clientApps = echoClient.Install (nodes.Get (m_xSize*m_ySize-1));
- clientApps.Start (Seconds (0.0));
- clientApps.Stop (Seconds (m_totalTime));
-}
-int
-MeshTest::Run ()
-{
- CreateNodes ();
- InstallInternetStack ();
- InstallApplication ();
- Simulator::Schedule (Seconds(m_totalTime), & MeshTest::Report, this);
- Simulator::Stop (Seconds (m_totalTime));
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
-void
-MeshTest::Report ()
-{
- unsigned n (0);
- for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.End (); ++i, ++n)
- {
- std::ostringstream os;
- os << "mp-report-" << n << ".xml";
- std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os.str () << "\n";
- std::ofstream of;
- of.open (os.str().c_str());
- if (! of.is_open ())
- {
- std::cerr << "Error: Can't open file " << os.str() << "\n";
- return;
- }
- mesh.Report (*i, of);
- of.close ();
- }
-}
-int
-main (int argc, char *argv[])
-{
- MeshTest t;
- t.Configure (argc, argv);
- return t.Run();
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mesh/mesh.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,251 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008,2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Kirill Andreev <andreev@iitp.ru>
+ *
+ *
+ * By default this script creates m_xSize * m_ySize square grid topology with
+ * IEEE802.11s stack installed at each node with peering management
+ * and HWMP protocol.
+ * The side of the square cell is defined by m_step parameter.
+ * When topology is created, UDP ping is installed to opposite corners
+ * by diagonals. packet size of the UDP ping and interval between two
+ * successive packets is configurable.
+ *
+ * m_xSize * step
+ * |<--------->|
+ * step
+ * |<--->|
+ * * --- * --- * <---Ping sink _
+ * | \ | / | ^
+ * | \ | / | |
+ * * --- * --- * m_ySize * step |
+ * | / | \ | |
+ * | / | \ | |
+ * * --- * --- * _
+ * ^ Ping source
+ *
+ * See also MeshTest::Configure to read more about configurable
+ * parameters.
+ */
+
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/global-routing-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mesh-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/mesh-helper.h"
+
+#include <iostream>
+#include <sstream>
+#include <fstream>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TestMeshScript");
+class MeshTest
+{
+ public:
+ /// Init test
+ MeshTest ();
+ /// Configure test from command line arguments
+ void Configure (int argc, char ** argv);
+ /// Run test
+ int Run ();
+ private:
+ int m_xSize;
+ int m_ySize;
+ double m_step;
+ double m_randomStart;
+ double m_totalTime;
+ double m_packetInterval;
+ uint16_t m_packetSize;
+ uint32_t m_nIfaces;
+ bool m_chan;
+ bool m_pcap;
+ std::string m_stack;
+ std::string m_root;
+ /// List of network nodes
+ NodeContainer nodes;
+ /// List of all mesh point devices
+ NetDeviceContainer meshDevices;
+ //Addresses of interfaces:
+ Ipv4InterfaceContainer interfaces;
+ // MeshHelper. Report is not static methods
+ MeshHelper mesh;
+ private:
+ /// Create nodes and setup their mobility
+ void CreateNodes ();
+ /// Install internet m_stack on nodes
+ void InstallInternetStack ();
+ /// Install applications
+ void InstallApplication ();
+ /// Print mesh devices diagnostics
+ void Report ();
+};
+MeshTest::MeshTest () :
+ m_xSize (3),
+ m_ySize (3),
+ m_step (100.0),
+ m_randomStart (0.1),
+ m_totalTime (100.0),
+ m_packetInterval (0.1),
+ m_packetSize (1024),
+ m_nIfaces (1),
+ m_chan (true),
+ m_pcap (false),
+ m_stack ("ns3::Dot11sStack"),
+ m_root ("ff:ff:ff:ff:ff:ff")
+{
+}
+void
+MeshTest::Configure (int argc, char *argv[])
+{
+ CommandLine cmd;
+ cmd.AddValue ("x-size", "Number of nodes in a row grid. [6]", m_xSize);
+ cmd.AddValue ("y-size", "Number of rows in a grid. [6]", m_ySize);
+ cmd.AddValue ("step", "Size of edge in our grid, meters. [100 m]", m_step);
+ /*
+ * As soon as starting node means that it sends a beacon,
+ * simultaneous start is not good.
+ */
+ cmd.AddValue ("start", "Maximum random start delay, seconds. [0.1 s]", m_randomStart);
+ cmd.AddValue ("time", "Simulation time, seconds [100 s]", m_totalTime);
+ cmd.AddValue ("packet-interval", "Interval between packets in UDP ping, seconds [0.001 s]", m_packetInterval);
+ cmd.AddValue ("packet-size", "Size of packets in UDP ping", m_packetSize);
+ cmd.AddValue ("interfaces", "Number of radio interfaces used by each mesh point. [1]", m_nIfaces);
+ cmd.AddValue ("channels", "Use different frequency channels for different interfaces. [0]", m_chan);
+ cmd.AddValue ("pcap", "Enable PCAP traces on interfaces. [0]", m_pcap);
+ cmd.AddValue ("stack", "Type of protocol stack. ns3::Dot11sStack by default", m_stack);
+ cmd.AddValue ("root", "Mac address of root mesh point in HWMP", m_root);
+
+ cmd.Parse (argc, argv);
+ NS_LOG_DEBUG ("Grid:" << m_xSize << "*" << m_ySize);
+ NS_LOG_DEBUG ("Simulation time: " << m_totalTime << " s");
+}
+void
+MeshTest::CreateNodes ()
+{
+ /*
+ * Create m_ySize*m_xSize stations to form a grid topology
+ */
+ nodes.Create (m_ySize*m_xSize);
+ // Configure YansWifiChannel
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ /*
+ * Create mesh helper and set stack installer to it
+ * Stack installer creates all needed protocols and install them to
+ * mesh point device
+ */
+ mesh = MeshHelper::Default ();
+ mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
+ if (m_chan)
+ {
+ mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
+ }
+ else
+ {
+ mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
+ }
+ mesh.SetMacType ("RandomStart", TimeValue (Seconds(m_randomStart)));
+ // Set number of interfaces - default is single-interface mesh point
+ mesh.SetNumberOfInterfaces (m_nIfaces);
+ // Install protocols and return container if MeshPointDevices
+ meshDevices = mesh.Install (wifiPhy, nodes);
+ // Setup mobility - static grid topology
+ MobilityHelper mobility;
+ mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (0.0),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (m_step),
+ "DeltaY", DoubleValue (m_step),
+ "GridWidth", UintegerValue (m_xSize),
+ "LayoutType", StringValue ("RowFirst"));
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (nodes);
+ if (m_pcap)
+ wifiPhy.EnablePcapAll (std::string ("mp-"));
+}
+void
+MeshTest::InstallInternetStack ()
+{
+ InternetStackHelper internetStack;
+ internetStack.Install (nodes);
+ Ipv4AddressHelper address;
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+ interfaces = address.Assign (meshDevices);
+}
+void
+MeshTest::InstallApplication ()
+{
+ UdpEchoServerHelper echoServer (9);
+ ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
+ serverApps.Start (Seconds (0.0));
+ serverApps.Stop (Seconds (m_totalTime));
+ UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(m_totalTime*(1/m_packetInterval))));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (m_packetInterval)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
+ ApplicationContainer clientApps = echoClient.Install (nodes.Get (m_xSize*m_ySize-1));
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (m_totalTime));
+}
+int
+MeshTest::Run ()
+{
+ CreateNodes ();
+ InstallInternetStack ();
+ InstallApplication ();
+ Simulator::Schedule (Seconds(m_totalTime), & MeshTest::Report, this);
+ Simulator::Stop (Seconds (m_totalTime));
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
+void
+MeshTest::Report ()
+{
+ unsigned n (0);
+ for (NetDeviceContainer::Iterator i = meshDevices.Begin (); i != meshDevices.End (); ++i, ++n)
+ {
+ std::ostringstream os;
+ os << "mp-report-" << n << ".xml";
+ std::cerr << "Printing mesh point device #" << n << " diagnostics to " << os.str () << "\n";
+ std::ofstream of;
+ of.open (os.str().c_str());
+ if (! of.is_open ())
+ {
+ std::cerr << "Error: Can't open file " << os.str() << "\n";
+ return;
+ }
+ mesh.Report (*i, of);
+ of.close ();
+ }
+}
+int
+main (int argc, char *argv[])
+{
+ MeshTest t;
+ t.Configure (argc, argv);
+ return t.Run();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mesh/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mesh/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,5 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('mesh', ['core', 'simulator', 'mobility', 'wifi', 'mesh'])
+ obj.source = 'mesh.cc'
--- a/examples/mixed-global-routing.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-// This script exercises global routing code in a mixed point-to-point
-// and csma/cd environment
-//
-// Network topology
-//
-// n0
-// \ p-p
-// \ (shared csma/cd)
-// n2 -------------------------n3
-// / | |
-// / p-p n4 n5 ---------- n6
-// n1 p-p
-//
-// - CBR/UDP flows from n0 to n6
-// - Tracing of queues and packet receptions to file "mixed-global-routing.tr"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample");
-
-int
-main (int argc, char *argv[])
-{
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
-
- // Allow the user to override any of the defaults and the above
- // Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (7);
- NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
- NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
- NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer d5d6 = p2p.Install (n5n6);
-
- // We create the channels first without any IP addressing information
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
- csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d2345 = csma.Install (n2345);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
-
- ipv4.SetBase ("10.250.1.0", "255.255.255.0");
- ipv4.Assign (d2345);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- InetSocketAddress (i5i6.GetAddress (1), port));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", StringValue ("300bps"));
- onoff.SetAttribute ("PacketSize", UintegerValue (50));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("mixed-global-routing.tr");
- PointToPointHelper::EnablePcapAll ("mixed-global-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
- CsmaHelper::EnablePcapAll ("mixed-global-routing", false);
- CsmaHelper::EnableAsciiAll (ascii);
-
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/mixed-wireless.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,418 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-//
-// This ns-3 example demonstrates the use of helper functions to ease
-// the construction of simulation scenarios.
-//
-// The simulation topology consists of a mixed wired and wireless
-// scenario in which a hierarchical mobility model is used.
-//
-// The simulation layout consists of N backbone routers interconnected
-// by an ad hoc wifi network.
-// Each backbone router also has a local 802.11 network and is connected
-// to a local LAN. An additional set of (K-1) nodes are connected to
-// this backbone. Finally, a local LAN is connected to each router
-// on the backbone, with L-1 additional hosts.
-//
-// The nodes are populated with TCP/IP stacks, and OLSR unicast routing
-// on the backbone. An example UDP transfer is shown. The simulator
-// be configured to output tcpdumps or traces from different nodes.
-//
-//
-// +--------------------------------------------------------+
-// | |
-// | 802.11 ad hoc, ns-2 mobility |
-// | |
-// +--------------------------------------------------------+
-// | o o o (N backbone routers) |
-// +--------+ +--------+
-// wired LAN | mobile | wired LAN | mobile |
-// -----------| router | -----------| router |
-// --------- ---------
-// | |
-// +----------------+ +----------------+
-// | 802.11 | | 802.11 |
-// | infra net | | infra net |
-// | K-1 hosts | | K-1 hosts |
-// +----------------+ +----------------+
-//
-// We'll send data from the first wired LAN node on the first wired LAN
-// to the last wireless STA on the last infrastructure net, thereby
-// causing packets to traverse CSMA to adhoc to infrastructure links
-//
-// Note that certain mobility patterns may cause packet forwarding
-// to fail (if nodes become disconnected)
-
-#include <fstream>
-#include <string>
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-#include "ns3/wifi-module.h"
-
-using namespace ns3;
-
-//
-// Define logging keyword for this file
-//
-NS_LOG_COMPONENT_DEFINE ("MixedWireless");
-
-//
-// This function will be used below as a trace sink, if the command-line
-// argument or default value "useCourseChangeCallback" is set to true
-//
-static void
-CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
-{
- Vector position = model->GetPosition ();
- std::cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std::endl;
-}
-
-int
-main (int argc, char *argv[])
-{
- //
- // First, we declare and initialize a few local variables that control some
- // simulation parameters.
- //
- uint32_t backboneNodes = 10;
- uint32_t infraNodes = 5;
- uint32_t lanNodes = 5;
- uint32_t stopTime = 10;
- bool useCourseChangeCallback = false;
- bool enableTracing = false;
-
- //
- // Simulation defaults are typically set next, before command line
- // arguments are parsed.
- //
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("210"));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("10kb/s"));
-
- //
- // For convenience, we add the local variables to the command line argument
- // system so that they can be overridden with flags such as
- // "--backboneNodes=20"
- //
- CommandLine cmd;
- cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes);
- cmd.AddValue ("infraNodes", "number of leaf nodes", infraNodes);
- cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes);
- cmd.AddValue("stopTime", "simulation stop time (seconds)", stopTime);
- cmd.AddValue("useCourseChangeCallback", "whether to enable course change tracing", useCourseChangeCallback);
- cmd.AddValue("enableTracing", "enable tracing", enableTracing);
-
- //
- // The system global variables and the local values added to the argument
- // system can be overridden by command line arguments by using this call.
- //
- cmd.Parse (argc, argv);
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Construct the backbone //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- //
- // Create a container to manage the nodes of the adhoc (backbone) network.
- // Later we'll create the rest of the nodes we'll need.
- //
- NodeContainer backbone;
- backbone.Create (backboneNodes);
- //
- // Create the backbone wifi net devices and install them into the nodes in
- // our container
- //
- WifiHelper wifi;
- NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
- mac.SetType ("ns3::AdhocWifiMac");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-54mbs"));
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
- NetDeviceContainer backboneDevices = wifi.Install (wifiPhy, mac, backbone);
-
- // We enable OLSR (which will be consulted at a higher priority than
- // the global routing) on the backbone ad hoc nodes
- NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes");
- OlsrHelper olsr;
- //
- // Add the IPv4 protocol stack to the nodes in our container
- //
- InternetStackHelper internet;
- internet.SetRoutingHelper (olsr);
- internet.Install (backbone);
-
- // re-initialize for non-olsr routing.
- internet.Reset ();
-
- //
- // Assign IPv4 addresses to the device drivers (actually to the associated
- // IPv4 interfaces) we just created.
- //
- Ipv4AddressHelper ipAddrs;
- ipAddrs.SetBase ("192.168.0.0", "255.255.255.0");
- ipAddrs.Assign (backboneDevices);
-
- //
- // The ad-hoc network nodes need a mobility model so we aggregate one to
- // each of the nodes we just finished building.
- //
- MobilityHelper mobility;
- Ptr<ListPositionAllocator> positionAlloc =
- CreateObject<ListPositionAllocator> ();
- double x = 0.0;
- for (uint32_t i = 0; i < backboneNodes; ++i)
- {
- positionAlloc->Add (Vector (x, 0.0, 0.0));
- x += 5.0;
- }
- mobility.SetPositionAllocator (positionAlloc);
- mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (0, 20, 0, 20)),
- "Speed", RandomVariableValue (ConstantVariable (2)),
- "Pause", RandomVariableValue (ConstantVariable (0.2)));
- mobility.Install (backbone);
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Construct the LANs //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- // Reset the address base-- all of the CSMA networks will be in
- // the "172.16 address space
- ipAddrs.SetBase ("172.16.0.0", "255.255.255.0");
-
-
- for (uint32_t i = 0; i < backboneNodes; ++i)
- {
- NS_LOG_INFO ("Configuring local area network for backbone node " << i);
- //
- // Create a container to manage the nodes of the LAN. We need
- // two containers here; one with all of the new nodes, and one
- // with all of the nodes including new and existing nodes
- //
- NodeContainer newLanNodes;
- newLanNodes.Create (lanNodes - 1);
- // Now, create the container with all nodes on this link
- NodeContainer lan (backbone.Get (i), newLanNodes);
- //
- // Create the CSMA net devices and install them into the nodes in our
- // collection.
- //
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate",
- DataRateValue (DataRate (5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer lanDevices = csma.Install (lan);
- //
- // Add the IPv4 protocol stack to the new LAN nodes
- //
- internet.Install (newLanNodes);
- //
- // Assign IPv4 addresses to the device drivers (actually to the
- // associated IPv4 interfaces) we just created.
- //
- ipAddrs.Assign (lanDevices);
- //
- // Assign a new network prefix for the next LAN, according to the
- // network mask initialized above
- //
- ipAddrs.NewNetwork ();
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Construct the mobile networks //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- // Reset the address base-- all of the 802.11 networks will be in
- // the "10.0" address space
- ipAddrs.SetBase ("10.0.0.0", "255.255.255.0");
-
- for (uint32_t i = 0; i < backboneNodes; ++i)
- {
- NS_LOG_INFO ("Configuring wireless network for backbone node " << i);
- //
- // Create a container to manage the nodes of the LAN. We need
- // two containers here; one with all of the new nodes, and one
- // with all of the nodes including new and existing nodes
- //
- NodeContainer stas;
- stas.Create (infraNodes - 1);
- // Now, create the container with all nodes on this link
- NodeContainer infra (backbone.Get (i), stas);
- //
- // Create an infrastructure network
- //
- WifiHelper wifiInfra = WifiHelper::Default ();
- NqosWifiMacHelper macInfra = NqosWifiMacHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
- // Create unique ssids for these networks
- std::string ssidString("wifi-infra");
- std::stringstream ss;
- ss << i;
- ssidString += ss.str();
- Ssid ssid = Ssid (ssidString);
- wifiInfra.SetRemoteStationManager ("ns3::ArfWifiManager");
- // setup stas
- macInfra.SetType ("ns3::NqstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- NetDeviceContainer staDevices = wifiInfra.Install (wifiPhy, macInfra, stas);
- // setup ap.
- macInfra.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
- NetDeviceContainer apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i));
- // Collect all of these new devices
- NetDeviceContainer infraDevices (apDevices, staDevices);
-
- // Add the IPv4 protocol stack to the nodes in our container
- //
- internet.Install (stas);
- //
- // Assign IPv4 addresses to the device drivers (actually to the associated
- // IPv4 interfaces) we just created.
- //
- ipAddrs.Assign (infraDevices);
- //
- // Assign a new network prefix for each mobile network, according to
- // the network mask initialized above
- //
- ipAddrs.NewNetwork ();
- //
- // The new wireless nodes need a mobility model so we aggregate one
- // to each of the nodes we just finished building.
- //
- Ptr<ListPositionAllocator> subnetAlloc =
- CreateObject<ListPositionAllocator> ();
- for (uint32_t j = 0; j < infra.GetN (); ++j)
- {
- subnetAlloc->Add (Vector (0.0, j, 0.0));
- }
- mobility.PushReferenceMobilityModel (backbone.Get (i));
- mobility.SetPositionAllocator (subnetAlloc);
- mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (-10, 10, -10, 10)),
- "Speed", RandomVariableValue (ConstantVariable (3)),
- "Pause", RandomVariableValue (ConstantVariable (0.4)));
- mobility.Install (infra);
- }
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Routing configuration //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- // The below global routing does not take into account wireless effects.
- // However, it is useful for setting default routes for all of the nodes
- // such as the LAN nodes.
- NS_LOG_INFO ("Enabling global routing on all nodes");
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Application configuration //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 10 Kb/s, between two nodes
- // We'll send data from the first wired LAN node on the first wired LAN
- // to the last wireless STA on the last infrastructure net, thereby
- // causing packets to traverse CSMA to adhoc to infrastructure links
-
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- // Let's make sure that the user does not define too few nodes
- // to make this example work. We need lanNodes > 1 and infraNodes > 1
- NS_ASSERT (lanNodes > 1 && infraNodes > 1);
- // We want the source to be the first node created outside of the backbone
- // Conveniently, the variable "backboneNodes" holds this node index value
- Ptr<Node> appSource = NodeList::GetNode (backboneNodes);
- // We want the sink to be the last node created in the topology.
- uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
- Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
- // Let's fetch the IP address of the last node, which is on Ipv4Interface 1
- Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1, 0).GetLocal ();
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (remoteAddr, port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer apps = onoff.Install (appSource);
- apps.Start (Seconds (3.0));
- apps.Stop (Seconds (20.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (), port));
- apps = sink.Install (appSink);
- apps.Start (Seconds (3.0));
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Tracing configuration //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- NS_LOG_INFO ("Configure Tracing.");
- std::ofstream ascii;
- if (enableTracing == true)
- {
- //
- // Let's set up some ns-2-like ascii traces, using another helper class
- //
- ascii.open ("mixed-wireless.tr");
- YansWifiPhyHelper::EnableAsciiAll (ascii);
- CsmaHelper::EnableAsciiAll (ascii);
- InternetStackHelper::EnableAsciiAll (ascii);
-
- // Let's do a pcap trace on the application source and sink, ifIndex 0
- // Csma captures in non-promiscuous mode
- CsmaHelper::EnablePcap ("mixed-wireless", appSource->GetId (), 0, false);
- wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0);
- wifiPhy.EnablePcap ("mixed-wireless", 9, 2);
- wifiPhy.EnablePcap ("mixed-wireless", 9, 0);
- }
-
- if (useCourseChangeCallback == true)
- {
- Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChangeCallback));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // //
- // Run simulation //
- // //
- ///////////////////////////////////////////////////////////////////////////
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Stop (Seconds (stopTime));
- Simulator::Run ();
- Simulator::Destroy ();
-}
--- a/examples/mixed-wireless.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,352 +0,0 @@
-# /*
-# * This program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License version 2 as
-# * published by the Free Software Foundation;
-# *
-# * This program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with this program; if not, write to the Free Software
-# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-# *
-# */
-
-#
-# This ns-3 example demonstrates the use of helper functions to ease
-# the construction of simulation scenarios.
-#
-# The simulation topology consists of a mixed wired and wireless
-# scenario in which a hierarchical mobility model is used.
-#
-# The simulation layout consists of N backbone routers interconnected
-# by an ad hoc wifi network.
-# Each backbone router also has a local 802.11 network and is connected
-# to a local LAN. An additional set of(K-1) nodes are connected to
-# this backbone. Finally, a local LAN is connected to each router
-# on the backbone, with L-1 additional hosts.
-#
-# The nodes are populated with TCP/IP stacks, and OLSR unicast routing
-# on the backbone. An example UDP transfer is shown. The simulator
-# be configured to output tcpdumps or traces from different nodes.
-#
-#
-# +--------------------------------------------------------+
-# | |
-# | 802.11 ad hoc, ns-2 mobility |
-# | |
-# +--------------------------------------------------------+
-# | o o o(N backbone routers) |
-# +--------+ +--------+
-# wired LAN | mobile | wired LAN | mobile |
-# -----------| router | -----------| router |
-# --------- ---------
-# | |
-# +----------------+ +----------------+
-# | 802.11 | | 802.11 |
-# | net | | net |
-# | K-1 hosts | | K-1 hosts |
-# +----------------+ +----------------+
-#
-
-import ns3
-
-# #
-# # This function will be used below as a trace sink
-# #
-# static void
-# CourseChangeCallback(std.string path, Ptr<const MobilityModel> model)
-# {
-# Vector position = model.GetPosition();
-# std.cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std.endl;
-# }
-
-def main(argv):
- #
- # First, we declare and initialize a few local variables that control some
- # simulation parameters.
- #
- backboneNodes = 10
- infraNodes = 5
- lanNodes = 5
- stopTime = 10
-
- #
- # Simulation defaults are typically set next, before command line
- # arguments are parsed.
- #
- ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.StringValue("210"))
- ns3.Config.SetDefault("ns3::OnOffApplication::DataRate", ns3.StringValue("448kb/s"))
-
- #
- # For convenience, we add the local variables to the command line argument
- # system so that they can be overridden with flags such as
- # "--backboneNodes=20"
- #
- cmd = ns3.CommandLine()
- #cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes)
- #cmd.AddValue("infraNodes", "number of leaf nodes", infraNodes)
- #cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes)
- #cmd.AddValue("stopTime", "simulation stop time(seconds)", stopTime)
-
- #
- # The system global variables and the local values added to the argument
- # system can be overridden by command line arguments by using this call.
- #
- cmd.Parse(argv)
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
- # #
- # Construct the backbone #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
-
- #
- # Create a container to manage the nodes of the adhoc(backbone) network.
- # Later we'll create the rest of the nodes we'll need.
- #
- backbone = ns3.NodeContainer()
- backbone.Create(backboneNodes)
- #
- # Create the backbone wifi net devices and install them into the nodes in
- # our container
- #
- wifi = ns3.WifiHelper()
- mac = ns3.NqosWifiMacHelper.Default()
- mac.SetType("ns3::AdhocWifiMac")
- wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
- "DataMode", ns3.StringValue("wifia-54mbs"))
- wifiPhy = ns3.YansWifiPhyHelper.Default()
- wifiChannel = ns3.YansWifiChannelHelper.Default()
- wifiPhy.SetChannel(wifiChannel.Create())
- backboneDevices = wifi.Install(wifiPhy, mac, backbone)
- #
- # Add the IPv4 protocol stack to the nodes in our container
- #
- print "Enabling OLSR routing on all backbone nodes"
- internet = ns3.InternetStackHelper()
- olsr = ns3.OlsrHelper()
- internet.SetRoutingHelper(olsr);
- internet.Install(backbone);
- # re-initialize for non-olsr routing.
- internet.Reset()
- #
- # Assign IPv4 addresses to the device drivers(actually to the associated
- # IPv4 interfaces) we just created.
- #
- ipAddrs = ns3.Ipv4AddressHelper()
- ipAddrs.SetBase(ns3.Ipv4Address("192.168.0.0"), ns3.Ipv4Mask("255.255.255.0"))
- ipAddrs.Assign(backboneDevices)
-
- #
- # The ad-hoc network nodes need a mobility model so we aggregate one to
- # each of the nodes we just finished building.
- #
- mobility = ns3.MobilityHelper()
- positionAlloc = ns3.ListPositionAllocator()
- x = 0.0
- for i in range(backboneNodes):
- positionAlloc.Add(ns3.Vector(x, 0.0, 0.0))
- x += 5.0
- mobility.SetPositionAllocator(positionAlloc)
- mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
- "Bounds", ns3.RectangleValue(ns3.Rectangle(0, 1000, 0, 1000)),
- "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(2000)),
- "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.2)))
- mobility.Install(backbone)
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
- # #
- # Construct the LANs #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
-
- # Reset the address base-- all of the CSMA networks will be in
- # the "172.16 address space
- ipAddrs.SetBase(ns3.Ipv4Address("172.16.0.0"), ns3.Ipv4Mask("255.255.255.0"))
-
- for i in range(backboneNodes):
- print "Configuring local area network for backbone node ", i
- #
- # Create a container to manage the nodes of the LAN. We need
- # two containers here; one with all of the new nodes, and one
- # with all of the nodes including new and existing nodes
- #
- newLanNodes = ns3.NodeContainer()
- newLanNodes.Create(lanNodes - 1)
- # Now, create the container with all nodes on this link
- lan = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), newLanNodes)
- #
- # Create the CSMA net devices and install them into the nodes in our
- # collection.
- #
- csma = ns3.CsmaHelper()
- csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
- csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
- lanDevices = csma.Install(lan)
- #
- # Add the IPv4 protocol stack to the new LAN nodes
- #
- internet.Install(newLanNodes)
- #
- # Assign IPv4 addresses to the device drivers(actually to the
- # associated IPv4 interfaces) we just created.
- #
- ipAddrs.Assign(lanDevices)
- #
- # Assign a new network prefix for the next LAN, according to the
- # network mask initialized above
- #
- ipAddrs.NewNetwork()
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
- # #
- # Construct the mobile networks #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
-
- # Reset the address base-- all of the 802.11 networks will be in
- # the "10.0" address space
- ipAddrs.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
-
- for i in range(backboneNodes):
- print "Configuring wireless network for backbone node ", i
- #
- # Create a container to manage the nodes of the LAN. We need
- # two containers here; one with all of the new nodes, and one
- # with all of the nodes including new and existing nodes
- #
- stas = ns3.NodeContainer()
- stas.Create(infraNodes - 1)
- # Now, create the container with all nodes on this link
- infra = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), stas)
- #
- # Create another ad hoc network and devices
- #
- ssid = ns3.Ssid('wifi-infra' + str(i))
- wifiInfra = ns3.WifiHelper.Default()
- wifiPhy.SetChannel(wifiChannel.Create())
- wifiInfra.SetRemoteStationManager('ns3::ArfWifiManager')
- macInfra = ns3.NqosWifiMacHelper.Default();
- macInfra.SetType("ns3::NqstaWifiMac",
- "Ssid", ns3.SsidValue(ssid),
- "ActiveProbing", ns3.BooleanValue(False))
-
- # setup stas
- staDevices = wifiInfra.Install(wifiPhy, macInfra, stas)
- # setup ap.
- macInfra.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid),
- "BeaconGeneration", ns3.BooleanValue(True),
- "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
- apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i))
- # Collect all of these new devices
- infraDevices = ns3.NetDeviceContainer(apDevices, staDevices)
-
- # Add the IPv4 protocol stack to the nodes in our container
- #
- internet.Install(stas)
- #
- # Assign IPv4 addresses to the device drivers(actually to the associated
- # IPv4 interfaces) we just created.
- #
- ipAddrs.Assign(infraDevices)
- #
- # Assign a new network prefix for each mobile network, according to
- # the network mask initialized above
- #
- ipAddrs.NewNetwork()
- #
- # The new wireless nodes need a mobility model so we aggregate one
- # to each of the nodes we just finished building.
- #
- subnetAlloc = ns3.ListPositionAllocator()
- for j in range(infra.GetN()):
- subnetAlloc.Add(ns3.Vector(0.0, j, 0.0))
-
- mobility.PushReferenceMobilityModel(backbone.Get(i))
- mobility.SetPositionAllocator(subnetAlloc)
- mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
- "Bounds", ns3.RectangleValue(ns3.Rectangle(-25, 25, -25, 25)),
- "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(30)),
- "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.4)))
- mobility.Install(infra)
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
- # #
- # Application configuration #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
-
- # Create the OnOff application to send UDP datagrams of size
- # 210 bytes at a rate of 448 Kb/s, between two nodes
- print "Create Applications."
- port = 9 # Discard port(RFC 863)
-
- # Let's make sure that the user does not define too few LAN nodes
- # to make this example work. We need lanNodes >= 5
- assert(lanNodes >= 5)
- appSource = ns3.NodeList.GetNode(11)
- appSink = ns3.NodeList.GetNode(13)
- remoteAddr = ns3.Ipv4Address("172.16.0.5")
-
- onoff = ns3.OnOffHelper("ns3::UdpSocketFactory",
- ns3.Address(ns3.InetSocketAddress(remoteAddr, port)))
- onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
- onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
- apps = onoff.Install(ns3.NodeContainer(appSource))
- apps.Start(ns3.Seconds(3.0))
- apps.Stop(ns3.Seconds(20.0))
-
- # Create a packet sink to receive these packets
- sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
- ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port))
- apps = sink.Install(ns3.NodeContainer(appSink))
- apps.Start(ns3.Seconds(3.0))
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
- # #
- # Tracing configuration #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
-
- print "Configure Tracing."
- #
- # Let's set up some ns-2-like ascii traces, using another helper class
- #
- #std.ofstream ascii
- #ascii.open("mixed-wireless.tr")
- #WifiHelper.EnableAsciiAll(ascii)
- #CsmaHelper.EnableAsciiAll(ascii)
- print "(tracing not done for Python)"
- # Look at nodes 11, 13 only
- # WifiHelper.EnableAscii(ascii, 11, 0);
- # WifiHelper.EnableAscii(ascii, 13, 0);
-
- # Let's do a pcap trace on the backbone devices
- wifiPhy.EnablePcap("mixed-wireless", backboneDevices)
- # Let's additionally trace the application Sink, ifIndex 0
- ns3.CsmaHelper.EnablePcap("mixed-wireless", appSink.GetId(), 0, False)
-
-# #ifdef ENABLE_FOR_TRACING_EXAMPLE
-# Config.Connect("/NodeList/*/$MobilityModel/CourseChange",
-# MakeCallback(&CourseChangeCallback))
-# #endif
-
-
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- # #
- # Run simulation #
- # #
- # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-
- print "Run Simulation."
- ns3.Simulator.Stop(ns3.Seconds(stopTime))
- ns3.Simulator.Run()
- ns3.Simulator.Destroy()
-
-
-if __name__ == '__main__':
- import sys
- main(sys.argv)
--- a/examples/multirate.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,588 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Duy Nguyen <duy@soe.ucsc.edu>
- */
-
-/**
- * Scenarios: 100 nodes, multiple simultaneous flows, multi-hop ad hoc, routing,
- * and mobility
- *
- * INSTRUCTIONS:
- *
- * To optimize build:
- * ./waf -d optimized configure
- * ./waf
- *
- * To compile:
- * ./waf --run multirate
- *
- * To compile with commandline(useful for varying parameters or configurations):
- * ./waf --run "scratch/multirate.cc --packetSize=2000 --totalTime=50"
- *
- * To turn on NS_LOG:
- * export NS_LOG=multirate=level_all
- * (can only view log if built with ./waf -d debug configure)
- *
- * To debug:
- * ./waf --shell
- * gdb ./build/debug/scratch/multirate
- *
- * To view pcap files:
- * tcpdump -nn -tt -r filename.pcap
- *
- * To monitor the files
- * tail -f filename.pcap
- *
- * Sidenote: Simulation might take sometime
- */
-
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-#include "ns3/random-variable.h"
-#include "ns3/wifi-module.h"
-
-#include <iostream>
-#include <fstream>
-
-NS_LOG_COMPONENT_DEFINE ("multirate");
-
-using namespace ns3;
-
-class Experiment
-{
-public:
-
- Experiment ();
- Experiment (std::string name);
- Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility);
-
- bool CommandSetup (int argc, char **argv);
- bool IsRouting () { return (enableRouting == 1) ? 1:0; }
- bool IsMobility () { return (enableMobility == 1) ? 1:0; }
-
- uint32_t GetScenario () {return scenario; }
-
- std::string GetRtsThreshold () { return rtsThreshold; }
- std::string GetOutputFileName () { return outputFileName; }
- std::string GetRateManager () { return rateManager; }
-
-private:
-
- Vector GetPosition (Ptr<Node> node);
- Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
- NodeContainer GenerateNeighbors(NodeContainer c, uint32_t senderId);
-
- void ApplicationSetup (Ptr<Node> client, Ptr<Node> server, double start, double stop);
- void AssignNeighbors (NodeContainer c);
- void SelectSrcDest (NodeContainer c);
- void ReceivePacket (Ptr<Socket> socket);
- void CheckThroughput ();
- void SendMultiDestinations (Ptr<Node> sender, NodeContainer c);
-
- Gnuplot2dDataset m_output;
-
- double totalTime;
-
- uint32_t bytesTotal;
- uint32_t packetSize;
- uint32_t gridSize;
- uint32_t nodeDistance;
- uint32_t port;
- uint32_t expMean;
- uint32_t scenario;
-
- bool enablePcap;
- bool enableTracing;
- bool enableFlowMon;
- bool enableRouting;
- bool enableMobility;
-
- NodeContainer containerA, containerB, containerC, containerD;
- std::string rtsThreshold, rateManager, outputFileName;
-};
-
-Experiment::Experiment ()
-{}
-
-Experiment::Experiment (std::string name) :
- m_output (name),
- totalTime (50), //use shorter time for faster simulation
- bytesTotal(0),
- packetSize (2000),
- gridSize (10), //10x10 grid for a total of 100 nodes
- nodeDistance (30),
- port (5000),
- expMean (4), //flows being exponentially distributed
- scenario (4),
- enablePcap (false), // will flood the directory with *.pcap files
- enableTracing (true),
- enableFlowMon (true),
- enableRouting (false),
- enableMobility (false),
- rtsThreshold ("2200"), //0 for enabling rts/cts
- rateManager ("ns3::MinstrelWifiManager"),
- outputFileName ("minstrel")
-{
- m_output.SetStyle (Gnuplot2dDataset::LINES);
-}
-
-Ptr<Socket>
-Experiment::SetupPacketReceive (Ptr<Node> node)
-{
- TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
- Ptr<Socket> sink = Socket::CreateSocket (node, tid);
- InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), port);
- sink->Bind (local);
- sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
-
- return sink;
-}
-
-void
-Experiment::ReceivePacket (Ptr<Socket> socket)
-{
- Ptr<Packet> packet;
- while (packet = socket->Recv ())
- {
- bytesTotal += packet->GetSize();
- }
-}
-
-void
-Experiment::CheckThroughput()
-{
- double mbs = ((bytesTotal * 8.0) /1000000);
- bytesTotal = 0;
- m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
-
- Simulator::Schedule (Seconds (1.0), &Experiment::CheckThroughput, this);
-}
-
-Vector
-Experiment::GetPosition (Ptr<Node> node)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- return mobility->GetPosition ();
-}
-
-/**
- *
- * Take the grid map, divide it into 4 quadrants
- * Assign all nodes from each quadrant to a specific container
- *
- */
-void
-Experiment::AssignNeighbors (NodeContainer c)
-{
- uint32_t totalNodes = c.GetN ();
- for (uint32_t i=0; i< totalNodes; i++)
- {
- if ( (i % gridSize) <= (gridSize/2 - 1))
- {
- //lower left quadrant
- if ( i < totalNodes/2 )
- {
- containerA.Add(c.Get(i));
- }
-
- //upper left quadrant
- if ( i >= (uint32_t)(4*totalNodes)/10 )
- {
- containerC.Add(c.Get(i));
- }
- }
- if ( (i % gridSize) >= (gridSize/2 - 1))
- {
- //lower right quadrant
- if ( i < totalNodes/2 )
- {
- containerB.Add(c.Get(i));
- }
-
- //upper right quadrant
- if ( i >= (uint32_t)(4*totalNodes)/10 )
- {
- containerD.Add(c.Get(i));
- }
- }
- }
-}
-
-/**
- * Generate 1-hop and 2-hop neighbors of a node in grid topology
- *
- */
-NodeContainer
-Experiment::GenerateNeighbors (NodeContainer c, uint32_t senderId)
-{
- NodeContainer nc;
- uint32_t limit = senderId + 2;
- for (uint32_t i= senderId - 2; i <= limit; i++)
- {
- //must ensure the boundaries for other topologies
- nc.Add(c.Get(i));
- nc.Add(c.Get(i + 10));
- nc.Add(c.Get(i + 20));
- nc.Add(c.Get(i - 10));
- nc.Add(c.Get(i - 20));
- }
- return nc;
-}
-
-/**
- * Sources and destinations are randomly selected such that a node
- * may be the source for multiple destinations and a node maybe a destination
- * for multiple sources.
- */
-void
-Experiment::SelectSrcDest (NodeContainer c)
-{
- uint32_t totalNodes = c.GetN();
- UniformVariable uvSrc (0, totalNodes/2 -1);
- UniformVariable uvDest (totalNodes/2, totalNodes);
-
- for (uint32_t i=0; i < totalNodes/3; i++)
- {
- ApplicationSetup (c.Get(uvSrc.RandomVariable::GetInteger()), c.Get(uvDest.RandomVariable::GetInteger()) , 1, totalTime);
- }
-}
-
-/**
- *
- * A sender node will set up a flow to each of the its neighbors
- * in its quadrant randomly. All the flows are exponentially distributed
- *
- */
-void
-Experiment::SendMultiDestinations(Ptr<Node> sender, NodeContainer c)
-{
-
- // UniformVariable params: (Xrange, Yrange)
- UniformVariable uv(0, c.GetN ());
-
- // ExponentialVariable params: (mean, upperbound)
- ExponentialVariable ev(expMean, totalTime);
-
- double start=1, stop=totalTime;
- uint32_t destIndex;
-
- for (uint32_t i=0; i < c.GetN (); i++)
- {
- stop = start + ev.GetValue();
- NS_LOG_DEBUG("Start=" << start << " Stop=" << stop);
-
- do {
- destIndex = (uint32_t) uv.GetValue();
- } while ( (c.Get(destIndex))->GetId () == sender->GetId ());
-
- ApplicationSetup (sender, c.Get(destIndex) , start, stop);
-
- start = stop;
-
- if(start > totalTime)
- {
- break;
- }
- }
-}
-
-void
-Experiment::ApplicationSetup (Ptr<Node> client, Ptr<Node> server, double start, double stop)
-{
-
- Vector serverPos = GetPosition (server);
- Vector clientPos = GetPosition (client);
-
- Ptr<Ipv4> ipv4Server = server->GetObject<Ipv4>();
- Ptr<Ipv4> ipv4Client = client->GetObject<Ipv4>();
-
- Ipv4InterfaceAddress iaddrServer = ipv4Server->GetAddress(1,0);
- Ipv4InterfaceAddress iaddrClient = ipv4Client->GetAddress(1,0);
-
- Ipv4Address ipv4AddrServer = iaddrServer.GetLocal ();
- Ipv4Address ipv4AddrClient = iaddrClient.GetLocal ();
-
- NS_LOG_DEBUG("Set up Server Device " << (server->GetDevice(0))->GetAddress ()
- << " with ip " << ipv4AddrServer
- << " position (" << serverPos.x << "," << serverPos.y << "," << serverPos.z << ")");
-
- NS_LOG_DEBUG("Set up Client Device " << (client->GetDevice(0))->GetAddress ()
- << " with ip " << ipv4AddrClient
- << " position (" << clientPos.x << "," << clientPos.y << "," << clientPos.z << ")"
- << "\n");
-
-
- // Equipping the source node with OnOff Application used for sending
- OnOffHelper onoff ("ns3::UdpSocketFactory", Address(InetSocketAddress(Ipv4Address("10.0.0.1"), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
- onoff.SetAttribute ("PacketSize", UintegerValue (packetSize));
- onoff.SetAttribute ("Remote", AddressValue(InetSocketAddress (ipv4AddrServer, port)));
-
- ApplicationContainer apps = onoff.Install (client);
- apps.Start (Seconds (start));
- apps.Stop (Seconds (stop));
-
-/*
- // Select either Sink Method 1 or 2 for setting up sink
- // one using a helper vs one without
- // Sink: Method 1
- Address sinkAddr(InetSocketAddress (Ipv4Address::GetAny (), port));
- PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkAddr);
- ApplicationContainer sinkApp = sinkHelper.Install (server);
- sinkApp.Start (Seconds (start));
- sinkApp.Stop (Seconds (stop));
-*/
-
- // Sink: Method 2
- Ptr<Socket> sink = SetupPacketReceive (server);
-
-}
-
-Gnuplot2dDataset
-Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility)
-{
-
-
- uint32_t nodeSize = gridSize*gridSize;
- NodeContainer c;
- c.Create (nodeSize);
-
- YansWifiPhyHelper phy = wifiPhy;
- phy.SetChannel (wifiChannel.Create ());
-
- NqosWifiMacHelper mac = wifiMac;
- NetDeviceContainer devices = wifi.Install (phy, mac, c);
-
-
- OlsrHelper olsr;
- Ipv4StaticRoutingHelper staticRouting;
-
- Ipv4ListRoutingHelper list;
-
- if (enableRouting)
- {
- list.Add (staticRouting, 0);
- list.Add (olsr, 10);
- }
-
- InternetStackHelper internet;
-
- if (enableRouting)
- {
- internet.SetRoutingHelper(list);
- }
- internet.Install (c);
-
-
- Ipv4AddressHelper address;
- address.SetBase ("10.0.0.0", "255.255.255.0");
-
- Ipv4InterfaceContainer ipInterfaces;
- ipInterfaces = address.Assign(devices);
-
- MobilityHelper mobil= mobility;
- mobil.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (0.0),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (nodeDistance),
- "DeltaY", DoubleValue (nodeDistance),
- "GridWidth", UintegerValue (gridSize),
- "LayoutType", StringValue ("RowFirst"));
-
- mobil.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
-
- if (enableMobility && enableRouting)
- {
- //Rectangle (xMin, xMax, yMin, yMax)
- mobil.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (0, 500, 0, 500)),
- "Speed", RandomVariableValue (ConstantVariable (10)),
- "Pause", RandomVariableValue (ConstantVariable (0.2)));
- }
- mobil.Install (c);
-
-
-// NS_LOG_INFO ("Enabling global routing on all nodes");
-// Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- if ( scenario == 1 && enableRouting)
- {
- SelectSrcDest(c);
- }
- else if ( scenario == 2)
- {
- //All flows begin at the same time
- for (uint32_t i = 0; i < nodeSize - 1; i = i+2)
- {
- ApplicationSetup (c.Get (i), c.Get (i+1), 1, totalTime);
- }
- }
- else if ( scenario == 3)
- {
- AssignNeighbors(c);
- //Note: these senders are hand-picked in order to ensure good coverage
- //for 10x10 grid, basically one sender for each quadrant
- //you might have to change these values for other grids
- NS_LOG_DEBUG(">>>>>>>>>region A<<<<<<<<<");
- SendMultiDestinations(c.Get(22), containerA);
-
- NS_LOG_DEBUG(">>>>>>>>>region B<<<<<<<<<");
- SendMultiDestinations(c.Get(26), containerB);
-
- NS_LOG_DEBUG(">>>>>>>>>region C<<<<<<<<<");
- SendMultiDestinations(c.Get(72), containerC);
-
- NS_LOG_DEBUG(">>>>>>>>>region D<<<<<<<<<");
- SendMultiDestinations(c.Get(76), containerD);
- }
- else if ( scenario == 4)
- {
- //GenerateNeighbors(NodeContainer, uint32_t sender)
- //Note: these senders are hand-picked in order to ensure good coverage
- //you might have to change these values for other grids
- NodeContainer c1, c2, c3, c4, c5, c6, c7, c8, c9;
-
- c1 = GenerateNeighbors(c, 22);
- c2 = GenerateNeighbors(c, 24);;
- c3 = GenerateNeighbors(c, 26);;
- c4 = GenerateNeighbors(c, 42);;
- c5 = GenerateNeighbors(c, 44);;
- c6 = GenerateNeighbors(c, 46);;
- c7 = GenerateNeighbors(c, 62);;
- c8 = GenerateNeighbors(c, 64);;
- c9 = GenerateNeighbors(c, 66);;
-
- SendMultiDestinations(c.Get(22), c1);
- SendMultiDestinations(c.Get(24), c2);
- SendMultiDestinations(c.Get(26), c3);
- SendMultiDestinations(c.Get(42), c4);
- SendMultiDestinations(c.Get(44), c5);
- SendMultiDestinations(c.Get(46), c6);
- SendMultiDestinations(c.Get(62), c7);
- SendMultiDestinations(c.Get(64), c8);
- SendMultiDestinations(c.Get(66), c9);
- }
-
- CheckThroughput ();
-
- if (enablePcap)
- {
- phy.EnablePcapAll(GetOutputFileName());
- }
-
- if (enableTracing)
- {
- std::ofstream ascii;
- ascii.open ((GetOutputFileName() + ".tr").c_str());
- phy.EnableAsciiAll (ascii);
- }
-
- Ptr<FlowMonitor> flowmon;
-
- if (enableFlowMon)
- {
- FlowMonitorHelper flowmonHelper;
- flowmon = flowmonHelper.InstallAll ();
- }
-
- Simulator::Stop (Seconds (totalTime));
- Simulator::Run ();
-
- if (enableFlowMon)
- {
- flowmon->SerializeToXmlFile ((GetOutputFileName() + ".flomon"), false, false);
- }
-
- Simulator::Destroy ();
-
- return m_output;
-}
-
-bool
-Experiment::CommandSetup (int argc, char **argv)
-{
- // for commandline input
- CommandLine cmd;
- cmd.AddValue ("packetSize", "packet size", packetSize);
- cmd.AddValue ("totalTime", "simulation time", totalTime);
- cmd.AddValue ("rtsThreshold", "rts threshold", rtsThreshold);
- cmd.AddValue ("rateManager", "type of rate", rateManager);
- cmd.AddValue ("outputFileName", "output filename", outputFileName);
- cmd.AddValue ("enableRouting", "enable Routing", enableRouting);
- cmd.AddValue ("enableMobility", "enable Mobility", enableMobility);
- cmd.AddValue ("scenario", "scenario ", scenario);
-
- cmd.Parse (argc, argv);
- return true;
-}
-
-int main (int argc, char *argv[])
-{
-
- Experiment experiment;
- experiment = Experiment ("multirate");
-
- //for commandline input
- if (!experiment.CommandSetup(argc, argv))
- {
- std::cout << "Configuration failed..." << std::endl;
- exit(1);
- }
-
- // disable fragmentation
- // set value to 0 for enabling fragmentation
- Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
- Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue (experiment.GetRtsThreshold()));
-
- std::ofstream outfile ((experiment.GetOutputFileName()+ ".plt").c_str());
-
- MobilityHelper mobility;
- Gnuplot gnuplot;
- Gnuplot2dDataset dataset;
-
- WifiHelper wifi = WifiHelper::Default ();
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- Ssid ssid = Ssid ("Testbed");
-
- wifiMac.SetType ("ns3::AdhocWifiMac", "Ssid", SsidValue(ssid));
- wifi.SetStandard (WIFI_PHY_STANDARD_holland);
- wifi.SetRemoteStationManager (experiment.GetRateManager());
-
- //printing out selection confirmation
- std::cout << "Scenario: " << experiment.GetScenario () << std::endl;
- std::cout << "Rts Threshold: " << experiment.GetRtsThreshold() << std::endl;
- std::cout << "Name: " << experiment.GetOutputFileName() << std::endl;
- std::cout << "Rate: " << experiment.GetRateManager() << std::endl;
- std::cout << "Routing: " << experiment.IsRouting() << std::endl;
- std::cout << "Mobility: " << experiment.IsMobility() << std::endl;
-
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility);
-
- gnuplot.AddDataset (dataset);
- gnuplot.GenerateOutput (outfile);
-
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/naming/object-names.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,158 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("ObjectNamesExample");
+
+void
+RxEvent (std::string context, Ptr<const Packet> packet)
+{
+ NS_LOG_INFO (context << " packet " << packet);
+}
+
+int
+main (int argc, char *argv[])
+{
+#if 1
+ LogComponentEnable ("ObjectNamesExample", LOG_LEVEL_INFO);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NodeContainer n;
+ n.Create (4);
+
+ //
+ // We're going to use the zeroth node in the container as the client, and
+ // the first node as the server. Add some "human readable" names for these
+ // nodes. The names below will go into the name system as "/Names/clientZero"
+ // and "/Names/server", but note that the Add function assumes that if you
+ // omit the leading "/Names/" the remaining string is assumed to be rooted
+ // in the "/Names" namespace. The following calls,
+ //
+ // Names::Add ("clientZero", n.Get (0));
+ // Names::Add ("/Names/clientZero", n.Get (0));
+ //
+ // will produce identical results.
+ //
+ Names::Add ("clientZero", n.Get (0));
+ Names::Add ("/Names/server", n.Get (1));
+
+ //
+ // It is possible to rename a node that has been previously named. This is
+ // useful in automatic name generation. You can automatically generate node
+ // names such as, "node-0", "node-1", etc., and then go back and change
+ // the name of some distinguished node to another value -- "access-point"
+ // for example. We illustrate this by just changing the client's name.
+ // As is typical of the object name service, you can either provide or elide
+ // the "/Names" prefix as you choose.
+ //
+ Names::Rename ("clientZero", "client");
+
+ InternetStackHelper internet;
+ internet.Install (n);
+
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
+ NetDeviceContainer d = csma.Install (n);
+
+ //
+ // Add some human readable names for the devices we'll be interested in.
+ // We add the names to the name space "under" the nodes we created above.
+ // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0".
+ // In this case, we again omit the "/Names/" prefix on one call to illustrate
+ // the shortcut.
+ //
+ Names::Add ("/Names/client/eth0", d.Get (0));
+ Names::Add ("server/eth0", d.Get (1));
+
+ //
+ // You can use the object names that you've assigned in calls to the Config
+ // system to set Object Attributes. For example, you can set the Mtu
+ // Attribute of a Csma devices using the object naming service. Note that
+ // in this case, the "/Names" prefix is always required since the _Config_
+ // system always expects to see a fully qualified path name.
+ //
+ Config::Set ("/Names/client/eth0/Mtu", UintegerValue (1234));
+
+ //
+ // You can mix and match names and Attributes in calls to the Config system.
+ // For example, if "eth0" is a named object, you can get to its parent through
+ // a different namespace. For example, you could use the NodeList namespace
+ // to get to the server node, and then continue seamlessly adding named objects
+ // in the path. This is not nearly as readable as the previous version, but it
+ // illustrates how you can mix and match object names and Attribute names.
+ // Note that the config path now begins with a path in the "/NodeList"
+ // namespace.
+ //
+ Config::Set ("/NodeList/1/eth0/Mtu", UintegerValue (1234));
+
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (d);
+
+ uint16_t port = 9;
+ UdpEchoServerHelper server (port);
+ //
+ // Install the UdpEchoServer application on the server node using its name
+ // directly.
+ //
+ ApplicationContainer apps = server.Install ("/Names/server");
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 1;
+ Time interPacketInterval = Seconds (1.);
+ UdpEchoClientHelper client (i.GetAddress (1), port);
+ client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ client.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ client.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ //
+ // Install the UdpEchoClient application on the server node using its name
+ // directly.
+ //
+ apps = client.Install ("/Names/client");
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+ //
+ // Use the Config system to connect a trace source using the object name
+ // service to specify the path. Note that in this case, the "/Names"
+ // prefix is always required since the _Config_ system always expects to
+ // see a fully qualified path name
+ //
+ Config::Connect ("/Names/client/eth0/MacRx", MakeCallback (&RxEvent));
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/naming/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/naming/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,5 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('object-names', ['core', 'simulator', 'csma', 'internet-stack'])
+ obj.source = 'object-names.cc'
--- a/examples/nix-simple.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-/*
- * Simple point to point links:
- *
- * n0 -- n1 -- n2 -- n3
- *
- * n0 has UdpEchoClient
- * n3 has UdpEchoServer
- *
- * n0 IP: 10.1.1.1
- * n1 IP: 10.1.1.2, 10.1.2.1
- * n2 IP: 10.1.2.2, 10.1.3.1
- * n3 IP: 10.1.3.2
- *
- */
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
-
- int
-main (int argc, char *argv[])
-{
- LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
-
- NodeContainer nodes12;
- nodes12.Create (2);
-
- NodeContainer nodes23;
- nodes23.Add (nodes12.Get (1));
- nodes23.Create (1);
-
- NodeContainer nodes34;
- nodes34.Add(nodes23.Get (1));
- nodes34.Create (1);
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NodeContainer allNodes = NodeContainer (nodes12, nodes23.Get (1), nodes34.Get (1));
-
- // NixHelper to install nix-vector routing
- // on all nodes
- Ipv4NixVectorHelper nixRouting;
- Ipv4StaticRoutingHelper staticRouting;
-
- Ipv4ListRoutingHelper list;
- list.Add (staticRouting, 0);
- list.Add (nixRouting, 10);
-
- InternetStackHelper stack;
- stack.SetRoutingHelper (list);
- stack.Install (allNodes);
-
- NetDeviceContainer devices12;
- NetDeviceContainer devices23;
- NetDeviceContainer devices34;
- devices12 = pointToPoint.Install (nodes12);
- devices23 = pointToPoint.Install (nodes23);
- devices34 = pointToPoint.Install (nodes34);
-
- Ipv4AddressHelper address1;
- address1.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4AddressHelper address2;
- address2.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4AddressHelper address3;
- address3.SetBase ("10.1.3.0", "255.255.255.0");
-
- address1.Assign (devices12);
- address2.Assign (devices23);
- Ipv4InterfaceContainer interfaces = address3.Assign (devices34);
-
- UdpEchoServerHelper echoServer (9);
-
- ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
-
- UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
- ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
-
-
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
--- a/examples/nms-p2p-nix.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,458 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-// DARPA NMS Campus Network Model
-//
-// - This topology replicates the original NMS Campus Network model
-// with the exception of chord links (which were never utilized in the
-// original model)
-// - Link Bandwidths and Delays may not be the same as the original
-// specifications
-//
-// (c)2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
-
-// for timing functions
-#include <cstdlib>
-#include <sys/time.h>
-#include <fstream>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/global-routing-module.h"
-#include "ns3/onoff-application.h"
-#include "ns3/packet-sink.h"
-#include "ns3/point-to-point-net-device.h"
-#include "ns3/simulator.h"
-
-using namespace std;
-using namespace ns3;
-
-typedef struct timeval TIMER_TYPE;
-#define TIMER_NOW(_t) gettimeofday(&_t,NULL);
-#define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
-#define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS(_t1)-TIMER_SECONDS(_t2))
-
-NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
-
-void Progress ()
-{
- Time now = Simulator::Now ();
- Simulator::Schedule (Seconds (0.1), Progress);
-}
-
-int
-main (int argc, char *argv[])
-{
- //Config::SetDefault ("ns3::Simulator::SchedulerType", StringValue ("ns3::CalendarScheduler"));
- TIMER_TYPE t0, t1, t2;
- TIMER_NOW(t0);
- cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
- LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
-
- //RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
-
- int nCN = 2, nLANClients = 42;
- bool nix = true;
-
- CommandLine cmd;
- cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
- cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
- cmd.AddValue ("NIX", "Toggle nix-vector routing", nix);
- cmd.Parse (argc,argv);
-
- if (nCN < 2)
- {
- cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
- << endl;
- return 1;
- }
-
- cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << endl;
-
- NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
- nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
- nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
- PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
- InternetStackHelper stack;
- Ipv4InterfaceContainer ifs, ifs0[nCN][3], ifs1[nCN][6], ifs2[nCN][14],
- ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
- ifs3LAN[nCN][5][nLANClients];
- Ipv4AddressHelper address;
- std::ostringstream oss;
- p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
- p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
- p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
- p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
- p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
- p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
-
- // Setup NixVector Routing
- Ipv4NixVectorHelper nixRouting;
- Ipv4StaticRoutingHelper staticRouting;
-
- Ipv4ListRoutingHelper list;
- list.Add (staticRouting, 0);
- list.Add (nixRouting, 10);
-
- if (nix)
- {
- stack.SetRoutingHelper (list);
- }
-
- // Create Campus Networks
- for (int z = 0; z < nCN; ++z)
- {
- cout << "Creating Campus Network " << z << ":" << endl;
- // Create Net0
- cout << " SubNet [ 0";
- for (int i = 0; i < 3; ++i)
- {
- nodes_net0[z][i].Create (1);
- stack.Install (nodes_net0[z][i]);
- }
- nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
- nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
- nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
- NetDeviceContainer ndc0[3];
- for (int i = 0; i < 3; ++i)
- {
- ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
- }
- // Create Net1
- cout << " 1";
- for (int i = 0; i < 6; ++i)
- {
- nodes_net1[z][i].Create (1);
- stack.Install (nodes_net1[z][i]);
- }
- nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
- nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
- nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
- nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
- nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
- NetDeviceContainer ndc1[6];
- for (int i = 0; i < 6; ++i)
- {
- if (i == 1)
- {
- continue;
- }
- ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
- }
- // Connect Net0 <-> Net1
- NodeContainer net0_1;
- net0_1.Add (nodes_net0[z][2].Get (0));
- net0_1.Add (nodes_net1[z][0].Get (0));
- NetDeviceContainer ndc0_1;
- ndc0_1 = p2p_1gb5ms.Install (net0_1);
- oss.str("");
- oss << 10 + z << ".1.252.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc0_1);
- // Create Net2
- cout << " 2";
- for (int i = 0; i < 14; ++i)
- {
- nodes_net2[z][i].Create (1);
- stack.Install (nodes_net2[z][i]);
- }
- nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
- nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
- nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
- nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
- nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
- nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
- nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
- nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
- nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
- nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
- nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
- nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
- nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
- nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
- NetDeviceContainer ndc2[14];
- for (int i = 0; i < 14; ++i)
- {
- ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
- }
- NetDeviceContainer ndc2LAN[7][nLANClients];
- for (int i = 0; i < 7; ++i)
- {
- oss.str ("");
- oss << 10 + z << ".4." << 15 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- for (int j = 0; j < nLANClients; ++j)
- {
- nodes_net2LAN[z][i][j].Create (1);
- stack.Install (nodes_net2LAN[z][i][j]);
- nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
- ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
- ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
- }
- }
- // Create Net3
- cout << " 3 ]" << endl;
- for (int i = 0; i < 9; ++i)
- {
- nodes_net3[z][i].Create (1);
- stack.Install(nodes_net3[z][i]);
- }
- nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
- nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
- nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
- nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
- nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
- nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
- nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
- nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
- nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
- NetDeviceContainer ndc3[9];
- for (int i = 0; i < 9; ++i)
- {
- ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
- }
- NetDeviceContainer ndc3LAN[5][nLANClients];
- for (int i = 0; i < 5; ++i)
- {
- oss.str ("");
- oss << 10 + z << ".5." << 10 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.255");
- for (int j = 0; j < nLANClients; ++j)
- {
- nodes_net3LAN[z][i][j].Create (1);
- stack.Install (nodes_net3LAN[z][i][j]);
- nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
- ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
- ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
- }
- }
- cout << " Connecting Subnets..." << endl;
- // Create Lone Routers (Node 4 & 5)
- nodes_netLR[z].Create (2);
- stack.Install (nodes_netLR[z]);
- NetDeviceContainer ndcLR;
- ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
- // Connect Net2/Net3 through Lone Routers to Net0
- NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
- net0_4.Add (nodes_netLR[z].Get (0));
- net0_4.Add (nodes_net0[z][0].Get (0));
- net0_5.Add (nodes_netLR[z].Get (1));
- net0_5.Add (nodes_net0[z][1].Get (0));
- net2_4a.Add (nodes_netLR[z].Get (0));
- net2_4a.Add (nodes_net2[z][0].Get (0));
- net2_4b.Add (nodes_netLR[z].Get (1));
- net2_4b.Add (nodes_net2[z][1].Get (0));
- net3_5a.Add (nodes_netLR[z].Get (1));
- net3_5a.Add (nodes_net3[z][0].Get (0));
- net3_5b.Add (nodes_netLR[z].Get (1));
- net3_5b.Add (nodes_net3[z][1].Get (0));
- NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
- ndc0_4 = p2p_1gb5ms.Install (net0_4);
- oss.str ("");
- oss << 10 + z << ".1.253.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc0_4);
- ndc0_5 = p2p_1gb5ms.Install (net0_5);
- oss.str ("");
- oss << 10 + z << ".1.254.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc0_5);
- ndc2_4a = p2p_1gb5ms.Install (net2_4a);
- oss.str ("");
- oss << 10 + z << ".4.253.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc2_4a);
- ndc2_4b = p2p_1gb5ms.Install (net2_4b);
- oss.str ("");
- oss << 10 + z << ".4.254.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc2_4b);
- ndc3_5a = p2p_1gb5ms.Install (net3_5a);
- oss.str ("");
- oss << 10 + z << ".5.253.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc3_5a);
- ndc3_5b = p2p_1gb5ms.Install (net3_5b);
- oss.str ("");
- oss << 10 + z << ".5.254.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc3_5b);
- // Assign IP addresses
- cout << " Assigning IP addresses..." << endl;
- for (int i = 0; i < 3; ++i)
- {
- oss.str ("");
- oss << 10 + z << ".1." << 1 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs0[z][i] = address.Assign (ndc0[i]);
- }
- for (int i = 0; i < 6; ++i)
- {
- if (i == 1)
- {
- continue;
- }
- oss.str ("");
- oss << 10 + z << ".2." << 1 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs1[z][i] = address.Assign (ndc1[i]);
- }
- oss.str ("");
- oss << 10 + z << ".3.1.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndcLR);
- for (int i = 0; i < 14; ++i)
- {
- oss.str ("");
- oss << 10 + z << ".4." << 1 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs2[z][i] = address.Assign (ndc2[i]);
- }
- for (int i = 0; i < 9; ++i)
- {
- oss.str ("");
- oss << 10 + z << ".5." << 1 + i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs3[z][i] = address.Assign (ndc3[i]);
- }
- }
- // Create Ring Links
- if (nCN > 1)
- {
- cout << "Forming Ring Topology..." << endl;
- NodeContainer nodes_ring[nCN];
- for (int z = 0; z < nCN-1; ++z)
- {
- nodes_ring[z].Add (nodes_net0[z][0].Get (0));
- nodes_ring[z].Add (nodes_net0[z+1][0].Get (0));
- }
- nodes_ring[nCN-1].Add (nodes_net0[nCN-1][0].Get (0));
- nodes_ring[nCN-1].Add (nodes_net0[0][0].Get (0));
- NetDeviceContainer ndc_ring[nCN];
- for (int z = 0; z < nCN; ++z)
- {
- ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
- oss.str ("");
- oss << "254.1." << z + 1 << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- ifs = address.Assign (ndc_ring[z]);
- }
- }
-
- // Create Traffic Flows
- cout << "Creating TCP Traffic Flows:" << endl;
- Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
- Config::SetDefault ("ns3::OnOffApplication::OnTime",
- RandomVariableValue (ConstantVariable (1)));
- Config::SetDefault ("ns3::OnOffApplication::OffTime",
- RandomVariableValue (ConstantVariable (0)));
- Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
-
- UniformVariable urng;
- int r1;
- double r2;
- for (int z = 0; z < nCN; ++z)
- {
- int x = z + 1;
- if (z == nCN - 1)
- {
- x = 0;
- }
- // Subnet 2 LANs
- cout << " Campus Network " << z << " Flows [ Net2 ";
- for (int i = 0; i < 7; ++i)
- {
- for (int j = 0; j < nLANClients; ++j)
- {
- // Sinks
- PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (), 9999));
- ApplicationContainer sinkApp = sinkHelper.Install (
- nodes_net2LAN[z][i][j].Get (0));
- sinkApp.Start (Seconds (100.0));
- // Sources
- r1 = 2 + (int)(4 * urng.GetValue ());
- r2 = 100 + (10 * urng.GetValue ());;
- OnOffHelper client ("ns3::TcpSocketFactory", Address ());
- AddressValue remoteAddress(InetSocketAddress (
- ifs2LAN[z][i][j].GetAddress (0), 9999));
- client.SetAttribute ("Remote", remoteAddress);
- ApplicationContainer clientApp;
- clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
- clientApp.Start (Seconds (r2));
- }
- }
- // Subnet 3 LANs
- cout << "Net3 ]" << endl;
- for (int i = 0; i < 5; ++i)
- {
- for (int j = 0; j < nLANClients; ++j)
- {
- // Sinks
- PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (), 9999));
- ApplicationContainer sinkApp = sinkHelper.Install (
- nodes_net3LAN[z][i][j].Get (0));
- sinkApp.Start (Seconds (100.0));
- // Sources
- r1 = 2 + (int)(4 * urng.GetValue ());
- r2 = 100 + (10 * urng.GetValue ());;
- OnOffHelper client ("ns3::TcpSocketFactory", Address ());
- AddressValue remoteAddress (InetSocketAddress (
- ifs2LAN[z][i][j].GetAddress (0), 9999));
- client.SetAttribute ("Remote", remoteAddress);
- ApplicationContainer clientApp;
- clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
- clientApp.Start (Seconds (r2));
- }
- }
- }
-
- cout << "Created " << NodeList::GetNNodes () << " nodes." << endl;
- TIMER_TYPE routingStart;
- TIMER_NOW (routingStart);
-
- if (nix)
- {
- // Calculate routing tables
- cout << "Using Nix-vectors..." << endl;
- }
- else
- {
- // Calculate routing tables
- cout << "Populating Global Static Routing Tables..." << endl;
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- }
-
- TIMER_TYPE routingEnd;
- TIMER_NOW (routingEnd);
- cout << "Routing tables population took "
- << TIMER_DIFF (routingEnd, routingStart) << endl;
-#if 0
- std::ofstream ascii;
- ascii.open("nms_p2p_nix.tr");
- PointToPointHelper::EnableAsciiAll(ascii);
- CsmaHelper::EnableAsciiAll(ascii);
-#endif
-
-#if 0
- PointToPointHelper::EnablePcapAll("nms_p2p");
- CsmaHelper::EnablePcapAll("nms_csma");
-#endif
-
- Simulator::ScheduleNow (Progress);
- cout << "Running simulator..." << endl;
- TIMER_NOW (t1);
- Simulator::Stop (Seconds (200.0));
- Simulator::Run ();
- TIMER_NOW (t2);
- cout << "Simulator finished." << endl;
- Simulator::Destroy ();
-
- double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
- cout << "-----" << endl << "Runtime Stats:" << endl;
- cout << "Simulator init time: " << d1 << endl;
- cout << "Simulator run time: " << d2 << endl;
- cout << "Total elapsed time: " << d1+d2 << endl;
- return 0;
-}
--- a/examples/object-names.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// n0 n1 n2 n3
-// | | | |
-// =================
-// LAN
-//
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("ObjectNamesExample");
-
-void
-RxEvent (std::string context, Ptr<const Packet> packet)
-{
- NS_LOG_INFO (context << " packet " << packet);
-}
-
-int
-main (int argc, char *argv[])
-{
-#if 1
- LogComponentEnable ("ObjectNamesExample", LOG_LEVEL_INFO);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NodeContainer n;
- n.Create (4);
-
- //
- // We're going to use the zeroth node in the container as the client, and
- // the first node as the server. Add some "human readable" names for these
- // nodes. The names below will go into the name system as "/Names/clientZero"
- // and "/Names/server", but note that the Add function assumes that if you
- // omit the leading "/Names/" the remaining string is assumed to be rooted
- // in the "/Names" namespace. The following calls,
- //
- // Names::Add ("clientZero", n.Get (0));
- // Names::Add ("/Names/clientZero", n.Get (0));
- //
- // will produce identical results.
- //
- Names::Add ("clientZero", n.Get (0));
- Names::Add ("/Names/server", n.Get (1));
-
- //
- // It is possible to rename a node that has been previously named. This is
- // useful in automatic name generation. You can automatically generate node
- // names such as, "node-0", "node-1", etc., and then go back and change
- // the name of some distinguished node to another value -- "access-point"
- // for example. We illustrate this by just changing the client's name.
- // As is typical of the object name service, you can either provide or elide
- // the "/Names" prefix as you choose.
- //
- Names::Rename ("clientZero", "client");
-
- InternetStackHelper internet;
- internet.Install (n);
-
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
- NetDeviceContainer d = csma.Install (n);
-
- //
- // Add some human readable names for the devices we'll be interested in.
- // We add the names to the name space "under" the nodes we created above.
- // This has the effect of making "/Names/client/eth0" and "/Names/server/eth0".
- // In this case, we again omit the "/Names/" prefix on one call to illustrate
- // the shortcut.
- //
- Names::Add ("/Names/client/eth0", d.Get (0));
- Names::Add ("server/eth0", d.Get (1));
-
- //
- // You can use the object names that you've assigned in calls to the Config
- // system to set Object Attributes. For example, you can set the Mtu
- // Attribute of a Csma devices using the object naming service. Note that
- // in this case, the "/Names" prefix is always required since the _Config_
- // system always expects to see a fully qualified path name.
- //
- Config::Set ("/Names/client/eth0/Mtu", UintegerValue (1234));
-
- //
- // You can mix and match names and Attributes in calls to the Config system.
- // For example, if "eth0" is a named object, you can get to its parent through
- // a different namespace. For example, you could use the NodeList namespace
- // to get to the server node, and then continue seamlessly adding named objects
- // in the path. This is not nearly as readable as the previous version, but it
- // illustrates how you can mix and match object names and Attribute names.
- // Note that the config path now begins with a path in the "/NodeList"
- // namespace.
- //
- Config::Set ("/NodeList/1/eth0/Mtu", UintegerValue (1234));
-
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i = ipv4.Assign (d);
-
- uint16_t port = 9;
- UdpEchoServerHelper server (port);
- //
- // Install the UdpEchoServer application on the server node using its name
- // directly.
- //
- ApplicationContainer apps = server.Install ("/Names/server");
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 1;
- Time interPacketInterval = Seconds (1.);
- UdpEchoClientHelper client (i.GetAddress (1), port);
- client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- client.SetAttribute ("Interval", TimeValue (interPacketInterval));
- client.SetAttribute ("PacketSize", UintegerValue (packetSize));
- //
- // Install the UdpEchoClient application on the server node using its name
- // directly.
- //
- apps = client.Install ("/Names/client");
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
- //
- // Use the Config system to connect a trace source using the object name
- // service to specify the path. Note that in this case, the "/Names"
- // prefix is always required since the _Config_ system always expects to
- // see a fully qualified path name
- //
- Config::Connect ("/Names/client/eth0/MacRx", MakeCallback (&RxEvent));
-
- Simulator::Run ();
- Simulator::Destroy ();
-}
--- a/examples/ping6.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008-2009 Strasbourg University
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
- */
-
-// Network topology
-//
-// n0 n1
-// | |
-// =================
-// LAN
-//
-// - ICMPv6 echo request flows from n0 to n1 and back with ICMPv6 echo reply
-// - DropTail queues
-// - Tracing of queues and packet receptions to file "ping6.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("Ping6Example");
-
-int main (int argc, char **argv)
-{
-#if 0
- LogComponentEnable ("Ping6Example", LOG_LEVEL_INFO);
- LogComponentEnable ("Ipv6EndPointDemux", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6ListRouting", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
- LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
- LogComponentEnable ("NdiscCache", LOG_LEVEL_ALL);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer n;
- n.Create (4);
-
- /* Install IPv4/IPv6 stack */
- InternetStackHelper internetv6;
- internetv6.SetIpv4StackInstall (false);
- internetv6.Install (n);
-
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer d = csma.Install (n);
-
- Ipv6AddressHelper ipv6;
- NS_LOG_INFO ("Assign IPv6 Addresses.");
- Ipv6InterfaceContainer i = ipv6.Assign (d);
-
- NS_LOG_INFO ("Create Applications.");
-
- /* Create a Ping6 application to send ICMPv6 echo request from node zero to
- * all-nodes (ff02::1).
- */
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 5;
- Time interPacketInterval = Seconds (1.);
- Ping6Helper ping6;
-
-/*
- ping6.SetLocal (i.GetAddress (0, 1));
- ping6.SetRemote (i.GetAddress (1, 1));
-*/
- ping6.SetIfIndex (i.GetInterfaceIndex (0));
- ping6.SetRemote (Ipv6Address::GetAllNodesMulticast ());
-
- ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
- ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
- ApplicationContainer apps = ping6.Install (n.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("ping6.tr");
- CsmaHelper::EnablePcapAll (std::string ("ping6"), true);
- CsmaHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
-
--- a/examples/radvd-two-prefix.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Strasbourg University
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: David Gross <gdavid.devel@gmail.com>
- * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
- */
-
-// Network topology
-// //
-// // n0 R n1
-// // | _ |
-// // ====|_|====
-// // router
-// // - R sends RA to n0's subnet (2001:1::/64 and 2001:ABCD::/64);
-// // - R interface to n0 has two addresses with following prefixes 2001:1::/64 and 2001:ABCD::/64;
-// // - R sends RA to n1's subnet (2001:2::/64);
-// // - n0 ping6 n1.
-// //
-// // - Tracing of queues and packet receptions to file "radvd-two-prefix.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-#include "ns3/ipv6-routing-table-entry.h"
-#include "ns3/radvd.h"
-#include "ns3/radvd-interface.h"
-#include "ns3/radvd-prefix.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("RadvdExample");
-
-/**
- * \class StackHelper
- * \brief Helper to set or get some IPv6 information about nodes.
- */
-class StackHelper
-{
- public:
- /**
- * \brief Add an address to a IPv6 node.
- * \param n node
- * \param interface interface index
- * \param address IPv6 address to add
- */
- inline void AddAddress (Ptr<Node>& n, uint32_t interface, Ipv6Address address)
- {
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
- ipv6->AddAddress (interface, address);
- }
-
- /**
- * \brief Print the routing table.
- * \param n the node
- */
- inline void PrintRoutingTable (Ptr<Node>& n)
- {
- Ptr<Ipv6StaticRouting> routing = 0;
- Ipv6StaticRoutingHelper routingHelper;
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
- uint32_t nbRoutes = 0;
- Ipv6RoutingTableEntry route;
-
- routing = routingHelper.GetStaticRouting (ipv6);
-
- std::cout << "Routing table of " << n << " : " << std::endl;
- std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
-
- nbRoutes = routing->GetNRoutes ();
- for (uint32_t i = 0 ; i < nbRoutes ; i++)
- {
- route = routing->GetRoute (i);
- std::cout << route.GetDest () << "\t"
- << route.GetGateway () << "\t"
- << route.GetInterface () << "\t"
- << route.GetPrefixToUse () << "\t"
- << std::endl;
- }
- }
-};
-
-int main (int argc, char** argv)
-{
-#if 0
- LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
- LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
- LogComponentEnable ("RadvdApplication", LOG_LEVEL_ALL);
- LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- Ptr<Node> n0 = CreateObject<Node> ();
- Ptr<Node> r = CreateObject<Node> ();
- Ptr<Node> n1 = CreateObject<Node> ();
-
- NodeContainer net1 (n0, r);
- NodeContainer net2 (r, n1);
- NodeContainer all (n0, r, n1);
- StackHelper stackHelper;
-
- NS_LOG_INFO ("Create IPv6 Internet Stack");
- InternetStackHelper internetv6;
- internetv6.Install (all);
-
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer d1 = csma.Install (net1); /* n0 - R */
- NetDeviceContainer d2 = csma.Install (net2); /* R - n1 */
-
- NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
- Ipv6AddressHelper ipv6;
-
- /* first subnet */
- ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
- NetDeviceContainer tmp;
- tmp.Add (d1.Get (0)); /* n0 */
- Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (tmp); /* n0 interface */
-
- NetDeviceContainer tmp2;
- tmp2.Add (d1.Get (1)); /* R */
- Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
- iicr1.SetRouter (0, true);
- iic1.Add (iicr1);
-
- /* add another IPv6 address for second prefix advertised on first subnet */
- stackHelper.AddAddress (r, iic1.GetInterfaceIndex (1), Ipv6Address ("2001:ABCD::2"));
-
- /* second subnet R - n1 */
- ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
- NetDeviceContainer tmp3;
- tmp3.Add (d2.Get (0)); /* R */
- Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
- iicr2.SetRouter (0, true);
-
- NetDeviceContainer tmp4;
- tmp4.Add (d2.Get (1)); /* n1 */
- Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (tmp4);
- iic2.Add (iicr2);
-
- /* radvd configuration */
- Ipv6Address prefix ("2001:ABCD::0"); /* create the prefix */
- Ipv6Address prefixBis ("2001:1::0"); /* create the prefix */
- Ipv6Address prefix2 ("2001:2::0"); /* create the prefix */
- uint32_t indexRouter = iic1.GetInterfaceIndex (1); /* R interface (n0 - R) */
- uint32_t indexRouter2 = iic2.GetInterfaceIndex (1); /* R interface (R - n1) */
- Ptr<Radvd> radvd = CreateObject<Radvd> ();
- Ptr<RadvdInterface> routerInterface = Create<RadvdInterface> (indexRouter, 2000, 1000);
- Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix> (prefix, 64, 3, 5);
- Ptr<RadvdPrefix> routerPrefixBis = Create<RadvdPrefix> (prefixBis, 64, 3, 5);
- Ptr<RadvdInterface> routerInterface2 = Create<RadvdInterface> (indexRouter2, 2000, 1000);
- Ptr<RadvdPrefix> routerPrefix2 = Create<RadvdPrefix> (prefix2, 64, 3, 5);
-
- /* first interface advertise two prefixes (2001:1::/64 and 2001:ABCD::/64) */
- /* prefix is added in the inverse order in packet */
- routerInterface->AddPrefix (routerPrefix);
- routerInterface->AddPrefix (routerPrefixBis);
- routerInterface2->AddPrefix (routerPrefix2);
- radvd->AddConfiguration (routerInterface);
- radvd->AddConfiguration (routerInterface2);
-
- r->AddApplication (radvd);
- radvd->Start (Seconds (1.0));
- radvd->Stop (Seconds (2.0));
-
- /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 8;
- Time interPacketInterval = Seconds (1.);
- Ping6Helper ping6;
-
- /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
- ping6.SetRemote (Ipv6Address ("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
- ping6.SetIfIndex (iic1.GetInterfaceIndex (0));
-
- ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
- ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
- ApplicationContainer apps = ping6.Install (net1.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (9.0));
-
- /* RA should be received, two prefixes + routes + default route should be present */
- Simulator::Schedule (Seconds (2.0), &StackHelper::PrintRoutingTable, &stackHelper, n0);
- /* at the end, RA addresses and routes should be cleared */
- Simulator::Schedule (Seconds (10.0), &StackHelper::PrintRoutingTable, &stackHelper, n0);
-
- std::ofstream ascii;
- ascii.open ("radvd-two-prefix.tr");
- CsmaHelper::EnablePcapAll (std::string ("radvd-two-prefix"), true);
- CsmaHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
-
--- a/examples/radvd.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Strasbourg University
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: David Gross <gdavid.devel@gmail.com>
- * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
- */
-
-// Network topology
-// //
-// // n0 R n1
-// // | _ |
-// // ====|_|====
-// // router
-// // - R sends RA to n0's subnet (2001:1::/64);
-// // - R sends RA to n1's subnet (2001:2::/64);
-// // - n0 ping6 n1.
-// //
-// // - Tracing of queues and packet receptions to file "radvd.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-#include "ns3/radvd.h"
-#include "ns3/radvd-interface.h"
-#include "ns3/radvd-prefix.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("RadvdExample");
-
-int main (int argc, char** argv)
-{
-#if 0
- LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6RawSocketImpl", LOG_LEVEL_ALL);
- LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
- LogComponentEnable ("RadvdApplication", LOG_LEVEL_ALL);
- LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- Ptr<Node> n0 = CreateObject<Node> ();
- Ptr<Node> r = CreateObject<Node> ();
- Ptr<Node> n1 = CreateObject<Node> ();
-
- NodeContainer net1 (n0, r);
- NodeContainer net2 (r, n1);
- NodeContainer all (n0, r, n1);
-
- NS_LOG_INFO ("Create IPv6 Internet Stack");
- InternetStackHelper internetv6;
- internetv6.Install (all);
-
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer d1 = csma.Install (net1); /* n0 - R */
- NetDeviceContainer d2 = csma.Install (net2); /* R - n1 */
-
- NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
- Ipv6AddressHelper ipv6;
-
- /* first subnet */
- ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
- NetDeviceContainer tmp;
- tmp.Add (d1.Get (0)); /* n0 */
- Ipv6InterfaceContainer iic1 = ipv6.AssignWithoutAddress (tmp); /* n0 interface */
-
- NetDeviceContainer tmp2;
- tmp2.Add (d1.Get (1)); /* R */
- Ipv6InterfaceContainer iicr1 = ipv6.Assign (tmp2); /* R interface to the first subnet is just statically assigned */
- iicr1.SetRouter (0, true);
- iic1.Add (iicr1);
-
- /* second subnet R - n1 */
- ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
- NetDeviceContainer tmp3;
- tmp3.Add (d2.Get (0)); /* R */
- Ipv6InterfaceContainer iicr2 = ipv6.Assign (tmp3); /* R interface */
- iicr2.SetRouter (0, true);
-
- NetDeviceContainer tmp4;
- tmp4.Add (d2.Get (1)); /* n1 */
- Ipv6InterfaceContainer iic2 = ipv6.AssignWithoutAddress (tmp4);
- iic2.Add (iicr2);
-
- /* radvd configuration */
- Ipv6Address prefix ("2001:1::0"); /* create the prefix */
- Ipv6Address prefix2 ("2001:2::0"); /* create the prefix */
- uint32_t indexRouter = iic1.GetInterfaceIndex (1); /* R interface (n0 - R) */
- uint32_t indexRouter2 = iic2.GetInterfaceIndex (1); /* R interface (R - n1) */
- Ptr<Radvd> radvd = CreateObject<Radvd> ();
- Ptr<RadvdInterface> routerInterface = Create<RadvdInterface> (indexRouter, 5000, 1000);
- Ptr<RadvdPrefix> routerPrefix = Create<RadvdPrefix> (prefix, 64, 3, 5);
- Ptr<RadvdInterface> routerInterface2 = Create<RadvdInterface> (indexRouter2, 5000, 1000);
- Ptr<RadvdPrefix> routerPrefix2 = Create<RadvdPrefix> (prefix2, 64, 3, 5);
-
- routerInterface->AddPrefix (routerPrefix);
- routerInterface2->AddPrefix (routerPrefix2);
- radvd->AddConfiguration (routerInterface);
- radvd->AddConfiguration (routerInterface2);
-
- r->AddApplication (radvd);
- radvd->Start (Seconds (1.0));
- radvd->Stop (Seconds (10.0));
-
- /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via R */
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 5;
- Time interPacketInterval = Seconds (1.);
- Ping6Helper ping6;
-
- /* ping6.SetLocal (iic1.GetAddress (0, 1)); */
- ping6.SetRemote (Ipv6Address ("2001:2::200:ff:fe00:4")); /* should be n1 address after autoconfiguration */
- ping6.SetIfIndex (iic1.GetInterfaceIndex (0));
-
- ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
- ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
- ApplicationContainer apps = ping6.Install (net1.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (7.0));
-
- std::ofstream ascii;
- ascii.open ("radvd.tr");
- CsmaHelper::EnablePcapAll (std::string ("radvd"), true);
- CsmaHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
-
--- a/examples/realtime-udp-echo.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// n0 n1 n2 n3
-// | | | |
-// =================
-// LAN
-//
-// - UDP flows from n0 to n1 and back
-// - DropTail queues
-// - Tracing of queues and packet receptions to file "udp-echo.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("RealtimeUdpEchoExample");
-
-int
-main (int argc, char *argv[])
-{
- //
- // Allow the user to override any of the defaults and the above Bind() at
- // run-time, via command-line arguments
- //
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- //
- // But since this is a realtime script, don't allow the user to mess with
- // that.
- //
- GlobalValue::Bind ("SimulatorImplementationType",
- StringValue ("ns3::RealtimeSimulatorImpl"));
-
- //
- // Explicitly create the nodes required by the topology (shown above).
- //
- NS_LOG_INFO ("Create nodes.");
- NodeContainer n;
- n.Create (4);
-
- InternetStackHelper internet;
- internet.Install (n);
-
- //
- // Explicitly create the channels required by the topology (shown above).
- //
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
- NetDeviceContainer d = csma.Install (n);
-
- //
- // We've got the "hardware" in place. Now we need to add IP addresses.
- //
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i = ipv4.Assign (d);
-
- NS_LOG_INFO ("Create Applications.");
-
- //
- // Create a UdpEchoServer application on node one.
- //
- uint16_t port = 9; // well-known echo port number
- UdpEchoServerHelper server (port);
- ApplicationContainer apps = server.Install (n.Get(1));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- //
- // Create a UdpEchoClient application to send UDP datagrams from node zero to
- // node one.
- //
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 500;
- Time interPacketInterval = Seconds (0.01);
- UdpEchoClientHelper client (i.GetAddress (1), port);
- client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- client.SetAttribute ("Interval", TimeValue (interPacketInterval));
- client.SetAttribute ("PacketSize", UintegerValue (packetSize));
- apps = client.Install (n.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("realtime-udp-echo.tr");
- CsmaHelper::EnablePcapAll ("realtime-udp-echo", false);
- CsmaHelper::EnableAsciiAll (ascii);
-
- //
- // Now, do the actual simulation.
- //
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/realtime/realtime-udp-echo.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,120 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+// - UDP flows from n0 to n1 and back
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "udp-echo.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("RealtimeUdpEchoExample");
+
+int
+main (int argc, char *argv[])
+{
+ //
+ // Allow the user to override any of the defaults and the above Bind() at
+ // run-time, via command-line arguments
+ //
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ //
+ // But since this is a realtime script, don't allow the user to mess with
+ // that.
+ //
+ GlobalValue::Bind ("SimulatorImplementationType",
+ StringValue ("ns3::RealtimeSimulatorImpl"));
+
+ //
+ // Explicitly create the nodes required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer n;
+ n.Create (4);
+
+ InternetStackHelper internet;
+ internet.Install (n);
+
+ //
+ // Explicitly create the channels required by the topology (shown above).
+ //
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
+ NetDeviceContainer d = csma.Install (n);
+
+ //
+ // We've got the "hardware" in place. Now we need to add IP addresses.
+ //
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (d);
+
+ NS_LOG_INFO ("Create Applications.");
+
+ //
+ // Create a UdpEchoServer application on node one.
+ //
+ uint16_t port = 9; // well-known echo port number
+ UdpEchoServerHelper server (port);
+ ApplicationContainer apps = server.Install (n.Get(1));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ //
+ // Create a UdpEchoClient application to send UDP datagrams from node zero to
+ // node one.
+ //
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 500;
+ Time interPacketInterval = Seconds (0.01);
+ UdpEchoClientHelper client (i.GetAddress (1), port);
+ client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ client.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ client.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ apps = client.Install (n.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("realtime-udp-echo.tr");
+ CsmaHelper::EnablePcapAll ("realtime-udp-echo", false);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ //
+ // Now, do the actual simulation.
+ //
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/realtime/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/realtime/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,5 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('realtime-udp-echo', ['csma', 'internet-stack'])
+ obj.source = 'realtime-udp-echo.cc'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/dynamic-global-routing.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,231 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Contributed by: Luis Cortes (cortes@gatech.edu)
+ */
+
+
+// This script exercises global routing code in a mixed point-to-point
+// and csma/cd environment
+//
+// Network topology
+//
+// n0
+// \ p-p
+// \ (shared csma/cd)
+// n2 -------------------------n3
+// / | |
+// / p-p n4 n5 ---------- n6
+// n1 p-p
+// | |
+// ----------------------------------------
+// p-p
+//
+// - at time 1 CBR/UDP flow from n1 to n6's IP address on the n5/n6 link
+// - at time 10, start similar flow from n1 to n6's address on the n1/n6 link
+//
+// Order of events
+// At pre-simulation time, configure global routes. Shortest path from
+// n1 to n6 is via the direct point-to-point link
+// At time 1s, start CBR traffic flow from n1 to n6
+// At time 2s, set the n1 point-to-point interface to down. Packets
+// will start to be dropped
+// At time 3s, call RecomputeRoutingTables() and traffic will
+// start flowing again on the alternate path
+// At time 4s, re-enable the n1/n6 interface to up. Will not change routing
+// At time 5s, call RecomputeRoutingTables() and traffic will start flowing
+// again on the original path
+// At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this
+// keeps the point-to-point link "up" from n1's perspective). Packets
+// will traverse the link and be dropped at n6 upon receipt. These drops
+// are not visible in the pcap trace but in the ascii trace.
+// At time 7s, call RecomputeRoutingTables() and traffic will flow again
+// through the path n1-n2-n5-n6
+// At time 8s, bring the interface back up.
+// At time 9s, call RecomputeRoutingTables() and traffic will flow again
+// through the path n1-n6
+// At time 10s, stop the first flow.
+// At time 11s, start a new flow, but to n6's other IP address (the one
+// on the n1/n6 p2p link)
+// At time 12s, bring the n1 interface down between n1 and n6. Packets
+// will start to be dropped
+// At time 13s, call RecomputeRoutingTables() and traffic will
+// start flowing again on the alternate path
+// At time 14s, re-enable the n1/n6 interface to up. This will change
+// routing back to n1-n6 since the interface up notification will cause
+// a new local interface route, at higher priority than global routing
+// At time 15s, call RecomputeRoutingTables(), but there is no effect
+// since global routing is lower in priority than static routing
+// At time 16s, stop the second flow.
+
+// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("DynamicGlobalRoutingExample");
+
+int
+main (int argc, char *argv[])
+{
+ // Allow the user to override any of the defaults and the above
+ // Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (7);
+ NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
+ NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
+ NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6));
+ NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+ NetDeviceContainer d1d6 = p2p.Install (n1n6);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d5d6 = p2p.Install (n5n6);
+
+ // We create the channels first without any IP addressing information
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
+ csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d2345 = csma.Install (n2345);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
+
+ ipv4.SetBase ("10.250.1.0", "255.255.255.0");
+ ipv4.Assign (d2345);
+
+ ipv4.SetBase ("172.16.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ InetSocketAddress (i5i6.GetAddress (1), port));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", StringValue ("2kbps"));
+ onoff.SetAttribute ("PacketSize", UintegerValue (50));
+
+ ApplicationContainer apps = onoff.Install (c.Get (1));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a second OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ OnOffHelper onoff2 ("ns3::UdpSocketFactory",
+ InetSocketAddress (i1i6.GetAddress (1), port));
+ onoff2.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff2.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff2.SetAttribute ("DataRate", StringValue ("2kbps"));
+ onoff2.SetAttribute ("PacketSize", UintegerValue (50));
+
+ ApplicationContainer apps2 = onoff2.Install (c.Get (1));
+ apps2.Start (Seconds (11.0));
+ apps2.Stop (Seconds (16.0));
+
+ // Create an optional packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (6));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ PacketSinkHelper sink2 ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps2 = sink2.Install (c.Get (6));
+ apps2.Start (Seconds (11.0));
+ apps2.Stop (Seconds (16.0));
+
+
+ std::ofstream ascii;
+ ascii.open ("dynamic-global-routing.tr", std::ios_base::binary | std::ios_base::out);
+ PointToPointHelper::EnablePcapAll ("dynamic-global-routing");
+ PointToPointHelper::EnableAsciiAll (ascii);
+ CsmaHelper::EnablePcapAll ("dynamic-global-routing", false);
+ CsmaHelper::EnableAsciiAll (ascii);
+ InternetStackHelper::EnableAsciiAll (ascii);
+
+ Ptr<Node> n1 = c.Get (1);
+ Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
+ // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
+ // then the next p2p is numbered 2
+ uint32_t ipv4ifIndex1 = 2;
+
+ Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
+ Simulator::Schedule (Seconds (3),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+ Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
+ Simulator::Schedule (Seconds (5),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+
+ Ptr<Node> n6 = c.Get (6);
+ Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
+ // The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
+ // then the next p2p is numbered 2
+ uint32_t ipv4ifIndex6 = 2;
+ Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
+ Simulator::Schedule (Seconds (7),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+ Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
+ Simulator::Schedule (Seconds (9),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+
+ Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
+ Simulator::Schedule (Seconds (13),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+ Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
+ Simulator::Schedule (Seconds (15),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/global-injection-slash32.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,158 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+// Test program for this 3-router scenario, using global routing
+//
+// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/csma-net-device.h"
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/ipv4-static-routing.h"
+#include "ns3/ipv4-global-routing.h"
+#include "ns3/ipv4-list-routing.h"
+#include "ns3/ipv4-routing-table-entry.h"
+#include "ns3/global-router-interface.h"
+
+using namespace ns3;
+using std::cout;
+
+NS_LOG_COMPONENT_DEFINE ("GlobalRouterInjectionTest");
+
+int
+main (int argc, char *argv[])
+{
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ Ptr<Node> nA = CreateObject<Node> ();
+ Ptr<Node> nB = CreateObject<Node> ();
+ Ptr<Node> nC = CreateObject<Node> ();
+
+ NodeContainer c = NodeContainer (nA, nB, nC);
+
+ InternetStackHelper internet;
+
+ // Point-to-point links
+ NodeContainer nAnB = NodeContainer (nA, nB);
+ NodeContainer nBnC = NodeContainer (nB, nC);
+
+ internet.Install (nAnB);
+ Ipv4ListRoutingHelper staticonly;
+ Ipv4ListRoutingHelper staticRouting;
+ staticonly.Add(staticRouting, 0);
+ internet.SetRoutingHelper(staticonly);
+ internet.Install(NodeContainer(nC));
+
+ // We create the channels first without any IP addressing information
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer dAdB = p2p.Install (nAnB);
+
+ NetDeviceContainer dBdC = p2p.Install (nBnC);;
+
+ Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
+ deviceA->SetAddress (Mac48Address::Allocate ());
+ nA->AddDevice (deviceA);
+
+ Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
+ deviceC->SetAddress (Mac48Address::Allocate ());
+ nC->AddDevice (deviceC);
+
+ // Later, we add IP addresses.
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.252");
+ Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
+
+ ipv4.SetBase ("10.1.1.4", "255.255.255.252");
+ Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
+
+ Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
+ Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
+ Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
+
+ int32_t ifIndexA = ipv4A->AddInterface (deviceA);
+ int32_t ifIndexC = ipv4C->AddInterface (deviceC);
+
+ Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
+ ipv4A->AddAddress (ifIndexA, ifInAddrA);
+ ipv4A->SetMetric (ifIndexA, 1);
+ ipv4A->SetUp (ifIndexA);
+
+ Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
+ ipv4C->AddAddress (ifIndexC, ifInAddrC);
+ ipv4C->SetMetric (ifIndexC, 1);
+ ipv4C->SetUp (ifIndexC);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+
+ // Populate routing tables for nodes nA and nB
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+ // Inject global routes from Node B, including transit network...
+ Ptr<GlobalRouter> globalRouterB = nB->GetObject<GlobalRouter> ();
+ globalRouterB->InjectRoute ("10.1.1.4", "255.255.255.252");
+ // ...and the host in network "C"
+ globalRouterB->InjectRoute ("192.168.1.1", "255.255.255.255");
+
+ Ipv4GlobalRoutingHelper::RecomputeRoutingTables();
+ // In addition, nB needs a static route to nC so it knows what to do with stuff
+ // going to 192.168.1.1
+ Ipv4StaticRoutingHelper ipv4RoutingHelper;
+ Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting(ipv4B);
+ staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"),2);
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
+ ApplicationContainer apps = onoff.Install (nA);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (nC);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("global-routing-injection32.tr", std::ios_base::binary | std::ios_base::out);
+ PointToPointHelper::EnablePcapAll ("global-routing-injection32");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/global-routing-slash32.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,131 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+// Test program for this 3-router scenario, using global routing
+//
+// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/csma-net-device.h"
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("GlobalRouterSlash32Test");
+
+int
+main (int argc, char *argv[])
+{
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ Ptr<Node> nA = CreateObject<Node> ();
+ Ptr<Node> nB = CreateObject<Node> ();
+ Ptr<Node> nC = CreateObject<Node> ();
+
+ NodeContainer c = NodeContainer (nA, nB, nC);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // Point-to-point links
+ NodeContainer nAnB = NodeContainer (nA, nB);
+ NodeContainer nBnC = NodeContainer (nB, nC);
+
+ // We create the channels first without any IP addressing information
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer dAdB = p2p.Install (nAnB);
+
+ NetDeviceContainer dBdC = p2p.Install (nBnC);;
+
+ Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
+ deviceA->SetAddress (Mac48Address::Allocate ());
+ nA->AddDevice (deviceA);
+
+ Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
+ deviceC->SetAddress (Mac48Address::Allocate ());
+ nC->AddDevice (deviceC);
+
+ // Later, we add IP addresses.
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.252");
+ Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
+
+ ipv4.SetBase ("10.1.1.4", "255.255.255.252");
+ Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
+
+ Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
+ Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
+
+ int32_t ifIndexA = ipv4A->AddInterface (deviceA);
+ int32_t ifIndexC = ipv4C->AddInterface (deviceC);
+
+ Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
+ ipv4A->AddAddress (ifIndexA, ifInAddrA);
+ ipv4A->SetMetric (ifIndexA, 1);
+ ipv4A->SetUp (ifIndexA);
+
+ Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
+ ipv4C->AddAddress (ifIndexC, ifInAddrC);
+ ipv4C->SetMetric (ifIndexC, 1);
+ ipv4C->SetUp (ifIndexC);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (ifInAddrC.GetLocal(), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
+ ApplicationContainer apps = onoff.Install (nA);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (nC);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("global-routing-slash32.tr", std::ios_base::binary | std::ios_base::out);
+ PointToPointHelper::EnablePcapAll ("global-routing-slash32");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/mixed-global-routing.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,135 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+// This script exercises global routing code in a mixed point-to-point
+// and csma/cd environment
+//
+// Network topology
+//
+// n0
+// \ p-p
+// \ (shared csma/cd)
+// n2 -------------------------n3
+// / | |
+// / p-p n4 n5 ---------- n6
+// n1 p-p
+//
+// - CBR/UDP flows from n0 to n6
+// - Tracing of queues and packet receptions to file "mixed-global-routing.tr"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample");
+
+int
+main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ // Allow the user to override any of the defaults and the above
+ // Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (7);
+ NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
+ NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
+ NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d5d6 = p2p.Install (n5n6);
+
+ // We create the channels first without any IP addressing information
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
+ csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d2345 = csma.Install (n2345);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
+
+ ipv4.SetBase ("10.250.1.0", "255.255.255.0");
+ ipv4.Assign (d2345);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ InetSocketAddress (i5i6.GetAddress (1), port));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", StringValue ("300bps"));
+ onoff.SetAttribute ("PacketSize", UintegerValue (50));
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("mixed-global-routing.tr");
+ PointToPointHelper::EnablePcapAll ("mixed-global-routing");
+ PointToPointHelper::EnableAsciiAll (ascii);
+ CsmaHelper::EnablePcapAll ("mixed-global-routing", false);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/nix-simple.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,114 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+/*
+ * Simple point to point links:
+ *
+ * n0 -- n1 -- n2 -- n3
+ *
+ * n0 has UdpEchoClient
+ * n3 has UdpEchoServer
+ *
+ * n0 IP: 10.1.1.1
+ * n1 IP: 10.1.1.2, 10.1.2.1
+ * n2 IP: 10.1.2.2, 10.1.3.1
+ * n3 IP: 10.1.3.2
+ *
+ */
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
+
+ int
+main (int argc, char *argv[])
+{
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
+
+ NodeContainer nodes12;
+ nodes12.Create (2);
+
+ NodeContainer nodes23;
+ nodes23.Add (nodes12.Get (1));
+ nodes23.Create (1);
+
+ NodeContainer nodes34;
+ nodes34.Add(nodes23.Get (1));
+ nodes34.Create (1);
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ NodeContainer allNodes = NodeContainer (nodes12, nodes23.Get (1), nodes34.Get (1));
+
+ // NixHelper to install nix-vector routing
+ // on all nodes
+ Ipv4NixVectorHelper nixRouting;
+ Ipv4StaticRoutingHelper staticRouting;
+
+ Ipv4ListRoutingHelper list;
+ list.Add (staticRouting, 0);
+ list.Add (nixRouting, 10);
+
+ InternetStackHelper stack;
+ stack.SetRoutingHelper (list);
+ stack.Install (allNodes);
+
+ NetDeviceContainer devices12;
+ NetDeviceContainer devices23;
+ NetDeviceContainer devices34;
+ devices12 = pointToPoint.Install (nodes12);
+ devices23 = pointToPoint.Install (nodes23);
+ devices34 = pointToPoint.Install (nodes34);
+
+ Ipv4AddressHelper address1;
+ address1.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4AddressHelper address2;
+ address2.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4AddressHelper address3;
+ address3.SetBase ("10.1.3.0", "255.255.255.0");
+
+ address1.Assign (devices12);
+ address2.Assign (devices23);
+ Ipv4InterfaceContainer interfaces = address3.Assign (devices34);
+
+ UdpEchoServerHelper echoServer (9);
+
+ ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
+ serverApps.Start (Seconds (1.0));
+ serverApps.Stop (Seconds (10.0));
+
+ UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+
+ ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
+ clientApps.Start (Seconds (2.0));
+ clientApps.Stop (Seconds (10.0));
+
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/nms-p2p-nix.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,458 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+// DARPA NMS Campus Network Model
+//
+// - This topology replicates the original NMS Campus Network model
+// with the exception of chord links (which were never utilized in the
+// original model)
+// - Link Bandwidths and Delays may not be the same as the original
+// specifications
+//
+// (c)2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
+
+// for timing functions
+#include <cstdlib>
+#include <sys/time.h>
+#include <fstream>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/global-routing-module.h"
+#include "ns3/onoff-application.h"
+#include "ns3/packet-sink.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/simulator.h"
+
+using namespace std;
+using namespace ns3;
+
+typedef struct timeval TIMER_TYPE;
+#define TIMER_NOW(_t) gettimeofday(&_t,NULL);
+#define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
+#define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS(_t1)-TIMER_SECONDS(_t2))
+
+NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
+
+void Progress ()
+{
+ Time now = Simulator::Now ();
+ Simulator::Schedule (Seconds (0.1), Progress);
+}
+
+int
+main (int argc, char *argv[])
+{
+ //Config::SetDefault ("ns3::Simulator::SchedulerType", StringValue ("ns3::CalendarScheduler"));
+ TIMER_TYPE t0, t1, t2;
+ TIMER_NOW(t0);
+ cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
+ LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
+
+ //RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
+
+ int nCN = 2, nLANClients = 42;
+ bool nix = true;
+
+ CommandLine cmd;
+ cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
+ cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
+ cmd.AddValue ("NIX", "Toggle nix-vector routing", nix);
+ cmd.Parse (argc,argv);
+
+ if (nCN < 2)
+ {
+ cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
+ << endl;
+ return 1;
+ }
+
+ cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << endl;
+
+ NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
+ nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
+ nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
+ PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
+ InternetStackHelper stack;
+ Ipv4InterfaceContainer ifs, ifs0[nCN][3], ifs1[nCN][6], ifs2[nCN][14],
+ ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
+ ifs3LAN[nCN][5][nLANClients];
+ Ipv4AddressHelper address;
+ std::ostringstream oss;
+ p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
+ p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
+ p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
+ p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
+ p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
+ p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
+
+ // Setup NixVector Routing
+ Ipv4NixVectorHelper nixRouting;
+ Ipv4StaticRoutingHelper staticRouting;
+
+ Ipv4ListRoutingHelper list;
+ list.Add (staticRouting, 0);
+ list.Add (nixRouting, 10);
+
+ if (nix)
+ {
+ stack.SetRoutingHelper (list);
+ }
+
+ // Create Campus Networks
+ for (int z = 0; z < nCN; ++z)
+ {
+ cout << "Creating Campus Network " << z << ":" << endl;
+ // Create Net0
+ cout << " SubNet [ 0";
+ for (int i = 0; i < 3; ++i)
+ {
+ nodes_net0[z][i].Create (1);
+ stack.Install (nodes_net0[z][i]);
+ }
+ nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
+ nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
+ nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
+ NetDeviceContainer ndc0[3];
+ for (int i = 0; i < 3; ++i)
+ {
+ ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
+ }
+ // Create Net1
+ cout << " 1";
+ for (int i = 0; i < 6; ++i)
+ {
+ nodes_net1[z][i].Create (1);
+ stack.Install (nodes_net1[z][i]);
+ }
+ nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
+ nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
+ nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
+ nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
+ nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
+ NetDeviceContainer ndc1[6];
+ for (int i = 0; i < 6; ++i)
+ {
+ if (i == 1)
+ {
+ continue;
+ }
+ ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
+ }
+ // Connect Net0 <-> Net1
+ NodeContainer net0_1;
+ net0_1.Add (nodes_net0[z][2].Get (0));
+ net0_1.Add (nodes_net1[z][0].Get (0));
+ NetDeviceContainer ndc0_1;
+ ndc0_1 = p2p_1gb5ms.Install (net0_1);
+ oss.str("");
+ oss << 10 + z << ".1.252.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc0_1);
+ // Create Net2
+ cout << " 2";
+ for (int i = 0; i < 14; ++i)
+ {
+ nodes_net2[z][i].Create (1);
+ stack.Install (nodes_net2[z][i]);
+ }
+ nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
+ nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
+ nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
+ nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
+ nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
+ nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
+ nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
+ nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
+ nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
+ nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
+ nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
+ nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
+ nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
+ nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
+ NetDeviceContainer ndc2[14];
+ for (int i = 0; i < 14; ++i)
+ {
+ ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
+ }
+ NetDeviceContainer ndc2LAN[7][nLANClients];
+ for (int i = 0; i < 7; ++i)
+ {
+ oss.str ("");
+ oss << 10 + z << ".4." << 15 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ for (int j = 0; j < nLANClients; ++j)
+ {
+ nodes_net2LAN[z][i][j].Create (1);
+ stack.Install (nodes_net2LAN[z][i][j]);
+ nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
+ ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
+ ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
+ }
+ }
+ // Create Net3
+ cout << " 3 ]" << endl;
+ for (int i = 0; i < 9; ++i)
+ {
+ nodes_net3[z][i].Create (1);
+ stack.Install(nodes_net3[z][i]);
+ }
+ nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
+ nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
+ nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
+ nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
+ nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
+ nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
+ nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
+ nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
+ nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
+ NetDeviceContainer ndc3[9];
+ for (int i = 0; i < 9; ++i)
+ {
+ ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
+ }
+ NetDeviceContainer ndc3LAN[5][nLANClients];
+ for (int i = 0; i < 5; ++i)
+ {
+ oss.str ("");
+ oss << 10 + z << ".5." << 10 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.255");
+ for (int j = 0; j < nLANClients; ++j)
+ {
+ nodes_net3LAN[z][i][j].Create (1);
+ stack.Install (nodes_net3LAN[z][i][j]);
+ nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
+ ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
+ ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
+ }
+ }
+ cout << " Connecting Subnets..." << endl;
+ // Create Lone Routers (Node 4 & 5)
+ nodes_netLR[z].Create (2);
+ stack.Install (nodes_netLR[z]);
+ NetDeviceContainer ndcLR;
+ ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
+ // Connect Net2/Net3 through Lone Routers to Net0
+ NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
+ net0_4.Add (nodes_netLR[z].Get (0));
+ net0_4.Add (nodes_net0[z][0].Get (0));
+ net0_5.Add (nodes_netLR[z].Get (1));
+ net0_5.Add (nodes_net0[z][1].Get (0));
+ net2_4a.Add (nodes_netLR[z].Get (0));
+ net2_4a.Add (nodes_net2[z][0].Get (0));
+ net2_4b.Add (nodes_netLR[z].Get (1));
+ net2_4b.Add (nodes_net2[z][1].Get (0));
+ net3_5a.Add (nodes_netLR[z].Get (1));
+ net3_5a.Add (nodes_net3[z][0].Get (0));
+ net3_5b.Add (nodes_netLR[z].Get (1));
+ net3_5b.Add (nodes_net3[z][1].Get (0));
+ NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
+ ndc0_4 = p2p_1gb5ms.Install (net0_4);
+ oss.str ("");
+ oss << 10 + z << ".1.253.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc0_4);
+ ndc0_5 = p2p_1gb5ms.Install (net0_5);
+ oss.str ("");
+ oss << 10 + z << ".1.254.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc0_5);
+ ndc2_4a = p2p_1gb5ms.Install (net2_4a);
+ oss.str ("");
+ oss << 10 + z << ".4.253.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc2_4a);
+ ndc2_4b = p2p_1gb5ms.Install (net2_4b);
+ oss.str ("");
+ oss << 10 + z << ".4.254.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc2_4b);
+ ndc3_5a = p2p_1gb5ms.Install (net3_5a);
+ oss.str ("");
+ oss << 10 + z << ".5.253.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc3_5a);
+ ndc3_5b = p2p_1gb5ms.Install (net3_5b);
+ oss.str ("");
+ oss << 10 + z << ".5.254.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc3_5b);
+ // Assign IP addresses
+ cout << " Assigning IP addresses..." << endl;
+ for (int i = 0; i < 3; ++i)
+ {
+ oss.str ("");
+ oss << 10 + z << ".1." << 1 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs0[z][i] = address.Assign (ndc0[i]);
+ }
+ for (int i = 0; i < 6; ++i)
+ {
+ if (i == 1)
+ {
+ continue;
+ }
+ oss.str ("");
+ oss << 10 + z << ".2." << 1 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs1[z][i] = address.Assign (ndc1[i]);
+ }
+ oss.str ("");
+ oss << 10 + z << ".3.1.0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndcLR);
+ for (int i = 0; i < 14; ++i)
+ {
+ oss.str ("");
+ oss << 10 + z << ".4." << 1 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs2[z][i] = address.Assign (ndc2[i]);
+ }
+ for (int i = 0; i < 9; ++i)
+ {
+ oss.str ("");
+ oss << 10 + z << ".5." << 1 + i << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs3[z][i] = address.Assign (ndc3[i]);
+ }
+ }
+ // Create Ring Links
+ if (nCN > 1)
+ {
+ cout << "Forming Ring Topology..." << endl;
+ NodeContainer nodes_ring[nCN];
+ for (int z = 0; z < nCN-1; ++z)
+ {
+ nodes_ring[z].Add (nodes_net0[z][0].Get (0));
+ nodes_ring[z].Add (nodes_net0[z+1][0].Get (0));
+ }
+ nodes_ring[nCN-1].Add (nodes_net0[nCN-1][0].Get (0));
+ nodes_ring[nCN-1].Add (nodes_net0[0][0].Get (0));
+ NetDeviceContainer ndc_ring[nCN];
+ for (int z = 0; z < nCN; ++z)
+ {
+ ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
+ oss.str ("");
+ oss << "254.1." << z + 1 << ".0";
+ address.SetBase (oss.str ().c_str (), "255.255.255.0");
+ ifs = address.Assign (ndc_ring[z]);
+ }
+ }
+
+ // Create Traffic Flows
+ cout << "Creating TCP Traffic Flows:" << endl;
+ Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
+ Config::SetDefault ("ns3::OnOffApplication::OnTime",
+ RandomVariableValue (ConstantVariable (1)));
+ Config::SetDefault ("ns3::OnOffApplication::OffTime",
+ RandomVariableValue (ConstantVariable (0)));
+ Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
+
+ UniformVariable urng;
+ int r1;
+ double r2;
+ for (int z = 0; z < nCN; ++z)
+ {
+ int x = z + 1;
+ if (z == nCN - 1)
+ {
+ x = 0;
+ }
+ // Subnet 2 LANs
+ cout << " Campus Network " << z << " Flows [ Net2 ";
+ for (int i = 0; i < 7; ++i)
+ {
+ for (int j = 0; j < nLANClients; ++j)
+ {
+ // Sinks
+ PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), 9999));
+ ApplicationContainer sinkApp = sinkHelper.Install (
+ nodes_net2LAN[z][i][j].Get (0));
+ sinkApp.Start (Seconds (100.0));
+ // Sources
+ r1 = 2 + (int)(4 * urng.GetValue ());
+ r2 = 100 + (10 * urng.GetValue ());;
+ OnOffHelper client ("ns3::TcpSocketFactory", Address ());
+ AddressValue remoteAddress(InetSocketAddress (
+ ifs2LAN[z][i][j].GetAddress (0), 9999));
+ client.SetAttribute ("Remote", remoteAddress);
+ ApplicationContainer clientApp;
+ clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
+ clientApp.Start (Seconds (r2));
+ }
+ }
+ // Subnet 3 LANs
+ cout << "Net3 ]" << endl;
+ for (int i = 0; i < 5; ++i)
+ {
+ for (int j = 0; j < nLANClients; ++j)
+ {
+ // Sinks
+ PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), 9999));
+ ApplicationContainer sinkApp = sinkHelper.Install (
+ nodes_net3LAN[z][i][j].Get (0));
+ sinkApp.Start (Seconds (100.0));
+ // Sources
+ r1 = 2 + (int)(4 * urng.GetValue ());
+ r2 = 100 + (10 * urng.GetValue ());;
+ OnOffHelper client ("ns3::TcpSocketFactory", Address ());
+ AddressValue remoteAddress (InetSocketAddress (
+ ifs2LAN[z][i][j].GetAddress (0), 9999));
+ client.SetAttribute ("Remote", remoteAddress);
+ ApplicationContainer clientApp;
+ clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
+ clientApp.Start (Seconds (r2));
+ }
+ }
+ }
+
+ cout << "Created " << NodeList::GetNNodes () << " nodes." << endl;
+ TIMER_TYPE routingStart;
+ TIMER_NOW (routingStart);
+
+ if (nix)
+ {
+ // Calculate routing tables
+ cout << "Using Nix-vectors..." << endl;
+ }
+ else
+ {
+ // Calculate routing tables
+ cout << "Populating Global Static Routing Tables..." << endl;
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+ }
+
+ TIMER_TYPE routingEnd;
+ TIMER_NOW (routingEnd);
+ cout << "Routing tables population took "
+ << TIMER_DIFF (routingEnd, routingStart) << endl;
+#if 0
+ std::ofstream ascii;
+ ascii.open("nms_p2p_nix.tr");
+ PointToPointHelper::EnableAsciiAll(ascii);
+ CsmaHelper::EnableAsciiAll(ascii);
+#endif
+
+#if 0
+ PointToPointHelper::EnablePcapAll("nms_p2p");
+ CsmaHelper::EnablePcapAll("nms_csma");
+#endif
+
+ Simulator::ScheduleNow (Progress);
+ cout << "Running simulator..." << endl;
+ TIMER_NOW (t1);
+ Simulator::Stop (Seconds (200.0));
+ Simulator::Run ();
+ TIMER_NOW (t2);
+ cout << "Simulator finished." << endl;
+ Simulator::Destroy ();
+
+ double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
+ cout << "-----" << endl << "Runtime Stats:" << endl;
+ cout << "Simulator init time: " << d1 << endl;
+ cout << "Simulator run time: " << d2 << endl;
+ cout << "Total elapsed time: " << d1+d2 << endl;
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/simple-alternate-routing.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,166 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 ------------------------n3
+// / /
+// / 5 Mb/s, 2ms /
+// n1--------------------------
+// 1.5 Mb/s, 100ms
+//
+// this is a modification of simple-global-routing to allow for
+// a single hop but higher-cost path between n1 and n3
+//
+// - Tracing of queues and packet receptions to file "simple-rerouting.tr"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleAlternateRoutingExample");
+
+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
+#if 0
+ LogComponentEnable("GlobalRoutingHelper", LOG_LOGIC);
+ LogComponentEnable("GlobalRouter", LOG_LOGIC);
+#endif
+
+
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("300b/s"));
+
+ // The below metric, if set to 3 or higher, will cause packets between
+ // n1 and n3 to take the 2-hop route through n2
+
+ CommandLine cmd;
+ //
+ // Additionally, we plumb this metric into the default value / command
+ // line argument system as well, for exemplary purposes. This means
+ // that it can be resettable at the command-line to the program,
+ // rather than recompiling
+ // e.g. waf --run "simple-alternate-routing --AlternateCost=5"
+ uint16_t sampleMetric = 1;
+ cmd.AddValue ("AlternateCost",
+ "This metric is used in the example script between n3 and n1 ",
+ sampleMetric);
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+ NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
+ NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
+ NodeContainer n1n3 = NodeContainer (c.Get (1), c.Get (3));
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d3d2 = p2p.Install (n3n2);
+
+ p2p.SetChannelAttribute ("Delay", StringValue ("100ms"));
+ NetDeviceContainer d1d3 = p2p.Install (n1n3);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // Later, we add IP addresses. The middle two octets correspond to
+ // the channel number.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.0.0.0", "255.255.255.0");
+ ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.2.2.0", "255.255.255.0");
+ ipv4.Assign (d3d2);
+
+ ipv4.SetBase ("10.3.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i3 = ipv4.Assign (d1d3);
+
+ i1i3.SetMetric (0, sampleMetric);
+ i1i3.SetMetric (1, sampleMetric);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams
+ NS_LOG_INFO ("Create Application.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ // Create a flow from n3 to n1, starting at time 1.1 seconds
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (i1i2.GetAddress (0), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer apps = onoff.Install (c.Get (3));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("simple-alternate-routing.tr");
+ PointToPointHelper::EnablePcapAll ("simple-alternate-routing");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/simple-global-routing.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,173 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ns-2 simple.tcl script (ported from ns-2)
+ * Originally authored by Steve McCanne, 12/19/1996
+ */
+
+// Port of ns-2/tcl/ex/simple.tcl to ns-3
+//
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 -------------------------n3
+// /
+// / 5 Mb/s, 2ms
+// n1
+//
+// - all links are point-to-point links with indicated one-way BW/delay
+// - CBR/UDP flows from n0 to n3, and from n3 to n1
+// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
+// - 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 "simple-global-routing.tr"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
+
+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
+#if 0
+ LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
+#endif
+
+ // Set up some default values for the simulation. Use the
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ bool enableFlowMonitor = false;
+ cmd.AddValue("EnableMonitor", "Enable Flow Monitor", enableFlowMonitor);
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+ NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
+ NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d3d2 = p2p.Install (n3n2);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (i3i2.GetAddress (0), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a similar flow from n3 to n1, starting at time 1.1 seconds
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
+ apps = onoff.Install (c.Get (3));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("simple-global-routing.tr");
+ PointToPointHelper::EnablePcapAll ("simple-global-routing");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ // Flow Monitor
+ Ptr<FlowMonitor> flowmon;
+ if (enableFlowMonitor)
+ {
+ FlowMonitorHelper flowmonHelper;
+ flowmon = flowmonHelper.InstallAll ();
+ }
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Stop (Seconds (11));
+ Simulator::Run ();
+ NS_LOG_INFO ("Done.");
+
+ if (enableFlowMonitor)
+ {
+ flowmon->SerializeToXmlFile ("simple-global-routing.flowmon", false, false);
+ }
+
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/simple-point-to-point-olsr.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,173 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ns-2 simple.tcl script (ported from ns-2)
+ * Originally authored by Steve McCanne, 12/19/1996
+ */
+
+// Port of ns-2/tcl/ex/simple.tcl to ns-3
+//
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 -------------------------n3---------n4
+// /
+// / 5 Mb/s, 2ms
+// n1
+//
+// - all links are point-to-point links with indicated one-way BW/delay
+// - CBR/UDP flows from n0 to n3, and from n3 to n1
+// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
+// - 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 "simple-point-to-point-olsr.tr"
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
+
+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
+#if 0
+ LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
+#endif
+
+ // Set up some default values for the simulation. Use the
+
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (5);
+ NodeContainer n02 = NodeContainer (c.Get(0), c.Get (2));
+ NodeContainer n12 = NodeContainer (c.Get(1), c.Get (2));
+ NodeContainer n32 = NodeContainer (c.Get(3), c.Get (2));
+ NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4));
+
+ // Enable OLSR
+ NS_LOG_INFO ("Enabling OLSR Routing.");
+ OlsrHelper olsr;
+
+ Ipv4StaticRoutingHelper staticRouting;
+
+ Ipv4ListRoutingHelper list;
+ list.Add (staticRouting, 0);
+ list.Add (olsr, 10);
+
+ InternetStackHelper internet;
+ internet.SetRoutingHelper (list);
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer nd02 = p2p.Install (n02);
+ NetDeviceContainer nd12 = p2p.Install (n12);
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer nd32 = p2p.Install (n32);
+ NetDeviceContainer nd34 = p2p.Install (n34);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i02 = ipv4.Assign (nd02);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer i12 = ipv4.Assign (nd12);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i32 = ipv4.Assign (nd32);
+
+ ipv4.SetBase ("10.1.4.0", "255.255.255.0");
+ Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ InetSocketAddress (i34.GetAddress (1), port));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), port));
+
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a similar flow from n3 to n1, starting at time 1.1 seconds
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (i12.GetAddress (0), port)));
+ apps = onoff.Install (c.Get (3));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("simple-point-to-point-olsr.tr");
+ PointToPointHelper::EnablePcapAll ("simple-point-to-point-olsr");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ Simulator::Stop (Seconds (30));
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/simple-routing-ping6.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,164 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2008-2009 Strasbourg University
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: David Gross <david.gross@eturs.u-strasbg.fr>
+ * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
+ */
+
+// Network topology
+// //
+// // n0 r n1
+// // | _ |
+// // ====|_|====
+// // router
+// //
+// // - Tracing of queues and packet receptions to file "simple-routing-ping6.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+#include "ns3/ipv6-routing-table-entry.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleRoutingPing6Example");
+
+/**
+ * \class StackHelper
+ * \brief Helper to set or get some IPv6 information about nodes.
+ */
+class StackHelper
+{
+ public:
+
+ /**
+ * \brief Add an address to a IPv6 node.
+ * \param n node
+ * \param interface interface index
+ * \param address IPv6 address to add
+ */
+ inline void AddAddress (Ptr<Node>& n, uint32_t interface, Ipv6Address address)
+ {
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+ ipv6->AddAddress (interface, address);
+ }
+
+ /**
+ * \brief Print the routing table.
+ * \param n the node
+ */
+ inline void PrintRoutingTable (Ptr<Node>& n)
+ {
+ Ptr<Ipv6StaticRouting> routing = 0;
+ Ipv6StaticRoutingHelper routingHelper;
+ Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
+ uint32_t nbRoutes = 0;
+ Ipv6RoutingTableEntry route;
+
+ routing = routingHelper.GetStaticRouting (ipv6);
+
+ std::cout << "Routing table of " << n << " : " << std::endl;
+ std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
+
+ nbRoutes = routing->GetNRoutes ();
+ for (uint32_t i = 0 ; i < nbRoutes ; i++)
+ {
+ route = routing->GetRoute (i);
+ std::cout << route.GetDest () << "\t"
+ << route.GetGateway () << "\t"
+ << route.GetInterface () << "\t"
+ << route.GetPrefixToUse () << "\t"
+ << std::endl;
+ }
+ }
+};
+
+int main (int argc, char** argv)
+{
+#if 0
+ LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
+ LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
+#endif
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ StackHelper stackHelper;
+
+ NS_LOG_INFO ("Create nodes.");
+ Ptr<Node> n0 = CreateObject<Node> ();
+ Ptr<Node> r = CreateObject<Node> ();
+ Ptr<Node> n1 = CreateObject<Node> ();
+
+ NodeContainer net1 (n0, r);
+ NodeContainer net2 (r, n1);
+ NodeContainer all (n0, r, n1);
+
+ NS_LOG_INFO ("Create IPv6 Internet Stack");
+ InternetStackHelper internetv6;
+ internetv6.Install (all);
+
+ NS_LOG_INFO ("Create channels.");
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer d1 = csma.Install (net1);
+ NetDeviceContainer d2 = csma.Install (net2);
+
+ NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
+ Ipv6AddressHelper ipv6;
+ ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
+ Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
+ i1.SetRouter (1, true);
+ ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
+ Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
+ i2.SetRouter (0, true);
+
+ stackHelper.PrintRoutingTable(n0);
+
+ /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 5;
+ Time interPacketInterval = Seconds (1.);
+ Ping6Helper ping6;
+
+ ping6.SetLocal (i1.GetAddress (0, 1));
+ ping6.SetRemote (i2.GetAddress (1, 1));
+
+ ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ ApplicationContainer apps = ping6.Install (net1.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (20.0));
+
+ std::ofstream ascii;
+ ascii.open ("simple-routing-ping6.tr");
+ CsmaHelper::EnablePcapAll (std::string ("simple-routing-ping6"), true);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/simple-routing-ping6.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,106 @@
+#
+# Copyright (c) 2008-2009 Strasbourg University
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Author: David Gross <david.gross@eturs.u-strasbg.fr>
+# Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
+#
+
+#
+# Network topology:
+#
+# n0 r n1
+# | _ |
+# ====|_|====
+# router
+#
+
+import ns3;
+
+def main(argv):
+
+ cmd = ns3.CommandLine();
+
+ cmd.Parse(argv);
+
+ # Create nodes
+ print "Create nodes"
+ n0 = ns3.Node();
+ r = ns3.Node();
+ n1 = ns3.Node();
+
+ net1 = ns3.NodeContainer();
+ net1.Add(n0);
+ net1.Add(r);
+ net2 = ns3.NodeContainer();
+ net2.Add(r);
+ net2.Add(n1);
+ all = ns3.NodeContainer();
+ all.Add(n0);
+ all.Add(r);
+ all.Add(n1);
+
+ # Create IPv6 Internet Stack
+ internetv6 = ns3.InternetStackHelper();
+ internetv6.Install(all);
+
+ # Create channels
+ csma = ns3.CsmaHelper();
+ csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)));
+ csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
+ d1 = csma.Install(net1);
+ d2 = csma.Install(net2);
+
+ # Create networks and assign IPv6 Addresses
+ print "Addressing"
+ ipv6 = ns3.Ipv6AddressHelper();
+ ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64));
+ i1 = ipv6.Assign(d1);
+ i1.SetRouter(1, True);
+ ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64));
+ i2 = ipv6.Assign(d2);
+ i2.SetRouter(0, True);
+
+ # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
+ print "Application"
+ packetSize = 1024;
+ maxPacketCount = 5;
+ interPacketInterval = ns3.Seconds(1.);
+ ping6 = ns3.Ping6Helper();
+
+ ping6.SetLocal(i1.GetAddress(0, 1));
+ ping6.SetRemote(i2.GetAddress(1, 1));
+
+ ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount));
+ ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval));
+ ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize));
+
+ apps = ping6.Install(ns3.NodeContainer(net1.Get(0)));
+ apps.Start(ns3.Seconds(2.0));
+ apps.Stop(ns3.Seconds(20.0));
+
+ print "Tracing"
+ ascii = ns3.ofstream("simple-routing-ping6.tr");
+ ns3.CsmaHelper.EnableAsciiAll(ascii);
+ ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True);
+
+ # Run Simulation
+ ns3.Simulator.Run();
+ ns3.Simulator.Destroy();
+
+if __name__ == '__main__':
+ import sys
+ main(sys.argv)
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/static-routing-slash32.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,136 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+// Test program for this 3-router scenario, using static routing
+//
+// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/csma-net-device.h"
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("StaticRoutingSlash32Test");
+
+int
+main (int argc, char *argv[])
+{
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ Ptr<Node> nA = CreateObject<Node> ();
+ Ptr<Node> nB = CreateObject<Node> ();
+ Ptr<Node> nC = CreateObject<Node> ();
+
+ NodeContainer c = NodeContainer (nA, nB, nC);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // Point-to-point links
+ NodeContainer nAnB = NodeContainer (nA, nB);
+ NodeContainer nBnC = NodeContainer (nB, nC);
+
+ // We create the channels first without any IP addressing information
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer dAdB = p2p.Install (nAnB);
+
+ NetDeviceContainer dBdC = p2p.Install (nBnC);;
+
+ Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
+ deviceA->SetAddress (Mac48Address::Allocate ());
+ nA->AddDevice (deviceA);
+
+ Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
+ deviceC->SetAddress (Mac48Address::Allocate ());
+ nC->AddDevice (deviceC);
+
+ // Later, we add IP addresses.
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.252");
+ Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
+
+ ipv4.SetBase ("10.1.1.4", "255.255.255.252");
+ Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
+
+ Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
+ Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
+ Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
+
+ int32_t ifIndexA = ipv4A->AddInterface (deviceA);
+ int32_t ifIndexC = ipv4C->AddInterface (deviceC);
+
+ Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32"));
+ ipv4A->AddAddress (ifIndexA, ifInAddrA);
+ ipv4A->SetMetric (ifIndexA, 1);
+ ipv4A->SetUp (ifIndexA);
+
+ Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32"));
+ ipv4C->AddAddress (ifIndexC, ifInAddrC);
+ ipv4C->SetMetric (ifIndexC, 1);
+ ipv4C->SetUp (ifIndexC);
+
+ Ipv4StaticRoutingHelper ipv4RoutingHelper;
+ // Create static routes from A to C
+ Ptr<Ipv4StaticRouting> staticRoutingA = ipv4RoutingHelper.GetStaticRouting (ipv4A);
+ // The ifIndex for this outbound route is 1; the first p2p link added
+ staticRoutingA->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);
+ Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting (ipv4B);
+ // The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link
+ staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2);
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (ifInAddrC.GetLocal (), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
+ ApplicationContainer apps = onoff.Install (nA);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (nC);
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("static-routing-slash32.tr");
+ PointToPointHelper::EnablePcapAll ("static-routing-slash32");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,46 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('dynamic-global-routing',
+ ['point-to-point', 'csma', 'internet-stack', 'global-routing'])
+ obj.source = 'dynamic-global-routing.cc'
+
+ obj = bld.create_ns3_program('static-routing-slash32',
+ ['point-to-point', 'internet-stack', 'global-routing'])
+ obj.source = 'static-routing-slash32.cc'
+
+ obj = bld.create_ns3_program('global-routing-slash32',
+ ['point-to-point', 'internet-stack', 'global-routing'])
+ obj.source = 'global-routing-slash32.cc'
+
+ obj = bld.create_ns3_program('global-injection-slash32',
+ ['point-to-point', 'internet-stack', 'global-routing'])
+ obj.source = 'global-injection-slash32.cc'
+
+ obj = bld.create_ns3_program('simple-global-routing',
+ ['point-to-point', 'internet-stack', 'global-routing'])
+ obj.source = 'simple-global-routing.cc'
+
+ obj = bld.create_ns3_program('simple-alternate-routing',
+ ['point-to-point', 'internet-stack', 'global-routing'])
+ obj.source = 'simple-alternate-routing.cc'
+
+ obj = bld.create_ns3_program( 'mixed-global-routing',
+ ['point-to-point', 'internet-stack', 'global-routing' , 'csma-cd'])
+ obj.source = 'mixed-global-routing.cc'
+
+ obj = bld.create_ns3_program('simple-point-to-point-olsr',
+ ['point-to-point', 'internet-stack', 'olsr'])
+ obj.source = 'simple-point-to-point-olsr.cc'
+
+ obj = bld.create_ns3_program('nix-simple',
+ ['point-to-point', 'internet-stack', 'nix-vector-routing'])
+ obj.source = 'nix-simple.cc'
+
+ obj = bld.create_ns3_program('nms-p2p-nix',
+ ['point-to-point', 'internet-stack', 'nix-vector-routing'])
+ obj.source = 'nms-p2p-nix.cc'
+
+ obj = bld.create_ns3_program('simple-routing-ping6',
+ ['csma', 'internet-stack'])
+ obj.source = 'simple-routing-ping6.cc'
--- a/examples/second.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-// Default Network Topology
-//
-// 10.1.1.0
-// n0 -------------- n1 n2 n3 n4
-// point-to-point | | | |
-// ================
-// LAN 10.1.2.0
-
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
-
-int
-main (int argc, char *argv[])
-{
- bool verbose = true;
- uint32_t nCsma = 3;
-
- CommandLine cmd;
- cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
- cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
-
- cmd.Parse (argc,argv);
-
- if (verbose)
- {
- LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
- }
-
- nCsma = nCsma == 0 ? 1 : nCsma;
-
- NodeContainer p2pNodes;
- p2pNodes.Create (2);
-
- NodeContainer csmaNodes;
- csmaNodes.Add (p2pNodes.Get (1));
- csmaNodes.Create (nCsma);
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NetDeviceContainer p2pDevices;
- p2pDevices = pointToPoint.Install (p2pNodes);
-
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
- csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
-
- NetDeviceContainer csmaDevices;
- csmaDevices = csma.Install (csmaNodes);
-
- InternetStackHelper stack;
- stack.Install (p2pNodes.Get (0));
- stack.Install (csmaNodes);
-
- Ipv4AddressHelper address;
- address.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer p2pInterfaces;
- p2pInterfaces = address.Assign (p2pDevices);
-
- address.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer csmaInterfaces;
- csmaInterfaces = address.Assign (csmaDevices);
-
- UdpEchoServerHelper echoServer (9);
-
- ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
-
- UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
- ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
-
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- PointToPointHelper::EnablePcapAll ("second");
- CsmaHelper::EnablePcap ("second", csmaDevices.Get (1), true);
-
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
--- a/examples/simple-alternate-routing.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-//
-// Network topology
-//
-// n0
-// \ 5 Mb/s, 2ms
-// \ 1.5Mb/s, 10ms
-// n2 ------------------------n3
-// / /
-// / 5 Mb/s, 2ms /
-// n1--------------------------
-// 1.5 Mb/s, 100ms
-//
-// this is a modification of simple-global-routing to allow for
-// a single hop but higher-cost path between n1 and n3
-//
-// - Tracing of queues and packet receptions to file "simple-rerouting.tr"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleAlternateRoutingExample");
-
-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
-#if 0
- LogComponentEnable("GlobalRoutingHelper", LOG_LOGIC);
- LogComponentEnable("GlobalRouter", LOG_LOGIC);
-#endif
-
-
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("300b/s"));
-
- // The below metric, if set to 3 or higher, will cause packets between
- // n1 and n3 to take the 2-hop route through n2
-
- CommandLine cmd;
- //
- // Additionally, we plumb this metric into the default value / command
- // line argument system as well, for exemplary purposes. This means
- // that it can be resettable at the command-line to the program,
- // rather than recompiling
- // e.g. waf --run "simple-alternate-routing --AlternateCost=5"
- uint16_t sampleMetric = 1;
- cmd.AddValue ("AlternateCost",
- "This metric is used in the example script between n3 and n1 ",
- sampleMetric);
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
- NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
- NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
- NodeContainer n1n3 = NodeContainer (c.Get (1), c.Get (3));
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer d3d2 = p2p.Install (n3n2);
-
- p2p.SetChannelAttribute ("Delay", StringValue ("100ms"));
- NetDeviceContainer d1d3 = p2p.Install (n1n3);
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // Later, we add IP addresses. The middle two octets correspond to
- // the channel number.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.0.0.0", "255.255.255.0");
- ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.2.2.0", "255.255.255.0");
- ipv4.Assign (d3d2);
-
- ipv4.SetBase ("10.3.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i3 = ipv4.Assign (d1d3);
-
- i1i3.SetMetric (0, sampleMetric);
- i1i3.SetMetric (1, sampleMetric);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams
- NS_LOG_INFO ("Create Application.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- // Create a flow from n3 to n1, starting at time 1.1 seconds
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (i1i2.GetAddress (0), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer apps = onoff.Install (c.Get (3));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (1));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("simple-alternate-routing.tr");
- PointToPointHelper::EnablePcapAll ("simple-alternate-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- a/examples/simple-error-model.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,178 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * ns-2 simple.tcl script (ported from ns-2)
- * Originally authored by Steve McCanne, 12/19/1996
- */
-
-// Port of ns-2/tcl/ex/simple.tcl to ns-3
-//
-// Network topology
-//
-// n0
-// \ 5 Mb/s, 2ms
-// \ 1.5Mb/s, 10ms
-// n2 -------------------------n3
-// /
-// / 5 Mb/s, 2ms
-// n1
-//
-// - all links are point-to-point links with indicated one-way BW/delay
-// - CBR/UDP flows from n0 to n3, and from n3 to n1
-// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
-// - 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
-// "simple-error-model.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleErrorModelExample");
-
-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
-#if 0
- LogComponentEnable ("SimplePointToPointExample", LOG_LEVEL_INFO);
-#endif
-
-
- // Set a few attributes
- Config::SetDefault ("ns3::RateErrorModel::ErrorRate", DoubleValue (0.01));
- Config::SetDefault ("ns3::RateErrorModel::ErrorUnit", StringValue ("EU_PKT"));
-
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", DataRateValue (DataRate ("448kb/s")));
-
-
- // Allow the user to override any of the defaults and the above
- // Bind()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
- NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
- NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (5000000)));
- p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (1500000)));
- p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
- NetDeviceContainer d3d2 = p2p.Install (n3n2);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
-
- NS_LOG_INFO ("Use global routing.");
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (i3i2.GetAddress (1), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0)));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start(Seconds(1.0));
- apps.Stop (Seconds(10.0));
-
- // Create an optional packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (2));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a similar flow from n3 to n1, starting at time 1.1 seconds
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
- apps = onoff.Install (c.Get (3));
- apps.Start(Seconds(1.1));
- apps.Stop (Seconds(10.0));
-
- // Create a packet sink to receive these packets
- sink.SetAttribute ("Local",
- AddressValue (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (1));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- //
- // Error model
- //
- // Create an ErrorModel based on the implementation (constructor)
- // specified by the default classId
- Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> ("RanVar", RandomVariableValue (UniformVariable (0.0, 1.0)),
- "ErrorRate", DoubleValue (0.001));
- d3d2.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em));
-
- // Now, let's use the ListErrorModel and explicitly force a loss
- // of the packets with pkt-uids = 11 and 17 on node 2, device 0
- std::list<uint32_t> sampleList;
- sampleList.push_back (11);
- sampleList.push_back (17);
- // This time, we'll explicitly create the error model we want
- Ptr<ListErrorModel> pem = CreateObject<ListErrorModel> ();
- pem->SetList (sampleList);
- d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (pem));
-
- std::ofstream ascii;
- ascii.open ("simple-error-model.tr");
- PointToPointHelper::EnablePcapAll ("simple-error-model");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- a/examples/simple-global-routing.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * ns-2 simple.tcl script (ported from ns-2)
- * Originally authored by Steve McCanne, 12/19/1996
- */
-
-// Port of ns-2/tcl/ex/simple.tcl to ns-3
-//
-// Network topology
-//
-// n0
-// \ 5 Mb/s, 2ms
-// \ 1.5Mb/s, 10ms
-// n2 -------------------------n3
-// /
-// / 5 Mb/s, 2ms
-// n1
-//
-// - all links are point-to-point links with indicated one-way BW/delay
-// - CBR/UDP flows from n0 to n3, and from n3 to n1
-// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
-// - 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 "simple-global-routing.tr"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
-
-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
-#if 0
- LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
-#endif
-
- // Set up some default values for the simulation. Use the
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
-
- //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- bool enableFlowMonitor = false;
- cmd.AddValue("EnableMonitor", "Enable Flow Monitor", enableFlowMonitor);
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
- NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
- NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer d3d2 = p2p.Install (n3n2);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (i3i2.GetAddress (0), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (3));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a similar flow from n3 to n1, starting at time 1.1 seconds
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
- apps = onoff.Install (c.Get (3));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- apps = sink.Install (c.Get (1));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("simple-global-routing.tr");
- PointToPointHelper::EnablePcapAll ("simple-global-routing");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- // Flow Monitor
- Ptr<FlowMonitor> flowmon;
- if (enableFlowMonitor)
- {
- FlowMonitorHelper flowmonHelper;
- flowmon = flowmonHelper.InstallAll ();
- }
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Stop (Seconds (11));
- Simulator::Run ();
- NS_LOG_INFO ("Done.");
-
- if (enableFlowMonitor)
- {
- flowmon->SerializeToXmlFile ("simple-global-routing.flowmon", false, false);
- }
-
- Simulator::Destroy ();
- return 0;
-}
--- a/examples/simple-point-to-point-olsr.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * ns-2 simple.tcl script (ported from ns-2)
- * Originally authored by Steve McCanne, 12/19/1996
- */
-
-// Port of ns-2/tcl/ex/simple.tcl to ns-3
-//
-// Network topology
-//
-// n0
-// \ 5 Mb/s, 2ms
-// \ 1.5Mb/s, 10ms
-// n2 -------------------------n3---------n4
-// /
-// / 5 Mb/s, 2ms
-// n1
-//
-// - all links are point-to-point links with indicated one-way BW/delay
-// - CBR/UDP flows from n0 to n3, and from n3 to n1
-// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
-// - 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 "simple-point-to-point-olsr.tr"
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
-
-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
-#if 0
- LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
-#endif
-
- // Set up some default values for the simulation. Use the
-
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
-
- //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (5);
- NodeContainer n02 = NodeContainer (c.Get(0), c.Get (2));
- NodeContainer n12 = NodeContainer (c.Get(1), c.Get (2));
- NodeContainer n32 = NodeContainer (c.Get(3), c.Get (2));
- NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4));
-
- // Enable OLSR
- NS_LOG_INFO ("Enabling OLSR Routing.");
- OlsrHelper olsr;
-
- Ipv4StaticRoutingHelper staticRouting;
-
- Ipv4ListRoutingHelper list;
- list.Add (staticRouting, 0);
- list.Add (olsr, 10);
-
- InternetStackHelper internet;
- internet.SetRoutingHelper (list);
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer nd02 = p2p.Install (n02);
- NetDeviceContainer nd12 = p2p.Install (n12);
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer nd32 = p2p.Install (n32);
- NetDeviceContainer nd34 = p2p.Install (n34);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i02 = ipv4.Assign (nd02);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer i12 = ipv4.Assign (nd12);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i32 = ipv4.Assign (nd32);
-
- ipv4.SetBase ("10.1.4.0", "255.255.255.0");
- Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
-
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- InetSocketAddress (i34.GetAddress (1), port));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (), port));
-
- apps = sink.Install (c.Get (3));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a similar flow from n3 to n1, starting at time 1.1 seconds
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (i12.GetAddress (0), port)));
- apps = onoff.Install (c.Get (3));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- apps = sink.Install (c.Get (1));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("simple-point-to-point-olsr.tr");
- PointToPointHelper::EnablePcapAll ("simple-point-to-point-olsr");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- Simulator::Stop (Seconds (30));
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- a/examples/simple-routing-ping6.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008-2009 Strasbourg University
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: David Gross <david.gross@eturs.u-strasbg.fr>
- * Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
- */
-
-// Network topology
-// //
-// // n0 r n1
-// // | _ |
-// // ====|_|====
-// // router
-// //
-// // - Tracing of queues and packet receptions to file "simple-routing-ping6.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-#include "ns3/ipv6-routing-table-entry.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleRoutingPing6Example");
-
-/**
- * \class StackHelper
- * \brief Helper to set or get some IPv6 information about nodes.
- */
-class StackHelper
-{
- public:
-
- /**
- * \brief Add an address to a IPv6 node.
- * \param n node
- * \param interface interface index
- * \param address IPv6 address to add
- */
- inline void AddAddress (Ptr<Node>& n, uint32_t interface, Ipv6Address address)
- {
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
- ipv6->AddAddress (interface, address);
- }
-
- /**
- * \brief Print the routing table.
- * \param n the node
- */
- inline void PrintRoutingTable (Ptr<Node>& n)
- {
- Ptr<Ipv6StaticRouting> routing = 0;
- Ipv6StaticRoutingHelper routingHelper;
- Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
- uint32_t nbRoutes = 0;
- Ipv6RoutingTableEntry route;
-
- routing = routingHelper.GetStaticRouting (ipv6);
-
- std::cout << "Routing table of " << n << " : " << std::endl;
- std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
-
- nbRoutes = routing->GetNRoutes ();
- for (uint32_t i = 0 ; i < nbRoutes ; i++)
- {
- route = routing->GetRoute (i);
- std::cout << route.GetDest () << "\t"
- << route.GetGateway () << "\t"
- << route.GetInterface () << "\t"
- << route.GetPrefixToUse () << "\t"
- << std::endl;
- }
- }
-};
-
-int main (int argc, char** argv)
-{
-#if 0
- LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
- LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
- LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
-#endif
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- StackHelper stackHelper;
-
- NS_LOG_INFO ("Create nodes.");
- Ptr<Node> n0 = CreateObject<Node> ();
- Ptr<Node> r = CreateObject<Node> ();
- Ptr<Node> n1 = CreateObject<Node> ();
-
- NodeContainer net1 (n0, r);
- NodeContainer net2 (r, n1);
- NodeContainer all (n0, r, n1);
-
- NS_LOG_INFO ("Create IPv6 Internet Stack");
- InternetStackHelper internetv6;
- internetv6.Install (all);
-
- NS_LOG_INFO ("Create channels.");
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- NetDeviceContainer d1 = csma.Install (net1);
- NetDeviceContainer d2 = csma.Install (net2);
-
- NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
- Ipv6AddressHelper ipv6;
- ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
- Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
- i1.SetRouter (1, true);
- ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
- Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
- i2.SetRouter (0, true);
-
- stackHelper.PrintRoutingTable(n0);
-
- /* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 5;
- Time interPacketInterval = Seconds (1.);
- Ping6Helper ping6;
-
- ping6.SetLocal (i1.GetAddress (0, 1));
- ping6.SetRemote (i2.GetAddress (1, 1));
-
- ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
- ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
- ApplicationContainer apps = ping6.Install (net1.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (20.0));
-
- std::ofstream ascii;
- ascii.open ("simple-routing-ping6.tr");
- CsmaHelper::EnablePcapAll (std::string ("simple-routing-ping6"), true);
- CsmaHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
-
--- a/examples/simple-routing-ping6.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-#
-# Copyright (c) 2008-2009 Strasbourg University
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation;
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Author: David Gross <david.gross@eturs.u-strasbg.fr>
-# Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
-#
-
-#
-# Network topology:
-#
-# n0 r n1
-# | _ |
-# ====|_|====
-# router
-#
-
-import ns3;
-
-def main(argv):
-
- cmd = ns3.CommandLine();
-
- cmd.Parse(argv);
-
- # Create nodes
- print "Create nodes"
- n0 = ns3.Node();
- r = ns3.Node();
- n1 = ns3.Node();
-
- net1 = ns3.NodeContainer();
- net1.Add(n0);
- net1.Add(r);
- net2 = ns3.NodeContainer();
- net2.Add(r);
- net2.Add(n1);
- all = ns3.NodeContainer();
- all.Add(n0);
- all.Add(r);
- all.Add(n1);
-
- # Create IPv6 Internet Stack
- internetv6 = ns3.InternetStackHelper();
- internetv6.Install(all);
-
- # Create channels
- csma = ns3.CsmaHelper();
- csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)));
- csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
- d1 = csma.Install(net1);
- d2 = csma.Install(net2);
-
- # Create networks and assign IPv6 Addresses
- print "Addressing"
- ipv6 = ns3.Ipv6AddressHelper();
- ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64));
- i1 = ipv6.Assign(d1);
- i1.SetRouter(1, True);
- ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64));
- i2 = ipv6.Assign(d2);
- i2.SetRouter(0, True);
-
- # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
- print "Application"
- packetSize = 1024;
- maxPacketCount = 5;
- interPacketInterval = ns3.Seconds(1.);
- ping6 = ns3.Ping6Helper();
-
- ping6.SetLocal(i1.GetAddress(0, 1));
- ping6.SetRemote(i2.GetAddress(1, 1));
-
- ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount));
- ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval));
- ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize));
-
- apps = ping6.Install(ns3.NodeContainer(net1.Get(0)));
- apps.Start(ns3.Seconds(2.0));
- apps.Stop(ns3.Seconds(20.0));
-
- print "Tracing"
- ascii = ns3.ofstream("simple-routing-ping6.tr");
- ns3.CsmaHelper.EnableAsciiAll(ascii);
- ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True);
-
- # Run Simulation
- ns3.Simulator.Run();
- ns3.Simulator.Destroy();
-
-if __name__ == '__main__':
- import sys
- main(sys.argv)
-
--- a/examples/simple-wifi-frame-aggregation.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 MIRKO BANCHI
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mirko Banchi <mk.banchi@gmail.com>
- */
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/mobility-module.h"
-
-//This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works.
-//
-//Network topology:
-//
-// Wifi 192.168.1.0
-//
-// AP
-// * * *
-// | | |
-// n1 n2 n3
-//
-//Packets in this simulation aren't marked with a QosTag so they are considered
-//belonging to BestEffort Access Class (AC_BE).
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("SimpleWifiFrameAggregation");
-
-int main (int argc, char *argv[])
-{
- //LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
- LogComponentEnable ("MsduAggregator", LOG_LEVEL_INFO);
- LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
-
- uint32_t nWifi = 1;
- CommandLine cmd;
- cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
- cmd.Parse (argc,argv);
-
- NodeContainer wifiNodes;
- wifiNodes.Create (2);
- NodeContainer wifiApNode;
- wifiApNode.Create (1);
-
- YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
- YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
- phy.SetChannel (channel.Create ());
-
- WifiHelper wifi = WifiHelper::Default ();
- QosWifiMacHelper mac = QosWifiMacHelper::Default ();
- wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
-
- Ssid ssid = Ssid ("ns-3-802.11n");
- mac.SetType ("ns3::QstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
- "MaxAmsduSize", UintegerValue (3839));
-
- NetDeviceContainer staDevices;
- staDevices = wifi.Install (phy, mac, wifiNodes);
-
- mac.SetType ("ns3::QapWifiMac",
- "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
- mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
- "MaxAmsduSize", UintegerValue (7935));
-
- NetDeviceContainer apDevice;
- apDevice = wifi.Install (phy, mac, wifiApNode);
-
- /* Setting mobility model */
- MobilityHelper mobility;
-
- mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (0.0),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (5.0),
- "DeltaY", DoubleValue (10.0),
- "GridWidth", UintegerValue (3),
- "LayoutType", StringValue ("RowFirst"));
-
- mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
- mobility.Install (wifiNodes);
-
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.Install (wifiApNode);
-
- /* Internet stack*/
- InternetStackHelper stack;
- stack.Install (wifiApNode);
- stack.Install (wifiNodes);
-
- Ipv4AddressHelper address;
-
- address.SetBase ("192.168.1.0", "255.255.255.0");
- Ipv4InterfaceContainer wifiNodesInterfaces;
- Ipv4InterfaceContainer apNodeInterface;
-
- wifiNodesInterfaces = address.Assign (staDevices);
- apNodeInterface = address.Assign (apDevice);
-
- /* Setting applications */
- UdpEchoServerHelper echoServer (9);
-
- ApplicationContainer serverApps = echoServer.Install (wifiNodes.Get (1));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
-
- UdpEchoClientHelper echoClient (wifiNodesInterfaces.GetAddress (1), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (3));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.000001)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1500));
-
- ApplicationContainer clientApps =
- echoClient.Install (wifiNodes.Get (0));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
-
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- Simulator::Stop (Seconds (10.0));
-
- phy.EnablePcap ("test-802.11n",
- wifiNodes.Get (nWifi - 1)->GetId (), 0);
-
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/star.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-// Network topology (default)
-//
-// n2 n3 n4 .
-// \ | / .
-// \|/ .
-// n1--- n0---n5 .
-// /|\ .
-// / | \ .
-// n8 n7 n6 .
-//
-
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("Star");
-
-int
-main (int argc, char *argv[])
-{
-
- //
- // Set up some default values for the simulation.
- //
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
-
- // ??? try and stick 15kb/s into the data rate
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
-
- //
- // Default number of nodes in the star. Overridable by command line argument.
- //
- uint32_t nNodes = 9;
-
- CommandLine cmd;
- cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
- cmd.Parse (argc, argv);
-
- NS_LOG_INFO ("Create nodes.");
- NodeContainer hubNode;
- NodeContainer spokeNodes;
- hubNode.Create (1);
- Ptr<Node> hub = hubNode.Get (0);
- spokeNodes.Create (nNodes - 1);
-
- NS_LOG_INFO ("Install internet stack on all nodes.");
- InternetStackHelper internet;
- internet.Install (NodeContainer (hubNode, spokeNodes));
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NS_LOG_INFO ("Build star topology.");
- NetDeviceContainer hubDevices, spokeDevices;
- pointToPoint.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
-
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper address;
-
- //
- // Assign IPv4 interfaces and IP addresses to the devices we previously
- // created. Keep track of the resulting addresses, one for the addresses
- // of the hub node, and one for addresses on the spoke nodes. Despite the
- // name of the class, what is visible to clients is really the address.
- //
- Ipv4InterfaceContainer hubAddresses;
- Ipv4InterfaceContainer spokeAddresses;
-
- for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
- {
- std::ostringstream subnet;
- subnet << "10.1.1." << (i << 2);
- NS_LOG_INFO ("Assign IP Addresses for point-to-point subnet " << subnet.str ());
- address.SetBase (subnet.str ().c_str (), "255.255.255.252");
- hubAddresses.Add (address.Assign (hubDevices.Get (i)));
- spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
- }
-
- NS_LOG_INFO ("Create applications.");
- //
- // Create a packet sink on the star "hub" to receive packets.
- //
- uint16_t port = 50000;
- Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
- PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
- ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
- hubApp.Start (Seconds (1.0));
- hubApp.Stop (Seconds (10.0));
-
- //
- // Create OnOff applications to send TCP to the hub, one on each spoke node.
- //
- OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
- onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer spokeApps;
-
- for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
- {
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
- onOffHelper.SetAttribute ("Remote", remoteAddress);
- spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
- }
- spokeApps.Start (Seconds (1.0));
- spokeApps.Stop (Seconds (10.0));
-
- NS_LOG_INFO ("Enable static global routing.");
- //
- // Turn on global static routing so we can actually be routed across the star.
- //
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- NS_LOG_INFO ("Enable pcap tracing.");
- //
- // Do pcap tracing on all point-to-point devices on all nodes.
- //
- PointToPointHelper::EnablePcapAll ("star");
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- a/examples/static-routing-slash32.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-// Test program for this 3-router scenario, using static routing
-//
-// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/csma-net-device.h"
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("StaticRoutingSlash32Test");
-
-int
-main (int argc, char *argv[])
-{
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- Ptr<Node> nA = CreateObject<Node> ();
- Ptr<Node> nB = CreateObject<Node> ();
- Ptr<Node> nC = CreateObject<Node> ();
-
- NodeContainer c = NodeContainer (nA, nB, nC);
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // Point-to-point links
- NodeContainer nAnB = NodeContainer (nA, nB);
- NodeContainer nBnC = NodeContainer (nB, nC);
-
- // We create the channels first without any IP addressing information
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer dAdB = p2p.Install (nAnB);
-
- NetDeviceContainer dBdC = p2p.Install (nBnC);;
-
- Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
- deviceA->SetAddress (Mac48Address::Allocate ());
- nA->AddDevice (deviceA);
-
- Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
- deviceC->SetAddress (Mac48Address::Allocate ());
- nC->AddDevice (deviceC);
-
- // Later, we add IP addresses.
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.252");
- Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
-
- ipv4.SetBase ("10.1.1.4", "255.255.255.252");
- Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
-
- Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
- Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
- Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
-
- int32_t ifIndexA = ipv4A->AddInterface (deviceA);
- int32_t ifIndexC = ipv4C->AddInterface (deviceC);
-
- Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32"));
- ipv4A->AddAddress (ifIndexA, ifInAddrA);
- ipv4A->SetMetric (ifIndexA, 1);
- ipv4A->SetUp (ifIndexA);
-
- Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32"));
- ipv4C->AddAddress (ifIndexC, ifInAddrC);
- ipv4C->SetMetric (ifIndexC, 1);
- ipv4C->SetUp (ifIndexC);
-
- Ipv4StaticRoutingHelper ipv4RoutingHelper;
- // Create static routes from A to C
- Ptr<Ipv4StaticRouting> staticRoutingA = ipv4RoutingHelper.GetStaticRouting (ipv4A);
- // The ifIndex for this outbound route is 1; the first p2p link added
- staticRoutingA->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);
- Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting (ipv4B);
- // The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link
- staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2);
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (ifInAddrC.GetLocal (), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
- ApplicationContainer apps = onoff.Install (nA);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (nC);
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("static-routing-slash32.tr");
- PointToPointHelper::EnablePcapAll ("static-routing-slash32");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/tap-wifi-dumbbell.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// +----------+
-// | external |
-// | Linux |
-// | Host |
-// | |
-// | "mytap" |
-// +----------+
-// | n0 n3 n4
-// | +--------+ +------------+ +------------+
-// +-------| tap | | | | |
-// | bridge | ... | | | |
-// +--------+ +------------+ +------------+
-// | Wifi | | Wifi | P2P |-----| P2P | CSMA |
-// +--------+ +------+-----+ +-----+------+
-// | | ^ |
-// ((*)) ((*)) | |
-// P2P 10.1.2 |
-// ((*)) ((*)) | n5 n6 n7
-// | | | | | |
-// n1 n2 ================
-// Wifi 10.1.1 CSMA LAN 10.1.3
-//
-// The Wifi device on node zero is: 10.1.1.1
-// The Wifi device on node one is: 10.1.1.2
-// The Wifi device on node two is: 10.1.1.3
-// The Wifi device on node three is: 10.1.1.4
-// The P2P device on node three is: 10.1.2.1
-// The P2P device on node four is: 10.1.2.2
-// The CSMA device on node four is: 10.1.3.1
-// The CSMA device on node five is: 10.1.3.2
-// The CSMA device on node six is: 10.1.3.3
-// The CSMA device on node seven is: 10.1.3.4
-//
-// Some simple things to do:
-//
-// 1) Ping one of the simulated nodes on the left side of the topology.
-//
-// ./waf --run tap-wifi-dumbbell&
-// ping 10.1.1.3
-//
-// 2) Configure a route in the linux host and ping once of the nodes on the
-// right, across the point-to-point link. You will see relatively large
-// delays due to CBR background traffic on the point-to-point (see next
-// item).
-//
-// ./waf --run tap-wifi-dumbbell&
-// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
-// ping 10.1.3.4
-//
-// Take a look at the pcap traces and note that the timing reflects the
-// addition of the significant delay and low bandwidth configured on the
-// point-to-point link along with the high traffic.
-//
-// 3) Fiddle with the background CBR traffic across the point-to-point
-// link and watch the ping timing change. The OnOffApplication "DataRate"
-// attribute defaults to 500kb/s and the "PacketSize" Attribute defaults
-// to 512. The point-to-point "DataRate" is set to 512kb/s in the script,
-// so in the default case, the link is pretty full. This should be
-// reflected in large delays seen by ping. You can crank down the CBR
-// traffic data rate and watch the ping timing change dramatically.
-//
-// ./waf --run "tap-wifi-dumbbell --ns3::OnOffApplication::DataRate=100kb/s"&
-// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
-// ping 10.1.3.4
-//
-// 4) Try to run this in UseLocal mode. This allows you to provide an existing
-// pre-configured tap device to the simulation. The IP address and MAC
-// address in this mode do not have to match those of the ns-3 device.
-//
-// sudo tunctl -t mytap
-// sudo ifconfig mytap hw ether 08:00:2e:00:00:01
-// sudo ifconfig mytap 10.1.1.1 netmask 255.255.255.0 up
-// ./waf --run "tap-wifi-dumbbell --mode=UseLocal --tapName=mytap"&
-// ping 10.1.1.3
-//
-// 5) Try to run this in UseBridge mode. This allows you to bridge an ns-3
-// simulation to an existing pre-configured bridge. This uses tap devices
-// just for illustration, you can create your own bridge if you want.
-//
-// sudo tunctl -t mytap1
-// sudo ifconfig mytap1 0.0.0.0 promisc up
-// sudo tunctl -t mytap2
-// sudo ifconfig mytap2 0.0.0.0 promisc up
-// sudo brctl addbr mybridge
-// sudo brctl addif mybridge mytap1
-// sudo brctl addif mybridge mytap2
-// sudo ifconfig mybridge 10.1.1.5 netmask 255.255.255.0 up
-// ./waf --run "tap-wifi-dumbbell --mode=UseBridge --tapName=mytap2"&
-// ping 10.1.1.3
-
-#include <iostream>
-#include <fstream>
-
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/core-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TapDumbbellExample");
-
-int
-main (int argc, char *argv[])
-{
- std::string mode = "ConfigureLocal";
- std::string tapName = "thetap";
-
- CommandLine cmd;
- cmd.AddValue("mode", "Mode setting of TapBridge", mode);
- cmd.AddValue("tapName", "Name of the OS tap device", tapName);
- cmd.Parse (argc, argv);
-
- GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
- GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
-
- //
- // The topology has a Wifi network of four nodes on the left side. We'll make
- // node zero the AP and have the other three will be the STAs.
- //
- NodeContainer nodesLeft;
- nodesLeft.Create (4);
-
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
-
- Ssid ssid = Ssid ("left");
- WifiHelper wifi = WifiHelper::Default ();
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
-
- wifiMac.SetType ("ns3::NqapWifiMac",
- "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
- NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
-
-
- wifiMac.SetType ("ns3::NqstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
-
- MobilityHelper mobility;
- mobility.Install (nodesLeft);
-
- InternetStackHelper internetLeft;
- internetLeft.Install (nodesLeft);
-
- Ipv4AddressHelper ipv4Left;
- ipv4Left.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
-
- TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1));
- tapBridge.SetAttribute ("Mode", StringValue (mode));
- tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
- tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
-
- //
- // Now, create the right side.
- //
- NodeContainer nodesRight;
- nodesRight.Create (4);
-
- CsmaHelper csmaRight;
- csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000));
- csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
-
- NetDeviceContainer devicesRight = csmaRight.Install (nodesRight);
-
- InternetStackHelper internetRight;
- internetRight.Install (nodesRight);
-
- Ipv4AddressHelper ipv4Right;
- ipv4Right.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight);
-
- //
- // Stick in the point-to-point line between the sides.
- //
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
-
- NodeContainer nodes = NodeContainer (nodesLeft.Get(3), nodesRight.Get (0));
- NetDeviceContainer devices = p2p.Install (nodes);
-
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.2.0", "255.255.255.192");
- Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
-
- //
- // Simulate some CBR traffic over the point-to-point link
- //
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer apps = onoff.Install (nodesLeft.Get (3));
- apps.Start (Seconds (1.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
-
- apps = sink.Install (nodesRight.Get (0));
- apps.Start (Seconds (1.0));
-
- CsmaHelper::EnablePcapAll ("tap-wifi-dumbbell", false);
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- Simulator::Stop (Seconds (60.));
- Simulator::Run ();
- Simulator::Destroy ();
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tap/tap-wifi-dumbbell.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,235 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// +----------+
+// | external |
+// | Linux |
+// | Host |
+// | |
+// | "mytap" |
+// +----------+
+// | n0 n3 n4
+// | +--------+ +------------+ +------------+
+// +-------| tap | | | | |
+// | bridge | ... | | | |
+// +--------+ +------------+ +------------+
+// | Wifi | | Wifi | P2P |-----| P2P | CSMA |
+// +--------+ +------+-----+ +-----+------+
+// | | ^ |
+// ((*)) ((*)) | |
+// P2P 10.1.2 |
+// ((*)) ((*)) | n5 n6 n7
+// | | | | | |
+// n1 n2 ================
+// Wifi 10.1.1 CSMA LAN 10.1.3
+//
+// The Wifi device on node zero is: 10.1.1.1
+// The Wifi device on node one is: 10.1.1.2
+// The Wifi device on node two is: 10.1.1.3
+// The Wifi device on node three is: 10.1.1.4
+// The P2P device on node three is: 10.1.2.1
+// The P2P device on node four is: 10.1.2.2
+// The CSMA device on node four is: 10.1.3.1
+// The CSMA device on node five is: 10.1.3.2
+// The CSMA device on node six is: 10.1.3.3
+// The CSMA device on node seven is: 10.1.3.4
+//
+// Some simple things to do:
+//
+// 1) Ping one of the simulated nodes on the left side of the topology.
+//
+// ./waf --run tap-wifi-dumbbell&
+// ping 10.1.1.3
+//
+// 2) Configure a route in the linux host and ping once of the nodes on the
+// right, across the point-to-point link. You will see relatively large
+// delays due to CBR background traffic on the point-to-point (see next
+// item).
+//
+// ./waf --run tap-wifi-dumbbell&
+// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
+// ping 10.1.3.4
+//
+// Take a look at the pcap traces and note that the timing reflects the
+// addition of the significant delay and low bandwidth configured on the
+// point-to-point link along with the high traffic.
+//
+// 3) Fiddle with the background CBR traffic across the point-to-point
+// link and watch the ping timing change. The OnOffApplication "DataRate"
+// attribute defaults to 500kb/s and the "PacketSize" Attribute defaults
+// to 512. The point-to-point "DataRate" is set to 512kb/s in the script,
+// so in the default case, the link is pretty full. This should be
+// reflected in large delays seen by ping. You can crank down the CBR
+// traffic data rate and watch the ping timing change dramatically.
+//
+// ./waf --run "tap-wifi-dumbbell --ns3::OnOffApplication::DataRate=100kb/s"&
+// sudo route add -net 10.1.3.0 netmask 255.255.255.0 dev thetap gw 10.1.1.2
+// ping 10.1.3.4
+//
+// 4) Try to run this in UseLocal mode. This allows you to provide an existing
+// pre-configured tap device to the simulation. The IP address and MAC
+// address in this mode do not have to match those of the ns-3 device.
+//
+// sudo tunctl -t mytap
+// sudo ifconfig mytap hw ether 08:00:2e:00:00:01
+// sudo ifconfig mytap 10.1.1.1 netmask 255.255.255.0 up
+// ./waf --run "tap-wifi-dumbbell --mode=UseLocal --tapName=mytap"&
+// ping 10.1.1.3
+//
+// 5) Try to run this in UseBridge mode. This allows you to bridge an ns-3
+// simulation to an existing pre-configured bridge. This uses tap devices
+// just for illustration, you can create your own bridge if you want.
+//
+// sudo tunctl -t mytap1
+// sudo ifconfig mytap1 0.0.0.0 promisc up
+// sudo tunctl -t mytap2
+// sudo ifconfig mytap2 0.0.0.0 promisc up
+// sudo brctl addbr mybridge
+// sudo brctl addif mybridge mytap1
+// sudo brctl addif mybridge mytap2
+// sudo ifconfig mybridge 10.1.1.5 netmask 255.255.255.0 up
+// ./waf --run "tap-wifi-dumbbell --mode=UseBridge --tapName=mytap2"&
+// ping 10.1.1.3
+
+#include <iostream>
+#include <fstream>
+
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/core-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TapDumbbellExample");
+
+int
+main (int argc, char *argv[])
+{
+ std::string mode = "ConfigureLocal";
+ std::string tapName = "thetap";
+
+ CommandLine cmd;
+ cmd.AddValue("mode", "Mode setting of TapBridge", mode);
+ cmd.AddValue("tapName", "Name of the OS tap device", tapName);
+ cmd.Parse (argc, argv);
+
+ GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
+ GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
+
+ //
+ // The topology has a Wifi network of four nodes on the left side. We'll make
+ // node zero the AP and have the other three will be the STAs.
+ //
+ NodeContainer nodesLeft;
+ nodesLeft.Create (4);
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ Ssid ssid = Ssid ("left");
+ WifiHelper wifi = WifiHelper::Default ();
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
+
+ wifiMac.SetType ("ns3::NqapWifiMac",
+ "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ NetDeviceContainer devicesLeft = wifi.Install (wifiPhy, wifiMac, nodesLeft.Get (0));
+
+
+ wifiMac.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ devicesLeft.Add (wifi.Install (wifiPhy, wifiMac, NodeContainer (nodesLeft.Get (1), nodesLeft.Get (2), nodesLeft.Get (3))));
+
+ MobilityHelper mobility;
+ mobility.Install (nodesLeft);
+
+ InternetStackHelper internetLeft;
+ internetLeft.Install (nodesLeft);
+
+ Ipv4AddressHelper ipv4Left;
+ ipv4Left.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfacesLeft = ipv4Left.Assign (devicesLeft);
+
+ TapBridgeHelper tapBridge (interfacesLeft.GetAddress (1));
+ tapBridge.SetAttribute ("Mode", StringValue (mode));
+ tapBridge.SetAttribute ("DeviceName", StringValue (tapName));
+ tapBridge.Install (nodesLeft.Get (0), devicesLeft.Get (0));
+
+ //
+ // Now, create the right side.
+ //
+ NodeContainer nodesRight;
+ nodesRight.Create (4);
+
+ CsmaHelper csmaRight;
+ csmaRight.SetChannelAttribute ("DataRate", DataRateValue (5000000));
+ csmaRight.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+
+ NetDeviceContainer devicesRight = csmaRight.Install (nodesRight);
+
+ InternetStackHelper internetRight;
+ internetRight.Install (nodesRight);
+
+ Ipv4AddressHelper ipv4Right;
+ ipv4Right.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer interfacesRight = ipv4Right.Assign (devicesRight);
+
+ //
+ // Stick in the point-to-point line between the sides.
+ //
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("512kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+
+ NodeContainer nodes = NodeContainer (nodesLeft.Get(3), nodesRight.Get (0));
+ NetDeviceContainer devices = p2p.Install (nodes);
+
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.2.0", "255.255.255.192");
+ Ipv4InterfaceContainer interfaces = ipv4.Assign (devices);
+
+ //
+ // Simulate some CBR traffic over the point-to-point link
+ //
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (interfaces.GetAddress (1), port));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer apps = onoff.Install (nodesLeft.Get (3));
+ apps.Start (Seconds (1.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
+
+ apps = sink.Install (nodesRight.Get (0));
+ apps.Start (Seconds (1.0));
+
+ CsmaHelper::EnablePcapAll ("tap-wifi-dumbbell", false);
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ Simulator::Stop (Seconds (60.));
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tap/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tap/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,8 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ env = bld.env_of_name('default')
+ if env['ENABLE_TAP']:
+ obj = bld.create_ns3_program('tap-wifi-dumbbell',
+ ['wifi', 'csma', 'point-to-point', 'tap-bridge', 'internet-stack'])
+ obj.source = 'tap-wifi-dumbbell.cc'
--- a/examples/tcp-large-transfer.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-//
-// Network topology
-//
-// 10Mb/s, 10ms 10Mb/s, 10ms
-// n0-----------------n1-----------------n2
-//
-//
-// - Tracing of queues and packet receptions to file
-// "tcp-large-transfer.tr"
-// - pcap traces also generated in the following files
-// "tcp-large-transfer-$n-$i.pcap" where n and i represent node and interface
-// numbers respectively
-// Usage (e.g.): ./waf --run tcp-large-transfer
-
-
-#include <ctype.h>
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/node-module.h"
-#include "ns3/simulator-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TcpLargeTransfer");
-
-
-// The number of bytes to send in this simulation.
-static const uint32_t totalTxBytes = 2000000;
-static uint32_t currentTxBytes = 0;
-// Perform series of 1040 byte writes (this is a multiple of 26 since
-// we want to detect data splicing in the output stream)
-static const uint32_t writeSize = 1040;
-uint8_t data[writeSize];
-
-// These are for starting the writing process, and handling the sending
-// socket's notification upcalls (events). These two together more or less
-// implement a sending "Application", although not a proper ns3::Application
-// subclass.
-
-void StartFlow(Ptr<Socket>, Ipv4Address, uint16_t);
-void WriteUntilBufferFull (Ptr<Socket>, uint32_t);
-
-static void
-CwndTracer (uint32_t oldval, uint32_t newval)
-{
- NS_LOG_INFO ("Moving cwnd from " << oldval << " to " << newval);
-}
-
-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
- // LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
- // LogComponentEnable("TcpSocketImpl", LOG_LEVEL_ALL);
- // LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
- // LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL);
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // initialize the tx buffer.
- for(uint32_t i = 0; i < writeSize; ++i)
- {
- char m = toascii (97 + i % 26);
- data[i] = m;
- }
-
- // Here, we will explicitly create three nodes. The first container contains
- // nodes 0 and 1 from the diagram above, and the second one contains nodes
- // 1 and 2. This reflects the channel connectivity, and will be used to
- // install the network interfaces and connect them with a channel.
- NodeContainer n0n1;
- n0n1.Create (2);
-
- NodeContainer n1n2;
- n1n2.Add (n0n1.Get (1));
- n1n2.Create (1);
-
- // We create the channels first without any IP addressing information
- // First make and configure the helper, so that it will put the appropriate
- // attributes on the network interfaces and channels we are about to install.
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(10000000)));
- p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(10)));
-
- // And then install devices and channels connecting our topology.
- NetDeviceContainer dev0 = p2p.Install (n0n1);
- NetDeviceContainer dev1 = p2p.Install (n1n2);
-
- // Now add ip/tcp stack to all nodes.
- InternetStackHelper internet;
- internet.InstallAll ();
-
- // Later, we add IP addresses.
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- ipv4.Assign (dev0);
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer ipInterfs = ipv4.Assign (dev1);
-
- // and setup ip routing tables to get total ip-level connectivity.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- ///////////////////////////////////////////////////////////////////////////
- // Simulation 1
- //
- // Send 2000000 bytes over a connection to server port 50000 at time 0
- // Should observe SYN exchange, a lot of data segments and ACKS, and FIN
- // exchange. FIN exchange isn't quite compliant with TCP spec (see release
- // notes for more info)
- //
- ///////////////////////////////////////////////////////////////////////////
-
- uint16_t servPort = 50000;
-
- // Create a packet sink to receive these packets on n2...
- PacketSinkHelper sink ("ns3::TcpSocketFactory",
- InetSocketAddress (Ipv4Address::GetAny (), servPort));
-
- ApplicationContainer apps = sink.Install (n1n2.Get (1));
- apps.Start (Seconds (0.0));
- apps.Stop (Seconds (3.0));
-
- // Create a source to send packets from n0. Instead of a full Application
- // and the helper APIs you might see in other example files, this example
- // will use sockets directly and register some socket callbacks as a sending
- // "Application".
-
- // Create and bind the socket...
- Ptr<Socket> localSocket =
- Socket::CreateSocket (n0n1.Get (0), TcpSocketFactory::GetTypeId ());
- localSocket->Bind ();
-
- // Trace changes to the congestion window
- Config::ConnectWithoutContext ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer));
-
- // ...and schedule the sending "Application"; This is similar to what an
- // ns3::Application subclass would do internally.
- Simulator::ScheduleNow (&StartFlow, localSocket,
- ipInterfs.GetAddress (1), servPort);
-
- // One can toggle the comment for the following line on or off to see the
- // effects of finite send buffer modelling. One can also change the size of
- // said buffer.
-
- //localSocket->SetAttribute("SndBufSize", UintegerValue(4096));
-
- //Ask for ASCII and pcap traces of network traffic
- std::ofstream ascii;
- ascii.open ("tcp-large-transfer.tr");
- PointToPointHelper::EnableAsciiAll (ascii);
- PointToPointHelper::EnablePcapAll ("tcp-large-transfer");
-
- // Finally, set up the simulator to run. The 1000 second hard limit is a
- // failsafe in case some change above causes the simulation to never end
- Simulator::Stop (Seconds(1000));
- Simulator::Run ();
- Simulator::Destroy ();
-}
-
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//begin implementation of sending "Application"
-void StartFlow(Ptr<Socket> localSocket,
- Ipv4Address servAddress,
- uint16_t servPort)
-{
- NS_LOG_LOGIC("Starting flow at time " << Simulator::Now ().GetSeconds ());
- localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect
-
- // tell the tcp implementation to call WriteUntilBufferFull again
- // if we blocked and new tx buffer space becomes available
- localSocket->SetSendCallback (MakeCallback (&WriteUntilBufferFull));
- WriteUntilBufferFull (localSocket, localSocket->GetTxAvailable ());
-}
-
-void WriteUntilBufferFull (Ptr<Socket> localSocket, uint32_t txSpace)
-{
- while (currentTxBytes < totalTxBytes && localSocket->GetTxAvailable () > 0)
- {
- uint32_t left = totalTxBytes - currentTxBytes;
- uint32_t dataOffset = currentTxBytes % writeSize;
- uint32_t toWrite = writeSize - dataOffset;
- toWrite = std::min (toWrite, left);
- toWrite = std::min (toWrite, localSocket->GetTxAvailable ());
- int amountSent = localSocket->Send (&data[dataOffset], toWrite, 0);
- if(amountSent < 0)
- {
- // we will be called again when new tx space becomes available.
- return;
- }
- currentTxBytes += amountSent;
- }
- localSocket->Close ();
-}
--- a/examples/tcp-nsc-lfn.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-//
-// Network topology
-//
-// 6Mb/s, 500ms
-// n0-----------------n1
-//
-// - a 'lossy' network with long delay
-// - TCP flow from n0 to n1 and from n1 to n0
-// - pcap traces generated as tcp-nsc-lfn-0-0.pcap and tcp-nsc-lfn-1-0.pcap
-// Usage (e.g.): ./waf --run 'tcp-nsc-lfn --TCP_CONGESTION=hybla --runtime=30'
-
-#include <ctype.h>
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/node-module.h"
-#include "ns3/simulator-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TcpNscLfn");
-
-static void
-CwndTracer (uint32_t oldval, uint32_t newval)
-{
- NS_LOG_INFO ("Moving cwnd from " << oldval << " to " << newval);
-}
-
-int main (int argc, char *argv[])
-{
-
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps"));
-
- // cubic is the default congestion algorithm in Linux 2.6.26
- std::string tcpCong = "cubic";
- // this is the default error rate of our link, that is, the the probability of a single
- // byte being 'corrupted' during transfer.
- double errRate = 0.000001;
- // how long the sender should be running, in seconds.
- unsigned int runtime = 120;
- // the name of the NSC stack library that should be used
- std::string nscStack = "liblinux2.6.26.so";
-
- CommandLine cmd;
- // Here, we define additional command line options.
- // This allows a user to override the defaults set above from the command line.
- cmd.AddValue("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong);
- cmd.AddValue("error-rate", "Error rate to apply to link", errRate);
- cmd.AddValue("runtime", "How long the applications should send data (default 120 seconds)", runtime);
- cmd.AddValue("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack);
- cmd.Parse (argc, argv);
-
- NodeContainer n;
- n.Create (2);
-
- PointToPointHelper p2p;
- // create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds)
- p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(6 * 1000 * 1000)));
- p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(500)));
-
- NetDeviceContainer p2pInterfaces = p2p.Install (n);
- // The default MTU of the p2p link would be 65535, which doesn't work
- // well with our default errRate (most packets would arrive corrupted).
- p2pInterfaces.Get(0)->SetMtu(1500);
- p2pInterfaces.Get(1)->SetMtu(1500);
-
- InternetStackHelper internet;
- // The next statement switches the nodes to 'NSC'-Mode.
- // It disables the native ns-3 TCP model and loads the NSC library.
- internet.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue(nscStack));
- internet.Install (n);
-
- if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used
- {
- // This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the
- // stack.
- // The same mechanism could be used to e.g. disable TCP timestamps:
- // Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
- Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong));
- }
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.0.0.0", "255.255.255.0");
- Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces);
-
- DoubleValue rate(errRate);
- RandomVariableValue u01(UniformVariable (0.0, 1.0));
- Ptr<RateErrorModel> em1 =
- CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
- Ptr<RateErrorModel> em2 =
- CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
-
- // This enables the specified errRate on both link endpoints.
- p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1));
- p2pInterfaces.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em2));
-
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- uint16_t servPort = 8080;
- PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
- ApplicationContainer sinkApp = sinkHelper.Install (n);
- sinkApp.Start (Seconds (0.0));
- // this makes sure that the receiver will run one minute longer than the sender applicaton.
- sinkApp.Stop (Seconds (runtime + 60.0));
-
- // This sets up two TCP flows, one from A -> B, one from B -> A.
- for (int i = 0, j = 1; i < 2; j--, i++)
- {
- Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (i), servPort));
- OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
- clientHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- clientHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer clientApp = clientHelper.Install(n.Get(j));
- clientApp.Start (Seconds (1.0 + i));
- clientApp.Stop (Seconds (runtime + 1.0 + i));
- }
-
- // Trace changes to the congestion window
- Config::ConnectWithoutContext ("/NodeList/1/$ns3::NscTcpL4Protocol/SocketList/0/CongestionWindow",
- MakeCallback (&CwndTracer));
-
- // This tells ns-3 to generate pcap traces.
- PointToPointHelper::EnablePcapAll ("tcp-nsc-lfn");
-
- Simulator::Stop (Seconds(900));
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/tcp-nsc-zoo.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-
-// Network topology
-//
-// n0 n1 n2 n3
-// | | | |
-// =================
-// LAN
-//
-// - Pcap traces are saved as tcp-nsc-zoo-$n-0.pcap, where $n represents the node number
-// - TCP flows from n0 to n1, n2, n3, from n1 to n0, n2, n3, etc.
-// Usage (e.g.): ./waf --run 'tcp-nsc-zoo --nodes=5'
-
-#include <iostream>
-#include <string>
-
-#include "ns3/core-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/node-module.h"
-#include "ns3/simulator-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TcpNscZoo");
-
-// Simulates a diverse network with various stacks supported by NSC.
-int main(int argc, char *argv[])
-{
- CsmaHelper csma;
- unsigned int MaxNodes = 4;
- unsigned int runtime = 3;
-
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (2048));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("8kbps"));
- CommandLine cmd;
- // this allows the user to raise the number of nodes using --nodes=X command-line argument.
- cmd.AddValue("nodes", "Number of nodes in the network (must be > 1)", MaxNodes);
- cmd.AddValue("runtime", "How long the applications should send data (default 3 seconds)", runtime);
- cmd.Parse (argc, argv);
-
- if (MaxNodes < 2)
- {
- std::cerr << "--nodes: must be >= 2" << std::endl;
- return 1;
- }
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(100 * 1000 * 1000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (200)));
-
- NodeContainer n;
- n.Create(MaxNodes);
- NetDeviceContainer ethInterfaces = csma.Install (n);
-
- InternetStackHelper internetStack;
- internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.26.so"));
- // this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
- internetStack.Install (n.Get(0));
- internetStack.Install (n.Get(1));
- // this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values).
- Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0"));
- Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
- Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0"));
-
- if (MaxNodes > 2)
- {
- internetStack.Install (n.Get(2));
- }
-
- if (MaxNodes > 3)
- {
- // the next statement doesn't change anything for the nodes 0, 1, and 2; since they
- // already have a stack assigned.
- internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.18.so"));
- // this switches node 3 to NSCs Linux 2.6.18 stack.
- internetStack.Install (n.Get(3));
- // and then agains disables sack/timestamps/wscale on node 3.
- Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_sack", StringValue ("0"));
- Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_timestamps", StringValue ("0"));
- Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_window_scaling", StringValue ("0"));
- }
- // the freebsd stack is not yet built by default, so its commented out for now.
- // internetStack.SetNscStack ("libfreebsd5.so");
- for (unsigned int i =4; i < MaxNodes; i++)
- {
- internetStack.Install (n.Get(i));
- }
- Ipv4AddressHelper ipv4;
-
- ipv4.SetBase ("10.0.0.0", "255.255.255.0");
- Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (ethInterfaces);
-
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- uint16_t servPort = 8080;
- PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
- // start a sink client on all nodes
- ApplicationContainer sinkApp = sinkHelper.Install (n);
- sinkApp.Start (Seconds (0));
- sinkApp.Stop (Seconds (30.0));
-
- // This tells every node on the network to start a flow to all other nodes on the network ...
- for (unsigned int i = 0 ; i < MaxNodes;i++)
- {
- for (unsigned int j = 0 ; j < MaxNodes;j++)
- {
- if (i == j)
- { // ...but we don't want a node to talk to itself.
- continue;
- }
- Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (j), servPort));
- OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
- clientHelper.SetAttribute
- ("OnTime", RandomVariableValue (ConstantVariable (1)));
- clientHelper.SetAttribute
- ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer clientApp = clientHelper.Install(n.Get(i));
- clientApp.Start (Seconds (j)); /* delay startup depending on node number */
- clientApp.Stop (Seconds (j + runtime));
- }
- }
-
- CsmaHelper::EnablePcapAll ("tcp-nsc-zoo", false);
-
- Simulator::Stop (Seconds(100));
- Simulator::Run ();
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/tcp-star-server.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-
-// Default Network topology, 9 nodes in a star
-/*
- n2 n3 n4
- \ | /
- \|/
- n1---n0---n5
- /|\
- / | \
- n8 n7 n6
-*/
-// - CBR Traffic goes from the star "arms" to the "hub"
-// - Tracing of queues and packet receptions to file
-// "tcp-star-server.tr"
-// - pcap traces also generated in the following files
-// "tcp-star-server-$n-$i.pcap" where n and i represent node and interface
-// numbers respectively
-// Usage examples for things you might want to tweak:
-// ./waf --run="tcp-star-server"
-// ./waf --run="tcp-star-server --nNodes=25"
-// ./waf --run="tcp-star-server --ns3::OnOffApplication::DataRate=10000"
-// ./waf --run="tcp-star-server --ns3::OnOffApplication::PacketSize=500"
-// See the ns-3 tutorial for more info on the command line:
-// http://www.nsnam.org/tutorials.html
-
-
-
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TcpServer");
-
-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
-
- //LogComponentEnable ("TcpServer", LOG_LEVEL_INFO);
- //LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_ALL);
- //LogComponentEnable ("TcpSocketImpl", LOG_LEVEL_ALL);
- //LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
-
- // Set up some default values for the simulation.
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (250));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("5kb/s"));
- uint32_t N = 9; //number of nodes in the star
-
- // Allow the user to override any of the defaults and the above
- // Config::SetDefault()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.AddValue("nNodes", "Number of nodes to place in the star", N);
- cmd.Parse (argc, argv);
-
- // Here, we will create N nodes in a star.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer serverNode;
- NodeContainer clientNodes;
- serverNode.Create(1);
- clientNodes.Create(N-1);
- NodeContainer allNodes = NodeContainer(serverNode, clientNodes);
-
- // Install network stacks on the nodes
- InternetStackHelper internet;
- internet.Install (allNodes);
-
- //Collect an adjacency list of nodes for the p2p topology
- std::vector<NodeContainer> nodeAdjacencyList(N-1);
- for(uint32_t i=0; i<nodeAdjacencyList.size(); ++i)
- {
- nodeAdjacencyList[i] = NodeContainer (serverNode, clientNodes.Get (i));
- }
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- std::vector<NetDeviceContainer> deviceAdjacencyList(N-1);
- for(uint32_t i=0; i<deviceAdjacencyList.size(); ++i)
- {
- deviceAdjacencyList[i] = p2p.Install (nodeAdjacencyList[i]);
- }
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- std::vector<Ipv4InterfaceContainer> interfaceAdjacencyList(N-1);
- for(uint32_t i=0; i<interfaceAdjacencyList.size(); ++i)
- {
- std::ostringstream subnet;
- subnet<<"10.1."<<i+1<<".0";
- ipv4.SetBase (subnet.str().c_str(), "255.255.255.0");
- interfaceAdjacencyList[i] = ipv4.Assign (deviceAdjacencyList[i]);
- }
-
- //Turn on global static routing
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Create a packet sink on the star "hub" to receive these packets
- uint16_t port = 50000;
- Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
- PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
- ApplicationContainer sinkApp = sinkHelper.Install (serverNode);
- sinkApp.Start (Seconds (1.0));
- sinkApp.Stop (Seconds (10.0));
-
- // Create the OnOff applications to send TCP to the server
- OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
- clientHelper.SetAttribute
- ("OnTime", RandomVariableValue (ConstantVariable (1)));
- clientHelper.SetAttribute
- ("OffTime", RandomVariableValue (ConstantVariable (0)));
- //normally wouldn't need a loop here but the server IP address is different
- //on each p2p subnet
- ApplicationContainer clientApps;
- for(uint32_t i=0; i<clientNodes.GetN(); ++i)
- {
- AddressValue remoteAddress
- (InetSocketAddress (interfaceAdjacencyList[i].GetAddress (0), port));
- clientHelper.SetAttribute ("Remote", remoteAddress);
- clientApps.Add(clientHelper.Install (clientNodes.Get(i)));
- }
- clientApps.Start (Seconds (1.0));
- clientApps.Stop (Seconds (10.0));
-
-
- //configure tracing
- std::ofstream ascii;
- ascii.open ("tcp-star-server.tr");
- PointToPointHelper::EnablePcapAll ("tcp-star-server");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/star.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,148 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+// Network topology (default)
+//
+// n2 n3 n4 .
+// \ | / .
+// \|/ .
+// n1--- n0---n5 .
+// /|\ .
+// / | \ .
+// n8 n7 n6 .
+//
+
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("Star");
+
+int
+main (int argc, char *argv[])
+{
+
+ //
+ // Set up some default values for the simulation.
+ //
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
+
+ // ??? try and stick 15kb/s into the data rate
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
+
+ //
+ // Default number of nodes in the star. Overridable by command line argument.
+ //
+ uint32_t nNodes = 9;
+
+ CommandLine cmd;
+ cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer hubNode;
+ NodeContainer spokeNodes;
+ hubNode.Create (1);
+ Ptr<Node> hub = hubNode.Get (0);
+ spokeNodes.Create (nNodes - 1);
+
+ NS_LOG_INFO ("Install internet stack on all nodes.");
+ InternetStackHelper internet;
+ internet.Install (NodeContainer (hubNode, spokeNodes));
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ NS_LOG_INFO ("Build star topology.");
+ NetDeviceContainer hubDevices, spokeDevices;
+ pointToPoint.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper address;
+
+ //
+ // Assign IPv4 interfaces and IP addresses to the devices we previously
+ // created. Keep track of the resulting addresses, one for the addresses
+ // of the hub node, and one for addresses on the spoke nodes. Despite the
+ // name of the class, what is visible to clients is really the address.
+ //
+ Ipv4InterfaceContainer hubAddresses;
+ Ipv4InterfaceContainer spokeAddresses;
+
+ for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ {
+ std::ostringstream subnet;
+ subnet << "10.1.1." << (i << 2);
+ NS_LOG_INFO ("Assign IP Addresses for point-to-point subnet " << subnet.str ());
+ address.SetBase (subnet.str ().c_str (), "255.255.255.252");
+ hubAddresses.Add (address.Assign (hubDevices.Get (i)));
+ spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
+ }
+
+ NS_LOG_INFO ("Create applications.");
+ //
+ // Create a packet sink on the star "hub" to receive packets.
+ //
+ uint16_t port = 50000;
+ Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
+ ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
+ hubApp.Start (Seconds (1.0));
+ hubApp.Stop (Seconds (10.0));
+
+ //
+ // Create OnOff applications to send TCP to the hub, one on each spoke node.
+ //
+ OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
+ onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer spokeApps;
+
+ for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ {
+ AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
+ }
+ spokeApps.Start (Seconds (1.0));
+ spokeApps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Enable static global routing.");
+ //
+ // Turn on global static routing so we can actually be routed across the star.
+ //
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ NS_LOG_INFO ("Enable pcap tracing.");
+ //
+ // Do pcap tracing on all point-to-point devices on all nodes.
+ //
+ PointToPointHelper::EnablePcapAll ("star");
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/tcp-large-transfer.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,219 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// Network topology
+//
+// 10Mb/s, 10ms 10Mb/s, 10ms
+// n0-----------------n1-----------------n2
+//
+//
+// - Tracing of queues and packet receptions to file
+// "tcp-large-transfer.tr"
+// - pcap traces also generated in the following files
+// "tcp-large-transfer-$n-$i.pcap" where n and i represent node and interface
+// numbers respectively
+// Usage (e.g.): ./waf --run tcp-large-transfer
+
+
+#include <ctype.h>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/node-module.h"
+#include "ns3/simulator-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TcpLargeTransfer");
+
+
+// The number of bytes to send in this simulation.
+static const uint32_t totalTxBytes = 2000000;
+static uint32_t currentTxBytes = 0;
+// Perform series of 1040 byte writes (this is a multiple of 26 since
+// we want to detect data splicing in the output stream)
+static const uint32_t writeSize = 1040;
+uint8_t data[writeSize];
+
+// These are for starting the writing process, and handling the sending
+// socket's notification upcalls (events). These two together more or less
+// implement a sending "Application", although not a proper ns3::Application
+// subclass.
+
+void StartFlow(Ptr<Socket>, Ipv4Address, uint16_t);
+void WriteUntilBufferFull (Ptr<Socket>, uint32_t);
+
+static void
+CwndTracer (uint32_t oldval, uint32_t newval)
+{
+ NS_LOG_INFO ("Moving cwnd from " << oldval << " to " << newval);
+}
+
+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
+ // LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
+ // LogComponentEnable("TcpSocketImpl", LOG_LEVEL_ALL);
+ // LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
+ // LogComponentEnable("TcpLargeTransfer", LOG_LEVEL_ALL);
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // initialize the tx buffer.
+ for(uint32_t i = 0; i < writeSize; ++i)
+ {
+ char m = toascii (97 + i % 26);
+ data[i] = m;
+ }
+
+ // Here, we will explicitly create three nodes. The first container contains
+ // nodes 0 and 1 from the diagram above, and the second one contains nodes
+ // 1 and 2. This reflects the channel connectivity, and will be used to
+ // install the network interfaces and connect them with a channel.
+ NodeContainer n0n1;
+ n0n1.Create (2);
+
+ NodeContainer n1n2;
+ n1n2.Add (n0n1.Get (1));
+ n1n2.Create (1);
+
+ // We create the channels first without any IP addressing information
+ // First make and configure the helper, so that it will put the appropriate
+ // attributes on the network interfaces and channels we are about to install.
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(10000000)));
+ p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(10)));
+
+ // And then install devices and channels connecting our topology.
+ NetDeviceContainer dev0 = p2p.Install (n0n1);
+ NetDeviceContainer dev1 = p2p.Install (n1n2);
+
+ // Now add ip/tcp stack to all nodes.
+ InternetStackHelper internet;
+ internet.InstallAll ();
+
+ // Later, we add IP addresses.
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ ipv4.Assign (dev0);
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer ipInterfs = ipv4.Assign (dev1);
+
+ // and setup ip routing tables to get total ip-level connectivity.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Simulation 1
+ //
+ // Send 2000000 bytes over a connection to server port 50000 at time 0
+ // Should observe SYN exchange, a lot of data segments and ACKS, and FIN
+ // exchange. FIN exchange isn't quite compliant with TCP spec (see release
+ // notes for more info)
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ uint16_t servPort = 50000;
+
+ // Create a packet sink to receive these packets on n2...
+ PacketSinkHelper sink ("ns3::TcpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), servPort));
+
+ ApplicationContainer apps = sink.Install (n1n2.Get (1));
+ apps.Start (Seconds (0.0));
+ apps.Stop (Seconds (3.0));
+
+ // Create a source to send packets from n0. Instead of a full Application
+ // and the helper APIs you might see in other example files, this example
+ // will use sockets directly and register some socket callbacks as a sending
+ // "Application".
+
+ // Create and bind the socket...
+ Ptr<Socket> localSocket =
+ Socket::CreateSocket (n0n1.Get (0), TcpSocketFactory::GetTypeId ());
+ localSocket->Bind ();
+
+ // Trace changes to the congestion window
+ Config::ConnectWithoutContext ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer));
+
+ // ...and schedule the sending "Application"; This is similar to what an
+ // ns3::Application subclass would do internally.
+ Simulator::ScheduleNow (&StartFlow, localSocket,
+ ipInterfs.GetAddress (1), servPort);
+
+ // One can toggle the comment for the following line on or off to see the
+ // effects of finite send buffer modelling. One can also change the size of
+ // said buffer.
+
+ //localSocket->SetAttribute("SndBufSize", UintegerValue(4096));
+
+ //Ask for ASCII and pcap traces of network traffic
+ std::ofstream ascii;
+ ascii.open ("tcp-large-transfer.tr");
+ PointToPointHelper::EnableAsciiAll (ascii);
+ PointToPointHelper::EnablePcapAll ("tcp-large-transfer");
+
+ // Finally, set up the simulator to run. The 1000 second hard limit is a
+ // failsafe in case some change above causes the simulation to never end
+ Simulator::Stop (Seconds(1000));
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
+
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//begin implementation of sending "Application"
+void StartFlow(Ptr<Socket> localSocket,
+ Ipv4Address servAddress,
+ uint16_t servPort)
+{
+ NS_LOG_LOGIC("Starting flow at time " << Simulator::Now ().GetSeconds ());
+ localSocket->Connect (InetSocketAddress (servAddress, servPort));//connect
+
+ // tell the tcp implementation to call WriteUntilBufferFull again
+ // if we blocked and new tx buffer space becomes available
+ localSocket->SetSendCallback (MakeCallback (&WriteUntilBufferFull));
+ WriteUntilBufferFull (localSocket, localSocket->GetTxAvailable ());
+}
+
+void WriteUntilBufferFull (Ptr<Socket> localSocket, uint32_t txSpace)
+{
+ while (currentTxBytes < totalTxBytes && localSocket->GetTxAvailable () > 0)
+ {
+ uint32_t left = totalTxBytes - currentTxBytes;
+ uint32_t dataOffset = currentTxBytes % writeSize;
+ uint32_t toWrite = writeSize - dataOffset;
+ toWrite = std::min (toWrite, left);
+ toWrite = std::min (toWrite, localSocket->GetTxAvailable ());
+ int amountSent = localSocket->Send (&data[dataOffset], toWrite, 0);
+ if(amountSent < 0)
+ {
+ // we will be called again when new tx space becomes available.
+ return;
+ }
+ currentTxBytes += amountSent;
+ }
+ localSocket->Close ();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/tcp-nsc-lfn.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,152 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// Network topology
+//
+// 6Mb/s, 500ms
+// n0-----------------n1
+//
+// - a 'lossy' network with long delay
+// - TCP flow from n0 to n1 and from n1 to n0
+// - pcap traces generated as tcp-nsc-lfn-0-0.pcap and tcp-nsc-lfn-1-0.pcap
+// Usage (e.g.): ./waf --run 'tcp-nsc-lfn --TCP_CONGESTION=hybla --runtime=30'
+
+#include <ctype.h>
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/node-module.h"
+#include "ns3/simulator-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TcpNscLfn");
+
+static void
+CwndTracer (uint32_t oldval, uint32_t newval)
+{
+ NS_LOG_INFO ("Moving cwnd from " << oldval << " to " << newval);
+}
+
+int main (int argc, char *argv[])
+{
+
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps"));
+
+ // cubic is the default congestion algorithm in Linux 2.6.26
+ std::string tcpCong = "cubic";
+ // this is the default error rate of our link, that is, the the probability of a single
+ // byte being 'corrupted' during transfer.
+ double errRate = 0.000001;
+ // how long the sender should be running, in seconds.
+ unsigned int runtime = 120;
+ // the name of the NSC stack library that should be used
+ std::string nscStack = "liblinux2.6.26.so";
+
+ CommandLine cmd;
+ // Here, we define additional command line options.
+ // This allows a user to override the defaults set above from the command line.
+ cmd.AddValue("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong);
+ cmd.AddValue("error-rate", "Error rate to apply to link", errRate);
+ cmd.AddValue("runtime", "How long the applications should send data (default 120 seconds)", runtime);
+ cmd.AddValue("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack);
+ cmd.Parse (argc, argv);
+
+ NodeContainer n;
+ n.Create (2);
+
+ PointToPointHelper p2p;
+ // create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds)
+ p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(6 * 1000 * 1000)));
+ p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(500)));
+
+ NetDeviceContainer p2pInterfaces = p2p.Install (n);
+ // The default MTU of the p2p link would be 65535, which doesn't work
+ // well with our default errRate (most packets would arrive corrupted).
+ p2pInterfaces.Get(0)->SetMtu(1500);
+ p2pInterfaces.Get(1)->SetMtu(1500);
+
+ InternetStackHelper internet;
+ // The next statement switches the nodes to 'NSC'-Mode.
+ // It disables the native ns-3 TCP model and loads the NSC library.
+ internet.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue(nscStack));
+ internet.Install (n);
+
+ if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used
+ {
+ // This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the
+ // stack.
+ // The same mechanism could be used to e.g. disable TCP timestamps:
+ // Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
+ Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong));
+ }
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.0.0.0", "255.255.255.0");
+ Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces);
+
+ DoubleValue rate(errRate);
+ RandomVariableValue u01(UniformVariable (0.0, 1.0));
+ Ptr<RateErrorModel> em1 =
+ CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
+ Ptr<RateErrorModel> em2 =
+ CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
+
+ // This enables the specified errRate on both link endpoints.
+ p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1));
+ p2pInterfaces.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em2));
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ uint16_t servPort = 8080;
+ PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
+ ApplicationContainer sinkApp = sinkHelper.Install (n);
+ sinkApp.Start (Seconds (0.0));
+ // this makes sure that the receiver will run one minute longer than the sender applicaton.
+ sinkApp.Stop (Seconds (runtime + 60.0));
+
+ // This sets up two TCP flows, one from A -> B, one from B -> A.
+ for (int i = 0, j = 1; i < 2; j--, i++)
+ {
+ Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (i), servPort));
+ OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
+ clientHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ clientHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer clientApp = clientHelper.Install(n.Get(j));
+ clientApp.Start (Seconds (1.0 + i));
+ clientApp.Stop (Seconds (runtime + 1.0 + i));
+ }
+
+ // Trace changes to the congestion window
+ Config::ConnectWithoutContext ("/NodeList/1/$ns3::NscTcpL4Protocol/SocketList/0/CongestionWindow",
+ MakeCallback (&CwndTracer));
+
+ // This tells ns-3 to generate pcap traces.
+ PointToPointHelper::EnablePcapAll ("tcp-nsc-lfn");
+
+ Simulator::Stop (Seconds(900));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/tcp-nsc-zoo.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,144 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+// - Pcap traces are saved as tcp-nsc-zoo-$n-0.pcap, where $n represents the node number
+// - TCP flows from n0 to n1, n2, n3, from n1 to n0, n2, n3, etc.
+// Usage (e.g.): ./waf --run 'tcp-nsc-zoo --nodes=5'
+
+#include <iostream>
+#include <string>
+
+#include "ns3/core-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/node-module.h"
+#include "ns3/simulator-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TcpNscZoo");
+
+// Simulates a diverse network with various stacks supported by NSC.
+int main(int argc, char *argv[])
+{
+ CsmaHelper csma;
+ unsigned int MaxNodes = 4;
+ unsigned int runtime = 3;
+
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (2048));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("8kbps"));
+ CommandLine cmd;
+ // this allows the user to raise the number of nodes using --nodes=X command-line argument.
+ cmd.AddValue("nodes", "Number of nodes in the network (must be > 1)", MaxNodes);
+ cmd.AddValue("runtime", "How long the applications should send data (default 3 seconds)", runtime);
+ cmd.Parse (argc, argv);
+
+ if (MaxNodes < 2)
+ {
+ std::cerr << "--nodes: must be >= 2" << std::endl;
+ return 1;
+ }
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(100 * 1000 * 1000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (200)));
+
+ NodeContainer n;
+ n.Create(MaxNodes);
+ NetDeviceContainer ethInterfaces = csma.Install (n);
+
+ InternetStackHelper internetStack;
+ internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.26.so"));
+ // this switches nodes 0 and 1 to NSCs Linux 2.6.26 stack.
+ internetStack.Install (n.Get(0));
+ internetStack.Install (n.Get(1));
+ // this disables TCP SACK, wscale and timestamps on node 1 (the attributes represent sysctl-values).
+ Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0"));
+ Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
+ Config::Set ("/NodeList/1/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0"));
+
+ if (MaxNodes > 2)
+ {
+ internetStack.Install (n.Get(2));
+ }
+
+ if (MaxNodes > 3)
+ {
+ // the next statement doesn't change anything for the nodes 0, 1, and 2; since they
+ // already have a stack assigned.
+ internetStack.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue("liblinux2.6.18.so"));
+ // this switches node 3 to NSCs Linux 2.6.18 stack.
+ internetStack.Install (n.Get(3));
+ // and then agains disables sack/timestamps/wscale on node 3.
+ Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_sack", StringValue ("0"));
+ Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_timestamps", StringValue ("0"));
+ Config::Set ("/NodeList/3/$ns3::Ns3NscStack<linux2.6.18>/net.ipv4.tcp_window_scaling", StringValue ("0"));
+ }
+ // the freebsd stack is not yet built by default, so its commented out for now.
+ // internetStack.SetNscStack ("libfreebsd5.so");
+ for (unsigned int i =4; i < MaxNodes; i++)
+ {
+ internetStack.Install (n.Get(i));
+ }
+ Ipv4AddressHelper ipv4;
+
+ ipv4.SetBase ("10.0.0.0", "255.255.255.0");
+ Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (ethInterfaces);
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ uint16_t servPort = 8080;
+ PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
+ // start a sink client on all nodes
+ ApplicationContainer sinkApp = sinkHelper.Install (n);
+ sinkApp.Start (Seconds (0));
+ sinkApp.Stop (Seconds (30.0));
+
+ // This tells every node on the network to start a flow to all other nodes on the network ...
+ for (unsigned int i = 0 ; i < MaxNodes;i++)
+ {
+ for (unsigned int j = 0 ; j < MaxNodes;j++)
+ {
+ if (i == j)
+ { // ...but we don't want a node to talk to itself.
+ continue;
+ }
+ Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (j), servPort));
+ OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer clientApp = clientHelper.Install(n.Get(i));
+ clientApp.Start (Seconds (j)); /* delay startup depending on node number */
+ clientApp.Stop (Seconds (j + runtime));
+ }
+ }
+
+ CsmaHelper::EnablePcapAll ("tcp-nsc-zoo", false);
+
+ Simulator::Stop (Seconds(100));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/tcp-star-server.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,167 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+// Default Network topology, 9 nodes in a star
+/*
+ n2 n3 n4
+ \ | /
+ \|/
+ n1---n0---n5
+ /|\
+ / | \
+ n8 n7 n6
+*/
+// - CBR Traffic goes from the star "arms" to the "hub"
+// - Tracing of queues and packet receptions to file
+// "tcp-star-server.tr"
+// - pcap traces also generated in the following files
+// "tcp-star-server-$n-$i.pcap" where n and i represent node and interface
+// numbers respectively
+// Usage examples for things you might want to tweak:
+// ./waf --run="tcp-star-server"
+// ./waf --run="tcp-star-server --nNodes=25"
+// ./waf --run="tcp-star-server --ns3::OnOffApplication::DataRate=10000"
+// ./waf --run="tcp-star-server --ns3::OnOffApplication::PacketSize=500"
+// See the ns-3 tutorial for more info on the command line:
+// http://www.nsnam.org/tutorials.html
+
+
+
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TcpServer");
+
+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
+
+ //LogComponentEnable ("TcpServer", LOG_LEVEL_INFO);
+ //LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_ALL);
+ //LogComponentEnable ("TcpSocketImpl", LOG_LEVEL_ALL);
+ //LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
+
+ // Set up some default values for the simulation.
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (250));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("5kb/s"));
+ uint32_t N = 9; //number of nodes in the star
+
+ // Allow the user to override any of the defaults and the above
+ // Config::SetDefault()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.AddValue("nNodes", "Number of nodes to place in the star", N);
+ cmd.Parse (argc, argv);
+
+ // Here, we will create N nodes in a star.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer serverNode;
+ NodeContainer clientNodes;
+ serverNode.Create(1);
+ clientNodes.Create(N-1);
+ NodeContainer allNodes = NodeContainer(serverNode, clientNodes);
+
+ // Install network stacks on the nodes
+ InternetStackHelper internet;
+ internet.Install (allNodes);
+
+ //Collect an adjacency list of nodes for the p2p topology
+ std::vector<NodeContainer> nodeAdjacencyList(N-1);
+ for(uint32_t i=0; i<nodeAdjacencyList.size(); ++i)
+ {
+ nodeAdjacencyList[i] = NodeContainer (serverNode, clientNodes.Get (i));
+ }
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ std::vector<NetDeviceContainer> deviceAdjacencyList(N-1);
+ for(uint32_t i=0; i<deviceAdjacencyList.size(); ++i)
+ {
+ deviceAdjacencyList[i] = p2p.Install (nodeAdjacencyList[i]);
+ }
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ std::vector<Ipv4InterfaceContainer> interfaceAdjacencyList(N-1);
+ for(uint32_t i=0; i<interfaceAdjacencyList.size(); ++i)
+ {
+ std::ostringstream subnet;
+ subnet<<"10.1."<<i+1<<".0";
+ ipv4.SetBase (subnet.str().c_str(), "255.255.255.0");
+ interfaceAdjacencyList[i] = ipv4.Assign (deviceAdjacencyList[i]);
+ }
+
+ //Turn on global static routing
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Create a packet sink on the star "hub" to receive these packets
+ uint16_t port = 50000;
+ Address sinkLocalAddress(InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
+ ApplicationContainer sinkApp = sinkHelper.Install (serverNode);
+ sinkApp.Start (Seconds (1.0));
+ sinkApp.Stop (Seconds (10.0));
+
+ // Create the OnOff applications to send TCP to the server
+ OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ //normally wouldn't need a loop here but the server IP address is different
+ //on each p2p subnet
+ ApplicationContainer clientApps;
+ for(uint32_t i=0; i<clientNodes.GetN(); ++i)
+ {
+ AddressValue remoteAddress
+ (InetSocketAddress (interfaceAdjacencyList[i].GetAddress (0), port));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add(clientHelper.Install (clientNodes.Get(i)));
+ }
+ clientApps.Start (Seconds (1.0));
+ clientApps.Stop (Seconds (10.0));
+
+
+ //configure tracing
+ std::ofstream ascii;
+ ascii.open ("tcp-star-server.tr");
+ PointToPointHelper::EnablePcapAll ("tcp-star-server");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tcp/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,22 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('tcp-large-transfer',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'tcp-large-transfer.cc'
+
+ obj = bld.create_ns3_program('tcp-nsc-lfn',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'tcp-nsc-lfn.cc'
+
+ obj = bld.create_ns3_program('tcp-nsc-zoo',
+ ['csma', 'internet-stack'])
+ obj.source = 'tcp-nsc-zoo.cc'
+
+ obj = bld.create_ns3_program('tcp-star-server',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'tcp-star-server.cc'
+
+ obj = bld.create_ns3_program('star',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'star.cc'
--- a/examples/test-ipv6.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2008 Louis Pasteur University / Telecom Bretagne
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Angelos Chatzipapas <Angelos.CHATZIPAPAS@enst-bretagne.fr> /
- * <chatzipa@ceid.upatras.gr>
- */
-
-#include "ns3/log.h"
-#include "ns3/ipv6-address.h"
-#include "ns3/node.h"
-#include "ns3/mac48-address.h"
-
-NS_LOG_COMPONENT_DEFINE ("TestIpv6");
-
-using namespace ns3;
-
-int
-main (int argc, char *argv[])
-{
- LogComponentEnable ("TestIpv6", LOG_LEVEL_ALL);
-
- NS_LOG_INFO ("Test Ipv6");
-
- Mac48Address m_addresses[10];
-
- m_addresses[0] = ("00:00:00:00:00:01");
- m_addresses[1] = ("00:00:00:00:00:02");
- m_addresses[2] = ("00:00:00:00:00:03");
- m_addresses[3] = ("00:00:00:00:00:04");
- m_addresses[4] = ("00:00:00:00:00:05");
- m_addresses[5] = ("00:00:00:00:00:06");
- m_addresses[6] = ("00:00:00:00:00:07");
- m_addresses[7] = ("00:00:00:00:00:08");
- m_addresses[8] = ("00:00:00:00:00:09");
- m_addresses[9] = ("00:00:00:00:00:10");
-
- Ipv6Address prefix1 ("2001:1::");
- NS_LOG_INFO ("prefix = " << prefix1);
- for (uint32_t i = 0; i < 10 ; ++i)
- {
- NS_LOG_INFO ("address = " << m_addresses[i]);
- Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix1);
- NS_LOG_INFO ("address = " << ipv6address);
- }
-
- Ipv6Address prefix2 ("2002:1:1::");
-
- NS_LOG_INFO ("prefix = " << prefix2);
- for (uint32_t i = 0; i < 10 ; ++i)
- {
- Ipv6Address ipv6address = Ipv6Address::MakeAutoconfiguredAddress (m_addresses[i], prefix2);
- NS_LOG_INFO ("address = " << ipv6address);
- }
-}
-
--- a/examples/third.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/mobility-module.h"
-
-// Default Network Topology
-//
-// Wifi 10.1.3.0
-// AP
-// * * * *
-// | | | | 10.1.1.0
-// n5 n6 n7 n0 -------------- n1 n2 n3 n4
-// point-to-point | | | |
-// ================
-// LAN 10.1.2.0
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
-
-int
-main (int argc, char *argv[])
-{
- bool verbose = true;
- uint32_t nCsma = 3;
- uint32_t nWifi = 3;
-
- CommandLine cmd;
- cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
- cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
- cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
-
- cmd.Parse (argc,argv);
-
- if (verbose)
- {
- LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
- LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
- }
-
- NodeContainer p2pNodes;
- p2pNodes.Create (2);
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NetDeviceContainer p2pDevices;
- p2pDevices = pointToPoint.Install (p2pNodes);
-
- NodeContainer csmaNodes;
- csmaNodes.Add (p2pNodes.Get (1));
- csmaNodes.Create (nCsma);
-
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
- csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
-
- NetDeviceContainer csmaDevices;
- csmaDevices = csma.Install (csmaNodes);
-
- NodeContainer wifiStaNodes;
- wifiStaNodes.Create (nWifi);
- NodeContainer wifiApNode = p2pNodes.Get (0);
-
- YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
- YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
- phy.SetChannel (channel.Create ());
-
- WifiHelper wifi = WifiHelper::Default ();
- wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
-
- NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
-
- Ssid ssid = Ssid ("ns-3-ssid");
- mac.SetType ("ns3::NqstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
-
- NetDeviceContainer staDevices;
- staDevices = wifi.Install (phy, mac, wifiStaNodes);
-
- mac.SetType ("ns3::NqapWifiMac",
- "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
-
- NetDeviceContainer apDevices;
- apDevices = wifi.Install (phy, mac, wifiApNode);
-
- MobilityHelper mobility;
-
- mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (0.0),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (5.0),
- "DeltaY", DoubleValue (10.0),
- "GridWidth", UintegerValue (3),
- "LayoutType", StringValue ("RowFirst"));
-
- mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
- "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
- mobility.Install (wifiStaNodes);
-
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.Install (wifiApNode);
-
- InternetStackHelper stack;
- stack.Install (csmaNodes);
- stack.Install (wifiApNode);
- stack.Install (wifiStaNodes);
-
- Ipv4AddressHelper address;
-
- address.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer p2pInterfaces;
- p2pInterfaces = address.Assign (p2pDevices);
-
- address.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer csmaInterfaces;
- csmaInterfaces = address.Assign (csmaDevices);
-
- address.SetBase ("10.1.3.0", "255.255.255.0");
- address.Assign (staDevices);
- address.Assign (apDevices);
-
- UdpEchoServerHelper echoServer (9);
-
- ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
- serverApps.Start (Seconds (1.0));
- serverApps.Stop (Seconds (10.0));
-
- UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
- echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
- echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
- echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
-
- ApplicationContainer clientApps =
- echoClient.Install (wifiStaNodes.Get (nWifi - 1));
- clientApps.Start (Seconds (2.0));
- clientApps.Stop (Seconds (10.0));
-
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- Simulator::Stop (Seconds (10.0));
-
- PointToPointHelper::EnablePcapAll ("third");
- phy.EnablePcap ("third", apDevices.Get (0));
- CsmaHelper::EnablePcap ("third", csmaDevices.Get (0), true);
-
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tunneling/virtual-net-device.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,303 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based on simple-global-routing.cc
+ * ns-2 simple.tcl script (ported from ns-2)
+ * Originally authored by Steve McCanne, 12/19/1996
+ */
+
+// Network topology
+//
+// n0
+// \ 5 Mb/s, 2ms
+// \ 1.5Mb/s, 10ms
+// n2 -------------------------n3
+// /
+// / 5 Mb/s, 2ms
+// n1
+//
+// - all links are point-to-point links with indicated one-way BW/delay
+// - CBR/UDP flows from n0 to n3, and from n3 to n1
+// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
+// - 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 "virtual-net-device.tr"
+
+// Tunneling changes (relative to the simple-global-routing example):
+// n0 will receive an extra virtual interface with address 11.0.0.1
+// n1 will also receive an extra virtual interface with the same address 11.0.0.1
+// n3 will receive an extra virtual interface with address 11.0.0.254
+// The flows will be between 11.0.0.x (tunnel) addresses instead of 10.1.x.y ones
+// n3 will decide, on a per-packet basis, via random number, whether to
+// send the packet to n0 or to n1.
+//
+// Note: here we create a tunnel where IP packets are tunneled over
+// UDP/IP, but tunneling directly IP-over-IP would also be possible;
+// see src/node/ipv4-raw-socket-factory.h.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cassert>
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/virtual-net-device.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample");
+
+class Tunnel
+{
+ Ptr<Socket> m_n3Socket;
+ Ptr<Socket> m_n0Socket;
+ Ptr<Socket> m_n1Socket;
+ Ipv4Address m_n3Address;
+ Ipv4Address m_n0Address;
+ Ipv4Address m_n1Address;
+ UniformVariable m_rng;
+ Ptr<VirtualNetDevice> m_n0Tap;
+ Ptr<VirtualNetDevice> m_n1Tap;
+ Ptr<VirtualNetDevice> m_n3Tap;
+
+
+ bool
+ N0VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+ {
+ NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
+ m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
+ return true;
+ }
+
+ bool
+ N1VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+ {
+ NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
+ m_n1Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
+ return true;
+ }
+
+ bool
+ N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
+ {
+ if (m_rng.GetValue () < 0.25)
+ {
+ NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet);
+ m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
+ }
+ else
+ {
+ NS_LOG_DEBUG ("Send to " << m_n1Address << ": " << *packet);
+ m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n1Address, 667));
+ }
+ return true;
+ }
+
+ void N3SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ NS_LOG_DEBUG ("N3SocketRecv: " << *packet);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+ void N0SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ NS_LOG_DEBUG ("N0SocketRecv: " << *packet);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+ void N1SocketRecv (Ptr<Socket> socket)
+ {
+ Ptr<Packet> packet = socket->Recv (65535, 0);
+ NS_LOG_DEBUG ("N1SocketRecv: " << *packet);
+ SocketAddressTag socketAddressTag;
+ packet->RemovePacketTag (socketAddressTag);
+ m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST);
+ }
+
+public:
+
+ Tunnel (Ptr<Node> n3, Ptr<Node> n0, Ptr<Node> n1,
+ Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr)
+ : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr)
+ {
+ m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));
+
+ m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this));
+
+ m_n1Socket = Socket::CreateSocket (n1, TypeId::LookupByName ("ns3::UdpSocketFactory"));
+ m_n1Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
+ m_n1Socket->SetRecvCallback (MakeCallback (&Tunnel::N1SocketRecv, this));
+
+ // n0 tap device
+ m_n0Tap = CreateObject<VirtualNetDevice> ();
+ m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01"));
+ m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0VirtualSend, this));
+ n0->AddDevice (m_n0Tap);
+ Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> ();
+ uint32_t i = ipv4->AddInterface (m_n0Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ // n1 tap device
+ m_n1Tap = CreateObject<VirtualNetDevice> ();
+ m_n1Tap->SetAddress (Mac48Address ("11:00:01:02:03:02"));
+ m_n1Tap->SetSendCallback (MakeCallback (&Tunnel::N1VirtualSend, this));
+ n1->AddDevice (m_n1Tap);
+ ipv4 = n1->GetObject<Ipv4> ();
+ i = ipv4->AddInterface (m_n1Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ // n3 tap device
+ m_n3Tap = CreateObject<VirtualNetDevice> ();
+ m_n3Tap->SetAddress (Mac48Address ("11:00:01:02:03:04"));
+ m_n3Tap->SetSendCallback (MakeCallback (&Tunnel::N3VirtualSend, this));
+ n3->AddDevice (m_n3Tap);
+ ipv4 = n3->GetObject<Ipv4> ();
+ i = ipv4->AddInterface (m_n3Tap);
+ ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.254"), Ipv4Mask ("255.255.255.0")));
+ ipv4->SetUp (i);
+
+ }
+
+
+};
+
+
+
+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
+#if 0
+ LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO);
+#endif
+ Packet::EnablePrinting ();
+
+
+ // Set up some default values for the simulation. Use the
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
+
+ //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
+
+ // Allow the user to override any of the defaults and the above
+ // DefaultValue::Bind ()s at run-time, via command-line arguments
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ // Here, we will explicitly create four nodes. In more sophisticated
+ // topologies, we could configure a node factory.
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer c;
+ c.Create (4);
+ NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
+ NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
+ NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ // We create the channels first without any IP addressing information
+ NS_LOG_INFO ("Create channels.");
+ PointToPointHelper p2p;
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ NetDeviceContainer d0d2 = p2p.Install (n0n2);
+
+ NetDeviceContainer d1d2 = p2p.Install (n1n2);
+
+ p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
+ p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
+ NetDeviceContainer d3d2 = p2p.Install (n3n2);
+
+ // Later, we add IP addresses.
+ NS_LOG_INFO ("Assign IP Addresses.");
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
+
+ ipv4.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
+
+ ipv4.SetBase ("10.1.3.0", "255.255.255.0");
+ Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
+
+ // Create router nodes, initialize routing database and set up the routing
+ // tables in the nodes.
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Add the tunnels
+ Tunnel tunnel (c.Get (3), c.Get (0), c.Get (1),
+ i3i2.GetAddress (0), i0i2.GetAddress (0), i1i2.GetAddress (0));
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 448 Kb/s
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address ("11.0.0.254"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
+ apps = sink.Install (c.Get (3));
+ apps.Start (Seconds (1.0));
+ //apps.Stop (Seconds (10.0));
+
+ // Create a similar flow from n3 to n1, starting at time 1.1 seconds
+ onoff.SetAttribute ("Remote",
+ AddressValue (InetSocketAddress (Ipv4Address ("11.0.0.1"), port)));
+ apps = onoff.Install (c.Get (3));
+ apps.Start (Seconds (1.1));
+ apps.Stop (Seconds (10.0));
+
+ // Create a packet sink to receive these packets
+ apps = sink.Install (c.Get (1));
+ apps.Start (Seconds (1.1));
+ //apps.Stop (Seconds (10.0));
+
+ std::ofstream ascii;
+ ascii.open ("virtual-net-device.tr");
+ PointToPointHelper::EnablePcapAll ("virtual-net-device");
+ PointToPointHelper::EnableAsciiAll (ascii);
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tunneling/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tunneling/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,6 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('virtual-net-device', ['point-to-point', 'internet-stack', 'global-routing',
+ 'virtual-net-device'])
+ obj.source = 'virtual-net-device.cc'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/first.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,68 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
+
+ int
+main (int argc, char *argv[])
+{
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
+
+ NodeContainer nodes;
+ nodes.Create (2);
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ NetDeviceContainer devices;
+ devices = pointToPoint.Install (nodes);
+
+ InternetStackHelper stack;
+ stack.Install (nodes);
+
+ Ipv4AddressHelper address;
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+
+ Ipv4InterfaceContainer interfaces = address.Assign (devices);
+
+ UdpEchoServerHelper echoServer (9);
+
+ ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
+ serverApps.Start (Seconds (1.0));
+ serverApps.Stop (Seconds (10.0));
+
+ UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+
+ ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
+ clientApps.Start (Seconds (2.0));
+ clientApps.Stop (Seconds (10.0));
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/first.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,55 @@
+# /*
+# * This program is free software; you can redistribute it and/or modify
+# * it under the terms of the GNU General Public License version 2 as
+# * published by the Free Software Foundation;
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# * GNU General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public License
+# * along with this program; if not, write to the Free Software
+# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# */
+
+import ns3
+
+ns3.LogComponentEnable("UdpEchoClientApplication", ns3.LOG_LEVEL_INFO)
+ns3.LogComponentEnable("UdpEchoServerApplication", ns3.LOG_LEVEL_INFO)
+
+nodes = ns3.NodeContainer()
+nodes.Create(2)
+
+pointToPoint = ns3.PointToPointHelper()
+pointToPoint.SetDeviceAttribute("DataRate", ns3.StringValue("5Mbps"))
+pointToPoint.SetChannelAttribute("Delay", ns3.StringValue("2ms"))
+
+devices = pointToPoint.Install(nodes)
+
+stack = ns3.InternetStackHelper()
+stack.Install(nodes)
+
+address = ns3.Ipv4AddressHelper()
+address.SetBase(ns3.Ipv4Address("10.1.1.0"), ns3.Ipv4Mask("255.255.255.0"))
+
+interfaces = address.Assign (devices);
+
+echoServer = ns3.UdpEchoServerHelper(9)
+
+serverApps = echoServer.Install(nodes.Get(1))
+serverApps.Start(ns3.Seconds(1.0))
+serverApps.Stop(ns3.Seconds(10.0))
+
+echoClient = ns3.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
+echoClient.SetAttribute("MaxPackets", ns3.UintegerValue(1))
+echoClient.SetAttribute("Interval", ns3.TimeValue(ns3.Seconds (1.0)))
+echoClient.SetAttribute("PacketSize", ns3.UintegerValue(1024))
+
+clientApps = echoClient.Install(nodes.Get(0))
+clientApps.Start(ns3.Seconds(2.0))
+clientApps.Stop(ns3.Seconds(10.0))
+
+ns3.Simulator.Run()
+ns3.Simulator.Destroy()
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/hello-simulator.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,27 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/core-module.h"
+
+NS_LOG_COMPONENT_DEFINE ("HelloSimulator");
+
+using namespace ns3;
+
+ int
+main (int argc, char *argv[])
+{
+ NS_LOG_UNCOND ("Hello Simulator");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/second.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,112 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+// Default Network Topology
+//
+// 10.1.1.0
+// n0 -------------- n1 n2 n3 n4
+// point-to-point | | | |
+// ================
+// LAN 10.1.2.0
+
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
+
+int
+main (int argc, char *argv[])
+{
+ bool verbose = true;
+ uint32_t nCsma = 3;
+
+ CommandLine cmd;
+ cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
+ cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
+
+ cmd.Parse (argc,argv);
+
+ if (verbose)
+ {
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
+ }
+
+ nCsma = nCsma == 0 ? 1 : nCsma;
+
+ NodeContainer p2pNodes;
+ p2pNodes.Create (2);
+
+ NodeContainer csmaNodes;
+ csmaNodes.Add (p2pNodes.Get (1));
+ csmaNodes.Create (nCsma);
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ NetDeviceContainer p2pDevices;
+ p2pDevices = pointToPoint.Install (p2pNodes);
+
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
+ csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
+
+ NetDeviceContainer csmaDevices;
+ csmaDevices = csma.Install (csmaNodes);
+
+ InternetStackHelper stack;
+ stack.Install (p2pNodes.Get (0));
+ stack.Install (csmaNodes);
+
+ Ipv4AddressHelper address;
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer p2pInterfaces;
+ p2pInterfaces = address.Assign (p2pDevices);
+
+ address.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer csmaInterfaces;
+ csmaInterfaces = address.Assign (csmaDevices);
+
+ UdpEchoServerHelper echoServer (9);
+
+ ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
+ serverApps.Start (Seconds (1.0));
+ serverApps.Stop (Seconds (10.0));
+
+ UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+
+ ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
+ clientApps.Start (Seconds (2.0));
+ clientApps.Stop (Seconds (10.0));
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ PointToPointHelper::EnablePcapAll ("second");
+ CsmaHelper::EnablePcap ("second", csmaDevices.Get (1), true);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/third.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,172 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+
+// Default Network Topology
+//
+// Wifi 10.1.3.0
+// AP
+// * * * *
+// | | | | 10.1.1.0
+// n5 n6 n7 n0 -------------- n1 n2 n3 n4
+// point-to-point | | | |
+// ================
+// LAN 10.1.2.0
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
+
+int
+main (int argc, char *argv[])
+{
+ bool verbose = true;
+ uint32_t nCsma = 3;
+ uint32_t nWifi = 3;
+
+ CommandLine cmd;
+ cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
+ cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
+ cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
+
+ cmd.Parse (argc,argv);
+
+ if (verbose)
+ {
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
+ }
+
+ NodeContainer p2pNodes;
+ p2pNodes.Create (2);
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ NetDeviceContainer p2pDevices;
+ p2pDevices = pointToPoint.Install (p2pNodes);
+
+ NodeContainer csmaNodes;
+ csmaNodes.Add (p2pNodes.Get (1));
+ csmaNodes.Create (nCsma);
+
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
+ csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
+
+ NetDeviceContainer csmaDevices;
+ csmaDevices = csma.Install (csmaNodes);
+
+ NodeContainer wifiStaNodes;
+ wifiStaNodes.Create (nWifi);
+ NodeContainer wifiApNode = p2pNodes.Get (0);
+
+ YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
+ YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
+ phy.SetChannel (channel.Create ());
+
+ WifiHelper wifi = WifiHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
+
+ NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
+
+ Ssid ssid = Ssid ("ns-3-ssid");
+ mac.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+
+ NetDeviceContainer staDevices;
+ staDevices = wifi.Install (phy, mac, wifiStaNodes);
+
+ mac.SetType ("ns3::NqapWifiMac",
+ "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+
+ NetDeviceContainer apDevices;
+ apDevices = wifi.Install (phy, mac, wifiApNode);
+
+ MobilityHelper mobility;
+
+ mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (0.0),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (5.0),
+ "DeltaY", DoubleValue (10.0),
+ "GridWidth", UintegerValue (3),
+ "LayoutType", StringValue ("RowFirst"));
+
+ mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
+ mobility.Install (wifiStaNodes);
+
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (wifiApNode);
+
+ InternetStackHelper stack;
+ stack.Install (csmaNodes);
+ stack.Install (wifiApNode);
+ stack.Install (wifiStaNodes);
+
+ Ipv4AddressHelper address;
+
+ address.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer p2pInterfaces;
+ p2pInterfaces = address.Assign (p2pDevices);
+
+ address.SetBase ("10.1.2.0", "255.255.255.0");
+ Ipv4InterfaceContainer csmaInterfaces;
+ csmaInterfaces = address.Assign (csmaDevices);
+
+ address.SetBase ("10.1.3.0", "255.255.255.0");
+ address.Assign (staDevices);
+ address.Assign (apDevices);
+
+ UdpEchoServerHelper echoServer (9);
+
+ ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
+ serverApps.Start (Seconds (1.0));
+ serverApps.Stop (Seconds (10.0));
+
+ UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
+
+ ApplicationContainer clientApps =
+ echoClient.Install (wifiStaNodes.Get (nWifi - 1));
+ clientApps.Start (Seconds (2.0));
+ clientApps.Stop (Seconds (10.0));
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ Simulator::Stop (Seconds (10.0));
+
+ PointToPointHelper::EnablePcapAll ("third");
+ phy.EnablePcap ("third", apDevices.Get (0));
+ CsmaHelper::EnablePcap ("third", csmaDevices.Get (0), true);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/tutorial/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('hello-simulator')
+ obj.source = 'hello-simulator.cc'
+
+ obj = bld.create_ns3_program('first', ['core', 'simulator', 'point-to-point', 'internet-stack'])
+ obj.source = 'first.cc'
+
+ obj = bld.create_ns3_program('second', ['core', 'simulator', 'point-to-point', 'csma', 'internet-stack'])
+ obj.source = 'second.cc'
+
+ obj = bld.create_ns3_program('third', ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack'])
+ obj.source = 'third.cc'
--- a/examples/udp-echo.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-// Network topology
-//
-// n0 n1 n2 n3
-// | | | |
-// =================
-// LAN
-//
-// - UDP flows from n0 to n1 and back
-// - DropTail queues
-// - Tracing of queues and packet receptions to file "udp-echo.tr"
-
-#include <fstream>
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/helper-module.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("UdpEchoExample");
-
-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
-//
-#if 0
- LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO);
- LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
- LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
-#endif
-//
-// Allow the user to override any of the defaults and the above Bind() at
-// run-time, via command-line arguments
-//
- CommandLine cmd;
- cmd.Parse (argc, argv);
-//
-// Explicitly create the nodes required by the topology (shown above).
-//
- NS_LOG_INFO ("Create nodes.");
- NodeContainer n;
- n.Create (4);
-
- InternetStackHelper internet;
- internet.Install (n);
-
- NS_LOG_INFO ("Create channels.");
-//
-// Explicitly create the channels required by the topology (shown above).
-//
- CsmaHelper csma;
- csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
- csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
- csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
- NetDeviceContainer d = csma.Install (n);
-
- Ipv4AddressHelper ipv4;
-//
-// We've got the "hardware" in place. Now we need to add IP addresses.
-//
- NS_LOG_INFO ("Assign IP Addresses.");
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i = ipv4.Assign (d);
-
- NS_LOG_INFO ("Create Applications.");
-//
-// Create a UdpEchoServer application on node one.
-//
- uint16_t port = 9; // well-known echo port number
- UdpEchoServerHelper server (port);
- ApplicationContainer apps = server.Install (n.Get(1));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
-//
-// Create a UdpEchoClient application to send UDP datagrams from node zero to
-// node one.
-//
- uint32_t packetSize = 1024;
- uint32_t maxPacketCount = 1;
- Time interPacketInterval = Seconds (1.);
- UdpEchoClientHelper client (i.GetAddress (1), port);
- client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
- client.SetAttribute ("Interval", TimeValue (interPacketInterval));
- client.SetAttribute ("PacketSize", UintegerValue (packetSize));
- apps = client.Install (n.Get (0));
- apps.Start (Seconds (2.0));
- apps.Stop (Seconds (10.0));
-
-#if 0
-//
-// Users may find it convenient to initialize echo packets with actual data;
-// the below lines suggest how to do this
-//
- client.SetFill(apps.Get (0), "Hello World");
-
- client.SetFill(apps.Get (0), 0xa5, 1024);
-
- uint8_t fill[] = {0, 1, 2, 3, 4, 5, 6};
- client.SetFill(apps.Get (0), fill, sizeof(fill), 1024);
-#endif
-
- std::ofstream ascii;
- ascii.open ("udp-echo.tr");
- CsmaHelper::EnablePcapAll ("udp-echo", false);
- CsmaHelper::EnableAsciiAll (ascii);
-
-//
-// Now, do the actual simulation.
-//
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/udp/udp-echo.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,133 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Network topology
+//
+// n0 n1 n2 n3
+// | | | |
+// =================
+// LAN
+//
+// - UDP flows from n0 to n1 and back
+// - DropTail queues
+// - Tracing of queues and packet receptions to file "udp-echo.tr"
+
+#include <fstream>
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("UdpEchoExample");
+
+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
+//
+#if 0
+ LogComponentEnable ("UdpEchoExample", LOG_LEVEL_INFO);
+ LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
+ LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
+#endif
+//
+// Allow the user to override any of the defaults and the above Bind() at
+// run-time, via command-line arguments
+//
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+//
+// Explicitly create the nodes required by the topology (shown above).
+//
+ NS_LOG_INFO ("Create nodes.");
+ NodeContainer n;
+ n.Create (4);
+
+ InternetStackHelper internet;
+ internet.Install (n);
+
+ NS_LOG_INFO ("Create channels.");
+//
+// Explicitly create the channels required by the topology (shown above).
+//
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate(5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
+ NetDeviceContainer d = csma.Install (n);
+
+ Ipv4AddressHelper ipv4;
+//
+// We've got the "hardware" in place. Now we need to add IP addresses.
+//
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (d);
+
+ NS_LOG_INFO ("Create Applications.");
+//
+// Create a UdpEchoServer application on node one.
+//
+ uint16_t port = 9; // well-known echo port number
+ UdpEchoServerHelper server (port);
+ ApplicationContainer apps = server.Install (n.Get(1));
+ apps.Start (Seconds (1.0));
+ apps.Stop (Seconds (10.0));
+
+//
+// Create a UdpEchoClient application to send UDP datagrams from node zero to
+// node one.
+//
+ uint32_t packetSize = 1024;
+ uint32_t maxPacketCount = 1;
+ Time interPacketInterval = Seconds (1.);
+ UdpEchoClientHelper client (i.GetAddress (1), port);
+ client.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
+ client.SetAttribute ("Interval", TimeValue (interPacketInterval));
+ client.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ apps = client.Install (n.Get (0));
+ apps.Start (Seconds (2.0));
+ apps.Stop (Seconds (10.0));
+
+#if 0
+//
+// Users may find it convenient to initialize echo packets with actual data;
+// the below lines suggest how to do this
+//
+ client.SetFill(apps.Get (0), "Hello World");
+
+ client.SetFill(apps.Get (0), 0xa5, 1024);
+
+ uint8_t fill[] = {0, 1, 2, 3, 4, 5, 6};
+ client.SetFill(apps.Get (0), fill, sizeof(fill), 1024);
+#endif
+
+ std::ofstream ascii;
+ ascii.open ("udp-echo.tr");
+ CsmaHelper::EnablePcapAll ("udp-echo", false);
+ CsmaHelper::EnableAsciiAll (ascii);
+
+//
+// Now, do the actual simulation.
+//
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/udp/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/udp/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,5 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('udp-echo', ['csma', 'internet-stack'])
+ obj.source = 'udp-echo.cc'
--- a/examples/virtual-net-device.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,303 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Based on simple-global-routing.cc
- * ns-2 simple.tcl script (ported from ns-2)
- * Originally authored by Steve McCanne, 12/19/1996
- */
-
-// Network topology
-//
-// n0
-// \ 5 Mb/s, 2ms
-// \ 1.5Mb/s, 10ms
-// n2 -------------------------n3
-// /
-// / 5 Mb/s, 2ms
-// n1
-//
-// - all links are point-to-point links with indicated one-way BW/delay
-// - CBR/UDP flows from n0 to n3, and from n3 to n1
-// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
-// - 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 "virtual-net-device.tr"
-
-// Tunneling changes (relative to the simple-global-routing example):
-// n0 will receive an extra virtual interface with address 11.0.0.1
-// n1 will also receive an extra virtual interface with the same address 11.0.0.1
-// n3 will receive an extra virtual interface with address 11.0.0.254
-// The flows will be between 11.0.0.x (tunnel) addresses instead of 10.1.x.y ones
-// n3 will decide, on a per-packet basis, via random number, whether to
-// send the packet to n0 or to n1.
-//
-// Note: here we create a tunnel where IP packets are tunneled over
-// UDP/IP, but tunneling directly IP-over-IP would also be possible;
-// see src/node/ipv4-raw-socket-factory.h.
-
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <cassert>
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/virtual-net-device.h"
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("VirtualNetDeviceExample");
-
-class Tunnel
-{
- Ptr<Socket> m_n3Socket;
- Ptr<Socket> m_n0Socket;
- Ptr<Socket> m_n1Socket;
- Ipv4Address m_n3Address;
- Ipv4Address m_n0Address;
- Ipv4Address m_n1Address;
- UniformVariable m_rng;
- Ptr<VirtualNetDevice> m_n0Tap;
- Ptr<VirtualNetDevice> m_n1Tap;
- Ptr<VirtualNetDevice> m_n3Tap;
-
-
- bool
- N0VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
- {
- NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
- m_n0Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
- return true;
- }
-
- bool
- N1VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
- {
- NS_LOG_DEBUG ("Send to " << m_n3Address << ": " << *packet);
- m_n1Socket->SendTo (packet, 0, InetSocketAddress (m_n3Address, 667));
- return true;
- }
-
- bool
- N3VirtualSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
- {
- if (m_rng.GetValue () < 0.25)
- {
- NS_LOG_DEBUG ("Send to " << m_n0Address << ": " << *packet);
- m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n0Address, 667));
- }
- else
- {
- NS_LOG_DEBUG ("Send to " << m_n1Address << ": " << *packet);
- m_n3Socket->SendTo (packet, 0, InetSocketAddress (m_n1Address, 667));
- }
- return true;
- }
-
- void N3SocketRecv (Ptr<Socket> socket)
- {
- Ptr<Packet> packet = socket->Recv (65535, 0);
- NS_LOG_DEBUG ("N3SocketRecv: " << *packet);
- SocketAddressTag socketAddressTag;
- packet->RemovePacketTag (socketAddressTag);
- m_n3Tap->Receive (packet, 0x0800, m_n3Tap->GetAddress (), m_n3Tap->GetAddress (), NetDevice::PACKET_HOST);
- }
-
- void N0SocketRecv (Ptr<Socket> socket)
- {
- Ptr<Packet> packet = socket->Recv (65535, 0);
- NS_LOG_DEBUG ("N0SocketRecv: " << *packet);
- SocketAddressTag socketAddressTag;
- packet->RemovePacketTag (socketAddressTag);
- m_n0Tap->Receive (packet, 0x0800, m_n0Tap->GetAddress (), m_n0Tap->GetAddress (), NetDevice::PACKET_HOST);
- }
-
- void N1SocketRecv (Ptr<Socket> socket)
- {
- Ptr<Packet> packet = socket->Recv (65535, 0);
- NS_LOG_DEBUG ("N1SocketRecv: " << *packet);
- SocketAddressTag socketAddressTag;
- packet->RemovePacketTag (socketAddressTag);
- m_n1Tap->Receive (packet, 0x0800, m_n1Tap->GetAddress (), m_n1Tap->GetAddress (), NetDevice::PACKET_HOST);
- }
-
-public:
-
- Tunnel (Ptr<Node> n3, Ptr<Node> n0, Ptr<Node> n1,
- Ipv4Address n3Addr, Ipv4Address n0Addr, Ipv4Address n1Addr)
- : m_n3Address (n3Addr), m_n0Address (n0Addr), m_n1Address (n1Addr)
- {
- m_n3Socket = Socket::CreateSocket (n3, TypeId::LookupByName ("ns3::UdpSocketFactory"));
- m_n3Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
- m_n3Socket->SetRecvCallback (MakeCallback (&Tunnel::N3SocketRecv, this));
-
- m_n0Socket = Socket::CreateSocket (n0, TypeId::LookupByName ("ns3::UdpSocketFactory"));
- m_n0Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
- m_n0Socket->SetRecvCallback (MakeCallback (&Tunnel::N0SocketRecv, this));
-
- m_n1Socket = Socket::CreateSocket (n1, TypeId::LookupByName ("ns3::UdpSocketFactory"));
- m_n1Socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), 667));
- m_n1Socket->SetRecvCallback (MakeCallback (&Tunnel::N1SocketRecv, this));
-
- // n0 tap device
- m_n0Tap = CreateObject<VirtualNetDevice> ();
- m_n0Tap->SetAddress (Mac48Address ("11:00:01:02:03:01"));
- m_n0Tap->SetSendCallback (MakeCallback (&Tunnel::N0VirtualSend, this));
- n0->AddDevice (m_n0Tap);
- Ptr<Ipv4> ipv4 = n0->GetObject<Ipv4> ();
- uint32_t i = ipv4->AddInterface (m_n0Tap);
- ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
- ipv4->SetUp (i);
-
- // n1 tap device
- m_n1Tap = CreateObject<VirtualNetDevice> ();
- m_n1Tap->SetAddress (Mac48Address ("11:00:01:02:03:02"));
- m_n1Tap->SetSendCallback (MakeCallback (&Tunnel::N1VirtualSend, this));
- n1->AddDevice (m_n1Tap);
- ipv4 = n1->GetObject<Ipv4> ();
- i = ipv4->AddInterface (m_n1Tap);
- ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.1"), Ipv4Mask ("255.255.255.0")));
- ipv4->SetUp (i);
-
- // n3 tap device
- m_n3Tap = CreateObject<VirtualNetDevice> ();
- m_n3Tap->SetAddress (Mac48Address ("11:00:01:02:03:04"));
- m_n3Tap->SetSendCallback (MakeCallback (&Tunnel::N3VirtualSend, this));
- n3->AddDevice (m_n3Tap);
- ipv4 = n3->GetObject<Ipv4> ();
- i = ipv4->AddInterface (m_n3Tap);
- ipv4->AddAddress (i, Ipv4InterfaceAddress (Ipv4Address ("11.0.0.254"), Ipv4Mask ("255.255.255.0")));
- ipv4->SetUp (i);
-
- }
-
-
-};
-
-
-
-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
-#if 0
- LogComponentEnable ("VirtualNetDeviceExample", LOG_LEVEL_INFO);
-#endif
- Packet::EnablePrinting ();
-
-
- // Set up some default values for the simulation. Use the
- Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
- Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
-
- //DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
-
- // Allow the user to override any of the defaults and the above
- // DefaultValue::Bind ()s at run-time, via command-line arguments
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- // Here, we will explicitly create four nodes. In more sophisticated
- // topologies, we could configure a node factory.
- NS_LOG_INFO ("Create nodes.");
- NodeContainer c;
- c.Create (4);
- NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
- NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
- NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
-
- InternetStackHelper internet;
- internet.Install (c);
-
- // We create the channels first without any IP addressing information
- NS_LOG_INFO ("Create channels.");
- PointToPointHelper p2p;
- p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
- NetDeviceContainer d0d2 = p2p.Install (n0n2);
-
- NetDeviceContainer d1d2 = p2p.Install (n1n2);
-
- p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
- p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
- NetDeviceContainer d3d2 = p2p.Install (n3n2);
-
- // Later, we add IP addresses.
- NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper ipv4;
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
-
- ipv4.SetBase ("10.1.2.0", "255.255.255.0");
- Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
-
- ipv4.SetBase ("10.1.3.0", "255.255.255.0");
- Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
-
- // Create router nodes, initialize routing database and set up the routing
- // tables in the nodes.
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
-
- // Add the tunnels
- Tunnel tunnel (c.Get (3), c.Get (0), c.Get (1),
- i3i2.GetAddress (0), i0i2.GetAddress (0), i1i2.GetAddress (0));
-
- // Create the OnOff application to send UDP datagrams of size
- // 210 bytes at a rate of 448 Kb/s
- NS_LOG_INFO ("Create Applications.");
- uint16_t port = 9; // Discard port (RFC 863)
- OnOffHelper onoff ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address ("11.0.0.254"), port)));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (1.0));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- PacketSinkHelper sink ("ns3::UdpSocketFactory",
- Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
- apps = sink.Install (c.Get (3));
- apps.Start (Seconds (1.0));
- //apps.Stop (Seconds (10.0));
-
- // Create a similar flow from n3 to n1, starting at time 1.1 seconds
- onoff.SetAttribute ("Remote",
- AddressValue (InetSocketAddress (Ipv4Address ("11.0.0.1"), port)));
- apps = onoff.Install (c.Get (3));
- apps.Start (Seconds (1.1));
- apps.Stop (Seconds (10.0));
-
- // Create a packet sink to receive these packets
- apps = sink.Install (c.Get (1));
- apps.Start (Seconds (1.1));
- //apps.Stop (Seconds (10.0));
-
- std::ofstream ascii;
- ascii.open ("virtual-net-device.tr");
- PointToPointHelper::EnablePcapAll ("virtual-net-device");
- PointToPointHelper::EnableAsciiAll (ascii);
-
- NS_LOG_INFO ("Run Simulation.");
- Simulator::Run ();
- Simulator::Destroy ();
- NS_LOG_INFO ("Done.");
-
- return 0;
-}
--- a/examples/wifi-adhoc.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,287 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-
-#include <iostream>
-
-NS_LOG_COMPONENT_DEFINE ("Main");
-
-using namespace ns3;
-
-class Experiment
-{
-public:
- Experiment ();
- Experiment (std::string name);
- Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
-private:
- void ReceivePacket (Ptr<Socket> socket);
- void SetPosition (Ptr<Node> node, Vector position);
- Vector GetPosition (Ptr<Node> node);
- void AdvancePosition (Ptr<Node> node);
- Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
-
- uint32_t m_bytesTotal;
- Gnuplot2dDataset m_output;
-};
-
-Experiment::Experiment ()
-{}
-
-Experiment::Experiment (std::string name)
- : m_output (name)
-{
- m_output.SetStyle (Gnuplot2dDataset::LINES);
-}
-
-void
-Experiment::SetPosition (Ptr<Node> node, Vector position)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- mobility->SetPosition (position);
-}
-
-Vector
-Experiment::GetPosition (Ptr<Node> node)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- return mobility->GetPosition ();
-}
-
-void
-Experiment::AdvancePosition (Ptr<Node> node)
-{
- Vector pos = GetPosition (node);
- double mbs = ((m_bytesTotal * 8.0) / 1000000);
- m_bytesTotal = 0;
- m_output.Add (pos.x, mbs);
- pos.x += 1.0;
- if (pos.x >= 210.0)
- {
- return;
- }
- SetPosition (node, pos);
- //std::cout << "x="<<pos.x << std::endl;
- Simulator::Schedule (Seconds (1.0), &Experiment::AdvancePosition, this, node);
-}
-
-void
-Experiment::ReceivePacket (Ptr<Socket> socket)
-{
- Ptr<Packet> packet;
- while (packet = socket->Recv ())
- {
- m_bytesTotal += packet->GetSize ();
- }
-}
-
-Ptr<Socket>
-Experiment::SetupPacketReceive (Ptr<Node> node)
-{
- TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
- Ptr<Socket> sink = Socket::CreateSocket (node, tid);
- sink->Bind ();
- sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
- return sink;
-}
-
-Gnuplot2dDataset
-Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
-{
- m_bytesTotal = 0;
-
- NodeContainer c;
- c.Create (2);
-
- PacketSocketHelper packetSocket;
- packetSocket.Install (c);
-
- YansWifiPhyHelper phy = wifiPhy;
- phy.SetChannel (wifiChannel.Create ());
-
- NqosWifiMacHelper mac = wifiMac;
- NetDeviceContainer devices = wifi.Install (phy, mac, c);
-
- MobilityHelper mobility;
- Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
- positionAlloc->Add (Vector (0.0, 0.0, 0.0));
- positionAlloc->Add (Vector (5.0, 0.0, 0.0));
- mobility.SetPositionAllocator (positionAlloc);
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
-
- mobility.Install (c);
-
- PacketSocketAddress socket;
- socket.SetSingleDevice(devices.Get (0)->GetIfIndex ());
- socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
- socket.SetProtocol (1);
-
- OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
- onoff.SetAttribute ("PacketSize", UintegerValue (2000));
-
- ApplicationContainer apps = onoff.Install (c.Get (0));
- apps.Start (Seconds (0.5));
- apps.Stop (Seconds (250.0));
-
- Simulator::Schedule (Seconds (1.5), &Experiment::AdvancePosition, this, c.Get (1));
- Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
-
- Simulator::Run ();
-
- Simulator::Destroy ();
-
- return m_output;
-}
-
-int main (int argc, char *argv[])
-{
- // disable fragmentation
- Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
- Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- Gnuplot gnuplot = Gnuplot ("reference-rates.png");
-
- Experiment experiment;
- WifiHelper wifi = WifiHelper::Default ();
- wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- Gnuplot2dDataset dataset;
-
- wifiMac.SetType ("ns3::AdhocWifiMac");
-
- NS_LOG_DEBUG ("54");
- experiment = Experiment ("54mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-54mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("48");
- experiment = Experiment ("48mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-48mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("36");
- experiment = Experiment ("36mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-36mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("24");
- experiment = Experiment ("24mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-24mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("18");
- experiment = Experiment ("18mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-18mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("12");
- experiment = Experiment ("12mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-12mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("9");
- experiment = Experiment ("9mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-9mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("6");
- experiment = Experiment ("6mb");
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode", StringValue ("wifia-6mbs"));
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- gnuplot.GenerateOutput (std::cout);
-
-
- gnuplot = Gnuplot ("rate-control.png");
- wifi.SetStandard (WIFI_PHY_STANDARD_holland);
-
-
- NS_LOG_DEBUG ("arf");
- experiment = Experiment ("arf");
- wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("aarf");
- experiment = Experiment ("aarf");
- wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("aarf-cd");
- experiment = Experiment ("aarf-cd");
- wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("cara");
- experiment = Experiment ("cara");
- wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("rraa");
- experiment = Experiment ("rraa");
- wifi.SetRemoteStationManager ("ns3::RraaWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- NS_LOG_DEBUG ("ideal");
- experiment = Experiment ("ideal");
- wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
- dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- gnuplot.AddDataset (dataset);
-
- gnuplot.GenerateOutput (std::cout);
-
- return 0;
-}
--- a/examples/wifi-ap.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006,2007 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/athstats-helper.h"
-
-#include <iostream>
-
-using namespace ns3;
-
-static bool g_verbose = true;
-
-void
-DevTxTrace (std::string context, Ptr<const Packet> p)
-{
- if (g_verbose)
- {
- std::cout << " TX p: " << *p << std::endl;
- }
-}
-void
-DevRxTrace (std::string context, Ptr<const Packet> p)
-{
- if (g_verbose)
- {
- std::cout << " RX p: " << *p << std::endl;
- }
-}
-void
-PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
-{
- if (g_verbose)
- {
- std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
- }
-}
-void
-PhyRxErrorTrace (std::string context, Ptr<const Packet> packet, double snr)
-{
- if (g_verbose)
- {
- std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
- }
-}
-void
-PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
-{
- if (g_verbose)
- {
- std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
- }
-}
-void
-PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state)
-{
- if (g_verbose)
- {
- std::cout << " state=";
- switch (state) {
- case WifiPhy::SWITCHING:
- std::cout << "switchng";
- break;
- case WifiPhy::TX:
- std::cout << "tx ";
- break;
- case WifiPhy::SYNC:
- std::cout << "sync ";
- break;
- case WifiPhy::CCA_BUSY:
- std::cout << "cca-busy";
- break;
- case WifiPhy::IDLE:
- std::cout << "idle ";
- break;
- }
- std::cout << " start="<<start<<" duration="<<duration<<std::endl;
- }
-}
-
-static void
-SetPosition (Ptr<Node> node, Vector position)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- mobility->SetPosition (position);
-}
-
-static Vector
-GetPosition (Ptr<Node> node)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- return mobility->GetPosition ();
-}
-
-static void
-AdvancePosition (Ptr<Node> node)
-{
- Vector pos = GetPosition (node);
- pos.x += 5.0;
- if (pos.x >= 210.0)
- {
- return;
- }
- SetPosition (node, pos);
-
- if (g_verbose)
- {
- //std::cout << "x="<<pos.x << std::endl;
- }
- Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
-}
-
-int main (int argc, char *argv[])
-{
- CommandLine cmd;
- cmd.AddValue ("verbose", "Print trace information if true", g_verbose);
-
- cmd.Parse (argc, argv);
-
- Packet::EnablePrinting ();
-
- // enable rts cts all the time.
- Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
- // disable fragmentation
- Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
-
- WifiHelper wifi = WifiHelper::Default ();
- MobilityHelper mobility;
- NodeContainer stas;
- NodeContainer ap;
- NetDeviceContainer staDevs;
- PacketSocketHelper packetSocket;
-
- stas.Create (2);
- ap.Create (1);
-
- // give packet socket powers to nodes.
- packetSocket.Install (stas);
- packetSocket.Install (ap);
-
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
- Ssid ssid = Ssid ("wifi-default");
- wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
- // setup stas.
- wifiMac.SetType ("ns3::NqstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- staDevs = wifi.Install (wifiPhy, wifiMac, stas);
- // setup ap.
- wifiMac.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
- wifi.Install (wifiPhy, wifiMac, ap);
-
- // mobility.
- mobility.Install (stas);
- mobility.Install (ap);
-
- Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0));
-
- PacketSocketAddress socket;
- socket.SetSingleDevice(staDevs.Get (0)->GetIfIndex ());
- socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ());
- socket.SetProtocol (1);
-
- OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
-
- ApplicationContainer apps = onoff.Install (stas.Get (0));
- apps.Start (Seconds (0.5));
- apps.Stop (Seconds (43.0));
-
- Simulator::Stop (Seconds (44.0));
-
- Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback (&DevTxTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback (&DevRxTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", MakeCallback (&PhyRxOkTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&PhyRxErrorTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace));
- Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace));
-
- AthstatsHelper athstats;
- athstats.EnableAthstats("athstats-sta", stas);
- athstats.EnableAthstats("athstats-ap", ap);
-
- Simulator::Run ();
-
- Simulator::Destroy ();
-
- return 0;
-}
--- a/examples/wifi-ap.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-# -*- Mode: Python; -*-
-# /*
-# * Copyright (c) 2005,2006,2007 INRIA
-# * Copyright (c) 2009 INESC Porto
-# *
-# * This program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License version 2 as
-# * published by the Free Software Foundation;
-# *
-# * This program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with this program; if not, write to the Free Software
-# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-# *
-# * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
-# * Gustavo Carneiro <gjc@inescporto.pt>
-# */
-
-import sys
-import ns3
-
-# void
-# DevTxTrace (std::string context, Ptr<const Packet> p, Mac48Address address)
-# {
-# std::cout << " TX to=" << address << " p: " << *p << std::endl;
-# }
-# void
-# DevRxTrace(std::string context, Ptr<const Packet> p, Mac48Address address)
-# {
-# std::cout << " RX from=" << address << " p: " << *p << std::endl;
-# }
-# void
-# PhyRxOkTrace(std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
-# {
-# std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
-# }
-# void
-# PhyRxErrorTrace(std::string context, Ptr<const Packet> packet, double snr)
-# {
-# std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
-# }
-# void
-# PhyTxTrace(std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
-# {
-# std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
-# }
-# void
-# PhyStateTrace(std::string context, Time start, Time duration, enum WifiPhy::State state)
-# {
-# std::cout << " state=";
-# switch(state) {
-# case WifiPhy::TX:
-# std::cout << "tx ";
-# break;
-# case WifiPhy::SYNC:
-# std::cout << "sync ";
-# break;
-# case WifiPhy::CCA_BUSY:
-# std::cout << "cca-busy";
-# break;
-# case WifiPhy::IDLE:
-# std::cout << "idle ";
-# break;
-# }
-# std::cout << " start="<<start<<" duration="<<duration<<std::endl;
-# }
-
-def SetPosition(node, position):
- mobility = node.GetObject(ns3.MobilityModel.GetTypeId())
- mobility.SetPosition(position)
-
-
-def GetPosition(node):
- mobility = node.GetObject(ns3.MobilityModel.GetTypeId())
- return mobility.GetPosition()
-
-def AdvancePosition(node):
- pos = GetPosition(node);
- pos.x += 5.0
- if pos.x >= 210.0:
- return
- SetPosition(node, pos)
- ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, node)
-
-
-def main(argv):
- ns3.Packet.EnablePrinting();
-
- # enable rts cts all the time.
- ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns3.StringValue("0"))
- # disable fragmentation
- ns3.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue("2200"))
-
- wifi = ns3.WifiHelper.Default()
- mobility = ns3.MobilityHelper()
- stas = ns3.NodeContainer()
- ap = ns3.NodeContainer()
- #NetDeviceContainer staDevs;
- packetSocket = ns3.PacketSocketHelper()
-
- stas.Create(2)
- ap.Create(1)
-
- # give packet socket powers to nodes.
- packetSocket.Install(stas)
- packetSocket.Install(ap)
-
- wifiPhy = ns3.YansWifiPhyHelper.Default()
- wifiChannel = ns3.YansWifiChannelHelper.Default()
- wifiPhy.SetChannel(wifiChannel.Create())
-
- ssid = ns3.Ssid("wifi-default")
- wifi.SetRemoteStationManager("ns3::ArfWifiManager")
- wifiMac = ns3.NqosWifiMacHelper.Default()
-
- # setup stas.
- wifiMac.SetType("ns3::NqstaWifiMac",
- "Ssid", ns3.SsidValue(ssid),
- "ActiveProbing", ns3.BooleanValue(False))
- staDevs = wifi.Install(wifiPhy, wifiMac, stas)
- # setup ap.
- wifiMac.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid),
- "BeaconGeneration", ns3.BooleanValue(True),
- "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
- wifi.Install(wifiPhy, wifiMac, ap)
-
- # mobility.
- mobility.Install(stas)
- mobility.Install(ap)
-
- ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, ap.Get(0))
-
- socket = ns3.PacketSocketAddress()
- socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
- socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
- socket.SetProtocol(1)
-
- onoff = ns3.OnOffHelper("ns3::PacketSocketFactory", ns3.Address(socket))
- onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(42)))
- onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
-
- apps = onoff.Install(ns3.NodeContainer(stas.Get(0)))
- apps.Start(ns3.Seconds(0.5))
- apps.Stop(ns3.Seconds(43.0))
-
- ns3.Simulator.Stop(ns3.Seconds(44.0))
-
- # Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace));
- # Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace));
- # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback(&PhyRxOkTrace));
- # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback(&PhyRxErrorTrace));
- # Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace));
- # Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace));
-
- ascii = ns3.ofstream("wifi-ap.tr")
- ns3.YansWifiPhyHelper.EnableAsciiAll(ascii)
-
- ns3.Simulator.Run()
-
- ns3.Simulator.Destroy()
- ascii.close()
-
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv))
-
--- a/examples/wifi-clear-channel-cmu.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 The Boeing Company
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Guangyu Pei <guangyu.pei@boeing.com>
- */
-
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-
-#include <iostream>
-#include <fstream>
-#include <vector>
-#include <string>
-
-NS_LOG_COMPONENT_DEFINE ("Main");
-
-using namespace ns3;
-
-class Experiment
-{
-public:
- Experiment ();
- Experiment (std::string name);
- uint32_t Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
-private:
- void ReceivePacket (Ptr<Socket> socket);
- void SetPosition (Ptr<Node> node, Vector position);
- Vector GetPosition (Ptr<Node> node);
- Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
- void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
- uint32_t pktCount, Time pktInterval );
-
- uint32_t m_pktsTotal;
- Gnuplot2dDataset m_output;
-};
-
-Experiment::Experiment ()
-{}
-
-Experiment::Experiment (std::string name)
- : m_output (name)
-{
- m_output.SetStyle (Gnuplot2dDataset::LINES);
-}
-
-void
-Experiment::SetPosition (Ptr<Node> node, Vector position)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- mobility->SetPosition (position);
-}
-
-Vector
-Experiment::GetPosition (Ptr<Node> node)
-{
- Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
- return mobility->GetPosition ();
-}
-
-void
-Experiment::ReceivePacket (Ptr<Socket> socket)
-{
- Ptr<Packet> packet;
- while (packet = socket->Recv ())
- {
- m_pktsTotal ++;
- }
-}
-
-Ptr<Socket>
-Experiment::SetupPacketReceive (Ptr<Node> node)
-{
- TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
- Ptr<Socket> sink = Socket::CreateSocket (node, tid);
- InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
- sink->Bind (local);
- sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
- return sink;
-}
-
-void
-Experiment::GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
- uint32_t pktCount, Time pktInterval )
-{
- if (pktCount > 0)
- {
- socket->Send (Create<Packet> (pktSize));
- Simulator::Schedule (pktInterval, &Experiment::GenerateTraffic, this,
- socket, pktSize,pktCount-1, pktInterval);
- }
- else
- {
- socket->Close ();
- }
-}
-
-uint32_t
-Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
- const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
-{
- m_pktsTotal = 0;
-
- NodeContainer c;
- c.Create (2);
-
- InternetStackHelper internet;
- internet.Install (c);
-
- YansWifiPhyHelper phy = wifiPhy;
- phy.SetChannel (wifiChannel.Create ());
-
- NqosWifiMacHelper mac = wifiMac;
- NetDeviceContainer devices = wifi.Install (phy, mac, c);
-
- MobilityHelper mobility;
- Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
- positionAlloc->Add (Vector (0.0, 0.0, 0.0));
- positionAlloc->Add (Vector (5.0, 0.0, 0.0));
- mobility.SetPositionAllocator (positionAlloc);
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.Install (c);
-
- Ipv4AddressHelper ipv4;
- NS_LOG_INFO ("Assign IP Addresses.");
- ipv4.SetBase ("10.1.1.0", "255.255.255.0");
- Ipv4InterfaceContainer i = ipv4.Assign (devices);
-
- Ptr<Socket> recvSink = SetupPacketReceive (c.Get (0));
-
- TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
- Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
- InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
- source->Connect (remote);
- uint32_t packetSize = 1014;
- uint32_t maxPacketCount = 200;
- Time interPacketInterval = Seconds (1.);
- Simulator::Schedule (Seconds (1.0), &Experiment::GenerateTraffic,
- this, source, packetSize, maxPacketCount,interPacketInterval);
- Simulator::Run ();
-
- Simulator::Destroy ();
-
- return m_pktsTotal;
-}
-
-int main (int argc, char *argv[])
-{
- std::ofstream outfile ("clear-channel.plt");
- std::vector <std::string> modes;
-
- modes.push_back ("wifib-1mbs");
- modes.push_back ("wifib-2mbs");
- modes.push_back ("wifib-5.5mbs");
- modes.push_back ("wifib-11mbs");
- // disable fragmentation
- Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
- Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
-
- CommandLine cmd;
- cmd.Parse (argc, argv);
-
- Gnuplot gnuplot = Gnuplot ("clear-channel.eps");
-
- for (uint32_t i = 0; i < modes.size(); i++)
- {
- std::cout << modes[i] << std::endl;
- Gnuplot2dDataset dataset (modes[i]);
-
- for (double rss = -102.0; rss <= -80.0; rss += 0.5)
- {
- Experiment experiment;
- dataset.SetStyle (Gnuplot2dDataset::LINES);
-
- WifiHelper wifi;
- wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
- StringValue (modes[i]));
- wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
- "DataMode",StringValue(modes[i]),
- "ControlMode",StringValue(modes[i]));
- wifiMac.SetType ("ns3::AdhocWifiMac");
-
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- YansWifiChannelHelper wifiChannel ;
- wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
- wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
-
-
- NS_LOG_DEBUG (modes[i]);
- experiment = Experiment (modes[i]);
- wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-110.0) );
- wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-110.0) );
- wifiPhy.Set ("TxPowerStart", DoubleValue (15.0) );
- wifiPhy.Set ("RxGain", DoubleValue (0) );
- wifiPhy.Set ("RxNoiseFigure", DoubleValue (7) );
- uint32_t pktsRecvd = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
- dataset.Add (rss, pktsRecvd);
- }
-
- gnuplot.AddDataset (dataset);
- }
- gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
- gnuplot.SetLegend ("RSS(dBm)", "Number of packets received");
- gnuplot.SetExtra ("set xrange [-102:-83]");
- gnuplot.GenerateOutput (outfile);
- outfile.close ();
-
- return 0;
-}
--- a/examples/wifi-olsr-flowmon.py Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,171 +0,0 @@
-# -*- Mode: Python; -*-
-# Copyright (c) 2009 INESC Porto
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation;
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Authors: Gustavo Carneiro <gjc@inescporto.pt>
-
-import sys
-import ns3
-
-DISTANCE = 150 # (m)
-NUM_NODES_SIDE = 3
-
-def main(argv):
-
- cmd = ns3.CommandLine()
-
- cmd.NumNodesSide = None
- cmd.AddValue("NumNodesSide", "Grid side number of nodes (total number of nodes will be this number squared)")
-
- cmd.Results = None
- cmd.AddValue("Results", "Write XML results to file")
-
- cmd.Plot = None
- cmd.AddValue("Plot", "Plot the results using the matplotlib python module")
-
- cmd.Parse(argv)
-
- wifi = ns3.WifiHelper.Default()
- wifiMac = ns3.NqosWifiMacHelper.Default()
- wifiPhy = ns3.YansWifiPhyHelper.Default()
- wifiChannel = ns3.YansWifiChannelHelper.Default()
- wifiPhy.SetChannel(wifiChannel.Create())
- ssid = ns3.Ssid("wifi-default")
- wifi.SetRemoteStationManager("ns3::ArfWifiManager")
- wifiMac.SetType ("ns3::AdhocWifiMac", "Ssid", ns3.SsidValue(ssid))
-
- internet = ns3.InternetStackHelper()
- list_routing = ns3.Ipv4ListRoutingHelper()
- olsr_routing = ns3.OlsrHelper()
- static_routing = ns3.Ipv4StaticRoutingHelper()
- list_routing.Add(static_routing, 0)
- list_routing.Add(olsr_routing, 100)
- internet.SetRoutingHelper(list_routing)
-
- ipv4Addresses = ns3.Ipv4AddressHelper()
- ipv4Addresses.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
-
- port = 9 # Discard port(RFC 863)
- onOffHelper = ns3.OnOffHelper("ns3::UdpSocketFactory",
- ns3.Address(ns3.InetSocketAddress(ns3.Ipv4Address("10.0.0.1"), port)))
- onOffHelper.SetAttribute("DataRate", ns3.DataRateValue(ns3.DataRate("100kbps")))
- onOffHelper.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
- onOffHelper.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
-
- addresses = []
- nodes = []
-
- if cmd.NumNodesSide is None:
- num_nodes_side = NUM_NODES_SIDE
- else:
- num_nodes_side = int(cmd.NumNodesSide)
-
- for xi in range(num_nodes_side):
- for yi in range(num_nodes_side):
-
- node = ns3.Node()
- nodes.append(node)
-
- internet.Install(ns3.NodeContainer(node))
-
- mobility = ns3.ConstantPositionMobilityModel()
- mobility.SetPosition(ns3.Vector(xi*DISTANCE, yi*DISTANCE, 0))
- node.AggregateObject(mobility)
-
- devices = wifi.Install(wifiPhy, wifiMac, node)
- ipv4_interfaces = ipv4Addresses.Assign(devices)
- addresses.append(ipv4_interfaces.GetAddress(0))
-
- for i, node in enumerate(nodes):
- destaddr = addresses[(len(addresses) - 1 - i) % len(addresses)]
- #print i, destaddr
- onOffHelper.SetAttribute("Remote", ns3.AddressValue(ns3.InetSocketAddress(destaddr, port)))
- app = onOffHelper.Install(ns3.NodeContainer(node))
- app.Start(ns3.Seconds(ns3.UniformVariable(20, 30).GetValue()))
-
- #internet.EnablePcapAll("wifi-olsr")
- flowmon_helper = ns3.FlowMonitorHelper()
- #flowmon_helper.SetMonitorAttribute("StartTime", ns3.TimeValue(ns3.Seconds(31)))
- monitor = flowmon_helper.InstallAll()
- monitor.SetAttribute("DelayBinWidth", ns3.DoubleValue(0.001))
- monitor.SetAttribute("JitterBinWidth", ns3.DoubleValue(0.001))
- monitor.SetAttribute("PacketSizeBinWidth", ns3.DoubleValue(20))
-
- ns3.Simulator.Stop(ns3.Seconds(44.0))
- ns3.Simulator.Run()
-
- def print_stats(os, st):
- print >> os, " Tx Bytes: ", st.txBytes
- print >> os, " Rx Bytes: ", st.rxBytes
- print >> os, " Tx Packets: ", st.txPackets
- print >> os, " Rx Packets: ", st.rxPackets
- print >> os, " Lost Packets: ", st.lostPackets
- if st.rxPackets > 0:
- print >> os, " Mean{Delay}: ", (st.delaySum.GetSeconds() / st.rxPackets)
- print >> os, " Mean{Jitter}: ", (st.jitterSum.GetSeconds() / (st.rxPackets-1))
- print >> os, " Mean{Hop Count}: ", float(st.timesForwarded) / st.rxPackets + 1
-
- if 0:
- print >> os, "Delay Histogram"
- for i in range(st.delayHistogram.GetNBins () ):
- print >> os, " ",i,"(", st.delayHistogram.GetBinStart (i), "-", \
- st.delayHistogram.GetBinEnd (i), "): ", st.delayHistogram.GetBinCount (i)
- print >> os, "Jitter Histogram"
- for i in range(st.jitterHistogram.GetNBins () ):
- print >> os, " ",i,"(", st.jitterHistogram.GetBinStart (i), "-", \
- st.jitterHistogram.GetBinEnd (i), "): ", st.jitterHistogram.GetBinCount (i)
- print >> os, "PacketSize Histogram"
- for i in range(st.packetSizeHistogram.GetNBins () ):
- print >> os, " ",i,"(", st.packetSizeHistogram.GetBinStart (i), "-", \
- st.packetSizeHistogram.GetBinEnd (i), "): ", st.packetSizeHistogram.GetBinCount (i)
-
- for reason, drops in enumerate(st.packetsDropped):
- print " Packets dropped by reason %i: %i" % (reason, drops)
- #for reason, drops in enumerate(st.bytesDropped):
- # print "Bytes dropped by reason %i: %i" % (reason, drops)
-
- monitor.CheckForLostPackets()
- classifier = flowmon_helper.GetClassifier()
-
- if cmd.Results is None:
- for flow_id, flow_stats in monitor.GetFlowStats():
- t = classifier.FindFlow(flow_id)
- proto = {6: 'TCP', 17: 'UDP'} [t.protocol]
- print "FlowID: %i (%s %s/%s --> %s/%i)" % \
- (flow_id, proto, t.sourceAddress, t.sourcePort, t.destinationAddress, t.destinationPort)
- print_stats(sys.stdout, flow_stats)
- else:
- print monitor.SerializeToXmlFile(cmd.Results, True, True)
-
-
- if cmd.Plot is not None:
- import pylab
- delays = []
- for flow_id, flow_stats in monitor.GetFlowStats():
- tupl = classifier.FindFlow(flow_id)
- if tupl.protocol == 17 and tupl.sourcePort == 698:
- continue
- delays.append(flow_stats.delaySum.GetSeconds() / flow_stats.rxPackets)
- pylab.hist(delays, 20)
- pylab.xlabel("Delay (s)")
- pylab.ylabel("Number of Flows")
- pylab.show()
-
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv))
-
--- a/examples/wifi-wired-bridging.cc Mon Oct 05 15:32:12 2009 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,197 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-//
-// Default network topology includes some number of AP nodes specified by
-// the variable nWifis (defaults to two). Off of each AP node, there are some
-// number of STA nodes specified by the variable nStas (defaults to two).
-// Each AP talks to its associated STA nodes. There are bridge net devices
-// on each AP node that bridge the whole thing into one network.
-//
-// +-----+ +-----+ +-----+ +-----+
-// | STA | | STA | | STA | | STA |
-// +-----+ +-----+ +-----+ +-----+
-// 192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6
-// -------- -------- -------- --------
-// WIFI STA WIFI STA WIFI STA WIFI STA
-// -------- -------- -------- --------
-// ((*)) ((*)) | ((*)) ((*))
-// |
-// ((*)) | ((*))
-// ------- -------
-// WIFI AP CSMA ========= CSMA WIFI AP
-// ------- ---- ---- -------
-// ############## ##############
-// BRIDGE BRIDGE
-// ############## ##############
-// 192.168.0.1 192.168.0.2
-// +---------+ +---------+
-// | AP Node | | AP Node |
-// +---------+ +---------+
-//
-
-#include "ns3/core-module.h"
-#include "ns3/simulator-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/wifi-module.h"
-#include "ns3/node-module.h"
-#include <vector>
-#include <stdint.h>
-#include <sstream>
-#include <fstream>
-
-using namespace ns3;
-
-int main (int argc, char *argv[])
-{
- uint32_t nWifis = 2;
- uint32_t nStas = 2;
- bool sendIp = true;
-
- CommandLine cmd;
- cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
- cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
- cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
- cmd.Parse (argc, argv);
-
- NodeContainer backboneNodes;
- NetDeviceContainer backboneDevices;
- Ipv4InterfaceContainer backboneInterfaces;
- std::vector<NodeContainer> staNodes;
- std::vector<NetDeviceContainer> staDevices;
- std::vector<NetDeviceContainer> apDevices;
- std::vector<Ipv4InterfaceContainer> staInterfaces;
- std::vector<Ipv4InterfaceContainer> apInterfaces;
-
- InternetStackHelper stack;
- CsmaHelper csma;
- Ipv4AddressHelper ip;
- ip.SetBase ("192.168.0.0", "255.255.255.0");
-
- backboneNodes.Create (nWifis);
- stack.Install (backboneNodes);
-
- backboneDevices = csma.Install (backboneNodes);
-
- double wifiX = 0.0;
-
- YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
- wifiPhy.SetPcapFormat(YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
-
- for (uint32_t i = 0; i < nWifis; ++i)
- {
- // calculate ssid for wifi subnetwork
- std::ostringstream oss;
- oss << "wifi-default-" << i;
- Ssid ssid = Ssid (oss.str ());
-
- NodeContainer sta;
- NetDeviceContainer staDev;
- NetDeviceContainer apDev;
- Ipv4InterfaceContainer staInterface;
- Ipv4InterfaceContainer apInterface;
- MobilityHelper mobility;
- BridgeHelper bridge;
- WifiHelper wifi = WifiHelper::Default ();
- NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
- YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
- wifiPhy.SetChannel (wifiChannel.Create ());
-
- sta.Create (nStas);
- mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
- "MinX", DoubleValue (wifiX),
- "MinY", DoubleValue (0.0),
- "DeltaX", DoubleValue (5.0),
- "DeltaY", DoubleValue (5.0),
- "GridWidth", UintegerValue (1),
- "LayoutType", StringValue ("RowFirst"));
-
-
- // setup the AP.
- mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
- mobility.Install (backboneNodes.Get (i));
- wifiMac.SetType ("ns3::NqapWifiMac",
- "Ssid", SsidValue (ssid),
- "BeaconGeneration", BooleanValue (true),
- "BeaconInterval", TimeValue (Seconds (2.5)));
- apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));
-
- NetDeviceContainer bridgeDev;
- bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
-
- // assign AP IP address to bridge, not wifi
- apInterface = ip.Assign (bridgeDev);
-
- // setup the STAs
- stack.Install (sta);
- mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
- "Mode", StringValue ("Time"),
- "Time", StringValue ("2s"),
- "Speed", StringValue ("Constant:1.0"),
- "Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0, (nStas+1)*5.0)));
- mobility.Install (sta);
- wifiMac.SetType ("ns3::NqstaWifiMac",
- "Ssid", SsidValue (ssid),
- "ActiveProbing", BooleanValue (false));
- staDev = wifi.Install (wifiPhy, wifiMac, sta);
- staInterface = ip.Assign (staDev);
-
- // save everything in containers.
- staNodes.push_back (sta);
- apDevices.push_back (apDev);
- apInterfaces.push_back (apInterface);
- staDevices.push_back (staDev);
- staInterfaces.push_back (staInterface);
-
- wifiX += 20.0;
- }
-
- Address dest;
- std::string protocol;
- if (sendIp)
- {
- dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
- protocol = "ns3::UdpSocketFactory";
- }
- else
- {
- PacketSocketAddress tmp;
- tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
- tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
- tmp.SetProtocol (0x807);
- dest = tmp;
- protocol = "ns3::PacketSocketFactory";
- }
-
- OnOffHelper onoff = OnOffHelper (protocol, dest);
- onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
- onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
- ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
- apps.Start (Seconds (0.5));
- apps.Stop (Seconds (3.0));
-
- wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
- wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);
-
- std::ofstream os;
- os.open ("wifi-wired-bridging.mob");
- MobilityHelper::EnableAsciiAll (os);
-
- Simulator::Stop (Seconds (100.0));
- Simulator::Run ();
- Simulator::Destroy ();
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/mixed-wireless.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,418 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// This ns-3 example demonstrates the use of helper functions to ease
+// the construction of simulation scenarios.
+//
+// The simulation topology consists of a mixed wired and wireless
+// scenario in which a hierarchical mobility model is used.
+//
+// The simulation layout consists of N backbone routers interconnected
+// by an ad hoc wifi network.
+// Each backbone router also has a local 802.11 network and is connected
+// to a local LAN. An additional set of (K-1) nodes are connected to
+// this backbone. Finally, a local LAN is connected to each router
+// on the backbone, with L-1 additional hosts.
+//
+// The nodes are populated with TCP/IP stacks, and OLSR unicast routing
+// on the backbone. An example UDP transfer is shown. The simulator
+// be configured to output tcpdumps or traces from different nodes.
+//
+//
+// +--------------------------------------------------------+
+// | |
+// | 802.11 ad hoc, ns-2 mobility |
+// | |
+// +--------------------------------------------------------+
+// | o o o (N backbone routers) |
+// +--------+ +--------+
+// wired LAN | mobile | wired LAN | mobile |
+// -----------| router | -----------| router |
+// --------- ---------
+// | |
+// +----------------+ +----------------+
+// | 802.11 | | 802.11 |
+// | infra net | | infra net |
+// | K-1 hosts | | K-1 hosts |
+// +----------------+ +----------------+
+//
+// We'll send data from the first wired LAN node on the first wired LAN
+// to the last wireless STA on the last infrastructure net, thereby
+// causing packets to traverse CSMA to adhoc to infrastructure links
+//
+// Note that certain mobility patterns may cause packet forwarding
+// to fail (if nodes become disconnected)
+
+#include <fstream>
+#include <string>
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+
+using namespace ns3;
+
+//
+// Define logging keyword for this file
+//
+NS_LOG_COMPONENT_DEFINE ("MixedWireless");
+
+//
+// This function will be used below as a trace sink, if the command-line
+// argument or default value "useCourseChangeCallback" is set to true
+//
+static void
+CourseChangeCallback (std::string path, Ptr<const MobilityModel> model)
+{
+ Vector position = model->GetPosition ();
+ std::cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std::endl;
+}
+
+int
+main (int argc, char *argv[])
+{
+ //
+ // First, we declare and initialize a few local variables that control some
+ // simulation parameters.
+ //
+ uint32_t backboneNodes = 10;
+ uint32_t infraNodes = 5;
+ uint32_t lanNodes = 5;
+ uint32_t stopTime = 10;
+ bool useCourseChangeCallback = false;
+ bool enableTracing = false;
+
+ //
+ // Simulation defaults are typically set next, before command line
+ // arguments are parsed.
+ //
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", StringValue ("210"));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("10kb/s"));
+
+ //
+ // For convenience, we add the local variables to the command line argument
+ // system so that they can be overridden with flags such as
+ // "--backboneNodes=20"
+ //
+ CommandLine cmd;
+ cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes);
+ cmd.AddValue ("infraNodes", "number of leaf nodes", infraNodes);
+ cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes);
+ cmd.AddValue("stopTime", "simulation stop time (seconds)", stopTime);
+ cmd.AddValue("useCourseChangeCallback", "whether to enable course change tracing", useCourseChangeCallback);
+ cmd.AddValue("enableTracing", "enable tracing", enableTracing);
+
+ //
+ // The system global variables and the local values added to the argument
+ // system can be overridden by command line arguments by using this call.
+ //
+ cmd.Parse (argc, argv);
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Construct the backbone //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ //
+ // Create a container to manage the nodes of the adhoc (backbone) network.
+ // Later we'll create the rest of the nodes we'll need.
+ //
+ NodeContainer backbone;
+ backbone.Create (backboneNodes);
+ //
+ // Create the backbone wifi net devices and install them into the nodes in
+ // our container
+ //
+ WifiHelper wifi;
+ NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
+ mac.SetType ("ns3::AdhocWifiMac");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-54mbs"));
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ NetDeviceContainer backboneDevices = wifi.Install (wifiPhy, mac, backbone);
+
+ // We enable OLSR (which will be consulted at a higher priority than
+ // the global routing) on the backbone ad hoc nodes
+ NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes");
+ OlsrHelper olsr;
+ //
+ // Add the IPv4 protocol stack to the nodes in our container
+ //
+ InternetStackHelper internet;
+ internet.SetRoutingHelper (olsr);
+ internet.Install (backbone);
+
+ // re-initialize for non-olsr routing.
+ internet.Reset ();
+
+ //
+ // Assign IPv4 addresses to the device drivers (actually to the associated
+ // IPv4 interfaces) we just created.
+ //
+ Ipv4AddressHelper ipAddrs;
+ ipAddrs.SetBase ("192.168.0.0", "255.255.255.0");
+ ipAddrs.Assign (backboneDevices);
+
+ //
+ // The ad-hoc network nodes need a mobility model so we aggregate one to
+ // each of the nodes we just finished building.
+ //
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc =
+ CreateObject<ListPositionAllocator> ();
+ double x = 0.0;
+ for (uint32_t i = 0; i < backboneNodes; ++i)
+ {
+ positionAlloc->Add (Vector (x, 0.0, 0.0));
+ x += 5.0;
+ }
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (0, 20, 0, 20)),
+ "Speed", RandomVariableValue (ConstantVariable (2)),
+ "Pause", RandomVariableValue (ConstantVariable (0.2)));
+ mobility.Install (backbone);
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Construct the LANs //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ // Reset the address base-- all of the CSMA networks will be in
+ // the "172.16 address space
+ ipAddrs.SetBase ("172.16.0.0", "255.255.255.0");
+
+
+ for (uint32_t i = 0; i < backboneNodes; ++i)
+ {
+ NS_LOG_INFO ("Configuring local area network for backbone node " << i);
+ //
+ // Create a container to manage the nodes of the LAN. We need
+ // two containers here; one with all of the new nodes, and one
+ // with all of the nodes including new and existing nodes
+ //
+ NodeContainer newLanNodes;
+ newLanNodes.Create (lanNodes - 1);
+ // Now, create the container with all nodes on this link
+ NodeContainer lan (backbone.Get (i), newLanNodes);
+ //
+ // Create the CSMA net devices and install them into the nodes in our
+ // collection.
+ //
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate",
+ DataRateValue (DataRate (5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer lanDevices = csma.Install (lan);
+ //
+ // Add the IPv4 protocol stack to the new LAN nodes
+ //
+ internet.Install (newLanNodes);
+ //
+ // Assign IPv4 addresses to the device drivers (actually to the
+ // associated IPv4 interfaces) we just created.
+ //
+ ipAddrs.Assign (lanDevices);
+ //
+ // Assign a new network prefix for the next LAN, according to the
+ // network mask initialized above
+ //
+ ipAddrs.NewNetwork ();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Construct the mobile networks //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ // Reset the address base-- all of the 802.11 networks will be in
+ // the "10.0" address space
+ ipAddrs.SetBase ("10.0.0.0", "255.255.255.0");
+
+ for (uint32_t i = 0; i < backboneNodes; ++i)
+ {
+ NS_LOG_INFO ("Configuring wireless network for backbone node " << i);
+ //
+ // Create a container to manage the nodes of the LAN. We need
+ // two containers here; one with all of the new nodes, and one
+ // with all of the nodes including new and existing nodes
+ //
+ NodeContainer stas;
+ stas.Create (infraNodes - 1);
+ // Now, create the container with all nodes on this link
+ NodeContainer infra (backbone.Get (i), stas);
+ //
+ // Create an infrastructure network
+ //
+ WifiHelper wifiInfra = WifiHelper::Default ();
+ NqosWifiMacHelper macInfra = NqosWifiMacHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ // Create unique ssids for these networks
+ std::string ssidString("wifi-infra");
+ std::stringstream ss;
+ ss << i;
+ ssidString += ss.str();
+ Ssid ssid = Ssid (ssidString);
+ wifiInfra.SetRemoteStationManager ("ns3::ArfWifiManager");
+ // setup stas
+ macInfra.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ NetDeviceContainer staDevices = wifiInfra.Install (wifiPhy, macInfra, stas);
+ // setup ap.
+ macInfra.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ NetDeviceContainer apDevices = wifiInfra.Install (wifiPhy, macInfra, backbone.Get (i));
+ // Collect all of these new devices
+ NetDeviceContainer infraDevices (apDevices, staDevices);
+
+ // Add the IPv4 protocol stack to the nodes in our container
+ //
+ internet.Install (stas);
+ //
+ // Assign IPv4 addresses to the device drivers (actually to the associated
+ // IPv4 interfaces) we just created.
+ //
+ ipAddrs.Assign (infraDevices);
+ //
+ // Assign a new network prefix for each mobile network, according to
+ // the network mask initialized above
+ //
+ ipAddrs.NewNetwork ();
+ //
+ // The new wireless nodes need a mobility model so we aggregate one
+ // to each of the nodes we just finished building.
+ //
+ Ptr<ListPositionAllocator> subnetAlloc =
+ CreateObject<ListPositionAllocator> ();
+ for (uint32_t j = 0; j < infra.GetN (); ++j)
+ {
+ subnetAlloc->Add (Vector (0.0, j, 0.0));
+ }
+ mobility.PushReferenceMobilityModel (backbone.Get (i));
+ mobility.SetPositionAllocator (subnetAlloc);
+ mobility.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (-10, 10, -10, 10)),
+ "Speed", RandomVariableValue (ConstantVariable (3)),
+ "Pause", RandomVariableValue (ConstantVariable (0.4)));
+ mobility.Install (infra);
+ }
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Routing configuration //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ // The below global routing does not take into account wireless effects.
+ // However, it is useful for setting default routes for all of the nodes
+ // such as the LAN nodes.
+ NS_LOG_INFO ("Enabling global routing on all nodes");
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Application configuration //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ // Create the OnOff application to send UDP datagrams of size
+ // 210 bytes at a rate of 10 Kb/s, between two nodes
+ // We'll send data from the first wired LAN node on the first wired LAN
+ // to the last wireless STA on the last infrastructure net, thereby
+ // causing packets to traverse CSMA to adhoc to infrastructure links
+
+ NS_LOG_INFO ("Create Applications.");
+ uint16_t port = 9; // Discard port (RFC 863)
+
+ // Let's make sure that the user does not define too few nodes
+ // to make this example work. We need lanNodes > 1 and infraNodes > 1
+ NS_ASSERT (lanNodes > 1 && infraNodes > 1);
+ // We want the source to be the first node created outside of the backbone
+ // Conveniently, the variable "backboneNodes" holds this node index value
+ Ptr<Node> appSource = NodeList::GetNode (backboneNodes);
+ // We want the sink to be the last node created in the topology.
+ uint32_t lastNodeIndex = backboneNodes + backboneNodes*(lanNodes - 1) + backboneNodes*(infraNodes - 1) - 1;
+ Ptr<Node> appSink = NodeList::GetNode (lastNodeIndex);
+ // Let's fetch the IP address of the last node, which is on Ipv4Interface 1
+ Ipv4Address remoteAddr = appSink->GetObject<Ipv4> ()->GetAddress(1, 0).GetLocal ();
+
+ OnOffHelper onoff ("ns3::UdpSocketFactory",
+ Address (InetSocketAddress (remoteAddr, port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer apps = onoff.Install (appSource);
+ apps.Start (Seconds (3.0));
+ apps.Stop (Seconds (20.0));
+
+ // Create a packet sink to receive these packets
+ PacketSinkHelper sink ("ns3::UdpSocketFactory",
+ InetSocketAddress (Ipv4Address::GetAny (), port));
+ apps = sink.Install (appSink);
+ apps.Start (Seconds (3.0));
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Tracing configuration //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ NS_LOG_INFO ("Configure Tracing.");
+ std::ofstream ascii;
+ if (enableTracing == true)
+ {
+ //
+ // Let's set up some ns-2-like ascii traces, using another helper class
+ //
+ ascii.open ("mixed-wireless.tr");
+ YansWifiPhyHelper::EnableAsciiAll (ascii);
+ CsmaHelper::EnableAsciiAll (ascii);
+ InternetStackHelper::EnableAsciiAll (ascii);
+
+ // Let's do a pcap trace on the application source and sink, ifIndex 0
+ // Csma captures in non-promiscuous mode
+ CsmaHelper::EnablePcap ("mixed-wireless", appSource->GetId (), 0, false);
+ wifiPhy.EnablePcap ("mixed-wireless", appSink->GetId (), 0);
+ wifiPhy.EnablePcap ("mixed-wireless", 9, 2);
+ wifiPhy.EnablePcap ("mixed-wireless", 9, 0);
+ }
+
+ if (useCourseChangeCallback == true)
+ {
+ Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange", MakeCallback (&CourseChangeCallback));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // //
+ // Run simulation //
+ // //
+ ///////////////////////////////////////////////////////////////////////////
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Stop (Seconds (stopTime));
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/mixed-wireless.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,352 @@
+# /*
+# * This program is free software; you can redistribute it and/or modify
+# * it under the terms of the GNU General Public License version 2 as
+# * published by the Free Software Foundation;
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# * GNU General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public License
+# * along with this program; if not, write to the Free Software
+# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# *
+# */
+
+#
+# This ns-3 example demonstrates the use of helper functions to ease
+# the construction of simulation scenarios.
+#
+# The simulation topology consists of a mixed wired and wireless
+# scenario in which a hierarchical mobility model is used.
+#
+# The simulation layout consists of N backbone routers interconnected
+# by an ad hoc wifi network.
+# Each backbone router also has a local 802.11 network and is connected
+# to a local LAN. An additional set of(K-1) nodes are connected to
+# this backbone. Finally, a local LAN is connected to each router
+# on the backbone, with L-1 additional hosts.
+#
+# The nodes are populated with TCP/IP stacks, and OLSR unicast routing
+# on the backbone. An example UDP transfer is shown. The simulator
+# be configured to output tcpdumps or traces from different nodes.
+#
+#
+# +--------------------------------------------------------+
+# | |
+# | 802.11 ad hoc, ns-2 mobility |
+# | |
+# +--------------------------------------------------------+
+# | o o o(N backbone routers) |
+# +--------+ +--------+
+# wired LAN | mobile | wired LAN | mobile |
+# -----------| router | -----------| router |
+# --------- ---------
+# | |
+# +----------------+ +----------------+
+# | 802.11 | | 802.11 |
+# | net | | net |
+# | K-1 hosts | | K-1 hosts |
+# +----------------+ +----------------+
+#
+
+import ns3
+
+# #
+# # This function will be used below as a trace sink
+# #
+# static void
+# CourseChangeCallback(std.string path, Ptr<const MobilityModel> model)
+# {
+# Vector position = model.GetPosition();
+# std.cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std.endl;
+# }
+
+def main(argv):
+ #
+ # First, we declare and initialize a few local variables that control some
+ # simulation parameters.
+ #
+ backboneNodes = 10
+ infraNodes = 5
+ lanNodes = 5
+ stopTime = 10
+
+ #
+ # Simulation defaults are typically set next, before command line
+ # arguments are parsed.
+ #
+ ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.StringValue("210"))
+ ns3.Config.SetDefault("ns3::OnOffApplication::DataRate", ns3.StringValue("448kb/s"))
+
+ #
+ # For convenience, we add the local variables to the command line argument
+ # system so that they can be overridden with flags such as
+ # "--backboneNodes=20"
+ #
+ cmd = ns3.CommandLine()
+ #cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes)
+ #cmd.AddValue("infraNodes", "number of leaf nodes", infraNodes)
+ #cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes)
+ #cmd.AddValue("stopTime", "simulation stop time(seconds)", stopTime)
+
+ #
+ # The system global variables and the local values added to the argument
+ # system can be overridden by command line arguments by using this call.
+ #
+ cmd.Parse(argv)
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+ # #
+ # Construct the backbone #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+
+ #
+ # Create a container to manage the nodes of the adhoc(backbone) network.
+ # Later we'll create the rest of the nodes we'll need.
+ #
+ backbone = ns3.NodeContainer()
+ backbone.Create(backboneNodes)
+ #
+ # Create the backbone wifi net devices and install them into the nodes in
+ # our container
+ #
+ wifi = ns3.WifiHelper()
+ mac = ns3.NqosWifiMacHelper.Default()
+ mac.SetType("ns3::AdhocWifiMac")
+ wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
+ "DataMode", ns3.StringValue("wifia-54mbs"))
+ wifiPhy = ns3.YansWifiPhyHelper.Default()
+ wifiChannel = ns3.YansWifiChannelHelper.Default()
+ wifiPhy.SetChannel(wifiChannel.Create())
+ backboneDevices = wifi.Install(wifiPhy, mac, backbone)
+ #
+ # Add the IPv4 protocol stack to the nodes in our container
+ #
+ print "Enabling OLSR routing on all backbone nodes"
+ internet = ns3.InternetStackHelper()
+ olsr = ns3.OlsrHelper()
+ internet.SetRoutingHelper(olsr);
+ internet.Install(backbone);
+ # re-initialize for non-olsr routing.
+ internet.Reset()
+ #
+ # Assign IPv4 addresses to the device drivers(actually to the associated
+ # IPv4 interfaces) we just created.
+ #
+ ipAddrs = ns3.Ipv4AddressHelper()
+ ipAddrs.SetBase(ns3.Ipv4Address("192.168.0.0"), ns3.Ipv4Mask("255.255.255.0"))
+ ipAddrs.Assign(backboneDevices)
+
+ #
+ # The ad-hoc network nodes need a mobility model so we aggregate one to
+ # each of the nodes we just finished building.
+ #
+ mobility = ns3.MobilityHelper()
+ positionAlloc = ns3.ListPositionAllocator()
+ x = 0.0
+ for i in range(backboneNodes):
+ positionAlloc.Add(ns3.Vector(x, 0.0, 0.0))
+ x += 5.0
+ mobility.SetPositionAllocator(positionAlloc)
+ mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
+ "Bounds", ns3.RectangleValue(ns3.Rectangle(0, 1000, 0, 1000)),
+ "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(2000)),
+ "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.2)))
+ mobility.Install(backbone)
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+ # #
+ # Construct the LANs #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+
+ # Reset the address base-- all of the CSMA networks will be in
+ # the "172.16 address space
+ ipAddrs.SetBase(ns3.Ipv4Address("172.16.0.0"), ns3.Ipv4Mask("255.255.255.0"))
+
+ for i in range(backboneNodes):
+ print "Configuring local area network for backbone node ", i
+ #
+ # Create a container to manage the nodes of the LAN. We need
+ # two containers here; one with all of the new nodes, and one
+ # with all of the nodes including new and existing nodes
+ #
+ newLanNodes = ns3.NodeContainer()
+ newLanNodes.Create(lanNodes - 1)
+ # Now, create the container with all nodes on this link
+ lan = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), newLanNodes)
+ #
+ # Create the CSMA net devices and install them into the nodes in our
+ # collection.
+ #
+ csma = ns3.CsmaHelper()
+ csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
+ csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
+ lanDevices = csma.Install(lan)
+ #
+ # Add the IPv4 protocol stack to the new LAN nodes
+ #
+ internet.Install(newLanNodes)
+ #
+ # Assign IPv4 addresses to the device drivers(actually to the
+ # associated IPv4 interfaces) we just created.
+ #
+ ipAddrs.Assign(lanDevices)
+ #
+ # Assign a new network prefix for the next LAN, according to the
+ # network mask initialized above
+ #
+ ipAddrs.NewNetwork()
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+ # #
+ # Construct the mobile networks #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+
+ # Reset the address base-- all of the 802.11 networks will be in
+ # the "10.0" address space
+ ipAddrs.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
+
+ for i in range(backboneNodes):
+ print "Configuring wireless network for backbone node ", i
+ #
+ # Create a container to manage the nodes of the LAN. We need
+ # two containers here; one with all of the new nodes, and one
+ # with all of the nodes including new and existing nodes
+ #
+ stas = ns3.NodeContainer()
+ stas.Create(infraNodes - 1)
+ # Now, create the container with all nodes on this link
+ infra = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), stas)
+ #
+ # Create another ad hoc network and devices
+ #
+ ssid = ns3.Ssid('wifi-infra' + str(i))
+ wifiInfra = ns3.WifiHelper.Default()
+ wifiPhy.SetChannel(wifiChannel.Create())
+ wifiInfra.SetRemoteStationManager('ns3::ArfWifiManager')
+ macInfra = ns3.NqosWifiMacHelper.Default();
+ macInfra.SetType("ns3::NqstaWifiMac",
+ "Ssid", ns3.SsidValue(ssid),
+ "ActiveProbing", ns3.BooleanValue(False))
+
+ # setup stas
+ staDevices = wifiInfra.Install(wifiPhy, macInfra, stas)
+ # setup ap.
+ macInfra.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid),
+ "BeaconGeneration", ns3.BooleanValue(True),
+ "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
+ apDevices = wifiInfra.Install(wifiPhy, macInfra, backbone.Get(i))
+ # Collect all of these new devices
+ infraDevices = ns3.NetDeviceContainer(apDevices, staDevices)
+
+ # Add the IPv4 protocol stack to the nodes in our container
+ #
+ internet.Install(stas)
+ #
+ # Assign IPv4 addresses to the device drivers(actually to the associated
+ # IPv4 interfaces) we just created.
+ #
+ ipAddrs.Assign(infraDevices)
+ #
+ # Assign a new network prefix for each mobile network, according to
+ # the network mask initialized above
+ #
+ ipAddrs.NewNetwork()
+ #
+ # The new wireless nodes need a mobility model so we aggregate one
+ # to each of the nodes we just finished building.
+ #
+ subnetAlloc = ns3.ListPositionAllocator()
+ for j in range(infra.GetN()):
+ subnetAlloc.Add(ns3.Vector(0.0, j, 0.0))
+
+ mobility.PushReferenceMobilityModel(backbone.Get(i))
+ mobility.SetPositionAllocator(subnetAlloc)
+ mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
+ "Bounds", ns3.RectangleValue(ns3.Rectangle(-25, 25, -25, 25)),
+ "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(30)),
+ "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.4)))
+ mobility.Install(infra)
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+ # #
+ # Application configuration #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+
+ # Create the OnOff application to send UDP datagrams of size
+ # 210 bytes at a rate of 448 Kb/s, between two nodes
+ print "Create Applications."
+ port = 9 # Discard port(RFC 863)
+
+ # Let's make sure that the user does not define too few LAN nodes
+ # to make this example work. We need lanNodes >= 5
+ assert(lanNodes >= 5)
+ appSource = ns3.NodeList.GetNode(11)
+ appSink = ns3.NodeList.GetNode(13)
+ remoteAddr = ns3.Ipv4Address("172.16.0.5")
+
+ onoff = ns3.OnOffHelper("ns3::UdpSocketFactory",
+ ns3.Address(ns3.InetSocketAddress(remoteAddr, port)))
+ onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
+ onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
+ apps = onoff.Install(ns3.NodeContainer(appSource))
+ apps.Start(ns3.Seconds(3.0))
+ apps.Stop(ns3.Seconds(20.0))
+
+ # Create a packet sink to receive these packets
+ sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory",
+ ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port))
+ apps = sink.Install(ns3.NodeContainer(appSink))
+ apps.Start(ns3.Seconds(3.0))
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+ # #
+ # Tracing configuration #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /
+
+ print "Configure Tracing."
+ #
+ # Let's set up some ns-2-like ascii traces, using another helper class
+ #
+ #std.ofstream ascii
+ #ascii.open("mixed-wireless.tr")
+ #WifiHelper.EnableAsciiAll(ascii)
+ #CsmaHelper.EnableAsciiAll(ascii)
+ print "(tracing not done for Python)"
+ # Look at nodes 11, 13 only
+ # WifiHelper.EnableAscii(ascii, 11, 0);
+ # WifiHelper.EnableAscii(ascii, 13, 0);
+
+ # Let's do a pcap trace on the backbone devices
+ wifiPhy.EnablePcap("mixed-wireless", backboneDevices)
+ # Let's additionally trace the application Sink, ifIndex 0
+ ns3.CsmaHelper.EnablePcap("mixed-wireless", appSink.GetId(), 0, False)
+
+# #ifdef ENABLE_FOR_TRACING_EXAMPLE
+# Config.Connect("/NodeList/*/$MobilityModel/CourseChange",
+# MakeCallback(&CourseChangeCallback))
+# #endif
+
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ # #
+ # Run simulation #
+ # #
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+ print "Run Simulation."
+ ns3.Simulator.Stop(ns3.Seconds(stopTime))
+ ns3.Simulator.Run()
+ ns3.Simulator.Destroy()
+
+
+if __name__ == '__main__':
+ import sys
+ main(sys.argv)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/multirate.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,588 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Duy Nguyen <duy@soe.ucsc.edu>
+ */
+
+/**
+ * Scenarios: 100 nodes, multiple simultaneous flows, multi-hop ad hoc, routing,
+ * and mobility
+ *
+ * INSTRUCTIONS:
+ *
+ * To optimize build:
+ * ./waf -d optimized configure
+ * ./waf
+ *
+ * To compile:
+ * ./waf --run multirate
+ *
+ * To compile with commandline(useful for varying parameters or configurations):
+ * ./waf --run "scratch/multirate.cc --packetSize=2000 --totalTime=50"
+ *
+ * To turn on NS_LOG:
+ * export NS_LOG=multirate=level_all
+ * (can only view log if built with ./waf -d debug configure)
+ *
+ * To debug:
+ * ./waf --shell
+ * gdb ./build/debug/scratch/multirate
+ *
+ * To view pcap files:
+ * tcpdump -nn -tt -r filename.pcap
+ *
+ * To monitor the files
+ * tail -f filename.pcap
+ *
+ * Sidenote: Simulation might take sometime
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/random-variable.h"
+#include "ns3/wifi-module.h"
+
+#include <iostream>
+#include <fstream>
+
+NS_LOG_COMPONENT_DEFINE ("multirate");
+
+using namespace ns3;
+
+class Experiment
+{
+public:
+
+ Experiment ();
+ Experiment (std::string name);
+ Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility);
+
+ bool CommandSetup (int argc, char **argv);
+ bool IsRouting () { return (enableRouting == 1) ? 1:0; }
+ bool IsMobility () { return (enableMobility == 1) ? 1:0; }
+
+ uint32_t GetScenario () {return scenario; }
+
+ std::string GetRtsThreshold () { return rtsThreshold; }
+ std::string GetOutputFileName () { return outputFileName; }
+ std::string GetRateManager () { return rateManager; }
+
+private:
+
+ Vector GetPosition (Ptr<Node> node);
+ Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
+ NodeContainer GenerateNeighbors(NodeContainer c, uint32_t senderId);
+
+ void ApplicationSetup (Ptr<Node> client, Ptr<Node> server, double start, double stop);
+ void AssignNeighbors (NodeContainer c);
+ void SelectSrcDest (NodeContainer c);
+ void ReceivePacket (Ptr<Socket> socket);
+ void CheckThroughput ();
+ void SendMultiDestinations (Ptr<Node> sender, NodeContainer c);
+
+ Gnuplot2dDataset m_output;
+
+ double totalTime;
+
+ uint32_t bytesTotal;
+ uint32_t packetSize;
+ uint32_t gridSize;
+ uint32_t nodeDistance;
+ uint32_t port;
+ uint32_t expMean;
+ uint32_t scenario;
+
+ bool enablePcap;
+ bool enableTracing;
+ bool enableFlowMon;
+ bool enableRouting;
+ bool enableMobility;
+
+ NodeContainer containerA, containerB, containerC, containerD;
+ std::string rtsThreshold, rateManager, outputFileName;
+};
+
+Experiment::Experiment ()
+{}
+
+Experiment::Experiment (std::string name) :
+ m_output (name),
+ totalTime (50), //use shorter time for faster simulation
+ bytesTotal(0),
+ packetSize (2000),
+ gridSize (10), //10x10 grid for a total of 100 nodes
+ nodeDistance (30),
+ port (5000),
+ expMean (4), //flows being exponentially distributed
+ scenario (4),
+ enablePcap (false), // will flood the directory with *.pcap files
+ enableTracing (true),
+ enableFlowMon (true),
+ enableRouting (false),
+ enableMobility (false),
+ rtsThreshold ("2200"), //0 for enabling rts/cts
+ rateManager ("ns3::MinstrelWifiManager"),
+ outputFileName ("minstrel")
+{
+ m_output.SetStyle (Gnuplot2dDataset::LINES);
+}
+
+Ptr<Socket>
+Experiment::SetupPacketReceive (Ptr<Node> node)
+{
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> sink = Socket::CreateSocket (node, tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), port);
+ sink->Bind (local);
+ sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
+
+ return sink;
+}
+
+void
+Experiment::ReceivePacket (Ptr<Socket> socket)
+{
+ Ptr<Packet> packet;
+ while (packet = socket->Recv ())
+ {
+ bytesTotal += packet->GetSize();
+ }
+}
+
+void
+Experiment::CheckThroughput()
+{
+ double mbs = ((bytesTotal * 8.0) /1000000);
+ bytesTotal = 0;
+ m_output.Add ((Simulator::Now ()).GetSeconds (), mbs);
+
+ Simulator::Schedule (Seconds (1.0), &Experiment::CheckThroughput, this);
+}
+
+Vector
+Experiment::GetPosition (Ptr<Node> node)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ return mobility->GetPosition ();
+}
+
+/**
+ *
+ * Take the grid map, divide it into 4 quadrants
+ * Assign all nodes from each quadrant to a specific container
+ *
+ */
+void
+Experiment::AssignNeighbors (NodeContainer c)
+{
+ uint32_t totalNodes = c.GetN ();
+ for (uint32_t i=0; i< totalNodes; i++)
+ {
+ if ( (i % gridSize) <= (gridSize/2 - 1))
+ {
+ //lower left quadrant
+ if ( i < totalNodes/2 )
+ {
+ containerA.Add(c.Get(i));
+ }
+
+ //upper left quadrant
+ if ( i >= (uint32_t)(4*totalNodes)/10 )
+ {
+ containerC.Add(c.Get(i));
+ }
+ }
+ if ( (i % gridSize) >= (gridSize/2 - 1))
+ {
+ //lower right quadrant
+ if ( i < totalNodes/2 )
+ {
+ containerB.Add(c.Get(i));
+ }
+
+ //upper right quadrant
+ if ( i >= (uint32_t)(4*totalNodes)/10 )
+ {
+ containerD.Add(c.Get(i));
+ }
+ }
+ }
+}
+
+/**
+ * Generate 1-hop and 2-hop neighbors of a node in grid topology
+ *
+ */
+NodeContainer
+Experiment::GenerateNeighbors (NodeContainer c, uint32_t senderId)
+{
+ NodeContainer nc;
+ uint32_t limit = senderId + 2;
+ for (uint32_t i= senderId - 2; i <= limit; i++)
+ {
+ //must ensure the boundaries for other topologies
+ nc.Add(c.Get(i));
+ nc.Add(c.Get(i + 10));
+ nc.Add(c.Get(i + 20));
+ nc.Add(c.Get(i - 10));
+ nc.Add(c.Get(i - 20));
+ }
+ return nc;
+}
+
+/**
+ * Sources and destinations are randomly selected such that a node
+ * may be the source for multiple destinations and a node maybe a destination
+ * for multiple sources.
+ */
+void
+Experiment::SelectSrcDest (NodeContainer c)
+{
+ uint32_t totalNodes = c.GetN();
+ UniformVariable uvSrc (0, totalNodes/2 -1);
+ UniformVariable uvDest (totalNodes/2, totalNodes);
+
+ for (uint32_t i=0; i < totalNodes/3; i++)
+ {
+ ApplicationSetup (c.Get(uvSrc.RandomVariable::GetInteger()), c.Get(uvDest.RandomVariable::GetInteger()) , 1, totalTime);
+ }
+}
+
+/**
+ *
+ * A sender node will set up a flow to each of the its neighbors
+ * in its quadrant randomly. All the flows are exponentially distributed
+ *
+ */
+void
+Experiment::SendMultiDestinations(Ptr<Node> sender, NodeContainer c)
+{
+
+ // UniformVariable params: (Xrange, Yrange)
+ UniformVariable uv(0, c.GetN ());
+
+ // ExponentialVariable params: (mean, upperbound)
+ ExponentialVariable ev(expMean, totalTime);
+
+ double start=1, stop=totalTime;
+ uint32_t destIndex;
+
+ for (uint32_t i=0; i < c.GetN (); i++)
+ {
+ stop = start + ev.GetValue();
+ NS_LOG_DEBUG("Start=" << start << " Stop=" << stop);
+
+ do {
+ destIndex = (uint32_t) uv.GetValue();
+ } while ( (c.Get(destIndex))->GetId () == sender->GetId ());
+
+ ApplicationSetup (sender, c.Get(destIndex) , start, stop);
+
+ start = stop;
+
+ if(start > totalTime)
+ {
+ break;
+ }
+ }
+}
+
+void
+Experiment::ApplicationSetup (Ptr<Node> client, Ptr<Node> server, double start, double stop)
+{
+
+ Vector serverPos = GetPosition (server);
+ Vector clientPos = GetPosition (client);
+
+ Ptr<Ipv4> ipv4Server = server->GetObject<Ipv4>();
+ Ptr<Ipv4> ipv4Client = client->GetObject<Ipv4>();
+
+ Ipv4InterfaceAddress iaddrServer = ipv4Server->GetAddress(1,0);
+ Ipv4InterfaceAddress iaddrClient = ipv4Client->GetAddress(1,0);
+
+ Ipv4Address ipv4AddrServer = iaddrServer.GetLocal ();
+ Ipv4Address ipv4AddrClient = iaddrClient.GetLocal ();
+
+ NS_LOG_DEBUG("Set up Server Device " << (server->GetDevice(0))->GetAddress ()
+ << " with ip " << ipv4AddrServer
+ << " position (" << serverPos.x << "," << serverPos.y << "," << serverPos.z << ")");
+
+ NS_LOG_DEBUG("Set up Client Device " << (client->GetDevice(0))->GetAddress ()
+ << " with ip " << ipv4AddrClient
+ << " position (" << clientPos.x << "," << clientPos.y << "," << clientPos.z << ")"
+ << "\n");
+
+
+ // Equipping the source node with OnOff Application used for sending
+ OnOffHelper onoff ("ns3::UdpSocketFactory", Address(InetSocketAddress(Ipv4Address("10.0.0.1"), port)));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
+ onoff.SetAttribute ("PacketSize", UintegerValue (packetSize));
+ onoff.SetAttribute ("Remote", AddressValue(InetSocketAddress (ipv4AddrServer, port)));
+
+ ApplicationContainer apps = onoff.Install (client);
+ apps.Start (Seconds (start));
+ apps.Stop (Seconds (stop));
+
+/*
+ // Select either Sink Method 1 or 2 for setting up sink
+ // one using a helper vs one without
+ // Sink: Method 1
+ Address sinkAddr(InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory", sinkAddr);
+ ApplicationContainer sinkApp = sinkHelper.Install (server);
+ sinkApp.Start (Seconds (start));
+ sinkApp.Stop (Seconds (stop));
+*/
+
+ // Sink: Method 2
+ Ptr<Socket> sink = SetupPacketReceive (server);
+
+}
+
+Gnuplot2dDataset
+Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel, const MobilityHelper &mobility)
+{
+
+
+ uint32_t nodeSize = gridSize*gridSize;
+ NodeContainer c;
+ c.Create (nodeSize);
+
+ YansWifiPhyHelper phy = wifiPhy;
+ phy.SetChannel (wifiChannel.Create ());
+
+ NqosWifiMacHelper mac = wifiMac;
+ NetDeviceContainer devices = wifi.Install (phy, mac, c);
+
+
+ OlsrHelper olsr;
+ Ipv4StaticRoutingHelper staticRouting;
+
+ Ipv4ListRoutingHelper list;
+
+ if (enableRouting)
+ {
+ list.Add (staticRouting, 0);
+ list.Add (olsr, 10);
+ }
+
+ InternetStackHelper internet;
+
+ if (enableRouting)
+ {
+ internet.SetRoutingHelper(list);
+ }
+ internet.Install (c);
+
+
+ Ipv4AddressHelper address;
+ address.SetBase ("10.0.0.0", "255.255.255.0");
+
+ Ipv4InterfaceContainer ipInterfaces;
+ ipInterfaces = address.Assign(devices);
+
+ MobilityHelper mobil= mobility;
+ mobil.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (0.0),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (nodeDistance),
+ "DeltaY", DoubleValue (nodeDistance),
+ "GridWidth", UintegerValue (gridSize),
+ "LayoutType", StringValue ("RowFirst"));
+
+ mobil.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+
+ if (enableMobility && enableRouting)
+ {
+ //Rectangle (xMin, xMax, yMin, yMax)
+ mobil.SetMobilityModel ("ns3::RandomDirection2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (0, 500, 0, 500)),
+ "Speed", RandomVariableValue (ConstantVariable (10)),
+ "Pause", RandomVariableValue (ConstantVariable (0.2)));
+ }
+ mobil.Install (c);
+
+
+// NS_LOG_INFO ("Enabling global routing on all nodes");
+// Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ if ( scenario == 1 && enableRouting)
+ {
+ SelectSrcDest(c);
+ }
+ else if ( scenario == 2)
+ {
+ //All flows begin at the same time
+ for (uint32_t i = 0; i < nodeSize - 1; i = i+2)
+ {
+ ApplicationSetup (c.Get (i), c.Get (i+1), 1, totalTime);
+ }
+ }
+ else if ( scenario == 3)
+ {
+ AssignNeighbors(c);
+ //Note: these senders are hand-picked in order to ensure good coverage
+ //for 10x10 grid, basically one sender for each quadrant
+ //you might have to change these values for other grids
+ NS_LOG_DEBUG(">>>>>>>>>region A<<<<<<<<<");
+ SendMultiDestinations(c.Get(22), containerA);
+
+ NS_LOG_DEBUG(">>>>>>>>>region B<<<<<<<<<");
+ SendMultiDestinations(c.Get(26), containerB);
+
+ NS_LOG_DEBUG(">>>>>>>>>region C<<<<<<<<<");
+ SendMultiDestinations(c.Get(72), containerC);
+
+ NS_LOG_DEBUG(">>>>>>>>>region D<<<<<<<<<");
+ SendMultiDestinations(c.Get(76), containerD);
+ }
+ else if ( scenario == 4)
+ {
+ //GenerateNeighbors(NodeContainer, uint32_t sender)
+ //Note: these senders are hand-picked in order to ensure good coverage
+ //you might have to change these values for other grids
+ NodeContainer c1, c2, c3, c4, c5, c6, c7, c8, c9;
+
+ c1 = GenerateNeighbors(c, 22);
+ c2 = GenerateNeighbors(c, 24);;
+ c3 = GenerateNeighbors(c, 26);;
+ c4 = GenerateNeighbors(c, 42);;
+ c5 = GenerateNeighbors(c, 44);;
+ c6 = GenerateNeighbors(c, 46);;
+ c7 = GenerateNeighbors(c, 62);;
+ c8 = GenerateNeighbors(c, 64);;
+ c9 = GenerateNeighbors(c, 66);;
+
+ SendMultiDestinations(c.Get(22), c1);
+ SendMultiDestinations(c.Get(24), c2);
+ SendMultiDestinations(c.Get(26), c3);
+ SendMultiDestinations(c.Get(42), c4);
+ SendMultiDestinations(c.Get(44), c5);
+ SendMultiDestinations(c.Get(46), c6);
+ SendMultiDestinations(c.Get(62), c7);
+ SendMultiDestinations(c.Get(64), c8);
+ SendMultiDestinations(c.Get(66), c9);
+ }
+
+ CheckThroughput ();
+
+ if (enablePcap)
+ {
+ phy.EnablePcapAll(GetOutputFileName());
+ }
+
+ if (enableTracing)
+ {
+ std::ofstream ascii;
+ ascii.open ((GetOutputFileName() + ".tr").c_str());
+ phy.EnableAsciiAll (ascii);
+ }
+
+ Ptr<FlowMonitor> flowmon;
+
+ if (enableFlowMon)
+ {
+ FlowMonitorHelper flowmonHelper;
+ flowmon = flowmonHelper.InstallAll ();
+ }
+
+ Simulator::Stop (Seconds (totalTime));
+ Simulator::Run ();
+
+ if (enableFlowMon)
+ {
+ flowmon->SerializeToXmlFile ((GetOutputFileName() + ".flomon"), false, false);
+ }
+
+ Simulator::Destroy ();
+
+ return m_output;
+}
+
+bool
+Experiment::CommandSetup (int argc, char **argv)
+{
+ // for commandline input
+ CommandLine cmd;
+ cmd.AddValue ("packetSize", "packet size", packetSize);
+ cmd.AddValue ("totalTime", "simulation time", totalTime);
+ cmd.AddValue ("rtsThreshold", "rts threshold", rtsThreshold);
+ cmd.AddValue ("rateManager", "type of rate", rateManager);
+ cmd.AddValue ("outputFileName", "output filename", outputFileName);
+ cmd.AddValue ("enableRouting", "enable Routing", enableRouting);
+ cmd.AddValue ("enableMobility", "enable Mobility", enableMobility);
+ cmd.AddValue ("scenario", "scenario ", scenario);
+
+ cmd.Parse (argc, argv);
+ return true;
+}
+
+int main (int argc, char *argv[])
+{
+
+ Experiment experiment;
+ experiment = Experiment ("multirate");
+
+ //for commandline input
+ if (!experiment.CommandSetup(argc, argv))
+ {
+ std::cout << "Configuration failed..." << std::endl;
+ exit(1);
+ }
+
+ // disable fragmentation
+ // set value to 0 for enabling fragmentation
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue (experiment.GetRtsThreshold()));
+
+ std::ofstream outfile ((experiment.GetOutputFileName()+ ".plt").c_str());
+
+ MobilityHelper mobility;
+ Gnuplot gnuplot;
+ Gnuplot2dDataset dataset;
+
+ WifiHelper wifi = WifiHelper::Default ();
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ Ssid ssid = Ssid ("Testbed");
+
+ wifiMac.SetType ("ns3::AdhocWifiMac", "Ssid", SsidValue(ssid));
+ wifi.SetStandard (WIFI_PHY_STANDARD_holland);
+ wifi.SetRemoteStationManager (experiment.GetRateManager());
+
+ //printing out selection confirmation
+ std::cout << "Scenario: " << experiment.GetScenario () << std::endl;
+ std::cout << "Rts Threshold: " << experiment.GetRtsThreshold() << std::endl;
+ std::cout << "Name: " << experiment.GetOutputFileName() << std::endl;
+ std::cout << "Rate: " << experiment.GetRateManager() << std::endl;
+ std::cout << "Routing: " << experiment.IsRouting() << std::endl;
+ std::cout << "Mobility: " << experiment.IsMobility() << std::endl;
+
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel, mobility);
+
+ gnuplot.AddDataset (dataset);
+ gnuplot.GenerateOutput (outfile);
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/simple-wifi-frame-aggregation.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,150 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 MIRKO BANCHI
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mirko Banchi <mk.banchi@gmail.com>
+ */
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/mobility-module.h"
+
+//This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works.
+//
+//Network topology:
+//
+// Wifi 192.168.1.0
+//
+// AP
+// * * *
+// | | |
+// n1 n2 n3
+//
+//Packets in this simulation aren't marked with a QosTag so they are considered
+//belonging to BestEffort Access Class (AC_BE).
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("SimpleWifiFrameAggregation");
+
+int main (int argc, char *argv[])
+{
+ //LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
+ LogComponentEnable ("MsduAggregator", LOG_LEVEL_INFO);
+ LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
+ LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
+
+ uint32_t nWifi = 1;
+ CommandLine cmd;
+ cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
+ cmd.Parse (argc,argv);
+
+ NodeContainer wifiNodes;
+ wifiNodes.Create (2);
+ NodeContainer wifiApNode;
+ wifiApNode.Create (1);
+
+ YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
+ YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
+ phy.SetChannel (channel.Create ());
+
+ WifiHelper wifi = WifiHelper::Default ();
+ QosWifiMacHelper mac = QosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
+
+ Ssid ssid = Ssid ("ns-3-802.11n");
+ mac.SetType ("ns3::QstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
+ "MaxAmsduSize", UintegerValue (3839));
+
+ NetDeviceContainer staDevices;
+ staDevices = wifi.Install (phy, mac, wifiNodes);
+
+ mac.SetType ("ns3::QapWifiMac",
+ "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
+ "MaxAmsduSize", UintegerValue (7935));
+
+ NetDeviceContainer apDevice;
+ apDevice = wifi.Install (phy, mac, wifiApNode);
+
+ /* Setting mobility model */
+ MobilityHelper mobility;
+
+ mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (0.0),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (5.0),
+ "DeltaY", DoubleValue (10.0),
+ "GridWidth", UintegerValue (3),
+ "LayoutType", StringValue ("RowFirst"));
+
+ mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
+ "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
+ mobility.Install (wifiNodes);
+
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (wifiApNode);
+
+ /* Internet stack*/
+ InternetStackHelper stack;
+ stack.Install (wifiApNode);
+ stack.Install (wifiNodes);
+
+ Ipv4AddressHelper address;
+
+ address.SetBase ("192.168.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer wifiNodesInterfaces;
+ Ipv4InterfaceContainer apNodeInterface;
+
+ wifiNodesInterfaces = address.Assign (staDevices);
+ apNodeInterface = address.Assign (apDevice);
+
+ /* Setting applications */
+ UdpEchoServerHelper echoServer (9);
+
+ ApplicationContainer serverApps = echoServer.Install (wifiNodes.Get (1));
+ serverApps.Start (Seconds (1.0));
+ serverApps.Stop (Seconds (10.0));
+
+ UdpEchoClientHelper echoClient (wifiNodesInterfaces.GetAddress (1), 9);
+ echoClient.SetAttribute ("MaxPackets", UintegerValue (3));
+ echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.000001)));
+ echoClient.SetAttribute ("PacketSize", UintegerValue (1500));
+
+ ApplicationContainer clientApps =
+ echoClient.Install (wifiNodes.Get (0));
+ clientApps.Start (Seconds (2.0));
+ clientApps.Stop (Seconds (10.0));
+
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ Simulator::Stop (Seconds (10.0));
+
+ phy.EnablePcap ("test-802.11n",
+ wifiNodes.Get (nWifi - 1)->GetId (), 0);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/waf Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-adhoc.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,287 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+
+#include <iostream>
+
+NS_LOG_COMPONENT_DEFINE ("Main");
+
+using namespace ns3;
+
+class Experiment
+{
+public:
+ Experiment ();
+ Experiment (std::string name);
+ Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
+private:
+ void ReceivePacket (Ptr<Socket> socket);
+ void SetPosition (Ptr<Node> node, Vector position);
+ Vector GetPosition (Ptr<Node> node);
+ void AdvancePosition (Ptr<Node> node);
+ Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
+
+ uint32_t m_bytesTotal;
+ Gnuplot2dDataset m_output;
+};
+
+Experiment::Experiment ()
+{}
+
+Experiment::Experiment (std::string name)
+ : m_output (name)
+{
+ m_output.SetStyle (Gnuplot2dDataset::LINES);
+}
+
+void
+Experiment::SetPosition (Ptr<Node> node, Vector position)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ mobility->SetPosition (position);
+}
+
+Vector
+Experiment::GetPosition (Ptr<Node> node)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ return mobility->GetPosition ();
+}
+
+void
+Experiment::AdvancePosition (Ptr<Node> node)
+{
+ Vector pos = GetPosition (node);
+ double mbs = ((m_bytesTotal * 8.0) / 1000000);
+ m_bytesTotal = 0;
+ m_output.Add (pos.x, mbs);
+ pos.x += 1.0;
+ if (pos.x >= 210.0)
+ {
+ return;
+ }
+ SetPosition (node, pos);
+ //std::cout << "x="<<pos.x << std::endl;
+ Simulator::Schedule (Seconds (1.0), &Experiment::AdvancePosition, this, node);
+}
+
+void
+Experiment::ReceivePacket (Ptr<Socket> socket)
+{
+ Ptr<Packet> packet;
+ while (packet = socket->Recv ())
+ {
+ m_bytesTotal += packet->GetSize ();
+ }
+}
+
+Ptr<Socket>
+Experiment::SetupPacketReceive (Ptr<Node> node)
+{
+ TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
+ Ptr<Socket> sink = Socket::CreateSocket (node, tid);
+ sink->Bind ();
+ sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
+ return sink;
+}
+
+Gnuplot2dDataset
+Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
+{
+ m_bytesTotal = 0;
+
+ NodeContainer c;
+ c.Create (2);
+
+ PacketSocketHelper packetSocket;
+ packetSocket.Install (c);
+
+ YansWifiPhyHelper phy = wifiPhy;
+ phy.SetChannel (wifiChannel.Create ());
+
+ NqosWifiMacHelper mac = wifiMac;
+ NetDeviceContainer devices = wifi.Install (phy, mac, c);
+
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (5.0, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+
+ mobility.Install (c);
+
+ PacketSocketAddress socket;
+ socket.SetSingleDevice(devices.Get (0)->GetIfIndex ());
+ socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
+ socket.SetProtocol (1);
+
+ OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
+ onoff.SetAttribute ("PacketSize", UintegerValue (2000));
+
+ ApplicationContainer apps = onoff.Install (c.Get (0));
+ apps.Start (Seconds (0.5));
+ apps.Stop (Seconds (250.0));
+
+ Simulator::Schedule (Seconds (1.5), &Experiment::AdvancePosition, this, c.Get (1));
+ Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
+
+ Simulator::Run ();
+
+ Simulator::Destroy ();
+
+ return m_output;
+}
+
+int main (int argc, char *argv[])
+{
+ // disable fragmentation
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ Gnuplot gnuplot = Gnuplot ("reference-rates.png");
+
+ Experiment experiment;
+ WifiHelper wifi = WifiHelper::Default ();
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ Gnuplot2dDataset dataset;
+
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+
+ NS_LOG_DEBUG ("54");
+ experiment = Experiment ("54mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-54mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("48");
+ experiment = Experiment ("48mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-48mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("36");
+ experiment = Experiment ("36mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-36mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("24");
+ experiment = Experiment ("24mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-24mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("18");
+ experiment = Experiment ("18mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-18mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("12");
+ experiment = Experiment ("12mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-12mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("9");
+ experiment = Experiment ("9mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-9mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("6");
+ experiment = Experiment ("6mb");
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode", StringValue ("wifia-6mbs"));
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ gnuplot.GenerateOutput (std::cout);
+
+
+ gnuplot = Gnuplot ("rate-control.png");
+ wifi.SetStandard (WIFI_PHY_STANDARD_holland);
+
+
+ NS_LOG_DEBUG ("arf");
+ experiment = Experiment ("arf");
+ wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("aarf");
+ experiment = Experiment ("aarf");
+ wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("aarf-cd");
+ experiment = Experiment ("aarf-cd");
+ wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("cara");
+ experiment = Experiment ("cara");
+ wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("rraa");
+ experiment = Experiment ("rraa");
+ wifi.SetRemoteStationManager ("ns3::RraaWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ NS_LOG_DEBUG ("ideal");
+ experiment = Experiment ("ideal");
+ wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
+ dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ gnuplot.AddDataset (dataset);
+
+ gnuplot.GenerateOutput (std::cout);
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-ap.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,218 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006,2007 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/athstats-helper.h"
+
+#include <iostream>
+
+using namespace ns3;
+
+static bool g_verbose = true;
+
+void
+DevTxTrace (std::string context, Ptr<const Packet> p)
+{
+ if (g_verbose)
+ {
+ std::cout << " TX p: " << *p << std::endl;
+ }
+}
+void
+DevRxTrace (std::string context, Ptr<const Packet> p)
+{
+ if (g_verbose)
+ {
+ std::cout << " RX p: " << *p << std::endl;
+ }
+}
+void
+PhyRxOkTrace (std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
+{
+ if (g_verbose)
+ {
+ std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
+ }
+}
+void
+PhyRxErrorTrace (std::string context, Ptr<const Packet> packet, double snr)
+{
+ if (g_verbose)
+ {
+ std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
+ }
+}
+void
+PhyTxTrace (std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
+{
+ if (g_verbose)
+ {
+ std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
+ }
+}
+void
+PhyStateTrace (std::string context, Time start, Time duration, enum WifiPhy::State state)
+{
+ if (g_verbose)
+ {
+ std::cout << " state=";
+ switch (state) {
+ case WifiPhy::SWITCHING:
+ std::cout << "switchng";
+ break;
+ case WifiPhy::TX:
+ std::cout << "tx ";
+ break;
+ case WifiPhy::SYNC:
+ std::cout << "sync ";
+ break;
+ case WifiPhy::CCA_BUSY:
+ std::cout << "cca-busy";
+ break;
+ case WifiPhy::IDLE:
+ std::cout << "idle ";
+ break;
+ }
+ std::cout << " start="<<start<<" duration="<<duration<<std::endl;
+ }
+}
+
+static void
+SetPosition (Ptr<Node> node, Vector position)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ mobility->SetPosition (position);
+}
+
+static Vector
+GetPosition (Ptr<Node> node)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ return mobility->GetPosition ();
+}
+
+static void
+AdvancePosition (Ptr<Node> node)
+{
+ Vector pos = GetPosition (node);
+ pos.x += 5.0;
+ if (pos.x >= 210.0)
+ {
+ return;
+ }
+ SetPosition (node, pos);
+
+ if (g_verbose)
+ {
+ //std::cout << "x="<<pos.x << std::endl;
+ }
+ Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
+}
+
+int main (int argc, char *argv[])
+{
+ CommandLine cmd;
+ cmd.AddValue ("verbose", "Print trace information if true", g_verbose);
+
+ cmd.Parse (argc, argv);
+
+ Packet::EnablePrinting ();
+
+ // enable rts cts all the time.
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("0"));
+ // disable fragmentation
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+
+ WifiHelper wifi = WifiHelper::Default ();
+ MobilityHelper mobility;
+ NodeContainer stas;
+ NodeContainer ap;
+ NetDeviceContainer staDevs;
+ PacketSocketHelper packetSocket;
+
+ stas.Create (2);
+ ap.Create (1);
+
+ // give packet socket powers to nodes.
+ packetSocket.Install (stas);
+ packetSocket.Install (ap);
+
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+ Ssid ssid = Ssid ("wifi-default");
+ wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
+ // setup stas.
+ wifiMac.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ staDevs = wifi.Install (wifiPhy, wifiMac, stas);
+ // setup ap.
+ wifiMac.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ wifi.Install (wifiPhy, wifiMac, ap);
+
+ // mobility.
+ mobility.Install (stas);
+ mobility.Install (ap);
+
+ Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0));
+
+ PacketSocketAddress socket;
+ socket.SetSingleDevice(staDevs.Get (0)->GetIfIndex ());
+ socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ());
+ socket.SetProtocol (1);
+
+ OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer apps = onoff.Install (stas.Get (0));
+ apps.Start (Seconds (0.5));
+ apps.Stop (Seconds (43.0));
+
+ Simulator::Stop (Seconds (44.0));
+
+ Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback (&DevTxTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback (&DevRxTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk", MakeCallback (&PhyRxOkTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&PhyRxErrorTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx", MakeCallback (&PhyTxTrace));
+ Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State", MakeCallback (&PhyStateTrace));
+
+ AthstatsHelper athstats;
+ athstats.EnableAthstats("athstats-sta", stas);
+ athstats.EnableAthstats("athstats-ap", ap);
+
+ Simulator::Run ();
+
+ Simulator::Destroy ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-ap.py Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,172 @@
+# -*- Mode: Python; -*-
+# /*
+# * Copyright (c) 2005,2006,2007 INRIA
+# * Copyright (c) 2009 INESC Porto
+# *
+# * This program is free software; you can redistribute it and/or modify
+# * it under the terms of the GNU General Public License version 2 as
+# * published by the Free Software Foundation;
+# *
+# * This program is distributed in the hope that it will be useful,
+# * but WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# * GNU General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public License
+# * along with this program; if not, write to the Free Software
+# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# *
+# * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+# * Gustavo Carneiro <gjc@inescporto.pt>
+# */
+
+import sys
+import ns3
+
+# void
+# DevTxTrace (std::string context, Ptr<const Packet> p, Mac48Address address)
+# {
+# std::cout << " TX to=" << address << " p: " << *p << std::endl;
+# }
+# void
+# DevRxTrace(std::string context, Ptr<const Packet> p, Mac48Address address)
+# {
+# std::cout << " RX from=" << address << " p: " << *p << std::endl;
+# }
+# void
+# PhyRxOkTrace(std::string context, Ptr<const Packet> packet, double snr, WifiMode mode, enum WifiPreamble preamble)
+# {
+# std::cout << "PHYRXOK mode=" << mode << " snr=" << snr << " " << *packet << std::endl;
+# }
+# void
+# PhyRxErrorTrace(std::string context, Ptr<const Packet> packet, double snr)
+# {
+# std::cout << "PHYRXERROR snr=" << snr << " " << *packet << std::endl;
+# }
+# void
+# PhyTxTrace(std::string context, Ptr<const Packet> packet, WifiMode mode, WifiPreamble preamble, uint8_t txPower)
+# {
+# std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;
+# }
+# void
+# PhyStateTrace(std::string context, Time start, Time duration, enum WifiPhy::State state)
+# {
+# std::cout << " state=";
+# switch(state) {
+# case WifiPhy::TX:
+# std::cout << "tx ";
+# break;
+# case WifiPhy::SYNC:
+# std::cout << "sync ";
+# break;
+# case WifiPhy::CCA_BUSY:
+# std::cout << "cca-busy";
+# break;
+# case WifiPhy::IDLE:
+# std::cout << "idle ";
+# break;
+# }
+# std::cout << " start="<<start<<" duration="<<duration<<std::endl;
+# }
+
+def SetPosition(node, position):
+ mobility = node.GetObject(ns3.MobilityModel.GetTypeId())
+ mobility.SetPosition(position)
+
+
+def GetPosition(node):
+ mobility = node.GetObject(ns3.MobilityModel.GetTypeId())
+ return mobility.GetPosition()
+
+def AdvancePosition(node):
+ pos = GetPosition(node);
+ pos.x += 5.0
+ if pos.x >= 210.0:
+ return
+ SetPosition(node, pos)
+ ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, node)
+
+
+def main(argv):
+ ns3.Packet.EnablePrinting();
+
+ # enable rts cts all the time.
+ ns3.Config.SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", ns3.StringValue("0"))
+ # disable fragmentation
+ ns3.Config.SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold", ns3.StringValue("2200"))
+
+ wifi = ns3.WifiHelper.Default()
+ mobility = ns3.MobilityHelper()
+ stas = ns3.NodeContainer()
+ ap = ns3.NodeContainer()
+ #NetDeviceContainer staDevs;
+ packetSocket = ns3.PacketSocketHelper()
+
+ stas.Create(2)
+ ap.Create(1)
+
+ # give packet socket powers to nodes.
+ packetSocket.Install(stas)
+ packetSocket.Install(ap)
+
+ wifiPhy = ns3.YansWifiPhyHelper.Default()
+ wifiChannel = ns3.YansWifiChannelHelper.Default()
+ wifiPhy.SetChannel(wifiChannel.Create())
+
+ ssid = ns3.Ssid("wifi-default")
+ wifi.SetRemoteStationManager("ns3::ArfWifiManager")
+ wifiMac = ns3.NqosWifiMacHelper.Default()
+
+ # setup stas.
+ wifiMac.SetType("ns3::NqstaWifiMac",
+ "Ssid", ns3.SsidValue(ssid),
+ "ActiveProbing", ns3.BooleanValue(False))
+ staDevs = wifi.Install(wifiPhy, wifiMac, stas)
+ # setup ap.
+ wifiMac.SetType("ns3::NqapWifiMac", "Ssid", ns3.SsidValue(ssid),
+ "BeaconGeneration", ns3.BooleanValue(True),
+ "BeaconInterval", ns3.TimeValue(ns3.Seconds(2.5)))
+ wifi.Install(wifiPhy, wifiMac, ap)
+
+ # mobility.
+ mobility.Install(stas)
+ mobility.Install(ap)
+
+ ns3.Simulator.Schedule(ns3.Seconds(1.0), AdvancePosition, ap.Get(0))
+
+ socket = ns3.PacketSocketAddress()
+ socket.SetSingleDevice(staDevs.Get(0).GetIfIndex())
+ socket.SetPhysicalAddress(staDevs.Get(1).GetAddress())
+ socket.SetProtocol(1)
+
+ onoff = ns3.OnOffHelper("ns3::PacketSocketFactory", ns3.Address(socket))
+ onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(42)))
+ onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
+
+ apps = onoff.Install(ns3.NodeContainer(stas.Get(0)))
+ apps.Start(ns3.Seconds(0.5))
+ apps.Stop(ns3.Seconds(43.0))
+
+ ns3.Simulator.Stop(ns3.Seconds(44.0))
+
+ # Config::Connect("/NodeList/*/DeviceList/*/Tx", MakeCallback(&DevTxTrace));
+ # Config::Connect("/NodeList/*/DeviceList/*/Rx", MakeCallback(&DevRxTrace));
+ # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxOk", MakeCallback(&PhyRxOkTrace));
+ # Config::Connect("/NodeList/*/DeviceList/*/Phy/RxError", MakeCallback(&PhyRxErrorTrace));
+ # Config::Connect("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback(&PhyTxTrace));
+ # Config::Connect("/NodeList/*/DeviceList/*/Phy/State", MakeCallback(&PhyStateTrace));
+
+ ascii = ns3.ofstream("wifi-ap.tr")
+ ns3.YansWifiPhyHelper.EnableAsciiAll(ascii)
+
+ ns3.Simulator.Run()
+
+ ns3.Simulator.Destroy()
+ ascii.close()
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-clear-channel-cmu.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,229 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 The Boeing Company
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Guangyu Pei <guangyu.pei@boeing.com>
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+NS_LOG_COMPONENT_DEFINE ("Main");
+
+using namespace ns3;
+
+class Experiment
+{
+public:
+ Experiment ();
+ Experiment (std::string name);
+ uint32_t Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel);
+private:
+ void ReceivePacket (Ptr<Socket> socket);
+ void SetPosition (Ptr<Node> node, Vector position);
+ Vector GetPosition (Ptr<Node> node);
+ Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
+ void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval );
+
+ uint32_t m_pktsTotal;
+ Gnuplot2dDataset m_output;
+};
+
+Experiment::Experiment ()
+{}
+
+Experiment::Experiment (std::string name)
+ : m_output (name)
+{
+ m_output.SetStyle (Gnuplot2dDataset::LINES);
+}
+
+void
+Experiment::SetPosition (Ptr<Node> node, Vector position)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ mobility->SetPosition (position);
+}
+
+Vector
+Experiment::GetPosition (Ptr<Node> node)
+{
+ Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
+ return mobility->GetPosition ();
+}
+
+void
+Experiment::ReceivePacket (Ptr<Socket> socket)
+{
+ Ptr<Packet> packet;
+ while (packet = socket->Recv ())
+ {
+ m_pktsTotal ++;
+ }
+}
+
+Ptr<Socket>
+Experiment::SetupPacketReceive (Ptr<Node> node)
+{
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> sink = Socket::CreateSocket (node, tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
+ sink->Bind (local);
+ sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
+ return sink;
+}
+
+void
+Experiment::GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval )
+{
+ if (pktCount > 0)
+ {
+ socket->Send (Create<Packet> (pktSize));
+ Simulator::Schedule (pktInterval, &Experiment::GenerateTraffic, this,
+ socket, pktSize,pktCount-1, pktInterval);
+ }
+ else
+ {
+ socket->Close ();
+ }
+}
+
+uint32_t
+Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy,
+ const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel)
+{
+ m_pktsTotal = 0;
+
+ NodeContainer c;
+ c.Create (2);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ YansWifiPhyHelper phy = wifiPhy;
+ phy.SetChannel (wifiChannel.Create ());
+
+ NqosWifiMacHelper mac = wifiMac;
+ NetDeviceContainer devices = wifi.Install (phy, mac, c);
+
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (5.0, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (c);
+
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (devices);
+
+ Ptr<Socket> recvSink = SetupPacketReceive (c.Get (0));
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
+ InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
+ source->Connect (remote);
+ uint32_t packetSize = 1014;
+ uint32_t maxPacketCount = 200;
+ Time interPacketInterval = Seconds (1.);
+ Simulator::Schedule (Seconds (1.0), &Experiment::GenerateTraffic,
+ this, source, packetSize, maxPacketCount,interPacketInterval);
+ Simulator::Run ();
+
+ Simulator::Destroy ();
+
+ return m_pktsTotal;
+}
+
+int main (int argc, char *argv[])
+{
+ std::ofstream outfile ("clear-channel.plt");
+ std::vector <std::string> modes;
+
+ modes.push_back ("wifib-1mbs");
+ modes.push_back ("wifib-2mbs");
+ modes.push_back ("wifib-5.5mbs");
+ modes.push_back ("wifib-11mbs");
+ // disable fragmentation
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ Gnuplot gnuplot = Gnuplot ("clear-channel.eps");
+
+ for (uint32_t i = 0; i < modes.size(); i++)
+ {
+ std::cout << modes[i] << std::endl;
+ Gnuplot2dDataset dataset (modes[i]);
+
+ for (double rss = -102.0; rss <= -80.0; rss += 0.5)
+ {
+ Experiment experiment;
+ dataset.SetStyle (Gnuplot2dDataset::LINES);
+
+ WifiHelper wifi;
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+ StringValue (modes[i]));
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode",StringValue(modes[i]),
+ "ControlMode",StringValue(modes[i]));
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ YansWifiChannelHelper wifiChannel ;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
+
+
+ NS_LOG_DEBUG (modes[i]);
+ experiment = Experiment (modes[i]);
+ wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-110.0) );
+ wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-110.0) );
+ wifiPhy.Set ("TxPowerStart", DoubleValue (15.0) );
+ wifiPhy.Set ("RxGain", DoubleValue (0) );
+ wifiPhy.Set ("RxNoiseFigure", DoubleValue (7) );
+ uint32_t pktsRecvd = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
+ dataset.Add (rss, pktsRecvd);
+ }
+
+ gnuplot.AddDataset (dataset);
+ }
+ gnuplot.SetTerminal ("postscript eps color enh \"Times-BoldItalic\"");
+ gnuplot.SetLegend ("RSS(dBm)", "Number of packets received");
+ gnuplot.SetExtra ("set xrange [-102:-83]");
+ gnuplot.GenerateOutput (outfile);
+ outfile.close ();
+
+ return 0;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-simple-adhoc-grid.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,239 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// This program configures a grid (default 5x5) of nodes on an
+// 802.11b physical layer, with
+// 802.11b NICs in adhoc mode, and by default, sends one packet of 1000
+// (application) bytes to node 1.
+//
+// The default layout is like this, on a 2-D grid.
+//
+// n20 n21 n22 n23 n24
+// n15 n16 n17 n18 n19
+// n10 n11 n12 n13 n14
+// n5 n6 n7 n8 n9
+// n0 n1 n2 n3 n4
+//
+// the layout is affected by the parameters given to GridPositionAllocator;
+// by default, GridWidth is 5 and numNodes is 25..
+//
+// There are a number of command-line options available to control
+// the default behavior. The list of available command-line options
+// can be listed with the following command:
+// ./waf --run "scratch/wifi-simple-adhoc-grid --help"
+//
+// Note that all ns-3 attributes (not just the ones exposed in the below
+// script) can be changed at command line; see the ns-3 documentation.
+//
+// For instance, for this configuration, the physical layer will
+// stop successfully receiving packets when distance increases beyond
+// the default of 500m.
+// To see this effect, try running:
+//
+// ./waf --run "scratch/wifi-simple-adhoc --distance=500"
+// ./waf --run "scratch/wifi-simple-adhoc --distance=1000"
+// ./waf --run "scratch/wifi-simple-adhoc --distance=1500"
+//
+// The source node and sink node can be changed like this:
+//
+// ./waf --run "scratch/wifi-simple-adhoc --sourceNode=20 --sinkNode=10"
+//
+// This script can also be helpful to put the Wifi layer into verbose
+// logging mode; this command will turn on all wifi logging:
+//
+// ./waf --run "scratch/wifi-simple-adhoc-grid --verbose=1"
+//
+// By default, trace file writing is off-- to enable it, try:
+// ./waf --run "scratch/wifi-simple-adhoc-grid --tracing=1"
+//
+// When you are done tracing, you will notice many pcap trace files
+// in your directory. If you have tcpdump installed, you can try this:
+//
+// tcpdump -r wifi-simple-adhoc-grid-0-0.pcap -nn -tt
+//
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhocGrid");
+
+using namespace ns3;
+
+void ReceivePacket (Ptr<Socket> socket)
+{
+ NS_LOG_UNCOND ("Received one packet!");
+}
+
+static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval )
+{
+ if (pktCount > 0)
+ {
+ socket->Send (Create<Packet> (pktSize));
+ Simulator::Schedule (pktInterval, &GenerateTraffic,
+ socket, pktSize,pktCount-1, pktInterval);
+ }
+ else
+ {
+ socket->Close ();
+ }
+}
+
+
+int main (int argc, char *argv[])
+{
+ std::string phyMode ("wifib-1mbs");
+ double distance = 500; // m
+ uint32_t packetSize = 1000; // bytes
+ uint32_t numPackets = 1;
+ uint32_t numNodes = 25; // by default, 5x5
+ uint32_t sinkNode = 0;
+ uint32_t sourceNode = 24;
+ double interval = 1.0; // seconds
+ bool verbose = false;
+ bool tracing = false;
+
+ CommandLine cmd;
+
+ cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
+ cmd.AddValue ("distance", "distance (m)", distance);
+ cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
+ cmd.AddValue ("numPackets", "number of packets generated", numPackets);
+ cmd.AddValue ("interval", "interval (seconds) between packets", interval);
+ cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
+ cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
+ cmd.AddValue ("numNodes", "number of nodes", numNodes);
+ cmd.AddValue ("sinkNode", "Receiver node number", sinkNode);
+ cmd.AddValue ("sourceNode", "Sender node number", sourceNode);
+
+ cmd.Parse (argc, argv);
+ // Convert to time object
+ Time interPacketInterval = Seconds (interval);
+
+ // disable fragmentation for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ // turn off RTS/CTS for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+ // Fix non-unicast data rate to be the same as that of unicast
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+ StringValue (phyMode));
+
+ NodeContainer c;
+ c.Create (numNodes);
+
+ // The below set of helpers will help us to put together the wifi NICs we want
+ WifiHelper wifi;
+ if (verbose)
+ {
+ wifi.EnableLogComponents (); // Turn on all Wifi logging
+ }
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ // This is one parameter that matters when using FixedRssLossModel
+ // set it to zero; otherwise, gain will be added
+ wifiPhy.Set ("RxGain", DoubleValue (-10) );
+ // ns-3 support RadioTap and Prism tracing extensions for 802.11b
+ wifiPhy.SetPcapFormat (YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
+
+ YansWifiChannelHelper wifiChannel ;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ // Add a non-QoS upper mac, and disable rate control
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode",StringValue(phyMode),
+ "ControlMode",StringValue(phyMode));
+ // Set it to adhoc mode
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+ NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
+
+ MobilityHelper mobility;
+ mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (0.0),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (distance),
+ "DeltaY", DoubleValue (distance),
+ "GridWidth", UintegerValue (5),
+ "LayoutType", StringValue ("RowFirst"));
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (c);
+
+ // Enable OLSR
+ OlsrHelper olsr;
+ Ipv4StaticRoutingHelper staticRouting;
+
+ Ipv4ListRoutingHelper list;
+ list.Add (staticRouting, 0);
+ list.Add (olsr, 10);
+
+ InternetStackHelper internet;
+ internet.SetRoutingHelper (list);
+ internet.Install (c);
+
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (devices);
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
+ recvSink->Bind (local);
+ recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
+
+ Ptr<Socket> source = Socket::CreateSocket (c.Get (sourceNode), tid);
+ InetSocketAddress remote = InetSocketAddress (i.GetAddress (sinkNode, 0), 80);
+ source->Connect (remote);
+
+ if (tracing == true)
+ {
+ wifiPhy.EnablePcap ("wifi-simple-adhoc-grid", devices);
+ std::ofstream ascii;
+ ascii.open ("wifi-simple-adhoc-grid.tr");
+ YansWifiPhyHelper::EnableAsciiAll (ascii);
+ // To do-- enable an IP-level trace that shows forwarding events only
+ }
+
+ // Give OLSR time to converge-- 30 seconds perhaps
+ Simulator::Schedule (Seconds (30.0), &GenerateTraffic,
+ source, packetSize, numPackets, interPacketInterval);
+
+ // Output what we are doing
+ NS_LOG_UNCOND ("Testing from node " << sourceNode << " to " << sinkNode << " with grid distance " << distance);
+
+ Simulator::Stop (Seconds (32.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-simple-adhoc.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,198 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 The Boeing Company
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// This script configures two nodes on an 802.11b physical layer, with
+// 802.11b NICs in adhoc mode, and by default, sends one packet of 1000
+// (application) bytes to the other node. The physical layer is configured
+// to receive at a fixed RSS (regardless of the distance and transmit
+// power); therefore, changing position of the nodes has no effect.
+//
+// There are a number of command-line options available to control
+// the default behavior. The list of available command-line options
+// can be listed with the following command:
+// ./waf --run "scratch/wifi-simple-adhoc --help"
+//
+// For instance, for this configuration, the physical layer will
+// stop successfully receiving packets when rss drops below -97 dBm.
+// To see this effect, try running:
+//
+// ./waf --run "scratch/wifi-simple-adhoc --rss=-97 --numPackets=20"
+// ./waf --run "scratch/wifi-simple-adhoc --rss=-98 --numPackets=20"
+// ./waf --run "scratch/wifi-simple-adhoc --rss=-99 --numPackets=20"
+//
+// Note that all ns-3 attributes (not just the ones exposed in the below
+// script) can be changed at command line; see the documentation.
+//
+// This script can also be helpful to put the Wifi layer into verbose
+// logging mode; this command will turn on all wifi logging:
+//
+// ./waf --run "scratch/wifi-simple-adhoc --verbose=1"
+//
+// When you are done, you will notice two pcap trace files in your directory.
+// If you have tcpdump installed, you can try this:
+//
+// tcpdump -r wifi-simple-adhoc-0-0.pcap -nn -tt
+//
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");
+
+using namespace ns3;
+
+void ReceivePacket (Ptr<Socket> socket)
+{
+ NS_LOG_UNCOND ("Received one packet!");
+}
+
+static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval )
+{
+ if (pktCount > 0)
+ {
+ socket->Send (Create<Packet> (pktSize));
+ Simulator::Schedule (pktInterval, &GenerateTraffic,
+ socket, pktSize,pktCount-1, pktInterval);
+ }
+ else
+ {
+ socket->Close ();
+ }
+}
+
+
+int main (int argc, char *argv[])
+{
+ std::string phyMode ("wifib-1mbs");
+ double rss = -80; // -dBm
+ uint32_t packetSize = 1000; // bytes
+ uint32_t numPackets = 1;
+ double interval = 1.0; // seconds
+ bool verbose = false;
+
+ CommandLine cmd;
+
+ cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
+ cmd.AddValue ("rss", "received signal strength", rss);
+ cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
+ cmd.AddValue ("numPackets", "number of packets generated", numPackets);
+ cmd.AddValue ("interval", "interval (seconds) between packets", interval);
+ cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
+
+ cmd.Parse (argc, argv);
+ // Convert to time object
+ Time interPacketInterval = Seconds (interval);
+
+ // disable fragmentation for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ // turn off RTS/CTS for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+ // Fix non-unicast data rate to be the same as that of unicast
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+ StringValue (phyMode));
+
+ NodeContainer c;
+ c.Create (2);
+
+ // The below set of helpers will help us to put together the wifi NICs we want
+ WifiHelper wifi;
+ if (verbose)
+ {
+ wifi.EnableLogComponents (); // Turn on all Wifi logging
+ }
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ // This is one parameter that matters when using FixedRssLossModel
+ // set it to zero; otherwise, gain will be added
+ wifiPhy.Set ("RxGain", DoubleValue (0) );
+ // ns-3 support RadioTap and Prism tracing extensions for 802.11b
+ wifiPhy.SetPcapFormat (YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
+
+ YansWifiChannelHelper wifiChannel ;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ // The below FixedRssLossModel will cause the rss to be fixed regardless
+ // of the distance between the two stations, and the transmit power
+ wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ // Add a non-QoS upper mac, and disable rate control
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode",StringValue(phyMode),
+ "ControlMode",StringValue(phyMode));
+ // Set it to adhoc mode
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+ NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
+
+ // Note that with FixedRssLossModel, the positions below are not
+ // used for received signal strength.
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (5.0, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (c);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (devices);
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
+ recvSink->Bind (local);
+ recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
+
+ Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
+ InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
+ source->Connect (remote);
+
+ // Tracing
+ wifiPhy.EnablePcap ("wifi-simple-adhoc", devices);
+
+ // Output what we are doing
+ NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss );
+
+ Simulator::Schedule (Seconds (1.0), &GenerateTraffic,
+ source, packetSize, numPackets, interPacketInterval);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-simple-infra.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,212 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 The Boeing Company
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// This script configures two nodes on an 802.11b physical layer, with
+// 802.11b NICs in infrastructure mode, and by default, the station sends
+// one packet of 1000 (application) bytes to the access point. The
+// physical layer is configured
+// to receive at a fixed RSS (regardless of the distance and transmit
+// power); therefore, changing position of the nodes has no effect.
+//
+// There are a number of command-line options available to control
+// the default behavior. The list of available command-line options
+// can be listed with the following command:
+// ./waf --run "scratch/wifi-simple-infra --help"
+//
+// For instance, for this configuration, the physical layer will
+// stop successfully receiving packets when rss drops below -97 dBm.
+// To see this effect, try running:
+//
+// ./waf --run "scratch/wifi-simple-infra --rss=-97 --numPackets=20"
+// ./waf --run "scratch/wifi-simple-infra --rss=-98 --numPackets=20"
+// ./waf --run "scratch/wifi-simple-infra --rss=-99 --numPackets=20"
+//
+// Note that all ns-3 attributes (not just the ones exposed in the below
+// script) can be changed at command line; see the documentation.
+//
+// This script can also be helpful to put the Wifi layer into verbose
+// logging mode; this command will turn on all wifi logging:
+//
+// ./waf --run "scratch/wifi-simple-infra --verbose=1"
+//
+// When you are done, you will notice two pcap trace files in your directory.
+// If you have tcpdump installed, you can try this:
+//
+// tcpdump -r wifi-simple-infra-0-0.pcap -nn -tt
+//
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+NS_LOG_COMPONENT_DEFINE ("WifiSimpleInfra");
+
+using namespace ns3;
+
+void ReceivePacket (Ptr<Socket> socket)
+{
+ NS_LOG_UNCOND ("Received one packet!");
+}
+
+static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval )
+{
+ if (pktCount > 0)
+ {
+ socket->Send (Create<Packet> (pktSize));
+ Simulator::Schedule (pktInterval, &GenerateTraffic,
+ socket, pktSize,pktCount-1, pktInterval);
+ }
+ else
+ {
+ socket->Close ();
+ }
+}
+
+
+int main (int argc, char *argv[])
+{
+ std::string phyMode ("wifib-1mbs");
+ double rss = -80; // -dBm
+ uint32_t packetSize = 1000; // bytes
+ uint32_t numPackets = 1;
+ double interval = 1.0; // seconds
+ bool verbose = false;
+
+ CommandLine cmd;
+
+ cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
+ cmd.AddValue ("rss", "received signal strength", rss);
+ cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
+ cmd.AddValue ("numPackets", "number of packets generated", numPackets);
+ cmd.AddValue ("interval", "interval (seconds) between packets", interval);
+ cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
+
+ cmd.Parse (argc, argv);
+ // Convert to time object
+ Time interPacketInterval = Seconds (interval);
+
+ // disable fragmentation for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ // turn off RTS/CTS for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+ // Fix non-unicast data rate to be the same as that of unicast
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+ StringValue (phyMode));
+
+ NodeContainer c;
+ c.Create (2);
+
+ // The below set of helpers will help us to put together the wifi NICs we want
+ WifiHelper wifi;
+ if (verbose)
+ {
+ wifi.EnableLogComponents (); // Turn on all Wifi logging
+ }
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ // This is one parameter that matters when using FixedRssLossModel
+ // set it to zero; otherwise, gain will be added
+ wifiPhy.Set ("RxGain", DoubleValue (0) );
+ // ns-3 support RadioTap and Prism tracing extensions for 802.11b
+ wifiPhy.SetPcapFormat (YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
+
+ YansWifiChannelHelper wifiChannel ;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ // The below FixedRssLossModel will cause the rss to be fixed regardless
+ // of the distance between the two stations, and the transmit power
+ wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ // Add a non-QoS upper mac, and disable rate control
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode",StringValue(phyMode),
+ "ControlMode",StringValue(phyMode));
+
+ // Setup the rest of the upper mac
+ Ssid ssid = Ssid ("wifi-default");
+ // setup sta.
+ wifiMac.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMac, c.Get(0));
+ NetDeviceContainer devices = staDevice;
+ // setup ap.
+ wifiMac.SetType ("ns3::NqapWifiMac", "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, c.Get(1));
+ devices.Add (apDevice);
+
+ // Note that with FixedRssLossModel, the positions below are not
+ // used for received signal strength.
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (5.0, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (c);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (devices);
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
+ recvSink->Bind (local);
+ recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
+
+ Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
+ InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
+ source->Connect (remote);
+
+ // Tracing
+ wifiPhy.EnablePcap ("wifi-simple-infra", devices);
+
+ // Output what we are doing
+ NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss );
+
+ Simulator::Schedule (Seconds (1.0), &GenerateTraffic,
+ source, packetSize, numPackets, interPacketInterval);
+
+ Simulator::Stop (Seconds (30.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-simple-interference.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,259 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 The Boeing Company
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+//
+// This script configures three nodes on an 802.11b physical layer, with
+// 802.11b NICs in adhoc mode. There is a transmitter, receiver, and
+// interferer. The transmitter sends one packet to the receiver and
+// the receiver receives it with a certain configurable RSS (by default,
+// -80 dBm). The interferer does not do carrier sense and also sends
+// the packet to interfere with the primary packet. The channel model
+// is clear channel.
+//
+// Therefore, at the receiver, the reception looks like this:
+//
+// ------------------time---------------->
+// t0
+//
+// |------------------------------------|
+// | |
+// | primary received frame (time t0) |
+// | |
+// |------------------------------------|
+//
+//
+// t1
+// |-----------------------------------|
+// | |
+// | interfering frame (time t1) |
+// | |
+// |-----------------------------------|
+//
+// The orientation is:
+// n2 ---------> n0 <---------- n1
+// interferer receiver transmitter
+//
+// The configurable parameters are:
+// - Prss (primary rss) (-80 dBm default)
+// - Irss (interfering rss) (-95 dBm default)
+// - delta (microseconds, (t1-t0), may be negative, default 0)
+// - PpacketSize (primary packet size) (bytes, default 1000)
+// - IpacketSize (interferer packet size) (bytes, default 1000)
+//
+// For instance, for this configuration, the interfering frame arrives
+// at -90 dBm with a time offset of 3.2 microseconds:
+//
+// ./waf --run "scratch/wifi-simple-interference --Irss=-90 --delta=3.2"
+//
+// Note that all ns-3 attributes (not just the ones exposed in the below
+// script) can be changed at command line; see the documentation.
+//
+// This script can also be helpful to put the Wifi layer into verbose
+// logging mode; this command will turn on all wifi logging:
+//
+// ./waf --run "scratch/wifi-simple-interference --verbose=1"
+//
+// When you are done, you will notice a pcap trace file in your directory.
+// If you have tcpdump installed, you can try this:
+//
+// tcpdump -r wifi-simple-interference-0-0.pcap -nn -tt
+// reading from file wifi-simple-interference-0-0.pcap, link-type IEEE802_11_RADIO (802.11 plus BSD radio information header)
+// 10.008704 10008704us tsft 1.0 Mb/s 2437 MHz (0x00c0) -80dB signal -98dB noise IP 10.1.1.2.49153 > 10.1.1.255.80: UDP, length 1000
+//
+// Next, try this command and look at the tcpdump-- you should see two packets
+// that are no longer interfering:
+// ./waf --run "wifi-simple-interference --delta=30000"
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h"
+
+#include <iostream>
+#include <fstream>
+#include <vector>
+#include <string>
+
+NS_LOG_COMPONENT_DEFINE ("WifiSimpleInterference");
+
+using namespace ns3;
+
+void ReceivePacket (Ptr<Socket> socket)
+{
+ Address addr;
+ socket->GetSockName (addr);
+ InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
+ NS_LOG_UNCOND ("Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort ());
+}
+
+static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
+ uint32_t pktCount, Time pktInterval )
+{
+ if (pktCount > 0)
+ {
+ socket->Send (Create<Packet> (pktSize));
+ Simulator::Schedule (pktInterval, &GenerateTraffic,
+ socket, pktSize,pktCount-1, pktInterval);
+ }
+ else
+ {
+ socket->Close ();
+ }
+}
+
+
+int main (int argc, char *argv[])
+{
+// LogComponentEnable ("InterferenceHelper", LOG_LEVEL_ALL);
+
+ std::string phyMode ("wifib-1mbs");
+ double Prss = -80; // -dBm
+ double Irss = -95; // -dBm
+ double delta = 0; // microseconds
+ uint32_t PpacketSize = 1000; // bytes
+ uint32_t IpacketSize = 1000; // bytes
+ bool verbose = false;
+
+ // these are not command line arguments for this version
+ uint32_t numPackets = 1;
+ double interval = 1.0; // seconds
+ double startTime = 10.0; // seconds
+ double distanceToRx = 100.0; // meters
+
+ double offset = 91; // This is a magic number used to set the
+ // transmit power, based on other configuration
+ CommandLine cmd;
+
+ cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
+ cmd.AddValue ("Prss", "Intended primary received signal strength (dBm)", Prss);
+ cmd.AddValue ("Irss", "Intended interfering received signal strength (dBm)", Irss);
+ cmd.AddValue ("delta", "time offset (microseconds) for interfering signal", delta);
+ cmd.AddValue ("PpacketSize", "size of application packet sent", PpacketSize);
+ cmd.AddValue ("IpacketSize", "size of interfering packet sent", IpacketSize);
+ cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
+
+ cmd.Parse (argc, argv);
+ // Convert to time object
+ Time interPacketInterval = Seconds (interval);
+
+ // disable fragmentation for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
+ // turn off RTS/CTS for frames below 2200 bytes
+ Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
+ // Fix non-unicast data rate to be the same as that of unicast
+ Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
+ StringValue (phyMode));
+
+ NodeContainer c;
+ c.Create (3);
+
+ // The below set of helpers will help us to put together the wifi NICs we want
+ WifiHelper wifi;
+ if (verbose)
+ {
+ wifi.EnableLogComponents (); // Turn on all Wifi logging
+ }
+ wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ // This is one parameter that matters when using FixedRssLossModel
+ // set it to zero; otherwise, gain will be added
+ wifiPhy.Set ("RxGain", DoubleValue (0) );
+ wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) );
+
+ // ns-3 support RadioTap and Prism tracing extensions for 802.11b
+ wifiPhy.SetPcapFormat (YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
+
+ YansWifiChannelHelper wifiChannel ;
+ wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
+ wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel");
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ // Add a non-QoS upper mac, and disable rate control
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
+ "DataMode",StringValue(phyMode),
+ "ControlMode",StringValue(phyMode));
+ // Set it to adhoc mode
+ wifiMac.SetType ("ns3::AdhocWifiMac");
+ NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c.Get (0));
+ // This will disable these sending devices from detecting a signal
+ // so that they do not backoff
+ wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (0.0) );
+ wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) );
+ devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
+ wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) );
+ devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (2)));
+
+ // Note that with FixedRssLossModel, the positions below are not
+ // used for received signal strength.
+ MobilityHelper mobility;
+ Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
+ positionAlloc->Add (Vector (0.0, 0.0, 0.0));
+ positionAlloc->Add (Vector (distanceToRx, 0.0, 0.0));
+ positionAlloc->Add (Vector (-1*distanceToRx, 0.0, 0.0));
+ mobility.SetPositionAllocator (positionAlloc);
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (c);
+
+ InternetStackHelper internet;
+ internet.Install (c);
+
+ Ipv4AddressHelper ipv4;
+ NS_LOG_INFO ("Assign IP Addresses.");
+ ipv4.SetBase ("10.1.1.0", "255.255.255.0");
+ Ipv4InterfaceContainer i = ipv4.Assign (devices);
+
+ TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
+ Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
+ InetSocketAddress local = InetSocketAddress (Ipv4Address("10.1.1.1"), 80);
+ recvSink->Bind (local);
+ recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
+
+ Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
+ InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
+ source->Connect (remote);
+
+ // Interferer will send to a different port; we will not see a
+ // "Received packet" message
+ Ptr<Socket> interferer = Socket::CreateSocket (c.Get (2), tid);
+ InetSocketAddress interferingAddr = InetSocketAddress (Ipv4Address ("255.255.255.255"), 49000);
+ interferer->Connect (interferingAddr);
+
+ // Tracing
+ wifiPhy.EnablePcap ("wifi-simple-interference", devices.Get (0));
+
+ // Output what we are doing
+ NS_LOG_UNCOND ("Primary packet RSS=" << Prss << " dBm and interferer RSS=" << Irss << " dBm at time offset=" << delta << " ms");
+
+ Simulator::Schedule (Seconds (startTime), &GenerateTraffic,
+ source, PpacketSize, numPackets, interPacketInterval);
+
+ Simulator::Schedule (Seconds (startTime + delta/1000000.0), &GenerateTraffic,
+ interferer, IpacketSize, numPackets, interPacketInterval);
+
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wifi-wired-bridging.cc Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,197 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+//
+// Default network topology includes some number of AP nodes specified by
+// the variable nWifis (defaults to two). Off of each AP node, there are some
+// number of STA nodes specified by the variable nStas (defaults to two).
+// Each AP talks to its associated STA nodes. There are bridge net devices
+// on each AP node that bridge the whole thing into one network.
+//
+// +-----+ +-----+ +-----+ +-----+
+// | STA | | STA | | STA | | STA |
+// +-----+ +-----+ +-----+ +-----+
+// 192.168.0.3 192.168.0.4 192.168.0.5 192.168.0.6
+// -------- -------- -------- --------
+// WIFI STA WIFI STA WIFI STA WIFI STA
+// -------- -------- -------- --------
+// ((*)) ((*)) | ((*)) ((*))
+// |
+// ((*)) | ((*))
+// ------- -------
+// WIFI AP CSMA ========= CSMA WIFI AP
+// ------- ---- ---- -------
+// ############## ##############
+// BRIDGE BRIDGE
+// ############## ##############
+// 192.168.0.1 192.168.0.2
+// +---------+ +---------+
+// | AP Node | | AP Node |
+// +---------+ +---------+
+//
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/wifi-module.h"
+#include "ns3/node-module.h"
+#include <vector>
+#include <stdint.h>
+#include <sstream>
+#include <fstream>
+
+using namespace ns3;
+
+int main (int argc, char *argv[])
+{
+ uint32_t nWifis = 2;
+ uint32_t nStas = 2;
+ bool sendIp = true;
+
+ CommandLine cmd;
+ cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
+ cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
+ cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
+ cmd.Parse (argc, argv);
+
+ NodeContainer backboneNodes;
+ NetDeviceContainer backboneDevices;
+ Ipv4InterfaceContainer backboneInterfaces;
+ std::vector<NodeContainer> staNodes;
+ std::vector<NetDeviceContainer> staDevices;
+ std::vector<NetDeviceContainer> apDevices;
+ std::vector<Ipv4InterfaceContainer> staInterfaces;
+ std::vector<Ipv4InterfaceContainer> apInterfaces;
+
+ InternetStackHelper stack;
+ CsmaHelper csma;
+ Ipv4AddressHelper ip;
+ ip.SetBase ("192.168.0.0", "255.255.255.0");
+
+ backboneNodes.Create (nWifis);
+ stack.Install (backboneNodes);
+
+ backboneDevices = csma.Install (backboneNodes);
+
+ double wifiX = 0.0;
+
+ YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+ wifiPhy.SetPcapFormat(YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
+
+ for (uint32_t i = 0; i < nWifis; ++i)
+ {
+ // calculate ssid for wifi subnetwork
+ std::ostringstream oss;
+ oss << "wifi-default-" << i;
+ Ssid ssid = Ssid (oss.str ());
+
+ NodeContainer sta;
+ NetDeviceContainer staDev;
+ NetDeviceContainer apDev;
+ Ipv4InterfaceContainer staInterface;
+ Ipv4InterfaceContainer apInterface;
+ MobilityHelper mobility;
+ BridgeHelper bridge;
+ WifiHelper wifi = WifiHelper::Default ();
+ NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+ YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+ wifiPhy.SetChannel (wifiChannel.Create ());
+
+ sta.Create (nStas);
+ mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
+ "MinX", DoubleValue (wifiX),
+ "MinY", DoubleValue (0.0),
+ "DeltaX", DoubleValue (5.0),
+ "DeltaY", DoubleValue (5.0),
+ "GridWidth", UintegerValue (1),
+ "LayoutType", StringValue ("RowFirst"));
+
+
+ // setup the AP.
+ mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+ mobility.Install (backboneNodes.Get (i));
+ wifiMac.SetType ("ns3::NqapWifiMac",
+ "Ssid", SsidValue (ssid),
+ "BeaconGeneration", BooleanValue (true),
+ "BeaconInterval", TimeValue (Seconds (2.5)));
+ apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));
+
+ NetDeviceContainer bridgeDev;
+ bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
+
+ // assign AP IP address to bridge, not wifi
+ apInterface = ip.Assign (bridgeDev);
+
+ // setup the STAs
+ stack.Install (sta);
+ mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
+ "Mode", StringValue ("Time"),
+ "Time", StringValue ("2s"),
+ "Speed", StringValue ("Constant:1.0"),
+ "Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0, (nStas+1)*5.0)));
+ mobility.Install (sta);
+ wifiMac.SetType ("ns3::NqstaWifiMac",
+ "Ssid", SsidValue (ssid),
+ "ActiveProbing", BooleanValue (false));
+ staDev = wifi.Install (wifiPhy, wifiMac, sta);
+ staInterface = ip.Assign (staDev);
+
+ // save everything in containers.
+ staNodes.push_back (sta);
+ apDevices.push_back (apDev);
+ apInterfaces.push_back (apInterface);
+ staDevices.push_back (staDev);
+ staInterfaces.push_back (staInterface);
+
+ wifiX += 20.0;
+ }
+
+ Address dest;
+ std::string protocol;
+ if (sendIp)
+ {
+ dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
+ protocol = "ns3::UdpSocketFactory";
+ }
+ else
+ {
+ PacketSocketAddress tmp;
+ tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
+ tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
+ tmp.SetProtocol (0x807);
+ dest = tmp;
+ protocol = "ns3::PacketSocketFactory";
+ }
+
+ OnOffHelper onoff = OnOffHelper (protocol, dest);
+ onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
+ apps.Start (Seconds (0.5));
+ apps.Stop (Seconds (3.0));
+
+ wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
+ wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);
+
+ std::ofstream os;
+ os.open ("wifi-wired-bridging.mob");
+ MobilityHelper::EnableAsciiAll (os);
+
+ Simulator::Stop (Seconds (100.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/wireless/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -0,0 +1,36 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('mixed-wireless', ['core', 'simulator', 'mobility', 'wifi', 'point-to-point',
+ 'internet-stack'])
+ obj.source = 'mixed-wireless.cc'
+
+ obj = bld.create_ns3_program('wifi-adhoc', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-adhoc.cc'
+
+ obj = bld.create_ns3_program('wifi-clear-channel-cmu', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-clear-channel-cmu.cc'
+
+ obj = bld.create_ns3_program('wifi-ap', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-ap.cc'
+
+ obj = bld.create_ns3_program('wifi-wired-bridging', ['core', 'simulator', 'mobility', 'wifi', 'csma', 'helper', 'bridge'])
+ obj.source = 'wifi-wired-bridging.cc'
+
+ obj = bld.create_ns3_program('simple-wifi-frame-aggregation', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'simple-wifi-frame-aggregation.cc'
+
+ obj = bld.create_ns3_program('multirate', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'multirate.cc'
+
+ obj = bld.create_ns3_program('wifi-simple-adhoc', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-simple-adhoc.cc'
+
+ obj = bld.create_ns3_program('wifi-simple-adhoc-grid', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-simple-adhoc-grid.cc'
+
+ obj = bld.create_ns3_program('wifi-simple-infra', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-simple-infra.cc'
+
+ obj = bld.create_ns3_program('wifi-simple-interference', ['core', 'simulator', 'mobility', 'wifi'])
+ obj.source = 'wifi-simple-interference.cc'
--- a/examples/wscript Mon Oct 05 15:32:12 2009 +0100
+++ b/examples/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -1,205 +1,21 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
- obj = bld.create_ns3_program('hello-simulator')
- obj.source = 'hello-simulator.cc'
-
- obj = bld.create_ns3_program('first',
- ['core', 'simulator', 'point-to-point', 'internet-stack'])
- obj.source = 'first.cc'
-
- obj = bld.create_ns3_program('second',
- ['core', 'simulator', 'point-to-point', 'csma', 'internet-stack'])
- obj.source = 'second.cc'
-
- obj = bld.create_ns3_program('third',
- ['core', 'simulator', 'point-to-point', 'csma', 'wifi', 'internet-stack'])
- obj.source = 'third.cc'
-
- obj = bld.create_ns3_program('object-names',
- ['core', 'simulator', 'csma', 'internet-stack'])
- obj.source = 'object-names.cc'
-
- obj = bld.create_ns3_program('mixed-wireless',
- ['core', 'simulator', 'mobility', 'wifi', 'point-to-point', 'internet-stack'])
- obj.source = 'mixed-wireless.cc'
-
- obj = bld.create_ns3_program('dynamic-global-routing',
- ['point-to-point', 'csma', 'internet-stack', 'global-routing'])
- obj.source = 'dynamic-global-routing.cc'
-
- obj = bld.create_ns3_program('static-routing-slash32',
- ['point-to-point', 'internet-stack', 'global-routing'])
- obj.source = 'static-routing-slash32.cc'
-
- obj = bld.create_ns3_program('global-routing-slash32',
- ['point-to-point', 'internet-stack', 'global-routing'])
- obj.source = 'global-routing-slash32.cc'
-
- obj = bld.create_ns3_program('global-injection-slash32',
- ['point-to-point', 'internet-stack', 'global-routing'])
- obj.source = 'global-injection-slash32.cc'
-
- obj = bld.create_ns3_program('simple-global-routing',
- ['point-to-point', 'internet-stack', 'global-routing'])
- obj.source = 'simple-global-routing.cc'
-
- obj = bld.create_ns3_program('virtual-net-device',
- ['point-to-point', 'internet-stack', 'global-routing', 'virtual-net-device'])
- obj.source = 'virtual-net-device.cc'
-
- obj = bld.create_ns3_program('simple-alternate-routing',
- ['point-to-point', 'internet-stack', 'global-routing'])
- obj.source = 'simple-alternate-routing.cc'
-
- obj = bld.create_ns3_program('simple-error-model',
- ['point-to-point', 'internet-stack'])
- obj.source = 'simple-error-model.cc'
-
- obj = bld.create_ns3_program('csma-one-subnet',
- ['csma', 'internet-stack'])
- obj.source = 'csma-one-subnet.cc'
-
- obj = bld.create_ns3_program('csma-bridge',
- ['bridge', 'csma', 'internet-stack'])
- obj.source = 'csma-bridge.cc'
-
- obj = bld.create_ns3_program('csma-bridge-one-hop',
- ['bridge', 'csma', 'internet-stack'])
- obj.source = 'csma-bridge-one-hop.cc'
-
- obj = bld.create_ns3_program('udp-echo',
- ['csma', 'internet-stack'])
- obj.source = 'udp-echo.cc'
-
- obj = bld.create_ns3_program('realtime-udp-echo',
- ['csma', 'internet-stack'])
- obj.source = 'realtime-udp-echo.cc'
-
- obj = bld.create_ns3_program('csma-broadcast',
- ['csma', 'internet-stack'])
- obj.source = 'csma-broadcast.cc'
-
- obj = bld.create_ns3_program('csma-packet-socket',
- ['csma', 'internet-stack'])
- obj.source = 'csma-packet-socket.cc'
-
- obj = bld.create_ns3_program('csma-multicast',
- ['csma', 'internet-stack'])
- obj.source = 'csma-multicast.cc'
-
- obj = bld.create_ns3_program( 'mixed-global-routing',
- ['point-to-point', 'internet-stack', 'global-routing' , 'csma-cd'])
- obj.source = 'mixed-global-routing.cc'
-
- obj = bld.create_ns3_program('simple-point-to-point-olsr',
- ['point-to-point', 'internet-stack', 'olsr'])
- obj.source = 'simple-point-to-point-olsr.cc'
-
- obj = bld.create_ns3_program('nix-simple',
- ['point-to-point', 'internet-stack', 'nix-vector-routing'])
- obj.source = 'nix-simple.cc'
-
- obj = bld.create_ns3_program('nms-p2p-nix',
- ['point-to-point', 'internet-stack', 'nix-vector-routing'])
- obj.source = 'nms-p2p-nix.cc'
-
- obj = bld.create_ns3_program('tcp-large-transfer',
- ['point-to-point', 'internet-stack'])
- obj.source = 'tcp-large-transfer.cc'
-
- obj = bld.create_ns3_program('tcp-nsc-lfn',
- ['point-to-point', 'internet-stack'])
- obj.source = 'tcp-nsc-lfn.cc'
-
- obj = bld.create_ns3_program('tcp-nsc-zoo',
- ['csma', 'internet-stack'])
- obj.source = 'tcp-nsc-zoo.cc'
-
- obj = bld.create_ns3_program('tcp-star-server',
- ['point-to-point', 'internet-stack'])
- obj.source = 'tcp-star-server.cc'
-
- obj = bld.create_ns3_program('star',
- ['point-to-point', 'internet-stack'])
- obj.source = 'star.cc'
-
- obj = bld.create_ns3_program('csma-star',
- ['csma', 'internet-stack'])
- obj.source = 'csma-star.cc'
-
- obj = bld.create_ns3_program('wifi-adhoc',
- ['core', 'simulator', 'mobility', 'wifi'])
- obj.source = 'wifi-adhoc.cc'
-
- obj = bld.create_ns3_program('wifi-clear-channel-cmu',
- ['core', 'simulator', 'mobility', 'wifi'])
- obj.source = 'wifi-clear-channel-cmu.cc'
-
- obj = bld.create_ns3_program('wifi-ap',
- ['core', 'simulator', 'mobility', 'wifi'])
- obj.source = 'wifi-ap.cc'
-
- obj = bld.create_ns3_program('mesh',
- ['core', 'simulator', 'mobility', 'wifi', 'mesh'])
- obj.source = 'mesh.cc'
-
- bld.add_subdirs('stats')
-
- obj = bld.create_ns3_program('wifi-wired-bridging',
- ['core', 'simulator', 'mobility', 'wifi',
- 'csma', 'helper', 'bridge'])
- obj.source = 'wifi-wired-bridging.cc'
-
- obj = bld.create_ns3_program('csma-raw-ip-socket',
- ['csma', 'internet-stack'])
- obj.source = 'csma-raw-ip-socket.cc'
-
- obj = bld.create_ns3_program('csma-ping',
- ['csma', 'internet-stack', 'v4ping'])
- obj.source = 'csma-ping.cc'
-
- obj = bld.create_ns3_program('test-ipv6',
- ['point-to-point', 'internet-stack'])
- obj.source = 'test-ipv6.cc'
-
- obj = bld.create_ns3_program('ping6',
- ['csma', 'internet-stack'])
- obj.source = 'ping6.cc'
-
- obj = bld.create_ns3_program('simple-routing-ping6',
- ['csma', 'internet-stack'])
- obj.source = 'simple-routing-ping6.cc'
-
- obj = bld.create_ns3_program('icmpv6-redirect',
- ['csma', 'internet-stack'])
- obj.source = 'icmpv6-redirect.cc'
-
- obj = bld.create_ns3_program('radvd',
- ['csma', 'internet-stack'])
- obj.source = 'radvd.cc'
-
- obj = bld.create_ns3_program('radvd-two-prefix',
- ['csma', 'internet-stack'])
- obj.source = 'radvd-two-prefix.cc'
-
env = bld.env_of_name('default')
- if env['ENABLE_EMU']:
- obj = bld.create_ns3_program('emu-udp-echo', ['emu', 'internet-stack'])
- obj.source = 'emu-udp-echo.cc'
-
- obj = bld.create_ns3_program('emu-ping', ['emu', 'internet-stack'])
- obj.source = 'emu-ping.cc'
-
- if env['ENABLE_TAP']:
- obj = bld.create_ns3_program('tap-wifi-dumbbell',
- ['wifi', 'csma', 'point-to-point', 'tap-bridge', 'internet-stack'])
- obj.source = 'tap-wifi-dumbbell.cc'
-
- obj = bld.create_ns3_program('simple-wifi-frame-aggregation',
- ['core', 'simulator', 'mobility', 'wifi'])
- obj.source = 'simple-wifi-frame-aggregation.cc'
-
- obj = bld.create_ns3_program('multirate',
- ['core', 'simulator', 'mobility', 'wifi'])
- obj.source = 'multirate.cc'
+ if env['ENABLE_EXAMPLES']:
+ bld.add_subdirs('csma')
+ bld.add_subdirs('emulation')
+ bld.add_subdirs('error-model')
+ bld.add_subdirs('flowmon')
+ bld.add_subdirs('ipv6')
+ bld.add_subdirs('mesh')
+ bld.add_subdirs('naming')
+ bld.add_subdirs('realtime')
+ bld.add_subdirs('routing')
+ bld.add_subdirs('stats')
+ bld.add_subdirs('tap')
+ bld.add_subdirs('tcp')
+ bld.add_subdirs('tunneling')
+ bld.add_subdirs('tutorial')
+ bld.add_subdirs('udp')
+ bld.add_subdirs('wireless')
--- a/regression/tests/test-csma-bridge.py Mon Oct 05 15:32:12 2009 +0100
+++ b/regression/tests/test-csma-bridge.py Tue Oct 06 19:34:29 2009 -0700
@@ -11,4 +11,4 @@
else:
return "Python bindings not available."
-pyscript = os.path.join('examples', 'csma-bridge.py')
+pyscript = os.path.join('examples/csma', 'csma-bridge.py')
--- a/samples/wscript Mon Oct 05 15:32:12 2009 +0100
+++ b/samples/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -1,6 +1,10 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
+ env = bld.env_of_name('default')
+ if not env['ENABLE_EXAMPLES']:
+ return;
+
obj = bld.create_ns3_program('main-attribute-value')
obj.source = 'main-attribute-value.cc'
--- a/src/test/ns3wifi/wifi-interference-test-suite.cc Mon Oct 05 15:32:12 2009 +0100
+++ b/src/test/ns3wifi/wifi-interference-test-suite.cc Tue Oct 06 19:34:29 2009 -0700
@@ -209,7 +209,7 @@
Config::Connect ("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/EndSync", MakeCallback (&WifiInterferenceTestCase::PrintEndSync, this));
// Tracing
- wifiPhy.EnablePcap ("wifi-simple-interference", devices.Get (0));
+// wifiPhy.EnablePcap ("wifi-simple-interference", devices.Get (0));
Simulator::Schedule (Seconds (startTime), &GenerateTraffic,
source, PpacketSize, numPackets, interPacketInterval);
--- a/test.py Mon Oct 05 15:32:12 2009 +0100
+++ b/test.py Tue Oct 06 19:34:29 2009 -0700
@@ -43,10 +43,17 @@
"NS3_MODULE_PATH",
"ENABLE_NSC",
"ENABLE_REAL_TIME",
+ "ENABLE_EXAMPLES",
]
ENABLE_NSC = False
ENABLE_REAL_TIME = False
+ENABLE_EXAMPLES = True
+
+#
+# If the user has constrained us to run certain kinds of tests, we can tell waf
+# to only build
+core_kinds = ["bvt", "core", "system", "unit"]
#
# A list of examples to run as smoke tests just to ensure that they remain
@@ -57,51 +64,76 @@
# hardcoded.
#
example_tests = [
- ("csma-bridge", "True"),
- ("csma-bridge-one-hop", "True"),
- ("csma-broadcast", "True"),
- ("csma-multicast", "True"),
- ("csma-one-subnet", "True"),
- ("csma-packet-socket", "True"),
- ("csma-ping", "True"),
- ("csma-raw-ip-socket", "True"),
- ("csma-star", "True"),
- ("dynamic-global-routing", "True"),
- ("first", "True"),
- ("global-injection-slash32", "True"),
- ("global-routing-slash32", "True"),
- ("hello-simulator", "True"),
- ("icmpv6-redirect", "True"),
- ("mesh", "True"),
- ("mixed-global-routing", "True"),
- ("mixed-wireless", "True"),
- ("multirate", "False"), # takes forever to run
- ("nix-simple", "True"),
- ("nms-p2p-nix", "False"), # takes forever to run
- ("object-names", "True"),
- ("ping6", "True"),
- ("radvd", "True"),
- ("radvd-two-prefix", "True"),
- ("realtime-udp-echo", "ENABLE_REAL_TIME == True"),
- ("second", "True"),
- ("simple-alternate-routing", "True"),
- ("simple-error-model", "True"),
- ("simple-global-routing", "True"),
- ("simple-point-to-point-olsr", "True"),
- ("simple-routing-ping6", "True"),
- ("simple-wifi-frame-aggregation", "True"),
- ("star", "True"),
- ("static-routing-slash32", "True"),
- ("tcp-large-transfer", "True"),
- ("tcp-nsc-zoo", "ENABLE_NSC == True"),
- ("tcp-star-server", "True"),
- ("test-ipv6", "True"),
- ("third", "True"),
- ("udp-echo", "True"),
- ("virtual-net-device", "True"),
- ("wifi-adhoc", "False"), # takes forever to run
- ("wifi-ap --verbose=0", "True"), # don't let it spew
- ("wifi-wired-bridging", "True"),
+ ("csma/csma-bridge", "True"),
+ ("csma/csma-bridge-one-hop", "True"),
+ ("csma/csma-broadcast", "True"),
+ ("csma/csma-multicast", "True"),
+ ("csma/csma-one-subnet", "True"),
+ ("csma/csma-packet-socket", "True"),
+ ("csma/csma-ping", "True"),
+ ("csma/csma-raw-ip-socket", "True"),
+ ("csma/csma-star", "True"),
+
+ ("emulation/emu-ping", "False"),
+ ("emulation/emu-udp-echo", "False"),
+
+ ("error-model/simple-error-model", "True"),
+
+ ("ipv6/icmpv6-redirect", "True"),
+ ("ipv6/ping6", "True"),
+ ("ipv6/radvd", "True"),
+ ("ipv6/radvd-two-prefix", "True"),
+ ("ipv6/test-ipv6", "True"),
+
+ ("mesh/mesh", "True"),
+
+ ("naming/object-names", "True"),
+
+ ("realtime/realtime-udp-echo", "ENABLE_REAL_TIME == True"),
+
+ ("routing/dynamic-global-routing", "True"),
+ ("routing/global-injection-slash32", "True"),
+ ("routing/global-routing-slash32", "True"),
+ ("routing/mixed-global-routing", "True"),
+ ("routing/nix-simple", "True"),
+ ("routing/nms-p2p-nix", "False"), # Takes too long to run
+ ("routing/simple-alternate-routing", "True"),
+ ("routing/simple-global-routing", "True"),
+ ("routing/simple-point-to-point-olsr", "True"),
+ ("routing/simple-routing-ping6", "True"),
+ ("routing/static-routing-slash32", "True"),
+
+ ("stats/wifi-example-sim", "True"),
+
+ ("tap/tap-wifi-dumbbell", "False"), # Requires manual configuration
+
+ ("tcp/star", "True"),
+ ("tcp/tcp-star-server", "True"),
+ ("tcp/tcp-large-transfer", "True"),
+ ("tcp/tcp-nsc-lfn", "ENABLE_NSC == True"),
+ ("tcp/tcp-nsc-zoo", "ENABLE_NSC == True"),
+ ("tcp/tcp-star-server", "True"),
+
+ ("tunneling/virtual-net-device", "True"),
+
+ ("tutorial/first", "True"),
+ ("tutorial/hello-simulator", "True"),
+ ("tutorial/second", "True"),
+ ("tutorial/third", "True"),
+
+ ("udp/udp-echo", "True"),
+
+ ("wireless/mixed-wireless", "True"),
+ ("wireless/multirate", "False"), # Takes too long to run
+ ("wireless/simple-wifi-frame-aggregation", "True"),
+ ("wireless/wifi-adhoc", "False"), # Takes too long to run
+ ("wireless/wifi-ap --verbose=0", "True"), # Don't let it spew to stdout
+ ("wireless/wifi-clear-channel-cmu", "False"), # Requires specific hardware
+ ("wireless/wifi-simple-adhoc", "True"),
+ ("wireless/wifi-simple-adhoc-grid", "True"),
+ ("wireless/wifi-simple-infra", "True"),
+ ("wireless/wifi-simple-interference", "True"),
+ ("wireless/wifi-wired-bridging", "True"),
]
#
@@ -667,10 +699,28 @@
def run_tests():
#
# Run waf to make sure that everything is built, configured and ready to go
- # unless we are explicitly told not to.
+ # unless we are explicitly told not to. We want to be careful about causing
+ # our users pain while waiting for extraneous stuff to compile and link, so
+ # we allow users that know what they''re doing to not invoke waf at all.
#
- if options.nowaf == False:
- proc = subprocess.Popen("./waf", shell=True)
+ if not options.nowaf:
+
+ #
+ # If the user is running the "kinds" or "list" options, there is an
+ # implied dependency on the test-runner since we call that program
+ # if those options are selected. We will exit after processing those
+ # options, so if we see them, we can safely only build the test-runner.
+ #
+ # If the user has constrained us to running only a particular type of
+ # file, we can only ask waf to build what we know will be necessary.
+ # For example, if the user only wants to run BVT tests, we only have
+ # to build the test-runner and can ignore all of the examples.
+ #
+ if options.kinds or options.list or (len(options.constrain) and options.constrain in core_kinds):
+ proc = subprocess.Popen("./waf --target=test-runner", shell=True)
+ else:
+ proc = subprocess.Popen("./waf", shell=True)
+
proc.communicate()
#
@@ -746,9 +796,10 @@
# This translates into allowing the following options with respect to the
# suites
#
- # ./test,py: run all of the suites
+ # ./test,py: run all of the suites and examples
+ # ./test.py --constrain=core: run all of the suites of all kinds
# ./test.py --constrain=unit: run all unit suites
- # ./test,py --suite=some-test-suite: run the single suite
+ # ./test,py --suite=some-test-suite: run a single suite
# ./test,py --example=udp-echo: run no test suites
# ./test,py --suite=some-suite --example=some-example: run the single suite
#
@@ -873,7 +924,7 @@
#
# ./test,py: run all of the examples
# ./test.py --constrain=unit run no examples
- # ./test.py --constrain=example run all of the examples
+ # ./test.py --constrain=example run all of the examples
# ./test,py --suite=some-test-suite: run no examples
# ./test,py --example=some-example: run the single example
# ./test,py --suite=some-suite --example=some-example: run the single example
@@ -883,22 +934,23 @@
#
if len(options.suite) == 0 and len(options.example) == 0:
if len(options.constrain) == 0 or options.constrain == "example":
- for test, condition in example_tests:
- if eval(condition) == True:
- job = Job()
- job.set_is_example(True)
- job.set_display_name(test)
- job.set_tmp_file_name("")
- job.set_cwd(TMP_TRACES_DIR)
- job.set_basedir(os.getcwd())
- job.set_shell_command("examples/%s" % test)
+ if ENABLE_EXAMPLES:
+ for test, condition in example_tests:
+ if eval(condition) == True:
+ job = Job()
+ job.set_is_example(True)
+ job.set_display_name(test)
+ job.set_tmp_file_name("")
+ job.set_cwd(TMP_TRACES_DIR)
+ job.set_basedir(os.getcwd())
+ job.set_shell_command("examples/%s" % test)
- if options.verbose:
- print "Queue %s" % test
+ if options.verbose:
+ print "Queue %s" % test
- input_queue.put(job)
- jobs = jobs + 1
- total_tests = total_tests + 1
+ input_queue.put(job)
+ jobs = jobs + 1
+ total_tests = total_tests + 1
elif len(options.example):
#
--- a/utils/test-runner.cc Mon Oct 05 15:32:12 2009 +0100
+++ b/utils/test-runner.cc Tue Oct 06 19:34:29 2009 -0700
@@ -133,10 +133,11 @@
// enum defined in test.h converted to lower case.
//
std::cout << " bvt: Build Verification Tests (to see if build completed successfully)" << std::endl;
- std::cout << " unit: Unit Tests (within modules to check basic functionality)" << std::endl;
- std::cout << " system: System Tests (spans modules to check integration of modules)" << std::endl;
+ std::cout << " core: Run all TestSuite-based tests (exclude examples)" << std::endl;
std::cout << " example: Examples (to see if example programs run successfully)" << std::endl;
std::cout << " performance: Performance Tests (check to see if the system is as fast as expected)" << std::endl;
+ std::cout << " system: System Tests (spans modules to check integration of modules)" << std::endl;
+ std::cout << " unit: Unit Tests (within modules to check basic functionality)" << std::endl;
return false;
}
@@ -153,9 +154,10 @@
TestSuite *suite = TestRunner::GetTestSuite (i);
//
- // Filter the tests listed by type if requested.
+ // Filter the tests listed by type if requested. The special typeName
+ // "core" means any TestSuite.
//
- if (haveType)
+ if (haveType && typeName != "core")
{
TestSuite::TestType type = suite->GetTestType ();
if (typeName == "bvt" && type != TestSuite::BVT)
--- a/wscript Mon Oct 05 15:32:12 2009 +0100
+++ b/wscript Tue Oct 06 19:34:29 2009 -0700
@@ -173,6 +173,13 @@
help=('Use sudo to setup suid bits on ns3 executables.'),
dest='enable_sudo', action='store_true',
default=False)
+ opt.add_option('--enable-examples',
+ help=('Build the ns-3 examples and samples.'),
+ dest='enable_examples', action='store_true',
+ default=True)
+ opt.add_option('--disable-examples',
+ help=('Do not build the ns-3 examples and samples.'),
+ dest='enable_examples', action='store_false')
opt.add_option('--regression',
help=("Enable regression testing; only used for the 'check' target"),
default=False, dest='regression', action="store_true")
@@ -324,6 +331,16 @@
conf.report_optional_feature("ENABLE_SUDO", "Use sudo to set suid bit", env['ENABLE_SUDO'], why_not_sudo)
+ if Options.options.enable_examples:
+ env['ENABLE_EXAMPLES'] = True
+ why_not_examples = "defaults to enabled"
+ else:
+ env['ENABLE_EXAMPLES'] = False
+ why_not_examples = "option --disable-examples selected"
+
+ conf.report_optional_feature("ENABLE_EXAMPLES", "Build examples and samples", env['ENABLE_EXAMPLES'],
+ why_not_examples)
+
# we cannot pull regression traces without mercurial
conf.find_program('hg', var='MERCURIAL')
@@ -482,7 +499,9 @@
# process subfolders from here
bld.add_subdirs('src')
- bld.add_subdirs('samples utils examples')
+ bld.add_subdirs('samples')
+ bld.add_subdirs('utils')
+ bld.add_subdirs('examples')
add_scratch_programs(bld)
@@ -564,7 +583,12 @@
if not regression_traces:
raise Utils.WafError("Cannot run regression tests: reference traces directory not given"
" (--with-regression-traces configure option)")
- regression.run_regression(bld, regression_traces)
+
+ if env['ENABLE_EXAMPLES'] == True:
+ regression.run_regression(bld, regression_traces)
+ else:
+ raise Utils.WafError("Cannot run regression tests: building the ns-3 examples is not enabled"
+ " (regression tests are based on examples)")
# if Options.options.check:
# Options.options.compile_targets += ',run-tests'