How to Develop LAN Protocols Projects Using NS3

To develop a Local Area Network (LAN) protocols within NS3 simulator, we can replicate the Ethernet, Wi-Fi, or custom LAN routing techniques. The following steps will assist you to attain the LAN protocols projects’ implementation using NS3.

Steps to Develop LAN Protocols Projects in NS3

  1. Understanding LAN in NS3

NS3 simulator offers diverse LAN technologies that contain:

Wired LAN (Ethernet)

Wireless LAN (Wi-Fi)

LAN Switching Protocols (Spanning Tree, VLAN, etc.)

LAN Routing Protocols (RIP, OSPF, Custom)

  1. Setting Up NS3

(a) Install NS3

We start by installing NS3 on the system

sudo apt update

sudo apt install git g++ python3 python3-pip cmake

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./ns3 configure –enable-examples –enable-tests

./ns3 build

This sets up will install NS3 and compile the environment.

  1. Developing a LAN Protocol

We can implement a LAN Protocol that has two key methods like:

  1. Utilizing existing LAN protocols such as Ethernet, Wi-Fi
  2. Designing a new LAN protocol

(A) Simulating Wired LAN (Ethernet)

  • NS3 provides supports for Ethernet with the support of CsmaHelper componenet.
  • Example: We make a basic Ethernet LAN

📝 Example: Basic CSMA (Ethernet) LAN

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/csma-module.h”

#include “ns3/internet-module.h”

#include “ns3/applications-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);

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

Simulator::Run();

Simulator::Destroy();

return 0;

}

📌 Run the simulation

./waf –run “scratch/lan_example”

(B) Simulating Wireless LAN (Wi-Fi)

  • NS3 assists the wireless LAN like IEEE 802.11 Wi-Fi.
  • Example: We generate a Wi-Fi-based LAN

#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);

Ipv4AddressHelper address;

address.SetBase(“192.168.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

Simulator::Run();

Simulator::Destroy();

return 0;

}

📌 Run the simulation

./waf –run “scratch/wifi_lan_example”

  1. Implementing a Custom LAN Protocol

If we want a custom LAN protocol, we have to:

  1. Generate a new protocol class as MyLanProtocol.
  2. Execute the packet forwarding and routing.
  3. Customize routing technique in NS3.

📝 Example: Creating a Simple Custom LAN Protocol

  1. We need to design a new LAN protocol class like my-lan-protocol.h

class MyLanProtocol : public Object {

public:

static TypeId GetTypeId(void);

MyLanProtocol();

virtual ~MyLanProtocol();

void SendPacket(Ptr<Packet> packet, Address dest);

void ReceivePacket(Ptr<Packet> packet, Address src);

};

  1. Execute the protocol such as my-lan-protocol.cc

TypeId MyLanProtocol::GetTypeId(void) {

static TypeId tid = TypeId(“ns3::MyLanProtocol”)

.SetParent<Object>()

.SetGroupName(“Network”);

return tid;

}

MyLanProtocol::MyLanProtocol() {}

MyLanProtocol::~MyLanProtocol() {}

void MyLanProtocol::SendPacket(Ptr<Packet> packet, Address dest) {

NS_LOG_INFO(“Sending packet to ” << dest);

}

void MyLanProtocol::ReceivePacket(Ptr<Packet> packet, Address src) {

NS_LOG_INFO(“Received packet from ” << src);

}

  1. Incorporate the custom protocol to the network

Ptr<MyLanProtocol> protocol = CreateObject<MyLanProtocol>();

nodes.Get(0)->AddApplication(protocol);

  1. Performance Evaluation
  • Estimate the performance parameters using FlowMonitor.
  • Example:

Ptr<FlowMonitor> flowMonitor;

FlowMonitorHelper flowHelper;

flowMonitor = flowHelper.InstallAll();

Simulator::Stop(Seconds(10.0));

Simulator::Run();

flowMonitor->SerializeToXmlFile(“results.xml”, true, true);

  • After that, execute the simulations as well as examine the performance using:

python3 analyze_results.py

  1. Example LAN Protocol Projects Using NS3

Below are some common project ideas we will execute:

1. VLAN-Based LAN Switching Protocol

  • Execute the VLAN tagging and forwarding
  • Equate the performance of VLAN with typical LAN performance

2. Software-Defined LAN (SD-LAN)

  • Apply LAN including the SDN controllers
  • Compete with traditional LAN switching

3. MAC Address Filtering in LAN

  • We can utilize MAC-based filtering to apply a LAN security approach
  • Mimic an attacker attempting to spoof MAC addresses

4. LAN Routing Using OSPF

  • Execute the OSPF routing in an LAN using NS3
  • Equate with the routing performance of RIP

5. Custom LAN Congestion Control

  • Implement a congestion control technique that used for high-traffic LANs
  • Evaluate the network performance with parameters such as latency, throughput, and packet loss

In this module, we accumulated the stepwise mechanisms for you to get more knowledge to develop and examine the LAN Protocols projects in NS3 and we provided sample project ideas for future use. We will intent to provide the extra specifics based on your request.