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

(-)a/src/internet/model/ipv4-address-generator.cc (-1 / +88 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 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);
 Lines 412-418    Link Here 
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)
 Lines 429-434    Link Here 
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
{
 Lines 546-551    Link Here 
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
{
(-)a/src/internet/model/ipv4-address-generator.h (+17 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
  /**
135
   * \brief Check if a network has already allocated addresses
136
   *
137
   * \param addr The Ipv4 network to be checked
138
   * \param mask The Ipv4 network mask
139
   * \returns true if the network is already allocated
140
   */
141
  static bool IsNetworkAllocated (const Ipv4Address addr, const Ipv4Mask mask);
142
143
  /**
127
   * \brief Used to turn off fatal errors and assertions, for testing
144
   * \brief Used to turn off fatal errors and assertions, for testing
128
   */
145
   */
129
  static void TestMode (void);
146
  static void TestMode (void);
(-)a/src/internet/model/ipv6-address-generator.cc (+90 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
  /**
140
   * \brief Check if a network has already allocated addresses
141
   *
142
   * \param addr The Ipv6 network to be checked
143
   * \param prefix The Ipv6 network prefix
144
   * \returns true if the network is already allocated
145
   */
146
  bool IsNetworkAllocated (const Ipv6Address addr, const Ipv6Prefix prefix);
147
148
  /**
132
   * \brief Used to turn off fatal errors and assertions, for testing
149
   * \brief Used to turn off fatal errors and assertions, for testing
133
   */
150
   */
134
  void TestMode (void);
151
  void TestMode (void);
 Lines 558-563    Link Here 
558
  return true;
575
  return true;
559
}
576
}
560
577
578
bool
579
Ipv6AddressGeneratorImpl::CheckAllocated (const Ipv6Address address)
580
{
581
  NS_LOG_FUNCTION (this << address);
582
583
  uint8_t addr[16];
584
  address.GetBytes (addr);
585
586
  std::list<Entry>::iterator i;
587
588
  for (i = m_entries.begin (); i != m_entries.end (); ++i)
589
    {
590
      NS_LOG_LOGIC ("examine entry: " << Ipv6Address ((*i).addrLow) <<
591
                    " to " << Ipv6Address ((*i).addrHigh));
592
593
      if (!(Ipv6Address (addr) < Ipv6Address ((*i).addrLow))
594
          && ((Ipv6Address (addr) < Ipv6Address ((*i).addrHigh))
595
              || (Ipv6Address (addr) == Ipv6Address ((*i).addrHigh))))
596
        {
597
          NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::CheckAllocated(): Address Collision: " << Ipv6Address (addr));
598
          return false;
599
        }
600
    }
601
  return true;
602
}
603
604
bool
605
Ipv6AddressGeneratorImpl::IsNetworkAllocated (const Ipv6Address address, const Ipv6Prefix prefix)
606
{
607
  NS_LOG_FUNCTION (this << address << prefix);
608
609
  Ipv6Address addr = address;
610
  NS_ABORT_MSG_UNLESS (address == addr.CombinePrefix (prefix),
611
                       "Ipv6AddressGeneratorImpl::IsNetworkAllocated(): network address and mask don't match " << address << " " << prefix);
612
613
  std::list<Entry>::iterator i;
614
615
  for (i = m_entries.begin (); i != m_entries.end (); ++i)
616
    {
617
      NS_LOG_LOGIC ("examine entry: " << Ipv6Address ((*i).addrLow) << " to " << Ipv6Address ((*i).addrHigh));
618
      Ipv6Address low = Ipv6Address ((*i).addrLow);
619
      Ipv6Address high = Ipv6Address ((*i).addrHigh);
620
621
      if (address == low.CombinePrefix (prefix) || address == high.CombinePrefix (prefix))
622
        {
623
          NS_LOG_LOGIC ("Ipv6AddressGeneratorImpl::IsNetworkAllocated(): Network already allocated: " <<
624
                        address << " " << low << "-" << high);
625
          return false;
626
        }
627
628
    }
629
  return true;
630
}
631
632
561
void
633
void
562
Ipv6AddressGeneratorImpl::TestMode (void)
634
Ipv6AddressGeneratorImpl::TestMode (void)
563
{
635
{
 Lines 676-681    Link Here 
676
         ->AddAllocated (addr);
748
         ->AddAllocated (addr);
677
}
749
}
678
750
751
bool
752
Ipv6AddressGenerator::CheckAllocated (const Ipv6Address addr)
753
{
754
  NS_LOG_FUNCTION_NOARGS ();
755
756
  return SimulationSingleton<Ipv6AddressGeneratorImpl>::Get ()
757
         ->CheckAllocated (addr);
758
}
759
760
bool
761
Ipv6AddressGenerator::IsNetworkAllocated (const Ipv6Address addr, const Ipv6Prefix prefix)
762
{
763
  NS_LOG_FUNCTION_NOARGS ();
764
765
  return SimulationSingleton<Ipv6AddressGeneratorImpl>::Get ()
766
         ->IsNetworkAllocated (addr, prefix);
767
}
768
679
void
769
void
680
Ipv6AddressGenerator::TestMode (void)
770
Ipv6AddressGenerator::TestMode (void)
681
{
771
{
(-)a/src/internet/model/ipv6-address-generator.h (+17 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 address is already allocated
154
   */
155
  static bool CheckAllocated (const Ipv6Address addr);
156
157
  /**
158
   * \brief Check if a network has already allocated addresses
159
   *
160
   * \param addr The Ipv6 network to be checked
161
   * \param prefix The Ipv6 network prefix
162
   * \returns true if the network is already allocated
163
   */
164
  static bool IsNetworkAllocated (const Ipv6Address addr, const Ipv6Prefix prefix);
165
166
  /**
150
   * \brief Used to turn off fatal errors and assertions, for testing
167
   * \brief Used to turn off fatal errors and assertions, for testing
151
   */
168
   */
152
  static void TestMode (void);
169
  static void TestMode (void);

Return to bug 2834