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

(-)a/src/internet/model/ipv4-interface.cc (+22 lines)
 Lines 346-350    Link Here 
346
  return (addr);  // quiet compiler
346
  return (addr);  // quiet compiler
347
}
347
}
348
348
349
Ipv4InterfaceAddress
350
Ipv4Interface::RemoveAddress(Ipv4Address address)
351
{
352
  NS_LOG_FUNCTION(this << address);
353
354
  if (address == address.GetLoopback())
355
    {
356
      NS_LOG_WARN ("Cannot remove loopback address.");
357
      return Ipv4InterfaceAddress();
358
    }
359
  for(Ipv4InterfaceAddressListI it = m_ifaddrs.begin(); it != m_ifaddrs.end(); it++)
360
    {
361
      if((*it).GetLocal() == address)
362
        {
363
          Ipv4InterfaceAddress ifAddr = *it;
364
          m_ifaddrs.erase(it);
365
          return ifAddr;
366
        }
367
    }
368
  return Ipv4InterfaceAddress();
369
}
370
349
} // namespace ns3
371
} // namespace ns3
350
372
(-)a/src/internet/model/ipv4-interface.h (+9 lines)
 Lines 152-157    Link Here 
152
   */
152
   */
153
  Ipv4InterfaceAddress RemoveAddress (uint32_t index);
153
  Ipv4InterfaceAddress RemoveAddress (uint32_t index);
154
154
155
  /**
156
   * \brief Remove the given Ipv4 address from the interface
157
   * \param address The Ipv4 address to remove
158
   * \returns The removed Ipv4 interface address 
159
   * \returns The null interface address if the interface did not contain the 
160
   * address
161
   */
162
  Ipv4InterfaceAddress RemoveAddress (Ipv4Address address);
163
155
protected:
164
protected:
156
  virtual void DoDispose (void);
165
  virtual void DoDispose (void);
157
private:
166
private:
(-)a/src/internet/model/ipv4-l3-protocol.cc (+23 lines)
 Lines 979-984    Link Here 
979
  return false;
979
  return false;
980
}
980
}
981
981
982
bool
983
Ipv4L3Protocol::RemoveAddress (uint32_t i, Ipv4Address address)
984
{
985
  NS_LOG_FUNCTION (this << i << address);
986
987
  if (address == address.GetLoopback())
988
    {
989
      NS_LOG_WARN ("Cannot remove loopback address.");
990
      return false;
991
    }
992
  Ptr<Ipv4Interface> interface = GetInterface (i);
993
  Ipv4InterfaceAddress ifAddr = interface->RemoveAddress (address);
994
  if (ifAddr != Ipv4InterfaceAddress ())
995
    {
996
      if (m_routingProtocol != 0)
997
        {
998
          m_routingProtocol->NotifyRemoveAddress (i, ifAddr);
999
        }
1000
      return true;
1001
    }
1002
  return false;
1003
}
1004
982
Ipv4Address 
1005
Ipv4Address 
983
Ipv4L3Protocol::SelectSourceAddress (Ptr<const NetDevice> device,
1006
Ipv4L3Protocol::SelectSourceAddress (Ptr<const NetDevice> device,
984
                                     Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
1007
                                     Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
(-)a/src/internet/model/ipv4-l3-protocol.h (+1 lines)
 Lines 194-199    Link Here 
194
  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
194
  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
195
  uint32_t GetNAddresses (uint32_t interface) const;
195
  uint32_t GetNAddresses (uint32_t interface) const;
196
  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
196
  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
197
  bool RemoveAddress (uint32_t interface, Ipv4Address address);
197
  Ipv4Address SelectSourceAddress (Ptr<const NetDevice> device,
198
  Ipv4Address SelectSourceAddress (Ptr<const NetDevice> device,
198
                                   Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope);
199
                                   Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope);
199
200
(-)a/src/internet/model/ipv4.h (+9 lines)
 Lines 248-253    Link Here 
248
   */
248
   */
249
  virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
249
  virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
250
250
251
   /**
252
   * Remove the given address on named interface.
253
   *
254
   * \param interface Interface number of an Ipv4 interface
255
   * \param address The address to remove
256
   * \returns true if the operation succeeded
257
   */
258
  virtual bool RemoveAddress (uint32_t interface, Ipv4Address address) = 0;
259
251
  /**
260
  /**
252
   * \brief Return the first primary source address with scope less than 
261
   * \brief Return the first primary source address with scope less than 
253
   * or equal to the requested scope, to use in sending a packet to 
262
   * or equal to the requested scope, to use in sending a packet to 
(-)a/src/internet/model/ipv6-interface.cc (+16 lines)
 Lines 291-296    Link Here 
291
  return addr;  /* quiet compiler */
291
  return addr;  /* quiet compiler */
292
}
292
}
293
293
294
Ipv6InterfaceAddress Ipv6Interface::RemoveAddress(Ipv6Address address)
295
{
296
  NS_LOG_FUNCTION(this << address);
297
298
  for (Ipv6InterfaceAddressListI it = m_addresses.begin (); it != m_addresses.end (); ++it)
299
    {
300
      if((*it).GetAddress() == address)
301
        {
302
          Ipv6InterfaceAddress iface = (*it);
303
          m_addresses.erase(it);
304
          return iface;
305
        }
306
    }
307
  return Ipv6InterfaceAddress();
308
}
309
294
Ipv6InterfaceAddress Ipv6Interface::GetAddressMatchingDestination (Ipv6Address dst)
310
Ipv6InterfaceAddress Ipv6Interface::GetAddressMatchingDestination (Ipv6Address dst)
295
{
311
{
296
  NS_LOG_FUNCTION (this << dst);
312
  NS_LOG_FUNCTION (this << dst);
(-)a/src/internet/model/ipv6-interface.h (+10 lines)
 Lines 228-233    Link Here 
228
  Ipv6InterfaceAddress RemoveAddress (uint32_t index);
228
  Ipv6InterfaceAddress RemoveAddress (uint32_t index);
229
229
230
  /**
230
  /**
231
   * \brief Remove the given Ipv6 address from the interface
232
   * \param address The Ipv6 address to remove
233
   * \returns The interface address of the Ipv6 interface from which the 
234
   * address was removed
235
   * \returns The null interface address if the interface did not contan the 
236
   * address
237
   */
238
  Ipv6InterfaceAddress RemoveAddress (Ipv6Address address);
239
240
  /**
231
   * \brief Update state of an interface address.
241
   * \brief Update state of an interface address.
232
   * \param address IPv6 address
242
   * \param address IPv6 address
233
   * \param state new state
243
   * \param state new state
(-)a/src/internet/model/ipv6-l3-protocol.cc (+16 lines)
 Lines 381-386    Link Here 
381
  return false;
381
  return false;
382
}
382
}
383
383
384
bool Ipv6L3Protocol::RemoveAddress (uint32_t i, Ipv6Address address)
385
{
386
  NS_LOG_FUNCTION (this << i << address);
387
  Ptr<Ipv6Interface> interface = GetInterface (i);
388
  Ipv6InterfaceAddress ifAddr = interface->RemoveAddress (address);
389
  if (ifAddr != Ipv6InterfaceAddress ())
390
  {
391
    if (m_routingProtocol != 0)
392
    {
393
      m_routingProtocol->NotifyRemoveAddress (i, ifAddr);
394
    }
395
    return true;
396
  }
397
  return false;
398
}
399
384
void Ipv6L3Protocol::SetMetric (uint32_t i, uint16_t metric)
400
void Ipv6L3Protocol::SetMetric (uint32_t i, uint16_t metric)
385
{
401
{
386
  NS_LOG_FUNCTION (this << i << metric);
402
  NS_LOG_FUNCTION (this << i << metric);
(-)a/src/internet/model/ipv6-l3-protocol.h (+7 lines)
 Lines 249-254    Link Here 
249
  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
249
  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
250
250
251
  /**
251
  /**
252
   * \brief Remove an address from an interface.
253
   * \param interfaceIndex interface index
254
   * \param address address on the interface
255
   */
256
   bool RemoveAddress (uint32_t interface, Ipv6Address address);
257
258
  /**
252
   * \brief Set metric for an interface.
259
   * \brief Set metric for an interface.
253
   * \param i index
260
   * \param i index
254
   * \param metric
261
   * \param metric
(-)a/src/internet/model/ipv6.h (+9 lines)
 Lines 218-223    Link Here 
218
  virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
218
  virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex) = 0;
219
219
220
  /**
220
  /**
221
   * \brief Remove an address on specified IPv6 interface.
222
   *
223
   * \param interface Interface number of an IPv6 interface
224
   * \param address the address to remove
225
   * \returns true if the operation succeeded
226
   */
227
  virtual bool RemoveAddress (uint32_t interface, Ipv6Address address) = 0;
228
229
  /**
221
   * \brief Set metric on specified Ipv6 interface.
230
   * \brief Set metric on specified Ipv6 interface.
222
   *
231
   *
223
   * \param interface The interface number of an IPv6 interface
232
   * \param interface The interface number of an IPv6 interface
(-)a/src/internet/test/ipv4-test.cc (+30 lines)
 Lines 94-102    Link Here 
94
  Ipv4InterfaceAddress output = interface->GetAddress (2);
94
  Ipv4InterfaceAddress output = interface->GetAddress (2);
95
  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
95
  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
96
                         "The addresses should be identical");
96
                         "The addresses should be identical");
97
98
  output = interface->RemoveAddress (Ipv4Address ("250.0.0.1"));
99
  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
100
                         "The addresses should be identical");
101
  num = interface->GetNAddresses ();
102
  NS_TEST_ASSERT_MSG_EQ (num, 2, "Should find 2 interfaces??");
103
  
104
  output = interface->RemoveAddress (Ipv4Address ("253.123.9.81"));
105
  NS_TEST_ASSERT_MSG_EQ (Ipv4InterfaceAddress (), output,
106
                         "The addresses should be identical");
107
  num = interface->GetNAddresses ();
108
  NS_TEST_ASSERT_MSG_EQ (num, 2, "Should find 2 interfaces??");
109
  
110
  bool removalSuccess = ipv4->RemoveAddress (index, Ipv4Address
111
  ("192.168.0.2"));
112
  NS_TEST_ASSERT_MSG_EQ (true, removalSuccess,
113
                         "The addresses was not removed");
114
  num = interface->GetNAddresses ();
115
  NS_TEST_ASSERT_MSG_EQ (num, 1, "Should find 1 interfaces??");
116
  removalSuccess = ipv4->RemoveAddress (index, Ipv4Address ("127.0.0.1"));
117
  NS_TEST_ASSERT_MSG_EQ (false, removalSuccess,
118
                         "Shouldn't removed loopback address");
119
  output = interface->RemoveAddress (Ipv4Address ("127.0.0.1"));
120
  NS_TEST_ASSERT_MSG_EQ (Ipv4InterfaceAddress (), output,
121
                         "The addresses should be identical");
122
123
  removalSuccess = ipv4->RemoveAddress (index, Ipv4Address ("189.0.0.1"));
124
  NS_TEST_ASSERT_MSG_EQ (false, removalSuccess,
125
                         "Non-existent IP Address removed");
97
  Simulator::Destroy ();
126
  Simulator::Destroy ();
98
}
127
}
99
128
129
  
100
static class IPv4L3ProtocolTestSuite : public TestSuite
130
static class IPv4L3ProtocolTestSuite : public TestSuite
101
{
131
{
102
public:
132
public:

Return to bug 760