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 26 matching lines...) Expand all Loading... |
37 TypeId InetTopologyReader::GetTypeId (void) | 37 TypeId InetTopologyReader::GetTypeId (void) |
38 { | 38 { |
39 static TypeId tid = TypeId ("ns3::InetTopologyReader") | 39 static TypeId tid = TypeId ("ns3::InetTopologyReader") |
40 .SetParent<Object> () | 40 .SetParent<Object> () |
41 ; | 41 ; |
42 return tid; | 42 return tid; |
43 } | 43 } |
44 | 44 |
45 InetTopologyReader::InetTopologyReader () | 45 InetTopologyReader::InetTopologyReader () |
46 { | 46 { |
47 NS_LOG_FUNCTION_NOARGS (); | 47 NS_LOG_FUNCTION (this); |
48 } | 48 } |
49 | 49 |
50 InetTopologyReader::~InetTopologyReader () | 50 InetTopologyReader::~InetTopologyReader () |
51 { | 51 { |
52 NS_LOG_FUNCTION_NOARGS (); | 52 NS_LOG_FUNCTION (this); |
53 } | 53 } |
54 | 54 |
55 void | 55 NodeContainer |
56 InetTopologyReader::DoDispose () | 56 InetTopologyReader::Read (void) |
57 { | |
58 NS_LOG_FUNCTION_NOARGS (); | |
59 | |
60 TopologyReader::DoDispose (); | |
61 // end InetTopologyReader::DoDispose | |
62 } | |
63 | |
64 int32_t | |
65 InetTopologyReader::Read (NodeContainer &nodes, list<TopologyLink> &linksList, m
ap<string, TopologyNode > &nodeMap) | |
66 { | 57 { |
67 ifstream topgen; | 58 ifstream topgen; |
68 topgen.open (m_fileName.c_str ()); | 59 topgen.open (GetFileName ().c_str ()); |
| 60 map<string, Ptr<Node> > nodeMap; |
| 61 NodeContainer nodes; |
69 | 62 |
70 if ( !topgen.is_open () ) | 63 if ( !topgen.is_open () ) |
71 { | 64 { |
72 return -1; | 65 return nodes; |
73 } | 66 } |
74 | 67 |
75 string from; | 68 string from; |
76 string to; | 69 string to; |
77 string linkAttr; | 70 string linkAttr; |
78 | 71 |
79 int linksNumber = 0; | 72 int linksNumber = 0; |
80 int nodesNumber = 0; | 73 int nodesNumber = 0; |
81 | 74 |
82 int totnode = 0; | 75 int totnode = 0; |
(...skipping 21 matching lines...) Expand all Loading... |
104 lineBuffer.str (line); | 97 lineBuffer.str (line); |
105 | 98 |
106 lineBuffer >> from; | 99 lineBuffer >> from; |
107 lineBuffer >> to; | 100 lineBuffer >> to; |
108 lineBuffer >> linkAttr; | 101 lineBuffer >> linkAttr; |
109 | 102 |
110 if ( (!from.empty ()) && (!to.empty ()) ) | 103 if ( (!from.empty ()) && (!to.empty ()) ) |
111 { | 104 { |
112 NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); | 105 NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); |
113 | 106 |
114 if ( nodeMap[from].nodePtr == 0 ) | 107 if ( nodeMap[from] == 0 ) |
115 { | 108 { |
116 Ptr<Node> tmpNode = CreateObject<Node> (); | 109 Ptr<Node> tmpNode = CreateObject<Node> (); |
117 nodeMap[from].nodePtr = tmpNode; | 110 nodeMap[from] = tmpNode; |
118 nodes.Add (tmpNode); | 111 nodes.Add (tmpNode); |
119 nodesNumber++; | 112 nodesNumber++; |
120 } | 113 } |
121 | 114 |
122 if (nodeMap[to].nodePtr == 0) | 115 if (nodeMap[to] == 0) |
123 { | 116 { |
124 Ptr<Node> tmpNode = CreateObject<Node> (); | 117 Ptr<Node> tmpNode = CreateObject<Node> (); |
125 nodeMap[to].nodePtr = tmpNode; | 118 nodeMap[to] = tmpNode; |
126 nodes.Add (tmpNode); | 119 nodes.Add (tmpNode); |
127 nodesNumber++; | 120 nodesNumber++; |
128 } | 121 } |
129 | 122 |
130 TopologyLink link; | 123 Link link ( nodeMap[from], from, nodeMap[to], to ); |
131 link.from = from; | |
132 link.fromPtr = nodeMap[from].nodePtr; | |
133 link.to = to; | |
134 link.toPtr = nodeMap[to].nodePtr; | |
135 | |
136 if ( !linkAttr.empty () ) | 124 if ( !linkAttr.empty () ) |
137 { | 125 { |
138 link.linkAttr["Weight"] = linkAttr; | 126 link.SetAttribute ("Weight", linkAttr); |
139 } | 127 } |
140 linksList.push_back (link); | 128 AddLink (link); |
141 | 129 |
142 linksNumber++; | 130 linksNumber++; |
143 } | 131 } |
144 } | 132 } |
145 | 133 |
146 NS_LOG_INFO ("Inet topology created with " << nodesNumber << " nodes and " <<
linksNumber << " links"); | 134 NS_LOG_INFO ("Inet topology created with " << nodesNumber << " nodes and " <<
linksNumber << " links"); |
147 topgen.close (); | 135 topgen.close (); |
148 | 136 |
149 return linksNumber; | 137 return nodes; |
150 } | |
151 | |
152 int32_t | |
153 InetTopologyReader::ReadSimple (NodeContainer &nodes, list<TopologyLink> &linksL
ist) | |
154 { | |
155 map<string, TopologyNode > nodeMap; | |
156 int32_t retVal; | |
157 | |
158 retVal = Read ( nodes, linksList, nodeMap ); | |
159 | |
160 return retVal; | |
161 } | 138 } |
162 | 139 |
163 } /* namespace ns3 */ | 140 } /* namespace ns3 */ |
LEFT | RIGHT |