To develop the OSI Layer Protocol used in NS3. We create the OSI layer protocol a project in NS3 needs recognize on how well changed the layers for OSI model plan to NS3 modules. Below is structured to guide the employ an OSI layer protocols using NS3.
Steps to Develop OSI Layer Protocol Projects Using NS3
- Understanding OSI Layers in NS3
We Recording the OSI Model to NS3 Modules
OSI Layer | NS-3 Component |
Physical (Layer 1) | Wi-Fi, LTE, CSMA, PPP |
Data Link (Layer 2) | CSMA/CD, MAC protocols |
Network (Layer 3) | IPv4, IPv6, Routing Protocols (AODV, OSPF, RIP) |
Transport (Layer 4) | TCP, UDP |
Session (Layer 5) | Socket API, Application-Specific Protocols |
Presentation (Layer 6) | Data Encoding, Encryption |
Application (Layer 7) | HTTP, FTP, VoIP, MQTT |
- Setting Up NS3
(a) Install and download the NS3 for your system
sudo apt update
sudo apt install git g++ python3 python3-pip cmake
git clone
cd ns-3-dev
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Developing OSI Layer Protocols
(A) Physical Layer (Layer 1) Protocols
- In NS-3, the Physical Layer is replicated for using the Wi-Fi, LTE, CSMA, and Point-to-Point.
- Example: Replicate a Simple Wired LAN using CSMA (Ethernet)
Example: Implementing Layer 1 (Physical Layer)
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/csma-module.h”
#include “ns3/internet-module.h”
using namespace ns3;
int main() {
NodeContainer nodes;
nodes.Create(4);
CsmaHelper csma;
csma.SetChannelAttribute(“DataRate”, StringValue(“100Mbps”));
csma.SetChannelAttribute(“Delay”, TimeValue(NanoSeconds(6560)));
NetDeviceContainer devices;
devices = csma.Install(nodes);
InternetStackHelper stack;
stack.Install(nodes);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Replicate for execute the result process for this approach
./waf –run “scratch/layer1_example”
(B) Data Link Layer (Layer 2) Protocols
- Execute the MAC protocols like as CSMA/CD, TDMA, and MAC Address Filtering.
- Example: Implement the Wi-Fi MAC Layer in NS-3
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/internet-module.h”
using namespace ns3;
int main() {
NodeContainer wifiNodes;
wifiNodes.Create(4);
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211n_5GHZ);
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
phy.SetChannel(channel.Create());
WifiMacHelper mac;
Ssid ssid = Ssid(“NS3-WIFI-LAN”);
mac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(ssid));
NetDeviceContainer devices;
devices = wifi.Install(phy, mac, wifiNodes);
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(5.0),
“DeltaY”, DoubleValue(10.0),
“GridWidth”, UintegerValue(2),
“LayoutType”, StringValue(“RowFirst”));
mobility.Install(wifiNodes);
InternetStackHelper stack;
stack.Install(wifiNodes);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Calcaute the implement process for a replication
./waf –run “scratch/wifi_mac_example”
(C) Network Layer (Layer 3) Protocols
- Apply the layer protocol in Routing Protocols like as AODV, OSPF, RIP.
- Example: Using AODV Routing
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/aodv-module.h”
using namespace ns3;
int main() {
NodeContainer nodes;
nodes.Create(4);
InternetStackHelper stack;
AodvHelper aodv;
stack.SetRoutingHelper(aodv);
stack.Install(nodes);
Simulator::Run();
Simulator::Destroy();
return 0;
}
Implement the replication for this process
./waf –run “scratch/aodv_example”
(D) Transport Layer (Layer 4) Protocols
- The TCP/UDP are executes the variation for congestion control.
- Example: Replicate a TCP Transmission
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main() {
NodeContainer nodes;
nodes.Create(2);
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = p2p.Install(nodes);
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
uint16_t port = 9;
BulkSendHelper source(“ns3::TcpSocketFactory”, InetSocketAddress(interfaces.GetAddress(1), port));
source.SetAttribute(“MaxBytes”, UintegerValue(0));
ApplicationContainer sourceApps = source.Install(nodes.Get(0));
sourceApps.Start(Seconds(0.0));
sourceApps.Stop(Seconds(10.0));
PacketSinkHelper sink(“ns3::TcpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), port));
ApplicationContainer sinkApps = sink.Install(nodes.Get(1));
sinkApps.Start(Seconds(0.0));
sinkApps.Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
We apply the execution process for the replication method
./waf –run “scratch/tcp_example”
- Performance Analysis for OSI Layer Protocols
- We utilized for FlowMonitor to examine the performance for OSI layer protocol:
Ptr<FlowMonitor> flowMonitor;
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();
Simulator::Stop(Seconds(10.0));
Simulator::Run();
flowMonitor->SerializeToXmlFile(“results.xml”, true, true);
Run Analysis
python3 analyze_results.py
- Example OSI Layer Protocol Project Ideas
✅ 1. Custom MAC Protocol for IoT Devices
✅ 2. Energy-Aware Routing for Wireless Networks
✅ 3. Execute the Secure TCP/IP by encode
✅ 4. QoS-Based on Data Prioritization in Application Layer
✅ 5. Edge Computing in 5G Networks
In the above following steps briefly explain the simulation process for executing the OSI layer in ns3 simulation tool. We design to elaborate further essential details about the OSI layer will be provided in further manual.