To simulate an Edge Computing projects using NS3, which encompasses modeling the deployment of computational resources at the network edge (closer to the end-users), minimizing latency and then enhancing the efficiency of applications like IoT, content delivery, and data processing. Below, we provide basic method on how we can simulate an edge computing scenario using NS3:
Steps to Simulate Edge Computing in NS-3
- Set Up the NS3 Environment
Initially, make certain that we have NS3 installed and set up on the system. We follow the installation instructions from the NS3 official site. Construct the NS3 using the below commands:
./waf configure
./waf build
- Define the Network Topology
In an edge computing simulation, the topology contains:
- End devices (Clients/IoT devices): Devices which generate data or request services.
- Edge nodes (Edge Servers): Nodes that process data or serve client requests.
- Cloud nodes: Centralized servers that manage the requests which the edge nodes cannot process.
We want to make these nodes using NodeContainer in NS3.
NodeContainer clients;
clients.Create(10); // 10 IoT or end-user devices
NodeContainer edgeServers;
edgeServers.Create(3); // 3 edge servers
NodeContainer cloudServer;
cloudServer.Create(1); // 1 central cloud server
- Network Configuration
Configure the network among clients, edge servers, and the cloud. It can be a combination of point-to-point links, Wi-Fi links, or CSMA links, based on the particular use case.
Point-to-Point Connections:
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
// Connect each client to its corresponding edge server
for (uint32_t i = 0; i < clients.GetN(); ++i) {
NetDeviceContainer devices;
devices = p2p.Install(clients.Get(i), edgeServers.Get(i % edgeServers.GetN()));
}
// Connect edge servers to the cloud
NetDeviceContainer cloudLink;
cloudLink = p2p.Install(edgeServers.Get(0), cloudServer.Get(0)); // Edge server 0 to cloud
- Install Internet Stack
Install the Internet stack on all nodes (clients, edge servers, and cloud server) to permit communication.
InternetStackHelper internet;
internet.Install(clients);
internet.Install(edgeServers);
internet.Install(cloudServer);
- Assign IP Addresses
We can use Ipv4AddressHelper to allocate an IP addresses to the devices on each link.
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
for (uint32_t i = 0; i < clients.GetN(); ++i) {
NetDeviceContainer devices = p2p.Install(clients.Get(i), edgeServers.Get(i % edgeServers.GetN()));
Ipv4InterfaceContainer interfaces = address.Assign(devices);
address.NewNetwork();
}
Ipv4InterfaceContainer cloudInterfaces;
cloudInterfaces = address.Assign(cloudLink);
- Edge Processing Logic
In an edge computing simulation, we will likely have some form of data offloading or processing at the edge servers. The clients can be either transmitted the data to the edge servers for processing or, if the edge server cannot manage the request then forward the data to the cloud.
To replicate it we can use a custom application, which decides whether to offload data to the edge or to the cloud rely on factors such as:
- Latency
- Processing capability at the edge
For instance, we can replicate a request using the BulkSendHelper to transmit data to the edge server:
uint16_t port = 9;
Address edgeAddress(InetSocketAddress(edgeInterfaces.GetAddress(0), port));
BulkSendHelper bulkSend(“ns3::TcpSocketFactory”, edgeAddress);
bulkSend.SetAttribute(“MaxBytes”, UintegerValue(0)); // Unlimited data transfer
ApplicationContainer sourceApps = bulkSend.Install(clients.Get(0));
sourceApps.Start(Seconds(1.0));
sourceApps.Stop(Seconds(10.0));
Likewise, if the edge server requires to offload the task to the cloud:
Address cloudAddress(InetSocketAddress(cloudInterfaces.GetAddress(0), port));
BulkSendHelper bulkSendToCloud(“ns3::TcpSocketFactory”, cloudAddress);
bulkSendToCloud.SetAttribute(“MaxBytes”, UintegerValue(0)); // Unlimited data transfer
ApplicationContainer edgeApps = bulkSendToCloud.Install(edgeServers.Get(0));
edgeApps.Start(Seconds(2.0));
edgeApps.Stop(Seconds(10.0));
- Simulate Edge-Centric Applications
Based on the use case, we may replicate various kinds of applications which benefit from edge computing:
- IoT Applications: Sensors are generating data which is processed at the edge.
- Video Streaming: Clients are requesting video content from edge servers with caching capabilities.
- Computation Offloading: Clients offloading computational tasks to edge servers.
To replicate these scenarios, we change the application layer utilising NS3’s existing applications such as OnOffApplication, PacketSink, or make a custom application.
- Measure Performance Metrics
Gather performance data like:
- Latency: Estimate the time taken to process data at the edge against sending it to the cloud.
- Throughput: The total amount of data processed at the edge and cloud.
- Offload Ratio: How much data is processed at the edge compared to the cloud.
We use NS3’s FlowMonitor to gather such metrics:
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
You can analyze the collected data after the simulation finishes:
monitor->SerializeToXmlFile(“edge-computing-simulation.xml”, true, true);
- Run the Simulation
Here, we run the simulation using the NS3 simulation engine:
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
Example Code Structure
The following is an instance structure of an NS3 simulation, which models a basic edge computing setup:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main (int argc, char *argv[]) {
NodeContainer clients, edgeServers, cloudServer;
clients.Create(10); // IoT or end-user devices
edgeServers.Create(3); // Edge servers
cloudServer.Create(1); // Central cloud server
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
InternetStackHelper internet;
internet.Install(clients);
internet.Install(edgeServers);
internet.Install(cloudServer);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
// Connect clients to edge servers
for (uint32_t i = 0; i < clients.GetN(); ++i) {
NetDeviceContainer devices;
devices = p2p.Install(clients.Get(i), edgeServers.Get(i % edgeServers.GetN()));
Ipv4InterfaceContainer interfaces = address.Assign(devices);
address.NewNetwork();
}
// Connect edge servers to cloud server
NetDeviceContainer cloudLink;
cloudLink = p2p.Install(edgeServers.Get(0), cloudServer.Get(0));
Ipv4InterfaceContainer cloudInterfaces = address.Assign(cloudLink);
uint16_t port = 9;
Address edgeAddress(InetSocketAddress(cloudInterfaces.GetAddress(0), port));
BulkSendHelper bulkSend(“ns3::TcpSocketFactory”, edgeAddress);
bulkSend.SetAttribute(“MaxBytes”, UintegerValue(0)); // Unlimited data transfer
ApplicationContainer clientApps = bulkSend.Install(clients.Get(0));
clientApps.Start(Seconds(1.0));
clientApps.Stop(Seconds(10.0));
PacketSinkHelper packetSinkHelper(“ns3::TcpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), port));
ApplicationContainer sinkApps = packetSinkHelper.Install(edgeServers.Get(0));
sinkApps.Start(Seconds(0.0));
sinkApps.Stop(Seconds(10.0));
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Advanced Features (Optional):
- Dynamic Task Offloading: Execute the logic in which tasks are actively offloaded to edge or cloud rely on network conditions or resource availability.
- Caching Mechanism: Replicate caching at the edge to minimize latency for content requests.
- Multi-access Edge Computing (MEC): Combine MEC concepts in which the edge servers are offer both compute and storage for various kinds of applications such as AR/VR or real-time analytics.
At the end, utilising above replication approach with sample coding in NS3 virtual environment we had replicated the Edge Computing projects. If you acquire any query on this projects, we will clear it.
If you want to simulate edge computing projects using the NS3 tool, check out phdprime.com. We offer the best simulation results! Just send us your project details, and we’ll help you get the best outcomes. We specialize in IoT, content delivery, and data processing, so keep in touch with us for great advice.