To implement the network relocation in ns3 has to generate the mechanism that reconfigure the connection and transfer the nodes in the network. It is helpful in this type of scenarios like mobile ad-hoc networks (MANETs) or dynamic sensor networks. The given below is the structured procedure to achieve this process using ns3:
Step-by-Step Implementation:
Step 1: Set Up the ns3 Environment
- Install ns3: Make certain ns3 is installed in the computer.
sudo apt-get update
sudo apt-get install ns3
Create a New ns3 Project: Create a directory for your new project within the ns3 workspace.
cd ns-3
mkdir scratch/network-relocation-project
Step 2: Define the Node Mobility
- Create a New Simulation Script: Create a new script in your scratch directory to implement the simulation scenario.
// network-relocation-project.cc
#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”
#include “ns3/mobility-module.h”
#include “ns3/aodv-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE(“NetworkRelocationProject”);
void MoveNode(Ptr<Node> node, Vector newPosition) {
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel>();
mobility->SetPosition(newPosition);
NS_LOG_UNCOND(“Node ” << node->GetId() << ” moved to ” << newPosition);
}
void ScheduleNodeMovements(NodeContainer nodes) {
Simulator::Schedule(Seconds(5.0), &MoveNode, nodes.Get(1), Vector(50.0, 50.0, 0.0));
Simulator::Schedule(Seconds(10.0), &MoveNode, nodes.Get(2), Vector(70.0, 70.0, 0.0));
Simulator::Schedule(Seconds(15.0), &MoveNode, nodes.Get(3), Vector(90.0, 90.0, 0.0));
}
int main(int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
NodeContainer nodes;
nodes.Create(4);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes);
InternetStackHelper stack;
AodvHelper aodv;
stack.SetRoutingHelper(aodv);
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
// Set up mobility
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
// Schedule node movements
ScheduleNodeMovements(nodes);
// Create traffic source and sink
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(20.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(20.0));
// Enable tracing
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll(ascii.CreateFileStream(“network-relocation.tr”));
pointToPoint.EnablePcapAll(“network-relocation”);
Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Compile the Script: Compile your script using the waf build system.
./waf build
Run the Simulation: Run your simulation script and observe the results.
./waf –run scratch/network-relocation-project
Step 3: Implement Node Relocation
- Define Relocation Function: Create a function to move nodes to new positions.
void MoveNode(Ptr<Node> node, Vector newPosition) {
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel>();
mobility->SetPosition(newPosition);
NS_LOG_UNCOND(“Node ” << node->GetId() << ” moved to ” << newPosition);
}
Schedule Node Movements: Use ns3 event scheduler to periodically move nodes to new positions.
void ScheduleNodeMovements(NodeContainer nodes) {
Simulator::Schedule(Seconds(5.0), &MoveNode, nodes.Get(1), Vector(50.0, 50.0, 0.0));
Simulator::Schedule(Seconds(10.0), &MoveNode, nodes.Get(2), Vector(70.0, 70.0, 0.0));
Simulator::Schedule(Seconds(15.0), &MoveNode, nodes.Get(3), Vector(90.0, 90.0, 0.0));
}
Step 4: Set Up Mobility
- Define Mobility Model: Use the MobilityHelper to define the mobility model for the nodes. In this example, we use the ConstantPositionMobilityModel.
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
Step 5: Generate Traffic
- Install Applications: Use the UdpEchoServerHelper and UdpEchoClientHelper to generate traffic between nodes.
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(20.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(100));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(20.0));
In the end, we had successfully implemented and configure the network relocation among the generated nodes in the mobility design that were incorporated with ns3 tool. Also further we provide and help additional details regarding network relocation.
Get project ideas and performance evaluation for Network Relocation using the ns3 tool. We offer a wide range of project concepts tailored to your needs, complete with thorough execution plans. Our expertise covers various scenarios, including mobile ad-hoc networks (MANETs) and dynamic sensor networks.