To implement hierarchical routing in ns3, we need to create a architecture of multi-tiered network which can handle the functionalities like critical scalability and efficiency. This type of routing is mainly designed for large networks, where the network uses appropriate routing protocols for each tier.
Here we have given the guide for implementing the hierarchical routing in ns3.
Step-by-Step guide to implement Hierarchical routing in ns3:
- Set Up ns-3 Environment: Make sure that ns3 is installed the system. If not, installed download and install it from the ns3 official website.
- Include Necessary Libraries: Required ns3 libraries should included in the script while starting.
- Define Network Topology: For network topology we need to create the nodes and links, for defining different tiers such as core, distribution, and access layers.
- Install Internet Stack: Install the Internet stack on the nodes.
- Configure Routing Protocols: For each layer we need to configure different routing protocols. For example, use static routing for the access layer and OSPF for the core layer.
- Set Up Applications: Install applications to generate traffic and test the routing.
- Run the Simulation: Configure the simulation parameters and run it.
Implementation in C++
Here’s a detailed example implement hierarchical routing in ns3:
- Include Libraries:
#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”
#include “ns3/ipv4-static-routing-helper.h”
- Define Network Topology:
using namespace ns3;
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
NodeContainer coreNodes, distNodes, accessNodes;
coreNodes.Create(2);
distNodes.Create(4);
accessNodes.Create(8);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Gbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
// Create links between core nodes
NetDeviceContainer coreDevices;
coreDevices = pointToPoint.Install(coreNodes.Get(0), coreNodes.Get(1));
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
// Create links between core and distribution nodes
NetDeviceContainer distDevices;
distDevices.Add(pointToPoint.Install(coreNodes.Get(0), distNodes.Get(0)));
distDevices.Add(pointToPoint.Install(coreNodes.Get(0), distNodes.Get(1)));
distDevices.Add(pointToPoint.Install(coreNodes.Get(1), distNodes.Get(2)));
distDevices.Add(pointToPoint.Install(coreNodes.Get(1), distNodes.Get(3)));
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“100Mbps”));
// Create links between distribution and access nodes
NetDeviceContainer accessDevices;
for (int i = 0; i < 4; ++i) {
accessDevices.Add(pointToPoint.Install(distNodes.Get(i), accessNodes.Get(i * 2)));
accessDevices.Add(pointToPoint.Install(distNodes.Get(i), accessNodes.Get(i * 2 + 1)));
}
InternetStackHelper stack;
stack.Install(coreNodes);
stack.Install(distNodes);
stack.Install(accessNodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer coreInterfaces = address.Assign(coreDevices);
address.SetBase(“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer distInterfaces = address.Assign(distDevices);
address.SetBase(“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer accessInterfaces = address.Assign(accessDevices);
// Setting up static routing for access nodes
Ipv4StaticRoutingHelper staticRoutingHelper;
Ptr<Ipv4StaticRouting> staticRouting;
for (int i = 0; i < 8; ++i) {
staticRouting=staticRoutingHelper.GetStaticRouting(accessNodes.Get(i)->GetObject<Ipv4>());
staticRouting->AddNetworkRouteTo(Ipv4Address(“10.1.1.0”), Ipv4Mask(“255.255.255.0”), accessInterfaces.GetAddress(i * 2));
}
// Setting up global routing for core and distribution nodes
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
// Set up applications
uint16_t port = 9;
UdpEchoServerHelper server(port);
ApplicationContainer apps = server.Install(accessNodes.Get(7));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
UdpEchoClientHelper client(accessInterfaces.GetAddress(7 * 2), port);
client.SetAttribute(“MaxPackets”, UintegerValue(1));
client.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
client.SetAttribute(“PacketSize”, UintegerValue(1024));
apps = client.Install(accessNodes.Get(0));
apps.Start(Seconds(2.0));
apps.Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
Explanation
- Network Topology: The code sets up a hierarchical network topology with core, distribution, and access layers. Core nodes are connected to distribution nodes, and distribution nodes are connected to access nodes.
- Static Routing for Access Nodes: Static routing is configured for access nodes to route traffic to the core layer.
- Global Routing for Core and Distribution Nodes: Global routing is used for the core and distribution nodes to handle dynamic routing.
- Applications: UdpEchoServer and UdpEchoClient applications are set up to test the routing.
- Running the Code
- Save the script to a file, for example, hierarchical-routing.cc.
- Compile the script using the ns3 build system:
./waf configure –enable-examples
./waf build
./waf –run scratch/hierarchical-routing
Overall, Hierarchical routing is typically used for large network which has critical scalability and efficiency, to implement this type of routing a multi-tiered network architecture need to be created which assigns the appropriate routing protocols for each tier.
For best programming aid in hierarchical routing in ns3 reach us out at ns3simulation.com.