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

(-)b5bc10de166d (+263 lines)
Added Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License version 2 as
6
 * published by the Free Software Foundation;
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License
14
 * along with this program; if not, write to the Free Software
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 *
17
 */
18
19
// 
20
// This script, adapted from examples/wireless/wifi-simple-adhoc illustrates
21
// the use of OLSR HNA.
22
// 
23
// Network Topology:
24
//
25
//             |------ OLSR ------|   |---- non-OLSR ----|
26
//           A ))))            (((( B ------------------- C
27
//           10.1.1.1     10.1.1.2   172.16.1.2     172.16.1.1
28
//
29
// Node A needs to send a UDP packet to node C. This can be done only after
30
// A receives an HNA message from B, in which B announces 172.16.1.0/24
31
// as an associated network.
32
//
33
// If no HNA message is generated by B, a will not be able to form a route to C.
34
// This can be verified as follows:
35
//
36
// ./waf --run olsr-hna
37
//
38
// There are two ways to make a node to generate HNA messages.
39
//
40
// One way is to use olsr::RoutingProtocol::SetRoutingTableAssociation ()
41
// to use which you may run:
42
//
43
// ./waf --run "olsr-hna --assocMethod1=1"
44
//
45
// The other way is to use olsr::RoutingProtocol::AddHostNetworkAssociation ()
46
// to use which you may run:
47
//
48
// ./waf --run "olsr-hna --assocMethod2=1"
49
//
50
51
#include "ns3/core-module.h"
52
#include "ns3/common-module.h"
53
#include "ns3/node-module.h"
54
#include "ns3/helper-module.h"
55
#include "ns3/mobility-module.h"
56
#include "ns3/contrib-module.h"
57
#include "ns3/wifi-module.h"
58
#include "ns3/ipv4-list-routing.h"
59
#include "ns3/olsr-routing-protocol.h"
60
61
#include <iostream>
62
#include <fstream>
63
#include <vector>
64
#include <string>
65
66
NS_LOG_COMPONENT_DEFINE ("OlsrHna");
67
68
using namespace ns3;
69
70
void ReceivePacket (Ptr<Socket> socket)
71
{
72
  NS_LOG_UNCOND ("Received one packet!");
73
}
74
75
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, 
76
                             uint32_t pktCount, Time pktInterval )
77
{
78
  if (pktCount > 0)
79
    {
80
      socket->Send (Create<Packet> (pktSize));
81
      Simulator::Schedule (pktInterval, &GenerateTraffic, 
82
                                      socket, pktSize,pktCount-1, pktInterval);
83
    }
84
  else
85
    {
86
      socket->Close ();
87
    }
88
}
89
90
91
int main (int argc, char *argv[])
92
{
93
  std::string phyMode ("wifib-1mbs");
94
  double rss = -80;  // -dBm
95
  uint32_t packetSize = 1000; // bytes
96
  uint32_t numPackets = 1;
97
  double interval = 1.0; // seconds
98
  bool verbose = false;
99
  bool assocMethod1 = false;
100
  bool assocMethod2 = false;
101
102
  CommandLine cmd;
103
104
  cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
105
  cmd.AddValue ("rss", "received signal strength", rss);
106
  cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
107
  cmd.AddValue ("numPackets", "number of packets generated", numPackets);
108
  cmd.AddValue ("interval", "interval (seconds) between packets", interval);
109
  cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
110
  cmd.AddValue ("assocMethod1", "Use SetRoutingTableAssociation () method", assocMethod1);
111
  cmd.AddValue ("assocMethod2", "Use AddHostNetworkAssociation () method", assocMethod2);
112
  
113
  cmd.Parse (argc, argv);
114
  // Convert to time object
115
  Time interPacketInterval = Seconds (interval);
116
117
  // disable fragmentation for frames below 2200 bytes
118
  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
119
  // turn off RTS/CTS for frames below 2200 bytes
120
  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
121
  // Fix non-unicast data rate to be the same as that of unicast
122
  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", 
123
                      StringValue (phyMode));
124
125
  NodeContainer olsrNodes;
126
  olsrNodes.Create (2);
127
128
  NodeContainer csmaNodes;
129
  csmaNodes.Create (1);
130
131
  // The below set of helpers will help us to put together the wifi NICs we want
132
  WifiHelper wifi;
133
  if (verbose)
134
    {
135
      wifi.EnableLogComponents ();  // Turn on all Wifi logging
136
    }
137
  wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
138
139
  YansWifiPhyHelper wifiPhy =  YansWifiPhyHelper::Default ();
140
  // This is one parameter that matters when using FixedRssLossModel
141
  // set it to zero; otherwise, gain will be added
142
  wifiPhy.Set ("RxGain", DoubleValue (0) ); 
143
  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
144
  wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
145
146
  YansWifiChannelHelper wifiChannel ;
147
  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
148
  // The below FixedRssLossModel will cause the rss to be fixed regardless
149
  // of the distance between the two stations, and the transmit power
150
  wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
151
  wifiPhy.SetChannel (wifiChannel.Create ());
152
153
  // Add a non-QoS upper mac, and disable rate control
154
  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
155
  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
156
                                "DataMode",StringValue(phyMode),
157
                                   "ControlMode",StringValue(phyMode));
158
  // Set it to adhoc mode
159
  wifiMac.SetType ("ns3::AdhocWifiMac");
160
  NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, olsrNodes);
161
162
  CsmaHelper csma;
163
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
164
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
165
  NetDeviceContainer csmaDevices = csma.Install (NodeContainer (csmaNodes.Get(0), olsrNodes.Get(1)));
166
167
  // Note that with FixedRssLossModel, the positions below are not 
168
  // used for received signal strength. 
169
  MobilityHelper mobility;
170
  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
171
  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
172
  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
173
  mobility.SetPositionAllocator (positionAlloc);
174
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
175
  mobility.Install (olsrNodes);
176
177
  OlsrHelper olsr;
178
179
  // Specify Node B's csma device as a non-OLSR device.
180
  olsr.ExcludeInterface (olsrNodes.Get (1), 2);
181
182
  Ipv4StaticRoutingHelper staticRouting;
183
184
  Ipv4ListRoutingHelper list;
185
  list.Add (staticRouting, 0);
186
  list.Add (olsr, 10);
187
188
  InternetStackHelper internet_olsr;
189
  internet_olsr.SetRoutingHelper (list);
190
  internet_olsr.Install (olsrNodes);
191
192
  InternetStackHelper internet_csma;
193
  internet_csma.Install (csmaNodes);
194
195
  Ipv4AddressHelper ipv4;
196
  NS_LOG_INFO ("Assign IP Addresses.");
197
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
198
  ipv4.Assign (devices);
199
200
  ipv4.SetBase ("172.16.1.0", "255.255.255.0");
201
  ipv4.Assign (csmaDevices);
202
203
  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
204
  Ptr<Socket> recvSink = Socket::CreateSocket (csmaNodes.Get(0), tid);
205
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
206
  recvSink->Bind (local);
207
  recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
208
209
  Ptr<Socket> source = Socket::CreateSocket (olsrNodes.Get (0), tid);
210
  InetSocketAddress remote = InetSocketAddress (Ipv4Address ("172.16.1.1"), 80);
211
  source->Connect (remote);
212
213
  // Obtain olsr::RoutingProtocol instance of gateway node
214
  // (namely, node B) and add the required association
215
  Ptr<Ipv4> stack = olsrNodes.Get (1) -> GetObject<Ipv4> ();
216
  Ptr<Ipv4RoutingProtocol> rp_Gw = (stack->GetRoutingProtocol ());
217
  Ptr<Ipv4ListRouting> lrp_Gw = DynamicCast<Ipv4ListRouting> (rp_Gw);
218
219
  Ptr<olsr::RoutingProtocol> olsrrp_Gw;
220
221
  for (uint32_t i = 0; i < lrp_Gw->GetNRoutingProtocols ();  i++)
222
    {
223
      int16_t priority;
224
      Ptr<Ipv4RoutingProtocol> temp = lrp_Gw->GetRoutingProtocol (i, priority);
225
      if (DynamicCast<olsr::RoutingProtocol> (temp))
226
        {
227
          olsrrp_Gw = DynamicCast<olsr::RoutingProtocol> (temp);
228
        }
229
    }
230
231
  // Create a special Ipv4StaticRouting instance for RoutingTableAssociation
232
  // Even the Ipv4StaticRouting instance added to list may be used
233
  Ptr<Ipv4StaticRouting> hnaEntries = Create<Ipv4StaticRouting> ();
234
235
  if (assocMethod1)
236
    {
237
      // Add the required routes into the Ipv4StaticRouting Protocol instance
238
      // and have the node generate HNA messages for all these routes
239
      // which are associated with non-OLSR interfaces specified above.
240
      hnaEntries->AddNetworkRouteTo (Ipv4Address ("172.16.1.0"), Ipv4Mask ("255.255.255.0"), uint32_t(2), uint32_t(1));
241
      olsrrp_Gw->SetRoutingTableAssociation (hnaEntries);
242
    }
243
 
244
  if (assocMethod2)
245
    {
246
      // Specify the required associations directly.
247
      olsrrp_Gw->AddHostNetworkAssociation (Ipv4Address ("172.16.1.0"), Ipv4Mask ("255.255.255.0"));
248
    }
249
250
  // Tracing
251
  wifiPhy.EnablePcap ("olsr-hna", devices);
252
  csma.EnablePcap ("olsr-hna", csmaDevices, false);
253
254
  Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
255
                                  Seconds (15.0), &GenerateTraffic, 
256
                                  source, packetSize, numPackets, interPacketInterval);
257
258
  Simulator::Stop (Seconds (20.0));
259
  Simulator::Run ();
260
  Simulator::Destroy ();
261
262
  return 0;
263
}
(-)a/examples/routing/wscript (+4 lines)
 Lines 33-38    Link Here 
33
                                 ['point-to-point', 'internet-stack', 'olsr'])
33
                                 ['point-to-point', 'internet-stack', 'olsr'])
34
    obj.source = 'simple-point-to-point-olsr.cc'
34
    obj.source = 'simple-point-to-point-olsr.cc'
35
35
36
    obj = bld.create_ns3_program('olsr-hna',
37
                                 ['core', 'simulator', 'mobility', 'wifi'])
38
    obj.source = 'olsr-hna.cc'
39
36
    obj = bld.create_ns3_program('nix-simple',
40
    obj = bld.create_ns3_program('nix-simple',
37
                                 ['point-to-point', 'internet-stack', 'nix-vector-routing'])
41
                                 ['point-to-point', 'internet-stack', 'nix-vector-routing'])
38
    obj.source = 'nix-simple.cc'
42
    obj.source = 'nix-simple.cc'
(-)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 (-17 / +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-196    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
{}
 Lines 204-209    Link Here 
204
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
214
  m_helloTimer.SetFunction (&RoutingProtocol::HelloTimerExpire, this);
205
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
215
  m_tcTimer.SetFunction (&RoutingProtocol::TcTimerExpire, this);
206
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
216
  m_midTimer.SetFunction (&RoutingProtocol::MidTimerExpire, this);
217
  m_hnaTimer.SetFunction (&RoutingProtocol::HnaTimerExpire, this);
207
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
218
  m_queuedMessagesTimer.SetFunction (&RoutingProtocol::SendQueuedMessages, this);
208
219
209
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
220
  m_packetSequenceNumber = OLSR_MAX_SEQ_NUM;
 Lines 213-223    Link Here 
213
  m_linkTupleTimerFirstTime = true;
224
  m_linkTupleTimerFirstTime = true;
214
225
215
  m_ipv4 = ipv4;
226
  m_ipv4 = ipv4;
227
  
228
  m_hnaRoutingTable->SetIpv4 (ipv4);
216
}
229
}
217
230
218
void RoutingProtocol::DoDispose ()
231
void RoutingProtocol::DoDispose ()
219
{
232
{
220
  m_ipv4 = 0;
233
  m_ipv4 = 0;
234
  m_hnaRoutingTable = 0;
235
  m_routingTableAssociation = 0;
221
236
222
  for (std::map< Ptr<Socket>, Ipv4InterfaceAddress >::iterator iter = m_socketAddresses.begin ();
237
  for (std::map< Ptr<Socket>, Ipv4InterfaceAddress >::iterator iter = m_socketAddresses.begin ();
223
       iter != m_socketAddresses.end (); iter++)
238
       iter != m_socketAddresses.end (); iter++)
 Lines 251-256    Link Here 
251
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
266
  NS_LOG_DEBUG ("Starting OLSR on node " << m_mainAddress);
252
267
253
  Ipv4Address loopback ("127.0.0.1");
268
  Ipv4Address loopback ("127.0.0.1");
269
270
  bool canRunOlsr = false;
254
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
271
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
255
    {
272
    {
256
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
273
      Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal ();
 Lines 269-274    Link Here 
269
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
286
          NS_ASSERT (GetMainAddress (addr) == m_mainAddress);
270
        }
287
        }
271
288
289
      if(m_interfaceExclusions.find (i) != m_interfaceExclusions.end ())
290
        continue;
291
272
      // Create a socket to listen only on this interface
292
      // Create a socket to listen only on this interface
273
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
293
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (), 
274
        UdpSocketFactory::GetTypeId()); 
294
        UdpSocketFactory::GetTypeId()); 
 Lines 279-291    Link Here 
279
        }
299
        }
280
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
300
      socket->Connect (InetSocketAddress (Ipv4Address (0xffffffff), OLSR_PORT_NUMBER));
281
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
301
      m_socketAddresses[socket] = m_ipv4->GetAddress (i, 0);
302
303
      canRunOlsr = true;
282
    }
304
    }
283
305
284
  HelloTimerExpire ();
306
  if(canRunOlsr)
285
  TcTimerExpire ();
307
   {
286
  MidTimerExpire ();
308
      HelloTimerExpire ();
309
      TcTimerExpire ();
310
      MidTimerExpire ();
311
      HnaTimerExpire ();      
287
312
288
  NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
313
      NS_LOG_DEBUG ("OLSR on node " << m_mainAddress << " started");
314
   }
289
}
315
}
290
316
291
void RoutingProtocol::SetMainInterface (uint32_t interface)
317
void RoutingProtocol::SetMainInterface (uint32_t interface)
 Lines 293-298    Link Here 
293
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
319
  m_mainAddress = m_ipv4->GetAddress (interface, 0).GetLocal ();
294
}
320
}
295
321
322
void RoutingProtocol::SetInterfaceExclusions (std::set<uint32_t> exceptions)
323
{
324
  m_interfaceExclusions = exceptions;
325
}
296
326
297
//
327
//
298
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
328
// \brief Processes an incoming %OLSR packet following RFC 3626 specification.
 Lines 397-402    Link Here 
397
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
427
                            <<  " received MID message of size " << messageHeader.GetSerializedSize ());
398
              ProcessMid (messageHeader, senderIfaceAddr);
428
              ProcessMid (messageHeader, senderIfaceAddr);
399
              break;
429
              break;
430
            case olsr::MessageHeader::HNA_MESSAGE:
431
              NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
432
                            << "s OLSR node " << m_mainAddress
433
                            <<  " received HNA message of size " << messageHeader.GetSerializedSize ());
434
              ProcessHna (messageHeader, senderIfaceAddr);
435
              break; 
400
436
401
            default:
437
            default:
402
              NS_LOG_DEBUG ("OLSR message type " <<
438
              NS_LOG_DEBUG ("OLSR message type " <<
 Lines 1039-1044    Link Here 
1039
        }
1075
        }
1040
    }
1076
    }
1041
1077
1078
  // 5. For each tuple in the association set,
1079
  //    If there is no entry in the routing table with:
1080
  //        R_dest_addr     == A_network_addr/A_netmask
1081
  //   then a new routing entry is created.
1082
  const AssociationSet &associationSet = m_state.GetAssociationSet ();
1083
  for (AssociationSet::const_iterator it = associationSet.begin ();
1084
       it != associationSet.end (); it++)
1085
    {
1086
      AssociationTuple const &tuple = *it;
1087
      RoutingTableEntry gatewayEntry;
1088
      
1089
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
1090
      bool addRoute = false;
1091
      
1092
      uint32_t routeIndex = 0;
1093
      
1094
      for (routeIndex = 0; routeIndex < m_hnaRoutingTable->GetNRoutes (); routeIndex++)
1095
        {
1096
          Ipv4RoutingTableEntry route = m_hnaRoutingTable->GetRoute (routeIndex);
1097
          if (route.GetDestNetwork () == tuple.networkAddr &&
1098
              route.GetDestNetworkMask () == tuple.netmask)
1099
            {
1100
              break;
1101
            }
1102
        }
1103
    
1104
      if (routeIndex == m_hnaRoutingTable->GetNRoutes ())
1105
        {
1106
          addRoute = true;
1107
        }
1108
      else if(gatewayEntryExists && m_hnaRoutingTable->GetMetric (routeIndex) > gatewayEntry.distance)
1109
        {
1110
          m_hnaRoutingTable->RemoveRoute(routeIndex);
1111
          addRoute = true;
1112
        }
1113
        
1114
      if(addRoute && gatewayEntryExists)
1115
        {
1116
          m_hnaRoutingTable->AddNetworkRouteTo (tuple.networkAddr,
1117
                                                tuple.netmask,
1118
                                                gatewayEntry.nextAddr,
1119
                                                gatewayEntry.interface,
1120
                                                gatewayEntry.distance);
1121
                                             
1122
        }
1123
    }
1124
1042
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1125
  NS_LOG_DEBUG ("Node " << m_mainAddress << ": RoutingTableComputation end.");
1043
  m_routingTableChanged (GetSize ());
1126
  m_routingTableChanged (GetSize ());
1044
}
1127
}
 Lines 1280-1285    Link Here 
1280
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1363
  NS_LOG_DEBUG ("Node " << m_mainAddress << " ProcessMid from " << senderIface << " -> END.");
1281
}
1364
}
1282
1365
1366
///
1367
/// \brief Processes a HNA message following RFC 3626 specification.
1368
///
1369
/// The Host Network Association Set is updated (if needed) with the information
1370
/// of the received HNA message.
1371
///
1372
/// \param msg the %OLSR message which contains the HNA message.
1373
/// \param sender_iface the address of the interface where the message was sent from.
1374
///
1375
void
1376
RoutingProtocol::ProcessHna (const olsr::MessageHeader &msg,
1377
                       const Ipv4Address &senderIface)
1378
{
1379
1380
  const olsr::MessageHeader::Hna &hna = msg.GetHna ();
1381
  Time now = Simulator::Now ();
1382
  
1383
  // 1. If the sender interface of this message is not in the symmetric
1384
  // 1-hop neighborhood of this node, the message MUST be discarded.
1385
  const LinkTuple *link_tuple = m_state.FindSymLinkTuple (senderIface, now);
1386
  if (link_tuple == NULL)
1387
    return;
1388
  
1389
  // 2. Otherwise, for each (network address, netmask) pair in the
1390
  // message:
1391
  
1392
  for (std::vector<olsr::MessageHeader::Hna::Association>::const_iterator it = hna.associations.begin();
1393
       it != hna.associations.end() ; it++)
1394
    {
1395
      AssociationTuple *tuple = m_state.FindAssociationTuple(msg.GetOriginatorAddress(),it->address,it->mask);
1396
  
1397
      // 2.1  if an entry in the association set already exists, where:
1398
      //          A_gateway_addr == originator address
1399
      //          A_network_addr == network address
1400
      //          A_netmask      == netmask
1401
      //      then the holding time for that tuple MUST be set to:
1402
      //          A_time         =  current time + validity time
1403
      if(tuple != NULL)
1404
        {
1405
          tuple->expirationTime = now + msg.GetVTime ();
1406
        }
1407
        
1408
      // 2.2 otherwise, a new tuple MUST be recorded with:
1409
      //          A_gateway_addr =  originator address
1410
      //          A_network_addr =  network address
1411
      //          A_netmask      =  netmask
1412
      //          A_time         =  current time + validity time
1413
      else
1414
        {
1415
          const AssociationTuple &assocTuple = (AssociationTuple){msg.GetOriginatorAddress(),it->address,it->mask,now + msg.GetVTime ()};
1416
          
1417
          AddAssociationTuple (assocTuple);
1418
          
1419
          //Schedule Association Tuple deletion
1420
          Simulator::Schedule (DELAY (assocTuple.expirationTime),
1421
                               &RoutingProtocol::AssociationTupleTimerExpire, this,
1422
                               assocTuple.gatewayAddr,assocTuple.networkAddr,assocTuple.netmask);
1423
        }
1424
        
1425
    }
1426
}
1283
1427
1284
///
1428
///
1285
/// \brief OLSR's default forwarding algorithm.
1429
/// \brief OLSR's default forwarding algorithm.
 Lines 1447-1453    Link Here 
1447
RoutingProtocol::SendHello ()
1591
RoutingProtocol::SendHello ()
1448
{
1592
{
1449
  NS_LOG_FUNCTION (this);
1593
  NS_LOG_FUNCTION (this);
1450
  
1594
    
1451
  olsr::MessageHeader msg;
1595
  olsr::MessageHeader msg;
1452
  Time now = Simulator::Now ();
1596
  Time now = Simulator::Now ();
1453
1597
 Lines 1569-1574    Link Here 
1569
  
1713
  
1570
  olsr::MessageHeader::Tc &tc = msg.GetTc ();
1714
  olsr::MessageHeader::Tc &tc = msg.GetTc ();
1571
  tc.ansn = m_ansn;
1715
  tc.ansn = m_ansn;
1716
      
1572
  for (MprSelectorSet::const_iterator mprsel_tuple = m_state.GetMprSelectors ().begin();
1717
  for (MprSelectorSet::const_iterator mprsel_tuple = m_state.GetMprSelectors ().begin();
1573
       mprsel_tuple != m_state.GetMprSelectors ().end(); mprsel_tuple++)
1718
       mprsel_tuple != m_state.GetMprSelectors ().end(); mprsel_tuple++)
1574
    {
1719
    {
 Lines 1622-1627    Link Here 
1622
}
1767
}
1623
1768
1624
///
1769
///
1770
/// \brief Creates a new %OLSR HNA message which is buffered for being sent later on.
1771
///
1772
void
1773
RoutingProtocol::SendHna ()
1774
{
1775
1776
  olsr::MessageHeader msg;
1777
1778
  msg.SetVTime (OLSR_HNA_HOLD_TIME);
1779
  msg.SetOriginatorAddress (m_mainAddress);
1780
  msg.SetTimeToLive (255);
1781
  msg.SetHopCount (0);
1782
  msg.SetMessageSequenceNumber (GetMessageSequenceNumber ());
1783
  olsr::MessageHeader::Hna &hna = msg.GetHna ();
1784
  
1785
  std::vector<olsr::MessageHeader::Hna::Association>
1786
    &associations = hna.associations;
1787
      
1788
  if (m_routingTableAssociation != 0)
1789
    {
1790
      // Add (NetworkAddr, Netmask) entries from Associated Routing Table to HNA message.
1791
      for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1792
        {
1793
          Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1794
          
1795
          std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1796
                  
1797
          if (ci != m_interfaceExclusions.end ())
1798
            {
1799
              olsr::MessageHeader::Hna::Association assoc = {route.GetDestNetwork (), route.GetDestNetworkMask ()};
1800
              associations.push_back(assoc);
1801
            }
1802
        }
1803
    }
1804
    
1805
  int size = associations.size ();
1806
1807
  // Add (NetworkAddr, Netmask) entries specified using AddHostNetworkAssociation () to HNA message.
1808
  for (Associations::const_iterator it = m_state.GetAssociations ().begin ();
1809
        it != m_state.GetAssociations ().end (); it++)
1810
    {
1811
      // Check if the entry has already been added from the Associated Routing Table
1812
      std::vector<olsr::MessageHeader::Hna::Association>::const_iterator ci = associations.begin ();
1813
      bool found = false;
1814
      for (int i = 0; i < size; i++)
1815
        {
1816
          if (it->networkAddr == ci->address && it->netmask == ci->mask)
1817
            {
1818
              found = true;
1819
              break;
1820
            }
1821
          ci++;
1822
        }
1823
      
1824
      if(!found)
1825
        {
1826
          olsr::MessageHeader::Hna::Association assoc = {it->networkAddr,it->netmask};
1827
          associations.push_back(assoc);
1828
        }
1829
    }
1830
    
1831
  if(associations.size () == 0)
1832
    return;
1833
  
1834
  QueueMessage (msg, JITTER);
1835
}
1836
1837
///
1838
/// \brief Injects a (networkAddr, netmask) tuple for which the node
1839
///        can generate an HNA message for
1840
///
1841
void
1842
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1843
{
1844
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1845
}
1846
1847
///
1848
/// \brief Adds an Ipv4StaticRouting protocol Association
1849
///        can generate an HNA message for
1850
///
1851
void
1852
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1853
{
1854
  m_routingTableAssociation = routingTable;
1855
}
1856
1857
///
1625
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1858
/// \brief	Updates Link Set according to a new received HELLO message (following RFC 3626
1626
///		specification). Neighbor Set is also updated if needed.
1859
///		specification). Neighbor Set is also updated if needed.
1627
void
1860
void
 Lines 2301-2306    Link Here 
2301
  m_state.EraseIfaceAssocTuple (tuple);
2534
  m_state.EraseIfaceAssocTuple (tuple);
2302
}
2535
}
2303
2536
2537
///
2538
/// \brief Adds a host network association tuple to the Association Set.
2539
///
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
///
2551
/// \param tuple the host network association tuple to be removed.
2552
///
2553
void
2554
RoutingProtocol::RemoveAssociationTuple (const AssociationTuple &tuple)
2555
{
2556
  m_state.EraseAssociationTuple (tuple);
2557
}
2558
2559
2304
2560
2305
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2561
uint16_t RoutingProtocol::GetPacketSequenceNumber ()
2306
{
2562
{
 Lines 2358-2363    Link Here 
2358
}
2614
}
2359
2615
2360
///
2616
///
2617
/// \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
2618
/// \param e The event which has expired.
2619
///
2620
void
2621
RoutingProtocol::HnaTimerExpire ()
2622
{
2623
  if (m_state.GetAssociations ().size () > 0 || m_routingTableAssociation !=0)
2624
    {
2625
      SendHna ();
2626
    }
2627
  else
2628
    {
2629
      NS_LOG_DEBUG ("Not sending any HNA, no associations to advertise.");
2630
    }
2631
  m_hnaTimer.Schedule (m_hnaInterval);
2632
}
2633
2634
///
2361
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2635
/// \brief Removes tuple if expired. Else timer is rescheduled to expire at tuple.expirationTime.
2362
///
2636
///
2363
/// The task of actually removing the tuple is left to the OLSR agent.
2637
/// The task of actually removing the tuple is left to the OLSR agent.
 Lines 2537-2542    Link Here 
2537
    }
2811
    }
2538
}
2812
}
2539
2813
2814
/// \brief Removes tuple_ if expired. Else timer is rescheduled to expire at tuple_->time().
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
      if (rtentry)
2965
        {
2966
          found = true;
2967
          NS_LOG_DEBUG ("Found route to " << rtentry->GetDestination () << " via nh " << rtentry->GetGateway () << " with source addr " << rtentry->GetSource () << " and output dev " << rtentry->GetOutputDevice());
2968
        }
2969
    }
2970
    
2971
  if (!found)
2972
    {
2661
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2973
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2662
                    << ": RouteOutput for dest=" << header.GetDestination ()
2974
                    << ": RouteOutput for dest=" << header.GetDestination ()
2663
                    << " No route to host");
2975
                    << " No route to host");
 Lines 2729-2746    Link Here 
2729
    }
3041
    }
2730
  else
3042
  else
2731
    {
3043
    {
3044
      if(m_hnaRoutingTable->RouteInput (p, header, idev, ucb, mcb, lcb, ecb))
3045
        {
3046
          return true;
3047
        }
3048
      else
3049
        {
3050
        
2732
#ifdef NS3_LOG_ENABLE
3051
#ifdef NS3_LOG_ENABLE
2733
      NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
3052
          NS_LOG_DEBUG ("Olsr node " << m_mainAddress 
2734
                    << ": RouteInput for dest=" << header.GetDestination ()
3053
                    << ": RouteInput for dest=" << header.GetDestination ()
2735
                    << " --> NOT FOUND; ** Dumping routing table...");      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
3054
                    << " --> NOT FOUND; ** Dumping routing table...");      
2736
           iter != m_table.end (); iter++)
3055
                    
2737
        {           NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
3056
          for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
3057
             iter != m_table.end (); iter++)
3058
          { 
3059
            NS_LOG_DEBUG ("dest=" << iter->first << " --> next=" << iter->second.nextAddr                 
2738
                        << " via interface " << iter->second.interface);
3060
                        << " via interface " << iter->second.interface);
3061
          }
3062
      
3063
          NS_LOG_DEBUG ("** Routing table dump end.");
3064
#endif // NS3_LOG_ENABLE
3065
3066
          return false;
2739
        }
3067
        }
2740
      
2741
      NS_LOG_DEBUG ("** Routing table dump end.");
2742
#endif // NS3_LOG_ENABLE
2743
      return false;
2744
    }
3068
    }
2745
}
3069
}
2746
void 
3070
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