Left: | ||
Right: |
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 * Copyright (c) 2008 University of Washington | 3 * Copyright (c) 2011 Atishay Jain |
Tom Henderson
2011/08/12 23:12:51
Consider whether to add your own copyright stateme
| |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 NS_LOG_FUNCTION_NOARGS (); | 83 NS_LOG_FUNCTION_NOARGS (); |
84 Reset (); | 84 Reset (); |
85 } | 85 } |
86 | 86 |
87 void | 87 void |
88 Ipv6AddressGeneratorImpl::Reset (void) | 88 Ipv6AddressGeneratorImpl::Reset (void) |
89 { | 89 { |
90 NS_LOG_FUNCTION_NOARGS (); | 90 NS_LOG_FUNCTION_NOARGS (); |
91 | 91 |
92 uint8_t prefix[16] = { 0}; | 92 uint8_t prefix[16] = { 0}; |
93 // | 93 |
94 for (uint32_t i = 0; i < N_BITS; ++i) | 94 for (uint32_t i = 0; i < N_BITS; ++i) |
95 { | 95 { |
96 for (uint32_t j = 0; j < 16; ++j) | 96 for (uint32_t j = 0; j < 16; ++j) |
97 { | 97 { |
98 m_netTable[i].prefix[j] = prefix[j]; | 98 m_netTable[i].prefix[j] = prefix[j]; |
99 } | 99 } |
100 for (uint32_t j = 0; j < 15; ++j) | 100 for (uint32_t j = 0; j < 15; ++j) |
101 { | 101 { |
102 prefix[15 - j] >>= 1; | 102 prefix[15 - j] >>= 1; |
103 prefix[15 - j] |= (prefix[15 - j - 1] & 1); | 103 prefix[15 - j] |= (prefix[15 - j - 1] & 1); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 } | 162 } |
163 for (uint32_t j = 0; j < a; j++) | 163 for (uint32_t j = 0; j < a; j++) |
164 { | 164 { |
165 m_netTable[index].network[j] = 0; | 165 m_netTable[index].network[j] = 0; |
166 } | 166 } |
167 for (uint32_t j = 15; j >= a; j--) | 167 for (uint32_t j = 15; j >= a; j--) |
168 { | 168 { |
169 m_netTable[index].network[j] = m_netTable[index].network[j] >> b; | 169 m_netTable[index].network[j] = m_netTable[index].network[j] >> b; |
170 m_netTable[index].network[j] |= m_netTable[index].network[j - 1] << (8 - b ); | 170 m_netTable[index].network[j] |= m_netTable[index].network[j - 1] << (8 - b ); |
171 } | 171 } |
172 //TODO NS_ABORT_MSG_UNLESS (addrBits <= m_netTable[index].addrMax, "Ipv6Addres sGeneratorImpl::Init(): Address overflow"); | |
Tom Henderson
2011/08/12 23:12:51
should this be uncommented? or removed?
| |
173 for (int32_t j = 0; j < 16; j++) | 172 for (int32_t j = 0; j < 16; j++) |
174 { | 173 { |
175 m_netTable[index].addr[j] = addrBits[j]; | 174 m_netTable[index].addr[j] = addrBits[j]; |
176 } | 175 } |
177 return; | 176 return; |
178 } | 177 } |
179 | 178 |
180 Ipv6Address | 179 Ipv6Address |
181 Ipv6AddressGeneratorImpl::GetNetwork ( | 180 Ipv6AddressGeneratorImpl::GetNetwork ( |
182 const Ipv6Prefix prefix) const | 181 const Ipv6Prefix prefix) const |
(...skipping 19 matching lines...) Expand all Loading... | |
202 nw[15] = nw[15] << b; | 201 nw[15] = nw[15] << b; |
203 | 202 |
204 return Ipv6Address (nw); | 203 return Ipv6Address (nw); |
205 } | 204 } |
206 | 205 |
207 Ipv6Address | 206 Ipv6Address |
208 Ipv6AddressGeneratorImpl::NextNetwork ( | 207 Ipv6AddressGeneratorImpl::NextNetwork ( |
209 const Ipv6Prefix prefix) | 208 const Ipv6Prefix prefix) |
210 { | 209 { |
211 NS_LOG_FUNCTION_NOARGS (); | 210 NS_LOG_FUNCTION_NOARGS (); |
212 // | 211 |
213 // The way this is expected to be used is that an address and network prefix | |
214 // are initialized, and then NextAddress() is called repeatedly to set the | |
215 // addresses on a given subnet. The client will expect that the first | |
216 // addresses will use the network prefix she used to initialize the generator | |
217 // with. After a subnet is assigned, the client will call NextNetwork to | |
218 // get the network number of the next subnet. This implies that that this | |
219 // operation is a pre-increment. | |
Tom Henderson
2011/08/12 23:12:51
This type of comment would be better moved to the
| |
220 // | |
221 uint32_t index = PrefixToIndex (prefix); | 212 uint32_t index = PrefixToIndex (prefix); |
222 for (uint8_t j = 15; j >= 0; j--) | 213 for (uint8_t j = 15; j >= 0; j--) |
223 { | 214 { |
224 if (m_netTable[index].network[j] < 0xff) | 215 if (m_netTable[index].network[j] < 0xff) |
225 { | 216 { |
226 ++m_netTable[index].network[j]; | 217 ++m_netTable[index].network[j]; |
227 break; | 218 break; |
228 } | 219 } |
229 else | 220 else |
230 { | 221 { |
(...skipping 27 matching lines...) Expand all Loading... | |
258 Ipv6AddressGeneratorImpl::InitAddress ( | 249 Ipv6AddressGeneratorImpl::InitAddress ( |
259 const Ipv6Address addr, | 250 const Ipv6Address addr, |
260 const Ipv6Prefix prefix) | 251 const Ipv6Prefix prefix) |
261 { | 252 { |
262 NS_LOG_FUNCTION_NOARGS (); | 253 NS_LOG_FUNCTION_NOARGS (); |
263 | 254 |
264 uint32_t index = PrefixToIndex (prefix); | 255 uint32_t index = PrefixToIndex (prefix); |
265 uint8_t addrBits[16]; | 256 uint8_t addrBits[16]; |
266 addr.GetBytes (addrBits); | 257 addr.GetBytes (addrBits); |
267 | 258 |
268 //TODO NS_ABORT_MSG_UNLESS (addrBits <= m_netTable[index].addrMax, "Ipv6Addres sGeneratorImpl::InitAddress(): Address overflow"); | |
Tom Henderson
2011/08/12 23:12:51
Should this be uncommented, or removed?
| |
269 for (uint32_t j = 0; j < 16; ++j) | 259 for (uint32_t j = 0; j < 16; ++j) |
270 { | 260 { |
271 m_netTable[index].addr[j] = addrBits[j]; | 261 m_netTable[index].addr[j] = addrBits[j]; |
272 } | 262 } |
273 } | 263 } |
274 | 264 |
275 Ipv6Address | 265 Ipv6Address |
276 Ipv6AddressGeneratorImpl::GetAddress ( | 266 Ipv6AddressGeneratorImpl::GetAddress ( |
277 const Ipv6Prefix prefix) const | 267 const Ipv6Prefix prefix) const |
278 { | 268 { |
(...skipping 23 matching lines...) Expand all Loading... | |
302 nw[j] |= m_netTable[index].addr[j]; | 292 nw[j] |= m_netTable[index].addr[j]; |
303 } | 293 } |
304 | 294 |
305 return Ipv6Address (nw); | 295 return Ipv6Address (nw); |
306 } | 296 } |
307 | 297 |
308 Ipv6Address | 298 Ipv6Address |
309 Ipv6AddressGeneratorImpl::NextAddress (const Ipv6Prefix prefix) | 299 Ipv6AddressGeneratorImpl::NextAddress (const Ipv6Prefix prefix) |
310 { | 300 { |
311 NS_LOG_FUNCTION_NOARGS (); | 301 NS_LOG_FUNCTION_NOARGS (); |
312 // | 302 |
313 // The way this is expected to be used is that an address and network prefix | |
314 // are initialized, and then NextAddress() is called repeatedly to set the | |
315 // addresses on a given subnet. The client will expect that the first address | |
316 // she gets back is the one she used to initialize the generator with. This | |
317 // implies that this operation is a post-increment. | |
318 // | |
Tom Henderson
2011/08/12 23:12:51
This type of comment would be better moved to the
| |
319 uint32_t index = PrefixToIndex (prefix); | 303 uint32_t index = PrefixToIndex (prefix); |
320 | 304 |
321 //TODO NS_ABORT_MSG_UNLESS (m_netTable[index].addr <= m_netTable[index].addrMa x, | |
322 // "Ipv6AddressGeneratorImpl::NextAddress(): Address overf low"); | |
Tom Henderson
2011/08/12 23:12:51
Uncomment this, or remove it?
| |
323 uint8_t ad[16]; | 305 uint8_t ad[16]; |
324 uint32_t a = m_netTable[index].shift / 8; | 306 uint32_t a = m_netTable[index].shift / 8; |
325 uint32_t b = m_netTable[index].shift % 8; | 307 uint32_t b = m_netTable[index].shift % 8; |
326 for (uint32_t j = 0; j < 16 - a; ++j) | 308 for (uint32_t j = 0; j < 16 - a; ++j) |
327 { | 309 { |
328 ad[j] = m_netTable[index].network[j + a]; | 310 ad[j] = m_netTable[index].network[j + a]; |
329 } | 311 } |
330 for (uint32_t j = 16 - a; j < 16; ++j) | 312 for (uint32_t j = 16 - a; j < 16; ++j) |
331 { | 313 { |
332 ad[j] = 0; | 314 ad[j] = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 } | 347 } |
366 | 348 |
367 bool | 349 bool |
368 Ipv6AddressGeneratorImpl::AddAllocated (const Ipv6Address address) | 350 Ipv6AddressGeneratorImpl::AddAllocated (const Ipv6Address address) |
369 { | 351 { |
370 NS_LOG_FUNCTION_NOARGS (); | 352 NS_LOG_FUNCTION_NOARGS (); |
371 | 353 |
372 uint8_t addr[16]; | 354 uint8_t addr[16]; |
373 address.GetBytes (addr); | 355 address.GetBytes (addr); |
374 | 356 |
375 //NS_ABORT_MSG_UNLESS (addr, "Ipv6AddressGeneratorImpl::Add(): Allocating the broadcast address is not a good idea"); | |
Tom Henderson
2011/08/12 23:12:51
Uncomment this, or remove it.
| |
376 | |
377 std::list<Entry>::iterator i; | 357 std::list<Entry>::iterator i; |
378 | 358 |
379 for (i = m_entries.begin (); i != m_entries.end (); ++i) | 359 for (i = m_entries.begin (); i != m_entries.end (); ++i) |
380 { | 360 { |
381 NS_LOG_LOGIC ("examine entry: " << Ipv6Address ((*i).addrLow) << | 361 NS_LOG_LOGIC ("examine entry: " << Ipv6Address ((*i).addrLow) << |
382 " to " << Ipv6Address ((*i).addrHigh)); | 362 " to " << Ipv6Address ((*i).addrHigh)); |
383 // | 363 // |
384 // First things first. Is there an address collision -- that is, does the | 364 // First things first. Is there an address collision -- that is, does the |
385 // new address fall in a previously allocated block of addresses. | 365 // new address fall in a previously allocated block of addresses. |
386 // | 366 // |
387 if (!((Ipv6Address)addr < (Ipv6Address)((*i).addrLow)) && (((Ipv6Address)a ddr < (Ipv6Address)(*i).addrHigh)|| ((Ipv6Address)addr == (Ipv6Address)((*i).add rHigh)))) | 367 if (!(Ipv6Address(addr) < Ipv6Address((*i).addrLow)) && ((Ipv6Address(addr ) < Ipv6Address((*i).addrHigh))|| (Ipv6Address(addr) == Ipv6Address((*i).addrHig h)))) |
388 { | 368 { |
389 NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::Add(): Address Collision: " < < Ipv6Address (addr)); | 369 NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::Add(): Address Collision: " < < Ipv6Address (addr)); |
390 if (!m_test) | 370 if (!m_test) |
391 { | 371 { |
392 //NS_FATAL_ERROR ("Ipv6AddressGeneratorImpl::Add(): Address Collis ion: " << Ipv6Address (addr)); | 372 NS_FATAL_ERROR ("Ipv6AddressGeneratorImpl::Add(): Address Collisio n: " << Ipv6Address (addr)); |
Tom Henderson
2011/08/12 23:12:51
Why is this commented out? In IPv4, this causes f
| |
393 } | 373 } |
394 return false; | 374 return false; |
395 } | 375 } |
396 // | 376 // |
397 // If the new address is less than the lowest address in the current block, | 377 // If the new address is less than the lowest address in the current block, |
398 // and can't be merged into to the current block, then insert it as a new | 378 // and can't be merged into to the current block, then insert it as a new |
399 // block before the current block. | 379 // block before the current block. |
400 // | 380 // |
401 uint8_t taddr[16]; | 381 uint8_t taddr[16]; |
402 for (uint32_t j = 0; j < 16; j++) | 382 for (uint32_t j = 0; j < 16; j++) |
403 { | 383 { |
404 taddr[j] = (*i).addrLow[j]; | 384 taddr[j] = (*i).addrLow[j]; |
405 } | 385 } |
406 taddr[15] -= 1; | 386 taddr[15] -= 1; |
407 if (((Ipv6Address)addr < (Ipv6Address)taddr)) | 387 if (Ipv6Address(addr) < Ipv6Address(taddr)) |
Tom Henderson
2011/08/12 23:12:51
Shouldn't these be creating IPv6 addresses, rather
| |
408 { | 388 { |
409 break; | 389 break; |
410 } | 390 } |
411 // | 391 // |
412 // If the new address fits at the end of the block, look ahead to the next | 392 // If the new address fits at the end of the block, look ahead to the next |
413 // block and make sure it's not a collision there. If we won't overlap, then | 393 // block and make sure it's not a collision there. If we won't overlap, then |
414 // just extend the current block by one address. We expect that completely | 394 // just extend the current block by one address. We expect that completely |
415 // filled network ranges will be a fairly rare occurrence, so we don't worry | 395 // filled network ranges will be a fairly rare occurrence, so we don't worry |
416 // about collapsing address range blocks. | 396 // about collapsing address range blocks. |
417 // | 397 // |
418 for (uint32_t j = 0; j < 16; j++) | 398 for (uint32_t j = 0; j < 16; j++) |
419 { | 399 { |
420 taddr[j] = (*i).addrLow[j]; | 400 taddr[j] = (*i).addrLow[j]; |
421 } | 401 } |
422 taddr[15] += 1; | 402 taddr[15] += 1; |
423 if (((Ipv6Address)addr == (Ipv6Address)taddr)) | 403 if (Ipv6Address(addr) == Ipv6Address(taddr)) |
424 { | 404 { |
425 std::list<Entry>::iterator j = i; | 405 std::list<Entry>::iterator j = i; |
426 ++j; | 406 ++j; |
427 | 407 |
428 if (j != m_entries.end ()) | 408 if (j != m_entries.end ()) |
429 { | 409 { |
430 if (((Ipv6Address)addr == (Ipv6Address)(*j).addrLow)) | 410 if (Ipv6Address(addr) == Ipv6Address((*j).addrLow)) |
431 { | 411 { |
432 NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::Add(): " | 412 NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::Add(): " |
433 "Address Collision: " << Ipv6Address (addr)); | 413 "Address Collision: " << Ipv6Address (addr)); |
434 if (!m_test) | 414 if (!m_test) |
435 { | 415 { |
436 NS_FATAL_ERROR ("Ipv6AddressGeneratorImpl::Add(): Address Collision: " << Ipv6Address (addr)); | 416 NS_FATAL_ERROR ("Ipv6AddressGeneratorImpl::Add(): Address Collision: " << Ipv6Address (addr)); |
437 } | 417 } |
438 return false; | 418 return false; |
439 } | 419 } |
440 } | 420 } |
(...skipping 10 matching lines...) Expand all Loading... | |
451 // have been extended to include this new address since the code immediately | 431 // have been extended to include this new address since the code immediately |
452 // above would have been executed and that next lower block extended upward. | 432 // above would have been executed and that next lower block extended upward. |
453 // So we know it's safe to extend the current block down to includ the new | 433 // So we know it's safe to extend the current block down to includ the new |
454 // address. | 434 // address. |
455 // | 435 // |
456 for (uint32_t j = 0; j < 16; j++) | 436 for (uint32_t j = 0; j < 16; j++) |
457 { | 437 { |
458 taddr[j] = (*i).addrLow[j]; | 438 taddr[j] = (*i).addrLow[j]; |
459 } | 439 } |
460 taddr[15] -= 1; | 440 taddr[15] -= 1; |
461 if (((Ipv6Address)addr == (Ipv6Address)taddr)) | 441 if ((Ipv6Address(addr) == Ipv6Address(taddr))) |
462 { | 442 { |
463 NS_LOG_LOGIC ("New addrLow = " << Ipv6Address (addr)); | 443 NS_LOG_LOGIC ("New addrLow = " << Ipv6Address (addr)); |
464 for (uint32_t j = 0; j < 16; j++) | 444 for (uint32_t j = 0; j < 16; j++) |
465 { | 445 { |
466 (*i).addrLow[j] = addr[j]; | 446 (*i).addrLow[j] = addr[j]; |
467 } | 447 } |
468 return true; | 448 return true; |
469 } | 449 } |
470 } | 450 } |
471 | 451 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
600 Ipv6AddressGenerator::TestMode (void) | 580 Ipv6AddressGenerator::TestMode (void) |
601 { | 581 { |
602 NS_LOG_FUNCTION_NOARGS (); | 582 NS_LOG_FUNCTION_NOARGS (); |
603 | 583 |
604 SimulationSingleton<Ipv6AddressGeneratorImpl>::Get () | 584 SimulationSingleton<Ipv6AddressGeneratorImpl>::Get () |
605 ->TestMode (); | 585 ->TestMode (); |
606 } | 586 } |
607 | 587 |
608 } // namespace ns3 | 588 } // namespace ns3 |
609 | 589 |
LEFT | RIGHT |