Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
authorTom Henderson <tomh@tomh.org>
Sun, 08 Jul 2007 15:12:50 -0700
changeset 1045 c2c43e021fb7
parent 1044 f6180a7631ee
child 1046 95c38ae06290
Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
src/routing/static-route-manager.cc
src/routing/static-route-manager.h
src/routing/static-router.cc
src/routing/static-router.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/static-route-manager.cc	Sun Jul 08 15:12:50 2007 -0700
@@ -0,0 +1,105 @@
+/* -*- 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
+ */
+#include <utility>
+#include <vector>
+#include "ns3/assert.h"
+#include "ns3/fatal-error.h"
+#include "ns3/debug.h"
+#include "ns3/node-list.h"
+#include "static-router.h"
+#include "static-route-manager.h"
+
+NS_DEBUG_COMPONENT_DEFINE ("StaticRouteManager");
+
+namespace ns3 {
+
+StaticRouteManager::StaticRouteManager ()
+{
+}
+
+StaticRouteManager::~StaticRouteManager ()
+{}
+
+void
+StaticRouteManager::BuildStaticRoutingDatabase () 
+{
+  // walk list of nodes.  QI for StaticRouter interface.
+  // if node has a StaticRouter interface, grab the LSAs 
+  // from it and stick them in the LSDB
+  typedef std::vector < Ptr<Node> >::iterator Iterator;
+  for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++)
+    {
+      Ptr<Node> node = *i;
+      NS_DEBUG_UNCOND ("node="<< node->GetId () );
+    }
+}
+
+void
+StaticRouteManager::InitializeRoutes ()
+{
+  // For each node that is a static router (which can be determined by
+  // the presence of StaticRouter interface), run Dijkstra SPF calculation
+  // on the database rooted at that router, and populate the node
+  // forwarding tables
+}
+
+} // namespace ns3
+
+#ifdef RUN_SELF_TESTS
+
+#include "ns3/test.h"
+
+namespace ns3 {
+
+class StaticRouteManagerTest : public Test {
+public:
+  StaticRouteManagerTest ();
+  virtual ~StaticRouteManagerTest ();
+  virtual bool RunTests (void);
+};
+
+StaticRouteManagerTest::StaticRouteManagerTest ()
+  : Test ("StaticRouteManager")
+{
+}
+
+StaticRouteManagerTest::~StaticRouteManagerTest ()
+{}
+
+bool
+StaticRouteManagerTest::RunTests (void)
+{
+  DebugComponentEnable("StaticRouteManager");
+  bool ok = true;
+  StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord();
+  lr1->m_linkId.Set(1);
+  lr1->m_linkData.Set(0xffffffff);
+  lr1->m_linkType = StaticRouterLinkRecord::PointToPoint;
+  lr1->m_metric = 1;
+  StaticRouterLSA* lsa1 = new StaticRouterLSA();
+  lsa1->m_linkStateId.Set(1);
+  lsa1->m_advertisingRtr.Set(1);
+  lsa1->Add(lr1);
+  
+  delete lsa1;
+  return ok;
+}
+
+static StaticRouteManagerTest g_staticRouteManagerTest;
+
+} // namespace ns3
+
+#endif 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/routing/static-route-manager.h	Sun Jul 08 15:12:50 2007 -0700
@@ -0,0 +1,94 @@
+/* -*- 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
+ */
+#ifndef STATIC_ROUTE_MANAGER_H
+#define STATIC_ROUTE_MANAGER_H
+
+#include <stdint.h>
+#include <list>
+#include "ns3/object.h"
+#include "ns3/ptr.h"
+#include "ns3/ipv4-address.h"
+
+namespace ns3 {
+
+/**
+ * \brief Vertex used in shortest path first (SPF) computations
+ *
+ * See RFC 2328, Section 16.
+ */
+class SPFVertex
+{
+public:
+  enum VertexType {
+    VertexRouter = 1,
+    VertexNetwork
+  } m_vertexType;
+
+  Ipv4Address m_vertexId;
+
+  uint32_t m_distanceFromRoot;
+
+  typedef std::list<SPFVertex> type_listOfSPFVertex;
+  type_listOfSPFVertex m_parents;
+  type_listOfSPFVertex m_children;
+  type_listOfSPFVertex::iterator m_iter;
+};
+
+/**
+ * \brief The Link State DataBase (LSDB) of a static router
+ */
+class StaticRouteManagerLSDB
+{
+public:
+};
+
+/**
+ * \brief A global static router
+ *
+ * This singleton object can query interface each node in the system
+ * for a StaticRouter interface.  For those nodes, it fetches one or
+ * more LSAs and stores them in a local database.  Then, it
+ * can compute shortest paths on a per-node basis to all routers, and
+ * finally configure each of the node's forwarding tables.
+ *
+ * The design is guided by OSPFv2 RFC 2328 section 16.1.1
+ * and quagga ospfd
+ */
+class StaticRouteManager : public Object
+{
+public:
+  static const InterfaceId iid;
+  StaticRouteManager ();
+  /**
+   * \brief Build routing database by gathering LSA from each routing node
+   */
+  virtual void BuildStaticRoutingDatabase();
+  /**
+   * \brief Compute routes using Dijkstra SPF computation, and populate
+   *        per-node forwarding tables
+   */
+  virtual void InitializeRoutes();
+
+protected:
+  virtual ~StaticRouteManager ();
+
+private:
+  StaticRouteManagerLSDB m_lsdb;
+};
+
+} // namespace ns3
+
+#endif /* STATIC_ROUTE_MANAGER_H */
--- a/src/routing/static-router.cc	Sun Jul 08 13:55:39 2007 -0700
+++ b/src/routing/static-router.cc	Sun Jul 08 15:12:50 2007 -0700
@@ -22,6 +22,30 @@
 
 namespace ns3 {
 
+StaticRouterLSA::StaticRouterLSA () : m_linkStateId(0x66666666), 
+  m_advertisingRtr(0x66666666), m_numLinks(0)
+{
+  NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()");
+}
+StaticRouterLSA::~StaticRouterLSA ()
+{
+  NS_DEBUG("StaticRouterLSA::~StaticRouterLSA ()");
+  for (m_iter = m_listOfLinkRecords.begin(); 
+    m_iter != m_listOfLinkRecords.end(); m_iter++)
+  {
+    NS_DEBUG_UNCOND("Deleting");
+    StaticRouterLinkRecord* temp = *m_iter;
+    delete temp;
+  }
+}
+
+uint32_t
+StaticRouterLSA::Add (StaticRouterLinkRecord* lr)
+{
+  m_listOfLinkRecords.push_back (lr);
+  return m_listOfLinkRecords.size ();
+}
+
 const InterfaceId StaticRouter::iid = 
   MakeInterfaceId ("StaticRouter", Object::iid);
 
--- a/src/routing/static-router.h	Sun Jul 08 13:55:39 2007 -0700
+++ b/src/routing/static-router.h	Sun Jul 08 15:12:50 2007 -0700
@@ -68,13 +68,17 @@
 class StaticRouterLSA
 {
 public:
+  StaticRouterLSA();
+  virtual ~StaticRouterLSA ();
+public:
   Ipv4Address  m_linkStateId;     // set to the NodeId
-  Ipv4Address  m_advertising_rtr;  // set to the NodeId
+  Ipv4Address  m_advertisingRtr;  // set to the NodeId
 
   uint32_t m_numLinks;
-  typedef std::list<StaticRouterLinkRecord> type_listOfLinkRecords;
+  typedef std::list<StaticRouterLinkRecord*> type_listOfLinkRecords;
   type_listOfLinkRecords m_listOfLinkRecords;
   type_listOfLinkRecords::iterator m_iter;
+  uint32_t Add (StaticRouterLinkRecord* lr);
 };
 
 /**