How to Simulate Network Function Virtualization Using NS2

To simulate Network Function Virtualization (NFV) projects using NS2 can be a bit difficult while NS2 does not directly support NFV. NFV is a comparatively modern ideas that isolates network functions such as firewalls, load balancers, etc. from the underlying hardware by virtualizing them as software-based instances, usually executes in virtual machines (VMs) or containers.

Since NS2 was originally built for traditional network simulations such as routing, wireless communication, we can still replicate some contexts of NFV in NS2 by adapting or prolonging its functionality.

Here’s a procedure on how to simulate the Network Function Virtualization in ns2

Steps to Simulate Network Function Virtualization Projects in NS2

  1. Install NS2
  • Download and install NS2 on the system.
  • Make sure that all dependencies (Tcl/Tk, OTcl, NAM) are installed correctly for writing simulation scripts and envision the outcomes.
  1. Understand NFV Concepts
  • Virtual Network Functions (VNFs): These are virtualized versions of network functions such as firewalls, NAT, DPI, etc., that were traditionally hardware-based.
  • NFV Infrastructure (NFVI): The physical and virtual resources on which VNFs are implemented, like servers, VMs, hypervisors, or containers.
  • NFV Orchestrator: The central entity responsible for handling the life cycle of VNFs, that involves deployment, scaling, and monitoring.
  • VNF Forwarding Graph (VNF-FG): A chain or graph of interconnected VNFs that describe how packets traverse via numerous VNFs.
  1. Extend NS2 to Simulate NFV

NS2 does not directly support virtualization or NFV-specific components such as VNFs; however we can emulate key NFV characteristics by executing virtualized network functions as isolate agents and implementing their processing capabilities.

  • Agent: In NS2, an agent is utilized to process and route packets. We can treat each VNF as a custom agent, in which the feature of the VNF such as firewall, NAT, load balancer is modelled.

Example: Create Custom Agents to Simulate VNFs

To simulate VNFs such a firewall or load balancer, we can generate custom agents in NS2 by encompassing its C++ core.

Firewall Agent (VNF) Example:

class FirewallAgent : public Agent {

public:

FirewallAgent() : Agent(PT_UDP) {}

void recv(Packet* p, Handler*) {

hdr_ip* ip_header = hdr_ip::access(p);

// Example: Block packets from a certain source

if (ip_header->src() == Address::instance().str2addr(“1.0.0.1”)) {

printf(“Packet blocked by firewall\n”);

drop(p);

return;

}

// Forward the packet to the next hop

send(p, 0);

}

};

Load Balancer Agent (VNF) Example:

class LoadBalancerAgent : public Agent {

public:

LoadBalancerAgent() : Agent(PT_UDP) {}

void recv(Packet* p, Handler*) {

hdr_ip* ip_header = hdr_ip::access(p);

// Example: Forward traffic to different servers based on a round-robin algorithm

if (ip_header->dst() == Address::instance().str2addr(“2.0.0.1”)) {

ip_header->dst() = Address::instance().str2addr(“2.0.0.2”); // Forward to a different server

}

// Send the packet to the next destination

send(p, 0);

}

};

  1. Create the NFV Topology in NS2

In NFV, we usually have numerous VNFs processing on virtual infrastructure like VMs or containers that process network traffic. For simplicity, we can replicate this by describing different nodes (each representing a VNF) and associate them in a chain or forwarding graph.

Example OTcl Code for NFV Topology:

# Create a simulator instance

set ns [new Simulator]

# Define the topology (network infrastructure for NFV)

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Flat grid of 1000×1000 meters

# Create nodes (each representing a physical server running VNFs)

set client [$ns node]

set firewall_vnf [$ns node]

set load_balancer_vnf [$ns node]

set server [$ns node]

# Establish links between VNFs

$ns simplex-link $client $firewall_vnf 100Mb 10ms DropTail

$ns simplex-link $firewall_vnf $load_balancer_vnf 100Mb 10ms DropTail

$ns simplex-link $load_balancer_vnf $server 100Mb 10ms DropTail

In this example:

  • A client node transmits traffic to a server node via a firewall VNF and a load balancer VNF.
  • The traffic is processed by the firewall and load balancer agents before reaching the server.
  1. Simulate NFV Orchestration

The NFV Orchestrator is responsible for implementing and handling VNFs. since NS2 does not natively support orchestration, we can replicate the orchestration logic by dynamically adding or removing VNFs in the course of the simulation.

Example: Simulate VNF Orchestration in NS2

We can simulate dynamic orchestration by activating or deactivating VNFs in the period of the simulation, implementing how an orchestrator would scale VNFs up or down according to traffic load.

# Function to activate a new VNF (e.g., load balancer) at runtime

proc activate_vnf {vnf_node} {

global ns

puts “Activating VNF at node $vnf_node”

$ns at 5.0 “$vnf_node start”

}

# Activate load balancer VNF at time 5.0 seconds

$ns at 5.0 “activate_vnf $load_balancer_vnf”

  1. Simulate Traffic between Nodes and VNFs

In NS2, we can emulate traffic between clients and servers by creating packets using UDP or TCP agents. These packets will pass via the chain of VNFs (like firewall and load balancer) before reaching their destination.

Example: UDP Traffic Simulation

# Create UDP agents and traffic from client to server

set udp [new Agent/UDP]

set null [new Agent/Null]

$ns attach-agent $client $udp

$ns attach-agent $server $null

$ns connect $udp $null

# Create a CBR traffic generator

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

$cbr attach-agent $udp

# Start CBR traffic at time 1.0 seconds

$ns at 1.0 “$cbr start”

This sample replicates a constant bit rate (CBR) traffic flow from the client to the server, passing via the firewall and load balancer VNFs.

  1. Run the Simulation

Save simulation script as nfv_simulation.tcl and execute it using NS2.

ns nfv_simulation.tcl

  1. Analyse the Results

NS2 creates trace files that capture network events in the period of the simulation. we can utilize these trace files to measure the parameters like:

  • Packet Delivery: How many packets reach their destination after being processed by VNFs?
  • Latency: The delay established by processing at diverse VNFs such as firewall, load balancer.
  • VNF Load: How different VNFs manage traffic load.

Example: Analyse Trace Files Using Awk

awk -f analyze_trace.awk nfv_simulation.tr

  1. Visualize the Simulation Using NAM

Utilize Network Animator (NAM) to envision the flow of packets via the NFV chain, demonstrates on how VNFs process and forward traffic.

nam nfv_simulation.nam

Example Simulation Script Outline for NFV

# Simulation script for Network Function Virtualization (NFV) in NS2

set ns [new Simulator]

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Define a flat grid

# Create nodes representing physical servers running VNFs

set client [$ns node]  ;# Client node

set firewall_vnf [$ns node]  ;# Firewall VNF

set load_balancer_vnf [$ns node]  ;# Load Balancer VNF

set server [$ns node]  ;# Destination server

# Establish links between the VNFs

$ns simplex-link $client $firewall_vnf 100Mb 10ms DropTail

$ns simplex-link $firewall_vnf $load_balancer_vnf 100Mb 10ms DropTail

$ns simplex-link $load_balancer_vnf $server 100Mb 10ms DropTail

# Define UDP traffic from the client to the server

set udp [new Agent/UDP]

set null [new Agent/Null]

$ns attach-agent $client $udp

$ns attach-agent $server $null

$ns connect $udp $null

# Create CBR traffic generator

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

$cbr attach-agent $udp

# Start CBR traffic at time 1.0 seconds

$ns at 1.0 “$cbr start”

# Function to activate a VNF dynamically

proc activate_vnf {vnf_node} {

puts “Activating VNF at node $vnf_node”

}

# Activate the load balancer VNF at time 5.0 seconds

$ns at 5.0 “activate_vnf $load_balancer_vnf”

# Run the simulation

$ns at 20.0 “finish”

$ns run

Key Points:

  • VNF Simulation: Generate custom agents to replicate VNFs such as firewalls, load balancers, etc.
  • NFV Topology: Replicate the chaining of VNFs and the traffic flow among clients, VNFs, and servers.
  • Dynamic Orchestration: Apply logic to activate and deactivate VNFs in the course of the simulation.
  • Traffic Simulation: Utilize UDP or TCP traffic to design real network traffic passing via VNFs.

We clearly explain the concepts and techniques on how to simulate the network function virtualization project using the tool of ns2 and it contains the step-by-step procedures, sample snippets and the project key points. More information will be shared in another manual. Please submit all the details of your Network Function Virtualization project to phdprime.com. We will provide you with the most favorable simulation results and insights into network performance. Additionally, you will receive guidance on the specialized protocols that we have developed.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2