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

(-)./12325/aodv-routing-protocol.cc (-4 / +19 lines)
 Lines 2052-2067   void Link Here 
2052
RoutingProtocol::DoInitialize (void)
2052
RoutingProtocol::DoInitialize (void)
2053
{
2053
{
2054
  NS_LOG_FUNCTION (this);
2054
  NS_LOG_FUNCTION (this);
2055
  uint32_t startTime;
2056
  if (m_enableHello)
2055
  if (m_enableHello)
2057
    {
2056
    {
2058
      m_htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
2057
      m_htimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
2059
      startTime = m_uniformRandomVariable->GetInteger (0, 100);
2058
      m_routingTable.SetActiveRouteCallback (MakeCallback (&RoutingProtocol::ScheduleHello, this));
2060
      NS_LOG_DEBUG ("Starting at time " << startTime << "ms");
2059
      m_routingTable.SetNoActiveRouteCallback (MakeCallback (&RoutingProtocol::CancelHello, this));
2061
      m_htimer.Schedule (MilliSeconds (startTime));
2062
    }
2060
    }
2063
  Ipv4RoutingProtocol::DoInitialize ();
2061
  Ipv4RoutingProtocol::DoInitialize ();
2064
}
2062
}
2065
2063
2064
void
2065
RoutingProtocol::ScheduleHello ()
2066
{
2067
  NS_LOG_FUNCTION (this);
2068
  uint32_t startTime;
2069
  startTime = m_uniformRandomVariable->GetInteger (0, 100);
2070
  NS_LOG_DEBUG ("Starting in " << startTime << "ms");
2071
  m_htimer.Schedule (MilliSeconds (startTime));
2072
}
2073
2074
void
2075
RoutingProtocol::CancelHello ()
2076
{
2077
  NS_LOG_FUNCTION (this);
2078
  m_htimer.Cancel ();
2079
}
2080
2066
} //namespace aodv
2081
} //namespace aodv
2067
} //namespace ns3
2082
} //namespace ns3
(-)./12325/aodv-routing-protocol.h (+4 lines)
 Lines 269-274   private: Link Here 
269
  void RouteRequestTimerExpire (Ipv4Address dst);
269
  void RouteRequestTimerExpire (Ipv4Address dst);
270
  /// Mark link to neighbor node as unidirectional for blacklistTimeout
270
  /// Mark link to neighbor node as unidirectional for blacklistTimeout
271
  void AckTimerExpire (Ipv4Address neighbor,  Time blacklistTimeout);
271
  void AckTimerExpire (Ipv4Address neighbor,  Time blacklistTimeout);
272
  /// Schedule hello transmission
273
  void ScheduleHello ();
274
  /// Cancel hello transmission
275
  void CancelHello ();
272
276
273
  /// Provides uniform random variables.
277
  /// Provides uniform random variables.
274
  Ptr<UniformRandomVariable> m_uniformRandomVariable;  
278
  Ptr<UniformRandomVariable> m_uniformRandomVariable;  
(-)./12325/aodv-rtable.cc (-34 / +26 lines)
 Lines 236-241   RoutingTable::DeleteRoute (Ipv4Address d Link Here 
236
{
236
{
237
  NS_LOG_FUNCTION (this << dst);
237
  NS_LOG_FUNCTION (this << dst);
238
  Purge ();
238
  Purge ();
239
  // DeleteRoute called only when no route is found after a route request, deleted entry is never in VALID state
240
  RoutingTableEntry rt;
241
  NS_ASSERT (LookupValidRoute (dst, rt) == false);
239
  if (m_ipv4AddressEntry.erase (dst) != 0)
242
  if (m_ipv4AddressEntry.erase (dst) != 0)
240
    {
243
    {
241
      NS_LOG_LOGIC ("Route deletion to " << dst << " successful");
244
      NS_LOG_LOGIC ("Route deletion to " << dst << " successful");
 Lines 254-259   RoutingTable::AddRoute (RoutingTableEntr Link Here 
254
    rt.SetRreqCnt (0);
257
    rt.SetRreqCnt (0);
255
  std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator, bool> result =
258
  std::pair<std::map<Ipv4Address, RoutingTableEntry>::iterator, bool> result =
256
    m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt));
259
    m_ipv4AddressEntry.insert (std::make_pair (rt.GetDestination (), rt));
260
  UpdateActiveRoutes (rt);
257
  return result.second;
261
  return result.second;
258
}
262
}
259
263
 Lines 268-273   RoutingTable::Update (RoutingTableEntry Link Here 
268
      NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " fails; not found");
272
      NS_LOG_LOGIC ("Route update to " << rt.GetDestination () << " fails; not found");
269
      return false;
273
      return false;
270
    }
274
    }
275
  UpdateActiveRoutes (rt);
271
  i->second = rt;
276
  i->second = rt;
272
  if (i->second.GetFlag () != IN_SEARCH)
277
  if (i->second.GetFlag () != IN_SEARCH)
273
    {
278
    {
 Lines 290-295   RoutingTable::SetEntryState (Ipv4Address Link Here 
290
    }
295
    }
291
  i->second.SetFlag (state);
296
  i->second.SetFlag (state);
292
  i->second.SetRreqCnt (0);
297
  i->second.SetRreqCnt (0);
298
  UpdateActiveRoutes (i->second);
293
  NS_LOG_LOGIC ("Route set entry state to " << id << ": new state is " << state);
299
  NS_LOG_LOGIC ("Route set entry state to " << id << ": new state is " << state);
294
  return true;
300
  return true;
295
}
301
}
 Lines 326-337   RoutingTable::InvalidateRoutesWithDst (c Link Here 
326
            {
332
            {
327
              NS_LOG_LOGIC ("Invalidate route with destination address " << i->first);
333
              NS_LOG_LOGIC ("Invalidate route with destination address " << i->first);
328
              i->second.Invalidate (m_badLinkLifetime);
334
              i->second.Invalidate (m_badLinkLifetime);
335
              UpdateActiveRoutes (i->second);
329
            }
336
            }
330
        }
337
        }
331
    }
338
    }
332
}
339
}
333
340
334
void
341
void
342
RoutingTable::UpdateActiveRoutes (RoutingTableEntry & rt)
343
{
344
  NS_LOG_FUNCTION (this);
345
  if ((rt.GetFlag () != VALID || rt.IsPrecursorListEmpty () == true) && m_activeRoutes.erase (rt.GetDestination ()) > 0
346
      && m_activeRoutes.empty () == true && m_narc.IsNull () == false)
347
    {
348
      NS_LOG_LOGIC ("Calling not in active route callback");
349
      m_narc ();
350
    }
351
  else if (rt.GetFlag () == VALID && rt.IsPrecursorListEmpty() == false && m_activeRoutes.insert (rt.GetDestination ()).second == true
352
      && m_activeRoutes.size () == 1 && m_arc.IsNull () == false)
353
    {
354
      NS_LOG_LOGIC ("Calling in active route callback");
355
      m_arc ();
356
    }
357
}
358
359
void
335
RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface)
360
RoutingTable::DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface)
336
{
361
{
337
  NS_LOG_FUNCTION (this);
362
  NS_LOG_FUNCTION (this);
 Lines 372-410   RoutingTable::Purge () Link Here 
372
            {
397
            {
373
              NS_LOG_LOGIC ("Invalidate route with destination address " << i->first);
398
              NS_LOG_LOGIC ("Invalidate route with destination address " << i->first);
374
              i->second.Invalidate (m_badLinkLifetime);
399
              i->second.Invalidate (m_badLinkLifetime);
375
              ++i;
400
              UpdateActiveRoutes (i->second);
376
            }
377
          else
378
            ++i;
379
        }
380
      else 
381
        {
382
          ++i;
383
        }
384
    }
385
}
386
387
void
388
RoutingTable::Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const
389
{
390
  NS_LOG_FUNCTION (this);
391
  if (table.empty ())
392
    return;
393
  for (std::map<Ipv4Address, RoutingTableEntry>::iterator i =
394
         table.begin (); i != table.end ();)
395
    {
396
      if (i->second.GetLifeTime () < Seconds (0))
397
        {
398
          if (i->second.GetFlag () == INVALID)
399
            {
400
              std::map<Ipv4Address, RoutingTableEntry>::iterator tmp = i;
401
              ++i;
402
              table.erase (tmp);
403
            }
404
          else if (i->second.GetFlag () == VALID)
405
            {
406
              NS_LOG_LOGIC ("Invalidate route with destination address " << i->first);
407
              i->second.Invalidate (m_badLinkLifetime);
408
              ++i;
401
              ++i;
409
            }
402
            }
410
          else
403
          else
 Lines 439-445   void Link Here 
439
RoutingTable::Print (Ptr<OutputStreamWrapper> stream) const
432
RoutingTable::Print (Ptr<OutputStreamWrapper> stream) const
440
{
433
{
441
  std::map<Ipv4Address, RoutingTableEntry> table = m_ipv4AddressEntry;
434
  std::map<Ipv4Address, RoutingTableEntry> table = m_ipv4AddressEntry;
442
  Purge (table);
443
  *stream->GetStream () << "\nAODV Routing table\n"
435
  *stream->GetStream () << "\nAODV Routing table\n"
444
                        << "Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n";
436
                        << "Destination\tGateway\t\tInterface\tFlag\tExpire\t\tHops\n";
445
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
437
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i =
(-)./12325/aodv-rtable.h (-2 / +14 lines)
 Lines 31-40    Link Here 
31
#include <stdint.h>
31
#include <stdint.h>
32
#include <cassert>
32
#include <cassert>
33
#include <map>
33
#include <map>
34
#include <set>
34
#include <sys/types.h>
35
#include <sys/types.h>
35
#include "ns3/ipv4.h"
36
#include "ns3/ipv4.h"
36
#include "ns3/ipv4-route.h"
37
#include "ns3/ipv4-route.h"
37
#include "ns3/timer.h"
38
#include "ns3/timer.h"
39
#include "ns3/callback.h"
38
#include "ns3/net-device.h"
40
#include "ns3/net-device.h"
39
#include "ns3/output-stream-wrapper.h"
41
#include "ns3/output-stream-wrapper.h"
40
42
 Lines 229-234   public: Link Here 
229
   *  3. The Lifetime field is updated to current time plus DELETE_PERIOD.
231
   *  3. The Lifetime field is updated to current time plus DELETE_PERIOD.
230
   */
232
   */
231
  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
233
  void InvalidateRoutesWithDst (std::map<Ipv4Address, uint32_t> const & unreachable);
234
  /// Update active routes (used for hello transmission)
235
  void UpdateActiveRoutes (RoutingTableEntry & rt);
236
  /// Set callback for in active route
237
  void SetActiveRouteCallback (Callback<void> cb) { m_arc = cb; }
238
  /// Set callback for not in active route
239
  void SetNoActiveRouteCallback (Callback<void> cb) { m_narc = cb; }
232
  /// Delete all route from interface with address iface
240
  /// Delete all route from interface with address iface
233
  void DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface);
241
  void DeleteAllRoutesFromInterface (Ipv4InterfaceAddress iface);
234
  /// Delete all entries from routing table
242
  /// Delete all entries from routing table
 Lines 248-255   private: Link Here 
248
  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
256
  std::map<Ipv4Address, RoutingTableEntry> m_ipv4AddressEntry;
249
  /// Deletion time for invalid routes
257
  /// Deletion time for invalid routes
250
  Time m_badLinkLifetime;
258
  Time m_badLinkLifetime;
251
  /// const version of Purge, for use by Print() method
259
  /// Set of active routes (used for hello transmission)
252
  void Purge (std::map<Ipv4Address, RoutingTableEntry> &table) const;
260
  std::set<Ipv4Address> m_activeRoutes;
261
  /// Callback for in active route
262
  Callback<void> m_arc;
263
  /// Callback for not in active route
264
  Callback<void> m_narc;
253
};
265
};
254
266
255
}
267
}

Return to bug 1188