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 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 23 | #include "ns3/nstime.h" |
| 24 | #include "ns3/log.h" |
| 25 | #include "ns3/assert.h" |
| 26 | #include "ns3/names.h" |
| 27 | #include "ns3/net-device-container.h" |
| 28 | #include "ns3/point-to-point-helper.h" |
| 29 | #include "ns3/point-to-point-net-device.h" |
| 30 | #include "ns3/internet-stack-helper.h" |
| 31 | #include "ns3/ipv4-address-helper.h" |
| 32 | #include "ns3/ipv4-global-routing-helper.h" |
| 33 | #include "ns3/drop-tail-queue.h" |
| 34 | #include "ns3/ipv4-interface.h" |
| 35 | #include "ns3/ipv4.h" |
| 36 | #include "ns3/string.h" |
| 37 | #include "ns3/pointer.h" |
| 38 | #include "ns3/uinteger.h" |
| 39 | #include "ns3/ipv4-address.h" |
| 40 | |
| 41 | #include "ns3/constant-position-mobility-model.h" |
| 42 | #include "ns3/random-variable.h" |
| 43 | |
| 44 | #include <boost/foreach.hpp> |
| 45 | #include <boost/lexical_cast.hpp> |
| 46 | |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 47 | using namespace std; |
| 48 | |
| 49 | namespace ns3 |
| 50 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 51 | |
| 52 | NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyReader"); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 53 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 54 | NS_OBJECT_ENSURE_REGISTERED (AnnotatedTopologyReader); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 55 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 56 | TypeId AnnotatedTopologyReader::GetTypeId (void) |
| 57 | { |
| 58 | static TypeId tid = TypeId ("ns3::AnnotatedTopologyReader") |
| 59 | .SetParent<Object> () |
| 60 | ; |
| 61 | return tid; |
| 62 | } |
| 63 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 64 | AnnotatedTopologyReader::AnnotatedTopologyReader (const std::string &path) |
| 65 | : m_path (path) |
| 66 | , m_ulx (0) |
| 67 | , m_uly (0) |
| 68 | , m_lrx (100.0) |
| 69 | , m_lry (100.0) |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 70 | { |
| 71 | NS_LOG_FUNCTION (this); |
| 72 | } |
| 73 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 74 | void |
| 75 | AnnotatedTopologyReader::SetBoundingBox (double ulx, double uly, double lrx, double lry) |
| 76 | { |
| 77 | NS_LOG_FUNCTION (this << ulx << uly << lrx << lry); |
| 78 | |
| 79 | m_ulx = ulx; |
| 80 | m_uly = uly; |
| 81 | m_lrx = lrx; |
| 82 | m_lry = lry; |
| 83 | } |
| 84 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 85 | AnnotatedTopologyReader::~AnnotatedTopologyReader () |
| 86 | { |
| 87 | NS_LOG_FUNCTION (this); |
| 88 | } |
| 89 | |
| 90 | NodeContainer |
| 91 | AnnotatedTopologyReader::Read (void) |
| 92 | { |
| 93 | ifstream topgen; |
| 94 | topgen.open (GetFileName ().c_str ()); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 95 | NodeContainer nodes; |
| 96 | |
| 97 | if ( !topgen.is_open () ) |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 98 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 99 | NS_LOG_ERROR ("Cannot open file " << GetFileName () << " for reading"); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 100 | return nodes; |
| 101 | } |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 102 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 103 | int linksNumber = 0; |
| 104 | int nodesNumber = 0; |
| 105 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 106 | string line; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 107 | getline (topgen,line); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 108 | istringstream headerLineBuffer (line); |
| 109 | |
| 110 | int totnode; |
| 111 | int totlink; |
| 112 | headerLineBuffer >> totnode; |
| 113 | headerLineBuffer >> totlink; |
| 114 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 115 | NS_LOG_INFO ("Annotated topology should have " << totnode << " nodes and " << totlink << " links"); |
| 116 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 117 | for (int i = 0; i < totlink && !topgen.eof (); i++) |
| 118 | { |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 119 | getline (topgen,line); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 120 | istringstream lineBuffer (line); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 122 | string from; |
| 123 | string to; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 124 | lineBuffer >> from; |
| 125 | lineBuffer >> to; |
| 126 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 127 | if ( (!from.empty ()) && (!to.empty ()) ) |
| 128 | { |
| 129 | NS_LOG_INFO ( linksNumber << " From: " << from << " to: " << to ); |
| 130 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 131 | Ptr<Node> fromNode = Names::Find<Node> (m_path, from); |
| 132 | Ptr<Node> toNode = Names::Find<Node> (m_path, to); |
| 133 | |
| 134 | if (fromNode == 0) |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 135 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 136 | fromNode = CreateObject<Node> (); |
| 137 | Names::Add (m_path, from, fromNode); |
| 138 | nodes.Add (fromNode); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 139 | nodesNumber++; |
| 140 | } |
| 141 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 142 | if (toNode == 0) |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 143 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 144 | toNode = CreateObject<Node> (); |
| 145 | Names::Add (m_path, to, toNode); |
| 146 | nodes.Add (toNode); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 147 | nodesNumber++; |
| 148 | } |
| 149 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 150 | Link link (fromNode, from, toNode, to); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 152 | string dataRate; |
| 153 | lineBuffer >> dataRate; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 154 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 155 | string ospf; |
| 156 | lineBuffer >> ospf; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 157 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 158 | string delay; |
| 159 | lineBuffer >> delay; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 160 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 161 | string queueSizeNode1; |
| 162 | lineBuffer >> queueSizeNode1; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 164 | string queueSizeNode2; |
| 165 | lineBuffer >> queueSizeNode2; |
| 166 | |
| 167 | if (dataRate.empty () || |
| 168 | ospf.empty () || |
| 169 | delay.empty () || |
| 170 | queueSizeNode1.empty () || |
| 171 | queueSizeNode2.empty ()) |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 172 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 173 | NS_LOG_ERROR ("File [" << GetFileName () << ":" << i+2 << " wrong format, skipping"); |
| 174 | continue; |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 175 | } |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame^] | 176 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 177 | link.SetAttribute ("DataRate", dataRate); |
| 178 | link.SetAttribute ("OSPF", ospf); |
| 179 | link.SetAttribute ("Delay", delay); |
| 180 | link.SetAttribute ("QueueSizeNode1", queueSizeNode1); |
| 181 | link.SetAttribute ("QueueSizeNode2", queueSizeNode2); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 182 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 183 | AddLink (link); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 184 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 185 | linksNumber++; |
| 186 | } |
| 187 | } |
| 188 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 189 | NS_ASSERT (nodesNumber == totnode && linksNumber == totlink); |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 190 | |
| 191 | NS_LOG_INFO ("Annotated topology created with " << nodesNumber << " nodes and " << linksNumber << " links"); |
| 192 | topgen.close (); |
| 193 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 194 | ApplySettings (); |
| 195 | AssignCoordinates (); |
| 196 | |
Ilya Moiseenko | 7dd43be | 2011-08-18 18:57:12 -0700 | [diff] [blame] | 197 | return nodes; |
| 198 | } |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 199 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 200 | void |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 201 | AnnotatedTopologyReader::AssignIpv4Addresses (Ipv4Address base) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 202 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 203 | Ipv4AddressHelper address (base, Ipv4Mask ("/24")); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 204 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 205 | BOOST_FOREACH (const Link &link, m_linksList) |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 206 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 207 | address.Assign (NetDeviceContainer (link.GetFromNetDevice (), |
| 208 | link.GetToNetDevice ())); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 209 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 210 | base = Ipv4Address (base.Get () + 256); |
| 211 | address.SetBase (base, Ipv4Mask ("/24")); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 214 | ApplyOspfMetric (); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 217 | void |
| 218 | AnnotatedTopologyReader::ApplyOspfMetric () |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 219 | { |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame^] | 220 | BOOST_FOREACH (const Link &link, m_linksList) |
| 221 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 222 | uint16_t metric = boost::lexical_cast<uint16_t> (link.GetAttribute ("OSPF")); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 223 | |
| 224 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 225 | Ptr<Ipv4> ipv4 = link.GetFromNode ()->GetObject<Ipv4> (); |
| 226 | NS_ASSERT (ipv4 != 0); |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame^] | 227 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 228 | int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetFromNetDevice ()); |
| 229 | NS_ASSERT (interfaceId >= 0); |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame^] | 230 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 231 | ipv4->SetMetric (interfaceId,metric); |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Ilya Moiseenko | 1eff17d | 2011-08-17 10:55:53 -0700 | [diff] [blame] | 234 | { |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 235 | Ptr<Ipv4> ipv4 = link.GetToNode ()->GetObject<Ipv4> (); |
| 236 | NS_ASSERT (ipv4 != 0); |
| 237 | |
| 238 | int32_t interfaceId = ipv4->GetInterfaceForDevice (link.GetToNetDevice ()); |
| 239 | NS_ASSERT (interfaceId >= 0); |
| 240 | |
| 241 | ipv4->SetMetric (interfaceId,metric); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 242 | } |
| 243 | } |
Alexander Afanasyev | 0777f1c | 2011-12-12 20:22:45 -0800 | [diff] [blame^] | 244 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 245 | |
| 246 | void |
| 247 | AnnotatedTopologyReader::ApplySettings () |
| 248 | { |
| 249 | PointToPointHelper p2p; |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 250 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 251 | // temporary queue, will be changed later |
| 252 | p2p.SetQueue ("ns3::DropTailQueue", |
| 253 | "MaxPackets", StringValue("100")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 254 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 255 | BOOST_FOREACH (Link &link, m_linksList) |
| 256 | { |
| 257 | NS_LOG_INFO ("DataRate = " + link.GetAttribute("DataRate")+"Kbps"); |
| 258 | p2p.SetDeviceAttribute ("DataRate", StringValue(link.GetAttribute("DataRate")+"Kbps")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 259 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 260 | NS_LOG_INFO ("Delay = " + link.GetAttribute("Delay")+"ms"); |
| 261 | p2p.SetChannelAttribute ("Delay", StringValue(link.GetAttribute("Delay")+"ms")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 262 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 263 | NetDeviceContainer nd = p2p.Install(link.GetFromNode (), link.GetToNode ()); |
| 264 | link.SetNetDevices (nd.Get (0), nd.Get (1)); |
| 265 | |
| 266 | NS_LOG_INFO ("Queue: " << link.GetAttribute("QueueSizeNode1") << " <==> " << link.GetAttribute("QueueSizeNode2")); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 267 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 268 | PointerValue txQueueFrom; |
| 269 | link.GetFromNetDevice ()->GetAttribute ("TxQueue", txQueueFrom); |
| 270 | NS_ASSERT (txQueueFrom.Get<DropTailQueue> () != 0); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 271 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 272 | PointerValue txQueueTo; |
| 273 | link.GetToNetDevice ()->GetAttribute ("TxQueue", txQueueTo); |
| 274 | NS_ASSERT (txQueueTo.Get<DropTailQueue> () != 0); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 275 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 276 | txQueueFrom.Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute("QueueSizeNode1"))); |
| 277 | txQueueTo. Get<DropTailQueue> ()->SetAttribute ("MaxPackets", StringValue (link.GetAttribute("QueueSizeNode2"))); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 278 | } |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 279 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 280 | |
| 281 | void |
| 282 | AnnotatedTopologyReader::AssignCoordinates () |
| 283 | { |
| 284 | UniformVariable randX (m_ulx, m_lrx); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 285 | double x = 0.0; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 286 | UniformVariable randY (m_uly, m_lry); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 287 | double y = 0.0; |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 288 | |
| 289 | BOOST_FOREACH (Link &link, m_linksList) |
| 290 | { |
| 291 | Ptr<ConstantPositionMobilityModel> loc = link.GetFromNode ()->GetObject<ConstantPositionMobilityModel> (); |
| 292 | if (loc != 0) |
| 293 | continue; // no need to assign twice |
Ilya Moiseenko | 7e14efa | 2011-12-12 17:56:22 -0800 | [diff] [blame] | 294 | |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 295 | loc = CreateObject<ConstantPositionMobilityModel> (); |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 296 | link.GetFromNode ()->AggregateObject (loc); |
| 297 | |
| 298 | x = randX.GetValue(); |
| 299 | y = randY.GetValue(); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 300 | NS_LOG_INFO("X = "<<x <<"Y = "<<y); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 301 | |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 302 | loc->SetPosition (Vector (x, y, 0)); |
Ilya Moiseenko | 58d2667 | 2011-12-08 13:48:06 -0800 | [diff] [blame] | 303 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 304 | } |
Alexander Afanasyev | 8633d5d | 2011-12-12 18:02:31 -0800 | [diff] [blame] | 305 | |
| 306 | } |