How to Implement Network Digital Twins in NS2

To implement the Network Digital Twins is denotes the virtual replicas of the physical networks, permitting the network administrators to replicate, observe, and also enhance the real-world networks in a controlled environment. In the context of NS2, executing it that includes making a simulation, which mirrors the performance and features of a real network. It encompasses replicating a real-world traffic patterns, failures, routing protocols, and performance metrics to forecast the performance of the real network under various conditions. The following steps are guide you on how to execute the network digital twins within NS2 simulation environment:

To implement Network Digital Twins in NS2, the below steps are normally involved:

  1. Create a Digital Twin of the Physical Network: Configure a nodes, links, and protocols within NS2, which simulate the topology, traffic, and behaviour of the actual network.
  2. Simulate Traffic Patterns: We use the data from the real network to replicate the normal traffic flows, loads, and conditions.
  3. Monitor and Analyze Performance: Gather the performance metrics such as throughput, delay, packet loss, and jitter from both the replicated and actual networks.
  4. Predict and Optimize: We can use the digital twin to simulate various situations like network failures, congestion, or new traffic patterns, and enhance network performance.
  5. Feedback and Adaptation: Adjust the simulation according to the real-time data from the physical network, creating the digital twin a dynamic and changing the model.

Steps to Implement a Network Digital Twin in NS2

  1. Define the Network Topology: Simulate the physical network’s topology within NS2 by configuring the nodes, links, and traffic patterns.
  2. Generate Traffic: Replicate the traffic flow in the network rely on real-world informations.
  3. Monitor Network Metrics: Gather the metrics like throughput, latency, and packet loss in both the real and simulated environments.
  4. Simulate Network Conditions: Model various situations like network failures, congestion, or traffic spikes in the digital twin and estimate their effect.
  5. Analyze and Compare: Compare the performance of the digital twin in the real network and we can use the outcomes to forecast future performance and enhance the behaviour.

Example: Implementing a Network Digital Twin in NS2

We will be replicated a small network topology within NS2, which mirrors the real-world setup. We will observe and simulate the traffic, routing protocols, and the performance metrics.

Example TCL Script for Simulating a Network Digital Twin:

# Create a new NS2 simulator instance

set ns [new Simulator]

# Define the output trace file for logging events

set tracefile [open digital_twin.tr w]

$ns trace-all $tracefile

# Define the animation file for NAM (optional)

set namfile [open digital_twin.nam w]

$ns namtrace-all $namfile

# Create network nodes: Clients, routers, and a server (replicating a real-world topology)

set client1 [$ns node]

set client2 [$ns node]

set router1 [$ns node]

set router2 [$ns node]

set server [$ns node]

# Create links between the nodes to replicate the physical network topology

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

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

$ns duplex-link $router1 $router2 50Mb 20ms DropTail

$ns duplex-link $router2 $server 100Mb 10ms DropTail

# —————- Traffic Simulation Based on Real Data —————-

# Define traffic for Client 1 (Simulate TCP traffic based on real-world traffic patterns)

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 (Simulate UDP traffic representing real-world video streaming)

set udp_client2 [new Agent/UDP]

$ns attach-agent $client2 $udp_client2

set udp_sink [new Agent/Null]

$ns attach-agent $server $udp_sink

$ns connect $udp_client2 $udp_sink

set cbr_client2 [new Application/Traffic/CBR]

$cbr_client2 attach-agent $udp_client2

$cbr_client2 set packetSize_ 1000

$cbr_client2 set rate_ 2Mb

$cbr_client2 set interval_ 0.01

# —————- Simulation Control —————-

# Schedule the start of traffic

$ns at 0.5 “$ftp_client1 start”

$ns at 0.5 “$cbr_client2 start”

# Schedule the stop time for traffic

$ns at 4.0 “$ftp_client1 stop”

$ns at 4.0 “$cbr_client2 stop”

# End the simulation at 5.0 seconds

$ns at 5.0 “finish”

# Define a 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 digital_twin.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Node Setup: The topology contain the two clients, two routers, and one server that signifying the real-world network. The links among them replicate the real network’s bandwidth and latency characteristics.
  2. Traffic Simulation: We replicate the traffic flows that mirror the real-world network:
    • Client 1 generates TCP traffic using an FTP application, mimicking file transfers.
    • Client 2 generates UDP traffic using a CBR (Constant Bit Rate) application that replicating real-time video streaming.
  3. Data Collection: The trace file (digital_twin.tr) will record all network events that can be examined for network performance metrics.
  4. Simulation Control: The traffic begins at 0.5 seconds and ends at 4.0 seconds. The simulation stops at 5.0 seconds, and the outcomes are logged in the trace file.
  1. Monitoring and Analyzing Network Performance

The digital twin simulation creates a trace file, which comprises thorough data concerning the packet transmissions, receptions, and losses. The given metrics can be extracted and compared with the actual network:

  1. a) Throughput Calculation:

We can be estimated the throughput for TCP traffic:

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

Above command computes the entire bytes received when the simulation and split it by the replication duration to obtain the average throughput.

  1. b) Packet Loss:

We can assess the number of dropped packets in the simulation:

awk ‘$1 == “d” { total_dropped++ } END { print “Packet Loss: “, total_dropped }’ digital_twin.tr

Above command counts the total number of dropped packets.

  1. c) Latency:

We can evaluate the average latency for TCP traffic:

awk ‘

/^s/ && $4 == “tcp” { sent[$6] = $2 }

/^r/ && $4 == “tcp” { if ($6 in sent) { total_delay += ($2 – sent[$6]); total_packets++ } }

END { print “Average Latency: “, total_delay/total_packets, “seconds” }’ digital_twin.tr

Above script estimates the average latency by following the forward and receive time of every packet.

  1. Simulating Network Conditions

When the digital twin is configure, we can be replicated various situation, like:

  • Network Congestion: Introduce congestion by maximizing the traffic rate or minimizing bandwidth and monitor how the digital twin responds.
  • Link Failures: Replicate link failures by momentarily disconnecting links among the routers or clients.
  • Load Balancing: Execute load balancing over several links and estimate how the digital twin manages differing the traffic loads.

Example: Simulating Link Failure

# Simulate a link failure between Router 1 and Router 2 at 2.0 seconds

$ns at 2.0 “$ns rtmodel-at 2.0 down $router1 $router2”

# Re-establish the link at 3.0 seconds

$ns at 3.0 “$ns rtmodel-at 3.0 up $router1 $router2”

  1. Feedback Loop from Real Network to Digital Twin

To create the digital twin more dynamic and precise, we can feed real-time data from the physical network into the NS2. It could be contained:

  • Real-Time Traffic Data: We can use the traffic data from the real network to change the traffic patterns in the digital twin.
  • Performance Data: Compare the performance of the digital twin with the real network and modify the replication metrics rely on the real-world observations (e.g., link delays, traffic spikes).
  1. Advanced Features for Digital Twins

To improve the digital twin further, we can:

  • Dynamic Routing: We use the dynamic routing protocols (e.g., AODV, OSPF) to reflect real-world routing behaviours within the digital twin.
  • Real-Time Data Synchronization: Endlessly synchronize the real-world network conditions including the digital twin to predict issues in real time.
  • Optimization Simulations: We can use the digital twin to analyse and enhance the new sets up before using them in the physical network.

As demonstrated above, we executed the implementation and estimation of Network Digital Twins deploying the simplified procedure within NS2. Likewise, we will deliver more comprehensive information on this topic in upcoming manual.

Our experts work on real-world traffic patterns, failures, routing protocols, and performance metrics  for your projects so get best ideas by staying in touch with us .