Merge remote-tracking branch 'git.irl/Ilya'
diff --git a/model/annotated-topology-reader.cc b/model/annotated-topology-reader.cc
index c92aec0..4b17ba4 100644
--- a/model/annotated-topology-reader.cc
+++ b/model/annotated-topology-reader.cc
@@ -55,10 +55,10 @@
TypeId AnnotatedTopologyReader::GetTypeId (void)
{
- static TypeId tid = TypeId ("ns3::AnnotatedTopologyReader")
+ static TypeId tid = TypeId ("ns3::AnnotatedTopologyReader")
.SetParent<Object> ()
;
- return tid;
+ return tid;
}
AnnotatedTopologyReader::AnnotatedTopologyReader (const std::string &path)
@@ -68,9 +68,9 @@
, m_lrx (100.0)
, m_lry (100.0)
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION (this);
}
-
+
void
AnnotatedTopologyReader::SetBoundingBox (double ulx, double uly, double lrx, double lry)
{
@@ -84,27 +84,27 @@
AnnotatedTopologyReader::~AnnotatedTopologyReader ()
{
- NS_LOG_FUNCTION (this);
+ NS_LOG_FUNCTION (this);
}
NodeContainer
AnnotatedTopologyReader::Read (void)
{
- ifstream topgen;
- topgen.open (GetFileName ().c_str ());
- NodeContainer nodes;
+ ifstream topgen;
+ topgen.open (GetFileName ().c_str ());
+ NodeContainer nodes;
- if (!topgen.is_open ())
+ if ( !topgen.is_open () )
{
NS_LOG_ERROR ("Cannot open file " << GetFileName () << " for reading");
- return nodes;
+ return nodes;
}
-
- int linksNumber = 0;
- int nodesNumber = 0;
- string line;
- getline (topgen,line);
+ int linksNumber = 0;
+ int nodesNumber = 0;
+
+ string line;
+ getline (topgen,line);
istringstream headerLineBuffer (line);
int totnode;
@@ -112,22 +112,22 @@
headerLineBuffer >> totnode;
headerLineBuffer >> totlink;
- NS_LOG_INFO ("Annotated topology should have " << totnode << " nodes and " << totlink << " links");
-
- for (int i = 0; i < totlink && !topgen.eof (); i++)
+ NS_LOG_INFO ("Annotated topology should have " << totnode << " nodes and " << totlink << " links");
+
+ for (int i = 0; i < totlink && !topgen.eof (); i++)
{
- getline (topgen, line);
+ getline (topgen,line);
istringstream lineBuffer (line);
string from;
string to;
- lineBuffer >> from;
- lineBuffer >> to;
-
- if ( (!from.empty ()) && (!to.empty ()) )
+ lineBuffer >> from;
+ lineBuffer >> to;
+
+ if ( (!from.empty ()) && (!to.empty ()) )
{
- NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to );
-
+ NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to );
+
Ptr<Node> fromNode = Names::Find<Node> (m_path, from);
Ptr<Node> toNode = Names::Find<Node> (m_path, to);
@@ -136,7 +136,7 @@
fromNode = CreateObject<Node> ();
Names::Add (m_path, from, fromNode);
nodes.Add (fromNode);
- nodesNumber++;
+ nodesNumber++;
}
if (toNode == 0)
@@ -144,23 +144,23 @@
toNode = CreateObject<Node> ();
Names::Add (m_path, to, toNode);
nodes.Add (toNode);
- nodesNumber++;
+ nodesNumber++;
}
Link link (fromNode, from, toNode, to);
string dataRate;
lineBuffer >> dataRate;
-
+
string ospf;
lineBuffer >> ospf;
-
+
string delay;
lineBuffer >> delay;
-
+
string queueSizeNode1;
lineBuffer >> queueSizeNode1;
-
+
string queueSizeNode2;
lineBuffer >> queueSizeNode2;
@@ -173,65 +173,65 @@
NS_LOG_ERROR ("File [" << GetFileName () << ":" << i+2 << " wrong format, skipping");
continue;
}
-
+
link.SetAttribute ("DataRate", dataRate);
link.SetAttribute ("OSPF", ospf);
link.SetAttribute ("Delay", delay);
link.SetAttribute ("QueueSizeNode1", queueSizeNode1);
link.SetAttribute ("QueueSizeNode2", queueSizeNode2);
- AddLink (link);
+ AddLink (link);
- linksNumber++;
+ linksNumber++;
}
}
-
+
NS_ASSERT (nodesNumber == totnode && linksNumber == totlink);
- NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links");
- topgen.close ();
-
+ NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links");
+ topgen.close ();
+
ApplySettings ();
AssignCoordinates ();
- return nodes;
+ return nodes;
}
-
+
void
AnnotatedTopologyReader::AssignIpv4Addresses (Ipv4Address base)
{
Ipv4AddressHelper address (base, Ipv4Mask ("/24"));
-
+
BOOST_FOREACH (const Link &link, m_linksList)
{
address.Assign (NetDeviceContainer (link.GetFromNetDevice (),
link.GetToNetDevice ()));
-
+
base = Ipv4Address (base.Get () + 256);
address.SetBase (base, Ipv4Mask ("/24"));
- }
-
+ }
+
ApplyOspfMetric ();
-}
-
+ }
+
void
AnnotatedTopologyReader::ApplyOspfMetric ()
-{
- BOOST_FOREACH (const Link &link, m_linksList)
{
+ BOOST_FOREACH (const Link &link, m_linksList)
+ {
uint16_t metric = boost::lexical_cast<uint16_t> (link.GetAttribute ("OSPF"));
-
- {
+
+ {
Ptr<Ipv4> ipv4 = link.GetFromNode ()->GetObject<Ipv4> ();
NS_ASSERT (ipv4 != 0);
-
+
int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetFromNetDevice ());
NS_ASSERT (interfaceId >= 0);
-
+
ipv4->SetMetric (interfaceId,metric);
- }
-
- {
+ }
+
+ {
Ptr<Ipv4> ipv4 = link.GetToNode ()->GetObject<Ipv4> ();
NS_ASSERT (ipv4 != 0);
@@ -239,68 +239,68 @@
NS_ASSERT (interfaceId >= 0);
ipv4->SetMetric (interfaceId,metric);
- }
}
}
+}
void
AnnotatedTopologyReader::ApplySettings ()
{
PointToPointHelper p2p;
-
+
// temporary queue, will be changed later
p2p.SetQueue ("ns3::DropTailQueue",
"MaxPackets", StringValue("100"));
-
+
BOOST_FOREACH (Link &link, m_linksList)
{
NS_LOG_INFO ("DataRate = " + link.GetAttribute("DataRate")+"Kbps");
p2p.SetDeviceAttribute ("DataRate", StringValue(link.GetAttribute("DataRate")+"Kbps"));
-
+
NS_LOG_INFO ("Delay = " + link.GetAttribute("Delay")+"ms");
p2p.SetChannelAttribute ("Delay", StringValue(link.GetAttribute("Delay")+"ms"));
-
+
NetDeviceContainer nd = p2p.Install(link.GetFromNode (), link.GetToNode ());
link.SetNetDevices (nd.Get (0), nd.Get (1));
NS_LOG_INFO ("Queue: " << link.GetAttribute("QueueSizeNode1") << " <==> " << link.GetAttribute("QueueSizeNode2"));
-
+
PointerValue txQueueFrom;
link.GetFromNetDevice ()->GetAttribute ("TxQueue", txQueueFrom);
NS_ASSERT (txQueueFrom.Get<DropTailQueue> () != 0);
-
+
PointerValue txQueueTo;
link.GetToNetDevice ()->GetAttribute ("TxQueue", txQueueTo);
NS_ASSERT (txQueueTo.Get<DropTailQueue> () != 0);
-
+
txQueueFrom.Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute("QueueSizeNode1")));
txQueueTo. Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute("QueueSizeNode2")));
- }
-}
+ }
+ }
void
AnnotatedTopologyReader::AssignCoordinates ()
{
UniformVariable randX (m_ulx, m_lrx);
- double x = 0.0;
+ double x = 0.0;
UniformVariable randY (m_uly, m_lry);
- double y = 0.0;
+ double y = 0.0;
BOOST_FOREACH (Link &link, m_linksList)
{
Ptr<ConstantPositionMobilityModel> loc = link.GetFromNode ()->GetObject<ConstantPositionMobilityModel> ();
if (loc != 0)
continue; // no need to assign twice
-
- loc = CreateObject<ConstantPositionMobilityModel> ();
+
+ loc = CreateObject<ConstantPositionMobilityModel> ();
link.GetFromNode ()->AggregateObject (loc);
x = randX.GetValue();
y = randY.GetValue();
- NS_LOG_INFO("X = "<<x <<"Y = "<<y);
-
+ NS_LOG_INFO("X = "<<x <<"Y = "<<y);
+
loc->SetPosition (Vector (x, y, 0));
+ }
}
-}
}
diff --git a/model/annotated-topology-reader.h b/model/annotated-topology-reader.h
index 6eec5ad..6346b6a 100644
--- a/model/annotated-topology-reader.h
+++ b/model/annotated-topology-reader.h
@@ -27,18 +27,18 @@
{
/**
- * \brief This class reads annotated topology and apply settings to the corresponding nodes and links
- * Input File Format
- * 1st line is NumberOfNodes TAB NumberofLinks
- * Nth line is NodeID1 TAB NodeID2 TAB DataRateKBPS TAB OSPF TAB DelayMiliseconds TAB QueueSizeInPacketsNode1 TAB QueueSizeInPacketsNode2
- *
- */
+* \brief This class reads annotated topology and apply settings to the corresponding nodes and links
+* Input File Format
+* 1st line is NumberOfNodes TAB NumberofLinks
+* Nth line is NodeID1 TAB NodeID2 TAB DataRateKBPS TAB OSPF TAB DelayMiliseconds TAB QueueSizeInPacketsNode1 TAB QueueSizeInPacketsNode2 TAB X-coordinate-node1 TAB Y-coordinate-node1 TAB X-coordinate-node2 TAB Y-coordinate-node2
+*
+*/
class AnnotatedTopologyReader : public TopologyReader
{
public:
- typedef std::list< Link >::iterator LinksIterator;
- static TypeId GetTypeId (void);
-
+ typedef std::list< Link >::iterator LinksIterator;
+ static TypeId GetTypeId (void);
+
/**
* \brief Constructor
*
@@ -47,19 +47,19 @@
* \see ns3::Names class
*/
AnnotatedTopologyReader (const std::string &path="");
- virtual ~AnnotatedTopologyReader ();
-
- /**
- * \brief Main annotated topology reading function.
- *
- * This method opens an input stream and reads topology file with annotations.
- *
- * \return the container of the nodes created (or empty container if there was an error)
- */
+ virtual ~AnnotatedTopologyReader ();
+
+ /**
+ * \brief Main annotated topology reading function.
+ *
+ * This method opens an input stream and reads topology file with annotations.
+ *
+ * \return the container of the nodes created (or empty container if there was an error)
+ */
virtual
NodeContainer Read (void);
-
- /**
+
+ /**
* \brief Set bounding box for the nodes
*/
void
@@ -79,17 +79,17 @@
private:
/**
- * \brief This method applies setting to corresponding nodes and links
- * NetDeviceContainer must be allocated
- * NodeContainer from Read method
- */
+ * \brief This method applies setting to corresponding nodes and links
+ * NetDeviceContainer must be allocated
+ * NodeContainer from Read method
+ */
void ApplySettings ();
void AssignCoordinates ();
void ApplyOspfMetric ();
-
+
private:
- AnnotatedTopologyReader (const AnnotatedTopologyReader&);
- AnnotatedTopologyReader& operator= (const AnnotatedTopologyReader&);
+ AnnotatedTopologyReader (const AnnotatedTopologyReader&);
+ AnnotatedTopologyReader& operator= (const AnnotatedTopologyReader&);
std::string m_path;
double m_ulx;
diff --git a/model/rocketfuel-weights-reader.cc b/model/rocketfuel-weights-reader.cc
index 67559d5..30d0780 100644
--- a/model/rocketfuel-weights-reader.cc
+++ b/model/rocketfuel-weights-reader.cc
@@ -78,128 +78,7 @@
std::map<std::string, Ptr<Node> > nodeMap;
NodeContainer
- RocketfuelWeightsReader::GenerateFromMapsFile (int argc, char *argv[])
- {
- std::string uid;
- std::string loc;
- std::string ptr;
- std::string name;
- std::string nuid;
- bool dns = false;
- bool bb = false;
- int num_neigh_s = 0;
- unsigned int num_neigh = 0;
- int radius = 0;
- std::vector <std::string> neigh_list;
- NodeContainer nodes;
-
- uid = argv[0];
- loc = argv[1];
-
- if (argv[2])
- {
- dns = true;
- }
-
- if (argv[3])
- {
- bb = true;
- }
-
- num_neigh_s = ::atoi (argv[4]);
- if (num_neigh_s < 0)
- {
- num_neigh = 0;
- NS_LOG_WARN ("Negative number of neighbors given");
- }
- else
- {
- num_neigh = num_neigh_s;
- }
-
- /* neighbors */
- if (argv[6])
- {
- char *nbr;
- char *stringp = argv[6];
- while ((nbr = strsep (&stringp, " \t")) != NULL)
- {
- nbr[strlen (nbr) - 1] = '\0';
- neigh_list.push_back (nbr + 1);
- }
- }
- if (num_neigh != neigh_list.size ())
- {
- NS_LOG_WARN ("Given number of neighbors = " << num_neigh << " != size of neighbors list = " << neigh_list.size ());
- }
-
- /* externs */
- if (argv[7])
- {
- // euid = argv[7];
- }
-
- /* name */
- if (argv[8])
- {
- name = argv[8];
- }
-
- radius = ::atoi (&argv[9][1]);
- if (radius > 0)
- {
- return nodes;
- }
-
- /* uid @loc [+] [bb] (num_neigh) [&ext] -> <nuid-1> <nuid-2> ... {-euid} ... =name[!] rn */
- NS_LOG_INFO ("Load Node[" << uid << "]: location: " << loc << " dns: " << dns
- << " bb: " << bb << " neighbors: " << neigh_list.size ()
- << "(" << "%d" << ") externals: \"%s\"(%d) "
- << "name: " << name << " radius: " << radius);
-
- //cast bb and dns to void, to suppress variable set but not used compiler warning
- //in optimized builds
- (void) bb;
- (void) dns;
-
- // Create node and link
- if (!uid.empty ())
- {
- if (nodeMap[uid] == 0)
- {
- Ptr<Node> tmpNode = CreateObject<Node> ();
- nodeMap[uid] = tmpNode;
- nodes.Add (tmpNode);
- nodesNumber++;
- }
-
- for (uint32_t i = 0; i < neigh_list.size (); ++i)
- {
- nuid = neigh_list[i];
-
- if (nuid.empty ())
- {
- return nodes;
- }
-
- if (nodeMap[nuid] == 0)
- {
- Ptr<Node> tmpNode = CreateObject<Node> ();
- nodeMap[nuid] = tmpNode;
- nodes.Add (tmpNode);
- nodesNumber++;
- }
- NS_LOG_INFO (linksNumber << ":" << nodesNumber << " From: " << uid << " to: " << nuid);
- Link link (nodeMap[uid], uid, nodeMap[nuid], nuid);
- AddLink (link);
- linksNumber++;
- }
- }
- return nodes;
- }
-
- NodeContainer
- RocketfuelWeightsReader::GenerateFromWeightsFile (int argc, char *argv[])
+ RocketfuelWeightsReader::GenerateFromWeightsFile (int argc, char *argv[], char *argl[])
{
/* uid @loc [+] [bb] (num_neigh) [&ext] -> <nuid-1> <nuid-2> ... {-euid} ... =name[!] rn */
std::string sname;
@@ -210,6 +89,7 @@
sname = argv[0];
tname = argv[1];
double v = strtod (argv[2], &endptr); // weight
+ double l = strtod (argl[2], &endptr); //latency
// cast v to void , to suppress 'v' set but not used compiler warning
//(void) v;
@@ -255,10 +135,19 @@
if (!found)
{
Link link (nodeMap[sname], sname, nodeMap[tname], tname);
+
std::ostringstream s;
s << std::setprecision(2) << v;
std::string ss = s.str();
link.SetAttribute ("OSPF", ss);
+
+ std::ostringstream s2;
+ s2 << std::setprecision(2) << l;
+ std::string ss2 = s2.str();
+ link.SetAttribute("Latency", ss2);
+ NS_LOG_INFO("Written Latency = " << ss2);
+
+
AddLink (link);
linksNumber++;
}
@@ -307,16 +196,29 @@
return RF_UNKNOWN;
}
-
NodeContainer
RocketfuelWeightsReader::Read (void)
{
+ NodeContainer nodes;
+ NS_LOG_INFO("Not implemented");
+ return nodes;
+ }
+
+ NodeContainer
+ RocketfuelWeightsReader::Read (std::string latenciesFile)
+ {
std::ifstream topgen;
topgen.open (GetFileName ().c_str ());
NodeContainer nodes;
+ std::ifstream latencies;
+ latencies.open(latenciesFile.c_str());
+
std::istringstream lineBuffer;
+ std::istringstream lineBuffer2;
std::string line;
+ std::string line2;
+
int lineNumber = 0;
enum RF_FileType ftype = RF_UNKNOWN;
char errbuf[512];
@@ -327,19 +229,31 @@
return nodes;
}
+ if (!latencies.is_open ())
+ {
+ NS_LOG_WARN ("Couldn't open Latencies file " << latenciesFile);
+ return nodes;
+ }
+
while (!topgen.eof ())
{
int ret;
int argc;
char *argv[REGMATCH_MAX];
+ char *argl[REGMATCH_MAX];
char *buf;
+ char *buf2;
lineNumber++;
line.clear ();
+ line2.clear ();
lineBuffer.clear ();
+ lineBuffer2.clear ();
getline (topgen, line);
+ getline (latencies, line2);
buf = (char *)line.c_str ();
+ buf2 = (char *)line2.c_str ();
if (lineNumber == 1)
{
@@ -383,6 +297,7 @@
}
ret = regexec (®ex, buf, REGMATCH_MAX, regmatch, 0);
+ regexec (®ex, buf2, REGMATCH_MAX, regmatch, 0);
if (ret == REG_NOMATCH)
{
NS_LOG_WARN ("match failed (weights file): %s" << buf);
@@ -392,6 +307,7 @@
}
line = buf;
+ line2 = buf2;
argc = 0;
/* regmatch[0] is the entire strings that matched */
@@ -400,22 +316,26 @@
if (regmatch[i].rm_so == -1)
{
argv[i - 1] = NULL;
+ argl[i - 1] = NULL;
}
else
{
line[regmatch[i].rm_eo] = '\0';
+ line2[regmatch[i].rm_eo] = '\0';
argv[i - 1] = &line[regmatch[i].rm_so];
+ argl[i - 1] = &line2[regmatch[i].rm_so];
argc = i;
}
}
if (ftype == RF_MAPS)
{
- nodes.Add (GenerateFromMapsFile (argc, argv));
+ NS_LOG_INFO("MAPS FILE is not supported");
+ //nodes.Add (GenerateFromMapsFile (argc, argv));
}
else if (ftype == RF_WEIGHTS)
{
- nodes.Add (GenerateFromWeightsFile (argc, argv));
+ nodes.Add (GenerateFromWeightsFile (argc, argv, argl));
}
else
{
@@ -427,7 +347,7 @@
topgen.close ();
-
+ latencies.close ();
NS_LOG_INFO ("Rocketfuel topology created with " << nodesNumber << " nodes and " << linksNumber << " links");
return nodes;
}
@@ -486,7 +406,11 @@
for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ )
{
p2p.SetDeviceAttribute("DataRate", StringValue("9920000Kbps"));
- p2p.SetChannelAttribute("Delay", StringValue("10ms"));
+ //p2p.SetChannelAttribute("Delay", StringValue("10ms"));
+ NS_LOG_INFO("Latency = " + iter2->GetAttribute("Latency")+"ms");
+ p2p.SetChannelAttribute("Delay", StringValue(iter2->GetAttribute("Latency")+"ms"));
+
+
p2p.SetQueue("ns3::DropTailQueue","MaxPackets",StringValue("100"));
ndc[i] = p2p.Install(nc[i]);
diff --git a/model/rocketfuel-weights-reader.h b/model/rocketfuel-weights-reader.h
index bea3bff..9b89a92 100644
--- a/model/rocketfuel-weights-reader.h
+++ b/model/rocketfuel-weights-reader.h
@@ -77,6 +77,8 @@
*
* \return the container of the nodes created (or empty container if there was an error)
*/
+ NodeContainer Read (std::string latenciesFile);
+
virtual NodeContainer Read (void);
void ApplySettings(NetDeviceContainer* ndc, NodeContainer* nc);
@@ -84,12 +86,9 @@
private:
RocketfuelWeightsReader (const RocketfuelWeightsReader&);
RocketfuelWeightsReader& operator= (const RocketfuelWeightsReader&);
- // Parser for the *.cch file available at:
- // http://www.cs.washington.edu/research/networking/rocketfuel/maps/rocketfuel_maps_cch.tar.gz
- NodeContainer GenerateFromMapsFile (int argc, char *argv[]);
// Parser for the weights.* file available at:
// http://www.cs.washington.edu/research/networking/rocketfuel/maps/weights-dist.tar.gz
- NodeContainer GenerateFromWeightsFile (int argc, char *argv[]);
+ NodeContainer GenerateFromWeightsFile (int argc, char *argv[], char *argl[]);
enum RF_FileType
{