|
|
| 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 address is already allocated |
| 134 |
*/ |
| 135 |
bool CheckAllocated (const Ipv4Address addr); |
| 136 |
|
| 137 |
/** |
| 138 |
* \brief Check if a network has already allocated addresses |
| 139 |
* |
| 140 |
* \param addr The Ipv4 network to be checked |
| 141 |
* \param mask The Ipv4 network mask |
| 142 |
* \returns true if the network is already allocated |
| 143 |
*/ |
| 144 |
bool IsNetworkAllocated (const Ipv4Address addr, const Ipv4Mask mask); |
| 145 |
|
| 146 |
/** |
| 130 |
* \brief Used to turn off fatal errors and assertions, for testing |
147 |
* \brief Used to turn off fatal errors and assertions, for testing |
| 131 |
*/ |
148 |
*/ |
| 132 |
void TestMode (void); |
149 |
void TestMode (void); |
|
|
| 412 |
// If we get here, we know that the next lower block of addresses couldn't |
429 |
// 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 |
430 |
// 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. |
431 |
// 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 |
432 |
// So we know it's safe to extend the current block down to include the new |
| 416 |
// address. |
433 |
// address. |
| 417 |
// |
434 |
// |
| 418 |
if (addr == (*i).addrLow - 1) |
435 |
if (addr == (*i).addrLow - 1) |
|
|
| 429 |
return true; |
446 |
return true; |
| 430 |
} |
447 |
} |
| 431 |
|
448 |
|
|
|
449 |
bool |
| 450 |
Ipv4AddressGeneratorImpl::CheckAllocated (const Ipv4Address address) |
| 451 |
{ |
| 452 |
NS_LOG_FUNCTION (this << address); |
| 453 |
|
| 454 |
uint32_t addr = address.Get (); |
| 455 |
|
| 456 |
NS_ABORT_MSG_UNLESS (addr, "Ipv4AddressGeneratorImpl::CheckAllocated(): Don't check for the broadcast address..."); |
| 457 |
|
| 458 |
std::list<Entry>::iterator i; |
| 459 |
|
| 460 |
for (i = m_entries.begin (); i != m_entries.end (); ++i) |
| 461 |
{ |
| 462 |
NS_LOG_LOGIC ("examine entry: " << Ipv4Address ((*i).addrLow) << |
| 463 |
" to " << Ipv4Address ((*i).addrHigh)); |
| 464 |
if (addr >= (*i).addrLow && addr <= (*i).addrHigh) |
| 465 |
{ |
| 466 |
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::CheckAllocated(): Address Collision: " << Ipv4Address (addr)); |
| 467 |
return false; |
| 468 |
} |
| 469 |
} |
| 470 |
return true; |
| 471 |
} |
| 472 |
|
| 473 |
bool |
| 474 |
Ipv4AddressGeneratorImpl::IsNetworkAllocated (const Ipv4Address address, const Ipv4Mask mask) |
| 475 |
{ |
| 476 |
NS_LOG_FUNCTION (this << address << mask); |
| 477 |
|
| 478 |
NS_ABORT_MSG_UNLESS (address == address.CombineMask (mask), |
| 479 |
"Ipv4AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match " << address << " " << mask); |
| 480 |
|
| 481 |
std::list<Entry>::iterator i; |
| 482 |
|
| 483 |
for (i = m_entries.begin (); i != m_entries.end (); ++i) |
| 484 |
{ |
| 485 |
NS_LOG_LOGIC ("examine entry: " << Ipv4Address ((*i).addrLow) << " to " << Ipv4Address ((*i).addrHigh)); |
| 486 |
Ipv4Address low = Ipv4Address ((*i).addrLow); |
| 487 |
Ipv4Address high = Ipv4Address ((*i).addrHigh); |
| 488 |
|
| 489 |
if (address == low.CombineMask (mask) || address == high.CombineMask (mask)) |
| 490 |
{ |
| 491 |
NS_LOG_LOGIC ("Ipv4AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: " << |
| 492 |
address << " " << low << "-" << high); |
| 493 |
return false; |
| 494 |
} |
| 495 |
|
| 496 |
} |
| 497 |
return true; |
| 498 |
} |
| 499 |
|
| 500 |
|
| 432 |
void |
501 |
void |
| 433 |
Ipv4AddressGeneratorImpl::TestMode (void) |
502 |
Ipv4AddressGeneratorImpl::TestMode (void) |
| 434 |
{ |
503 |
{ |
|
|
| 546 |
->AddAllocated (addr); |
615 |
->AddAllocated (addr); |
| 547 |
} |
616 |
} |
| 548 |
|
617 |
|
|
|
618 |
bool |
| 619 |
Ipv4AddressGenerator::CheckAllocated (const Ipv4Address addr) |
| 620 |
{ |
| 621 |
NS_LOG_FUNCTION_NOARGS (); |
| 622 |
|
| 623 |
return SimulationSingleton<Ipv4AddressGeneratorImpl>::Get () |
| 624 |
->CheckAllocated (addr); |
| 625 |
} |
| 626 |
|
| 627 |
bool |
| 628 |
Ipv4AddressGenerator::IsNetworkAllocated (const Ipv4Address addr, const Ipv4Mask mask) |
| 629 |
{ |
| 630 |
NS_LOG_FUNCTION_NOARGS (); |
| 631 |
|
| 632 |
return SimulationSingleton<Ipv4AddressGeneratorImpl>::Get () |
| 633 |
->IsNetworkAllocated (addr, mask); |
| 634 |
} |
| 635 |
|
| 549 |
void |
636 |
void |
| 550 |
Ipv4AddressGenerator::TestMode (void) |
637 |
Ipv4AddressGenerator::TestMode (void) |
| 551 |
{ |
638 |
{ |