How to Simulate Edge Computing Projects Using NS2

To simulate an Edge Computing projects using NS2 (Network Simulator 2)  that contains making a network in which computing resources are placed closer to end users at the edge of the network, minimizing latency and bandwidth usage compared to cloud computing. Edge computing normally encompasses devices such as edge servers or gateways, which process data near the source instead of transmitting it to a centralized cloud server.

Below is a guide on how to replicate an Edge Computing projects using NS2, with a concentrate on how to configure an edge network and model edge processing.

Steps to Simulate Edge Computing Projects in NS2

  1. Install NS2
  • We can download and install NS2 from the official NS2 website.
  • Make sure that essential libraries like Tcl/Tk and NAM (Network Animator) are installed to run and envision the simulation.
  1. Understand Edge Computing Concepts
  • Edge Devices: These are normally IoT devices, mobile phones, or other sensors, which generate data and may execute lightweight processing.
  • Edge Servers/Gateways: These are the servers at the edge of the network, which process the data generated by edge devices, minimizing the want to transmit data to centralized cloud servers.
  • Cloud Server: The cloud server can still be part of the network, however only for tasks that cannot be processed locally at the edge.
  1. Define the Edge Computing Topology

In NS2, we can make a hierarchical topology in which edge devices (sensors, IoT devices, etc.) are connect to edge servers for local processing. These edge servers are associated to a centralized cloud server for any more processing, which cannot be managed at the edge.

Example OTcl Code for Edge Computing Topology:

# Create a simulator instance

set ns [new Simulator]

# Define the topography (grid for the edge and cloud devices)

set topo [new Topography]

$topo load_flatgrid 1000 1000

# Create edge devices (e.g., IoT devices or mobile devices)

set edge_device_1 [$ns node]

set edge_device_2 [$ns node]

set edge_device_3 [$ns node]

# Create edge server (closer to the edge devices)

set edge_server [$ns node]

# Create cloud server (centralized location for non-local processing)

set cloud_server [$ns node]

# Set up links between edge devices and edge server (fast, local connection)

$ns duplex-link $edge_device_1 $edge_server 10Mb 5ms DropTail

$ns duplex-link $edge_device_2 $edge_server 10Mb 5ms DropTail

$ns duplex-link $edge_device_3 $edge_server 10Mb 5ms DropTail

# Set up link between edge server and cloud server (slower, higher latency)

$ns duplex-link $edge_server $cloud_server 1Gb 100ms DropTail

In this example:

  • Edge devices that denote IoT devices, smartphones, or sensors.
  • Edge server manages local processing and offers a link among the edge devices and the cloud.
  • Cloud server is utilized for processing, which cannot be managed at the edge.
  • Links among edge devices and edge servers have lower latency, even though the connection among the edge server and cloud has higher latency.
  1. Configure TCP/UDP Agents for Data Transmission

Edge devices normally transmit informations to the edge server using TCP or UDP protocols. We can replicate data transmission using these agents in NS2.

Example: Setting Up TCP Agents for Data Transmission

# Create TCP agent at edge device 1 (simulating data sent from edge device)

set tcp_device1 [new Agent/TCP]

$tcp_device1 set class_ 2  ;# Class 2 is TCP Reno by default

$ns attach-agent $edge_device_1 $tcp_device1

# Create TCP sink at the edge server (to receive data from the edge device)

set tcp_sink [new Agent/TCPSink]

$ns attach-agent $edge_server $tcp_sink

# Connect the TCP agent and TCP sink

$ns connect $tcp_device1 $tcp_sink

In this example:

  • A TCP agent is made at the edge device to replicate data being transmitted from the device to the edge server.
  • A TCP sink is made at the edge server to receive the data from the edge device.
  1. Simulate Data Processing at the Edge

To replicate edge processing, we can launch a delay to signify the time taken by the edge server to process the data.

Example: Simulating Edge Processing Delay

# Function to simulate data processing delay at the edge server

proc simulate_edge_processing {pkt} {

global ns

set processing_delay [expr rand() * 50]  ;# Random delay to simulate processing (e.g., 0-50 ms)

$ns at [$ns now + $processing_delay] “forward_to_cloud $pkt”

}

# Function to simulate forwarding data to the cloud after edge processing

proc forward_to_cloud {pkt} {

puts “Data processed at edge, forwarding to cloud if necessary”

# Normally forward the packet to the cloud server here

}

In this example:

  • The simulate_edge_processing function launches a random delay to denote edge processing time.
  • After processing, the data can be sent to the cloud server if required.
  1. Simulate Data Offloading to the Cloud

Not all data can be processed at the edge; sometimes, it requires to be transmitted to the cloud for further processing. We can replicate it by sending packets from the edge server to the cloud server after processing.

Example: Forwarding Data to Cloud Server

# Create a TCP agent at the edge server for forwarding data to the cloud

set tcp_edge_to_cloud [new Agent/TCP]

$ns attach-agent $edge_server $tcp_edge_to_cloud

# Create a TCP sink at the cloud server

set tcp_sink_cloud [new Agent/TCPSink]

$ns attach-agent $cloud_server $tcp_sink_cloud

# Connect the TCP agent at the edge server to the cloud sink

$ns connect $tcp_edge_to_cloud $tcp_sink_cloud

This code mimics the edge server sending data to the cloud server after it has been processed at the edge.

  1. Run the Simulation

We can save the simulation script as edge_computing_simulation.tcl and then we can run it using the NS2 command:

ns edge_computing_simulation.tcl

  1. Analyse the Results

NS2 generates trace files, which log all network events, like data transmission, delays, and processing times. We can examine these trace files to calculate performance parameters such as:

  • Latency: The time taken to process data at the edge and/or cloud.
  • Throughput: The amount of data processed by the edge server and cloud.
  • Data Offloading: The percentage of data, which was processed at the edge against forwarded to the cloud.

Example: Analyse Trace Files Using Awk

awk -f analyze_trace.awk edge_computing_simulation.tr

  1. Visualize the Simulation Using NAM

We can be used Network Animator (NAM) to envision the interaction among the edge devices, edge servers, and the cloud server. NAM can indicate data flows and processing delays.

nam edge_computing_simulation.nam

  1. Advanced Edge Computing Features to Simulate

We can expand the edge computing simulation to contain more advanced aspects:

  • Load Balancing: Replicate several edge servers, which balance the load among them according to data traffic.
  • Dynamic Offloading: Execute decision-making logic to find out whether data should be processed at the edge or transmitted to the cloud.
  • Edge Failures: Mimic edge server failures and monitor how the system manages data processing when an edge server is unobtainable.
  • Edge AI/ML Processing: Replicate lightweight AI/ML models running on edge servers to process data locally, minimizing the amount transmitted to the cloud.
  • QoS (Quality of Service): Execute traffic prioritization to make certain critical data is processed faster at the edge.

Example Simulation Script Outline for Edge Computing

# Edge Computing Simulation Script using NS2

set ns [new Simulator]

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Define the topology area

# Create edge devices (IoT devices)

set edge_device_1 [$ns node]

set edge_device_2 [$ns node]

# Create edge server (closer to edge devices)

set edge_server [$ns node]

# Create cloud server (for non-local processing)

set cloud_server [$ns node]

# Set up links between edge devices and edge server

$ns duplex-link $edge_device_1 $edge_server 10Mb 5ms DropTail

$ns duplex-link $edge_device_2 $edge_server 10Mb 5ms DropTail

# Set up link between edge server and cloud server

$ns duplex-link $edge_server $cloud_server 1Gb 100ms DropTail

# Create TCP agents for edge device to edge server communication

set tcp_device1 [new Agent/TCP]

$ns attach-agent $edge_device_1 $tcp_device1

set tcp_sink_edge [new Agent/TCPSink]

$ns attach-agent $edge_server $tcp_sink_edge

$ns connect $tcp_device1 $tcp_sink_edge

# Create an FTP application to simulate data being sent from edge device 1

set ftp_device1 [new Application/FTP]

$ftp_device1 attach-agent $tcp_device1

# Start data transmission from edge device at time 1.0 seconds

$ns at 1.0 “$ftp_device1 start”

# Function to simulate edge processing delay

proc simulate_edge_processing {pkt} {

global ns

set delay [expr rand() * 50]

$ns at [$ns now + $delay] “forward_to_cloud $pkt”

}

# Function to forward data to cloud after edge processing

proc forward_to_cloud {pkt} {

puts “Data processed at edge, forwarding to cloud”

}

# End the simulation after 10 seconds

$ns at 10.0 “finish”

# Run the simulation

$ns run

Key Points:

  • Edge Devices and Servers: Replicate a hierarchical edge computing network with devices transmitting data to neighbouring edge servers for processing.
  • Cloud Integration: Model data offloading from edge servers to the cloud for more processing when required.
  • Edge Processing: Launch processing delays to replicate local data processing at the edge.
  • Performance Metrics: Examine latency, throughput, and the distribution of processing among edge and cloud servers.

We presented a detailed stepwise execution strategy for Edge Computing Projects, simulated, analysed its outcomes, and visualized the simulation using NS2 tool. We can deliver additional in-depth analysis and details on this subject, if necessary.

We focus on simulations tailored to your project. Please provide us with all relevant details, and we will assist you with a comprehensive explanation.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2