Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 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 |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "annotated-topology-reader.h" |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 22 | |
| 23 | using namespace std; |
| 24 | |
| 25 | namespace ns3 |
| 26 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 27 | |
| 28 | NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReader"); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 29 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 30 | NS_OBJECT_ENSURE_REGISTERED (AnnotatedTopologyReader); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 31 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 32 | TypeId AnnotatedTopologyReader::GetTypeId (void) |
| 33 | { |
| 34 | static TypeId tid = TypeId ("ns3::AnnotatedTopologyReader") |
| 35 | .SetParent<Object> () |
| 36 | ; |
| 37 | return tid; |
| 38 | } |
| 39 | |
| 40 | AnnotatedTopologyReader::AnnotatedTopologyReader () |
| 41 | { |
| 42 | NS_LOG_FUNCTION (this); |
| 43 | } |
| 44 | |
| 45 | AnnotatedTopologyReader::~AnnotatedTopologyReader () |
| 46 | { |
| 47 | NS_LOG_FUNCTION (this); |
| 48 | } |
| 49 | |
| 50 | NodeContainer |
| 51 | AnnotatedTopologyReader::Read (void) |
| 52 | { |
| 53 | ifstream topgen; |
| 54 | topgen.open (GetFileName ().c_str ()); |
| 55 | map<string, Ptr<Node> > nodeMap; |
| 56 | NodeContainer nodes; |
| 57 | |
| 58 | if ( !topgen.is_open () ) |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 59 | { |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 60 | return nodes; |
| 61 | } |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 62 | |
| 63 | string from; |
| 64 | string to; |
| 65 | string linkAttr; |
| 66 | |
| 67 | int linksNumber = 0; |
| 68 | int nodesNumber = 0; |
| 69 | |
| 70 | int totnode = 0; |
| 71 | int totlink = 0; |
| 72 | |
| 73 | istringstream lineBuffer; |
| 74 | string line; |
| 75 | |
| 76 | getline (topgen,line); |
| 77 | lineBuffer.str (line); |
| 78 | |
| 79 | lineBuffer >> totnode; |
| 80 | lineBuffer >> totlink; |
| 81 | NS_LOG_INFO ("Annotated topology should have " << totnode << " nodes and " << totlink << " links"); |
| 82 | |
| 83 | if(!topgen.eof ()) |
| 84 | NS_LOG_INFO("!EOF"); |
| 85 | |
| 86 | |
| 87 | for (int i = 0; i < totlink && !topgen.eof (); i++) |
| 88 | { |
| 89 | //NS_LOG_INFO("Line #" <<i); |
| 90 | getline (topgen,line); |
| 91 | lineBuffer.clear (); |
| 92 | lineBuffer.str (line); |
| 93 | |
| 94 | lineBuffer >> from; |
| 95 | lineBuffer >> to; |
| 96 | |
| 97 | |
| 98 | if ( (!from.empty ()) && (!to.empty ()) ) |
| 99 | { |
| 100 | NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); |
| 101 | |
| 102 | if ( nodeMap[from] == 0 ) |
| 103 | { |
| 104 | Ptr<Node> tmpNode = CreateObject<Node> (); |
| 105 | nodeMap[from] = tmpNode; |
| 106 | nodes.Add (tmpNode); |
| 107 | nodesNumber++; |
| 108 | } |
| 109 | |
| 110 | if (nodeMap[to] == 0) |
| 111 | { |
| 112 | Ptr<Node> tmpNode = CreateObject<Node> (); |
| 113 | nodeMap[to] = tmpNode; |
| 114 | nodes.Add (tmpNode); |
| 115 | nodesNumber++; |
| 116 | } |
| 117 | |
| 118 | Link link ( nodeMap[from], from, nodeMap[to], to ); |
| 119 | |
| 120 | lineBuffer >> linkAttr; |
| 121 | if ( !linkAttr.empty () ) |
| 122 | { |
| 123 | link.SetAttribute ("DataRate", linkAttr); |
| 124 | } |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 125 | |
| 126 | lineBuffer >> linkAttr; |
| 127 | if ( !linkAttr.empty () ) |
| 128 | { |
| 129 | link.SetAttribute ("OSPF", linkAttr); |
| 130 | } |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 131 | |
| 132 | lineBuffer >> linkAttr; |
| 133 | if ( !linkAttr.empty () ) |
| 134 | { |
| 135 | link.SetAttribute ("Delay", linkAttr); |
| 136 | } |
| 137 | |
| 138 | lineBuffer >> linkAttr; |
| 139 | if ( !linkAttr.empty () ) |
| 140 | { |
| 141 | link.SetAttribute ("QueueSizeNode1", linkAttr); |
| 142 | } |
| 143 | |
| 144 | lineBuffer >> linkAttr; |
| 145 | if ( !linkAttr.empty () ) |
| 146 | { |
| 147 | link.SetAttribute ("QueueSizeNode2", linkAttr); |
| 148 | } |
Ilya Moiseenko | 7e14efa | 2011-12-12 17:56:22 -0800 | [diff] [blame] | 149 | |
| 150 | lineBuffer >> linkAttr; |
| 151 | if ( !linkAttr.empty () ) |
| 152 | { |
| 153 | link.SetAttribute ("X1", linkAttr); |
| 154 | } |
| 155 | |
| 156 | lineBuffer >> linkAttr; |
| 157 | if ( !linkAttr.empty () ) |
| 158 | { |
| 159 | link.SetAttribute ("Y1", linkAttr); |
| 160 | } |
| 161 | |
| 162 | lineBuffer >> linkAttr; |
| 163 | if ( !linkAttr.empty () ) |
| 164 | { |
| 165 | link.SetAttribute ("X2", linkAttr); |
| 166 | } |
| 167 | |
| 168 | lineBuffer >> linkAttr; |
| 169 | if ( !linkAttr.empty () ) |
| 170 | { |
| 171 | link.SetAttribute ("Y2", linkAttr); |
| 172 | } |
| 173 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 174 | AddLink (link); |
| 175 | |
| 176 | linksNumber++; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links"); |
| 181 | topgen.close (); |
| 182 | |
| 183 | return nodes; |
| 184 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 185 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 186 | void |
| 187 | AnnotatedTopologyReader::ApplySettings(NetDeviceContainer* ndc, NodeContainer* nc) |
| 188 | { |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 189 | InternetStackHelper stack; |
| 190 | Ipv4AddressHelper address; |
| 191 | address.SetBase ("10.1.0.0", "255.255.255.0"); |
| 192 | |
| 193 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 194 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 195 | |
| 196 | |
| 197 | |
| 198 | //This loop passes all links and checks if ipv4 is installed on the node |
| 199 | // if not, it installs. |
| 200 | // We can't use stack.Install(nc) because in nc there are duplicates and assertion fails |
| 201 | TopologyReader::ConstLinksIterator iter; |
| 202 | int j = 0; |
| 203 | for ( iter = this->LinksBegin (); iter != this->LinksEnd (); iter++, j++ ) |
| 204 | { |
| 205 | NodeContainer twoNodes = nc[j]; |
| 206 | |
| 207 | Ptr<Node> nd = twoNodes.Get(0); |
| 208 | if(nd==NULL) |
| 209 | NS_LOG_INFO("nd = null"); |
| 210 | |
| 211 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 212 | if(nd2==NULL) |
| 213 | NS_LOG_INFO("nd2 = null"); |
| 214 | |
| 215 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 216 | if(ipv4 == 0) |
| 217 | { |
| 218 | NS_LOG_INFO("ipv4 = null"); |
| 219 | stack.Install(nd); |
| 220 | } |
| 221 | |
| 222 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 223 | if(ipv42 == 0) |
| 224 | { |
| 225 | NS_LOG_INFO("ipv42 = null"); |
| 226 | stack.Install(nd2); |
| 227 | } |
| 228 | |
| 229 | //NS_LOG_INFO("#netdevices = " << nd->GetNDevices()); |
| 230 | //NS_LOG_INFO("#netdevices = " << nd2->GetNDevices()); |
| 231 | } |
| 232 | |
| 233 | NS_LOG_INFO("ITER2"); |
| 234 | uint32_t base = 0; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 235 | PointToPointHelper p2p; |
| 236 | TopologyReader::ConstLinksIterator iter2; |
| 237 | int i = 0; |
| 238 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 239 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 240 | p2p.SetDeviceAttribute("DataRate", StringValue(iter2->GetAttribute("DataRate")+"Kbps")); |
| 241 | NS_LOG_INFO("DataRate = " + iter2->GetAttribute("DataRate")+"Kbps"); |
| 242 | p2p.SetChannelAttribute("Delay", StringValue(iter2->GetAttribute("Delay")+"ms")); |
| 243 | NS_LOG_INFO("Delay = " + iter2->GetAttribute("Delay")+"ms"); |
| 244 | p2p.SetQueue("ns3::DropTailQueue","MaxPackets",StringValue("100")); |
| 245 | ndc[i] = p2p.Install(nc[i]); |
| 246 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 247 | Ipv4Address address1(base+i*256 + 1); |
| 248 | Ipv4Address address2(base+i*256 + 2); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 249 | |
| 250 | NodeContainer twoNodes = nc[i]; |
| 251 | |
| 252 | Ptr<Node> nd = twoNodes.Get(0); |
| 253 | if(nd==NULL) |
| 254 | NS_LOG_INFO("nd = null"); |
| 255 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 256 | |
| 257 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 258 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 259 | if(nd2==NULL) |
| 260 | NS_LOG_INFO("nd2 = null"); |
| 261 | |
| 262 | //NS_LOG_INFO("1"); |
| 263 | NS_LOG_INFO("#netdevices = " << nd->GetNDevices()); |
| 264 | NS_LOG_INFO("#netdevices = " << nd2->GetNDevices()); |
| 265 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 266 | Ptr<NetDevice> device = nd->GetDevice(nd->GetNDevices()-1)->GetObject<PointToPointNetDevice> (); |
| 267 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 268 | if(device==NULL) |
| 269 | NS_LOG_INFO("device = 0"); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 270 | |
| 271 | std::string ospf = iter2->GetAttribute("OSPF"); |
| 272 | uint16_t metric = atoi(ospf.c_str()); |
| 273 | NS_LOG_INFO("OSPF metric = " << metric); |
| 274 | |
| 275 | { |
| 276 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 277 | temp->Add(device); |
| 278 | address.Assign (*temp); |
| 279 | } |
| 280 | |
| 281 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 282 | if(ipv4 == 0) |
| 283 | { |
| 284 | NS_LOG_INFO("ipv4 = null"); |
| 285 | //stack.Install(nd); |
| 286 | /*NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 287 | temp->Add(device); |
| 288 | address.Assign (*temp); |
| 289 | ipv4 = nd->GetObject<Ipv4>();*/ |
| 290 | } |
| 291 | |
| 292 | NS_LOG_INFO("Before GetID"); |
| 293 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 294 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 295 | ipv4->SetMetric(interfaceId,metric); |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | /*Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 302 | |
| 303 | if(ipv4 == 0) |
| 304 | NS_LOG_INFO("ipv4 = null"); |
| 305 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 306 | ipv4->SetMetric(interfaceId,metric);*/ |
| 307 | |
| 308 | //Ptr<Ipv4Interface> interface = nd->GetDevice(nd->GetNDevices()-1)->GetObject<Ipv4Interface> (); |
| 309 | //ipv4->SetMetric(metric); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 310 | |
| 311 | //NS_LOG_INFO("2"); |
| 312 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 313 | Ptr<NetDevice> device2 = nd2->GetDevice(nd2->GetNDevices()-1)->GetObject<PointToPointNetDevice> (); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 314 | |
| 315 | if(device2==NULL) |
| 316 | NS_LOG_INFO("device2 = 0"); |
| 317 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 318 | { |
| 319 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 320 | temp->Add(device2); |
| 321 | address.Assign (*temp); |
| 322 | } |
| 323 | |
| 324 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 325 | if(ipv42 == 0) |
| 326 | { |
| 327 | NS_LOG_INFO("ipv42 = null"); |
| 328 | /*stack.Install(nd2); |
| 329 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 330 | temp->Add(device2); |
| 331 | address.Assign (*temp); |
| 332 | ipv42 = nd2->GetObject<Ipv4>();*/ |
| 333 | } |
| 334 | |
| 335 | NS_LOG_INFO("Before GetID"); |
| 336 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 337 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 338 | ipv42->SetMetric(interfaceId,metric); |
| 339 | |
| 340 | |
| 341 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 342 | PointerValue tmp1; |
| 343 | device->GetAttribute ("TxQueue", tmp1); |
| 344 | //NS_LOG_INFO("2.5"); |
| 345 | Ptr<Object> txQueue1 = tmp1.GetObject (); |
| 346 | |
| 347 | PointerValue tmp2; |
| 348 | device2->GetAttribute ("TxQueue", tmp2); |
| 349 | Ptr<Object> txQueue2 = tmp2.GetObject (); |
| 350 | //NS_LOG_INFO("3"); |
| 351 | Ptr<DropTailQueue> dtq1 = txQueue1->GetObject <DropTailQueue> (); |
| 352 | NS_ASSERT (dtq1 != 0); |
| 353 | |
| 354 | Ptr<DropTailQueue> dtq2 = txQueue2->GetObject <DropTailQueue> (); |
| 355 | NS_ASSERT (dtq2 != 0); |
| 356 | |
| 357 | std::string queuesize1 = iter2->GetAttribute("QueueSizeNode1"); |
| 358 | std::string queuesize2 = iter2->GetAttribute("QueueSizeNode2"); |
| 359 | //NS_LOG_INFO("4"); |
| 360 | txQueue1->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize1.c_str()))); |
| 361 | txQueue2->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize2.c_str()))); |
| 362 | |
| 363 | UintegerValue limit; |
| 364 | txQueue1->GetAttribute ("MaxPackets", limit); |
| 365 | NS_LOG_INFO ("NetDevice #"<< device->GetIfIndex() << "has queue limit " << limit.Get () << " packets"); |
| 366 | |
| 367 | txQueue2->GetAttribute ("MaxPackets", limit); |
| 368 | NS_LOG_INFO ("NetDevice #"<< device2->GetIfIndex() << "has queue limit " << limit.Get () << " packets"); |
| 369 | } |
| 370 | } |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | void |
| 374 | AnnotatedTopologyReader::ApplyOspfMetric(NetDeviceContainer* ndc, NodeContainer* nc) |
| 375 | { |
| 376 | InternetStackHelper stack; |
| 377 | Ipv4AddressHelper address; |
| 378 | address.SetBase ("10.0.0.0", "255.255.255.252"); |
| 379 | |
| 380 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 381 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 382 | |
| 383 | |
| 384 | TopologyReader::ConstLinksIterator iter2; |
| 385 | int i = 0; |
| 386 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 387 | { |
| 388 | NodeContainer twoNodes = nc[i]; |
| 389 | Ptr<NetDevice> device = ndc[i].Get(0); |
| 390 | Ptr<NetDevice> device2 = ndc[i].Get(1); |
| 391 | |
| 392 | //Ptr<Node> nd = twoNodes.Get(0); |
| 393 | Ptr<Node> nd = device->GetNode(); |
| 394 | if(nd==NULL) |
| 395 | NS_LOG_INFO("nd = null"); |
| 396 | |
| 397 | //Ptr<Node> nd2 = twoNodes.Get(1); |
| 398 | Ptr<Node> nd2 = device->GetNode(); |
| 399 | if(nd2==NULL) |
| 400 | NS_LOG_INFO("nd2 = null"); |
| 401 | |
| 402 | |
| 403 | |
| 404 | std::string ospf = iter2->GetAttribute("OSPF"); |
| 405 | uint16_t metric = atoi(ospf.c_str()); |
| 406 | NS_LOG_INFO("OSPF metric = " << metric); |
| 407 | |
| 408 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 409 | |
| 410 | if(ipv4 == 0) |
| 411 | { |
| 412 | NS_LOG_INFO("ipv4 = null"); |
| 413 | stack.Install(nd); |
| 414 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 415 | temp->Add(device); |
| 416 | address.Assign (*temp); |
| 417 | ipv4 = nd->GetObject<Ipv4>(); |
| 418 | } |
| 419 | |
| 420 | NS_LOG_INFO("Before GetID"); |
| 421 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 422 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 423 | ipv4->SetMetric(interfaceId,metric); |
| 424 | |
| 425 | |
| 426 | |
| 427 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 428 | if(ipv42 == 0) |
| 429 | { |
| 430 | NS_LOG_INFO("ipv42 = null"); |
| 431 | stack.Install(nd2); |
| 432 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 433 | temp->Add(device2); |
| 434 | address.Assign (*temp); |
| 435 | ipv42 = nd2->GetObject<Ipv4>(); |
| 436 | } |
| 437 | |
| 438 | //if(ipv4 == 0) |
| 439 | // NS_LOG_INFO("ipv4 = null"); |
| 440 | |
| 441 | NS_LOG_INFO("Before GetID"); |
| 442 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 443 | if(interfaceId == -1) |
| 444 | { |
| 445 | NS_LOG_INFO("interfaceID = -1"); |
| 446 | stack.Install(nd2); |
| 447 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 448 | temp->Add(device2); |
| 449 | address.Assign (*temp); |
| 450 | ipv42 = nd2->GetObject<Ipv4>(); |
| 451 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 452 | } |
| 453 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 454 | ipv42->SetMetric(interfaceId,metric); |
| 455 | |
| 456 | } |
| 457 | }*/ |
| 458 | |
| 459 | void |
| 460 | AnnotatedTopologyReader::BoundingBox (NodeContainer* nc, double ulx, double uly, double lrx, double lry) |
| 461 | { |
| 462 | |
| 463 | UniformVariable randX(ulx, lrx); |
| 464 | double x = 0.0; |
| 465 | UniformVariable randY(uly, lry); |
| 466 | double y = 0.0; |
| 467 | |
| 468 | |
| 469 | PointToPointHelper p2p; |
| 470 | TopologyReader::ConstLinksIterator iter2; |
| 471 | int i = 0; |
| 472 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 473 | { |
Ilya Moiseenko | 7e14efa | 2011-12-12 17:56:22 -0800 | [diff] [blame] | 474 | std::string x1str = iter2->GetAttribute("X1"); |
| 475 | uint16_t x1 = atoi(x1str.c_str()); |
| 476 | |
| 477 | std::string x2str = iter2->GetAttribute("X2"); |
| 478 | uint16_t x2 = atoi(x2str.c_str()); |
| 479 | |
| 480 | |
| 481 | std::string y1str = iter2->GetAttribute("Y1"); |
| 482 | uint16_t y1 = atoi(y1str.c_str()); |
| 483 | |
| 484 | std::string y2str = iter2->GetAttribute("Y2"); |
| 485 | uint16_t y2 = atoi(y2str.c_str()); |
| 486 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 487 | NodeContainer twoNodes = nc[i]; |
| 488 | |
| 489 | Ptr<Node> nd = twoNodes.Get(0); |
| 490 | if(nd==NULL) |
| 491 | NS_LOG_INFO("nd = null"); |
| 492 | |
| 493 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 494 | if(nd2==NULL) |
| 495 | NS_LOG_INFO("nd2 = null"); |
| 496 | |
| 497 | Ptr<ConstantPositionMobilityModel> loc = nd->GetObject<ConstantPositionMobilityModel> (); |
| 498 | if (loc ==0) |
| 499 | { |
| 500 | loc = CreateObject<ConstantPositionMobilityModel> (); |
| 501 | nd->AggregateObject (loc); |
| 502 | } |
| 503 | |
Ilya Moiseenko | 91b496a | 2011-12-12 19:26:41 -0800 | [diff] [blame^] | 504 | x = -x1; //randX.GetValue(); |
| 505 | y = -y1; //randY.GetValue(); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 506 | NS_LOG_INFO("X = "<<x <<"Y = "<<y); |
| 507 | Vector locVec (x, y, 0); |
| 508 | loc->SetPosition (locVec); |
| 509 | |
| 510 | |
| 511 | Ptr<ConstantPositionMobilityModel> loc2 = nd2->GetObject<ConstantPositionMobilityModel> (); |
| 512 | if (loc2 ==0) |
| 513 | { |
| 514 | loc2 = CreateObject<ConstantPositionMobilityModel> (); |
| 515 | nd2->AggregateObject (loc2); |
| 516 | } |
| 517 | |
Ilya Moiseenko | 91b496a | 2011-12-12 19:26:41 -0800 | [diff] [blame^] | 518 | x = -x2; //randX.GetValue(); |
| 519 | y = -y2; //randY.GetValue(); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 520 | NS_LOG_INFO("X = "<<x <<"Y = "<<y); |
| 521 | Vector locVec2 (x, y, 0); |
| 522 | loc2->SetPosition (locVec2); |
| 523 | } |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 524 | } |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 525 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 526 | |