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 | } |
| 149 | |
| 150 | AddLink (link); |
| 151 | |
| 152 | linksNumber++; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links"); |
| 157 | topgen.close (); |
| 158 | |
| 159 | return nodes; |
| 160 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 161 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 162 | void |
| 163 | AnnotatedTopologyReader::ApplySettings(NetDeviceContainer* ndc, NodeContainer* nc) |
| 164 | { |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 165 | InternetStackHelper stack; |
| 166 | Ipv4AddressHelper address; |
| 167 | address.SetBase ("10.1.0.0", "255.255.255.0"); |
| 168 | |
| 169 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 170 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 171 | |
| 172 | |
| 173 | |
| 174 | //This loop passes all links and checks if ipv4 is installed on the node |
| 175 | // if not, it installs. |
| 176 | // We can't use stack.Install(nc) because in nc there are duplicates and assertion fails |
| 177 | TopologyReader::ConstLinksIterator iter; |
| 178 | int j = 0; |
| 179 | for ( iter = this->LinksBegin (); iter != this->LinksEnd (); iter++, j++ ) |
| 180 | { |
| 181 | NodeContainer twoNodes = nc[j]; |
| 182 | |
| 183 | Ptr<Node> nd = twoNodes.Get(0); |
| 184 | if(nd==NULL) |
| 185 | NS_LOG_INFO("nd = null"); |
| 186 | |
| 187 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 188 | if(nd2==NULL) |
| 189 | NS_LOG_INFO("nd2 = null"); |
| 190 | |
| 191 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 192 | if(ipv4 == 0) |
| 193 | { |
| 194 | NS_LOG_INFO("ipv4 = null"); |
| 195 | stack.Install(nd); |
| 196 | } |
| 197 | |
| 198 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 199 | if(ipv42 == 0) |
| 200 | { |
| 201 | NS_LOG_INFO("ipv42 = null"); |
| 202 | stack.Install(nd2); |
| 203 | } |
| 204 | |
| 205 | //NS_LOG_INFO("#netdevices = " << nd->GetNDevices()); |
| 206 | //NS_LOG_INFO("#netdevices = " << nd2->GetNDevices()); |
| 207 | } |
| 208 | |
| 209 | NS_LOG_INFO("ITER2"); |
| 210 | uint32_t base = 0; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 211 | PointToPointHelper p2p; |
| 212 | TopologyReader::ConstLinksIterator iter2; |
| 213 | int i = 0; |
| 214 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 215 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 216 | p2p.SetDeviceAttribute("DataRate", StringValue(iter2->GetAttribute("DataRate")+"Kbps")); |
| 217 | NS_LOG_INFO("DataRate = " + iter2->GetAttribute("DataRate")+"Kbps"); |
| 218 | p2p.SetChannelAttribute("Delay", StringValue(iter2->GetAttribute("Delay")+"ms")); |
| 219 | NS_LOG_INFO("Delay = " + iter2->GetAttribute("Delay")+"ms"); |
| 220 | p2p.SetQueue("ns3::DropTailQueue","MaxPackets",StringValue("100")); |
| 221 | ndc[i] = p2p.Install(nc[i]); |
| 222 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 223 | Ipv4Address address1(base+i*256 + 1); |
| 224 | Ipv4Address address2(base+i*256 + 2); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 225 | |
| 226 | NodeContainer twoNodes = nc[i]; |
| 227 | |
| 228 | Ptr<Node> nd = twoNodes.Get(0); |
| 229 | if(nd==NULL) |
| 230 | NS_LOG_INFO("nd = null"); |
| 231 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 232 | |
| 233 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 234 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 235 | if(nd2==NULL) |
| 236 | NS_LOG_INFO("nd2 = null"); |
| 237 | |
| 238 | //NS_LOG_INFO("1"); |
| 239 | NS_LOG_INFO("#netdevices = " << nd->GetNDevices()); |
| 240 | NS_LOG_INFO("#netdevices = " << nd2->GetNDevices()); |
| 241 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 242 | Ptr<NetDevice> device = nd->GetDevice(nd->GetNDevices()-1)->GetObject<PointToPointNetDevice> (); |
| 243 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 244 | if(device==NULL) |
| 245 | NS_LOG_INFO("device = 0"); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 246 | |
| 247 | std::string ospf = iter2->GetAttribute("OSPF"); |
| 248 | uint16_t metric = atoi(ospf.c_str()); |
| 249 | NS_LOG_INFO("OSPF metric = " << metric); |
| 250 | |
| 251 | { |
| 252 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 253 | temp->Add(device); |
| 254 | address.Assign (*temp); |
| 255 | } |
| 256 | |
| 257 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 258 | if(ipv4 == 0) |
| 259 | { |
| 260 | NS_LOG_INFO("ipv4 = null"); |
| 261 | //stack.Install(nd); |
| 262 | /*NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 263 | temp->Add(device); |
| 264 | address.Assign (*temp); |
| 265 | ipv4 = nd->GetObject<Ipv4>();*/ |
| 266 | } |
| 267 | |
| 268 | NS_LOG_INFO("Before GetID"); |
| 269 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 270 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 271 | ipv4->SetMetric(interfaceId,metric); |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | /*Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 278 | |
| 279 | if(ipv4 == 0) |
| 280 | NS_LOG_INFO("ipv4 = null"); |
| 281 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 282 | ipv4->SetMetric(interfaceId,metric);*/ |
| 283 | |
| 284 | //Ptr<Ipv4Interface> interface = nd->GetDevice(nd->GetNDevices()-1)->GetObject<Ipv4Interface> (); |
| 285 | //ipv4->SetMetric(metric); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 286 | |
| 287 | //NS_LOG_INFO("2"); |
| 288 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 289 | Ptr<NetDevice> device2 = nd2->GetDevice(nd2->GetNDevices()-1)->GetObject<PointToPointNetDevice> (); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 290 | |
| 291 | if(device2==NULL) |
| 292 | NS_LOG_INFO("device2 = 0"); |
| 293 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 294 | { |
| 295 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 296 | temp->Add(device2); |
| 297 | address.Assign (*temp); |
| 298 | } |
| 299 | |
| 300 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 301 | if(ipv42 == 0) |
| 302 | { |
| 303 | NS_LOG_INFO("ipv42 = null"); |
| 304 | /*stack.Install(nd2); |
| 305 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 306 | temp->Add(device2); |
| 307 | address.Assign (*temp); |
| 308 | ipv42 = nd2->GetObject<Ipv4>();*/ |
| 309 | } |
| 310 | |
| 311 | NS_LOG_INFO("Before GetID"); |
| 312 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 313 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 314 | ipv42->SetMetric(interfaceId,metric); |
| 315 | |
| 316 | |
| 317 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 318 | PointerValue tmp1; |
| 319 | device->GetAttribute ("TxQueue", tmp1); |
| 320 | //NS_LOG_INFO("2.5"); |
| 321 | Ptr<Object> txQueue1 = tmp1.GetObject (); |
| 322 | |
| 323 | PointerValue tmp2; |
| 324 | device2->GetAttribute ("TxQueue", tmp2); |
| 325 | Ptr<Object> txQueue2 = tmp2.GetObject (); |
| 326 | //NS_LOG_INFO("3"); |
| 327 | Ptr<DropTailQueue> dtq1 = txQueue1->GetObject <DropTailQueue> (); |
| 328 | NS_ASSERT (dtq1 != 0); |
| 329 | |
| 330 | Ptr<DropTailQueue> dtq2 = txQueue2->GetObject <DropTailQueue> (); |
| 331 | NS_ASSERT (dtq2 != 0); |
| 332 | |
| 333 | std::string queuesize1 = iter2->GetAttribute("QueueSizeNode1"); |
| 334 | std::string queuesize2 = iter2->GetAttribute("QueueSizeNode2"); |
| 335 | //NS_LOG_INFO("4"); |
| 336 | txQueue1->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize1.c_str()))); |
| 337 | txQueue2->SetAttribute("MaxPackets", UintegerValue (atoi(queuesize2.c_str()))); |
| 338 | |
| 339 | UintegerValue limit; |
| 340 | txQueue1->GetAttribute ("MaxPackets", limit); |
| 341 | NS_LOG_INFO ("NetDevice #"<< device->GetIfIndex() << "has queue limit " << limit.Get () << " packets"); |
| 342 | |
| 343 | txQueue2->GetAttribute ("MaxPackets", limit); |
| 344 | NS_LOG_INFO ("NetDevice #"<< device2->GetIfIndex() << "has queue limit " << limit.Get () << " packets"); |
| 345 | } |
| 346 | } |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 347 | |
| 348 | /* |
| 349 | void |
| 350 | AnnotatedTopologyReader::ApplyOspfMetric(NetDeviceContainer* ndc, NodeContainer* nc) |
| 351 | { |
| 352 | InternetStackHelper stack; |
| 353 | Ipv4AddressHelper address; |
| 354 | address.SetBase ("10.0.0.0", "255.255.255.252"); |
| 355 | |
| 356 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 357 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 358 | |
| 359 | |
| 360 | TopologyReader::ConstLinksIterator iter2; |
| 361 | int i = 0; |
| 362 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 363 | { |
| 364 | NodeContainer twoNodes = nc[i]; |
| 365 | Ptr<NetDevice> device = ndc[i].Get(0); |
| 366 | Ptr<NetDevice> device2 = ndc[i].Get(1); |
| 367 | |
| 368 | //Ptr<Node> nd = twoNodes.Get(0); |
| 369 | Ptr<Node> nd = device->GetNode(); |
| 370 | if(nd==NULL) |
| 371 | NS_LOG_INFO("nd = null"); |
| 372 | |
| 373 | //Ptr<Node> nd2 = twoNodes.Get(1); |
| 374 | Ptr<Node> nd2 = device->GetNode(); |
| 375 | if(nd2==NULL) |
| 376 | NS_LOG_INFO("nd2 = null"); |
| 377 | |
| 378 | |
| 379 | |
| 380 | std::string ospf = iter2->GetAttribute("OSPF"); |
| 381 | uint16_t metric = atoi(ospf.c_str()); |
| 382 | NS_LOG_INFO("OSPF metric = " << metric); |
| 383 | |
| 384 | Ptr<Ipv4> ipv4 = nd->GetObject<Ipv4>(); |
| 385 | |
| 386 | if(ipv4 == 0) |
| 387 | { |
| 388 | NS_LOG_INFO("ipv4 = null"); |
| 389 | stack.Install(nd); |
| 390 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 391 | temp->Add(device); |
| 392 | address.Assign (*temp); |
| 393 | ipv4 = nd->GetObject<Ipv4>(); |
| 394 | } |
| 395 | |
| 396 | NS_LOG_INFO("Before GetID"); |
| 397 | int32_t interfaceId = ipv4->GetInterfaceForDevice(device); |
| 398 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 399 | ipv4->SetMetric(interfaceId,metric); |
| 400 | |
| 401 | |
| 402 | |
| 403 | Ptr<Ipv4> ipv42 = nd2->GetObject<Ipv4>(); |
| 404 | if(ipv42 == 0) |
| 405 | { |
| 406 | NS_LOG_INFO("ipv42 = null"); |
| 407 | stack.Install(nd2); |
| 408 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 409 | temp->Add(device2); |
| 410 | address.Assign (*temp); |
| 411 | ipv42 = nd2->GetObject<Ipv4>(); |
| 412 | } |
| 413 | |
| 414 | //if(ipv4 == 0) |
| 415 | // NS_LOG_INFO("ipv4 = null"); |
| 416 | |
| 417 | NS_LOG_INFO("Before GetID"); |
| 418 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 419 | if(interfaceId == -1) |
| 420 | { |
| 421 | NS_LOG_INFO("interfaceID = -1"); |
| 422 | stack.Install(nd2); |
| 423 | NetDeviceContainer* temp = new NetDeviceContainer[1]; |
| 424 | temp->Add(device2); |
| 425 | address.Assign (*temp); |
| 426 | ipv42 = nd2->GetObject<Ipv4>(); |
| 427 | interfaceId = ipv42->GetInterfaceForDevice(device2); |
| 428 | } |
| 429 | NS_LOG_INFO("InterfaceID = " << interfaceId); |
| 430 | ipv42->SetMetric(interfaceId,metric); |
| 431 | |
| 432 | } |
| 433 | }*/ |
| 434 | |
| 435 | void |
| 436 | AnnotatedTopologyReader::BoundingBox (NodeContainer* nc, double ulx, double uly, double lrx, double lry) |
| 437 | { |
| 438 | |
| 439 | UniformVariable randX(ulx, lrx); |
| 440 | double x = 0.0; |
| 441 | UniformVariable randY(uly, lry); |
| 442 | double y = 0.0; |
| 443 | |
| 444 | |
| 445 | PointToPointHelper p2p; |
| 446 | TopologyReader::ConstLinksIterator iter2; |
| 447 | int i = 0; |
| 448 | for ( iter2 = this->LinksBegin (); iter2 != this->LinksEnd (); iter2++, i++ ) |
| 449 | { |
| 450 | NodeContainer twoNodes = nc[i]; |
| 451 | |
| 452 | Ptr<Node> nd = twoNodes.Get(0); |
| 453 | if(nd==NULL) |
| 454 | NS_LOG_INFO("nd = null"); |
| 455 | |
| 456 | Ptr<Node> nd2 = twoNodes.Get(1); |
| 457 | if(nd2==NULL) |
| 458 | NS_LOG_INFO("nd2 = null"); |
| 459 | |
| 460 | Ptr<ConstantPositionMobilityModel> loc = nd->GetObject<ConstantPositionMobilityModel> (); |
| 461 | if (loc ==0) |
| 462 | { |
| 463 | loc = CreateObject<ConstantPositionMobilityModel> (); |
| 464 | nd->AggregateObject (loc); |
| 465 | } |
| 466 | |
| 467 | x = randX.GetValue(); |
| 468 | y = randY.GetValue(); |
| 469 | NS_LOG_INFO("X = "<<x <<"Y = "<<y); |
| 470 | Vector locVec (x, y, 0); |
| 471 | loc->SetPosition (locVec); |
| 472 | |
| 473 | |
| 474 | Ptr<ConstantPositionMobilityModel> loc2 = nd2->GetObject<ConstantPositionMobilityModel> (); |
| 475 | if (loc2 ==0) |
| 476 | { |
| 477 | loc2 = CreateObject<ConstantPositionMobilityModel> (); |
| 478 | nd2->AggregateObject (loc2); |
| 479 | } |
| 480 | |
| 481 | x = randX.GetValue(); |
| 482 | y = randY.GetValue(); |
| 483 | NS_LOG_INFO("X = "<<x <<"Y = "<<y); |
| 484 | Vector locVec2 (x, y, 0); |
| 485 | loc2->SetPosition (locVec2); |
| 486 | } |
| 487 | /* |
| 488 | double xDist; |
| 489 | double yDist; |
| 490 | if (lrx > ulx) |
| 491 | { |
| 492 | xDist = lrx - ulx; |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | xDist = ulx - lrx; |
| 497 | } |
| 498 | if (lry > uly) |
| 499 | { |
| 500 | yDist = lry - uly; |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | yDist = uly - lry; |
| 505 | } |
| 506 | double xAdder = xDist / m_xSize; |
| 507 | double yAdder = yDist / m_ySize; |
| 508 | double yLoc = yDist / 2; |
| 509 | for (uint32_t i = 0; i < m_ySize; ++i) |
| 510 | { |
| 511 | double xLoc = xDist / 2; |
| 512 | for (uint32_t j = 0; j < m_xSize; ++j) |
| 513 | { |
| 514 | Ptr<Node> node = GetNode (i, j); |
| 515 | Ptr<ConstantPositionMobilityModel> loc = node->GetObject<ConstantPositionMobilityModel> (); |
| 516 | if (loc ==0) |
| 517 | { |
| 518 | loc = CreateObject<ConstantPositionMobilityModel> (); |
| 519 | node->AggregateObject (loc); |
| 520 | } |
| 521 | Vector locVec (xLoc, yLoc, 0); |
| 522 | loc->SetPosition (locVec); |
| 523 | |
| 524 | xLoc += xAdder; |
| 525 | } |
| 526 | yLoc += yAdder; |
| 527 | } |
| 528 | } |
| 529 | */ |
| 530 | } |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 531 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 532 | |