|
|
| 127 |
bool AddAllocated (const Ipv4Address addr); |
127 |
bool AddAllocated (const Ipv4Address addr); |
| 128 |
|
128 |
|
| 129 |
/** |
129 |
/** |
|
|
130 |
* \brief Check the Ipv4Address allocation in the list of IPv4 entries |
| 131 |
* |
| 132 |
* \param addr The Ipv4Address to be checked in the list of Ipv4 entries |
| 133 |
* \returns true if the network is already allocated |
| 134 |
*/ |
| 135 |
bool CheckAllocated (const Ipv4Address addr); |
| 136 |
|
| 137 |
/** |
| 130 |
* \brief Used to turn off fatal errors and assertions, for testing |
138 |
* \brief Used to turn off fatal errors and assertions, for testing |
| 131 |
*/ |
139 |
*/ |
| 132 |
void TestMode (void); |
140 |
void TestMode (void); |
|
|
| 412 |
// If we get here, we know that the next lower block of addresses couldn't |
420 |
// If we get here, we know that the next lower block of addresses couldn't |
| 413 |
// have been extended to include this new address since the code immediately |
421 |
// have been extended to include this new address since the code immediately |
| 414 |
// above would have been executed and that next lower block extended upward. |
422 |
// above would have been executed and that next lower block extended upward. |
| 415 |
// So we know it's safe to extend the current block down to includ the new |
423 |
// So we know it's safe to extend the current block down to include the new |
| 416 |
// address. |
424 |
// address. |
| 417 |
// |
425 |
// |
| 418 |
if (addr == (*i).addrLow - 1) |
426 |
if (addr == (*i).addrLow - 1) |
|
|
| 429 |
return true; |
437 |
return true; |
| 430 |
} |
438 |
} |
| 431 |
|
439 |
|
|
|
440 |
bool |
| 441 |
Ipv4AddressGeneratorImpl::CheckAllocated (const Ipv4Address address) |
| 442 |
{ |
| 443 |
NS_LOG_FUNCTION (this << address); |
| 444 |
|
| 445 |
uint32_t addr = address.Get (); |
| 446 |
|
| 447 |
NS_ABORT_MSG_UNLESS (addr, "Ipv4AddressGeneratorImpl::CheckAllocated(): Don't check for the broadcast address..."); |
| 448 |
|
| 449 |
std::list<Entry>::iterator i; |
| 450 |
|
| 451 |
for (i = m_entries.begin (); i != m_entries.end (); ++i) |
| 452 |
{ |
| 453 |
NS_LOG_LOGIC ("examine entry: " << Ipv4Address ((*i).addrLow) << |
| 454 |
" to " << Ipv4Address ((*i).addrHigh)); |
| 455 |
// |
| 456 |
// First things first. Is there an address collision -- that is, does the |
| 457 |
// new address fall in a previously allocated block of addresses. |
| 458 |
// |
| 459 |
if (addr >= (*i).addrLow && addr <= (*i).addrHigh) |
| 460 |
{ |
| 461 |
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::CheckAllocated(): Address Collision: " << Ipv4Address (addr)); |
| 462 |
return false; |
| 463 |
} |
| 464 |
// |
| 465 |
// If the new address is less than the lowest address in the current block, |
| 466 |
// and can't be merged into to the current block, then insert it as a new |
| 467 |
// block before the current block. |
| 468 |
// |
| 469 |
if (addr < (*i).addrLow - 1) |
| 470 |
{ |
| 471 |
break; |
| 472 |
} |
| 473 |
// |
| 474 |
// If the new address fits at the end of the block, look ahead to the next |
| 475 |
// block and make sure it's not a collision there. If we won't overlap, then |
| 476 |
// just extend the current block by one address. We expect that completely |
| 477 |
// filled network ranges will be a fairly rare occurrence, so we don't worry |
| 478 |
// about collapsing address range blocks. |
| 479 |
// |
| 480 |
if (addr == (*i).addrHigh + 1) |
| 481 |
{ |
| 482 |
std::list<Entry>::iterator j = i; |
| 483 |
++j; |
| 484 |
|
| 485 |
if (j != m_entries.end ()) |
| 486 |
{ |
| 487 |
if (addr == (*j).addrLow) |
| 488 |
{ |
| 489 |
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::CheckAllocated(): " |
| 490 |
"Address Collision: " << Ipv4Address (addr)); |
| 491 |
return false; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
NS_LOG_LOGIC ("New addrHigh = " << Ipv4Address (addr)); |
| 496 |
(*i).addrHigh = addr; |
| 497 |
return true; |
| 498 |
} |
| 499 |
// |
| 500 |
// If we get here, we know that the next lower block of addresses couldn't |
| 501 |
// have been extended to include this new address since the code immediately |
| 502 |
// above would have been executed and that next lower block extended upward. |
| 503 |
// So we know it's safe to extend the current block down to include the new |
| 504 |
// address. |
| 505 |
// |
| 506 |
if (addr == (*i).addrLow - 1) |
| 507 |
{ |
| 508 |
NS_LOG_LOGIC ("New addrLow = " << Ipv4Address (addr)); |
| 509 |
(*i).addrLow = addr; |
| 510 |
return true; |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
return true; |
| 515 |
} |
| 516 |
|
| 517 |
|
| 432 |
void |
518 |
void |
| 433 |
Ipv4AddressGeneratorImpl::TestMode (void) |
519 |
Ipv4AddressGeneratorImpl::TestMode (void) |
| 434 |
{ |
520 |
{ |
|
|
| 546 |
->AddAllocated (addr); |
632 |
->AddAllocated (addr); |
| 547 |
} |
633 |
} |
| 548 |
|
634 |
|
|
|
635 |
bool |
| 636 |
Ipv4AddressGenerator::CheckAllocated (const Ipv4Address addr) |
| 637 |
{ |
| 638 |
NS_LOG_FUNCTION_NOARGS (); |
| 639 |
|
| 640 |
return SimulationSingleton<Ipv4AddressGeneratorImpl>::Get () |
| 641 |
->CheckAllocated (addr); |
| 642 |
} |
| 643 |
|
| 549 |
void |
644 |
void |
| 550 |
Ipv4AddressGenerator::TestMode (void) |
645 |
Ipv4AddressGenerator::TestMode (void) |
| 551 |
{ |
646 |
{ |