39 #include <ns3/core-module.h>
40 #include <ns3/csma-module.h>
41 #include <ns3/internet-apps-module.h>
42 #include <ns3/internet-module.h>
43 #include <ns3/network-module.h>
44 #include <ns3/ofswitch13-module.h>
45 #include <ns3/tap-bridge-module.h>
50 main(
int argc,
char* argv[])
52 uint16_t simTime = 100;
55 uint16_t numHosts = 20;
56 uint16_t numSwitches = 3;
57 uint16_t numPings = 20;
58 uint16_t pingTime = 10;
62 cmd.AddValue(
"simTime",
"Simulation time (seconds)", simTime);
63 cmd.AddValue(
"verbose",
"Enable verbose output",
verbose);
64 cmd.AddValue(
"trace",
"Enable datapath stats and pcap traces", trace);
65 cmd.AddValue(
"numHosts",
"Number of hosts in the simulation", numHosts);
66 cmd.AddValue(
"numSwitches",
"Number of switches in the simulation", numSwitches);
67 cmd.AddValue(
"numPings",
"Number of ping apps int the simulation", numPings);
68 cmd.AddValue(
"pingTime",
"Ping time (seconds)", pingTime);
69 cmd.Parse(argc, argv);
97 switches.
Create(numSwitches);
108 for (
int i = 0; i < numSwitches; i++)
114 for (
size_t i = 0; i < numHosts; i++)
116 int j = i % numSwitches;
118 pairDevs = csmaHelper.
Install(pair);
119 hostDevices.
Add(pairDevs.
Get(0));
120 switchPorts[j].
Add(pairDevs.
Get(1));
124 for (
int i = 0; i < numSwitches - 1; i++)
127 pairDevs = csmaHelper.
Install(pair);
128 switchPorts[i].
Add(pairDevs.
Get(0));
129 switchPorts[i + 1].
Add(pairDevs.
Get(1));
133 Ptr<Node> controllerNode = CreateObject<Node>();
137 Ptr<NetDevice> ctrlDev = of13Helper->InstallExternalController(controllerNode);
138 for (
int i = 0; i < numSwitches; i++)
140 of13Helper->InstallSwitch(switches.
Get(i), switchPorts[i]);
142 of13Helper->CreateOpenFlowChannels();
149 tapBridge.
Install(controllerNode, ctrlDev);
158 ipv4helpr.
SetBase(
"10.1.1.0",
"255.255.255.0");
159 hostIpIfaces = ipv4helpr.
Assign(hostDevices);
171 for (
int i = 0; i < numPings; i++)
177 pingHelper.SetAttribute(
"VerboseMode",
EnumValue(Ping::VerboseMode::VERBOSE));
188 of13Helper->EnableOpenFlowPcap(
"openflow");
189 of13Helper->EnableDatapathStats(
"switch-stats");
191 for (
int i = 0; i < numSwitches; i++)
193 csmaHelper.
EnablePcap(
"switch", switchPorts[i],
true);
void SetStopTime(Time stop)
Specify application stop time.
void SetStartTime(Time start)
Specify application start time.
AttributeValue implementation for Boolean.
Parse command-line arguments.
build a set of CsmaNetDevice objects
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold variables of type enum.
double GetValue(double mean, double bound)
Get the next random value drawn from the distribution.
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static void EnableDatapathLogs(std::string prefix="", bool explicitFilename=false)
Enable OpenFlow datapath logs at all OpenFlow switch devices on the simulation.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Create a ping application and associate it to a node.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
build TapBridge to allow ns-3 simulations to interact with Linux tap devices and processes on the Lin...
Ptr< NetDevice > Install(Ptr< Node > node, Ptr< NetDevice > nd)
This method installs a TapBridge on the specified Node and forms the bridge with the NetDevice specif...
void SetAttribute(std::string n1, const AttributeValue &v1)
Set an attribute in the underlying TapBridge net device when these devices are automatically created.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
@ LOG_LEVEL_ALL
Print everything.