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

How to Implement Network Mobility Management in ns3

To implement the Network Mobility Management in ns3 has includes to setup a network topology with mobile nodes, configuring mobility models, and using proper tools to handle and evaluate the movement of nodes.

Code Implementation are carried out by our developers for your project we have the necessary tools and resources to carry out in Network Mobility Management using ns3tool.

The given below are the procedures on how to implement the network mobility management in ns3:

Step-by-Step Implementation:

Step 1: Set Up the Simulation Environment

  • Make sure ns3 is installed in the computer.

Step 2: Create the Network Topology

  • Generate the simple network topology using ns3 with mobile nodes and access points (APs) or base stations (BS).

Step 3: Write the Script

  • Here, we provide the complete sample script to generate and configure a network topology in ns3 with mobility management:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

#include “ns3/flow-monitor-helper.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“MobilityManagementExample”);

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer wifiApNodes;

wifiApNodes.Create (2);

NodeContainer wifiStaNodes;

wifiStaNodes.Create (2);

// Set up Wi-Fi

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();

YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();

phy.SetChannel (channel.Create ());

WifiHelper wifi;

wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);

WifiMacHelper mac;

Ssid ssid1 = Ssid (“ns-3-ssid-1”);

Ssid ssid2 = Ssid (“ns-3-ssid-2”);

// Configure APs

mac.SetType (“ns3::ApWifiMac”,

“Ssid”, SsidValue (ssid1));

NetDeviceContainer apDevices1 = wifi.Install (phy, mac, wifiApNodes.Get (0));

mac.SetType (“ns3::ApWifiMac”,

“Ssid”, SsidValue (ssid2));

NetDeviceContainer apDevices2 = wifi.Install (phy, mac, wifiApNodes.Get (1));

// Configure STAs

mac.SetType (“ns3::StaWifiMac”,

“Ssid”, SsidValue (ssid1),

“ActiveProbing”, BooleanValue (false));

NetDeviceContainer staDevices1 = wifi.Install (phy, mac, wifiStaNodes.Get (0));

mac.SetType (“ns3::StaWifiMac”,

“Ssid”, SsidValue (ssid2),

“ActiveProbing”, BooleanValue (false));

NetDeviceContainer staDevices2 = wifi.Install (phy, mac, wifiStaNodes.Get (1));

// Install the Internet stack on the nodes

InternetStackHelper stack;

stack.Install (wifiApNodes);

stack.Install (wifiStaNodes);

// Assign IP addresses to the devices

Ipv4AddressHelper address;

Ipv4InterfaceContainer apInterfaces1, apInterfaces2, staInterfaces1, staInterfaces2;

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

apInterfaces1 = address.Assign (apDevices1);

staInterfaces1 = address.Assign (staDevices1);

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

apInterfaces2 = address.Assign (apDevices2);

staInterfaces2 = address.Assign (staDevices2);

// Set up mobility model for APs (static)

MobilityHelper mobility;

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // Position for AP1

positionAlloc->Add (Vector (50.0, 0.0, 0.0)); // Position for AP2

mobility.SetPositionAllocator (positionAlloc);

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

mobility.Install (wifiApNodes);

// Set up mobility model for STAs (moving)

mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,

“MinX”, DoubleValue (0.0),

“MinY”, DoubleValue (0.0),

“DeltaX”, DoubleValue (10.0),

“DeltaY”, DoubleValue (10.0),

“GridWidth”, UintegerValue (3),

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

mobility.SetMobilityModel (“ns3::RandomWalk2dMobilityModel”,

“Bounds”, RectangleValue (Rectangle (-100, 100, -50, 50)));

mobility.Install (wifiStaNodes);

// Set up applications

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (wifiApNodes.Get (0));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (20.0));

UdpEchoClientHelper echoClient (apInterfaces1.GetAddress (0), 9);

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

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

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

ApplicationContainer clientApps = echoClient.Install (wifiStaNodes);

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (20.0));

// Enable Flow Monitor

FlowMonitorHelper flowmon;

Ptr<FlowMonitor> monitor = flowmon.InstallAll ();

// Run simulation

Simulator::Stop (Seconds (20.0));

Simulator::Run ();

// Print statistics

monitor->CheckForLostPackets ();

Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();

for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)

{

Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);

std::cout << “Flow ID: ” << i->first << ” Src Addr ” << t.sourceAddress << ” Dst Addr ” << t.destinationAddress << std::endl;

std::cout << “Tx Packets = ” << i->second.txPackets << std::endl;

std::cout << “Rx Packets = ” << i->second.rxPackets << std::endl;

std::cout << “Throughput: ” << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds () – i->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 << ” Mbps” << std::endl;

std::cout << “Delay: ” << i->second.delaySum.GetSeconds() / i->second.rxPackets << ” s” << std::endl;

std::cout << “Packet Loss Ratio: ” << (i->second.txPackets – i->second.rxPackets) / static_cast<double>(i->second.txPackets) << std::endl;

}

Simulator::Destroy ();

return 0;

}

Explanation:

  1. Create Nodes:
    • Create Wi-Fi AP nodes and STA nodes.
  1. Configure Wi-Fi:
    • Set up the Wi-Fi PHY and MAC layers.
    • Create Wi-Fi APs and STAs.
  1. Install Internet Stack:
    • Install the Internet stack on all nodes.
  1. Assign IP Addresses:
    • Assign IP addresses to the Wi-Fi interfaces.
  1. Set Up Mobility Models:
    • Set up a constant position for the APs.
    • Set up a random walk mobility model for the STAs to simulate movement.
  1. Set Up Applications:
    • Create a UDP Echo server on one AP.
    • Create a UDP Echo client on the STAs.
  1. Enable Flow Monitor:
    • Install Flow Monitor to collect performance metrics.
  1. Run Simulation:
    • Run the simulation and print the collected statistics.

Step 4: Compile and Run the Script

  1. Save the script as mobility-management-example.cc in the scratch directory of your ns-3 installation.
  2. Compile the script using the following commands:

./waf configure

./waf build

./waf –run mobility-management-example

Step 5: Analyse the Results

  • After running the simulation, the script will output performance metrics such as the number of transmitted and received packets, delay, throughput, and packet loss ratio. We can further analyse this data to understand the impact of mobility on network performance.

Overall, we had clearly learned about how to implement and evaluate the Network Mobility Management in ns3 framework. We also provide further details that relates to Network Mobility Management.