OLD | NEW |
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 * This program is free software; you can redistribute it and/or modify | 3 * This program is free software; you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License version 2 as | 4 * it under the terms of the GNU General Public License version 2 as |
5 * published by the Free Software Foundation; | 5 * published by the Free Software Foundation; |
6 * | 6 * |
7 * This program is distributed in the hope that it will be useful, | 7 * This program is distributed in the hope that it will be useful, |
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 * GNU General Public License for more details. | 10 * GNU General Public License for more details. |
11 * | 11 * |
12 * You should have received a copy of the GNU General Public License | 12 * You should have received a copy of the GNU General Public License |
13 * along with this program; if not, write to the Free Software | 13 * along with this program; if not, write to the Free Software |
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 * | 15 * |
16 * Author: Josh Pelkey <jpelkey@gatech.edu> | 16 * Author: Josh Pelkey <jpelkey@gatech.edu> |
17 */ | 17 */ |
18 | 18 |
19 #include "ns3/point-to-point-grid.h" | 19 #include "ns3/point-to-point-grid.h" |
20 #include "ns3/animation-interface.h" | 20 #include "ns3/animation-interface.h" |
21 #include "ns3/internet-stack-helper.h" | 21 #include "ns3/internet-stack-helper.h" |
22 #include "ns3/point-to-point-helper.h" | 22 #include "ns3/point-to-point-helper.h" |
23 #include "ns3/constant-position-mobility-model.h" | 23 #include "ns3/constant-position-mobility-model.h" |
24 #include "ns3/string.h" | 24 #include "ns3/string.h" |
25 #include "ns3/vector.h" | 25 #include "ns3/vector.h" |
26 #include "ns3/log.h" | 26 #include "ns3/log.h" |
| 27 #include "ns3/ipv6-address-generator.h" |
27 | 28 |
28 NS_LOG_COMPONENT_DEFINE ("PointToPointGridHelper"); | 29 NS_LOG_COMPONENT_DEFINE ("PointToPointGridHelper"); |
29 | 30 |
30 namespace ns3 { | 31 namespace ns3 { |
31 | 32 |
32 PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,· | 33 PointToPointGridHelper::PointToPointGridHelper (uint32_t nRows,· |
33 uint32_t nCols,· | 34 uint32_t nCols,· |
34 PointToPointHelper pointToPoint) | 35 PointToPointHelper pointToPoint) |
35 : m_xSize (nCols), m_ySize (nRows) | 36 : m_xSize (nCols), m_ySize (nRows) |
36 { | 37 { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 { | 125 { |
125 colInterfaces.Add (colIp.Assign (colContainer.Get (j)));· | 126 colInterfaces.Add (colIp.Assign (colContainer.Get (j)));· |
126 colInterfaces.Add (colIp.Assign (colContainer.Get (j+1))); | 127 colInterfaces.Add (colIp.Assign (colContainer.Get (j+1))); |
127 colIp.NewNetwork (); | 128 colIp.NewNetwork (); |
128 } | 129 } |
129 m_colInterfaces.push_back (colInterfaces); | 130 m_colInterfaces.push_back (colInterfaces); |
130 } | 131 } |
131 } | 132 } |
132 | 133 |
133 void | 134 void |
| 135 PointToPointGridHelper::AssignIpv6Addresses(Ipv6Address addrBase, Ipv6Prefix pre
fix) |
| 136 { |
| 137 Ipv6AddressGenerator::Init(addrBase, prefix); |
| 138 Ipv6Address v6network; |
| 139 Ipv6AddressHelper addrHelper; |
| 140 |
| 141 // Assign addresses to all row devices in the grid. |
| 142 // These devices are stored in a vector. Each row· |
| 143 // of the grid has all the row devices in one entry· |
| 144 // of the vector. These entries come in pairs. |
| 145 for (uint32_t i = 0; i < m_rowDevices.size (); ++i) |
| 146 { |
| 147 Ipv6InterfaceContainer rowInterfaces;· |
| 148 NetDeviceContainer rowContainer = m_rowDevices[i]; |
| 149 for (uint32_t j = 0; j < rowContainer.GetN (); j+=2) |
| 150 { |
| 151 v6network = Ipv6AddressGenerator::GetNetwork (prefix); |
| 152 addrHelper.NewNetwork(v6network, prefix); |
| 153 Ipv6InterfaceContainer ic = addrHelper.Assign (rowContainer.Get (j)); |
| 154 rowInterfaces.Add (ic); |
| 155 ic = addrHelper.Assign (rowContainer.Get (j+1)); |
| 156 rowInterfaces.Add (ic); |
| 157 Ipv6AddressGenerator::NextNetwork (prefix); |
| 158 } |
| 159 m_rowInterfaces6.push_back (rowInterfaces); |
| 160 } |
| 161 |
| 162 // Assign addresses to all col devices in the grid. |
| 163 // These devices are stored in a vector. Each col· |
| 164 // of the grid has all the col devices in one entry· |
| 165 // of the vector. These entries come in pairs. |
| 166 for (uint32_t i = 0; i < m_colDevices.size (); ++i) |
| 167 { |
| 168 Ipv6InterfaceContainer colInterfaces;· |
| 169 NetDeviceContainer colContainer = m_colDevices[i]; |
| 170 for (uint32_t j = 0; j < colContainer.GetN (); j+=2) |
| 171 { |
| 172 v6network = Ipv6AddressGenerator::GetNetwork (prefix); |
| 173 addrHelper.NewNetwork(v6network, prefix); |
| 174 Ipv6InterfaceContainer ic = addrHelper.Assign (colContainer.Get (j)); |
| 175 colInterfaces.Add (ic); |
| 176 ic = addrHelper.Assign (colContainer.Get (j+1)); |
| 177 colInterfaces.Add (ic); |
| 178 Ipv6AddressGenerator::NextNetwork (prefix); |
| 179 } |
| 180 m_colInterfaces6.push_back (colInterfaces); |
| 181 } |
| 182 } |
| 183 |
| 184 void |
134 PointToPointGridHelper::BoundingBox (double ulx, double uly, | 185 PointToPointGridHelper::BoundingBox (double ulx, double uly, |
135 double lrx, double lry) | 186 double lrx, double lry) |
136 { | 187 { |
137 double xDist;· | 188 double xDist;· |
138 double yDist;· | 189 double yDist;· |
139 if (lrx > ulx) | 190 if (lrx > ulx) |
140 { | 191 { |
141 xDist = lrx - ulx; | 192 xDist = lrx - ulx; |
142 } | 193 } |
143 else | 194 else |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 if (col == 0) | 258 if (col == 0) |
208 { | 259 { |
209 return (m_rowInterfaces.at (row)).GetAddress (0); | 260 return (m_rowInterfaces.at (row)).GetAddress (0); |
210 } | 261 } |
211 else | 262 else |
212 { | 263 { |
213 return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1); | 264 return (m_rowInterfaces.at (row)).GetAddress ((2*col)-1); |
214 } | 265 } |
215 } | 266 } |
216 | 267 |
| 268 Ipv6Address |
| 269 PointToPointGridHelper::GetIpv6Address (uint32_t row, uint32_t col) |
| 270 { |
| 271 if (row > m_nodes.size () - 1 || |
| 272 col > m_nodes.at (row).GetN () - 1) |
| 273 { |
| 274 NS_FATAL_ERROR ("Index out of bounds in PointToPointGridHelper::GetIpv4Add
ress."); |
| 275 } |
| 276 |
| 277 // Right now this just gets one of the addresses of the |
| 278 // specified node. The exact device can't be specified. |
| 279 // If you picture the grid, the address returned is the |
| 280 // address of the left (row) device of all nodes, with |
| 281 // the exception of the left-most nodes in the grid; |
| 282 // in which case the right (row) device address is |
| 283 // returned |
| 284 if (col == 0) |
| 285 { |
| 286 return (m_rowInterfaces6.at (row)).GetAddress (0, 1); |
| 287 } |
| 288 else |
| 289 { |
| 290 return (m_rowInterfaces6.at (row)).GetAddress ((2*col)-1, 1); |
| 291 } |
| 292 } |
| 293 |
217 } // namespace ns3 | 294 } // namespace ns3 |
OLD | NEW |