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

(-)a/src/routing/olsr/olsr-repositories.h (+57 lines)
 Lines 231-236    Link Here 
231
  return os;
231
  return os;
232
}
232
}
233
233
234
/// Association
235
struct Association
236
{
237
  Ipv4Address networkAddr;
238
  Ipv4Mask netmask;
239
};
240
241
static inline bool
242
operator == (const Association &a, const Association &b)
243
{
244
  return (a.networkAddr == b.networkAddr
245
          && a.netmask == b.netmask);
246
}
247
248
static inline std::ostream&
249
operator << (std::ostream &os, const Association &tuple)
250
{
251
  os << "Association(networkAddr=" << tuple.networkAddr
252
     << ", netmask=" << tuple.netmask
253
     << ")";
254
  return os;
255
}
256
257
/// An Association Tuple
258
struct AssociationTuple
259
{
260
  /// Main address of the gateway.
261
  Ipv4Address gatewayAddr;
262
  /// Network Address of network reachable through gatewayAddr
263
  Ipv4Address networkAddr;
264
  /// Netmask of network reachable through gatewayAddr
265
  Ipv4Mask netmask;
266
  /// Time at which this tuple expires and must be removed
267
  Time expirationTime;
268
};
269
270
static inline bool
271
operator == (const AssociationTuple &a, const AssociationTuple &b)
272
{
273
  return (a.gatewayAddr == b.gatewayAddr
274
          && a.networkAddr == b.networkAddr
275
          && a.netmask == b.netmask);
276
}
277
278
static inline std::ostream&
279
operator << (std::ostream &os, const AssociationTuple &tuple)
280
{
281
  os << "AssociationTuple(gatewayAddr=" << tuple.gatewayAddr
282
     << ", networkAddr=" << tuple.networkAddr
283
     << ", netmask=" << tuple.netmask
284
     << ", expirationTime=" << tuple.expirationTime
285
     << ")";
286
  return os;
287
}
288
234
289
235
typedef std::set<Ipv4Address> 			MprSet;	///< MPR Set type.
290
typedef std::set<Ipv4Address> 			MprSet;	///< MPR Set type.
236
typedef std::vector<MprSelectorTuple>		MprSelectorSet;	///< MPR Selector Set type.
291
typedef std::vector<MprSelectorTuple>		MprSelectorSet;	///< MPR Selector Set type.
 Lines 240-245    Link Here 
240
typedef std::vector<TopologyTuple>		TopologySet;	///< Topology Set type.
295
typedef std::vector<TopologyTuple>		TopologySet;	///< Topology Set type.
241
typedef std::vector<DuplicateTuple>		DuplicateSet;	///< Duplicate Set type.
296
typedef std::vector<DuplicateTuple>		DuplicateSet;	///< Duplicate Set type.
242
typedef std::vector<IfaceAssocTuple>		IfaceAssocSet; ///< Interface Association Set type.
297
typedef std::vector<IfaceAssocTuple>		IfaceAssocSet; ///< Interface Association Set type.
298
typedef std::vector<AssociationTuple>		AssociationSet; ///< Association Set type.
299
typedef std::vector<Association>		Associations; ///< Association Set type.
243
300
244
301
245
}}; // namespace ns3, olsr
302
}}; // namespace ns3, olsr
(-)a/src/routing/olsr/olsr-routing-protocol.cc (-18 / +341 lines)
 Lines 41-46    Link Here 
41
#include "ns3/random-variable.h"
41
#include "ns3/random-variable.h"
42
#include "ns3/inet-socket-address.h"
42
#include "ns3/inet-socket-address.h"
43
#include "ns3/ipv4-routing-protocol.h"
43
#include "ns3/ipv4-routing-protocol.h"
44
#include "ns3/ipv4-routing-table-entry.h"
44
#include "ns3/ipv4-route.h"
45
#include "ns3/ipv4-route.h"
45
#include "ns3/boolean.h"
46
#include "ns3/boolean.h"
46
#include "ns3/uinteger.h"
47
#include "ns3/uinteger.h"
 Lines 79-85    Link Here 
79
#define OLSR_DUP_HOLD_TIME	Seconds (30)
80
#define OLSR_DUP_HOLD_TIME	Seconds (30)
80
/// MID holding time.
81
/// MID holding time.
81
#define OLSR_MID_HOLD_TIME	(Scalar (3) * m_midInterval)
82
#define OLSR_MID_HOLD_TIME	(Scalar (3) * m_midInterval)
82
83
/// HNA holding time.
84
#define OLSR_HNA_HOLD_TIME  (Scalar (3) * m_hnaInterval)
83
85
84
/********** Link types **********/
86
/********** Link types **********/
85
87
 Lines 165-170    Link Here 
165
                   TimeValue (Seconds (5)),
167
                   TimeValue (Seconds (5)),
166
                   MakeTimeAccessor (&RoutingProtocol::m_midInterval),
168
                   MakeTimeAccessor (&RoutingProtocol::m_midInterval),
167
                   MakeTimeChecker ())
169
                   MakeTimeChecker ())
170
    .AddAttribute ("HnaInterval", "HNA messages emission interval.  Normally it is equal to TcInterval.",
171
                   TimeValue (Seconds (5)),
172
                   MakeTimeAccessor (&RoutingProtocol::m_hnaInterval),
173
                   MakeTimeChecker ())
168
    .AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.",
174
    .AddAttribute ("Willingness", "Willingness of a node to carry and forward traffic for other nodes.",
169
                   EnumValue (OLSR_WILL_DEFAULT),
175
                   EnumValue (OLSR_WILL_DEFAULT),
170
                   MakeEnumAccessor (&RoutingProtocol::m_willingness),
176
                   MakeEnumAccessor (&RoutingProtocol::m_willingness),
 Lines 185-199    Link Here 
185
191
186
192
187
RoutingProtocol::RoutingProtocol ()
193
RoutingProtocol::RoutingProtocol ()
188
  : m_ipv4 (0),
194
  : m_routingTableAssociation (0),
195
    m_ipv4 (0),
189
    m_helloTimer (Timer::CANCEL_ON_DESTROY),
196
    m_helloTimer (Timer::CANCEL_ON_DESTROY),
190
    m_tcTimer (Timer::CANCEL_ON_DESTROY),
197
    m_tcTimer (Timer::CANCEL_ON_DESTROY),
191
    m_midTimer (Timer::CANCEL_ON_DESTROY),
198
    m_midTimer (Timer::CANCEL_ON_DESTROY),
199
    m_hnaTimer (Timer::CANCEL_ON_DESTROY),    
192
    m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY)
200
    m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY)
193
{}
201
{
202
  m_hnaRoutingTable = Create<Ipv4StaticRouting> ();
203
}
194
204
195
RoutingProtocol::~RoutingProtocol ()
205
RoutingProtocol::~RoutingProtocol ()
196
{}
206
{
207
}
197
208
198
void
209
void
199
RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
210
RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
 Lines 204-209    Link Here 
204
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
215
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
205
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
216
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
206
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
217
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
218
  m_hnaTimer.SetFunction (&RoutingProtocol::HnaTimerExpire, this);
207
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
219
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
208
220
209
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
221
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
 Lines 213-223    Link Here 
213
  m_linkTupleTimerFirstTime = true;
225
  m_linkTupleTimerFirstTime = true;
214
226
215
  m_ipv4 = ipv4;
227
  m_ipv4 = ipv4;
228
  
229
  m_hnaRoutingTable->SetIpv4 (ipv4);
216
}
230
}
217
231
218
void RoutingProtocol::DoDispose ()
232
void RoutingProtocol::DoDispose ()
219
{
233
{
220
  m_ipv4 = 0;
234
  m_ipv4 = 0;
235
  m_hnaRoutingTable = 0;
236
  m_routingTableAssociation = 0;
221
237
222
  for (std::map< Ptr<Socket>, Ipv4InterfaceAddress >::iterator iter = m_socketAddresses.begin ();
238
  for (std::map< Ptr<Socket>, Ipv4InterfaceAddress >::iterator iter = m_socketAddresses.begin ();
223
       iter != m_socketAddresses.end (); iter++)
239
       iter != m_socketAddresses.end (); iter++)
 Lines 251-256    Link Here 
251
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
267
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
252
268
253
  Ipv4Address loopback ("127.0.0.1");
269
  Ipv4Address loopback ("127.0.0.1");
270
271
  bool canRunOlsr = false;
254
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
272
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
255
    {
273
    {
256
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
274
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
 Lines 269-274    Link Here 
269
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
287
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
270
        }
288
        }
271
289
290
      if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ())
291
        continue;
292
272
      // Create a socket to listen only on this interface
293
      // Create a socket to listen only on this interface
273
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
294
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
274
        UdpSocketFactory::GetTypeId()); 
295
        UdpSocketFactory::GetTypeId()); 
 Lines 279-291    Link Here 
279
        }
300
        }
280
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
301
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
281
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
302
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
303
304
      canRunOlsr = true;
282
    }
305
    }
283
306
284
  HelloTimerExpire ();
307
  if(canRunOlsr)
285
  TcTimerExpire ();
308
   {
286
  MidTimerExpire ();
309
      HelloTimerExpire ();
310
      TcTimerExpire ();
311
      MidTimerExpire ();
312
      HnaTimerExpire ();      
287
313
288
  NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
314
      NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
315
   }
289
}
316
}
290
317
291
void RoutingProtocol::SetMainInterface (uint32_t interface)
318
void RoutingProtocol::SetMainInterface (uint32_t interface)
 Lines 293-298    Link Here 
293
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
320
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
294
}
321
}
295
322
323
void RoutingProtocol::SetInterfaceExclusions (std::set<uint32_t> exceptions)
324
{
325
  m_interfaceExclusions = exceptions;
326
}
296
327
297
//
328
//
298
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
329
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
 Lines 397-402    Link Here 
397
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
428
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
398
              ProcessMid (messageHeader, senderIfaceAddr);
429
              ProcessMid (messageHeader, senderIfaceAddr);
399
              break;
430
              break;
431
            case olsr::MessageHeader::HNA_MESSAGE:
432
              NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
433
                            << "s OLSR node " << m_mainAddress
434
                            <<  " received HNA message of size " << messageHeader.GetSerializedSize ());
435
              ProcessHna (messageHeader, senderIfaceAddr);
436
              break; 
400
437
401
            default:
438
            default:
402
              NS_LOG_DEBUG ("OLSR message type " <<
439
              NS_LOG_DEBUG ("OLSR message type " <<
 Lines 1039-1044    Link Here 
1039
        }
1076
        }
1040
    }
1077
    }
1041
1078
1079
  // 5. For each tuple in the association set,
1080
  //    If there is no entry in the routing table with:
1081
  //        R_dest_addr     == A_network_addr/A_netmask
1082
  //   then a new routing entry is created.
1083
  const AssociationSet &associationSet = m_state.GetAssociationSet ();
1084
  for (AssociationSet::const_iterator it = associationSet.begin ();
1085
       it != associationSet.end (); it++)
1086
    {
1087
      AssociationTuple const &tuple = *it;
1088
      RoutingTableEntry gatewayEntry;
1089
      
1090
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
1091
      bool addRoute = false;
1092
      
1093
      uint32_t routeIndex = 0;
1094
      
1095
      for (routeIndex = 0; routeIndex < m_hnaRoutingTable->GetNRoutes (); routeIndex++)
1096
        {
1097
          Ipv4RoutingTableEntry route = m_hnaRoutingTable->GetRoute (routeIndex);
1098
          if (route.GetDestNetwork () == tuple.networkAddr &&
1099
              route.GetDestNetworkMask () == tuple.netmask)
1100
            {
1101
              break;
1102
            }
1103
        }
1104
    
1105
      if (routeIndex == m_hnaRoutingTable->GetNRoutes ())
1106
        {
1107
          addRoute = true;
1108
        }
1109
      else if(gatewayEntryExists && m_hnaRoutingTable->GetMetric (routeIndex) > gatewayEntry.distance)
1110
        {
1111
          m_hnaRoutingTable->RemoveRoute(routeIndex);
1112
          addRoute = true;
1113
        }
1114
        
1115
      if(addRoute && gatewayEntryExists)
1116
        {
1117
          m_hnaRoutingTable->AddNetworkRouteTo (tuple.networkAddr,
1118
                                                tuple.netmask,
1119
                                                gatewayEntry.nextAddr,
1120
                                                gatewayEntry.interface,
1121
                                                gatewayEntry.distance);
1122
                                             
1123
        }
1124
    }
1125
1042
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1126
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1043
  m_routingTableChanged (GetSize ());
1127
  m_routingTableChanged (GetSize ());
1044
}
1128
}
 Lines 1280-1285    Link Here 
1280
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1364
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1281
}
1365
}
1282
1366
1367
///
1368
/// \brief Processes a HNA message following RFC 3626 specification.
1369
///
1370
/// The Host Network Association Set is updated (if needed) with the information
1371
/// of the received HNA message.
1372
///
1373
/// \param msg the %OLSR message which contains the HNA message.
1374
/// \param sender_iface the address of the interface where the message was sent from.
1375
///
1376
void
1377
RoutingProtocol::ProcessHna (const olsr::MessageHeader &msg,
1378
                       const Ipv4Address &senderIface)
1379
{
1380
1381
  const olsr::MessageHeader::Hna &hna = msg.GetHna ();
1382
  Time now = Simulator::Now ();
1383
  
1384
  // 1. If the sender interface of this message is not in the symmetric
1385
  // 1-hop neighborhood of this node, the message MUST be discarded.
1386
  const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now);
1387
  if (link_tuple == NULL)
1388
    return;
1389
  
1390
  // 2. Otherwise, for each (network address, netmask) pair in the
1391
  // message:
1392
  
1393
  for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.associations.begin();
1394
       it != hna.associations.end() ; it++)
1395
    {
1396
      AssociationTuple *tuple = m_state.FindAssociationTuple(msg.GetOriginatorAddress(),it->address,it->mask);
1397
  
1398
      // 2.1  if an entry in the association set already exists, where:
1399
      //          A_gateway_addr == originator address
1400
      //          A_network_addr == network address
1401
      //          A_netmask      == netmask
1402
      //      then the holding time for that tuple MUST be set to:
1403
      //          A_time         =  current time + validity time
1404
      if(tuple != NULL)
1405
        {
1406
          tuple->expirationTime = now + msg.GetVTime ();
1407
        }
1408
        
1409
      // 2.2 otherwise, a new tuple MUST be recorded with:
1410
      //          A_gateway_addr =  originator address
1411
      //          A_network_addr =  network address
1412
      //          A_netmask      =  netmask
1413
      //          A_time         =  current time + validity time
1414
      else
1415
        {
1416
          const AssociationTuple &assocTuple = (AssociationTuple){msg.GetOriginatorAddress(),it->address,it->mask,now + msg.GetVTime ()};
1417
          
1418
          AddAssociationTuple (assocTuple);
1419
          
1420
          //Schedule Association Tuple deletion
1421
          Simulator::Schedule (DELAY (assocTuple.expirationTime),
1422
                               &RoutingProtocol::AssociationTupleTimerExpire, this,
1423
                               assocTuple.gatewayAddr,assocTuple.networkAddr,assocTuple.netmask);
1424
        }
1425
        
1426
    }
1427
}
1283
1428
1284
///
1429
///
1285
/// \brief OLSR's default forwarding algorithm.
1430
/// \brief OLSR's default forwarding algorithm.
 Lines 1447-1453    Link Here 
1447
RoutingProtocol::SendHello ()
1592
RoutingProtocol::SendHello ()
1448
{
1593
{
1449
  NS_LOG_FUNCTION (this);
1594
  NS_LOG_FUNCTION (this);
1450
  
1595
    
1451
  olsr::MessageHeader msg;
1596
  olsr::MessageHeader msg;
1452
  Time now = Simulator::Now ();
1597
  Time now = Simulator::Now ();
1453
1598
 Lines 1569-1574    Link Here 
1569
  
1714
  
1570
  olsr::MessageHeader::Tc &tc = msg.GetTc ();
1715
  olsr::MessageHeader::Tc &tc = msg.GetTc ();
1571
  tc.ansn = m_ansn;
1716
  tc.ansn = m_ansn;
1717
      
1572
  for (MprSelectorSet::const_iterator mprsel_tuple = m_state.GetMprSelectors ().begin();
1718
  for (MprSelectorSet::const_iterator mprsel_tuple = m_state.GetMprSelectors ().begin();
1573
       mprsel_tuple != m_state.GetMprSelectors ().end(); mprsel_tuple++)
1719
       mprsel_tuple != m_state.GetMprSelectors ().end(); mprsel_tuple++)
1574
    {
1720
    {
 Lines 1622-1627    Link Here 
1622
}
1768
}
1623
1769
1624
///
1770
///
1771
/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on.
1772
///
1773
void
1774
RoutingProtocol::SendHna ()
1775
{
1776
1777
  olsr::MessageHeader msg;
1778
1779
  msg.SetVTime (OLSR_HNA_HOLD_TIME);
1780
  msg.SetOriginatorAddress (m_mainAddress);
1781
  msg.SetTimeToLive (255);
1782
  msg.SetHopCount (0);
1783
  msg.SetMessageSequenceNumber (GetMessageSequenceNumber ());
1784
  olsr::MessageHeader::Hna &hna = msg.GetHna ();
1785
  
1786
  std::vector<olsr::MessageHeader::Hna::Association>
1787
    &associations = hna.associations;
1788
      
1789
  if (m_routingTableAssociation != 0)
1790
    {
1791
      // Add (NetworkAddr, Netmask) entries from Associated Routing Table to HNA message.
1792
      for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1793
        {
1794
          Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1795
          
1796
          std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1797
                  
1798
          if (ci != m_interfaceExclusions.end ())
1799
            {
1800
              olsr::MessageHeader::Hna::Association assoc = {route.GetDestNetwork (), route.GetDestNetworkMask ()};
1801
              associations.push_back(assoc);
1802
            }
1803
        }
1804
    }
1805
    
1806
  int size = associations.size ();
1807
1808
  // Add (NetworkAddr, Netmask) entries specified using AddHostNetworkAssociation () to HNA message.
1809
  for (Associations::const_iterator it = m_state.GetAssociations ().begin ();
1810
        it != m_state.GetAssociations ().end (); it++)
1811
    {
1812
      // Check if the entry has already been added from the Associated Routing Table
1813
      std::vector<olsr::MessageHeader::Hna::Association>::const_iterator ci = associations.begin ();
1814
      bool found = false;
1815
      for (int i = 0; i < size; i++)
1816
        {
1817
          if (it->networkAddr == ci->address && it->netmask == ci->mask)
1818
            {
1819
              found = true;
1820
              break;
1821
            }
1822
          ci++;
1823
        }
1824
      
1825
      if(!found)
1826
        {
1827
          olsr::MessageHeader::Hna::Association assoc = {it->networkAddr,it->netmask};
1828
          associations.push_back(assoc);
1829
        }
1830
    }
1831
    
1832
  if(associations.size () == 0)
1833
    return;
1834
  
1835
  QueueMessage (msg, JITTER);
1836
}
1837
1838
///
1839
/// \brief Injects a (networkAddr, netmask) tuple for which the node
1840
///        can generate an HNA message for
1841
///
1842
void
1843
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1844
{
1845
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1846
}
1847
1848
///
1849
/// \brief Adds an Ipv4StaticRouting protocol Association
1850
///        can generate an HNA message for
1851
///
1852
void
1853
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1854
{
1855
  m_routingTableAssociation = routingTable;
1856
}
1857
1858
///
1625
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1859
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1626
///		specification). Neighbor Set is also updated if needed.
1860
///		specification). Neighbor Set is also updated if needed.
1627
void
1861
void
 Lines 2301-2306    Link Here 
2301
  m_state.EraseIfaceAssocTuple (tuple);
2535
  m_state.EraseIfaceAssocTuple (tuple);
2302
}
2536
}
2303
2537
2538
///
2539
/// \brief Adds a host network association tuple to the Association Set.
2540
/// \param tuple the host network association tuple to be added.
2541
///
2542
void
2543
RoutingProtocol::AddAssociationTuple (const AssociationTuple &tuple)
2544
{
2545
  m_state.InsertAssociationTuple (tuple);
2546
}
2547
2548
///
2549
/// \brief Removes a host network association tuple from the Association Set.
2550
/// \param tuple the host network association tuple to be removed.
2551
///
2552
void
2553
RoutingProtocol::RemoveAssociationTuple (const AssociationTuple &tuple)
2554
{
2555
  m_state.EraseAssociationTuple (tuple);
2556
}
2557
2558
2304
2559
2305
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2560
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2306
{
2561
{
 Lines 2358-2363    Link Here 
2358
}
2613
}
2359
2614
2360
///
2615
///
2616
/// \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
2617
/// \param e The event which has expired.
2618
///
2619
void
2620
RoutingProtocol::HnaTimerExpire ()
2621
{
2622
  if (m_state.GetAssociations ().size () > 0 || m_routingTableAssociation !=0)
2623
    {
2624
      SendHna ();
2625
    }
2626
  else
2627
    {
2628
      NS_LOG_DEBUG ("Not sending any HNA, no associations to advertise.");
2629
    }
2630
  m_hnaTimer.Schedule (m_hnaInterval);
2631
}
2632
2633
///
2361
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2634
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2362
///
2635
///
2363
/// The task of actually removing the tuple is left to the OLSR agent.
2636
/// The task of actually removing the tuple is left to the OLSR agent.
 Lines 2537-2542    Link Here 
2537
    }
2810
    }
2538
}
2811
}
2539
2812
2813
/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time().
2814
/// \warning Actually this is never invoked because there is no support for mixed interfaces.
2815
/// \param e The event which has expired.
2816
///
2817
void
2818
RoutingProtocol::AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
2819
{
2820
  AssociationTuple *tuple = m_state.FindAssociationTuple (gatewayAddr, networkAddr, netmask);
2821
  if (tuple == NULL)
2822
    {
2823
      return;
2824
    }
2825
  if (tuple->expirationTime < Simulator::Now ())
2826
    {
2827
      RemoveAssociationTuple (*tuple);
2828
    }
2829
  else
2830
    {
2831
      m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime),
2832
                                           &RoutingProtocol::AssociationTupleTimerExpire,
2833
                                           this, gatewayAddr, networkAddr, netmask));
2834
    }
2835
}
2836
2540
///
2837
///
2541
/// \brief Clears the routing table and frees the memory assigned to each one of its entries.
2838
/// \brief Clears the routing table and frees the memory assigned to each one of its entries.
2542
///
2839
///
 Lines 2612-2617    Link Here 
2612
  NS_LOG_FUNCTION (this << " " << m_ipv4->GetObject<Node> ()->GetId() << " " << header.GetDestination () << " " << oif);
2909
  NS_LOG_FUNCTION (this << " " << m_ipv4->GetObject<Node> ()->GetId() << " " << header.GetDestination () << " " << oif);
2613
  Ptr<Ipv4Route> rtentry;
2910
  Ptr<Ipv4Route> rtentry;
2614
  RoutingTableEntry entry1, entry2;
2911
  RoutingTableEntry entry1, entry2;
2912
  bool found = false;
2913
  
2615
  if (Lookup (header.GetDestination (), entry1) != 0)
2914
  if (Lookup (header.GetDestination (), entry1) != 0)
2616
    {
2915
    {
2617
      bool foundSendEntry = FindSendEntry (entry1, entry2);
2916
      bool foundSendEntry = FindSendEntry (entry1, entry2);
 Lines 2654-2663    Link Here 
2654
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2953
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2655
                    << ": RouteOutput for dest=" << header.GetDestination ()
2954
                    << ": RouteOutput for dest=" << header.GetDestination ()
2656
                    << " --> nextHop=" << entry2.nextAddr
2955
                    << " --> nextHop=" << entry2.nextAddr
2657
                    << " interface=" << entry2.interface);      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2956
                    << " interface=" << entry2.interface);
2957
      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2958
      found = true;
2658
    }
2959
    }
2659
  else
2960
  else
2660
    { 
2961
    { 
2962
      rtentry = m_hnaRoutingTable->RouteOutput (p, header, oif, sockerr);
2963
      
2964
      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2965
      
2966
      if (rtentry)
2967
        found = true;
2968
    }
2969
    
2970
  if (!found)
2971
    {
2661
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2972
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2662
                    << ": RouteOutput for dest=" << header.GetDestination ()
2973
                    << ": RouteOutput for dest=" << header.GetDestination ()
2663
                    << " No route to host");
2974
                    << " No route to host");
 Lines 2729-2746    Link Here 
2729
    }
3040
    }
2730
  else
3041
  else
2731
    {
3042
    {
3043
      if(m_hnaRoutingTable->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
3044
        {
3045
          return true;
3046
        }
3047
      else
3048
        {
3049
        
2732
#ifdef NS3_LOG_ENABLE
3050
#ifdef NS3_LOG_ENABLE
2733
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
3051
          NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2734
                    << ": RouteInput for dest=" << header.GetDestination ()
3052
                    << ": RouteInput for dest=" << header.GetDestination ()
2735
                    << " --> NOT FOUND; ** Dumping routing table...");      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
3053
                    << " --> NOT FOUND; ** Dumping routing table...");      
2736
           iter != m_table.end (); iter++)
3054
                    
2737
        {           NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
3055
          for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
3056
             iter != m_table.end (); iter++)
3057
          { 
3058
            NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
2738
                        << " via interface " << iter->second.interface);
3059
                        << " via interface " << iter->second.interface);
3060
          }
3061
      
3062
          NS_LOG_DEBUG ("** Routing table dump end.");
3063
#endif // NS3_LOG_ENABLE
3064
3065
          return false;
2739
        }
3066
        }
2740
      
2741
      NS_LOG_DEBUG ("** Routing table dump end.");
2742
#endif // NS3_LOG_ENABLE
2743
      return false;
2744
    }
3067
    }
2745
}
3068
}
2746
void 
3069
void 
(-)a/src/routing/olsr/olsr-routing-protocol.h (+31 lines)
 Lines 38-43    Link Here 
38
#include "ns3/traced-callback.h"
38
#include "ns3/traced-callback.h"
39
#include "ns3/ipv4.h"
39
#include "ns3/ipv4.h"
40
#include "ns3/ipv4-routing-protocol.h"
40
#include "ns3/ipv4-routing-protocol.h"
41
#include "ns3/ipv4-static-routing.h"
41
42
42
#include <vector>
43
#include <vector>
43
#include <map>
44
#include <map>
 Lines 105-115    Link Here 
105
   **/
106
   **/
106
  std::vector<RoutingTableEntry> GetRoutingTableEntries () const;
107
  std::vector<RoutingTableEntry> GetRoutingTableEntries () const;
107
108
109
private:
110
  std::set<uint32_t> m_interfaceExclusions;
111
  Ptr<Ipv4StaticRouting> m_routingTableAssociation;
112
113
public:
114
  std::set<uint32_t> GetInterfaceExclusions () const
115
    {
116
      return m_interfaceExclusions;
117
    }
118
  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
119
120
  /// Inject Association to be sent in HNA message
121
  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
122
123
  /// Inject Associations from an Ipv4StaticRouting instance
124
  void SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable);
125
108
protected:
126
protected:
109
  virtual void DoStart (void);
127
  virtual void DoStart (void);
110
private:
128
private:
111
  std::map<Ipv4Address, RoutingTableEntry> m_table; ///< Data structure for the routing table.
129
  std::map<Ipv4Address, RoutingTableEntry> m_table; ///< Data structure for the routing table.
112
130
131
  Ptr<Ipv4StaticRouting> m_hnaRoutingTable;
132
113
  EventGarbageCollector m_events;
133
  EventGarbageCollector m_events;
114
134
115
  /// Address of the routing agent.
135
  /// Address of the routing agent.
 Lines 128-133    Link Here 
128
  Time m_tcInterval;
148
  Time m_tcInterval;
129
  /// MID messages' emission interval.
149
  /// MID messages' emission interval.
130
  Time m_midInterval;
150
  Time m_midInterval;
151
  /// HNA messages' emission interval.
152
  Time m_hnaInterval;
131
  /// Willingness for forwarding packets on behalf of other nodes.
153
  /// Willingness for forwarding packets on behalf of other nodes.
132
  uint8_t m_willingness;
154
  uint8_t m_willingness;
133
	
155
	
 Lines 189-194    Link Here 
189
  Timer m_midTimer;
211
  Timer m_midTimer;
190
  void MidTimerExpire ();
212
  void MidTimerExpire ();
191
213
214
  Timer m_hnaTimer;
215
  void HnaTimerExpire ();
216
192
  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
217
  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
193
  bool m_linkTupleTimerFirstTime;
218
  bool m_linkTupleTimerFirstTime;
194
  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
219
  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
 Lines 196-201    Link Here 
196
  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
221
  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
197
  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
222
  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
198
  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
223
  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
224
  void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask);
199
225
200
  void IncrementAnsn ();
226
  void IncrementAnsn ();
201
227
 Lines 212-217    Link Here 
212
  void SendHello ();
238
  void SendHello ();
213
  void SendTc ();
239
  void SendTc ();
214
  void SendMid ();
240
  void SendMid ();
241
  void SendHna ();
215
242
216
  void NeighborLoss (const LinkTuple &tuple);
243
  void NeighborLoss (const LinkTuple &tuple);
217
  void AddDuplicateTuple (const DuplicateTuple &tuple);
244
  void AddDuplicateTuple (const DuplicateTuple &tuple);
 Lines 229-234    Link Here 
229
  void RemoveTopologyTuple (const TopologyTuple &tuple);
256
  void RemoveTopologyTuple (const TopologyTuple &tuple);
230
  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
257
  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
231
  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
258
  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
259
  void AddAssociationTuple (const AssociationTuple &tuple);
260
  void RemoveAssociationTuple (const AssociationTuple &tuple);
232
261
233
  void ProcessHello (const olsr::MessageHeader &msg,
262
  void ProcessHello (const olsr::MessageHeader &msg,
234
                     const Ipv4Address &receiverIface,
263
                     const Ipv4Address &receiverIface,
 Lines 237-242    Link Here 
237
                  const Ipv4Address &senderIface);
266
                  const Ipv4Address &senderIface);
238
  void ProcessMid (const olsr::MessageHeader &msg,
267
  void ProcessMid (const olsr::MessageHeader &msg,
239
                   const Ipv4Address &senderIface);
268
                   const Ipv4Address &senderIface);
269
  void ProcessHna (const olsr::MessageHeader &msg,
270
                   const Ipv4Address &senderIface);
240
271
241
  void LinkSensing (const olsr::MessageHeader &msg,
272
  void LinkSensing (const olsr::MessageHeader &msg,
242
                    const olsr::MessageHeader::Hello &hello,
273
                    const olsr::MessageHeader::Hello &hello,
(-)a/src/routing/olsr/olsr-state.cc (+56 lines)
 Lines 487-490    Link Here 
487
  return retval;
487
  return retval;
488
}
488
}
489
489
490
/********** Host-Network Association Set Manipulation **********/
491
492
AssociationTuple*
493
OlsrState::FindAssociationTuple (const Ipv4Address &gatewayAddr, const Ipv4Address &networkAddr, const Ipv4Mask &netmask)
494
{
495
  for (AssociationSet::iterator it = m_associationSet.begin ();
496
	it != m_associationSet.end (); it++)
497
    {
498
      if (it->gatewayAddr == gatewayAddr and it->networkAddr == networkAddr and it->netmask == netmask)
499
        {
500
          return &(*it);
501
        }
502
    }
503
   return NULL;
504
}
505
506
void
507
OlsrState::EraseAssociationTuple (const AssociationTuple &tuple)
508
{
509
  for (AssociationSet::iterator it = m_associationSet.begin ();
510
       it != m_associationSet.end (); it++)
511
    {
512
      if (*it == tuple)
513
        {
514
          m_associationSet.erase (it);
515
          break;
516
        }
517
    }
518
}
519
520
void
521
OlsrState::InsertAssociationTuple (const AssociationTuple &tuple)
522
{
523
  m_associationSet.push_back (tuple);
524
}
525
526
void
527
OlsrState::EraseAssociation (const Association &tuple)
528
{
529
  for (Associations::iterator it = m_associations.begin ();
530
       it != m_associations.end (); it++)
531
    {
532
      if (*it == tuple)
533
        {
534
          m_associations.erase (it);
535
          break;
536
        }
537
    }
538
}
539
540
void
541
OlsrState::InsertAssociation (const Association &tuple)
542
{
543
  m_associations.push_back(tuple);
544
}
545
490
} // namespace ns3
546
} // namespace ns3
(-)a/src/routing/olsr/olsr-state.h (+21 lines)
 Lines 45-50    Link Here 
45
  MprSelectorSet m_mprSelectorSet;	///< MPR Selector Set (RFC 3626, section 4.3.4).
45
  MprSelectorSet m_mprSelectorSet;	///< MPR Selector Set (RFC 3626, section 4.3.4).
46
  DuplicateSet m_duplicateSet;	///< Duplicate Set (RFC 3626, section 3.4).
46
  DuplicateSet m_duplicateSet;	///< Duplicate Set (RFC 3626, section 3.4).
47
  IfaceAssocSet m_ifaceAssocSet;	///< Interface Association Set (RFC 3626, section 4.1).
47
  IfaceAssocSet m_ifaceAssocSet;	///< Interface Association Set (RFC 3626, section 4.1).
48
  AssociationSet m_associationSet; ///<	Association Set (RFC 3626, section12.2). Associations obtained from HNA messages generated by other nodes.
49
  Associations m_associations;	///< The node's local Host Network Associations that will be advertised using HNA messages.
48
50
49
public:
51
public:
50
52
 Lines 147-152    Link Here 
147
  void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple);
149
  void EraseIfaceAssocTuple (const IfaceAssocTuple &tuple);
148
  void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple);
150
  void InsertIfaceAssocTuple (const IfaceAssocTuple &tuple);
149
151
152
  // Host-Network Association
153
  const AssociationSet & GetAssociationSet () const  // Associations known to the node
154
  {
155
    return m_associationSet;
156
  }
157
158
  const Associations & GetAssociations () const  // Set of associations that the node has
159
  {
160
    return m_associations;
161
  }
162
163
  AssociationTuple* FindAssociationTuple (const Ipv4Address &gatewayAddr,\
164
					  const Ipv4Address &networkAddr,\
165
					  const Ipv4Mask &netmask);
166
  void EraseAssociationTuple (const AssociationTuple &tuple);
167
  void InsertAssociationTuple (const AssociationTuple &tuple);
168
  void EraseAssociation (const Association &tuple);
169
  void InsertAssociation (const Association &tuple);
170
150
  // Returns a vector of all interfaces of a given neighbor, with the
171
  // Returns a vector of all interfaces of a given neighbor, with the
151
  // exception of the "main" one.
172
  // exception of the "main" one.
152
  std::vector<Ipv4Address>
173
  std::vector<Ipv4Address>

Return to bug 407