LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 Universita' di Firenze, Italy | 3 * Copyright (c) 2010 Universita' di Firenze, Italy |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include <fstream> | 22 #include <fstream> |
23 #include <cstdlib> | 23 #include <cstdlib> |
24 #include <iostream> | 24 #include <iostream> |
25 #include <sstream> | 25 #include <sstream> |
26 | 26 |
27 #include "ns3/log.h" | 27 #include "ns3/log.h" |
28 #include "orbis-topology-reader.h" | 28 #include "orbis-topology-reader.h" |
29 | 29 |
30 using namespace std; | 30 using namespace std; |
31 | 31 |
32 namespace ns3 | 32 namespace ns3 { |
33 { | |
34 | 33 |
35 NS_LOG_COMPONENT_DEFINE ("OrbisTopologyReader"); | 34 NS_LOG_COMPONENT_DEFINE ("OrbisTopologyReader"); |
36 | 35 |
37 NS_OBJECT_ENSURE_REGISTERED (OrbisTopologyReader); | 36 NS_OBJECT_ENSURE_REGISTERED (OrbisTopologyReader); |
38 | 37 |
39 TypeId OrbisTopologyReader::GetTypeId (void) | 38 TypeId OrbisTopologyReader::GetTypeId (void) |
40 { | 39 { |
41 static TypeId tid = TypeId ("ns3::OrbisTopologyReader") | 40 static TypeId tid = TypeId ("ns3::OrbisTopologyReader") |
42 .SetParent<Object> () | 41 .SetParent<Object> () |
43 ; | 42 ; |
44 return tid; | 43 return tid; |
45 } | 44 } |
46 | 45 |
47 OrbisTopologyReader::OrbisTopologyReader () | 46 OrbisTopologyReader::OrbisTopologyReader () |
48 { | 47 { |
49 NS_LOG_FUNCTION_NOARGS (); | 48 NS_LOG_FUNCTION (this); |
50 } | 49 } |
| 50 |
51 OrbisTopologyReader::~OrbisTopologyReader () | 51 OrbisTopologyReader::~OrbisTopologyReader () |
52 { | 52 { |
53 NS_LOG_FUNCTION_NOARGS (); | 53 NS_LOG_FUNCTION (this); |
54 } | 54 } |
55 | 55 |
56 void | 56 NodeContainer |
57 OrbisTopologyReader::DoDispose () | 57 OrbisTopologyReader::Read (void) |
58 { | |
59 NS_LOG_FUNCTION_NOARGS (); | |
60 | |
61 TopologyReaderInterface::DoDispose (); | |
62 // end OrbisTopologyReader::DoDispose | |
63 } | |
64 | |
65 int OrbisTopologyReader::Input (NodeContainer &nodes, map<string, TopologyNode >
&nodeMap, list<TopologyLink> &linksList) | |
66 { | 58 { |
67 ifstream topgen; | 59 ifstream topgen; |
68 topgen.open (m_fileName.c_str ()); | 60 topgen.open (GetFileName ().c_str ()); |
| 61 map<string, Ptr<Node> > nodeMap; |
| 62 NodeContainer nodes; |
69 | 63 |
70 if ( !topgen.is_open () ) | 64 if ( !topgen.is_open () ) |
71 { | 65 { |
72 return 0; | 66 return nodes; |
73 } | 67 } |
74 | 68 |
75 string from; | 69 string from; |
76 string to; | 70 string to; |
77 istringstream lineBuffer; | 71 istringstream lineBuffer; |
78 string line; | 72 string line; |
79 | 73 |
80 int linksNumber = 0; | 74 int linksNumber = 0; |
81 int nodesNumber = 0; | 75 int nodesNumber = 0; |
82 | 76 |
83 while (!topgen.eof ()) | 77 while (!topgen.eof ()) |
84 { | 78 { |
85 line.clear (); | 79 line.clear (); |
86 lineBuffer.clear (); | 80 lineBuffer.clear (); |
87 from.clear (); | 81 from.clear (); |
88 to.clear (); | 82 to.clear (); |
89 | 83 |
90 getline (topgen,line); | 84 getline (topgen,line); |
91 lineBuffer.str (line); | 85 lineBuffer.str (line); |
92 lineBuffer >> from; | 86 lineBuffer >> from; |
93 lineBuffer >> to; | 87 lineBuffer >> to; |
94 | 88 |
95 if ( (!from.empty ()) && (!to.empty ()) ) | 89 if ( (!from.empty ()) && (!to.empty ()) ) |
96 { | 90 { |
97 NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); | 91 NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); |
98 if ( nodeMap[from].nodePtr == 0 ) | 92 if ( nodeMap[from] == 0 ) |
99 { | 93 { |
100 Ptr<Node> tmpNode = CreateObject<Node> (); | 94 Ptr<Node> tmpNode = CreateObject<Node> (); |
101 nodeMap[from].nodePtr = tmpNode; | 95 nodeMap[from] = tmpNode; |
102 nodes.Add (tmpNode); | 96 nodes.Add (tmpNode); |
103 nodesNumber++; | 97 nodesNumber++; |
104 } | 98 } |
105 | 99 |
106 if (nodeMap[to].nodePtr == 0) | 100 if (nodeMap[to] == 0) |
107 { | 101 { |
108 Ptr<Node> tmpNode = CreateObject<Node> (); | 102 Ptr<Node> tmpNode = CreateObject<Node> (); |
109 nodeMap[to].nodePtr = tmpNode; | 103 nodeMap[to] = tmpNode; |
110 nodes.Add (tmpNode); | 104 nodes.Add (tmpNode); |
111 nodesNumber++; | 105 nodesNumber++; |
112 } | 106 } |
113 | 107 |
114 TopologyLink link; | 108 Link link ( nodeMap[from], from, nodeMap[to], to ); |
115 link.from = from; | 109 AddLink (link); |
116 link.to = to; | |
117 linksList.push_back (link); | |
118 | 110 |
119 linksNumber++; | 111 linksNumber++; |
120 } | 112 } |
121 } | 113 } |
122 NS_LOG_INFO ("Orbis topology created with " << nodesNumber << " nodes and " <<
linksNumber << " links"); | 114 NS_LOG_INFO ("Orbis topology created with " << nodesNumber << " nodes and " <<
linksNumber << " links"); |
123 topgen.close (); | 115 topgen.close (); |
124 | 116 |
125 return linksNumber; | 117 return nodes; |
126 } | 118 } |
127 | 119 |
128 } /* namespace ns3 */ | 120 } /* namespace ns3 */ |
129 | 121 |
LEFT | RIGHT |