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 * 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 for (uint32_t j = 0; j < colContainer.GetN (); j+=2) | 124 for (uint32_t j = 0; j < colContainer.GetN (); j+=2) |
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 #define UINT64_TO_IPV6_PREFIX(_network, _ret_address) \ | 134 void |
134 { \ | 135 PointToPointGridHelper::AssignIpv6Addresses(Ipv6Address addrBase, Ipv6Prefix pre
fix) |
135 uint8_t buf[16]; \ | 136 { |
136 memset(buf, 0, 16); \ | 137 Ipv6AddressGenerator::Init(addrBase, prefix); |
137 for (unsigned int _j = 0; _j < 8; _j++) \ | 138 Ipv6Address v6network; |
138 { \ | |
139 uint64_t value = (_network) & ((uint64_t)0xff << (56 - _j * 8)); \ | |
140 buf[_j] = value >> (56 - _j * 8); \ | |
141 } \ | |
142 (_ret_address) = Ipv6Address(buf); \ | |
143 }· | |
144 | |
145 void | |
146 PointToPointGridHelper::AssignIpv6Addresses(uint64_t ipv6AddressBase) | |
147 { | |
148 Ipv6AddressHelper addrHelper; | 139 Ipv6AddressHelper addrHelper; |
149 Ipv6Address v6addr; | |
150 | 140 |
151 // Assign addresses to all row devices in the grid. | 141 // Assign addresses to all row devices in the grid. |
152 // These devices are stored in a vector. Each row· | 142 // These devices are stored in a vector. Each row· |
153 // of the grid has all the row devices in one entry· | 143 // of the grid has all the row devices in one entry· |
154 // of the vector. These entries come in pairs. | 144 // of the vector. These entries come in pairs. |
155 for (uint32_t i = 0; i < m_rowDevices.size (); ++i) | 145 for (uint32_t i = 0; i < m_rowDevices.size (); ++i) |
156 { | 146 { |
157 Ipv6InterfaceContainer rowInterfaces;· | 147 Ipv6InterfaceContainer rowInterfaces;· |
158 NetDeviceContainer rowContainer = m_rowDevices[i]; | 148 NetDeviceContainer rowContainer = m_rowDevices[i]; |
159 for (uint32_t j = 0; j < rowContainer.GetN (); j+=2) | 149 for (uint32_t j = 0; j < rowContainer.GetN (); j+=2) |
160 { | 150 { |
161 UINT64_TO_IPV6_PREFIX(ipv6AddressBase, v6addr); | 151 v6network = Ipv6AddressGenerator::GetNetwork (prefix); |
162 addrHelper.NewNetwork(v6addr, Ipv6Prefix(64)); | 152 addrHelper.NewNetwork(v6network, prefix); |
163 Ipv6InterfaceContainer ic = addrHelper.Assign (rowContainer.Get (j)); | 153 Ipv6InterfaceContainer ic = addrHelper.Assign (rowContainer.Get (j)); |
164 rowInterfaces.Add (ic); | 154 rowInterfaces.Add (ic); |
165 ic = addrHelper.Assign (rowContainer.Get (j+1)); | 155 ic = addrHelper.Assign (rowContainer.Get (j+1)); |
166 rowInterfaces.Add (ic); | 156 rowInterfaces.Add (ic); |
167 ipv6AddressBase++; | 157 Ipv6AddressGenerator::NextNetwork (prefix); |
168 } | 158 } |
169 m_rowInterfaces6.push_back (rowInterfaces); | 159 m_rowInterfaces6.push_back (rowInterfaces); |
170 } | 160 } |
171 | 161 |
172 // Assign addresses to all col devices in the grid. | 162 // Assign addresses to all col devices in the grid. |
173 // These devices are stored in a vector. Each col· | 163 // These devices are stored in a vector. Each col· |
174 // of the grid has all the col devices in one entry· | 164 // of the grid has all the col devices in one entry· |
175 // of the vector. These entries come in pairs. | 165 // of the vector. These entries come in pairs. |
176 for (uint32_t i = 0; i < m_colDevices.size (); ++i) | 166 for (uint32_t i = 0; i < m_colDevices.size (); ++i) |
177 { | 167 { |
178 Ipv6InterfaceContainer colInterfaces;· | 168 Ipv6InterfaceContainer colInterfaces;· |
179 NetDeviceContainer colContainer = m_colDevices[i]; | 169 NetDeviceContainer colContainer = m_colDevices[i]; |
180 for (uint32_t j = 0; j < colContainer.GetN (); j+=2) | 170 for (uint32_t j = 0; j < colContainer.GetN (); j+=2) |
181 { | 171 { |
182 UINT64_TO_IPV6_PREFIX(ipv6AddressBase, v6addr); | 172 v6network = Ipv6AddressGenerator::GetNetwork (prefix); |
183 addrHelper.NewNetwork(v6addr, Ipv6Prefix(64)); | 173 addrHelper.NewNetwork(v6network, prefix); |
184 Ipv6InterfaceContainer ic = addrHelper.Assign (colContainer.Get (j)); | 174 Ipv6InterfaceContainer ic = addrHelper.Assign (colContainer.Get (j)); |
185 colInterfaces.Add (ic); | 175 colInterfaces.Add (ic); |
186 ic = addrHelper.Assign (colContainer.Get (j+1)); | 176 ic = addrHelper.Assign (colContainer.Get (j+1)); |
187 colInterfaces.Add (ic); | 177 colInterfaces.Add (ic); |
188 ipv6AddressBase++; | 178 Ipv6AddressGenerator::NextNetwork (prefix); |
189 } | 179 } |
190 m_colInterfaces6.push_back (colInterfaces); | 180 m_colInterfaces6.push_back (colInterfaces); |
191 } | 181 } |
192 } | 182 } |
193 | 183 |
194 void | 184 void |
195 PointToPointGridHelper::BoundingBox (double ulx, double uly, | 185 PointToPointGridHelper::BoundingBox (double ulx, double uly, |
196 double lrx, double lry) | 186 double lrx, double lry) |
197 { | 187 { |
198 double xDist;· | 188 double xDist;· |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 { | 285 { |
296 return (m_rowInterfaces6.at (row)).GetAddress (0, 1); | 286 return (m_rowInterfaces6.at (row)).GetAddress (0, 1); |
297 } | 287 } |
298 else | 288 else |
299 { | 289 { |
300 return (m_rowInterfaces6.at (row)).GetAddress ((2*col)-1, 1); | 290 return (m_rowInterfaces6.at (row)).GetAddress ((2*col)-1, 1); |
301 } | 291 } |
302 } | 292 } |
303 | 293 |
304 } // namespace ns3 | 294 } // namespace ns3 |
LEFT | RIGHT |