How to Implement Network Line Switching in NS2

To implement the Network Line Switching (Circuit Switching) in Network Simulator 2 (NS2), we need to replicate a network that contains a dedicated communication path which is accomplished amongst nodes before the data transmission. This path residues reserved until the communication is done, emulating a circuit-switched network similar to old fashioned telephony systems. NS2 is mainly built for packet-switched networks, yet you can replicate circuit-switching activities by handling resource reservation (like bandwidth) for the duration of the communication.

Follow the offered guide to implementing network line switching (circuit switching) in NS2:

Step-by-Step Implementation:

  1. Set Up the Simulation Environment

Begin by configuring the simplified network environment in ns2 to set up the nodes, links and the parameters like bandwidth and delay. The link amongst nodes will indicate the lines used in the circuit-switched networks.

Example TCL Script for Basic Setup:

# Create a simulator instance

set ns [new Simulator]

# Define link parameters

set bw 1Mb         ;# Bandwidth for each link (can be modified based on the scenario)

set delay 10ms     ;# Delay for each link

# Create nodes (representing network endpoints and switches)

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

# Create links between nodes (representing the circuit-switched connections)

$ns duplex-link $node1 $node2 $bw $delay DropTail

$ns duplex-link $node2 $node3 $bw $delay DropTail

$ns duplex-link $node3 $node4 $bw $delay DropTail

This configuration builds a basic topology with four nodes linked in a linear fashion, denoting a dedicated path in a circuit-switched network.

  1. Simulate Circuit Establishment

In circuit switching, a dedicated path must be accomplished before data transmission begins. We can simulate this by reserving the essential bandwidth for the communication session. We can emulate it by making sure that no other traffic intrudes with the scheduled path because the NS2 lacks the circuit switching natively.

Simulating the Circuit Establishment Process:

# Simulate circuit setup by reserving the path between node1 and node4

proc circuit_setup {src dst} {

global ns

 

# Ensure that no other traffic is allowed on the links during the communication

puts “Circuit setup from $src to $dst”

}

# Simulate the process of reserving the bandwidth between node1 and node4

circuit_setup $node1 $node4

This procedure replicates the circuit setup process by accomplishing a dedicated path amongst the source and destination nodes.

  1. Create Traffic for Circuit-Switched Communication

Once the circuit is completed, the source node can begin transmitting data to the destination node using the dedicated path. You can use TCP or UDP agents together with CBR (Constant Bit Rate) to model the data transmission and replicate the continuous communication through the circuit.

Example of Creating Traffic for Circuit-Switched Communication:

# Create a UDP agent for node1 (source)

set udp1 [new Agent/UDP]

$ns attach-agent $node1 $udp1

# Create a traffic generator (CBR) to simulate circuit-switched communication

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packet_size_ 1000   ;# Packet size in bytes

$cbr1 set rate_ 512Kb         ;# Data rate

$cbr1 attach-agent $udp1

# Create a UDP sink (receiver) at node4

set null1 [new Agent/Null]

$ns attach-agent $node4 $null1

# Connect the UDP source at node1 to the sink at node4

$ns connect $udp1 $null1

# Start and stop the traffic

$ns at 1.0 “$cbr1 start”

$ns at 10.0 “$cbr1 stop”

This configuration imitates the data transmission amongst node1 and node4 using the established circuit.

  1. Simulate Circuit Teardown

After the communication is complete, the circuit is typically torn down, and the resources (like bandwidth) are released. You can simulate this by freeing up the reserved bandwidth and permitting other traffic to use the links.

Simulating Circuit Teardown:

# Simulate circuit teardown by releasing the path between node1 and node4

proc circuit_teardown {src dst} {

global ns

# Allow other traffic to use the links after the circuit is torn down

puts “Circuit teardown from $src to $dst”

}

# Simulate the process of releasing the bandwidth between node1 and node4

$ns at 11.0 “circuit_teardown $node1 $node4”

This procedure mimics the circuit teardown process, freeing up resources after the communication is complete.

  1. Add Additional Traffic (Optional)

To simulate contention for the network resources, you can use the same links by including other traffic that tries. In a circuit-switched network, this traffic would be congested or delayed until the circuit is torn down and the resources are existed.

Example of Adding Additional Traffic:

# Create additional traffic that tries to use the same links after the circuit is torn down

set udp2 [new Agent/UDP]

$ns attach-agent $node2 $udp2

# Create a second CBR traffic generator

set cbr2 [new Application/Traffic/CBR]

$cbr2 set packet_size_ 1000

$cbr2 set rate_ 512Kb

$cbr2 attach-agent $udp2

# Create a sink for the additional traffic at node3

set null2 [new Agent/Null]

$ns attach-agent $node3 $null2

# Connect the additional traffic between node2 and node3

$ns connect $udp2 $null2

# Start the additional traffic after the circuit is torn down

$ns at 12.0 “$cbr2 start”

$ns at 20.0 “$cbr2 stop”

This mimics additional traffic trying to use the network links after the circuit has been released.

  1. Monitor and Trace the Simulation

To observe the activities of the circuit-switched network and assess performance, enable tracing in NS2. The trace file will capture events like packet transmissions, delays, and link utilization.

Enable Trace Files:

# Enable tracing for the simulation

set tracefile [open “circuit_switch_trace.tr” w]

$ns trace-all $tracefile

# Define a finish procedure to end the simulation and close the trace file

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Set the simulation end time

$ns at 20.0 “finish”

The trace file will record all network events, permitting you to assess the circuit-switched communication and the additional traffic after the circuit is released.

  1. Run the Simulation

Finally, execute the simulation to see the circuit-switched communication, the setup and teardown of the circuit, and the actions of additional traffic.

# Run the simulation

$ns run

Example Complete TCL Script for Circuit Switching in NS2

# Create a simulator instance

set ns [new Simulator]

# Define link parameters

set bw 1Mb

set delay 10ms

# Create nodes (representing network endpoints and switches)

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

# Create links between nodes

$ns duplex-link $node1 $node2 $bw $delay DropTail

$ns duplex-link $node2 $node3 $bw $delay DropTail

$ns duplex-link $node3 $node4 $bw $delay DropTail

# Simulate circuit setup by reserving the path between node1 and node4

proc circuit_setup {src dst} {

puts “Circuit setup from $src to $dst”

}

circuit_setup $node1 $node4

# Create UDP agent for circuit-switched communication

set udp1 [new Agent/UDP]

$ns attach-agent $node1 $udp1

# Create a CBR traffic generator for circuit-switched communication

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packet_size_ 1000

$cbr1 set rate_ 512Kb

$cbr1 attach-agent $udp1

# Create a UDP sink at node4

set null1 [new Agent/Null]

$ns attach-agent $node4 $null1

# Connect the source (node1) to the sink (node4)

$ns connect $udp1 $null1

# Start and stop the circuit-switched traffic

$ns at 1.0 “$cbr1 start”

$ns at 10.0 “$cbr1 stop”

# Simulate circuit teardown by releasing the path between node1 and node4

proc circuit_teardown {src dst} {

puts “Circuit teardown from $src to $dst”

}

$ns at 11.0 “circuit_teardown $node1 $node4”

# Add additional traffic that tries to use the same links after the circuit is torn down

set udp2 [new Agent/UDP]

$ns attach-agent $node2 $udp2

set cbr2 [new Application/Traffic/CBR]

$cbr2 set packet_size_ 1000

$cbr2 set rate_ 512Kb

$cbr2 attach-agent $udp2

set null2 [new Agent/Null]

$ns attach-agent $node3 $null2

$ns connect $udp2 $null2

# Start the additional traffic after the circuit is torn down

$ns at 12.0 “$cbr2 start”

$ns at 20.0 “$cbr2 stop”

# Enable tracing

set tracefile [open “circuit_switch_trace.tr” w]

$ns trace-all $tracefile

# End simulation

$ns at 20.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

In this manual, we gathered the essential details which will help you to implement the Network Line Switching in ns2 with sample snippets. It includes how to set up simulation scenario and how to set up the circuit establishment with examples. We have an intent to provide extra details on this switching. ns2project.com provide effective execution of  Network Line Switching in ns2  solutions specifically designed for your project. Our dedicated team will efficiently manage the performance analysis to meet your unique requirements.