Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(813)

Unified Diff: src/topology-read/model/brite-1-level-router-only-topology-reader.cc

Issue 15530043: New module pgbr (PGBR routing protocol) and extension of topology-read module
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/topology-read/model/brite-1-level-router-only-topology-reader.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/topology-read/model/brite-1-level-router-only-topology-reader.cc
@@ -0,0 +1,182 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) Waterford Institute of Technology, 2013, Julien Mineraud, BioFINT.
+ *
+ * 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: Julien Mineraud <julien.mineraud@gmail.com>
+ *
+ * Acknowledgements:
+ * This work has received support from Science Foundation Ireland via the
+ * "A Biologically inspired framework supporting network management for
+ * the Future Internet" starting investigator award (grant no. 09/SIRG/I1643).
+ */
+#include <fstream>
+#include <cstdlib>
+#include <sstream>
+
+#include "ns3/log.h"
+#include "brite-1-level-router-only-topology-reader.h"
+
+using namespace std;
+
+namespace ns3 {
+
+NS_LOG_COMPONENT_DEFINE ("Brite1LevelRouterOnlyTopologyReader");
+
+NS_OBJECT_ENSURE_REGISTERED (Brite1LevelRouterOnlyTopologyReader);
+
+TypeId
+Brite1LevelRouterOnlyTopologyReader::GetTypeId (void)
+{
+ static TypeId tid =
+ TypeId ("ns3::Brite1LevelRouterOnlyTopologyReader")
+ .SetParent<TopologyReader> ()
+ ;
+ return tid;
+}
+
+Brite1LevelRouterOnlyTopologyReader::Brite1LevelRouterOnlyTopologyReader ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+Brite1LevelRouterOnlyTopologyReader::~Brite1LevelRouterOnlyTopologyReader ()
+{
+ NS_LOG_FUNCTION (this);
+}
+
+NodeContainer
+Brite1LevelRouterOnlyTopologyReader::Read (void)
+{
+ ifstream topgen;
+ topgen.open (GetFileName ().c_str ());
+ map<string, Ptr<Node> > nodeMap;
+ NodeContainer nodes;
+
+ if ( !topgen.is_open () )
+ {
+ return nodes;
+ }
+
+ string from;
+ string to;
+ string length;
+ string delay;
+ string bandwidth;
+ string linkType;
+
+ int totnode = 0;
+ int totlink = 0;
+
+ istringstream lineBuffer;
+ string line;
+ string temp;
+
+ //skip the three first line and read the fourth
+ for (uint32_t i = 0; i < 4; i++)
+ {
+ getline (topgen,line);
+ }
+ lineBuffer.str (line);
+
+ lineBuffer >> temp >> temp >> totnode;
+
+ string type;
+ string nodeId;
+
+ nodes.Create (totnode);
+
+ for (int i = 0; i < totnode; i++)
+ {
+ getline (topgen,line);
+ //At the moment we dont do anything because the information on positioning or degrees are not used
+ lineBuffer.clear ();
+ lineBuffer.str (line);
+
+ lineBuffer >> nodeId;
+ lineBuffer >> temp >> temp; // No need for positions
+ lineBuffer >> temp >> temp >> temp;
+ lineBuffer >> type;
+
+ Ptr<Node> tmpNode = nodes.Get (atoi (nodeId.c_str ()));
+ nodeMap[nodeId] = tmpNode;
+
+ Vertex vertex (tmpNode, nodeId);
+ if ( !type.empty () )
+ {
+ vertex.SetAttribute ("type", type);
+ }
+ AddVertex (vertex);
+ }
+
+ //Skip the 2 next blank lines
+ for (int i = 0; i <= 2; i++)
+ {
+ getline (topgen,line);
+ }
+ lineBuffer.clear ();
+ lineBuffer.str (line);
+ lineBuffer >> temp >> temp >> totlink;
+
+ NS_LOG_INFO ("Brite topology should have " << totnode << " nodes and " << totlink << " links");
+
+ for (int i = 0; i < totlink && !topgen.eof (); i++)
+ {
+ getline (topgen,line);
+ lineBuffer.clear ();
+ lineBuffer.str (line);
+
+ lineBuffer >> temp; //No need for edgeId
+ lineBuffer >> from;
+ lineBuffer >> to;
+ lineBuffer >> length;
+ lineBuffer >> delay;
+ lineBuffer >> bandwidth;
+ lineBuffer >> temp;
+ lineBuffer >> temp;
+ lineBuffer >> linkType;
+
+ if ( (!from.empty ()) && (!to.empty ()) )
+ {
+ NS_LOG_INFO ( i << " From: " << from << " to: " << to );
+
+ Link link ( nodeMap[from], from, nodeMap[to], to );
+ if ( !length.empty () )
+ {
+ link.SetAttribute ("length", length);
+ }
+ if ( !delay.empty () )
+ {
+ link.SetAttribute ("delay", delay);
+ }
+ if ( !bandwidth.empty () )
+ {
+ link.SetAttribute ("bandwidth", bandwidth);
+ }
+ if ( !linkType.empty () )
+ {
+ link.SetAttribute ("type", linkType);
+ }
+ AddLink (link);
+ }
+ }
+
+ NS_LOG_INFO ("Brite topology created with " << VerticesSize () << " nodes and " << LinksSize () << " links");
+ topgen.close ();
+
+ return nodes;
+}
+
+} // namespace ns3
« no previous file with comments | « src/topology-read/model/brite-1-level-router-only-topology-reader.h ('k') | src/topology-read/model/inet-topology-reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b