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

(-)a/src/internet-stack/ipv4-global-routing.cc (-1 / +1 lines)
 Lines 110-116   Ipv4GlobalRouting::LookupGlobal (Ipv4Add Link Here 
110
       j != m_networkRoutes.end (); 
110
       j != m_networkRoutes.end (); 
111
       j++) 
111
       j++) 
112
    {
112
    {
113
      NS_ASSERT ((*j)->IsNetwork ());
113
      NS_ASSERT ((*j)->IsNetwork () || (*j)->IsDefault ());
114
      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
114
      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
115
      Ipv4Address entry = (*j)->GetDestNetwork ();
115
      Ipv4Address entry = (*j)->GetDestNetwork ();
116
      if (mask.IsMatch (dest, entry)) 
116
      if (mask.IsMatch (dest, entry)) 
(-)a/src/routing/global-routing/global-route-manager-impl.cc (+96 lines)
 Lines 1058-1063   GlobalRouteManagerImpl::DebugSPFCalculat Link Here 
1058
  SPFCalculate (root);
1058
  SPFCalculate (root);
1059
}
1059
}
1060
1060
1061
//
1062
// Used to test if a node is a stub, from an OSPF sense.
1063
// If there is only one link of type 1 or 2, then a default route
1064
// can safely be added to the next-hop router and SPF does not need
1065
// to be run
1066
//
1067
bool
1068
GlobalRouteManagerImpl::CheckForStubNode (Ipv4Address root)
1069
{
1070
  NS_LOG_FUNCTION (root);
1071
  GlobalRoutingLSA *rlsa = m_lsdb->GetLSA (root);
1072
  Ipv4Address myRouterId = rlsa->GetLinkStateId ();
1073
  int transits = 0;
1074
  GlobalRoutingLinkRecord *transitLink;
1075
  for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++)
1076
    {
1077
      GlobalRoutingLinkRecord *l = rlsa->GetLinkRecord (i);
1078
      if (l->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
1079
        {
1080
          transits++;
1081
          transitLink = l;
1082
        }
1083
      else if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
1084
        {
1085
          transits++;
1086
          transitLink = l;
1087
        }
1088
    }
1089
  if (transits == 0)
1090
    {
1091
      // This router is not connected to any router.  Probably, global
1092
      // routing should not be called for this node, but we can just raise
1093
      // a warning here and return true.
1094
      NS_LOG_WARN ("all nodes should have at least one transit link:" << root );
1095
      return true;
1096
    }
1097
  if (transits == 1)
1098
    {
1099
      if (transitLink->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
1100
        {
1101
          // Install default route to next hop router
1102
          // What is the next hop?  We need to check all neighbors on the link.
1103
          // If there is a single router that has two transit links, then
1104
          // that is the default next hop.  If there are more than one
1105
          // routers on link with multiple transit links, return false.
1106
          // Not yet implemented, so simply return false
1107
          NS_LOG_LOGIC ("TBD: Would have inserted default for transit");
1108
          return false;
1109
        }
1110
      else if (transitLink->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
1111
        {
1112
          // Install default route to next hop
1113
          // The link record LinkID is the router ID of the peer.
1114
          // The Link Data is the local IP interface address
1115
          GlobalRoutingLSA *w_lsa = m_lsdb->GetLSA (transitLink->GetLinkId ());
1116
          uint32_t nLinkRecords = w_lsa->GetNLinkRecords ();
1117
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1118
            {
1119
              //
1120
              // We are only concerned about point-to-point links
1121
              //
1122
              GlobalRoutingLinkRecord *lr = w_lsa->GetLinkRecord (j);
1123
              if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint)
1124
                {
1125
                  continue;
1126
                }
1127
              // Find the link record that corresponds to our routerId
1128
              if (lr->GetLinkId () ==  myRouterId)
1129
                {
1130
                  // Next hop is stored in the LinkID field of lr
1131
                  Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (rlsa->GetNode ()->GetId ());
1132
                  NS_ASSERT (gr);
1133
                  gr->AddNetworkRouteTo (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0"), lr->GetLinkData (), FindOutgoingInterfaceId (transitLink->GetLinkData ()));
1134
                  NS_LOG_LOGIC ("Inserting default route for node " << myRouterId << " to next hop " << lr->GetLinkData () << " via interface " << FindOutgoingInterfaceId(transitLink->GetLinkData()));
1135
                  return true;
1136
                }
1137
            }
1138
        }
1139
    }
1140
  return false;
1141
}
1142
1061
// quagga ospf_spf_calculate
1143
// quagga ospf_spf_calculate
1062
  void
1144
  void
1063
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
1145
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
 Lines 1090-1095   GlobalRouteManagerImpl::SPFCalculate (Ip Link Here 
1090
  v->SetDistanceFromRoot (0);
1172
  v->SetDistanceFromRoot (0);
1091
  v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1173
  v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1092
  NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
1174
  NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
1175
1176
//
1177
// Optimize SPF calculation, for ns-3.
1178
// We do not need to calculate SPF for every node in the network if this
1179
// node has only one interface through which another router can be 
1180
// reached.  Instead, short-circuit this computation and just install
1181
// a default route in the CheckForStubNode() method.
1182
//
1183
  if (NodeList::GetNNodes () > 0 && CheckForStubNode (root))
1184
    {
1185
      NS_LOG_LOGIC ("SPFCalculate truncated for stub node " << root);
1186
      delete m_spfroot;
1187
      return;
1188
    }
1093
1189
1094
  for (;;)
1190
  for (;;)
1095
    {
1191
    {
(-)a/src/routing/global-routing/global-route-manager-impl.h (+1 lines)
 Lines 788-793   private: Link Here 
788
788
789
  SPFVertex* m_spfroot;
789
  SPFVertex* m_spfroot;
790
  GlobalRouteManagerLSDB* m_lsdb;
790
  GlobalRouteManagerLSDB* m_lsdb;
791
  bool CheckForStubNode (Ipv4Address root);
791
  void SPFCalculate (Ipv4Address root);
792
  void SPFCalculate (Ipv4Address root);
792
  void SPFProcessStubs (SPFVertex* v);
793
  void SPFProcessStubs (SPFVertex* v);
793
  void SPFNext (SPFVertex*, CandidateQueue&);
794
  void SPFNext (SPFVertex*, CandidateQueue&);
(-)a/src/routing/global-routing/global-router-interface.cc (-4 / +25 lines)
 Lines 24-29    Link Here 
24
#include "ns3/channel.h"
24
#include "ns3/channel.h"
25
#include "ns3/net-device.h"
25
#include "ns3/net-device.h"
26
#include "ns3/node.h"
26
#include "ns3/node.h"
27
#include "ns3/node-list.h"
27
#include "ns3/ipv4.h"
28
#include "ns3/ipv4.h"
28
#include "ns3/bridge-net-device.h"
29
#include "ns3/bridge-net-device.h"
29
#include "ns3/net-device-container.h"
30
#include "ns3/net-device-container.h"
 Lines 140-146   GlobalRoutingLSA::GlobalRoutingLSA() Link Here 
140
  m_linkRecords(),
141
  m_linkRecords(),
141
  m_networkLSANetworkMask("0.0.0.0"),
142
  m_networkLSANetworkMask("0.0.0.0"),
142
  m_attachedRouters(),
143
  m_attachedRouters(),
143
  m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
144
  m_status(GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED),
145
  m_node_id(0)
144
{
146
{
145
  NS_LOG_FUNCTION_NOARGS ();
147
  NS_LOG_FUNCTION_NOARGS ();
146
}
148
}
 Lines 156-162   GlobalRoutingLSA::GlobalRoutingLSA ( Link Here 
156
  m_linkRecords(),
158
  m_linkRecords(),
157
  m_networkLSANetworkMask("0.0.0.0"),
159
  m_networkLSANetworkMask("0.0.0.0"),
158
  m_attachedRouters(),
160
  m_attachedRouters(),
159
  m_status(status)
161
  m_status(status),
162
  m_node_id(0)
160
{
163
{
161
  NS_LOG_FUNCTION (this << status << linkStateId << advertisingRtr);
164
  NS_LOG_FUNCTION (this << status << linkStateId << advertisingRtr);
162
}
165
}
 Lines 165-171   GlobalRoutingLSA::GlobalRoutingLSA (Glob Link Here 
165
  : m_lsType(lsa.m_lsType), m_linkStateId(lsa.m_linkStateId), 
168
  : m_lsType(lsa.m_lsType), m_linkStateId(lsa.m_linkStateId), 
166
    m_advertisingRtr(lsa.m_advertisingRtr), 
169
    m_advertisingRtr(lsa.m_advertisingRtr), 
167
    m_networkLSANetworkMask(lsa.m_networkLSANetworkMask), 
170
    m_networkLSANetworkMask(lsa.m_networkLSANetworkMask), 
168
    m_status(lsa.m_status)
171
    m_status(lsa.m_status),
172
    m_node_id(lsa.m_node_id)
169
{
173
{
170
  NS_LOG_FUNCTION_NOARGS ();
174
  NS_LOG_FUNCTION_NOARGS ();
171
  NS_ASSERT_MSG(IsEmpty(), 
175
  NS_ASSERT_MSG(IsEmpty(), 
 Lines 181-187   GlobalRoutingLSA::operator= (const Globa Link Here 
181
  m_linkStateId = lsa.m_linkStateId;
185
  m_linkStateId = lsa.m_linkStateId;
182
  m_advertisingRtr = lsa.m_advertisingRtr;
186
  m_advertisingRtr = lsa.m_advertisingRtr;
183
  m_networkLSANetworkMask = lsa.m_networkLSANetworkMask, 
187
  m_networkLSANetworkMask = lsa.m_networkLSANetworkMask, 
184
  m_status = lsa.m_status;
188
  m_status = lsa.m_status,
189
  m_node_id = lsa.m_node_id;
185
190
186
  ClearLinkRecords ();
191
  ClearLinkRecords ();
187
  CopyLinkRecords (lsa);
192
  CopyLinkRecords (lsa);
 Lines 380-385   GlobalRoutingLSA::SetStatus (GlobalRouti Link Here 
380
  m_status = status;
385
  m_status = status;
381
}
386
}
382
387
388
  Ptr<Node>
389
GlobalRoutingLSA::GetNode (void) const
390
{
391
  NS_LOG_FUNCTION_NOARGS ();
392
  return NodeList::GetNode (m_node_id);
393
}
394
395
  void
396
GlobalRoutingLSA::SetNode (Ptr<Node> node)
397
{
398
  NS_LOG_FUNCTION (node);
399
  m_node_id = node->GetId ();
400
}
401
383
  void 
402
  void 
384
GlobalRoutingLSA::Print (std::ostream &os) const
403
GlobalRoutingLSA::Print (std::ostream &os) const
385
{
404
{
 Lines 570-575   GlobalRouter::DiscoverLSAs (void) Link Here 
570
  pLSA->SetLinkStateId (m_routerId);
589
  pLSA->SetLinkStateId (m_routerId);
571
  pLSA->SetAdvertisingRouter (m_routerId);
590
  pLSA->SetAdvertisingRouter (m_routerId);
572
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
591
  pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
592
  pLSA->SetNode (node);
573
593
574
  //
594
  //
575
  // Ask the node for the number of net devices attached. This isn't necessarily 
595
  // Ask the node for the number of net devices attached. This isn't necessarily 
 Lines 1087-1092   GlobalRouter::BuildNetworkLSAs (NetDevic Link Here 
1087
      pLSA->SetAdvertisingRouter (m_routerId);
1107
      pLSA->SetAdvertisingRouter (m_routerId);
1088
      pLSA->SetNetworkLSANetworkMask (maskLocal);
1108
      pLSA->SetNetworkLSANetworkMask (maskLocal);
1089
      pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
1109
      pLSA->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
1110
      pLSA->SetNode (node);
1090
1111
1091
      //
1112
      //
1092
      // Build a list of AttachedRouters by walking the devices in the channel
1113
      // Build a list of AttachedRouters by walking the devices in the channel
(-)a/src/routing/global-routing/global-router-interface.h (+14 lines)
 Lines 476-481   public: Link Here 
476
 */
476
 */
477
  void SetStatus (SPFStatus status);
477
  void SetStatus (SPFStatus status);
478
478
479
/**
480
 * @brief Get the Node pointer of the node that originated this LSA
481
 * @returns Node pointer
482
 */
483
  Ptr<Node> GetNode (void) const;
484
485
/**
486
 * @brief Set the Node pointer of the node that originated this LSA
487
 * @param node Node pointer
488
 */
489
  void SetNode (Ptr<Node> node);
490
479
private:
491
private:
480
/**
492
/**
481
 * The type of the LSA.  Each LSA type has a separate advertisement
493
 * The type of the LSA.  Each LSA type has a separate advertisement
 Lines 544-549   private: Link Here 
544
 * proper position in the tree.
556
 * proper position in the tree.
545
 */
557
 */
546
  SPFStatus m_status;
558
  SPFStatus m_status;
559
560
  uint32_t m_node_id;
547
};
561
};
548
562
549
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa);
563
std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa);

Return to bug 521