How to Implement NFV Communication in NS2

To implement Network Function Virtualization (NFV) communication in Network Simulator 2 (NS2) has needs to mimic the virtualized network functions (VNFs) and orchestrating their interaction over a network. While NS2 traditionally emulated the classical interaction and network protocols that executes NFV that requires modelling VNFs, virtual links among them and the orchestration is essential to handle their lifecycle, scaling, and performance.

The below is the structured approach on how to implement NFV communication in NS2:

Step-by-Step Implementation:

  1. Understand the NFV Concepts

Before implementation, it’s significant to familarize the key components of NFV:

  • VNFs (Virtualized Network Functions): Software-based network functions such as firewall, NAT, load balancer that can execute on generic hardware.
  • NFV Infrastructure (NFVI): The physical and virtual resources (compute, storage, and network) need to support VNFs.
  • NFV Orchestrator: To handle VNF lifecycle, orchestrating their deployment, scaling, and communication.
  • Service Function Chain (SFC): A set of VNFs associated together in a certain sequence to deliver a service like firewall → load balancer → NAT.
  1. Set up NS2 Environment

Make sure that NS2 is properly installed on system. Follow these steps:

  1. Install NS2: Download and install NS2 from the NS2 official website.
  2. Verify Installation:

ns

This should open the NS2 interactive shell.

  1. Design VNFs and NFVI

To execute NFV in NS2, we need to design VNFs and the NFV infrastructure (NFVI). This contain to generate a VNF class and NFVI resources like virtual machines (VMs) or containers, and that mimic their interaction over a virtual network.

3.1. Create a VNF Class

VNFs in NS2 can be modelled as software entities that manage packets and perform particular network functions such as routing, load balancing.

Example VNF Class in C++:

class VNF {

public:

std::string vnfType;    // Type of the VNF (e.g., firewall, NAT, etc.)

int vnfID;              // VNF Identifier

int cpuUsage;           // CPU usage for the VNF

int memoryUsage;        // Memory usage for the VNF

bool isActive;          // VNF state

VNF(int id, std::string type, int cpu, int memory) {

vnfID = id;

vnfType = type;

cpuUsage = cpu;

memoryUsage = memory;

isActive = true;

}

// Simulate packet processing

void processPacket(Packet *p) {

if (isActive) {

std::cout << “Processing packet in VNF ” << vnfType << ” (ID: ” << vnfID << “)” << std::endl;

// Implement function-specific processing here (e.g., firewall, NAT, etc.)

}

}

// Simulate resource scaling (horizontal scaling)

void scaleResources(int additionalCpu, int additionalMemory) {

cpuUsage += additionalCpu;

memoryUsage += additionalMemory;

std::cout << “Scaling resources for VNF ” << vnfType << ” (ID: ” << vnfID << “)” << std::endl;

}

};

3.2. Create an NFVI Class

NFVI has contained the infrastructure to host VNFs such as virtual machines or containers. NS2 nodes can signify NFVI nodes hosting VNFs, and each NFVI node can have its resources (CPU, memory, storage) enthusiastically distributed to VNFs.

Example NFVI Class in C++:

class NFVINode {

public:

int nodeID;                         // Node ID in the network

std::vector<VNF> vnfs;              // List of VNFs hosted on this node

int totalCPU;                       // Total CPU resources available on this node

int totalMemory;                    // Total memory resources available on this node

int availableCPU;                   // Available CPU resources after deploying VNFs

int availableMemory;                // Available memory after deploying VNFs

NFVINode(int id, int cpu, int mem) {

nodeID = id;

totalCPU = cpu;

totalMemory = mem;

availableCPU = cpu;

availableMemory = mem;

}

// Deploy a VNF on this NFVI node

bool deployVNF(VNF newVNF) {

if (availableCPU >= newVNF.cpuUsage && availableMemory >= newVNF.memoryUsage) {

vnfs.push_back(newVNF);

availableCPU -= newVNF.cpuUsage;

availableMemory -= newVNF.memoryUsage;

std::cout << “VNF ” << newVNF.vnfType << ” deployed on NFVI node ” << nodeID << std::endl;

return true;

}

return false;  // Insufficient resources

}

// Terminate a VNF and free resources

void terminateVNF(int vnfID) {

for (size_t i = 0; i < vnfs.size(); i++) {

if (vnfs[i].vnfID == vnfID) {

availableCPU += vnfs[i].cpuUsage;

availableMemory += vnfs[i].memoryUsage;

std::cout << “VNF ” << vnfs[i].vnfType << ” terminated on NFVI node ” << nodeID << std::endl;

vnfs.erase(vnfs.begin() + i);

break;

}

}

}

};

  1. Simulate VNF Orchestration

To handle the lifecycle and interaction of VNFs, we will need an NFV Orchestrator that manages deployment, scaling, and communication among VNFs.

4.1. Create NFV Orchestrator Class

The orchestrator will handle VNFs, manage their communication, and make sure VNFs are implemented based on resource availability.

Example NFV Orchestrator in C++:

class NFVOrchestrator {

public:

std::vector<NFVINode> nfviNodes;   // List of NFVI nodes in the network

NFVOrchestrator(std::vector<NFVINode> nodes) {

nfviNodes = nodes;

}

// Deploy a VNF on an appropriate NFVI node

void deployVNF(VNF newVNF) {

for (auto &node : nfviNodes) {

if (node.deployVNF(newVNF)) {

std::cout << “VNF deployed successfully!” << std::endl;

return;

}

}

std::cout << “Failed to deploy VNF due to insufficient resources.” << std::endl;

}

// Scale a VNF on a specific node

void scaleVNF(int nodeID, int vnfID, int additionalCpu, int additionalMemory) {

for (auto &node : nfviNodes) {

if (node.nodeID == nodeID) {

for (auto &vnf : node.vnfs) {

if (vnf.vnfID == vnfID) {

vnf.scaleResources(additionalCpu, additionalMemory);

break;

}

}

}

}

}

// Terminate a VNF

void terminateVNF(int nodeID, int vnfID) {

for (auto &node : nfviNodes) {

if (node.nodeID == nodeID) {

node.terminateVNF(vnfID);

break;

}

}

}

// Manage communication between VNFs

void communicateVNF(VNF &srcVNF, VNF &dstVNF, Packet *p) {

std::cout << “Communicating between VNF ” << srcVNF.vnfType << ” and VNF ” << dstVNF.vnfType << std::endl;

srcVNF.processPacket(p);

dstVNF.processPacket(p);

}

};

  1. Extend OTcl to Support NFV Orchestration

We need to generate an OTcl script to mimic NFV communication. The OTcl script will:

  • Configure the network topology.
  • Describe NFVI nodes and VNFs.
  • Set up, communicate, and end VNFs as part of the simulation.

Example OTcl Script:

# Create a Simulator object

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

# Create NFVI nodes (Node1, Node2, Node3)

set nfvi1 [$ns node]

set nfvi2 [$ns node]

set nfvi3 [$ns node]

# Define links between NFVI nodes

$ns duplex-link $nfvi1 $nfvi2 100Mb 10ms DropTail

$ns duplex-link $nfvi2 $nfvi3 100Mb 10ms DropTail

# Deploy VNFs on NFVI nodes (Firewalls, NATs, etc.)

$ns at 1.0 “deployVNF nfvi1 firewall”

$ns at 1.5 “deployVNF nfvi2 load_balancer”

$ns at 2.0 “deployVNF nfvi3 NAT”

# Simulate communication between VNFs (firewall → load_balancer → NAT)

$ns at 2.5 “communicateVNF nfvi1 firewall nfvi2 load_balancer”

$ns at 3.0 “communicateVNF nfvi2 load_balancer nfvi3 NAT”

# Scale resources of a VNF

$ns at 3.5 “scaleVNF nfvi1 firewall 2 1024”

# Terminate a VNF

$ns at 4.0 “terminateVNF nfvi2 load_balancer”

# End simulation

$ns at 5.0 “finish”

proc finish {} {

global ns nf

$ns flush-trace

close $nf

exit 0

}

$ns run

This OTcl script configures three NFVI nodes, implements VNFs (firewall, load balancer, NAT), arranges communication among them, scales resources for one of the VNFs, and terminates another.

  1. Run and Validate the Simulation
  1. Run the Simulation: After writing C++ code and OTcl script, recompile NS2 (if made changes in C++) and execute OTcl script.

ns your_nfv_simulation.tcl

  1. Analyze the Output:
    • NAM (Network Animator): Envision on how VNFs are deployed and how communication flows between them.
    • Trace Files: investigate trace files for logs of VNF deployment, communication, and scaling operations.
  2. Console Output: Verify the console for messages based on VNF deployments, scaling, communication, and terminations.
  1. Enhancements and Future Work

Here are some concepts for improving NFV communication simulation in NS2:

  • Service Function Chaining (SFC): Execute a more complex service chaining mechanism in which packets are processed via a series of VNFs.
  • Dynamic Resource Allocation: To mimic dynamic resource allocation in which NFVI nodes can scale VNFs based on real-time traffic or resource usage.
  • Fault Tolerance: Execute fault-tolerant VNFs in which failed VNFs are systematically redeployed or restarted.
  • NFV Security: To mimic security VNFs (firewalls, IDS, etc.) that handles the security of network traffic.
  • Integration with SDN (Software-Defined Networking): Integrate NFV with SDN to enthusiastically control VNF placement, scaling, and traffic flow using a centralized controller.

In this demonstration we successfully completed the execution process to implement the NFV communication in ns2 simulation tool. We plan to deliver descriptive information regarding the performance of NFV communication in other tools.

You can count on us for timely delivery and comprehensive explanations. Please reach out to us to receive a customized implementation of NFV Communication in the NS2 tool that meets your specific requirements.