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

(-)a/src/node/ipv4.cc (+47 lines)
 Lines 18-23    Link Here 
18
 *
18
 *
19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
 */
20
 */
21
22
#include "ns3/assert.h" 
23
#include "ns3/node.h" 
21
#include "ipv4.h"
24
#include "ipv4.h"
22
25
23
namespace ns3 {
26
namespace ns3 {
 Lines 32-35   Ipv4::~Ipv4 () Link Here 
32
Ipv4::~Ipv4 ()
35
Ipv4::~Ipv4 ()
33
{}
36
{}
34
37
38
uint32_t 
39
GetIfIndexByIpv4Address (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
40
{
41
  Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
42
  NS_ASSERT_MSG (ipv4, "GetIfIndexByIpv4Address:  No Ipv4 interface");
43
  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
44
    {
45
      if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) )
46
        {
47
          return i;
48
        }
49
    }
50
  // Mapping not found
51
  NS_ASSERT_MSG (false, "GetIfIndexByIpv4Address failed");
52
  return 0;
53
}
54
55
bool 
56
GetIpv4RouteToDestination (Ptr<Node> node, Ipv4Route& route, 
57
                           Ipv4Address a, Ipv4Mask amask)
58
{
59
  Ipv4Route tempRoute;
60
  Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
61
  NS_ASSERT_MSG (ipv4, "GetIpv4RouteToDestination:  No Ipv4 interface");
62
  for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++) 
63
    {
64
      tempRoute = ipv4->GetRoute (i);
65
      // Host route found
66
      if ( tempRoute.IsNetwork () == false && tempRoute.GetDest () == a ) 
67
        {
68
          route = tempRoute;
69
          return true;
70
        }
71
      else if ( tempRoute.IsNetwork () && 
72
                tempRoute.GetDestNetwork () == a.CombineMask(amask) )
73
        {
74
          route = tempRoute;
75
          return true;
76
        }
77
    }
78
  return false;
79
}
80
81
35
} // namespace ns3
82
} // namespace ns3
(-)a/src/node/ipv4.h (+14 lines)
 Lines 29-34    Link Here 
29
29
30
namespace ns3 {
30
namespace ns3 {
31
31
32
class Node;
32
class NetDevice;
33
class NetDevice;
33
class Packet;
34
class Packet;
34
class Ipv4Route;
35
class Ipv4Route;
 Lines 273-278   public: Link Here 
273
  
274
  
274
};
275
};
275
276
277
/**
278
 * Convenience functions (Doxygen still needed)
279
 *
280
 * Return the ifIndex corresponding to the Ipv4Address provided.
281
 */
282
uint32_t GetIfIndexByIpv4Address (Ptr<Node> node, 
283
                                  Ipv4Address a, 
284
                                  Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
285
286
bool GetIpv4RouteToDestination (Ptr<Node> node, Ipv4Route& route, 
287
                                Ipv4Address a, 
288
                                Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
289
276
} // namespace ns3 
290
} // namespace ns3 
277
291
278
#endif /* IPV4_H */
292
#endif /* IPV4_H */
(-)a/src/routing/global-routing/global-route-manager-impl.cc (-88 / +7 lines)
 Lines 1089-1100   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1089
}
1089
}
1090
1090
1091
//
1091
//
1092
// XXX This should probably be a method on Ipv4
1093
//
1094
// Return the interface index corresponding to a given IP address
1092
// Return the interface index corresponding to a given IP address
1093
// This is a wrapper around GetIfIndexByIpv4Address(), but we first
1094
// have to find the right node pointer to pass to that function.
1095
//
1095
//
1096
  uint32_t
1096
  uint32_t
1097
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a)
1097
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
1098
{
1098
{
1099
//
1099
//
1100
// We have an IP address <a> and a vertex ID of the root of the SPF tree.  
1100
// We have an IP address <a> and a vertex ID of the root of the SPF tree.  
 Lines 1143-1232   GlobalRouteManagerImpl::FindOutgoingInte Link Here 
1143
// we're looking for.  If we find one, return the corresponding interface
1143
// we're looking for.  If we find one, return the corresponding interface
1144
// index.
1144
// index.
1145
//
1145
//
1146
          for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
1146
          return (GetIfIndexByIpv4Address (node, a, amask) );
1147
            {
1148
              if (ipv4->GetAddress (i) == a)
1149
                {
1150
                  NS_DEBUG (
1151
                    "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
1152
                    "Interface match for " << a);
1153
                  return i;
1154
                }
1155
            }
1156
        }
1157
    }
1158
//
1159
// Couldn't find it.
1160
//
1161
  return 0;
1162
}
1163
1164
//
1165
// XXX This should probably be a method on Ipv4
1166
//
1167
// Return the interface index corresponding to a given IP address
1168
//
1169
  uint32_t
1170
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
1171
{
1172
//
1173
// We have an IP address <a> and a vertex ID of the root of the SPF tree.  
1174
// The question is what interface index does this address correspond to.
1175
// The answer is a little complicated since we have to find a pointer to
1176
// the node corresponding to the vertex ID, find the Ipv4 interface on that
1177
// node in order to iterate the interfaces and find the one corresponding to
1178
// the address in question.
1179
//
1180
  Ipv4Address routerId = m_spfroot->GetVertexId ();
1181
//
1182
// Walk the list of nodes in the system looking for the one corresponding to
1183
// the node at the root of the SPF tree.  This is the node for which we are
1184
// building the routing table.
1185
//
1186
  NodeList::Iterator i = NodeList::Begin (); 
1187
  for (; i != NodeList::End (); i++)
1188
    {
1189
      Ptr<Node> node = *i;
1190
1191
      Ptr<GlobalRouter> rtr = 
1192
        node->QueryInterface<GlobalRouter> (GlobalRouter::iid);
1193
//
1194
// If the node doesn't have a GlobalRouter interface it can't be the one
1195
// we're interested in.
1196
//
1197
      if (rtr == 0)
1198
        {
1199
          continue;
1200
        }
1201
1202
      if (rtr->GetRouterId () == routerId)
1203
        {
1204
//
1205
// This is the node we're building the routing table for.  We're going to need
1206
// the Ipv4 interface to look for the ipv4 interface index.  Since this node
1207
// is participating in routing IP version 4 packets, it certainly must have 
1208
// an Ipv4 interface.
1209
//
1210
          Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
1211
          NS_ASSERT_MSG (ipv4, 
1212
            "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
1213
            "QI for <Ipv4> interface failed");
1214
//
1215
// Look through the interfaces on this node for one that has the IP address
1216
// we're looking for.  If we find one, return the corresponding interface
1217
// index.
1218
//
1219
          for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
1220
            {
1221
              if (ipv4->GetAddress (i).CombineMask(amask) == 
1222
                  a.CombineMask(amask) )
1223
                {
1224
                  NS_DEBUG (
1225
                    "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
1226
                    "Interface match for " << a);
1227
                  return i;
1228
                }
1229
            }
1230
        }
1147
        }
1231
    }
1148
    }
1232
//
1149
//
 Lines 1693-1698   GlobalRouteManagerImplTest::RunTests (vo Link Here 
1693
  srm->DebugSPFCalculate (lsa0->GetLinkStateId ());  // node n0
1610
  srm->DebugSPFCalculate (lsa0->GetLinkStateId ());  // node n0
1694
1611
1695
  Simulator::Run ();
1612
  Simulator::Run ();
1613
1614
// XXX here we should do some verification of the routes built
1615
1696
  Simulator::Destroy ();
1616
  Simulator::Destroy ();
1697
1617
1698
  // This delete clears the srm, which deletes the LSDB, which clears 
1618
  // This delete clears the srm, which deletes the LSDB, which clears 
 Lines 1703-1709   GlobalRouteManagerImplTest::RunTests (vo Link Here 
1703
}
1623
}
1704
1624
1705
// Instantiate this class for the unit tests
1625
// Instantiate this class for the unit tests
1706
// XXX here we should do some verification of the routes built
1707
static GlobalRouteManagerImplTest g_globalRouteManagerTest;
1626
static GlobalRouteManagerImplTest g_globalRouteManagerTest;
1708
1627
1709
} // namespace ns3
1628
} // namespace ns3
(-)a/src/routing/global-routing/global-route-manager-impl.h (-2 / +2 lines)
 Lines 754-761   private: Link Here 
754
    GlobalRoutingLinkRecord* prev_link);
754
    GlobalRoutingLinkRecord* prev_link);
755
  void SPFIntraAddRouter (SPFVertex* v);
755
  void SPFIntraAddRouter (SPFVertex* v);
756
  void SPFIntraAddTransit (SPFVertex* v);
756
  void SPFIntraAddTransit (SPFVertex* v);
757
  uint32_t FindOutgoingInterfaceId (Ipv4Address a);
757
  uint32_t FindOutgoingInterfaceId (Ipv4Address a, 
758
  uint32_t FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask);
758
    Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
759
};
759
};
760
760
761
} // namespace ns3
761
} // namespace ns3

Return to bug 65