This article is completely articulated with process that are essential to create the topology in network simulator 3 and this will be the great support for those who are enchantingly looking for creation helps.
Step: 1 Input Readers
The main intension of the topology modules is to read the topology file that is generated through the automatic topology generator. In addition, this process includes two significant steps and they are listed below.
- Topology file in created through running the topology generator
- Read the topology file to build the ns3 simulation
The model is focused to read the various topology formats and it includes three significant models such as.
- ns3::RocketfuelTopologyReader for Rocketfuel traces
- ns3::OrbisTopologyReader for Orbis 0.7 traces
- ns3::InetTopologyReader for Inet 3.0 traces
Additionally, the ns3::TopologyReaderHelper is considered as the helper and it is functioning to assist the trivial tasks.
Step: 2 Code for Topology Creation
The, we have to create the code for topology and for that we have to build the topology based inet or orbis trace files.
#include
#include
#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/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/ipv4-nix-vector-helper.h"
#include "ns3/topology-read-module.h"
#include
using namespace ns3;
NS_LOG_COMPONENT_DEFINE
("TopologyCreationExperiment");
int main (int argc, char *argv[])
{
// ------------------------------------------------------------
// -- Read topology data.
// --------------------------------------------
// Pick a topology reader based in the
requested format.
TopologyReaderHelper topoHelp;
topoHelp.SetFileName (input);
topoHelp.SetFileType (format);
Ptr inFile = topoHelp.GetTopologyReader ();
NodeContainer nodes;
int totlinks = inFile->LinksSize ();
NS_LOG_INFO ("creating node containers");
NodeContainer* nc = new NodeContainer[totlinks];
TopologyReader::ConstLinksIterator iter;
int i = 0;
for ( iter = inFile->LinksBegin (); iter != inFile->LinksEnd (); iter++, i++ )
{
nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ());
}
NS_LOG_INFO ("creating net device containers");
NetDeviceContainer* ndc = new NetDeviceContainer[totlinks];
PointToPointHelper p2p;
for (int i = 0; i < totlinks; i++)
{
// p2p.SetChannelAttribute ("Delay", TimeValue(MilliSeconds(weight[i])));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
ndc[i] = p2p.Install (nc[i]);
}
uint32_t totalNodes = nodes.GetN ();
Ptr unifRandom = CreateObject ();
unifRandom->SetAttribute ("Min", DoubleValue (0));
unifRandom->SetAttribute ("Max", DoubleValue (totalNodes - 1));
unsigned int randomServerNumber = unifRandom->GetInteger (0, totalNodes - 1);
// ------------------------------------------------------------
// -- Run the simulation
// --------------------------------------------
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
Step: 3 Execute Main File
Finally, we have to implement the main file through changing the location and executing the commands that are enlisted below.
cd /home/research/ns-allinone-3.26/ns-3.26
sudo ./waf –run Main –vis
Additionally, we have highlighted the results that are acquired through the execution of the commands based on WiFi based topology creation.
To this end, we hope that we have provided the appropriate processes that are used to create the ns3 topology. Ping us to aid more.