Small file reorganization (moving CCNx-unrelated stuff out of model/)
diff --git a/utils/annotated-topology-reader.cc b/utils/annotated-topology-reader.cc
new file mode 100644
index 0000000..d6bbad1
--- /dev/null
+++ b/utils/annotated-topology-reader.cc
@@ -0,0 +1,336 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "annotated-topology-reader.h"
+
+#include "ns3/nstime.h"
+#include "ns3/log.h"
+#include "ns3/assert.h"
+#include "ns3/names.h"
+#include "ns3/net-device-container.h"
+#include "ns3/point-to-point-helper.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/ipv4-global-routing-helper.h"
+#include "ns3/drop-tail-queue.h"
+#include "ns3/ipv4-interface.h"
+#include "ns3/ipv4.h"
+#include "ns3/string.h"
+#include "ns3/pointer.h"
+#include "ns3/uinteger.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/ccnx.h"
+#include "ns3/ccnx-face.h"
+
+#include "ns3/constant-position-mobility-model.h"
+
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <set>
+
+using namespace std;
+
+namespace ns3
+{
+
+NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReader");
+
+AnnotatedTopologyReader::AnnotatedTopologyReader (const std::string &path, double scale/*=1.0*/)
+ : m_path (path)
+ , m_randX (0, 100.0)
+ , m_randY (0, 100.0)
+ , m_scale (scale)
+{
+ NS_LOG_FUNCTION (this);
+
+ SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+}
+
+void
+AnnotatedTopologyReader::SetBoundingBox (double ulx, double uly, double lrx, double lry)
+{
+ NS_LOG_FUNCTION (this << ulx << uly << lrx << lry);
+
+ m_randX = UniformVariable (ulx, lrx);
+ m_randY = UniformVariable (uly, lry);
+}
+
+void
+AnnotatedTopologyReader::SetMobilityModel (const std::string &model)
+{
+ NS_LOG_FUNCTION (this << model);
+ m_mobilityFactory.SetTypeId (model);
+}
+
+AnnotatedTopologyReader::~AnnotatedTopologyReader ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+Ptr<Node>
+AnnotatedTopologyReader::CreateNode (const std::string name)
+{
+ return CreateNode (name, m_randX.GetValue (), m_randY.GetValue ());
+}
+
+Ptr<Node>
+AnnotatedTopologyReader::CreateNode (const std::string name, double posX, double posY)
+{
+ NS_LOG_FUNCTION (this << name << posX << posY);
+ Ptr<Node> node = CreateObject<Node> ();
+ Ptr<MobilityModel> loc = DynamicCast<MobilityModel> (m_mobilityFactory.Create ());
+ node->AggregateObject (loc);
+
+ loc->SetPosition (Vector (posX, posY, 0));
+
+ Names::Add (m_path, name, node);
+ m_nodes.Add (node);
+
+ return node;
+}
+
+NodeContainer
+AnnotatedTopologyReader::GetNodes () const
+{
+ return m_nodes;
+}
+
+const std::list<TopologyReader::Link>&
+AnnotatedTopologyReader::GetLinks () const
+{
+ return m_linksList;
+}
+
+NodeContainer
+AnnotatedTopologyReader::Read (void)
+{
+ ifstream topgen;
+ topgen.open (GetFileName ().c_str ());
+
+ if ( !topgen.is_open () )
+ {
+ NS_LOG_ERROR ("Cannot open file " << GetFileName () << " for reading");
+ return m_nodes;
+ }
+
+ while (!topgen.eof ())
+ {
+ string line;
+ getline (topgen, line);
+
+ if (line == "router") break;
+ }
+
+ while (!topgen.eof ())
+ {
+ string line;
+ getline (topgen,line);
+ if (line[0] == '#') continue; // comments
+ if (line=="link") break; // stop reading nodes
+
+ istringstream lineBuffer (line);
+ string name, city;
+ double latitude, longitude;
+
+ lineBuffer >> name >> city >> latitude >> longitude;
+ if (name.empty ()) continue;
+
+ Ptr<Node> node = CreateNode (name, m_scale*longitude, -m_scale*latitude);
+ }
+
+ map<string, set<string> > processedLinks; // to eliminate duplications
+
+ // SeekToSection ("link");
+ while (!topgen.eof ())
+ {
+ string line;
+ getline (topgen,line);
+ if (line == "") continue;
+ if (line[0] == '#') continue; // comments
+
+ // NS_LOG_DEBUG ("Input: [" << line << "]");
+
+ istringstream lineBuffer (line);
+ string from, to, capacity, metric, delay, maxPackets;
+
+ lineBuffer >> from >> to >> capacity >> metric >> delay >> maxPackets;
+
+ if (processedLinks[to].size () != 0 &&
+ processedLinks[to].find (from) != processedLinks[to].end ())
+ {
+ continue; // duplicated link
+ }
+ processedLinks[from].insert (to);
+
+ Ptr<Node> fromNode = Names::Find<Node> (m_path, from);
+ NS_ASSERT (fromNode != 0);
+ Ptr<Node> toNode = Names::Find<Node> (m_path, to);
+ NS_ASSERT (fromNode != 0);
+
+ Link link (fromNode, from, toNode, to);
+
+ link.SetAttribute ("DataRate", capacity);
+ link.SetAttribute ("OSPF", metric);
+
+ if (!delay.empty ())
+ link.SetAttribute ("Delay", delay);
+ if (!maxPackets.empty ())
+ link.SetAttribute ("MaxPackets", maxPackets);
+
+ AddLink (link);
+ NS_LOG_DEBUG ("New link " << from << " <==> " << to << " / " << capacity << " with " << metric << " metric (" << delay << ", " << maxPackets << ")");
+ }
+
+ NS_LOG_INFO ("Annotated topology created with " << m_nodes.GetN () << " nodes and " << LinksSize () << " links");
+ topgen.close ();
+
+ ApplySettings ();
+
+ return m_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"));
+ }
+}
+
+void
+AnnotatedTopologyReader::ApplyOspfMetric ()
+{
+ BOOST_FOREACH (const Link &link, m_linksList)
+ {
+ NS_LOG_DEBUG ("OSPF: " << link.GetAttribute ("OSPF"));
+ uint16_t metric = boost::lexical_cast<uint16_t> (link.GetAttribute ("OSPF"));
+
+ {
+ Ptr<Ipv4> ipv4 = link.GetFromNode ()->GetObject<Ipv4> ();
+ if (ipv4 != 0)
+ {
+ int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetFromNetDevice ());
+ NS_ASSERT (interfaceId >= 0);
+
+ ipv4->SetMetric (interfaceId,metric);
+ }
+
+ Ptr<Ccnx> ccnx = link.GetFromNode ()->GetObject<Ccnx> ();
+ if (ccnx != 0)
+ {
+ Ptr<CcnxFace> face = ccnx->GetFaceByNetDevice (link.GetFromNetDevice ());
+ NS_ASSERT (face != 0);
+
+ face->SetMetric (metric);
+ }
+ }
+
+ {
+ Ptr<Ipv4> ipv4 = link.GetToNode ()->GetObject<Ipv4> ();
+ if (ipv4 != 0)
+ {
+ int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetToNetDevice ());
+ NS_ASSERT (interfaceId >= 0);
+
+ ipv4->SetMetric (interfaceId,metric);
+ }
+
+ Ptr<Ccnx> ccnx = link.GetToNode ()->GetObject<Ccnx> ();
+ if (ccnx != 0)
+ {
+ Ptr<CcnxFace> face = ccnx->GetFaceByNetDevice (link.GetToNetDevice ());
+ NS_ASSERT (face != 0);
+
+ face->SetMetric (metric);
+ }
+ }
+ }
+}
+
+void
+AnnotatedTopologyReader::ApplySettings ()
+{
+ PointToPointHelper p2p;
+
+ BOOST_FOREACH (Link &link, m_linksList)
+ {
+ string tmp;
+
+ if (link.GetAttributeFailSafe ("DataRate", tmp))
+ {
+ NS_LOG_INFO ("DataRate = " + link.GetAttribute("DataRate"));
+ p2p.SetDeviceAttribute ("DataRate", StringValue (link.GetAttribute ("DataRate")));
+ }
+
+ if (link.GetAttributeFailSafe ("Delay", tmp))
+ {
+ NS_LOG_INFO ("Delay = " + link.GetAttribute("Delay"));
+ p2p.SetChannelAttribute ("Delay", StringValue (link.GetAttribute ("Delay")));
+ }
+
+ NetDeviceContainer nd = p2p.Install(link.GetFromNode (), link.GetToNode ());
+ link.SetNetDevices (nd.Get (0), nd.Get (1));
+
+ if (link.GetAttributeFailSafe ("MaxPackets", tmp))
+ {
+ NS_LOG_INFO ("MaxPackets = " + link.GetAttribute ("MaxPackets"));
+
+ PointerValue txQueue;
+
+ link.GetToNetDevice ()->GetAttribute ("TxQueue", txQueue);
+ NS_ASSERT (txQueue.Get<DropTailQueue> () != 0);
+ txQueue.Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute ("MaxPackets")));
+
+ link.GetFromNetDevice ()->GetAttribute ("TxQueue", txQueue);
+ NS_ASSERT (txQueue.Get<DropTailQueue> () != 0);
+ txQueue.Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute ("MaxPackets")));
+ }
+
+ }
+}
+
+void
+AnnotatedTopologyReader::SavePositions (const std::string &file) const
+{
+ ofstream os (file.c_str (), ios::trunc);
+ os << "router\n";
+
+ for (NodeContainer::Iterator node = m_nodes.Begin ();
+ node != m_nodes.End ();
+ node++)
+ {
+ std::string name = Names::FindName (*node);
+ Ptr<MobilityModel> mobility = (*node)->GetObject<MobilityModel> ();
+ Vector position = mobility->GetPosition ();
+
+ os << name << "\t" << "unknown" << "\t" << -position.y << "\t" << position.x << "\n";
+ }
+}
+
+}
diff --git a/utils/annotated-topology-reader.h b/utils/annotated-topology-reader.h
new file mode 100644
index 0000000..95ce123
--- /dev/null
+++ b/utils/annotated-topology-reader.h
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#ifndef __ANNOTATED_TOPOLOGY_READER_H__
+#define __ANNOTATED_TOPOLOGY_READER_H__
+
+#include "ns3/topology-reader.h"
+#include "ns3/random-variable.h"
+#include "ns3/object-factory.h"
+
+namespace ns3
+{
+
+/**
+ * \brief This class reads annotated topology and apply settings to the corresponding nodes and links
+ *
+ */
+class AnnotatedTopologyReader : public TopologyReader
+{
+public:
+ /**
+ * \brief Constructor
+ *
+ * \param path ns3::Names path
+ * \param scale Scaling factor for coordinates in input file
+ *
+ * \see ns3::Names class
+ */
+ AnnotatedTopologyReader (const std::string &path="", double scale=1.0);
+ 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 ();
+
+ /**
+ * \brief Get nodes read by the reader
+ */
+ NodeContainer
+ GetNodes () const;
+
+ /**
+ * \brief Get links read by the reader
+ */
+ const std::list<Link>&
+ GetLinks () const;
+
+ /**
+ * \brief Assign IPv4 addresses to all links
+ *
+ * Note, IPv4 stack should be installed on all nodes prior this call
+ *
+ * Every link will receive /24 netmask
+ *
+ * \param base Starting IPv4 address (second link will have base+256)
+ */
+ void
+ AssignIpv4Addresses (Ipv4Address base);
+
+ /**
+ * \brief Set bounding box where nodes will be randomly places (if positions are unspecified)
+ * \param ulx Upper left x coordinate
+ * \param uly Upper left y coordinate
+ * \param lrx Lower right x coordinate
+ * \param lry Lower right y coordinate
+ */
+ void
+ SetBoundingBox (double ulx, double uly, double lrx, double lry);
+
+ /**
+ * \brief Set mobility model to be used on nodes
+ * \param model class name of the model
+ */
+ void
+ SetMobilityModel (const std::string &model);
+
+ /**
+ * \brief Apply OSPF metric on Ipv4 (if exists) and Ccnx (if exists) stacks
+ */
+ void ApplyOspfMetric ();
+
+ /**
+ * \brief Save positions (e.g., after manual modification using visualizer)
+ */
+ void
+ SavePositions (const std::string &file) const;
+
+protected:
+ Ptr<Node>
+ CreateNode (const std::string name);
+
+ Ptr<Node>
+ CreateNode (const std::string name, double posX, double posY);
+
+protected:
+ /**
+ * \brief This method applies setting to corresponding nodes and links
+ * NetDeviceContainer must be allocated
+ * NodeContainer from Read method
+ */
+ void ApplySettings ();
+
+protected:
+ std::string m_path;
+ NodeContainer m_nodes;
+
+private:
+ AnnotatedTopologyReader (const AnnotatedTopologyReader&);
+ AnnotatedTopologyReader& operator= (const AnnotatedTopologyReader&);
+
+ UniformVariable m_randX;
+ UniformVariable m_randY;
+
+ ObjectFactory m_mobilityFactory;
+ double m_scale;
+};
+
+}
+
+#endif
+
+
diff --git a/utils/batches.cc b/utils/batches.cc
new file mode 100644
index 0000000..1dbccfa
--- /dev/null
+++ b/utils/batches.cc
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011,2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "ns3/batches.h"
+
+namespace ns3 {
+
+ATTRIBUTE_HELPER_CPP (Batches);
+
+std::ostream &
+operator << (std::ostream &os, const Batches &batch)
+{
+ for (Batches::const_iterator i = batch.begin (); i != batch.end (); i++)
+ os << i->get<0> () << " " << i->get<1> () << " ";
+
+ return os;
+}
+
+/**
+ * \brief Read components from input and add them to components. Will read input stream till eof
+ * Substrings separated by slashes will become separate components
+ */
+std::istream &
+operator >> (std::istream &is, Batches &batch)
+{
+ Time time;
+ uint32_t amount;
+ while (!is.eof ())
+ {
+ is >> time >> amount;
+ batch.Add (time, amount);
+ // std::cout << time << ", " << amount << ". \n";
+ }
+
+ is.clear ();
+ return is;
+}
+
+
+}
diff --git a/utils/batches.h b/utils/batches.h
new file mode 100644
index 0000000..d481a47
--- /dev/null
+++ b/utils/batches.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2011,2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef _BATCHES_H_
+#define _BATCHES_H_
+
+#include "ns3/attribute.h"
+#include "ns3/attribute-helper.h"
+#include "ns3/nstime.h"
+#include <list>
+#include <boost/tuple/tuple.hpp>
+
+namespace ns3 {
+
+class Batches : public std::list<boost::tuple<Time, uint32_t> >
+{
+public:
+ Batches () { };
+
+ void
+ Add (const Time &when, uint32_t amount)
+ {
+ push_back (boost::make_tuple<Time, uint32_t> (when, amount));
+ }
+};
+
+ATTRIBUTE_HELPER_HEADER (Batches);
+
+std::ostream &
+operator << (std::ostream &os, const Batches &batch);
+
+/**
+ * \brief Read components from input and add them to components. Will read input stream till eof
+ * Substrings separated by slashes will become separate components
+ */
+std::istream &
+operator >> (std::istream &is, Batches &batch);
+
+} // namespace ns3
+
+#endif // _BATCHES_H_
diff --git a/utils/rocketfuel-weights-reader.cc b/utils/rocketfuel-weights-reader.cc
new file mode 100644
index 0000000..acd3235
--- /dev/null
+++ b/utils/rocketfuel-weights-reader.cc
@@ -0,0 +1,180 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Hajime Tazaki
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Hajime Tazaki (tazaki@sfc.wide.ad.jp)
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "rocketfuel-weights-reader.h"
+
+#include "ns3/nstime.h"
+#include "ns3/log.h"
+#include "ns3/assert.h"
+#include "ns3/names.h"
+#include "ns3/net-device-container.h"
+#include "ns3/point-to-point-helper.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/internet-stack-helper.h"
+#include "ns3/ipv4-address-helper.h"
+#include "ns3/ipv4-global-routing-helper.h"
+#include "ns3/drop-tail-queue.h"
+#include "ns3/ipv4-interface.h"
+#include "ns3/ipv4.h"
+#include "ns3/string.h"
+#include "ns3/pointer.h"
+#include "ns3/uinteger.h"
+#include "ns3/ipv4-address.h"
+
+#include "ns3/mobility-model.h"
+
+#include <regex.h>
+
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+#include "../utils/spring-mobility-helper.h"
+
+#include <iomanip>
+#include <set>
+
+using namespace std;
+
+NS_LOG_COMPONENT_DEFINE ("RocketfuelWeightsReader");
+
+namespace ns3 {
+
+RocketfuelWeightsReader::RocketfuelWeightsReader (const std::string &path/*=""*/)
+ : AnnotatedTopologyReader (path)
+{
+ NS_LOG_FUNCTION (this);
+ SetMobilityModel ("ns3::SpringMobilityModel");
+}
+
+RocketfuelWeightsReader::~RocketfuelWeightsReader ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+void
+RocketfuelWeightsReader::SetFileType (uint8_t inputType)
+{
+ m_inputType = inputType;
+}
+
+NodeContainer
+RocketfuelWeightsReader::Read ()
+{
+ if (m_inputType == POSITIONS)
+ return AnnotatedTopologyReader::Read ();
+
+ ifstream topgen;
+ topgen.open (GetFileName ().c_str ());
+
+ if ( !topgen.is_open () )
+ {
+ NS_LOG_ERROR ("Cannot open file " << GetFileName () << " for reading");
+ return m_nodes;
+ }
+
+ map<string, set<string> > processedLinks; // to eliminate duplications
+ bool repeatedRun = LinksSize () > 0;
+ std::list<Link>::iterator linkIterator = m_linksList.begin ();
+
+ while (!topgen.eof ())
+ {
+ string line;
+ getline (topgen,line);
+ if (line == "") continue;
+ if (line[0] == '#') continue; // comments
+
+ // NS_LOG_DEBUG ("Input: [" << line << "]");
+
+ istringstream lineBuffer (line);
+ string from, to, attribute;
+
+ lineBuffer >> from >> to >> attribute;
+
+ if (processedLinks[to].size () != 0 &&
+ processedLinks[to].find (from) != processedLinks[to].end ())
+ {
+ continue; // duplicated link
+ }
+ processedLinks[from].insert (to);
+
+ Ptr<Node> fromNode = Names::Find<Node> (m_path, from);
+ if (fromNode == 0)
+ {
+ fromNode = CreateNode (from);
+ }
+
+ Ptr<Node> toNode = Names::Find<Node> (m_path, to);
+ if (toNode == 0)
+ {
+ toNode = CreateNode (to);
+ }
+
+ Link *link;
+ if (!repeatedRun)
+ link = new Link (fromNode, from, toNode, to);
+ else
+ {
+ NS_ASSERT (linkIterator != m_linksList.end ());
+ link = &(*linkIterator);
+
+ linkIterator++;
+ }
+
+ switch (m_inputType)
+ {
+ case WEIGHTS:
+ {
+ uint16_t metric = boost::lexical_cast<uint16_t> (attribute);
+ link->SetAttribute ("OSPF", boost::lexical_cast<string> (metric));
+ break;
+ }
+ case LATENCIES:
+ link->SetAttribute ("Delay", attribute+"ms");
+ break;
+ default:
+ ; //
+ }
+
+ NS_LOG_DEBUG ("Link " << from << " <==> " << to << " / " << attribute);
+ if (!repeatedRun)
+ {
+ AddLink (*link);
+ delete link;
+ }
+ }
+
+ topgen.close ();
+
+ if (!repeatedRun)
+ {
+ NS_LOG_INFO ("Rocketfuel topology created with " << m_nodes.GetN () << " nodes and " << LinksSize () << " links");
+ }
+ return m_nodes;
+}
+
+void
+RocketfuelWeightsReader::Commit ()
+{
+ ApplySettings ();
+
+ SpringMobilityHelper::InstallSprings (LinksBegin (), LinksEnd ());
+}
+
+} /* namespace ns3 */
diff --git a/utils/rocketfuel-weights-reader.h b/utils/rocketfuel-weights-reader.h
new file mode 100644
index 0000000..e93ca32
--- /dev/null
+++ b/utils/rocketfuel-weights-reader.h
@@ -0,0 +1,83 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2010 Hajime Tazaki
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Hajime Tazaki (tazaki@sfc.wide.ad.jp)
+ * Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#ifndef ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H
+#define ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H
+
+#include "annotated-topology-reader.h"
+#include "ns3/net-device-container.h"
+
+namespace ns3 {
+
+// ------------------------------------------------------------
+// --------------------------------------------
+/**
+ * \brief Topology file reader (extension of Rocketfuel-format type).
+ *
+ * http://www.cs.washington.edu/research/networking/rocketfuel/
+ *
+ * Only weights and latencies file is supported
+ */
+class RocketfuelWeightsReader : public AnnotatedTopologyReader
+{
+public:
+ RocketfuelWeightsReader (const std::string &path="");
+ virtual ~RocketfuelWeightsReader ();
+
+ void
+ SetFileType (uint8_t inputType);
+
+ /**
+ * \brief Main topology reading function.
+ *
+ * This method opens an input stream and reads the Rocketfuel-format file.
+ * Every row represents a topology link (the ids of a couple of nodes),
+ * so the input file is read line by line to figure out how many links
+ * and nodes are in the topology.
+ *
+ * \return the container of the nodes created (or empty container if there was an error)
+ */
+ virtual NodeContainer
+ Read (void);
+
+ void
+ Commit ();
+
+ enum
+ {
+ WEIGHTS,
+ LATENCIES,
+ POSITIONS
+ };
+
+private:
+ RocketfuelWeightsReader (const RocketfuelWeightsReader&);
+ RocketfuelWeightsReader& operator= (const RocketfuelWeightsReader&);
+
+private:
+ uint8_t m_inputType;
+
+}; // end class RocketfuelWeightsReader
+
+}; // end namespace ns3
+
+
+#endif /* ROCKETFUEL_TOPOLOGY_WEIGHTS_READER_H */
diff --git a/utils/weights-path-stretch-tag.cc b/utils/weights-path-stretch-tag.cc
new file mode 100644
index 0000000..fe3e41c
--- /dev/null
+++ b/utils/weights-path-stretch-tag.cc
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "weights-path-stretch-tag.h"
+#include "ns3/node.h"
+#include "ns3/names.h"
+
+namespace ns3 {
+
+WeightsPathStretchTag::WeightsPathStretchTag ()
+{
+}
+
+void
+WeightsPathStretchTag::AddPathInfo (Ptr<Node> node, uint32_t weight)
+{
+ m_infos.push_back (NodeWeightPair (node, weight));
+}
+
+
+TypeId WeightsPathStretchTag::GetTypeId ()
+{
+ static TypeId tid = TypeId("ns3::WeightsPathStretchTag")
+ .SetParent<Tag>()
+ .AddConstructor<WeightsPathStretchTag>()
+ ;
+ return tid;
+}
+
+// TypeId
+// WeightsPathStretchTag::GetInstanceTypeId () const
+// {
+// return GetTypeId ();
+// }
+
+uint64_t
+WeightsPathStretchTag::GetTotalWeight () const
+{
+ uint64_t total = 0;
+ for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin (); info != m_infos.end (); info++)
+ {
+ total += info->weight;
+ }
+ return total;
+}
+
+Ptr<Node>
+WeightsPathStretchTag::GetSourceNode () const
+{
+ NS_ASSERT (m_infos.size () > 0);
+ return m_infos.front ().node;
+}
+
+Ptr<Node>
+WeightsPathStretchTag::GetDestinationNode () const
+{
+ NS_ASSERT (m_infos.size () > 0);
+ return m_infos.back ().node;
+}
+
+uint32_t WeightsPathStretchTag::GetSerializedSize (void) const
+{
+ return 0;
+ // return sizeof (GetPointer (m_value.node)) + sizeof (m_value.weight);
+}
+
+void WeightsPathStretchTag::Serialize (TagBuffer i) const
+{
+ NS_FATAL_ERROR ("Serialization is not supported for this tag");
+ // m_value.node->Ref ();
+ // i.WriteU64 (reinterpret_cast<uint64_t> (GetPointer (m_value.node)));
+ // i.WriteU32 (m_value.weight);
+}
+
+void WeightsPathStretchTag::Deserialize (TagBuffer i)
+{
+ NS_FATAL_ERROR ("Deserialization is not supported for this tag");
+ // m_value.node = Ptr<Node> (reinterpret_cast<Node*> (i.ReadU64 ()), false);
+ // m_value.weight = i.ReadU32 ();
+}
+
+void WeightsPathStretchTag::Print (std::ostream &os) const
+{
+ for (std::list<NodeWeightPair>::const_iterator info = m_infos.begin ();
+ info != m_infos.end ();
+ info ++)
+ {
+ if (info != m_infos.begin ()) os << ",";
+ NS_ASSERT (info->node != 0);
+
+ os << info->node->GetId () << "(" << Names::FindName (info->node) << ")";
+ // std::string name = Names::FindName (info->node);
+ // if (!name.empty ())
+ // os << name;
+ // else
+ // os << info->node->GetId ();
+ os << ":" << info->weight;
+ }
+}
+
+} // namespace ns3
+
diff --git a/utils/weights-path-stretch-tag.h b/utils/weights-path-stretch-tag.h
new file mode 100644
index 0000000..644871f
--- /dev/null
+++ b/utils/weights-path-stretch-tag.h
@@ -0,0 +1,118 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
+ */
+
+#include "ns3/tag.h"
+
+#ifndef PATH_STRETCH_TAG_H
+#define PATH_STRETCH_TAG_H
+
+namespace ns3 {
+
+class Node;
+class Packet;
+
+//#define PATH_SPLICING_MAX_N_HOPS 38
+//#define PATH_SPLICING_MAX_SLICE_INDEX 16
+
+class WeightsPathStretchTag : public Tag
+{
+public:
+ struct NodeWeightPair
+ {
+ NodeWeightPair () : node (0), weight (0) { }
+ NodeWeightPair (Ptr<Node> _node, uint32_t _weight) : node (_node), weight (_weight) { }
+
+ Ptr<Node> node;
+ uint32_t weight;
+ };
+
+ static TypeId
+ GetTypeId ();
+
+ WeightsPathStretchTag ();
+ virtual ~WeightsPathStretchTag () { };
+
+ void
+ AddPathInfo (Ptr<Node> node, uint32_t weight);
+
+ uint64_t
+ GetTotalWeight () const;
+
+ Ptr<Node>
+ GetSourceNode () const;
+
+ Ptr<Node>
+ GetDestinationNode () const;
+
+ const std::list<NodeWeightPair> &
+ GetInfos () const
+ { return m_infos; }
+
+ // from Tag
+ virtual uint32_t
+ GetSerializedSize (void) const;
+
+ virtual void
+ Serialize (TagBuffer i) const;
+
+ virtual void
+ Deserialize (TagBuffer i);
+
+ virtual void
+ Print (std::ostream &os) const;
+
+private:
+ std::list<NodeWeightPair> m_infos;
+};
+
+// class DelaysPathStretchTag : public Tag
+// {
+// public:
+// DelaysPathStretchTag();
+
+// static TypeId GetTypeId(void);
+// virtual TypeId GetInstanceTypeId(void) const;
+
+// virtual uint32_t GetSerializedSize(void) const;
+// virtual void Serialize(TagBuffer i) const;
+// virtual void Deserialize(TagBuffer i);
+// virtual void Print(std::ostream &os) const;
+
+// int GetNHops();
+// void AddNewHop(double delay);
+// int GetCurrentHop();
+// void RemoveCurrentHop();
+// //void RandomizeTags(UniformVariable &rand, uint32_t max);
+
+// private:
+// //PathSplicingPathTag(const PathSplicingPathTag &o);
+// //PathSplicingPathTag &operator = (const PathSplicingPathTag &o);
+
+// //bool operator == (PathSplicingPathTag const &o) const;
+
+// private:
+// std::list<double> m_delays;
+// };
+
+
+} // namespace ns3
+
+
+#endif /* PATH_STRETCH_TAG_H */