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

(-)a/src/helper/olsr-helper.cc (+27 lines)
 Lines 33-38    Link Here 
33
OlsrHelper::OlsrHelper (const OlsrHelper &o)
33
OlsrHelper::OlsrHelper (const OlsrHelper &o)
34
  : m_agentFactory (o.m_agentFactory)
34
  : m_agentFactory (o.m_agentFactory)
35
{
35
{
36
  m_interfaceExclusions = o.m_interfaceExclusions;
36
}
37
}
37
38
38
OlsrHelper* 
39
OlsrHelper* 
 Lines 41-50    Link Here 
41
  return new OlsrHelper (*this); 
42
  return new OlsrHelper (*this); 
42
}
43
}
43
44
45
void
46
OlsrHelper::ExcludeInterface (Ptr<Node> node, uint32_t interface)
47
{
48
  std::map< Ptr<Node>, std::set<uint32_t> >::iterator it = m_interfaceExclusions.find (node);
49
50
  if(it == m_interfaceExclusions.end ())
51
    {
52
      std::set<uint32_t> interfaces;
53
      interfaces.insert (interface);
54
    
55
      m_interfaceExclusions.insert (std::make_pair (node, std::set<uint32_t> (interfaces) ));
56
    }
57
  else
58
    {
59
      it->second.insert (interface);
60
    }
61
}
62
44
Ptr<Ipv4RoutingProtocol> 
63
Ptr<Ipv4RoutingProtocol> 
45
OlsrHelper::Create (Ptr<Node> node) const
64
OlsrHelper::Create (Ptr<Node> node) const
46
{
65
{
47
  Ptr<olsr::RoutingProtocol> agent = m_agentFactory.Create<olsr::RoutingProtocol> ();
66
  Ptr<olsr::RoutingProtocol> agent = m_agentFactory.Create<olsr::RoutingProtocol> ();
67
68
  std::map<Ptr<Node>, std::set<uint32_t> >::const_iterator it = m_interfaceExclusions.find (node);
69
70
  if(it != m_interfaceExclusions.end ())
71
    {
72
      agent->SetInterfaceExclusions (it->second);
73
    }
74
48
  node->AggregateObject (agent);
75
  node->AggregateObject (agent);
49
  return agent;
76
  return agent;
50
}
77
}
(-)a/src/helper/olsr-helper.h (+13 lines)
 Lines 24-29    Link Here 
24
#include "ns3/node.h"
24
#include "ns3/node.h"
25
#include "node-container.h"
25
#include "node-container.h"
26
#include "ipv4-routing-helper.h"
26
#include "ipv4-routing-helper.h"
27
#include <map>
28
#include <set>
27
29
28
namespace ns3 {
30
namespace ns3 {
29
31
 Lines 57-62    Link Here 
57
   */
59
   */
58
  OlsrHelper* Copy (void) const;
60
  OlsrHelper* Copy (void) const;
59
61
62
 /**
63
   * \param node the node for which an exception is to be defined
64
   * \param interface an interface of node on which OLSR is not to be installed
65
   *
66
   * This method allows the user to specify an interface on which OLSR is not to be installed on
67
   */
68
  void ExcludeInterface (Ptr<Node> node, uint32_t interface);
69
60
  /**
70
  /**
61
   * \param node the node on which the routing protocol will run
71
   * \param node the node on which the routing protocol will run
62
   * \returns a newly-created routing protocol
72
   * \returns a newly-created routing protocol
 Lines 72-77    Link Here 
72
   * This method controls the attributes of ns3::olsr::RoutingProtocol
82
   * This method controls the attributes of ns3::olsr::RoutingProtocol
73
   */
83
   */
74
  void Set (std::string name, const AttributeValue &value);
84
  void Set (std::string name, const AttributeValue &value);
85
75
private:
86
private:
76
  /**
87
  /**
77
   * \internal
88
   * \internal
 Lines 80-85    Link Here 
80
   */
91
   */
81
  OlsrHelper &operator = (const OlsrHelper &o);
92
  OlsrHelper &operator = (const OlsrHelper &o);
82
  ObjectFactory m_agentFactory;
93
  ObjectFactory m_agentFactory;
94
95
  std::map< Ptr<Node>, std::set<uint32_t> > m_interfaceExclusions;
83
};
96
};
84
97
85
} // namespace ns3
98
} // namespace ns3
(-)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 (-14 / +283 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 189-194    Link Here 
189
    m_helloTimer (Timer::CANCEL_ON_DESTROY),
195
    m_helloTimer (Timer::CANCEL_ON_DESTROY),
190
    m_tcTimer (Timer::CANCEL_ON_DESTROY),
196
    m_tcTimer (Timer::CANCEL_ON_DESTROY),
191
    m_midTimer (Timer::CANCEL_ON_DESTROY),
197
    m_midTimer (Timer::CANCEL_ON_DESTROY),
198
    m_hnaTimer (Timer::CANCEL_ON_DESTROY),    
192
    m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY)
199
    m_queuedMessagesTimer (Timer::CANCEL_ON_DESTROY)
193
{}
200
{}
194
201
 Lines 204-209    Link Here 
204
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
211
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
205
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
212
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
206
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
213
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
214
  m_hnaTimer.SetFunction (&RoutingProtocol::HnaTimerExpire, this);
207
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
215
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
208
216
209
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
217
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
 Lines 213-218    Link Here 
213
  m_linkTupleTimerFirstTime = true;
221
  m_linkTupleTimerFirstTime = true;
214
222
215
  m_ipv4 = ipv4;
223
  m_ipv4 = ipv4;
224
  
225
  HnaRoutingTable.SetIpv4 (ipv4);
216
}
226
}
217
227
218
void RoutingProtocol::DoDispose ()
228
void RoutingProtocol::DoDispose ()
 Lines 251-256    Link Here 
251
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
261
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
252
262
253
  Ipv4Address loopback ("127.0.0.1");
263
  Ipv4Address loopback ("127.0.0.1");
264
265
  bool canRunOlsr = false;
254
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
266
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
255
    {
267
    {
256
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
268
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
 Lines 269-274    Link Here 
269
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
281
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
270
        }
282
        }
271
283
284
      if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ())
285
        continue;
286
272
      // Create a socket to listen only on this interface
287
      // Create a socket to listen only on this interface
273
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
288
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
274
        UdpSocketFactory::GetTypeId()); 
289
        UdpSocketFactory::GetTypeId()); 
 Lines 279-291    Link Here 
279
        }
294
        }
280
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
295
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
281
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
296
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
297
298
      canRunOlsr = true;
282
    }
299
    }
283
300
284
  HelloTimerExpire ();
301
  if(canRunOlsr)
285
  TcTimerExpire ();
302
   {
286
  MidTimerExpire ();
303
      HelloTimerExpire ();
304
      TcTimerExpire ();
305
      MidTimerExpire ();
306
      HnaTimerExpire ();      
287
307
288
  NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
308
      NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
309
   }
289
}
310
}
290
311
291
void RoutingProtocol::SetMainInterface (uint32_t interface)
312
void RoutingProtocol::SetMainInterface (uint32_t interface)
 Lines 293-298    Link Here 
293
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
314
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
294
}
315
}
295
316
317
void RoutingProtocol::SetInterfaceExclusions (std::set<uint32_t> exceptions)
318
{
319
  m_interfaceExclusions = exceptions;
320
}
296
321
297
//
322
//
298
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
323
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
 Lines 397-402    Link Here 
397
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
422
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
398
              ProcessMid (messageHeader, senderIfaceAddr);
423
              ProcessMid (messageHeader, senderIfaceAddr);
399
              break;
424
              break;
425
            case olsr::MessageHeader::HNA_MESSAGE:
426
              NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
427
                            << "s OLSR node " << m_mainAddress
428
                            <<  " received HNA message of size " << messageHeader.GetSerializedSize ());
429
              ProcessHna (messageHeader, senderIfaceAddr);
430
              break; 
400
431
401
            default:
432
            default:
402
              NS_LOG_DEBUG ("OLSR message type " <<
433
              NS_LOG_DEBUG ("OLSR message type " <<
 Lines 1039-1044    Link Here 
1039
        }
1070
        }
1040
    }
1071
    }
1041
1072
1073
  // 5. For each tuple in the association set,
1074
  //    If there is no entry in the routing table with:
1075
  //        R_dest_addr     == A_network_addr/A_netmask
1076
  //   then a new routing entry is created.
1077
  const AssociationSet &associationSet = m_state.GetAssociationSet ();
1078
  for (AssociationSet::const_iterator it = associationSet.begin ();
1079
       it != associationSet.end (); it++)
1080
    {
1081
      AssociationTuple const &tuple = *it;
1082
      RoutingTableEntry gateway_entry;
1083
      
1084
      bool have_gateway_entry = Lookup (tuple.gatewayAddr, gateway_entry);
1085
      bool to_add = false;
1086
      
1087
      uint32_t route_index = 0;
1088
      
1089
      for (route_index = 0; route_index < HnaRoutingTable.GetNRoutes (); route_index++)
1090
            {
1091
              Ipv4RoutingTableEntry route = HnaRoutingTable.GetRoute (route_index);
1092
              if (route.GetDestNetwork () == tuple.networkAddr &&
1093
                  route.GetDestNetworkMask () == tuple.netmask)
1094
                {
1095
                  break;
1096
                }
1097
            }
1098
      
1099
      if (route_index == HnaRoutingTable.GetNRoutes ())
1100
        {
1101
          to_add = true;
1102
        }
1103
      else if(have_gateway_entry && HnaRoutingTable.GetMetric (route_index) > gateway_entry.distance)
1104
        {
1105
          HnaRoutingTable.RemoveRoute(route_index);
1106
          to_add = true;
1107
        }
1108
        
1109
      if(to_add && have_gateway_entry)
1110
        {
1111
          HnaRoutingTable.AddNetworkRouteTo (tuple.networkAddr,
1112
                                             tuple.netmask,
1113
                                             gateway_entry.nextAddr,
1114
                                             gateway_entry.interface,
1115
                                             gateway_entry.distance);
1116
                                             
1117
        }
1118
    }
1119
1042
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1120
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1043
  m_routingTableChanged (GetSize ());
1121
  m_routingTableChanged (GetSize ());
1044
}
1122
}
 Lines 1280-1285    Link Here 
1280
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1358
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1281
}
1359
}
1282
1360
1361
///
1362
/// \brief Processes a HNA message following RFC 3626 specification.
1363
///
1364
/// The Host Network Association Set is updated (if needed) with the information
1365
/// of the received HNA message.
1366
///
1367
/// \param msg the %OLSR message which contains the HNA message.
1368
/// \param sender_iface the address of the interface where the message was sent from.
1369
///
1370
void
1371
RoutingProtocol::ProcessHna (const olsr::MessageHeader &msg,
1372
                       const Ipv4Address &senderIface)
1373
{
1374
1375
  const olsr::MessageHeader::Hna &hna = msg.GetHna ();
1376
  Time now = Simulator::Now ();
1377
  
1378
  // 1. If the sender interface of this message is not in the symmetric
1379
  // 1-hop neighborhood of this node, the message MUST be discarded.
1380
  const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now);
1381
  if (link_tuple == NULL)
1382
    return;
1383
  
1384
  // 2. Otherwise, for each (network address, netmask) pair in the
1385
  // message:
1386
  
1387
  for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.associations.begin();
1388
       it != hna.associations.end() ; it++)
1389
    {
1390
      AssociationTuple *tuple = m_state.FindAssociationTuple(msg.GetOriginatorAddress(),it->address,it->mask);
1391
  
1392
      // 2.1  if an entry in the association set already exists, where:
1393
      //          A_gateway_addr == originator address
1394
      //          A_network_addr == network address
1395
      //          A_netmask      == netmask
1396
      //      then the holding time for that tuple MUST be set to:
1397
      //          A_time         =  current time + validity time
1398
      if(tuple != NULL)
1399
        {
1400
          tuple->expirationTime = now + msg.GetVTime ();
1401
        }
1402
        
1403
      // 2.2 otherwise, a new tuple MUST be recorded with:
1404
      //          A_gateway_addr =  originator address
1405
      //          A_network_addr =  network address
1406
      //          A_netmask      =  netmask
1407
      //          A_time         =  current time + validity time
1408
      else
1409
        {
1410
          const AssociationTuple &assocTuple = (AssociationTuple){msg.GetOriginatorAddress(),it->address,it->mask,now + msg.GetVTime ()};
1411
          
1412
          AddAssociationTuple (assocTuple);
1413
          
1414
          //Schedule Association Tuple deletion
1415
          Simulator::Schedule (DELAY (assocTuple.expirationTime),
1416
                               &RoutingProtocol::AssociationTupleTimerExpire, this,
1417
                               assocTuple.gatewayAddr,assocTuple.networkAddr,assocTuple.netmask);
1418
        }
1419
        
1420
    }
1421
}
1283
1422
1284
///
1423
///
1285
/// \brief OLSR's default forwarding algorithm.
1424
/// \brief OLSR's default forwarding algorithm.
 Lines 1622-1627    Link Here 
1622
}
1761
}
1623
1762
1624
///
1763
///
1764
/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on.
1765
///
1766
void
1767
RoutingProtocol::SendHna ()
1768
{
1769
1770
  olsr::MessageHeader msg;
1771
1772
  msg.SetVTime (OLSR_HNA_HOLD_TIME);
1773
  msg.SetOriginatorAddress (m_mainAddress);
1774
  msg.SetTimeToLive (255);
1775
  msg.SetHopCount (0);
1776
  msg.SetMessageSequenceNumber (GetMessageSequenceNumber ());
1777
  olsr::MessageHeader::Hna &hna = msg.GetHna ();
1778
  
1779
  std::vector<olsr::MessageHeader::Hna::Association>
1780
    &associations = hna.associations;
1781
1782
  // Pack all host-network associations into the packet's associations vector
1783
  for (Associations::const_iterator it = m_state.GetAssociations ().begin ();
1784
        it != m_state.GetAssociations ().end (); it++)
1785
    {
1786
      associations.push_back((olsr::MessageHeader::Hna::Association){it->networkAddr,it->netmask});
1787
    }
1788
    
1789
  if(associations.size () == 0)
1790
    return;
1791
  
1792
  QueueMessage (msg, JITTER);
1793
}
1794
1795
1796
///
1797
/// \brief Injects a (networkAddr, netmask) tuple for which the node
1798
///        can generate an HNA message for
1799
///
1800
void
1801
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1802
{
1803
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1804
}
1805
1806
///
1807
1808
1809
///
1625
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1810
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1626
///		specification). Neighbor Set is also updated if needed.
1811
///		specification). Neighbor Set is also updated if needed.
1627
void
1812
void
 Lines 2301-2306    Link Here 
2301
  m_state.EraseIfaceAssocTuple (tuple);
2486
  m_state.EraseIfaceAssocTuple (tuple);
2302
}
2487
}
2303
2488
2489
///
2490
/// \brief Adds a host network association tuple to the Association Set.
2491
///
2492
/// \param tuple the host network association tuple to be added.
2493
///
2494
void
2495
RoutingProtocol::AddAssociationTuple (const AssociationTuple &tuple)
2496
{
2497
  m_state.InsertAssociationTuple (tuple);
2498
}
2499
2500
///
2501
/// \brief Removes a host network association tuple from the Association Set.
2502
///
2503
/// \param tuple the host network association tuple to be removed.
2504
///
2505
void
2506
RoutingProtocol::RemoveAssociationTuple (const AssociationTuple &tuple)
2507
{
2508
  m_state.EraseAssociationTuple (tuple);
2509
}
2510
2511
2304
2512
2305
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2513
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2306
{
2514
{
 Lines 2357-2362    Link Here 
2357
  m_midTimer.Schedule (m_midInterval);
2565
  m_midTimer.Schedule (m_midInterval);
2358
}
2566
}
2359
2567
2568
/// \brief Sends an HNA message (if the node implements support for non-OLSR interfaces).
2569
/// \warning Currently it does nothing because there is no support for mixed interfaces.
2570
/// \param e The event which has expired.
2571
///
2572
void
2573
RoutingProtocol::HnaTimerExpire ()
2574
{
2575
  SendHna ();
2576
  m_hnaTimer.Schedule (m_hnaInterval);
2577
}
2578
2360
///
2579
///
2361
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2580
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2362
///
2581
///
 Lines 2537-2542    Link Here 
2537
    }
2756
    }
2538
}
2757
}
2539
2758
2759
/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time().
2760
/// \warning Actually this is never invoked because there is no support for mixed interfaces.
2761
/// \param e The event which has expired.
2762
///
2763
void
2764
RoutingProtocol::AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask)
2765
{
2766
  AssociationTuple *tuple = m_state.FindAssociationTuple (gatewayAddr, networkAddr, netmask);
2767
  if (tuple == NULL)
2768
    {
2769
      return;
2770
    }
2771
  if (tuple->expirationTime < Simulator::Now ())
2772
    {
2773
      RemoveAssociationTuple (*tuple);
2774
    }
2775
  else
2776
    {
2777
      m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime),
2778
                                           &RoutingProtocol::AssociationTupleTimerExpire,
2779
                                           this, gatewayAddr, networkAddr, netmask));
2780
    }
2781
}
2782
2540
///
2783
///
2541
/// \brief Clears the routing table and frees the memory assigned to each one of its entries.
2784
/// \brief Clears the routing table and frees the memory assigned to each one of its entries.
2542
///
2785
///
 Lines 2612-2617    Link Here 
2612
  NS_LOG_FUNCTION (this << " " << m_ipv4->GetObject<Node> ()->GetId() << " " << header.GetDestination () << " " << oif);
2855
  NS_LOG_FUNCTION (this << " " << m_ipv4->GetObject<Node> ()->GetId() << " " << header.GetDestination () << " " << oif);
2613
  Ptr<Ipv4Route> rtentry;
2856
  Ptr<Ipv4Route> rtentry;
2614
  RoutingTableEntry entry1, entry2;
2857
  RoutingTableEntry entry1, entry2;
2858
  bool found = false;
2859
  
2615
  if (Lookup (header.GetDestination (), entry1) != 0)
2860
  if (Lookup (header.GetDestination (), entry1) != 0)
2616
    {
2861
    {
2617
      bool foundSendEntry = FindSendEntry (entry1, entry2);
2862
      bool foundSendEntry = FindSendEntry (entry1, entry2);
 Lines 2654-2663    Link Here 
2654
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2899
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2655
                    << ": RouteOutput for dest=" << header.GetDestination ()
2900
                    << ": RouteOutput for dest=" << header.GetDestination ()
2656
                    << " --> nextHop=" << entry2.nextAddr
2901
                    << " --> 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());
2902
                    << " interface=" << entry2.interface);
2903
      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2904
      found = true;
2658
    }
2905
    }
2659
  else
2906
  else
2660
    { 
2907
    { 
2908
      rtentry = HnaRoutingTable.RouteOutput (p, header, oif, sockerr);
2909
      
2910
      NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2911
      
2912
      if (rtentry)
2913
        found = true;
2914
    }
2915
    
2916
  if (!found)
2917
    {
2661
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2918
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2662
                    << ": RouteOutput for dest=" << header.GetDestination ()
2919
                    << ": RouteOutput for dest=" << header.GetDestination ()
2663
                    << " No route to host");
2920
                    << " No route to host");
 Lines 2729-2746    Link Here 
2729
    }
2986
    }
2730
  else
2987
  else
2731
    {
2988
    {
2989
      if(HnaRoutingTable.RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
2990
        {
2991
          return true;
2992
        }
2993
      else
2994
        {
2995
        
2732
#ifdef NS3_LOG_ENABLE
2996
#ifdef NS3_LOG_ENABLE
2733
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2997
          NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2734
                    << ": RouteInput for dest=" << header.GetDestination ()
2998
                    << ": RouteInput for dest=" << header.GetDestination ()
2735
                    << " --> NOT FOUND; ** Dumping routing table...");      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
2999
                    << " --> NOT FOUND; ** Dumping routing table...");      
2736
           iter != m_table.end (); iter++)
3000
                    
2737
        {           NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
3001
          for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
3002
             iter != m_table.end (); iter++)
3003
          { 
3004
            NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
2738
                        << " via interface " << iter->second.interface);
3005
                        << " via interface " << iter->second.interface);
3006
          }
3007
      
3008
          NS_LOG_DEBUG ("** Routing table dump end.");
3009
#endif // NS3_LOG_ENABLE
3010
3011
          return false;
2739
        }
3012
        }
2740
      
2741
      NS_LOG_DEBUG ("** Routing table dump end.");
2742
#endif // NS3_LOG_ENABLE
2743
      return false;
2744
    }
3013
    }
2745
}
3014
}
2746
void 
3015
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
112
public:
113
  std::set<uint32_t> GetInterfaceExclusions () const
114
    {
115
      return m_interfaceExclusions;
116
    }
117
  void SetInterfaceExclusions (std::set<uint32_t> exceptions);
118
108
protected:
119
protected:
109
  virtual void DoStart (void);
120
  virtual void DoStart (void);
110
private:
121
private:
111
  std::map<Ipv4Address, RoutingTableEntry> m_table; ///< Data structure for the routing table.
122
  std::map<Ipv4Address, RoutingTableEntry> m_table; ///< Data structure for the routing table.
112
123
124
  Ipv4StaticRouting HnaRoutingTable;
125
113
  EventGarbageCollector m_events;
126
  EventGarbageCollector m_events;
114
127
115
  /// Address of the routing agent.
128
  /// Address of the routing agent.
 Lines 128-133    Link Here 
128
  Time m_tcInterval;
141
  Time m_tcInterval;
129
  /// MID messages' emission interval.
142
  /// MID messages' emission interval.
130
  Time m_midInterval;
143
  Time m_midInterval;
144
  /// HNA messages' emission interval.
145
  Time m_hnaInterval;
131
  /// Willingness for forwarding packets on behalf of other nodes.
146
  /// Willingness for forwarding packets on behalf of other nodes.
132
  uint8_t m_willingness;
147
  uint8_t m_willingness;
133
	
148
	
 Lines 189-194    Link Here 
189
  Timer m_midTimer;
204
  Timer m_midTimer;
190
  void MidTimerExpire ();
205
  void MidTimerExpire ();
191
206
207
  Timer m_hnaTimer;
208
  void HnaTimerExpire ();
209
192
  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
210
  void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber);
193
  bool m_linkTupleTimerFirstTime;
211
  bool m_linkTupleTimerFirstTime;
194
  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
212
  void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr);
 Lines 196-201    Link Here 
196
  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
214
  void MprSelTupleTimerExpire (Ipv4Address mainAddr);
197
  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
215
  void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr);
198
  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
216
  void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr);
217
  void AssociationTupleTimerExpire (Ipv4Address gatewayAddr, Ipv4Address networkAddr, Ipv4Mask netmask);
199
218
200
  void IncrementAnsn ();
219
  void IncrementAnsn ();
201
220
 Lines 212-217    Link Here 
212
  void SendHello ();
231
  void SendHello ();
213
  void SendTc ();
232
  void SendTc ();
214
  void SendMid ();
233
  void SendMid ();
234
  void SendHna ();
215
235
216
  void NeighborLoss (const LinkTuple &tuple);
236
  void NeighborLoss (const LinkTuple &tuple);
217
  void AddDuplicateTuple (const DuplicateTuple &tuple);
237
  void AddDuplicateTuple (const DuplicateTuple &tuple);
 Lines 229-234    Link Here 
229
  void RemoveTopologyTuple (const TopologyTuple &tuple);
249
  void RemoveTopologyTuple (const TopologyTuple &tuple);
230
  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
250
  void AddIfaceAssocTuple (const IfaceAssocTuple &tuple);
231
  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
251
  void RemoveIfaceAssocTuple (const IfaceAssocTuple &tuple);
252
  void AddAssociationTuple (const AssociationTuple &tuple);
253
  void RemoveAssociationTuple (const AssociationTuple &tuple);
232
254
233
  void ProcessHello (const olsr::MessageHeader &msg,
255
  void ProcessHello (const olsr::MessageHeader &msg,
234
                     const Ipv4Address &receiverIface,
256
                     const Ipv4Address &receiverIface,
 Lines 237-242    Link Here 
237
                  const Ipv4Address &senderIface);
259
                  const Ipv4Address &senderIface);
238
  void ProcessMid (const olsr::MessageHeader &msg,
260
  void ProcessMid (const olsr::MessageHeader &msg,
239
                   const Ipv4Address &senderIface);
261
                   const Ipv4Address &senderIface);
262
  void ProcessHna (const olsr::MessageHeader &msg,
263
                   const Ipv4Address &senderIface);
240
264
241
  void LinkSensing (const olsr::MessageHeader &msg,
265
  void LinkSensing (const olsr::MessageHeader &msg,
242
                    const olsr::MessageHeader::Hello &hello,
266
                    const olsr::MessageHeader::Hello &hello,
 Lines 250-255    Link Here 
250
                               const olsr::MessageHeader::Hello &hello);
274
                               const olsr::MessageHeader::Hello &hello);
251
275
252
  int Degree (NeighborTuple const &tuple);
276
  int Degree (NeighborTuple const &tuple);
277
278
  /// Inject Association to be sent in HNA message
279
  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
280
281
  /// Inject Associations from an Ipv4StaticRouting instance
282
  void AddRoutingTableAssociation (Ptr<Ipv4StaticRouting>);
283
253
  /// Check that address is one of my interfaces
284
  /// Check that address is one of my interfaces
254
  bool IsMyOwnAddress (const Ipv4Address & a) const;
285
  bool IsMyOwnAddress (const Ipv4Address & a) const;
255
286
(-)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, section 12.2)
49
  Associations m_associations;	///< The Host Network Associations of the node
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