To implement an SD-WAN (Software-Defined Wide Area Network) protocol in ns-3, we have to create a simulation that has a similar behavior of an SD-WAN network. SD-WAN incorporates features such as dynamic path selection, centralized control, and the ability to manage multiple WAN links. ns-3 doesn’t provide built-in support for SD-WAN.
Hence, we need to simulate its basic functionalities by combining existing modules and custom scripts.
Steps to implement SD-WAN protocol in ns3
- Set up your environment
Make sure that ns3 is installed in the computer. If not, install it from the official ns3 website.
- Create a new ns3 script
On your ns3 installation, create a new simulation script in the scratch directory.
- Implement the SD-WAN network
Below is the example script for setting up a SD-WAN network.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/ipv4-global-routing-helper.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“SDWANSimulation”);
void
ChangePath (Ptr<Node> srcNode, Ptr<Node> dstNode, Ipv4Address newNextHop)
{
Ptr<Ipv4> ipv4 = srcNode->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRouting = Ipv4RoutingHelper::GetStaticRouting (ipv4);
staticRouting->RemoveRoute (1);
staticRouting->AddHostRouteTo (dstNode->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal (), newNextHop, 1);
NS_LOG_INFO (“Path changed to ” << newNextHop);
}
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer branchNodes;
branchNodes.Create (2);
NodeContainer wanNodes;
wanNodes.Create (2);
NodeContainer centralNode;
centralNode.Create (1);
// Set up point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“10Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
// Branch to WAN links
devices = pointToPoint.Install (branchNodes.Get (0), wanNodes.Get (0));
devices = pointToPoint.Install (branchNodes.Get (1), wanNodes.Get (1));
// WAN to Central links
devices = pointToPoint.Install (wanNodes.Get (0), centralNode.Get (0));
devices = pointToPoint.Install (wanNodes.Get (1), centralNode.Get (0));
// Install the internet stack on nodes
InternetStackHelper stack;
stack.Install (branchNodes);
stack.Install (wanNodes);
stack.Install (centralNode);
// Assign IP addresses to the devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer if0 = address.Assign (devices.Get (0));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer if1 = address.Assign (devices.Get (1));
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer if2 = address.Assign (devices.Get (2));
address.SetBase (“10.1.4.0”, “255.255.255.0”);
Ipv4InterfaceContainer if3 = address.Assign (devices.Get (3));
// Set up static routing
Ipv4StaticRoutingHelper staticRoutingHelper;
Ptr<Ipv4> ipv4Branch0 = branchNodes.Get (0)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingBranch0 = staticRoutingHelper.GetStaticRouting (ipv4Branch0);
staticRoutingBranch0->AddHostRouteTo (Ipv4Address (“10.1.3.2”), Ipv4Address (“10.1.1.2”), 1);
Ptr<Ipv4> ipv4Branch1 = branchNodes.Get (1)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingBranch1 = staticRoutingHelper.GetStaticRouting (ipv4Branch1);
staticRoutingBranch1->AddHostRouteTo (Ipv4Address (“10.1.4.2”), Ipv4Address (“10.1.2.2”), 1);
Ptr<Ipv4> ipv4Central = centralNode.Get (0)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingCentral = staticRoutingHelper.GetStaticRouting (ipv4Central);
staticRoutingCentral->AddHostRouteTo (Ipv4Address (“10.1.1.1”), Ipv4Address (“10.1.3.1”), 1);
staticRoutingCentral->AddHostRouteTo (Ipv4Address (“10.1.2.1”), Ipv4Address (“10.1.4.1”), 1);
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (centralNode.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (20.0));
UdpEchoClientHelper echoClient (Ipv4Address (“10.1.3.2”), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (branchNodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (20.0));
// Change path after 10 seconds
Simulator::Schedule (Seconds (10.0), &ChangePath, branchNodes.Get (0), centralNode.Get (0), Ipv4Address (“10.1.2.2”));
// Enable tracing
pointToPoint.EnablePcapAll (“sdwan-simulation”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation
- Node creation :
For the SD-WAN, create nodes that represents branches, WAN nodes, and a central node.
- Point-to-point link :
To simulate WAN connections, Set up point-to-point links between the nodes.
- Internet stack installation :
On the nodes, install the internet stack.
- IP address assignment :
Assigns IP addresses to the point-to-point links.
- Application setup :
On one node, set up a UDP echo server and on another node, setup a UDP echo client to test connectivity.
- Static routing setup :
To simulate path selection, configures static routes. Routes are set up to go through one path.
- Path change simulation :
To change the path dynamically during the simulation to simulate SD-WAN behavior, Use a function.
- Tracing :
To capture packet information, enable ASCII and pcap tracing for analysis.
- Simulation execution :
Run the simulation.
- Build and run the simulation
Build and run your script after writing.
./waf build
./waf –run scratch/sdwan-simulation
- Analyze the results
You can analyze the results after running the simulation, by generating trace files (sdwan-simulation.tr and sdwan-simulation-0-0.pcap).
Example script for SD-WAN protocol
Below is the example script for your reference:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/ipv4-global-routing-helper.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“SDWANSimulation”);
void
ChangePath (Ptr<Node> srcNode, Ptr<Node> dstNode, Ipv4Address newNextHop)
{
Ptr<Ipv4> ipv4 = srcNode->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRouting = Ipv4RoutingHelper::GetStaticRouting (ipv4);
staticRouting->RemoveRoute (1);
staticRouting->AddHostRouteTo (dstNode->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal (), newNextHop, 1);
NS_LOG_INFO (“Path changed to ” << newNextHop);
}
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer branchNodes;
branchNodes.Create (2);
NodeContainer wanNodes;
wanNodes.Create (2);
NodeContainer centralNode;
centralNode.Create (1);
// Set up point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“10Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
// Branch to WAN links
devices = pointToPoint.Install (branchNodes.Get (0), wanNodes.Get (0));
devices = pointToPoint.Install (branchNodes.Get (1), wanNodes.Get (1));
// WAN to Central links
devices = pointToPoint.Install (wanNodes.Get (0), centralNode.Get (0));
devices = pointToPoint.Install (wanNodes.Get (1), centralNode.Get (0));
// Install the internet stack on nodes
InternetStackHelper stack;
stack.Install (branchNodes);
stack.Install (wanNodes);
stack.Install (centralNode);
// Assign IP addresses to the devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer if0 = address.Assign (devices.Get (0));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer if1 = address.Assign (devices.Get (1));
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer if2 = address.Assign (devices.Get (2));
address.SetBase (“10.1.4.0”, “255.255.255.0”);
Ipv4InterfaceContainer if3 = address.Assign (devices.Get (3));
// Set up static routing
Ipv4StaticRoutingHelper staticRoutingHelper;
Ptr<Ipv4> ipv4Branch0 = branchNodes.Get (0)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingBranch0 = staticRoutingHelper.GetStaticRouting (ipv4Branch0);
staticRoutingBranch0->AddHostRouteTo (Ipv4Address (“10.1.3.2”), Ipv4Address (“10.1.1.2”), 1);
Ptr<Ipv4> ipv4Branch1 = branchNodes.Get (1)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingBranch1 = staticRoutingHelper.GetStaticRouting (ipv4Branch1);
staticRoutingBranch1->AddHostRouteTo (Ipv4Address (“10.1.4.2”), Ipv4Address (“10.1.2.2”), 1);
Ptr<Ipv4> ipv4Central = centralNode.Get (0)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting> staticRoutingCentral = staticRoutingHelper.GetStaticRouting (ipv4Central);
staticRoutingCentral->AddHostRouteTo (Ipv4Address (“10.1.1.1”), Ipv4Address (“10.1.3.1”), 1);
staticRoutingCentral->AddHostRouteTo (Ipv4Address (“10.1.2.1”), Ipv4Address (“10.1.4.1”), 1);
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (centralNode.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (20.0));
UdpEchoClientHelper echoClient (Ipv4Address (“10.1.3.2”), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (branchNodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (20.0));
// Change path after 10 seconds
Simulator::Schedule (Seconds (10.0), &ChangePath, branchNodes.Get (0), centralNode.Get (0), Ipv4Address (“10.1.2.2”));
// Enable tracing
pointToPoint.EnablePcapAll (“sdwan-simulation”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Overall, we had successfully implemented SD-WAN (Software-Defined Wide Area Network) protocol in ns-3 involves creating a simulation that mimics the behavior of an SD-WAN network. Also, we provide more related information on SD-WAN (Software-Defined Wide Area Network).For more programming help on SD-WAN connect with us.