How to Implement Network Neutrality in NS2

To implement the Network Neutrality in NS2, it means that all the internet traffic should be equally treated without favouring particular variants of traffic or users over others. In NS2, we have to simulate an environment that contains all traffic, regardless of its source kind or destination will treat with equal preference based on bandwidth allocation, queuing and dispatching. The below guide will help you get started using ns2:

Steps to Simulate Network Neutrality in NS2:

  1. Define Network Topology: Set up nodes indicating various users (clients), servers, and intermediate network components like routers or switches.
  2. Generate Different Types of Traffic: Generate various kinds of traffic (such as video streaming, web browsing, file transfer) to replicate numerous internet services.
  3. Apply Equal Resource Allocation: Make sure all traffic flows are treated equally depends on bandwidth, delay, and queuing. No traffic should be favoured.
  4. Monitor and Analyze Traffic: Use trace files to compute whether all traffic flows receive equal treatment in terms of throughput, delay, and packet loss.

Example: Simulating Network Neutrality in NS2

In this sample, we’ll simulate a network with three users (clients) produce several types of traffic (like FTP, web browsing, video streaming), all being treated equally without any prioritization.

Example TCL Script for Simulating Network Neutrality:

# Create a new simulator instance

set ns [new Simulator]

# Define output trace file for logging events

set tracefile [open network_neutrality.tr w]

$ns trace-all $tracefile

# Define the animation file for NAM (optional)

set namfile [open network_neutrality.nam w]

$ns namtrace-all $namfile

# Create network nodes representing clients, a router, and a server

set client1 [$ns node]   # Client 1 (FTP)

set client2 [$ns node]   # Client 2 (Web Browsing)

set client3 [$ns node]   # Client 3 (Video Streaming)

set router [$ns node]    # Router node

set server [$ns node]    # Server node

# Create links between clients, the router, and the server

$ns duplex-link $client1 $router 10Mb 10ms DropTail

$ns duplex-link $client2 $router 10Mb 10ms DropTail

$ns duplex-link $client3 $router 10Mb 10ms DropTail

$ns duplex-link $router $server 50Mb 10ms DropTail

# Define traffic for Client 1 (FTP – File Transfer)

set tcp_client1 [new Agent/TCP]

$ns attach-agent $client1 $tcp_client1

set tcp_sink [new Agent/TCPSink]

$ns attach-agent $server $tcp_sink

$ns connect $tcp_client1 $tcp_sink

set ftp_client1 [new Application/FTP]

$ftp_client1 attach-agent $tcp_client1

# Define traffic for Client 2 (Web Browsing – CBR Traffic)

set tcp_client2 [new Agent/TCP]

$ns attach-agent $client2 $tcp_client2

set tcp_sink2 [new Agent/TCPSink]

$ns attach-agent $server $tcp_sink2

$ns connect $tcp_client2 $tcp_sink2

set cbr_client2 [new Application/Traffic/CBR]

$cbr_client2 attach-agent $tcp_client2

$cbr_client2 set packetSize_ 512

$cbr_client2 set rate_ 1Mb

$cbr_client2 set interval_ 0.05

# Define traffic for Client 3 (Video Streaming – UDP Traffic)

set udp_client3 [new Agent/UDP]

$ns attach-agent $client3 $udp_client3

set udp_sink [new Agent/Null]

$ns attach-agent $server $udp_sink

$ns connect $udp_client3 $udp_sink

set cbr_client3 [new Application/Traffic/CBR]

$cbr_client3 attach-agent $udp_client3

$cbr_client3 set packetSize_ 1000

$cbr_client3 set rate_ 2Mb

$cbr_client3 set interval_ 0.01

# Schedule the traffic flows

$ns at 0.5 “$ftp_client1 start”

$ns at 1.0 “$cbr_client2 start”

$ns at 1.5 “$cbr_client3 start”

# Schedule the stop time for traffic

$ns at 4.0 “$ftp_client1 stop”

$ns at 4.0 “$cbr_client2 stop”

$ns at 4.0 “$cbr_client3 stop”

# End the simulation at 5.0 seconds

$ns at 5.0 “finish”

# Define finish procedure to close trace files and execute NAM for visualization

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam network_neutrality.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Node Setup:
    • We state nodes for three clients (client1, client2, client3), a router, and a server.
    • The router behaves like an intermediate node that forwards traffic amongst the clients and the server.
  2. Link Setup:
    • Duplex links with 10Mb bandwidth and 10ms delay are configured amongst the clients and the router.
    • A 50Mb link connects the router to the server, making sure that there is enough volume to manage traffic from all clients.
  3. Traffic Simulation:
    • Client 1 (FTP) replicates file transmit traffic using a TCP agent and FTP application.
    • Client 2 (Web Browsing) imitates web browsing traffic using a TCP agent and CBR (Constant Bit Rate) application.
    • Client 3 (Video Streaming) mimics video streaming traffic using a UDP agent and CBR application with a larger packet size and higher data rate.
  4. Traffic Scheduling:
    • The traffic flows begins at various times (to simulate a more realistic scenario) and finish at 4.0 seconds.
    • The simulation executes for 5.0 seconds, and a trace file (network_neutrality.tr) is produced for analysis.
  5. Equal Resource Allocation:
    • All traffic flows are treated equally, meaning that no traffic is preferred over the others. The DropTail queuing discipline is used, making certain that all packets are treated the same according to the queuing and dispatching.
  1. Analyzing Network Neutrality in the Simulation

Once the simulation is established, the trace file (network_neutrality.tr) can be assessed to verify whether all traffic types (FTP, web browsing, and video streaming) gets equal treatment. You can look at:

  • Throughput: The total of data successfully transferred for each traffic type.
  • Latency: The delay experienced by packets when move through the network.
  • Packet Loss: Whether any packets were dropped because of congestion or queue overflow.

Process the trace file and extract these performance metrics by using tools like awk or Python to.

Example: Analyzing Throughput Using awk

# Calculate total throughput for FTP traffic

awk ‘$4 == “tcp” && $1 == “r” { total_bytes += $5 } END { print “Throughput: “, total_bytes/5, “bytes/sec” }’ network_neutrality.tr

This script computes the total throughput for TCP traffic (indicating the FTP and web browsing traffic) by counting size of the received packets.

  1. Ensuring Network Neutrality

In this simulation:

  • Equal treatment is ensured by using the DropTail queuing discipline, which does not prioritize packets based on type or origin.
  • No Prioritization: All traffic is managed in the same way by the router and server. This reflects the principle of network neutrality, where no service or application is given privileged treatment.
  • Bandwidth and Queuing: All traffic shares the same links with equal bandwidth allocation.
  1. Advanced Features

You can extend the simulation by:

  • Simulating Violations of Network Neutrality: Launch traffic prioritization for particular kinds of traffic like video streaming, to replicate a violation of network neutrality. For instance, use priority queuing to give priority to one type of traffic over another.
  • Testing Under Congestion: Decrease the existed bandwidth or maximize the traffic load to mimic congestion and monitor how each traffic type is influenced.
  • Multiple Routers: Inculde more routers and simulate a more advanced network topology.

Example: Simulating a Violation of Network Neutrality Using Priority Queuing

# Enable priority queuing on the router for video streaming traffic

$ns queue-limit $router 20

$ns queue-type $router Queue/PriQueue

In this case, the router would prefer video streaming traffic over other types, simulating a defilement of network neutrality.

Overall, we have comprehensively presented every details and instructions to help you understand the implementation of Network Neutrality which is nothing but every variants of traffic should be treated equally without any favouritism. With this, you can establish this into the simulation.

Our team focuses on treating all projects equally when it comes to how we manage bandwidth, queuing, and dispatching. Just let us know what you need, and we’ll help you out! If you need extra help with implementing Network Neutrality using the NS2 tool, you can check out ns2project.com for more advice. We can also help you with performance analysis.