Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement Metropolitan Area Networks in NS3

To implement a Metropolitan Area Network (MAN) in ns-3, we need to set up a network that spans a metropolitan area, which connects more smaller networks that include local area networks (LANs). Here is a quick and detailed guide on setting up a basic MAN scenario in ns-3 which utilizes Wi-Fi and point-to-point connections for simulating the core network.

Steps to implement Metropolitan Area Network (MAN) in ns-3

  1. Set up your development environment
  • Install ns-3 : Ensure that you have ns-3 installed in your computer. To install, follow the official ns-3 installation guide.
  • Install required modules : Make sure that you have installed all the required ns-3 modules which includes Internet, mobility, Wi-Fi and point-to-point modules.
  1. Create a basic Wi-Fi simulation script

Here is a basic MAN scenario setup example script using ns-3 features :

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/mobility-module.h”

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“MetropolitanAreaNetworkExample”);

int main (int argc, char *argv[])

{

  // Set simulation parameters

  uint32_t numLANs = 3;

  uint32_t numNodesPerLAN = 5;

  double simTime = 30.0; // Simulation time in seconds

  CommandLine cmd;

  cmd.AddValue(“numLANs”, “Number of LANs”, numLANs);

  cmd.AddValue(“numNodesPerLAN”, “Number of nodes per LAN”, numNodesPerLAN);

  cmd.AddValue(“simTime”, “Simulation time”, simTime);

  cmd.Parse(argc, argv);

  // Create LANs and core nodes

  NodeContainer coreNodes;

  coreNodes.Create(numLANs);

  std::vector<NodeContainer> LANs;

  for (uint32_t i = 0; i < numLANs; ++i)

  {

    NodeContainer lan;

    lan.Create(numNodesPerLAN);

    LANs.push_back(lan);

  }

  // Create Point-to-Point links between core nodes

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Gbps”));

  pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

  NetDeviceContainer coreDevices;

  for (uint32_t i = 0; i < numLANs – 1; ++i)

  {

    NetDeviceContainer link = pointToPoint.Install(coreNodes.Get(i), coreNodes.Get(i + 1));

    coreDevices.Add(link);

  }

  // Install the Internet stack on core nodes and LAN nodes

  InternetStackHelper internet;

  internet.Install(coreNodes);

  for (auto &lan : LANs)

  {

    internet.Install(lan);

  }

  // Assign IP addresses to core devices

  Ipv4AddressHelper ipv4;

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

  ipv4.Assign(coreDevices);

  // Set up WiFi for LANs

  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

  wifiPhy.SetChannel(wifiChannel.Create());

  WifiHelper wifi;

  wifi.SetStandard(WIFI_PHY_STANDARD_80211n_5GHZ);

  WifiMacHelper wifiMac;

  wifiMac.SetType(“ns3::StaWifiMac”, “Ssid”, SsidValue(Ssid(“LAN”)));

  for (uint32_t i = 0; i < numLANs; ++i)

  {

    NetDeviceContainer lanDevices = wifi.Install(wifiPhy, wifiMac, LANs[i]);

    // Set up mobility for LAN nodes

    MobilityHelper mobility;

    mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

                                  “MinX”, DoubleValue(10.0 * i),

                                  “MinY”, DoubleValue(10.0),

                                  “DeltaX”, DoubleValue(5.0),

                                  “DeltaY”, DoubleValue(10.0),

                                  “GridWidth”, UintegerValue(numNodesPerLAN),

                                  “LayoutType”, StringValue(“RowFirst”));

    mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

    mobility.Install(LANs[i]);

    // Assign IP addresses to LAN devices

    std::string base = “192.168.” + std::to_string(i + 1) + “.0”;

    ipv4.SetBase(base.c_str(), “255.255.255.0”);

    ipv4.Assign(lanDevices);

  }

  // Install applications

  uint16_t port = 9;

  // Install a UDP echo server on the first node of the first LAN

  UdpEchoServerHelper echoServer(port);

  ApplicationContainer serverApps = echoServer.Install(LANs[0].Get(0));

  serverApps.Start(Seconds(1.0));

  serverApps.Stop(Seconds(simTime));

 

  // Install a UDP echo client on the first node of the last LAN

  UdpEchoClientHelper echoClient(LANs[0].Get(0)->GetObject<Ipv4>()->GetAddress(1, 0).GetLocal(), port);

  echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));

  echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

  echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

  ApplicationContainer clientApps = echoClient.Install(LANs[numLANs – 1].Get(0));

  clientApps.Start(Seconds(2.0));

  clientApps.Stop(Seconds(simTime));

  // Enable tracing

  pointToPoint.EnablePcapAll(“man-example”);

  wifiPhy.EnablePcap(“man-example-wifi”, coreDevices);

  // Run the simulation

  Simulator::Stop(Seconds(simTime));

  Simulator::Run();

  Simulator::Destroy();

  return 0;

}

Explanation of the script

In this set up, we had created a network with metropolitan area which includes smaller networks like LAN using ns-3 features. Let’s have a detailed explanation on the script below:

  1. Include necessary headers : Include all the required headers for ns-3 core, network, internet, Wi-Fi, mobility and application modules.
  2. Set simulation Parameters : Define the number of LANs, number of nodes for each LAN and also define the simulation time.
  3. Create nodes : Using NodeContainer, create core nodes and LANs.
  4. Set up point-to-point connection : Set up point-to-point connections between core nodes using PointToPointHelper.
  5. Install internet stack : Using InternetStackHelper, install the internet stack on the core nodes and LAN nodes.
  6. Assign IP addresses to LAN devices : Using Ipv4AddressHelper, assign IP addresses to the LAN devices.
  7. Set Up Wi-Fi for LANs: using WifiHelper, YansWifiPhyHelper, and WifiMacHelper, set up Wi-Fi for LAN nodes.
  8. Set Up Mobility : Using MobilityHelper, define the positions and mobility models.
  9. Install applications : On the first node of the first LAN, install the UDP echo server and on the first node of the last LAN, install the UDP echo clients to simulate communications.
  10. Enable tracking : Capture packet traces using pcap tracing for analysis.
  11. Run the simulator : Define the simulation stopping time and run the simulator and cleanup using Simulator::Stop, Simulator::Run, and Simulator::Destroy.

Further enhancements

         In future, we would like to enhance the mobility models, implement dynamic traffic patterns, implement QoS, analyze network performance etc. Let’s have a quick review on our future enhancements below :

  1. Dynamic Traffic Patterns:
    • To simulate real-world scenarios more accurately, implement dynamic traffic patterns.
  2. Advanced Mobility Models:
    • create more realistic mobility models for mobile nodes within the MAN.
  3. Quality of Service (QoS):
    • To prioritize critical applications and ensure timely delivery, implement QoS mechanisms.
  4. Network Performance Metrics:
    • Collect and analyze performance metrics such as throughput, latency, packet delivery ratio, and resource utilization.
  5. Fault Tolerance and Resilience:
    • Implement and evaluate fault tolerance mechanisms and resilience strategies for MANs.
  6. Security:
    • To protect data and services in the MAN environment, implement security mechanisms.

Overall, we had successfully implemented a Metropolitan Area Network (MAN) in ns-3 using a network that spans a metropolitan area, connecting multiple smaller networks like local area networks (LANs) which includes Wi-Fi and point-to-point connections to simulate the core network.  Also, we provide more information on Metropolitan Area Network (MAN).