How to Start Star Topology Projects Using NS3
To start a Star Topology project in NS3, follow these steps to model a central node, which associates to several peripheral nodes.
Steps to Start Star Topology Projects in NS3
Step 1: Set Up NS3
- Install NS3:
- Go to NS3 webpage to download NS3 on the system.
- We should install all necessary dependencies such as C++ compiler, Python, and so on.
- Verify Installation: Execute a simple example to make sure that NS3 is working properly:
./waf –run scratch/my_first
Step 2: Understand the Star Topology
- In a star topology:
- Every peripheral node associates to a single central node.
- Interaction among two peripheral nodes are traverses the central node.
Step 3: Plan Your Project
Define the project objectives like:
- To mimic data transfer among the nodes.
- We estimate the performance indicators such as throughput, latency, and packet loss.
- Focus on the behaviour of protocol like TCP, UDP.
Step 4: Create the Star Topology
- Create Nodes: Describe the central and peripheral nodes to utilize the NodeContainer class.
NodeContainer centralNode;
centralNode.Create(1); // Central node
NodeContainer peripheralNodes;
peripheralNodes.Create(5); // Five peripheral nodes
- Connect Nodes with Point-to-Point Links: We associate the nodes using PointToPointHelper for each connection.
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“100Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
NetDeviceContainer link = p2p.Install(centralNode.Get(0), peripheralNodes.Get(i));
devices.Add(link);
}
- Install Internet Protocol Stack: We should install the internet stack at every node.
InternetStackHelper stack;
stack.Install(centralNode);
stack.Install(peripheralNodes);
- Assign IP Addresses: In each link to allocate distinct IP address.
Ipv4AddressHelper address;
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
std::ostringstream subnet;
subnet << “192.168.” << i + 1 << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(i));
}
Step 5: Set Up Applications
We have to install applications making traffic among the nodes.
- UDP Server: Configure a server application at central node.
UdpEchoServerHelper echoServer(9); // Port 9
ApplicationContainer serverApp = echoServer.Install(centralNode.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
- UDP Clients: We can install client applications at every peripheral node.
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
UdpEchoClientHelper echoClient(Ipv4Address(“192.168.1.1”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(peripheralNodes.Get(i));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
}
Step 6: Simulate and Analyze
- Run the Simulation: Now, we follow these commands to execute the simulation.
Simulator::Run();
Simulator::Destroy();
- Enable Packet Capture: Allow packet to seize and save simulation information with .pcap files for analysis.
p2p.EnablePcap(“star_topology”, devices, true);
- Trace Logs: To support logging for debugging.
export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”
./waf –run scratch/star_topology
Step 7: Enhance the Simulation
- Insert traffic patterns like FTP or HTTP.
- We able to launch link failures or bandwidth variations.
- Examine the simulation indicators such as throughput, delay, and jitter.
Example: Minimal NS3 Script for Star 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[]) {
NodeContainer centralNode;
centralNode.Create(1);
NodeContainer peripheralNodes;
peripheralNodes.Create(5);
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“100Mbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices;
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
NetDeviceContainer link = p2p.Install(centralNode.Get(0), peripheralNodes.Get(i));
devices.Add(link);
}
InternetStackHelper stack;
stack.Install(centralNode);
stack.Install(peripheralNodes);
Ipv4AddressHelper address;
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
std::ostringstream subnet;
subnet << “192.168.” << i + 1 << “.0”;
address.SetBase(subnet.str().c_str(), “255.255.255.0”);
address.Assign(devices.Get(i));
}
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApp = echoServer.Install(centralNode.Get(0));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
for (uint32_t i = 0; i < peripheralNodes.GetN(); ++i) {
UdpEchoClientHelper echoClient(Ipv4Address(“192.168.1.1”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(peripheralNodes.Get(i));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
}
Simulator::Run();
Simulator::Destroy();
return 0;
}
We would save the script as star_topology.cc and then compile and execute it:
./waf –run star_topology
Next Steps
- Make use of NetAnim to envision the topology.
- Focus on the performance parameters.
- We want to equate the star topology including other topologies such as bus or ring.
We implemented an efficient simulation method using NS3 to simulate and analyse the Star Topology project and further insights will be elaborated upon in the next manual.
Rely on phdprojects.org to initiate a Star Topology project in NS3, we provide you with comprehensive steps that ensure the successful execution of your project, accompanied by a brief summary of our approach.