How to Start Centralized Routing Projects Using NS3
To start a Centralized Routing Project in NS3, we follow below simplified approach:
Steps to Start Centralized Routing Project in NS3
- Set Up NS3
- We install NS3 on the computer:
sudo apt update
sudo apt install g++ python3 git cmake
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./waf configure
./waf build
- Verify the Installation: We should execute a sample simulation, making sure that everything is configured:
./waf –run scratch/my-first
- Understand Centralized Routing
- Centralized Routing:
- A central controller determines the routes in centralized routing for every node within the network.
- Nodes send packets according to the guidelines that are offered by the central entity.
- Use Cases:
- Software-Defined Networking (SDN) is a general example in which a centralized controller handles the routing.
- Decide the Simulation Approach
We can be executed the centralized routing within two ways:
- Custom Implementation: We make routing logic by means of prolonging the Ipv4RoutingProtocol of ns3.
- SDN Controller Approach: We can utilize NS3 extensions such as OpenFlow or execute the simple controller.
- Basic Centralized Routing Implementation
Below is a simple instance on how to replicate the centralized routing by calculating the routes manually and setting up nodes.
Code Example:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/ipv4-static-routing-helper.h”
using namespace ns3;
int main() {
NodeContainer nodes;
nodes.Create(4); // Create 4 nodes
// Define links between nodes
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices1 = pointToPoint.Install(nodes.Get(0), nodes.Get(1));
NetDeviceContainer devices2 = pointToPoint.Install(nodes.Get(1), nodes.Get(2));
NetDeviceContainer devices3 = pointToPoint.Install(nodes.Get(2), nodes.Get(3));
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces1 = address.Assign(devices1);
address.SetBase(“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces2 = address.Assign(devices2);
address.SetBase(“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces3 = address.Assign(devices3);
// Implement centralized routing logic
Ipv4StaticRoutingHelper staticRoutingHelper;
Ptr<Ipv4StaticRouting> staticRoutingNode0 = staticRoutingHelper.GetStaticRouting(nodes.Get(0)->GetObject<Ipv4>());
staticRoutingNode0->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.1.2”), 1); // Route from Node 0 to Node 3 via Node 1
Ptr<Ipv4StaticRouting> staticRoutingNode1 = staticRoutingHelper.GetStaticRouting(nodes.Get(1)->GetObject<Ipv4>());
staticRoutingNode1->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.2.2”), 2); // Intermediate route
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Advanced Centralized Routing with Custom Protocol
If we require a dynamic centralized routing protocol:
- Make a centralized controller, which determines routes dynamically.
- We can utilize a global routing table to modernize routes periodically.
Skeleton for Centralized Routing Protocol:
#include “ns3/ipv4-routing-protocol.h”
namespace ns3 {
class CentralizedRoutingProtocol : public Ipv4RoutingProtocol {
public:
static TypeId GetTypeId();
CentralizedRoutingProtocol();
virtual ~CentralizedRoutingProtocol();
Ptr<Ipv4Route> RouteOutput(Ptr<Packet> packet, const Ipv4Header &header,
Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) override;
void UpdateRoutes();
private:
void ComputeGlobalRoutes();
std::map<uint32_t, uint32_t> globalRoutingTable; // Stores destination -> next hop
};
} // namespace ns3
- Centralized SDN-Like Routing
- Install OpenFlow Module (optional):
- NS3 environment contains OpenFlow support for SDN-based simulations.
- It permits to replicate a centralized controller communicating with the network.
- Set Up SDN in NS3:
- We should install the click module for NS3 or we utilise OpenFlow helpers.
- Make a controller node, which impels flow rules to switches.
- Simulate and Analyze
- Confirm routes to utilize logging:
./waf –run centralized-routing
- We need to examine the performance parameters such as:
- Route convergence time.
- Path optimality.
- Control overhead.
We had given common step-by-step approach with sample snippets for Centralized Routing Project in NS3 that were simulated and analysed. If you have any doubt on this process, please feel free to ask!
To successfully execute Centralized Routing Projects, it is essential to possess the necessary skills. The experts at phdprojects.org are ready to provide you with valuable insights and well-aligned topics that will engage your audience. Please feel free to reach out to us for further guidance. We are committed to addressing performance parameters that align with your specific needs.