48#include "ns3/core-module.h"
49#include "ns3/network-module.h"
50#include "ns3/internet-module.h"
51#include "ns3/point-to-point-module.h"
52#include "ns3/applications-module.h"
53#include "ns3/global-route-manager.h"
54#include "ns3/mobility-module.h"
55#include "ns3/netanim-module.h"
56#include "ns3/assert.h"
57#include "ns3/ipv4-global-routing-helper.h"
63std::vector<std::vector<bool>>
readNxNMatrix (std::string adj_mat_file_name);
64std::vector<std::vector<double>>
readCordinatesFile (std::string node_coordinates_file_name);
65void printCoordinateArray (
const char* description, std::vector<std::vector<double>> coord_array);
66void printMatrix (
const char* description, std::vector<std::vector<bool>> array);
70int main (
int argc,
char *argv[])
77 double SimTime = 3.00;
78 double SinkStartTime = 1.0001;
79 double SinkStopTime = 2.90001;
80 double AppStartTime = 2.0001;
81 double AppStopTime = 2.80001;
83 std::string AppPacketRate (
"40Kbps");
86 std::string LinkRate (
"10Mbps");
87 std::string LinkDelay (
"2ms");
91 srand ( (
unsigned)time ( NULL ) );
93 std::string tr_name (
"n-node-ppp.tr");
94 std::string pcap_name (
"n-node-ppp");
95 std::string flow_name (
"n-node-ppp.xml");
96 std::string anim_name (
"n-node-ppp.anim.xml");
98 std::string adj_mat_file_name (
"examples/matrix-topology/adjacency_matrix.txt");
99 std::string node_coordinates_file_name (
"examples/matrix-topology/node_coordinates.txt");
102 cmd.Parse (argc, argv);
108 std::vector<std::vector<bool>> Adj_Matrix;
118 std::vector<std::vector<double>> coord_array;
124 int n_nodes = coord_array.size ();
125 int matrixDimension = Adj_Matrix.size ();
127 if (matrixDimension != n_nodes)
129 NS_FATAL_ERROR (
"The number of lines in coordinate file is: " << n_nodes <<
" not equal to the number of nodes in adjacency matrix size " << matrixDimension);
139 nodes.Create (n_nodes);
150 internet.
Install (NodeContainer::GetGlobal ());
155 ipv4_n.
SetBase (
"10.0.0.0",
"255.255.255.252");
161 for (
size_t i = 0; i < Adj_Matrix.size (); i++)
163 for (
size_t j = 0; j < Adj_Matrix[i].size (); j++)
166 if (Adj_Matrix[i][j] == 1)
173 NS_LOG_INFO (
"matrix element [" << i <<
"][" << j <<
"] is 1");
177 NS_LOG_INFO (
"matrix element [" << i <<
"][" << j <<
"] is 0");
181 NS_LOG_INFO (
"Number of links in the adjacency matrix is: " << linkCount);
185 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
196 for (
size_t m = 0; m < coord_array.size (); m++)
198 positionAlloc_n->Add (
Vector (coord_array[m][0], coord_array[m][1], 0));
203 nLoc = CreateObject<ConstantPositionMobilityModel> ();
210 Vector nVec (coord_array[m][0], -coord_array[m][1], 0);
211 nLoc->SetPosition (nVec);
225 for (
int i = 0; i < n_nodes; i++)
235 for (
int i = 0; i < n_nodes; i++)
237 for (
int j = 0; j < n_nodes; j++)
256 onoff.SetConstantRate (
DataRate (AppPacketRate));
283 Simulator::Stop (
Seconds (SimTime));
286 Simulator::Destroy ();
298 std::ifstream adj_mat_file;
299 adj_mat_file.open (adj_mat_file_name.c_str (), std::ios::in);
300 if (adj_mat_file.fail ())
302 NS_FATAL_ERROR (
"File " << adj_mat_file_name.c_str () <<
" not found");
304 std::vector<std::vector<bool>> array;
308 while (!adj_mat_file.eof ())
311 getline (adj_mat_file, line);
314 NS_LOG_WARN (
"WARNING: Ignoring blank row in the array: " << i);
318 std::istringstream iss (line);
320 std::vector<bool> row;
323 while (iss >> element)
325 row.push_back (element);
336 NS_LOG_ERROR (
"ERROR: Number of elements in line " << i <<
": " << j <<
" not equal to number of elements in line 0: " << n_nodes);
337 NS_FATAL_ERROR (
"ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
341 array.push_back (row);
348 NS_LOG_ERROR (
"There are " << i <<
" rows and " << n_nodes <<
" columns.");
349 NS_FATAL_ERROR (
"ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
352 adj_mat_file.close ();
359 std::ifstream node_coordinates_file;
360 node_coordinates_file.open (node_coordinates_file_name.c_str (), std::ios::in);
361 if (node_coordinates_file.fail ())
363 NS_FATAL_ERROR (
"File " << node_coordinates_file_name.c_str () <<
" not found");
365 std::vector<std::vector<double>> coord_array;
368 while (!node_coordinates_file.eof ())
371 getline (node_coordinates_file, line);
375 NS_LOG_WARN (
"WARNING: Ignoring blank row: " << m);
379 std::istringstream iss (line);
381 std::vector<double> row;
383 while (iss >> coordinate)
385 row.push_back (coordinate);
391 NS_LOG_ERROR (
"ERROR: Number of elements at line#" << m <<
" is " << n <<
" which is not equal to 2 for node coordinates file");
397 coord_array.push_back (row);
401 node_coordinates_file.close ();
406void printMatrix (
const char* description, std::vector<std::vector<bool>> array)
408 std::cout <<
"**** Start " << description <<
"********" << std::endl;
409 for (
size_t m = 0; m < array.size (); m++)
411 for (
size_t n = 0; n < array[m].size (); n++)
413 std::cout << array[m][n] <<
' ';
415 std::cout << std::endl;
417 std::cout <<
"**** End " << description <<
"********" << std::endl;
423 std::cout <<
"**** Start " << description <<
"********" << std::endl;
424 for (
size_t m = 0; m < coord_array.size (); m++)
426 for (
size_t n = 0; n < coord_array[m].size (); n++)
428 std::cout << coord_array[m][n] <<
' ';
430 std::cout << std::endl;
432 std::cout <<
"**** End " << description <<
"********" << std::endl;
void Run(ObjectFactory &factory, uint32_t pop, uint32_t total, uint32_t runs, Ptr< RandomVariableStream > eventStream, bool calRev)
Perform the runs for a single scheduler type.
Interface to network animator.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
Mobility model for which the current position does not change once it has been set and until it is se...
Class for representing data rates.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
void SetDefault(std::string name, const AttributeValue &value)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Seconds(double value)
Construct a Time in the indicated unit.
void printMatrix(const char *description, std::vector< std::vector< bool > > array)
std::vector< std::vector< double > > readCordinatesFile(std::string node_coordinates_file_name)
void printCoordinateArray(const char *description, std::vector< std::vector< double > > coord_array)
std::vector< std::vector< bool > > readNxNMatrix(std::string adj_mat_file_name)
Every class exported by the ns3 library is enclosed in the ns3 namespace.