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

(-)a/src/routing/olsr/model/olsr-routing-protocol.cc (-57 / +130 lines)
 Lines 248-261    Link Here 
248
void
248
void
249
RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
249
RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
250
{
250
{
251
  std::ostream* os = stream->GetStream();
251
  std::ostream* os = stream->GetStream ();
252
  *os << "Destination\tNextHop\t\tInterface\tDistance\n";
252
  *os << "Destination\t\tNextHop\t\tInterface\tDistance\n";
253
253
254
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
254
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator iter = m_table.begin ();
255
    iter != m_table.end (); iter++)
255
    iter != m_table.end (); iter++)
256
    {
256
    {
257
      *os << iter->first << "\t";
257
      *os << iter->first << "\t\t";
258
      *os << iter->second.nextAddr << "\t";
258
      *os << iter->second.nextAddr << "\t\t";
259
      if (Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) != "")
259
      if (Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) != "")
260
            {
260
            {
261
              *os << Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) << "\t\t";
261
              *os << Names::FindName (m_ipv4->GetNetDevice (iter->second.interface)) << "\t\t";
 Lines 264-273    Link Here 
264
            {
264
            {
265
              *os << iter->second.interface << "\t\t";
265
              *os << iter->second.interface << "\t\t";
266
            }
266
            }
267
268
      *os << iter->second.distance << "\t";
267
      *os << iter->second.distance << "\t";
269
      *os << "\n";
268
      *os << "\n";
270
    }
269
    }
270
	// Also print the HNA routing table
271
	*os << " HNA Routing Table:\n";
272
	m_hnaRoutingTable->PrintRoutingTable (stream);
271
}
273
}
272
274
273
void RoutingProtocol::DoStart ()
275
void RoutingProtocol::DoStart ()
 Lines 1105-1116    Link Here 
1105
  // 5. For each tuple in the association set,
1107
  // 5. For each tuple in the association set,
1106
  //    If there is no entry in the routing table with:
1108
  //    If there is no entry in the routing table with:
1107
  //        R_dest_addr     == A_network_addr/A_netmask
1109
  //        R_dest_addr     == A_network_addr/A_netmask
1110
  //   and if the announced network is not announced by the node itself,
1108
  //   then a new routing entry is created.
1111
  //   then a new routing entry is created.
1109
  const AssociationSet &associationSet = m_state.GetAssociationSet ();
1112
  const AssociationSet &associationSet = m_state.GetAssociationSet ();
1110
  for (AssociationSet::const_iterator it = associationSet.begin ();
1113
  for (AssociationSet::const_iterator it = associationSet.begin ();
1111
       it != associationSet.end (); it++)
1114
       it != associationSet.end (); it++)
1112
    {
1115
    {
1113
      AssociationTuple const &tuple = *it;
1116
      AssociationTuple const &tuple = *it;
1117
1118
	  // Test if HNA associations received from other gateways
1119
	  // are also announced by this node. In such a case, no route
1120
	  // is created for this association tuple (go to the next one).
1121
	  bool goToNextAssociationTuple = false;
1122
	  const Associations &localHnaAssociations = m_state.GetAssociations ();
1123
	  NS_LOG_DEBUG ("Nb local associations: " << localHnaAssociations.size ());
1124
	  for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1125
		   assocIterator != localHnaAssociations.end (); assocIterator++)
1126
		{
1127
		  Association const &localHnaAssoc = *assocIterator;
1128
		  if (localHnaAssoc.networkAddr == tuple.networkAddr && localHnaAssoc.netmask == tuple.netmask)
1129
			{
1130
    		  NS_LOG_DEBUG ("HNA association received from another GW is part of local HNA associations: no route added for network "
1131
    				  << tuple.networkAddr << "/" << tuple.netmask);
1132
    		  goToNextAssociationTuple = true;
1133
			}
1134
		}
1135
	  if (goToNextAssociationTuple) continue;
1136
1114
      RoutingTableEntry gatewayEntry;
1137
      RoutingTableEntry gatewayEntry;
1115
      
1138
      
1116
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
1139
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
 Lines 1820-1895    Link Here 
1820
  msg.SetMessageSequenceNumber (GetMessageSequenceNumber ());
1843
  msg.SetMessageSequenceNumber (GetMessageSequenceNumber ());
1821
  olsr::MessageHeader::Hna &hna = msg.GetHna ();
1844
  olsr::MessageHeader::Hna &hna = msg.GetHna ();
1822
  
1845
  
1823
  std::vector<olsr::MessageHeader::Hna::Association>
1846
  std::vector<olsr::MessageHeader::Hna::Association> &associations = hna.associations;
1824
    &associations = hna.associations;
1825
      
1826
  if (m_routingTableAssociation != 0)
1827
    {
1828
      // Add (NetworkAddr, Netmask) entries from Associated Routing Table to HNA message.
1829
      for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1830
        {
1831
          Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1832
          
1833
          std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1834
                  
1847
                  
1835
          if (ci != m_interfaceExclusions.end ())
1848
  // Add all local HNA associations to the HNA message
1849
  const Associations &localHnaAssociations = m_state.GetAssociations ();
1850
  for (Associations::const_iterator it = localHnaAssociations.begin ();
1851
	   it != localHnaAssociations.end (); it++)
1836
            {
1852
            {
1837
              olsr::MessageHeader::Hna::Association assoc = {route.GetDestNetwork (), route.GetDestNetworkMask ()};
1853
	  olsr::MessageHeader::Hna::Association assoc = {it->networkAddr, it->netmask};
1838
              associations.push_back(assoc);
1854
	  associations.push_back (assoc);
1839
            }
1840
        }
1841
    }
1855
    }
1856
  // If there is no HNA associations to send, return without queuing the message
1857
  if (associations.size () == 0) return;
1842
    
1858
    
1843
  int size = associations.size ();
1859
  // Else, queue the message to be sent later on
1844
1845
  // Add (NetworkAddr, Netmask) entries specified using AddHostNetworkAssociation () to HNA message.
1846
  for (Associations::const_iterator it = m_state.GetAssociations ().begin ();
1847
        it != m_state.GetAssociations ().end (); it++)
1848
    {
1849
      // Check if the entry has already been added from the Associated Routing Table
1850
      std::vector<olsr::MessageHeader::Hna::Association>::const_iterator ci = associations.begin ();
1851
      bool found = false;
1852
      for (int i = 0; i < size; i++)
1853
        {
1854
          if (it->networkAddr == ci->address && it->netmask == ci->mask)
1855
            {
1856
              found = true;
1857
              break;
1858
            }
1859
          ci++;
1860
        }
1861
      
1862
      if(!found)
1863
        {
1864
          olsr::MessageHeader::Hna::Association assoc = {it->networkAddr,it->netmask};
1865
          associations.push_back(assoc);
1866
        }
1867
    }
1868
    
1869
  if(associations.size () == 0)
1870
    return;
1871
  
1872
  QueueMessage (msg, JITTER);
1860
  QueueMessage (msg, JITTER);
1873
}
1861
}
1874
1862
1875
///
1863
///
1876
/// \brief Injects a (networkAddr, netmask) tuple for which the node
1864
/// \brief Injects the specified (networkAddr, netmask) tuple in the list of
1877
///        can generate an HNA message for
1865
///        local HNA associations to be sent by the node via HNA messages.
1866
///        If this tuple already exists, nothing is done.
1878
///
1867
///
1879
void
1868
void
1880
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1869
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1881
{
1870
{
1882
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1871
  // Check if the (networkAddr, netmask) tuple already exist
1872
  // in the list of local HNA associations
1873
  const Associations &localHnaAssociations = m_state.GetAssociations ();
1874
  for (Associations::const_iterator assocIterator = localHnaAssociations.begin ();
1875
	   assocIterator != localHnaAssociations.end (); assocIterator++)
1876
            {
1877
	  Association const &localHnaAssoc = *assocIterator;
1878
	  if (localHnaAssoc.networkAddr == networkAddr && localHnaAssoc.netmask == netmask)
1879
        {
1880
		  NS_LOG_INFO ("HNA association for network " << networkAddr << "/" << netmask << " already exists.");
1881
		  return;
1882
        }
1883
    }
1884
  // If the tuple does not already exist, add it to the list of local HNA associations.
1885
  NS_LOG_INFO ("Adding HNA association for network " << networkAddr << "/" << netmask << ".");
1886
  m_state.InsertAssociation ( (Association) {networkAddr, netmask} );
1883
}
1887
}
1884
1888
1885
///
1889
///
1886
/// \brief Adds an Ipv4StaticRouting protocol Association
1890
/// \brief Removes the specified (networkAddr, netmask) tuple from the list of
1887
///        can generate an HNA message for
1891
///        local HNA associations to be sent by the node via HNA messages.
1892
///        If this tuple does not exist, nothing is done (see "OlsrState::EraseAssociation()").
1893
///
1894
void
1895
RoutingProtocol::RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1896
{
1897
  NS_LOG_INFO ("Removing HNA association for network " << networkAddr << "/" << netmask << ".");
1898
  m_state.EraseAssociation ( (Association) {networkAddr, netmask} );
1899
}
1900
1901
///
1902
/// \brief Associates the specified Ipv4StaticRouting routing table
1903
///        to the OLSR routing protocol. Entries from this associated
1904
///        routing table that use non-olsr outgoing interfaces are added
1905
///        to the list of local HNA associations so that they are included
1906
///        in HNA messages sent by the node.
1907
///        If this method is called more than once, entries from the old
1908
///        association are deleted before entries from the new one are added.
1909
/// \param the Ipv4StaticRouting routing table to be associated.
1888
///
1910
///
1889
void
1911
void
1890
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1912
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1891
{
1913
{
1914
  // If a routing table has already been associated, remove
1915
  // corresponding entries from the list of local HNA associations
1916
  if (m_routingTableAssociation != 0)
1917
	{
1918
	  NS_LOG_INFO ("Removing HNA entries coming from the old routing table association.");
1919
	  for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1920
		{
1921
		  Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1922
		  // If the outgoing interface for this route is a non-olsr interface
1923
		  if (UsesNonOlsrOutgoingInterface (route))
1924
			{
1925
			  // remove the corresponding entry
1926
			  RemoveHostNetworkAssociation (route.GetDestNetwork (), route.GetDestNetworkMask ());
1927
			}
1928
		}
1929
	}
1930
1931
  // Sets the routingTableAssociation to its new value
1892
  m_routingTableAssociation = routingTable;
1932
  m_routingTableAssociation = routingTable;
1933
1934
  // Iterate over entries of the associated routing table and
1935
  // add the routes using non-olsr outgoing interfaces to the list
1936
  // of local HNA associations
1937
  const Associations &localHnaAssociations = m_state.GetAssociations ();	//Just for logging
1938
  NS_LOG_DEBUG ("Nb local associations before adding some entries from the associated routing table: " << localHnaAssociations.size ());
1939
  for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1940
	{
1941
	  Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1942
	  Ipv4Address destNetworkAddress = route.GetDestNetwork ();
1943
	  Ipv4Mask destNetmask = route.GetDestNetworkMask ();
1944
1945
	  // If the outgoing interface for this route is a non-olsr interface,
1946
	  if (UsesNonOlsrOutgoingInterface (route))
1947
		{
1948
		  // Add this entry's network address and netmask to the list of local HNA entries
1949
		  AddHostNetworkAssociation (destNetworkAddress, destNetmask);
1950
		}
1951
	}
1952
  NS_LOG_DEBUG ("Nb local associations after having added some entries from the associated routing table: " << localHnaAssociations.size ());
1953
}
1954
1955
///
1956
/// \brief Tests whether or not the specified route uses a non-OLSR outgoing interface.
1957
///        Returns true if the outgoing interface of the specified route is a non-OLSR interface.
1958
///        Returns false otherwise.
1959
///
1960
bool
1961
RoutingProtocol::UsesNonOlsrOutgoingInterface (const Ipv4RoutingTableEntry &route)
1962
{
1963
  std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1964
  // The outgoing interface is a non-OLSR interface if a match is found
1965
  // before reaching the end of the list of excluded interfaces
1966
  return ci != m_interfaceExclusions.end ();
1893
}
1967
}
1894
1968
1895
///
1969
///
 Lines 2652-2663    Link Here 
2652
2726
2653
///
2727
///
2654
/// \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
2728
/// \brief Sends an HNA message (if the node has associated hosts/networks) and reschedules the HNA timer.
2655
/// \param e The event which has expired.
2656
///
2729
///
2657
void
2730
void
2658
RoutingProtocol::HnaTimerExpire ()
2731
RoutingProtocol::HnaTimerExpire ()
2659
{
2732
{
2660
  if (m_state.GetAssociations ().size () > 0 || m_routingTableAssociation !=0)
2733
  if (m_state.GetAssociations ().size () > 0)
2661
    {
2734
    {
2662
      SendHna ();
2735
      SendHna ();
2663
    }
2736
    }
(-)a/src/routing/olsr/model/olsr-routing-protocol.h (-15 / +17 lines)
 Lines 1-6    Link Here 
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
2
/*
3
 * Copyright (c) 2004 Francisco J. Ros 
3
 * Copyright (c) 2004 Francisco J. Ros
4
 * Copyright (c) 2007 INESC Porto
4
 * Copyright (c) 2007 INESC Porto
5
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
6
 * This program is free software; you can redistribute it and/or modify
 Lines 89-104    Link Here 
89
89
90
  ///
90
  ///
91
  /// \brief Set the OLSR main address to the first address on the indicated
91
  /// \brief Set the OLSR main address to the first address on the indicated
92
  ///        interface 
92
  ///        interface
93
  /// \param interface IPv4 interface index
93
  /// \param interface IPv4 interface index
94
  ///
94
  ///
95
  void SetMainInterface (uint32_t interface);
95
  void SetMainInterface (uint32_t interface);
96
96
97
  /// 
97
  ///
98
  /// Dump the neighbor table, two-hop neighbor table, and routing table
98
  /// Dump the neighbor table, two-hop neighbor table, and routing table
99
  /// to logging output (NS_LOG_DEBUG log level).  If logging is disabled,
99
  /// to logging output (NS_LOG_DEBUG log level).  If logging is disabled,
100
  /// this function does nothing.
100
  /// this function does nothing.
101
  /// 
101
  ///
102
  void Dump (void);
102
  void Dump (void);
103
103
104
  /**
104
  /**
 Lines 119-124    Link Here 
119
119
120
  /// Inject Association to be sent in HNA message
120
  /// Inject Association to be sent in HNA message
121
  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
121
  void AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
122
  /// Removes Association sent in HNA message
123
  void RemoveHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask);
122
124
123
  /// Inject Associations from an Ipv4StaticRouting instance
125
  /// Inject Associations from an Ipv4StaticRouting instance
124
  void SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable);
126
  void SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable);
 Lines 134-147    Link Here 
134
136
135
  /// Address of the routing agent.
137
  /// Address of the routing agent.
136
  Ipv4Address m_routingAgentAddr;
138
  Ipv4Address m_routingAgentAddr;
137
	
139
138
  /// Packets sequence number counter.
140
  /// Packets sequence number counter.
139
  uint16_t m_packetSequenceNumber;
141
  uint16_t m_packetSequenceNumber;
140
  /// Messages sequence number counter.
142
  /// Messages sequence number counter.
141
  uint16_t m_messageSequenceNumber;
143
  uint16_t m_messageSequenceNumber;
142
  /// Advertised Neighbor Set sequence number.
144
  /// Advertised Neighbor Set sequence number.
143
  uint16_t m_ansn;
145
  uint16_t m_ansn;
144
  
146
145
  /// HELLO messages' emission interval.
147
  /// HELLO messages' emission interval.
146
  Time m_helloInterval;
148
  Time m_helloInterval;
147
  /// TC messages' emission interval.
149
  /// TC messages' emission interval.
 Lines 152-163    Link Here 
152
  Time m_hnaInterval;
154
  Time m_hnaInterval;
153
  /// Willingness for forwarding packets on behalf of other nodes.
155
  /// Willingness for forwarding packets on behalf of other nodes.
154
  uint8_t m_willingness;
156
  uint8_t m_willingness;
155
	
157
156
  /// Internal state with all needed data structs.
158
  /// Internal state with all needed data structs.
157
  OlsrState m_state;
159
  OlsrState m_state;
158
160
159
  Ptr<Ipv4> m_ipv4;
161
  Ptr<Ipv4> m_ipv4;
160
	
162
161
  void Clear ();
163
  void Clear ();
162
  uint32_t GetSize () const { return m_table.size (); }
164
  uint32_t GetSize () const { return m_table.size (); }
163
  void RemoveEntry (const Ipv4Address &dest);
165
  void RemoveEntry (const Ipv4Address &dest);
 Lines 176-184    Link Here 
176
178
177
  // From Ipv4RoutingProtocol
179
  // From Ipv4RoutingProtocol
178
  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
180
  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
179
   virtual bool RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
181
   virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
180
                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
182
                            UnicastForwardCallback ucb, MulticastForwardCallback mcb,
181
                             LocalDeliverCallback lcb, ErrorCallback ecb);  
183
                            LocalDeliverCallback lcb, ErrorCallback ecb);
182
  virtual void NotifyInterfaceUp (uint32_t interface);
184
  virtual void NotifyInterfaceUp (uint32_t interface);
183
  virtual void NotifyInterfaceDown (uint32_t interface);
185
  virtual void NotifyInterfaceDown (uint32_t interface);
184
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
186
  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
 Lines 186-211    Link Here 
186
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
188
  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
187
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
189
  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
188
190
189
190
  void DoDispose ();
191
  void DoDispose ();
191
192
192
  void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
193
  void SendPacket (Ptr<Packet> packet, const MessageList &containedMessages);
193
	
194
194
  /// Increments packet sequence number and returns the new value.
195
  /// Increments packet sequence number and returns the new value.
195
  inline uint16_t GetPacketSequenceNumber ();
196
  inline uint16_t GetPacketSequenceNumber ();
196
  /// Increments message sequence number and returns the new value.
197
  /// Increments message sequence number and returns the new value.
197
  inline uint16_t GetMessageSequenceNumber ();
198
  inline uint16_t GetMessageSequenceNumber ();
198
	
199
199
  void RecvOlsr (Ptr<Socket> socket);
200
  void RecvOlsr (Ptr<Socket> socket);
200
201
201
  void MprComputation ();
202
  void MprComputation ();
202
  void RoutingTableComputation ();
203
  void RoutingTableComputation ();
203
  Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
204
  Ipv4Address GetMainAddress (Ipv4Address iface_addr) const;
205
  bool UsesNonOlsrOutgoingInterface (const Ipv4RoutingTableEntry &route);
204
206
205
  // Timer handlers
207
  // Timer handlers
206
  Timer m_helloTimer;
208
  Timer m_helloTimer;
207
  void HelloTimerExpire ();
209
  void HelloTimerExpire ();
208
  
210
209
  Timer m_tcTimer;
211
  Timer m_tcTimer;
210
  void TcTimerExpire ();
212
  void TcTimerExpire ();
211
213

Return to bug 1049