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"
64 vector<vector<bool> >
readNxNMatrix (std::string adj_mat_file_name);
67 void printMatrix (
const char* description, vector<vector<bool> > array);
71 int main (
int argc,
char *argv[])
78 double SimTime = 3.00;
79 double SinkStartTime = 1.0001;
80 double SinkStopTime = 2.90001;
81 double AppStartTime = 2.0001;
82 double AppStopTime = 2.80001;
84 std::string AppPacketRate (
"40Kbps");
87 std::string LinkRate (
"10Mbps");
88 std::string LinkDelay (
"2ms");
92 srand ( (
unsigned)time ( NULL ) );
94 std::string tr_name (
"n-node-ppp.tr");
95 std::string pcap_name (
"n-node-ppp");
96 std::string flow_name (
"n-node-ppp.xml");
97 std::string anim_name (
"n-node-ppp.anim.xml");
99 std::string adj_mat_file_name (
"examples/matrix-topology/adjacency_matrix.txt");
100 std::string node_coordinates_file_name (
"examples/matrix-topology/node_coordinates.txt");
106 vector<vector<bool> > Adj_Matrix;
116 vector<vector<double> > coord_array;
122 int n_nodes = coord_array.size ();
123 int matrixDimension = Adj_Matrix.size ();
125 if (matrixDimension != n_nodes)
127 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);
148 internet.
Install (NodeContainer::GetGlobal ());
153 ipv4_n.
SetBase (
"10.0.0.0",
"255.255.255.252");
157 uint32_t linkCount = 0;
159 for (
size_t i = 0; i < Adj_Matrix.size (); i++)
161 for (
size_t j = 0; j < Adj_Matrix[i].size (); j++)
164 if (Adj_Matrix[i][j] == 1)
171 NS_LOG_INFO (
"matrix element [" << i <<
"][" << j <<
"] is 1");
175 NS_LOG_INFO (
"matrix element [" << i <<
"][" << j <<
"] is 0");
179 NS_LOG_INFO (
"Number of links in the adjacency matrix is: " << linkCount);
183 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
194 for (
size_t m = 0; m < coord_array.size (); m++)
196 positionAlloc_n->
Add (
Vector (coord_array[m][0], coord_array[m][1], 0));
201 nLoc = CreateObject<ConstantPositionMobilityModel> ();
208 Vector nVec (coord_array[m][0], -coord_array[m][1], 0);
223 for (
int i = 0; i < n_nodes; i++)
227 apps_sink.
Start (Seconds (SinkStartTime));
228 apps_sink.
Stop (Seconds (SinkStopTime));
233 for (
int i = 0; i < n_nodes; i++)
235 for (
int j = 0; j < n_nodes; j++)
256 apps.
Start (Seconds (AppStartTime + rn));
257 apps.
Stop (Seconds (AppStopTime));
281 Simulator::Stop (Seconds (SimTime));
284 Simulator::Destroy ();
296 ifstream adj_mat_file;
297 adj_mat_file.open (adj_mat_file_name.c_str (), ios::in);
298 if (adj_mat_file.fail ())
300 NS_FATAL_ERROR (
"File " << adj_mat_file_name.c_str () <<
" not found");
302 vector<vector<bool> > array;
306 while (!adj_mat_file.eof ())
309 getline (adj_mat_file, line);
312 NS_LOG_WARN (
"WARNING: Ignoring blank row in the array: " << i);
316 istringstream iss (line);
321 while (iss >> element)
323 row.push_back (element);
334 NS_LOG_ERROR (
"ERROR: Number of elements in line " << i <<
": " << j <<
" not equal to number of elements in line 0: " << n_nodes);
335 NS_FATAL_ERROR (
"ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
339 array.push_back (row);
346 NS_LOG_ERROR (
"There are " << i <<
" rows and " << n_nodes <<
" columns.");
347 NS_FATAL_ERROR (
"ERROR: The number of rows is not equal to the number of columns! in the adjacency matrix");
350 adj_mat_file.close ();
357 ifstream node_coordinates_file;
358 node_coordinates_file.open (node_coordinates_file_name.c_str (), ios::in);
359 if (node_coordinates_file.fail ())
361 NS_FATAL_ERROR (
"File " << node_coordinates_file_name.c_str () <<
" not found");
363 vector<vector<double> > coord_array;
366 while (!node_coordinates_file.eof ())
369 getline (node_coordinates_file, line);
373 NS_LOG_WARN (
"WARNING: Ignoring blank row: " << m);
377 istringstream iss (line);
381 while (iss >> coordinate)
383 row.push_back (coordinate);
389 NS_LOG_ERROR (
"ERROR: Number of elements at line#" << m <<
" is " << n <<
" which is not equal to 2 for node coordinates file");
395 coord_array.push_back (row);
399 node_coordinates_file.close ();
404 void printMatrix (
const char* description, vector<vector<bool> > array)
406 cout <<
"**** Start " << description <<
"********" << endl;
407 for (
size_t m = 0; m < array.size (); m++)
409 for (
size_t n = 0; n < array[m].size (); n++)
411 cout << array[m][n] <<
' ';
415 cout <<
"**** End " << description <<
"********" << endl;
421 cout <<
"**** Start " << description <<
"********" << endl;
422 for (
size_t m = 0; m < coord_array.size (); m++)
424 for (
size_t n = 0; n < coord_array[m].size (); n++)
426 cout << coord_array[m][n] <<
' ';
430 cout <<
"**** End " << description <<
"********" << endl;
holds a vector of ns3::Application pointers.
vector< vector< double > > readCordinatesFile(std::string node_coordinates_file_name)
void printCoordinateArray(const char *description, vector< vector< double > > coord_array)
void printMatrix(const char *description, vector< vector< bool > > array)
Manage ASCII trace files for device models.
smart pointer class similar to boost::intrusive_ptr
hold variables of type string
NetDeviceContainer Install(NodeContainer c)
Mobility model for which the current position does not change once it has been set and until it is se...
NS_LOG_COMPONENT_DEFINE("GenericTopologyCreation")
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
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. ...
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.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_FATAL_ERROR(msg)
fatal error handling
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
void AggregateObject(Ptr< Object > other)
Access to the Ipv4 forwarding table, interfaces, and configuration.
void SetDefault(std::string name, const AttributeValue &value)
void SetConstantRate(DataRate dataRate, uint32_t packetSize=512)
Helper function to set a constant rate source.
keep track of a set of node pointers.
int main(int argc, char *argv[])
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void SetPosition(const Vector &position)
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
vector< vector< bool > > readNxNMatrix(std::string adj_mat_file_name)
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
a class to store IPv4 address information on an interface
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Interface to network animator.
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
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...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Hold a floating point type.
void SetAttribute(std::string name, const AttributeValue &value)
Ptr< T > GetObject(void) const
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.