How to Start Mixed Topology Projects Using NS3

Starting a Mixed Topology Project in NS-3

To create a Mixed Topology, it combines the various kinds of network topologies such as star, mesh, and tree into a single network. This permits we can replicate the complex and heterogeneous networks like as smart grids, IoT systems, or enterprise networks.

Steps to Start Mixed Topology Projects Using NS3

Step 1: Set Up NS-3

  1. Install NS-3:
    • Download NS-3.
    • Observe the installation steps.
  2. Verify Installation: Process a basic script to ensure NS-3 is correctly set up:

./waf –run scratch/my_first

Step 2: Understand Mixed Topology

  • Mixed Topology Characteristics:
    • It combines the multiple topologies such as star, mesh, and tree.
    • Useful for replicating the diverse network settings.
    • It can has contained the wired and wireless components.

Step 3: Plan the Topology

  1. Define sub-topologies:
    • For Sample:
      • A star topology for core network devices.
      • A tree topology for wired sub-networks.
      • A mesh topology for wireless IoT devices.
  2. Define the number of nodes in each sub-topology.
  3. Set simulation goals:
    • Estimate the performance with the heterogeneous network.
    • Validate the routing protocols, traffic patterns, or fault tolerance.

Step 4: Set Up the Mixed Topology

  1. Create Nodes: State the nodes for every sub-topology.

NodeContainer starNodes, treeNodes, meshNodes;

uint32_t numStarNodes = 5;

uint32_t numTreeNodes = 7;

uint32_t numMeshNodes = 6;

starNodes.Create(numStarNodes);

treeNodes.Create(numTreeNodes);

meshNodes.Create(numMeshNodes);

  1. Set Up Star Topology: Connect nodes in a star setting used a hub node.

NodeContainer hubNode;

hubNode.Create(1); // Central hub

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

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

NetDeviceContainer starDevices;

for (uint32_t i = 0; i < numStarNodes; ++i) {

NetDeviceContainer link = p2p.Install(hubNode.Get(0), starNodes.Get(i));

starDevices.Add(link);

}

  1. Set Up Tree Topology: Nodes are connected in the tree structure.

NetDeviceContainer treeDevices;

for (uint32_t i = 1; i < numTreeNodes; ++i) {

uint32_t parent = (i – 1) / 2;

NetDeviceContainer link = p2p.Install(treeNodes.Get(parent), treeNodes.Get(i));

treeDevices.Add(link);

}

  1. Set Up Mesh Topology: Utilized their Wi-Fi to create a wireless mesh network.

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211b);

YansWifiPhyHelper phy = YansWifiPhyHelper::Default();

phy.Set(“RxGain”, DoubleValue(-10));

YansWifiChannelHelper channel = YansWifiChannelHelper::Default();

phy.SetChannel(channel.Create());

WifiMacHelper mac;

mac.SetType(“ns3::AdhocWifiMac”);

NetDeviceContainer meshDevices = wifi.Install(phy, mac, meshNodes);

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,

“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”),

“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”));

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

mobility.Install(meshNodes);

  1. Install Internet Stack: Improve the Internet stack to all nodes and assign IP addresses.

InternetStackHelper stack;

stack.Install(starNodes);

stack.Install(hubNode);

stack.Install(treeNodes);

stack.Install(meshNodes);

Ipv4AddressHelper address;

// Star topology

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

Ipv4InterfaceContainer starInterfaces = address.Assign(starDevices);

// Tree topology

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

Ipv4InterfaceContainer treeInterfaces = address.Assign(treeDevices);

// Mesh topology

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

Ipv4InterfaceContainer meshInterfaces = address.Assign(meshDevices);

Step 5: Simulate Traffic

  1. Install Traffic Generators:
    • Star to Tree Communication:

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApp = echoServer.Install(treeNodes.Get(0)); // Server on Tree Root

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(treeInterfaces.GetAddress(0), 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(starNodes.Get(0)); // Client on Star Node

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

    • Mesh Communication:

UdpEchoServerHelper meshEchoServer(10);

ApplicationContainer meshServerApp = meshEchoServer.Install(meshNodes.Get(0)); // Mesh Server

meshServerApp.Start(Seconds(3.0));

meshServerApp.Stop(Seconds(10.0));

UdpEchoClientHelper meshEchoClient(meshInterfaces.GetAddress(0), 10);

meshEchoClient.SetAttribute(“MaxPackets”, UintegerValue(10));

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

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

ApplicationContainer meshClientApp = meshEchoClient.Install(meshNodes.Get(3)); // Mesh Client

meshClientApp.Start(Seconds(4.0));

meshClientApp.Stop(Seconds(10.0));

  1. Use Flow Monitor: Calculate the throughput, delay, and packet loss.

FlowMonitorHelper flowmon;

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

Step 6: Run and Analyze

  1. Run the Simulation:

Simulator::Run();

Simulator::Destroy();

  1. Enable Packet Capture: Save .pcap files for analysis.

p2p.EnablePcapAll(“mixed_topology”);

  1. Analyze Results: Utilized their Flow Monitor we analyse the network performance.

monitor->SerializeToXmlFile(“mixed_topology_flowmon.xml”, true, true);

Example: Minimal NS-3 Script for Mixed 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/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

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

using namespace ns3;

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

// Star Topology

NodeContainer starNodes, hubNode;

uint32_t numStarNodes = 5;

starNodes.Create(numStarNodes);

hubNode.Create(1);

// Tree Topology

NodeContainer treeNodes;

uint32_t numTreeNodes = 7;

treeNodes.Create(numTreeNodes);

// Mesh Topology

NodeContainer meshNodes;

uint32_t numMeshNodes = 6;

meshNodes.Create(numMeshNodes);

// Configure and connect topologies (as shown in the steps above)

// Configure traffic, Flow Monitor, and run simulation

Simulator::Run();

Simulator::Destroy();

return 0;

}

Step 7: Enhance the Simulation

  • Dynamic Mobility:
    • Replicate the movement in the mesh topology utilized their patterns such as RandomWalk2D.
  • Test Routing Protocols:
    • Compared the AODV, DSDV, and OLSR performance in the mixed network.
  • Simulate Faults:
    • Unable the specific connections or nodes we follow the impact of the network.
  • Visualize:
    • Utilized their NetAnim we show the mixed topology and traffic flow.

Next Steps

  • Scale Up:
    • Number of nodes are increased in sub-networks for large-scale replications.
  • Add Energy Models:
    • Integrate the energy usage designs for IoT or sensor nodes.

The above the detailed project about Mixed topology that was simulated and executed using NS3 tool and it has contained sample codes, detailed explanation about coding and provide the performance analysis regarding this project. Further details will be added later.

Getting started with a Mixed Topology Project in NS-3 can be challenging. At phdprojects.org, we provide tailored support whenever you need it. Just drop us a message, and we’ll help you with the best simulations and topics to work on.