44 #include <ns3/applications-module.h>
45 #include <ns3/core-module.h>
46 #include <ns3/csma-module.h>
47 #include <ns3/internet-module.h>
48 #include <ns3/mobility-module.h>
49 #include <ns3/netanim-module.h>
50 #include <ns3/network-module.h>
51 #include <ns3/ofswitch13-module.h>
56 main(
int argc,
char* argv[])
59 uint16_t simTime = 10;
65 cmd.AddValue(
"clients",
"Number of client nodes", clients);
66 cmd.AddValue(
"simTime",
"Simulation time (seconds)", simTime);
67 cmd.AddValue(
"verbose",
"Enable verbose output",
verbose);
68 cmd.AddValue(
"trace",
"Enable datapath stats and pcap traces", trace);
69 cmd.Parse(argc, argv);
107 controllerNodes.
Create(2);
108 clientNodes.
Create(clients);
112 listPosAllocator = CreateObject<ListPositionAllocator>();
113 listPosAllocator->Add(Vector(0, 0, 0));
114 listPosAllocator->Add(Vector(0, 75, 0));
115 listPosAllocator->Add(Vector(50, 50, 0));
116 listPosAllocator->Add(Vector(100, 50, 0));
117 listPosAllocator->Add(Vector(150, 50, 0));
118 listPosAllocator->Add(Vector(75, 25, 0));
119 listPosAllocator->Add(Vector(150, 25, 0));
120 for (
size_t i = 0; i < clients; i++)
122 listPosAllocator->Add(Vector(200, 25 * i, 0));
143 switch0Ports.
Add(link.
Get(0));
144 switch1Ports.
Add(link.
Get(1));
147 switch0Ports.
Add(link.
Get(0));
148 switch1Ports.
Add(link.
Get(1));
155 switch1Ports.
Add(link.
Get(0));
156 switch2Ports.
Add(link.
Get(1));
160 serverDevices.
Add(link.
Get(0));
161 switch0Ports.
Add(link.
Get(1));
164 serverDevices.
Add(link.
Get(0));
165 switch0Ports.
Add(link.
Get(1));
168 for (
size_t i = 0; i < clients; i++)
171 clientDevices.
Add(link.
Get(0));
172 switch2Ports.
Add(link.
Get(1));
179 ofQosHelper->InstallController(controllerNodes.
Get(0), qosCtrl);
184 ofLearningHelper->InstallController(controllerNodes.
Get(1), learnCtrl);
188 ofSwitchDevices.
Add(ofQosHelper->InstallSwitch(switchNodes.
Get(0), switch0Ports));
189 ofSwitchDevices.
Add(ofQosHelper->InstallSwitch(switchNodes.
Get(1), switch1Ports));
190 ofQosHelper->CreateOpenFlowChannels();
193 ofSwitchDevices.
Add(ofLearningHelper->InstallSwitch(switchNodes.
Get(2), switch2Ports));
194 ofLearningHelper->CreateOpenFlowChannels();
204 ipv4switches.
SetBase(
"10.1.0.0",
"255.255.0.0",
"0.0.1.2");
205 internetIpIfaces = ipv4switches.
Assign(serverDevices);
206 ipv4switches.
SetBase(
"10.1.0.0",
"255.255.0.0",
"0.0.2.1");
207 internetIpIfaces = ipv4switches.
Assign(clientDevices);
230 for (appIt = senderApps.
Begin(); appIt != senderApps.
End(); ++appIt)
238 ofLearningHelper->EnableOpenFlowPcap(
"openflow");
239 ofLearningHelper->EnableDatapathStats(
"switch-stats");
240 ofQosHelper->EnableOpenFlowPcap(
"openflow");
241 ofQosHelper->EnableDatapathStats(
"switch-stats");
242 csmaHelper.
EnablePcap(
"switch", switchNodes,
true);
243 csmaHelper.
EnablePcap(
"server", serverDevices);
244 csmaHelper.
EnablePcap(
"client", clientDevices);
260 for (
size_t i = 0; i < clients; i++)
262 std::ostringstream desc;
263 desc <<
"Client " << i;
269 if (getcwd(cwd,
sizeof(cwd)) !=
nullptr)
272 std::string(cwd) +
"/contrib/ofswitch13/examples/ofswitch13-qos-controller/images/";
285 for (
size_t i = 0; i < clients; i++)
289 for (
size_t i = 0; i < clients + 7U; i++)
303 std::cout <<
"Bytes received by server 1: " << sink1->
GetTotalRx() <<
" ("
304 << (8. * sink1->
GetTotalRx()) / 1000000 / simTime <<
" Mbps)" << std::endl;
305 std::cout <<
"Bytes received by server 2: " << sink2->
GetTotalRx() <<
" ("
306 << (8. * sink2->
GetTotalRx()) / 1000000 / simTime <<
" Mbps)" << std::endl;
Interface to network animator.
void UpdateNodeImage(uint32_t nodeId, uint32_t resourceId)
Helper function to update the image of a node.
void SetStartTime(Time t)
Specify the time at which capture should start.
uint32_t AddResource(std::string resourcePath)
Add a resource such as the path to an image file.
void UpdateNodeSize(Ptr< Node > n, double width, double height)
Helper function to update the size of a node.
void SetStopTime(Time t)
Specify the time at which capture should stop.
void UpdateNodeDescription(Ptr< Node > n, std::string descr)
Helper function to update the description for a given node.
holds a vector of ns3::Application pointers.
Iterator Begin() const
Get an iterator which refers to the first Application in the container.
Iterator End() const
Get an iterator which indicates past-the-last Application in the container.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
std::vector< Ptr< Application > >::const_iterator Iterator
Application container iterator.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
AttributeValue implementation for Boolean.
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
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.
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.
static Ipv4Address GetAny()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static Mac48Address Allocate()
Allocate a new Mac48Address.
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
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.
Holds a vector of ns3::OFSwitch13Device pointers.
void Add(OFSwitch13DeviceContainer other)
Append the contents of another OFSwitch13DeviceContainer to the end of this container.
static void EnableDatapathLogs(std::string prefix="", bool explicitFilename=false)
Enable OpenFlow datapath logs at all OpenFlow switch devices on the simulation.
@ DEDICATEDCSMA
Uses individual CSMA channels.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
uint64_t GetTotalRx() const
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Smart pointer class similar to boost::intrusive_ptr.
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 an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
AnimationInterface * anim
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.