View | Details | Raw Unified | Return to bug 2834
Collapse All | Expand All

(-)a/src/internet/model/ipv4-address-generator.cc (-1 / +96 lines)
 Lines 127-132    Link Here 
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);
 Lines 412-418    Link Here 
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)
 Lines 429-434    Link Here 
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
{
 Lines 546-551    Link Here 
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
{
(-)a/src/internet/model/ipv4-address-generator.h (+8 lines)
 Lines 124-129    Link Here 
124
  static bool AddAllocated (const Ipv4Address addr);
124
  static bool AddAllocated (const Ipv4Address addr);
125
125
126
  /**
126
  /**
127
   * \brief Check the Ipv4Address allocation in the list of IPv4 entries
128
   *
129
   * \param addr The Ipv4Address to be checked in the list of Ipv4 entries
130
   * \returns true if the network is already allocated
131
   */
132
  static bool CheckAllocated (const Ipv4Address addr);
133
134
  /**
127
   * \brief Used to turn off fatal errors and assertions, for testing
135
   * \brief Used to turn off fatal errors and assertions, for testing
128
   */
136
   */
129
  static void TestMode (void);
137
  static void TestMode (void);
(-)a/src/internet/model/ipv6-address-generator.cc (+116 lines)
 Lines 129-134    Link Here 
129
  bool AddAllocated (const Ipv6Address addr);
129
  bool AddAllocated (const Ipv6Address addr);
130
130
131
  /**
131
  /**
132
   * \brief Check the Ipv6Address allocation in the list of IPv6 entries
133
   *
134
   * \param addr The Ipv6Address to be checked in the list of Ipv4 entries
135
   * \returns true if the network is already allocated
136
   */
137
  bool CheckAllocated (const Ipv6Address addr);
138
139
  /**
132
   * \brief Used to turn off fatal errors and assertions, for testing
140
   * \brief Used to turn off fatal errors and assertions, for testing
133
   */
141
   */
134
  void TestMode (void);
142
  void TestMode (void);
 Lines 558-563    Link Here 
558
  return true;
566
  return true;
559
}
567
}
560
568
569
bool
570
Ipv6AddressGeneratorImpl::CheckAllocated (const Ipv6Address address)
571
{
572
  NS_LOG_FUNCTION (this << address);
573
574
  uint8_t addr[16];
575
  address.GetBytes (addr);
576
577
  std::list<Entry>::iterator i;
578
579
  for (i = m_entries.begin (); i != m_entries.end (); ++i)
580
    {
581
      NS_LOG_LOGIC ("examine entry: " << Ipv6Address ((*i).addrLow) <<
582
                    " to " << Ipv6Address ((*i).addrHigh));
583
      //
584
      // First things first.  Is there an address collision -- that is, does the
585
      // new address fall in a previously allocated block of addresses.
586
      //
587
      if (!(Ipv6Address (addr) < Ipv6Address ((*i).addrLow))
588
          && ((Ipv6Address (addr) < Ipv6Address ((*i).addrHigh))
589
              || (Ipv6Address (addr) == Ipv6Address ((*i).addrHigh))))
590
        {
591
          NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::CheckAllocated(): Address Collision: " << Ipv6Address (addr));
592
          return false;
593
        }
594
      //
595
      // If the new address is less than the lowest address in the current
596
      // block and can't be merged into to the current block, then insert it
597
      // as a new block before the current block.
598
      //
599
      uint8_t taddr[16];
600
      for (uint32_t j = 0; j < 16; j++)
601
        {
602
          taddr[j] = (*i).addrLow[j];
603
        }
604
      taddr[15] -= 1;
605
      if (Ipv6Address (addr) < Ipv6Address (taddr))
606
        {
607
          break;
608
        }
609
      //
610
      // If the new address fits at the end of the block, look ahead to the next
611
      // block and make sure it's not a collision there.  If we won't overlap,
612
      // then just extend the current block by one address.  We expect that
613
      // completely filled network ranges will be a fairly rare occurrence,
614
      // so we don't worry about collapsing address range blocks.
615
      //
616
      for (uint32_t j = 0; j < 16; j++)
617
        {
618
          taddr[j] = (*i).addrLow[j];
619
        }
620
      taddr[15] += 1;
621
      if (Ipv6Address (addr) == Ipv6Address (taddr))
622
        {
623
          std::list<Entry>::iterator j = i;
624
          ++j;
625
626
          if (j != m_entries.end ())
627
            {
628
              if (Ipv6Address (addr) == Ipv6Address ((*j).addrLow))
629
                {
630
                  NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::CheckAllocated(): "
631
                                "Address Collision: " << Ipv6Address (addr));
632
                 }
633
            }
634
635
          NS_LOG_LOGIC ("New addrHigh = " << Ipv6Address (addr));
636
          for (uint32_t j = 0; j < 16; j++)
637
            {
638
              (*i).addrHigh[j] = addr[j];
639
            }
640
          return true;
641
        }
642
      //
643
      // If we get here, we know that the next lower block of addresses
644
      // couldn't have been extended to include this new address since the
645
      // code immediately above would have been executed and that next lower
646
      // block extended upward.  So we know it's safe to extend the current
647
      // block down to includ the new address.
648
      //
649
      for (uint32_t j = 0; j < 16; j++)
650
        {
651
          taddr[j] = (*i).addrLow[j];
652
        }
653
      taddr[15] -= 1;
654
      if ((Ipv6Address (addr) == Ipv6Address (taddr)))
655
        {
656
          NS_LOG_LOGIC ("New addrLow = " << Ipv6Address (addr));
657
          for (uint32_t j = 0; j < 16; j++)
658
            {
659
              (*i).addrLow[j] = addr[j];
660
            }
661
          return true;
662
        }
663
    }
664
665
  return true;
666
}
667
561
void
668
void
562
Ipv6AddressGeneratorImpl::TestMode (void)
669
Ipv6AddressGeneratorImpl::TestMode (void)
563
{
670
{
 Lines 676-681    Link Here 
676
         ->AddAllocated (addr);
783
         ->AddAllocated (addr);
677
}
784
}
678
785
786
bool
787
Ipv6AddressGenerator::CheckAllocated (const Ipv6Address addr)
788
{
789
  NS_LOG_FUNCTION_NOARGS ();
790
791
  return SimulationSingleton<Ipv6AddressGeneratorImpl>::Get ()
792
         ->CheckAllocated (addr);
793
}
794
679
void
795
void
680
Ipv6AddressGenerator::TestMode (void)
796
Ipv6AddressGenerator::TestMode (void)
681
{
797
{
(-)a/src/internet/model/ipv6-address-generator.h (+8 lines)
 Lines 147-152    Link Here 
147
  static bool AddAllocated (const Ipv6Address addr);
147
  static bool AddAllocated (const Ipv6Address addr);
148
148
149
  /**
149
  /**
150
   * \brief Check the Ipv6Address allocation in the list of IPv6 entries
151
   *
152
   * \param addr The Ipv6Address to be checked in the list of Ipv4 entries
153
   * \returns true if the network is already allocated
154
   */
155
  static bool CheckAllocated (const Ipv6Address addr);
156
157
  /**
150
   * \brief Used to turn off fatal errors and assertions, for testing
158
   * \brief Used to turn off fatal errors and assertions, for testing
151
   */
159
   */
152
  static void TestMode (void);
160
  static void TestMode (void);

Return to bug 2834