How to Start Physical Topology Projects Using NS3
To create a Physical Topology project in NS-3 concentrations on building and analysing the physical connections among nodes in a network. This topology characterizes the actual layout and direct physical connections like as wires or wireless connections among devices.
Steps to Start Physical Topology Projects Using NS3
Step 1: Set Up NS-3
- Install NS-3:
- Download NS-3.
- Follow the installation steps.
- Verify Installation: Processing a basic script to verify the installation:
./waf –run scratch/my_first
Step 2: Understand Physical Topology
- Physical Topology:
- Signify on how devices are physically connected such as wired or wireless.
- Normal examples:
- Point-to-Point: The Two nodes directly connected.
- Star: The Central node connected to multiple nodes.
- Mesh: All nodes are interconnected.
- Tree: The Hierarchical structure like parent and child nodes.
- Ring: The Circular structure in which every node connects to two neighbours.
Step 3: Plan the Topology
- Choose the topology type:
- Example: Point-to-Point, Mesh, Star, etc.
- Define the number of nodes:
- For Sample, Build a mesh network with five nodes.
- Set simulation goals:
- Replicate the data flow and analyse the parameter metrics such as throughput, delay, and packet loss.
Step 4: Set Up the Physical Topology
- Create Nodes: State the nodes in the topology.
NodeContainer nodes;
uint32_t numNodes = 5; // Number of nodes in the topology
nodes.Create(numNodes);
- Set Up Links: Utilized their PointToPointHelper or other relevant helpers we state the physical connections.
- Point-to-Point Example:
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
for (uint32_t i = 0; i < numNodes – 1; ++i) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(i + 1));
devices.Add(link);
}
-
- Mesh Example:
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(j));
devices.Add(link);
}
}
- Install Internet Stack: Enhance the Internet stack to all nodes.
InternetStackHelper stack;
stack.Install(nodes);
- Assign IP Addresses: Allocate the unique IP addresses to each link.
Ipv4AddressHelper address;
uint32_t subnetIndex = 1;
for (uint32_t i = 0; i < devices.GetN(); ++i) {
std::ostringstream subnet;
subnet << “10.1.” << subnetIndex++ << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(i));
}
Step 5: Set Up Applications
- Install Applications: Utilized their applications such as UDP echo or TCP-based traffic generators we replicate the communication.
- UDP Echo Example:
UdpEchoServerHelper echoServer(9); // Port 9
ApplicationContainer serverApp = echoServer.Install(nodes.Get(numNodes – 1)); // Server on the last node
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9); // Server’s IP
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(0)); // Client on the first node
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
Step 6: Run and Analyze
- Run the Simulation:
Simulator::Run();
Simulator::Destroy();
- Enable Packet Capture: Save .pcap files for traffic analysis.
p2p.EnablePcapAll(“physical_topology”);
- Trace Logs: Ensure the logging for debugging:
export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”
./waf –run scratch/physical_topology
Example: Minimal NS-3 Script for a Physical Topology
#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”
using namespace ns3;
int main(int argc, char *argv[]) {
uint32_t numNodes = 5;
// Create nodes
NodeContainer nodes;
nodes.Create(numNodes);
// Set up Point-to-Point links
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
// Connect nodes in a mesh
NetDeviceContainer devices;
for (uint32_t i = 0; i < numNodes; ++i) {
for (uint32_t j = i + 1; j < numNodes; ++j) {
NetDeviceContainer link = p2p.Install(nodes.Get(i), nodes.Get(j));
devices.Add(link);
}
}
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
uint32_t subnetIndex = 1;
for (uint32_t i = 0; i < devices.GetN(); ++i) {
std::ostringstream subnet;
subnet << “10.1.” << subnetIndex++ << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(i));
}
// Set up UDP echo server
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApp = echoServer.Install(nodes.Get(numNodes – 1));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
// Set up UDP echo client
UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(0));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
// Enable packet capture
p2p.EnablePcapAll(“physical_topology”);
// Run the simulation
Simulator::Run();
Simulator::Destroy();
return 0;
}
Step 7: Compile and Run
- Save the script as physical_topology.cc.
- We compile and run it:
./waf –run physical_topology
Step 8: Enhance the Simulation
- Experiment with Different Topologies:
- The Star, Tree, Ring, or Custom Topologies.
- Simulate Failures:
- Unconnected the specific connections or nodes we follow the fault tolerance.
- Analyze Performance:
- Estimate the throughput, latency, jitter, and packet loss.
- Visualize:
- Utilized their NetAnim we show the physical topology and data exchange.
Next Steps
- Scale Up:
- Number of nodes are increase in complexity of the topology.
- Add Traffic Models:
- Utilized their FTP, HTTP, or custom traffic for more realistic environment.
- Integrate with Logical Topologies:
- Replicate the hybrid networks joining the physical and logical topologies.
Finally, we had successfully delivered the significant procedures to simulate the Physical Topology in NS3 tool and also, we deliver the sample snippets and their explanation. More information regarding Physical Topology will be shared in upcoming manual. Feel free to reach out to us by sending a message with your project details. We will assist you in selecting the most suitable simulations and topics.