document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
authorCraig Dowell <craigdo@ee.washington.edu>
Mon, 24 Nov 2008 21:39:00 -0800
changeset 3946 6a20c485ddb5
parent 3945 bbccb5d7b6ea
child 3947 756887a9bbea
document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
examples/wifi-wired-bridging.cc
src/routing/global-routing/global-route-manager-impl.cc
src/routing/global-routing/global-router-interface.cc
--- a/examples/wifi-wired-bridging.cc	Mon Nov 24 11:21:15 2008 -0800
+++ b/examples/wifi-wired-bridging.cc	Mon Nov 24 21:39:00 2008 -0800
@@ -1,4 +1,44 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+// Default network topology
+//
+//      +-----+      +-----+            +-----+      +-----+
+//      | sta |      | sta |            | sta |      | sta | 
+//      +-----+      +-----+            +-----+      +-----+
+//    192.168.1.2  192.168.1.3        192.168.2.2  192.168.2.3
+//      --------     --------           --------     --------
+//      WIFI STA     WIFI STA           WIFI STA     WIFI STA
+//      --------     --------     |     --------     --------
+//        ((*))       ((*))       |      ((*))        ((*))
+//                                |   
+//              ((*))             |            ((*))
+//             -------            |           -------
+//    ######## WIFI AP                        WIFI AP #########
+//    #        -------                        -------         #
+//  B #      102.168.1.1                    102.168.2.1       # B
+//  R #     +----------+                   +----------+       # R
+//  I #     | backbone |                   | backbone |       # I
+//  D #     +----------+                   +----------+       # D
+//  G #      192.168.0.1                    192.168.0.2       # G
+//  E #          ----                           ----          # E
+//    ########## CSMA                           CSMA ##########    
+//                |                              |      
+//                ================================
+//
 
 #include "ns3/core-module.h"
 #include "ns3/simulator-module.h"
--- a/src/routing/global-routing/global-route-manager-impl.cc	Mon Nov 24 11:21:15 2008 -0800
+++ b/src/routing/global-routing/global-route-manager-impl.cc	Mon Nov 24 21:39:00 2008 -0800
@@ -97,7 +97,7 @@
   void 
 SPFVertex::SetVertexType (SPFVertex::VertexType type)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (type);
   m_vertexType = type;
 }
 
@@ -111,7 +111,7 @@
   void 
 SPFVertex::SetVertexId (Ipv4Address id)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (id);
   m_vertexId = id;
 }
 
@@ -125,7 +125,7 @@
   void 
 SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (lsa);
   m_lsa = lsa;
 }
 
@@ -139,7 +139,7 @@
   void 
 SPFVertex::SetDistanceFromRoot (uint32_t distance)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (distance);
   m_distanceFromRoot = distance;
 }
 
@@ -153,7 +153,7 @@
   void 
 SPFVertex::SetOutgoingTypeId (uint32_t id)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (id);
   m_rootOif = id;
 }
 
@@ -167,7 +167,7 @@
   void 
 SPFVertex::SetNextHop (Ipv4Address nextHop)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (nextHop);
   m_nextHop = nextHop;
 }
 
@@ -181,7 +181,7 @@
   void
 SPFVertex::SetParent (SPFVertex* parent)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (parent);
   m_parent = parent;
 }
 
@@ -202,7 +202,7 @@
   SPFVertex* 
 SPFVertex::GetChild (uint32_t n) const
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (n);
   uint32_t j = 0;
 
   for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
@@ -221,7 +221,7 @@
   uint32_t 
 SPFVertex::AddChild (SPFVertex* child)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (child);
   m_children.push_back (child);
   return m_children.size ();
 }
@@ -268,14 +268,14 @@
   void
 GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (addr << lsa);
   m_database.insert (LSDBPair_t (addr, lsa));
 }
 
   GlobalRoutingLSA*
 GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (addr);
 //
 // Look up an LSA by its address.
 //
@@ -293,7 +293,7 @@
   GlobalRoutingLSA*
 GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (addr);
 //
 // Look up an LSA by its address.
 //
@@ -341,7 +341,7 @@
   void
 GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (lsdb);
   if (m_lsdb)
     {
       delete m_lsdb;
@@ -373,7 +373,7 @@
   void
 GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) 
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (&c);
   for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
     {
       Ptr<Node> node = *i;
@@ -518,7 +518,7 @@
   void
 GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v << &candidate);
 
   SPFVertex* w = 0;
   GlobalRoutingLSA* w_lsa = 0;
@@ -720,7 +720,7 @@
   GlobalRoutingLinkRecord* l,
   uint32_t distance)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v << w << l << distance);
 //
 // If w is a NetworkVertex, l should be null
 /*
@@ -905,7 +905,7 @@
   SPFVertex* w,
   GlobalRoutingLinkRecord* prev_link) 
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v << w << prev_link);
 
   bool skip = true;
   bool found_prev_link = false;
@@ -980,7 +980,7 @@
   void
 GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (root);
   SPFCalculate (root);
 }
 
@@ -1137,7 +1137,7 @@
   uint32_t
 GlobalRouteManagerImpl::FindOutgoingTypeId (Ipv4Address a, Ipv4Mask amask)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (a << amask);
 //
 // We have an IP address <a> and a vertex ID of the root of the SPF tree.  
 // The question is what interface index does this address correspond to.
@@ -1213,7 +1213,7 @@
   void
 GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v);
 
   NS_ASSERT_MSG (m_spfroot, 
     "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
@@ -1330,7 +1330,7 @@
   void
 GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v);
 
   NS_ASSERT_MSG (m_spfroot, 
     "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
@@ -1423,7 +1423,7 @@
   void
 GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
 {
-  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_FUNCTION (v);
   v->GetParent ()->AddChild (v);
 }
 
--- a/src/routing/global-routing/global-router-interface.cc	Mon Nov 24 11:21:15 2008 -0800
+++ b/src/routing/global-routing/global-router-interface.cc	Mon Nov 24 21:39:00 2008 -0800
@@ -581,9 +581,23 @@
       Ptr<NetDevice> ndLocal = node->GetDevice(i);
 
       //
+      // There is an assumption that bridge ports must never have an IP address 
+      // associated with them.  This turns out to be a very convenient place to
+      // check and make sure that this is the case.
+      //
+      if (NetDeviceIsBridged (ndLocal))
+        {
+          uint32_t ifIndexBridge;
+          bool rc = FindIfIndexForDevice(node, ndLocal, ifIndexBridge);
+          NS_ABORT_MSG_IF (rc, "GlobalRouter::ProcessBridgedBroadcastLink(): "
+                               "Bridge ports must not have an IPv4 interface index");
+        }
+
+      //
       // Check to see if the net device we just got has a corresponding IP 
       // interface (could be a pure L2 NetDevice) -- for example a net device
-      // associated with a bridge.
+      // associated with a bridge.  We are only going to involve devices with 
+      // IP addresses in routing.
       //
       bool isIp = false;
       for (uint32_t i = 0; i < ipv4Local->GetNInterfaces (); ++i )
@@ -735,6 +749,18 @@
       // case.
       //
       Ipv4Address desigRtr = FindDesignatedRouterForLink (nd, true);
+
+      //
+      // Let's double-check that any designated router we find out on our
+      // network is really on our network.
+      //
+      if (desigRtr != "255.255.255.255")
+        {
+          Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
+          Ipv4Address networkThere = desigRtr.CombineMask (maskLocal);
+          NS_ABORT_MSG_UNLESS (networkHere == networkThere, 
+                               "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
+        }
       if (desigRtr == addrLocal) 
         {
           c.Add (nd);
@@ -763,6 +789,27 @@
   NS_ABORT_MSG_UNLESS (bnd, "GlobalRouter::DiscoverLSAs (): GetObject for <BridgeNetDevice> failed");
 
   //
+  // We have some preliminaries to do to get enough information to proceed.
+  // This information we need comes from the internet stack, so notice that
+  // there is an implied assumption that global routing is only going to 
+  // work with devices attached to the internet stack (have an ipv4 interface
+  // associated to them.
+  //
+  Ptr<Node> node = nd->GetNode ();
+
+  uint32_t ifIndexLocal;
+  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
+  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
+
+  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
+  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
+
+  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
+  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
+  NS_LOG_LOGIC ("Working with local address " << addrLocal);
+  uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
+
+  //
   // We need to handle a bridge on the router.  This means that we have been 
   // given a net device that is a BridgeNetDevice.  It has an associated Ipv4
   // interface index and address.  Some number of other net devices live "under"
@@ -794,13 +841,24 @@
           // all.
           //
           Ipv4Address desigRtrTemp = FindDesignatedRouterForLink (ndTemp, true);
+
+          //
+          // Let's double-check that any designated router we find out on our
+          // network is really on our network.
+          //
+          if (desigRtrTemp != "255.255.255.255")
+            {
+              Ipv4Address networkHere = addrLocal.CombineMask (maskLocal);
+              Ipv4Address networkThere = desigRtrTemp.CombineMask (maskLocal);
+              NS_ABORT_MSG_UNLESS (networkHere == networkThere, 
+                                   "GlobalRouter::ProcessSingleBroadcastLink(): Network number confusion");
+            }
           if (desigRtrTemp < desigRtr)
             {
               desigRtr = desigRtrTemp;
             }
         }
     }
-
   //
   // That's all the information we need to put it all together, just like we did
   // in the case of a single broadcast link.
@@ -809,27 +867,6 @@
   GlobalRoutingLinkRecord *plr = new GlobalRoutingLinkRecord;
   NS_ABORT_MSG_IF (plr == 0, "GlobalRouter::ProcessBridgedBroadcastLink(): Can't alloc link record");
 
-  //
-  // We have some preliminaries to do to get enough information to proceed.
-  // This information we need comes from the internet stack, so notice that
-  // there is an implied assumption that global routing is only going to 
-  // work with devices attached to the internet stack (have an ipv4 interface
-  // associated to them.
-  //
-  Ptr<Node> node = nd->GetNode ();
-
-  uint32_t ifIndexLocal;
-  bool rc = FindIfIndexForDevice(node, nd, ifIndexLocal);
-  NS_ABORT_MSG_IF (rc == false, "GlobalRouter::ProcessBridgedBroadcastLink(): No interface index associated with device");
-
-  Ptr<Ipv4> ipv4Local = node->GetObject<Ipv4> ();
-  NS_ABORT_MSG_UNLESS (ipv4Local, "GlobalRouter::ProcessBridgedBroadcastLink (): GetObject for <Ipv4> interface failed");
-
-  Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
-  Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
-  NS_LOG_LOGIC ("Working with local address " << addrLocal);
-  uint16_t metricLocal = ipv4Local->GetMetric (ifIndexLocal);
-
   if (areTransitNetwork == false)
     {
       //