40 #include "ns3/applications-module.h"
41 #include "ns3/assert.h"
42 #include "ns3/core-module.h"
43 #include "ns3/global-route-manager.h"
44 #include "ns3/internet-module.h"
45 #include "ns3/ipv4-global-routing-helper.h"
46 #include "ns3/mobility-module.h"
47 #include "ns3/netanim-module.h"
48 #include "ns3/network-module.h"
49 #include "ns3/point-to-point-module.h"
62 std::vector<std::vector<bool>>
readNxNMatrix(std::string adj_mat_file_name);
63 std::vector<std::vector<double>>
readCoordinatesFile(std::string node_coordinates_file_name);
64 void printCoordinateArray(
const char* description, std::vector<std::vector<double>> coord_array);
65 void printMatrix(
const char* description, std::vector<std::vector<bool>> array);
70 main(
int argc,
char* argv[])
76 double SimTime = 3.00;
77 double SinkStartTime = 1.0001;
78 double SinkStopTime = 2.90001;
79 double AppStartTime = 2.0001;
80 double AppStopTime = 2.80001;
82 std::string AppPacketRate(
"40Kbps");
85 std::string LinkRate(
"10Mbps");
86 std::string LinkDelay(
"2ms");
90 srand((
unsigned)time(
nullptr));
92 std::string tr_name(
"n-node-ppp.tr");
93 std::string pcap_name(
"n-node-ppp");
94 std::string flow_name(
"n-node-ppp.xml");
95 std::string anim_name(
"n-node-ppp.anim.xml");
97 std::string adj_mat_file_name(
"examples/matrix-topology/adjacency_matrix.txt");
98 std::string node_coordinates_file_name(
"examples/matrix-topology/node_coordinates.txt");
101 cmd.Parse(argc, argv);
107 std::vector<std::vector<bool>> Adj_Matrix;
117 std::vector<std::vector<double>> coord_array;
123 int n_nodes = coord_array.size();
124 int matrixDimension = Adj_Matrix.size();
126 if (matrixDimension != n_nodes)
129 << n_nodes <<
" not equal to the number of nodes in adjacency matrix size "
156 ipv4_n.
SetBase(
"10.0.0.0",
"255.255.255.252");
160 uint32_t linkCount = 0;
162 for (
size_t i = 0; i < Adj_Matrix.size(); i++)
164 for (
size_t j = 0; j < Adj_Matrix[i].size(); j++)
166 if (Adj_Matrix[i][j])
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);
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);
224 for (
int i = 0; i < n_nodes; i++)
236 for (
int i = 0; i < n_nodes; i++)
238 for (
int j = 0; j < n_nodes; j++)
250 double rn =
x->GetValue();
256 "ns3::UdpSocketFactory",
298 std::vector<std::vector<bool>>
301 std::ifstream adj_mat_file;
302 adj_mat_file.open(adj_mat_file_name, std::ios::in);
303 if (adj_mat_file.fail())
307 std::vector<std::vector<bool>> array;
311 while (!adj_mat_file.eof())
314 getline(adj_mat_file, line);
317 NS_LOG_WARN(
"WARNING: Ignoring blank row in the array: " << i);
321 std::istringstream iss(line);
323 std::vector<bool> row;
326 while (iss >> element)
328 row.push_back(element);
341 <<
" not equal to number of elements in line 0: " << n_nodes);
342 NS_FATAL_ERROR(
"ERROR: The number of rows is not equal to the number of columns! in "
343 "the adjacency matrix");
347 array.push_back(row);
354 NS_LOG_ERROR(
"There are " << i <<
" rows and " << n_nodes <<
" columns.");
355 NS_FATAL_ERROR(
"ERROR: The number of rows is not equal to the number of columns! in the "
359 adj_mat_file.close();
363 std::vector<std::vector<double>>
366 std::ifstream node_coordinates_file;
367 node_coordinates_file.open(node_coordinates_file_name, std::ios::in);
368 if (node_coordinates_file.fail())
370 NS_FATAL_ERROR(
"File " << node_coordinates_file_name <<
" not found");
372 std::vector<std::vector<double>> coord_array;
375 while (!node_coordinates_file.eof())
378 getline(node_coordinates_file, line);
386 std::istringstream iss(line);
388 std::vector<double> row;
390 while (iss >> coordinate)
392 row.push_back(coordinate);
400 <<
" which is not equal to 2 for node coordinates file");
406 coord_array.push_back(row);
410 node_coordinates_file.close();
415 printMatrix(
const char* description, std::vector<std::vector<bool>> array)
417 std::cout <<
"**** Start " << description <<
"********" << std::endl;
418 for (
size_t m = 0;
m < array.size();
m++)
420 for (
size_t n = 0; n < array[
m].size(); n++)
422 std::cout << array[
m][n] <<
' ';
424 std::cout << std::endl;
426 std::cout <<
"**** End " << description <<
"********" << std::endl;
432 std::cout <<
"**** Start " << description <<
"********" << std::endl;
433 for (
size_t m = 0;
m < coord_array.size();
m++)
435 for (
size_t n = 0; n < coord_array[
m].size(); n++)
437 std::cout << coord_array[
m][n] <<
' ';
439 std::cout << std::endl;
441 std::cout <<
"**** End " << description <<
"********" << std::endl;
Interface to network animator.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
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...
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.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address NewNetwork()
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
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.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
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.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() 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.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
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.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Seconds(double value)
Construct a Time in the indicated unit.
AnimationInterface * anim
void printCoordinateArray(const char *description, std::vector< std::vector< double >> coord_array)
std::vector< std::vector< bool > > readNxNMatrix(std::string adj_mat_file_name)
void printMatrix(const char *description, std::vector< std::vector< bool >> array)
std::vector< std::vector< double > > readCoordinatesFile(std::string node_coordinates_file_name)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< PacketSink > sink
Pointer to the packet sink application.