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

(-)olsr-routing-protocol.cc (-45 / +116 lines)
 Lines 249-261    Link Here 
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 268-273    Link Here 
268
      *os << iter->second.distance << "\t";
268
      *os << iter->second.distance << "\t";
269
      *os << "\n";
269
      *os << "\n";
270
    }
270
    }
271
	// ADDED SECTION: also print the HNA routing table
272
	*os << " HNA Routing Table:\n";
273
	m_hnaRoutingTable->PrintRoutingTable(stream);
274
	// END OF ADDED SECTION
271
}
275
}
272
276
273
void RoutingProtocol::DoStart ()
277
void RoutingProtocol::DoStart ()
 Lines 1111-1116    Link Here 
1111
       it != associationSet.end (); it++)
1115
       it != associationSet.end (); it++)
1112
    {
1116
    {
1113
      AssociationTuple const &tuple = *it;
1117
      AssociationTuple const &tuple = *it;
1118
1119
      // ADDED SECTION: eliminates* BUG 1049 (http://www.nsnam.org/bugzilla/show_bug.cgi?id=1049)
1120
      // *in conjunction with other modifications in this file.
1121
      // Test if HNA associations received from other gateways
1122
      // are also announced by this node. In such a case, do NOT add
1123
      // a route for this association and go to the next association tuple.
1124
      bool goToNextAssociationTuple = false;
1125
      const Associations &localHnaAssociations = m_state.GetAssociations();
1126
      NS_LOG_DEBUG("Nb local associations: " << localHnaAssociations.size());
1127
      for (Associations::const_iterator assocIterator = localHnaAssociations.begin();
1128
			  assocIterator != localHnaAssociations.end(); assocIterator++) {
1129
    	  Association const &localHnaAssoc = *assocIterator;
1130
    	  if (localHnaAssoc.networkAddr == tuple.networkAddr &&
1131
    			  localHnaAssoc.netmask == tuple.netmask) {
1132
    		  NS_LOG_DEBUG("HNA association received from another GW is part of local associations: no route added for network " << tuple.networkAddr << "/" << tuple.netmask);
1133
    		  goToNextAssociationTuple = true;
1134
    	  }
1135
      }
1136
      if (goToNextAssociationTuple) continue;
1137
      // END OF ADDED SECTION
1138
1114
      RoutingTableEntry gatewayEntry;
1139
      RoutingTableEntry gatewayEntry;
1115
      
1140
      
1116
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
1141
      bool gatewayEntryExists = Lookup (tuple.gatewayAddr, gatewayEntry);
 Lines 1823-1870    Link Here 
1823
  std::vector<olsr::MessageHeader::Hna::Association>
1848
  std::vector<olsr::MessageHeader::Hna::Association>
1824
    &associations = hna.associations;
1849
    &associations = hna.associations;
1825
      
1850
      
1826
  if (m_routingTableAssociation != 0)
1851
  // USELESS SECTION TO BE REMOVED (see comments in method SetRoutingTableAssociation())
1827
    {
1852
//  if (m_routingTableAssociation != 0) {
1828
      // Add (NetworkAddr, Netmask) entries from Associated Routing Table to HNA message.
1853
//	  // Add (NetworkAddr, Netmask) entries from Associated Routing Table to HNA message.
1829
      for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++)
1854
//	  for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes (); i++) {
1830
        {
1855
//		  Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1831
          Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute (i);
1856
//		  std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1832
          
1857
//		  if (ci != m_interfaceExclusions.end ()) {
1833
          std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find (route.GetInterface ());
1858
//			  olsr::MessageHeader::Hna::Association assoc = {route.GetDestNetwork (), route.GetDestNetworkMask ()};
1834
                  
1859
//			  associations.push_back(assoc);
1835
          if (ci != m_interfaceExclusions.end ())
1860
//		  }
1836
            {
1861
//	  }
1837
              olsr::MessageHeader::Hna::Association assoc = {route.GetDestNetwork (), route.GetDestNetworkMask ()};
1862
//  }
1838
              associations.push_back(assoc);
1863
//  int size = associations.size ();
1839
            }
1864
  // END OF USELESS SECTION TO BE REMOVED
1840
        }
1841
    }
1842
    
1843
  int size = associations.size ();
1844
1865
1845
  // Add (NetworkAddr, Netmask) entries specified using AddHostNetworkAssociation () to HNA message.
1866
  // Add all HNA entries to the HNA message
1846
  for (Associations::const_iterator it = m_state.GetAssociations ().begin ();
1867
  for (Associations::const_iterator it = m_state.GetAssociations().begin();
1847
        it != m_state.GetAssociations ().end (); it++)
1868
		  it != m_state.GetAssociations().end(); it++) {
1848
    {
1869
1849
      // Check if the entry has already been added from the Associated Routing Table
1870
	  // USELESS SECTION TO BE REMOVED (see comments in method SetRoutingTableAssociation())
1850
      std::vector<olsr::MessageHeader::Hna::Association>::const_iterator ci = associations.begin ();
1871
//	  // Check if the entry has already been added from the Associated Routing Table
1851
      bool found = false;
1872
//	  std::vector<olsr::MessageHeader::Hna::Association>::const_iterator ci = associations.begin ();
1852
      for (int i = 0; i < size; i++)
1873
//	  bool found = false;
1853
        {
1874
//	  for (int i = 0; i < size; i++) {
1854
          if (it->networkAddr == ci->address && it->netmask == ci->mask)
1875
//		  if (it->networkAddr == ci->address && it->netmask == ci->mask) {
1855
            {
1876
//			  found = true;
1856
              found = true;
1877
//			  break;
1857
              break;
1878
//		  }
1858
            }
1879
//		  ci++;
1859
          ci++;
1880
//	  }
1860
        }
1881
//	  if(!found) { ... }
1882
	  // END OF USELESS SECTION TO BE REMOVED
1861
      
1883
      
1862
      if(!found)
1863
        {
1864
          olsr::MessageHeader::Hna::Association assoc = {it->networkAddr,it->netmask};
1884
          olsr::MessageHeader::Hna::Association assoc = {it->networkAddr,it->netmask};
1865
          associations.push_back(assoc);
1885
          associations.push_back(assoc);
1866
        }
1886
        }
1867
    }
1868
    
1887
    
1869
  if(associations.size () == 0)
1888
  if(associations.size () == 0)
1870
    return;
1889
    return;
 Lines 1873-1895    Link Here 
1873
}
1892
}
1874
1893
1875
///
1894
///
1876
/// \brief Injects a (networkAddr, netmask) tuple for which the node
1895
/// \brief Injects a (networkAddr, netmask) tuple to be included in
1877
///        can generate an HNA message for
1896
///        HNA messages sent by the node
1878
///
1897
///
1879
void
1898
void
1880
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1899
RoutingProtocol::AddHostNetworkAssociation (Ipv4Address networkAddr, Ipv4Mask netmask)
1881
{
1900
{
1901
  // ADDED LOG
1902
  NS_LOG_INFO("Adding HNA association for network " << networkAddr << "/" << netmask << ".");
1882
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1903
  m_state.InsertAssociation ((Association) {networkAddr, netmask});
1883
}
1904
}
1884
1905
1885
///
1906
///
1886
/// \brief Adds an Ipv4StaticRouting protocol Association
1907
/// \brief Adds an Ipv4StaticRouting protocol Association. Entries using
1887
///        can generate an HNA message for
1908
///        non-olsr outgoing interfaces are included in HNA messages
1909
///        sent by the node. Note that this RoutingTableAssociation
1910
///        is NOT supposed to change over time (the content of HNA messages
1911
///        does NOT change accordingly).
1888
///
1912
///
1889
void
1913
void
1890
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1914
RoutingProtocol::SetRoutingTableAssociation (Ptr<Ipv4StaticRouting> routingTable)
1891
{
1915
{
1892
  m_routingTableAssociation = routingTable;
1916
  m_routingTableAssociation = routingTable;
1917
1918
  // ADDED SECTION:
1919
  // In order to have all local HNA entries (sent by this node in HNA messages)
1920
  // stored in one consistent list, this code iterates over entries of the
1921
  // routing table association and adds the routes using non-olsr outgoing interfaces
1922
  // to the list of HNA entries (if they do not exist already).
1923
  const Associations &localHnaAssociations = m_state.GetAssociations();
1924
  NS_LOG_DEBUG("Nb local associations: " << localHnaAssociations.size());
1925
1926
  for (uint32_t i = 0; i < m_routingTableAssociation->GetNRoutes(); i++) {
1927
	  Ipv4RoutingTableEntry route = m_routingTableAssociation->GetRoute(i);
1928
	  Ipv4Address destNetworkAddress = route.GetDestNetwork();
1929
	  Ipv4Mask destNetmask = route.GetDestNetworkMask();
1930
1931
	  // Check if the RoutingTableAssociation entry is already
1932
	  // in the list of local HNA entries
1933
	  bool addHnaEntry = true;
1934
	  //TODO Could not the GetAssociations() method return a set rather than
1935
	  //	 a vector? The std::vector does not provide a "find(element)" method
1936
	  //	 that would be very useful right here...
1937
	  for (Associations::const_iterator assocIterator = localHnaAssociations.begin();
1938
			  assocIterator != localHnaAssociations.end(); assocIterator++) {
1939
		  Association const &localHnaAssoc = *assocIterator;
1940
		  if (localHnaAssoc.networkAddr == destNetworkAddress &&
1941
				  localHnaAssoc.netmask == destNetmask) {
1942
			  NS_LOG_DEBUG("HNA association for network " << destNetworkAddress << "/" << destNetmask << " already exists.");
1943
			  addHnaEntry = false;
1944
		  }
1945
	  }
1946
	  // If the RoutingTableAssociation entry is already in the list,
1947
	  // it is not necessary to add it, so continue.
1948
	  if ( ! addHnaEntry ) continue;
1949
1950
	  // Else, check whether the outgoing interface for this route is a non-olsr interface
1951
	  std::set<uint32_t>::const_iterator ci = m_interfaceExclusions.find(route.GetInterface());
1952
	  // If it is a non-olsr interface (match found in the list of excluded interfaces)
1953
	  if ( ci != m_interfaceExclusions.end() ) {
1954
		  NS_LOG_DEBUG("Call to the \"AddHostNetworkAssociation()\" method to add an HNA association for network " << destNetworkAddress << "/" << destNetmask << ".");
1955
		  // Add this entry's network address and netmask to the list of local HNA entries
1956
		  AddHostNetworkAssociation(destNetworkAddress, destNetmask);
1957
	  }
1958
  }
1959
  NS_LOG_DEBUG("Nb local associations (after adding some entries from the RoutingTableAssociation: " << localHnaAssociations.size());
1960
  // END OF ADDED SECTION
1893
}
1961
}
1894
1962
1895
///
1963
///
 Lines 2657-2663    Link Here 
2657
void
2725
void
2658
RoutingProtocol::HnaTimerExpire ()
2726
RoutingProtocol::HnaTimerExpire ()
2659
{
2727
{
2660
  if (m_state.GetAssociations ().size () > 0 || m_routingTableAssociation !=0)
2728
  // MODIFIED TEST
2729
//  if (m_state.GetAssociations ().size () > 0 || m_routingTableAssociation !=0)
2730
  if (m_state.GetAssociations().size() > 0)
2731
  // END OF MODIFIED TEST
2661
    {
2732
    {
2662
      SendHna ();
2733
      SendHna ();
2663
    }
2734
    }

Return to bug 1049