How to Implement Network Softwarization in NS2

To implement Network Softwarization in ns2 has numerous steps to follow and it usually demonstrated to transforming traditional hardware-centric network functions into software-based implementations that permit more resilience, scalability, and agility. This concept contains the Software-Defined Networking (SDN), Network Function Virtualization (NFV), and other software-driven network architectures. Since NS2 mainly mimics traditional networking that we can expand it to support network softwarization concepts by executing SDN controllers, NFV orchestration, and virtualized network functions.

The given below is the procedure to implement Network Softwarization in NS2:

Step-by-Step Implementation:

  1. Understand Key Concepts of Network Softwarization

Before starting the implementation, it’s significant to know the core components of network softwarization:

  • SDN (Software-Defined Networking): Centralizes control by decoupling the control plane (routing decisions) from the data plane (packet forwarding). The SDN controller handles network devices and configures them dynamically.
  • NFV (Network Function Virtualization): Replaces dedicated network hardware like routers, firewalls with software running on general-purpose hardware.
  • Service Function Chaining (SFC): Directs traffic across a sequence of VNFs to deliver end-to-end services.
  1. Set up NS2 Environment

Make sure that NS2 is installed and properly configure on system.

  1. Install NS2:

wget https://sourceforge.net/projects/nsnam/files/latest/download -O ns-allinone-2.35.tar.gz

tar -xzvf ns-allinone-2.35.tar.gz

cd ns-allinone-2.35

./install

  1. Verify Installation:

ns

This command should launch the NS2 command-line interface.

  1. Implement Software-Defined Networking (SDN)

In SDN, the controller handles the network devices enthusiastically by sending flow rules to switches. To mimic SDN in NS2, we need to generate a software-defined controller and incorporate it with the network nodes.

3.1. Create an SDN Controller in C++

The SDN controller will manage flow rules and handle the routing for switches in the network.

Example SDN Controller Class:

class SDNController {

public:

std::map<int, std::map<int, int>> flowTable;  // Flow table [srcNode][dstNode] = nextHopNode

SDNController() {

// Initialize controller

}

// Install flow rule in the switch

void installFlowRule(int srcNode, int dstNode, int nextHop) {

flowTable[srcNode][dstNode] = nextHop;

std::cout << “Installing flow rule: ” << srcNode << ” -> ” << dstNode << ” via ” << nextHop << std::endl;

}

// Get the next hop for a flow

int getNextHop(int srcNode, int dstNode) {

if (flowTable.count(srcNode) && flowTable[srcNode].count(dstNode)) {

return flowTable[srcNode][dstNode];

}

return -1;  // No flow rule found

}

// SDN controller logic for handling packet forwarding

void processPacket(int srcNode, int dstNode, Packet *packet) {

int nextHop = getNextHop(srcNode, dstNode);

if (nextHop != -1) {

std::cout << “Forwarding packet from ” << srcNode << ” to ” << dstNode << ” via ” << nextHop << std::endl;

// Logic to forward packet to next hop

} else {

std::cout << “No flow rule found for flow ” << srcNode << ” -> ” << dstNode << std::endl;

}

}

};

3.2. Modify Switch Behavior

The switches in the network will query the SDN controller for forwarding decisions rather than creating routing decisions themselves.

Example Switch Node in C++:

class SDNSwitch {

public:

int switchID;

SDNController* controller;

SDNSwitch(int id, SDNController* ctrl) {

switchID = id;

controller = ctrl;

}

// Receive a packet and forward based on controller’s decision

void receivePacket(Packet *p, int srcNode, int dstNode) {

controller->processPacket(srcNode, dstNode, p);

}

};

3.3. Extend OTcl to Support SDN

Describe the SDN controller and switches in the OTcl script and handle their communication.

Example OTcl Script:

# Create a Simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

# Create an SDN controller and switches

set sdn_controller [new SDNController]

set switch1 [new SDNSwitch 1 $sdn_controller]

set switch2 [new SDNSwitch 2 $sdn_controller]

# Define the links between switches

$ns duplex-link $switch1 $switch2 1Gb 10ms DropTail

# Install flow rules in the SDN controller

$ns at 1.0 “$sdn_controller installFlowRule 1 2 2”

# Simulate packet forwarding

set udp [new Agent/UDP]

$ns attach-agent $switch1 $udp

set null [new Agent/Null]

$ns attach-agent $switch2 $null

$ns connect $udp $null

$ns at 1.5 “$udp send 1000”

# End simulation

$ns at 10.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exit 0

}

$ns run

  1. Implement NFV (Network Function Virtualization)

NFV has contain virtualizing network functions like firewall, NAT and executing them as software instead of using dedicated hardware. We will mimic VNFs and NFV orchestration in NS2.

4.1. Create a VNF Class in C++

A VNF (Virtualized Network Function) can be a software-based firewall, NAT, load balancer, or other network function that processes packets.

Example VNF Class:

class VNF {

public:

std::string vnfType;

bool isActive;

VNF(std::string type) {

vnfType = type;

isActive = true;

}

// Process packet based on VNF type

void processPacket(Packet *p) {

if (vnfType == “firewall”) {

// Simulate firewall logic

std::cout << “Firewall processing packet…” << std::endl;

} else if (vnfType == “NAT”) {

// Simulate NAT logic

std::cout << “NAT processing packet…” << std::endl;

}

// Other VNF types…

}

};

4.2. Create an NFV Orchestrator

The NFV Orchestrator is liable for handle the lifecycle of VNFs that involves their deployment, scaling, and termination.

Example NFV Orchestrator Class:

class NFVOrchestrator {

public:

std::vector<VNF> vnfs;

NFVOrchestrator() {

// Initialize orchestrator

}

// Deploy a VNF

void deployVNF(std::string vnfType) {

VNF vnf(vnfType);

vnfs.push_back(vnf);

std::cout << “Deployed VNF: ” << vnfType << std::endl;

}

// Process packet through the VNF chain

void processPacketThroughVNFs(Packet *p) {

for (auto &vnf : vnfs) {

if (vnf.isActive) {

vnf.processPacket(p);

}

}

}

};

4.3. Extend OTcl to Support NFV

Describe VNFs and NFV orchestrator in the OTcl script, and mimics the packet processing through VNFs.

Example OTcl Script:

# Create a Simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

# Create NFV Orchestrator and deploy VNFs

set nfv_orchestrator [new NFVOrchestrator]

$ns at 1.0 “$nfv_orchestrator deployVNF firewall”

$ns at 1.5 “$nfv_orchestrator deployVNF NAT”

# Simulate packet flow through VNFs

set udp [new Agent/UDP]

set sink [new Agent/Null]

$ns attach-agent $nfv_orchestrator $udp

$ns attach-agent $nfv_orchestrator $sink

$ns connect $udp $sink

$ns at 2.0 “$udp send 1000”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exit 0

}

$ns run

  1. Implement Service Function Chaining (SFC)

In Service Function Chaining (SFC), packets are directed across a series of VNFs in a certain order (e.g., firewall → load balancer → NAT).

5.1. Create SFC Logic

Add a function in the NFV orchestrator to direct packets via a sequence of VNFs.

Example SFC in C++:

class SFC {

public:

std::vector<VNF> vnfs;  // VNFs in the chain

 

SFC(std::vector<VNF> chain) {

vnfs = chain;

}

// Process packet through the service function chain

void processPacketThroughSFC(Packet *p) {

for (auto &vnf : vnfs) {

if (vnf.isActive) {

vnf.processPacket(p);

}

}

}

};

5.2. Simulate SFC in OTcl

Describe the service function chain in OTcl, and mimic the flow of packets over the chain.

Example OTcl Script:

# Create a Simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

# Create VNFs and SFC

set firewall [new VNF firewall]

set load_balancer [new VNF load_balancer]

set nat [new VNF NAT]

set sfc [new SFC [list $firewall $load_balancer $nat]]

# Process packet through the SFC

set udp [new Agent/UDP]

set sink [new Agent/Null]

$ns attach-agent $sfc $udp

$ns attach-agent $sfc $sink

$ns connect $udp $sink

$ns at 2.0 “$udp send 1000”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exit 0

}

$ns run

  1. Run and Validate the Simulation
  1. Run the Simulation: After writing the OTcl scripts and compiling the C++ code, execute simulation:

ns your_script.tcl

  1. Validate the Output: Use NAM (Network Animator) and trace files to envision and evaluate the packet flows across the SDN switches, VNFs, and service function chains.

NAM:

nam out.nam

  1. Check Logs: Make sure that the SDN controller is installing the correct flow rules, VNFs are processing packets, and service chains are working as expected.
  1. Further Enhancements
  • Dynamic Scaling of VNFs: Execute dynamic resource allocation to scale VNFs up/down based on traffic load.
  • SDN Northbound API: Expand the SDN controller with a northbound API to allow application-level control across the network.
  • Network Slicing: To mimic numerous virtual networks slices with isolated resources for different services.
  • Security VNFs: We Execute VNFs for security functions such as firewalls, IDS, and DDoS prevention.

Contact us for help with implementing Network Softwarization in NS2. We are experts in Software-Defined Networking (SDN), Network Function Virtualization (NFV), and other software-based network designs. Get the best simulation advice from our team!