Add ability to pass statically determined routing information. Also allow bridge...
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 02:08:08 +0000 (02:08 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 02:08:08 +0000 (02:08 +0000)
code/src/devices/bridge/helper/moose-bridge-helper.cc
code/src/devices/bridge/helper/moose-bridge-helper.h

index ee3b838aae0aa0cd099cc9d47bea2420077e3b04..7d4b727ba53ef55f738765ed2768ef4d30d41cfb 100644 (file)
@@ -23,6 +23,7 @@
 #include "ns3/moose-bridge-net-device.h"
 #include "ns3/node.h"
 #include "ns3/names.h"
+#include "ns3/moose-address.h"
 
 NS_LOG_COMPONENT_DEFINE ("MooseBridgeHelper");
 
@@ -41,14 +42,47 @@ MooseBridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
   m_deviceFactory.Set (n1, v1);
 }
 
+NetDeviceContainer
+MooseBridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c, MoosePrefixAddress addr, std::map<Ptr<NetDevice>, MoosePrefixAddress> routes)
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_LOGIC ("**** Install MOOSE bridge device on node " << node->GetId ());
+
+  SetDeviceAttribute("MooseAddress", MooseAddressValue(MooseAddress::Allocate(addr)));
+
+  NetDeviceContainer devs;
+  Ptr<MooseBridgeNetDevice> dev = m_deviceFactory.Create<MooseBridgeNetDevice> ();
+  devs.Add (dev);
+  node->AddDevice (dev);
+
+  std::map<MoosePrefixAddress, Ptr<BridgePortNetDevice> > portMap;
+
+  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+    {
+      NS_LOG_LOGIC ("**** Add MooseBridgePort "<< *i);
+      Ptr<BridgePortNetDevice> port = dev->AddBridgePort (*i);
+      std::map<Ptr<NetDevice>, MoosePrefixAddress>::iterator it = routes.find(*i);
+      if(it != routes.end()){
+           portMap[routes[*i]] = port;
+      }
+    }
+
+  dev->AddRoutes(portMap);
+
+  return devs;
+}
+
+
 NetDeviceContainer
 MooseBridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
 {
   NS_LOG_FUNCTION_NOARGS ();
   NS_LOG_LOGIC ("**** Install MOOSE bridge device on node " << node->GetId ());
 
+  SetDeviceAttribute("MooseAddress", MooseAddressValue(MooseAddress::Allocate()));
+
   NetDeviceContainer devs;
-  Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
+  Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<MooseBridgeNetDevice> ();
   devs.Add (dev);
   node->AddDevice (dev);
 
index fa2e1e1c30cf77070adaff4531cb373b11342f76..c6fa8d904b7245f45184a4f1325dab5d57c44273 100644 (file)
@@ -28,6 +28,8 @@
 #include "ns3/net-device-container.h"
 #include "ns3/object-factory.h"
 #include <string>
+#include <map>
+#include "ns3/moose-prefix-address.h"
 
 namespace ns3 {
 
@@ -63,6 +65,12 @@ public:
    * \returns A container holding the added net device.
    */
   NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
+  /**
+   * This method creates an ns3::MooseBridgeNetDevice with static routing.
+   */
+
+  NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c, MoosePrefixAddress addr, std::map<Ptr<NetDevice>, MoosePrefixAddress> routes);
+
   /**
    * This method creates an ns3::MooseBridgeNetDevice with the attributes
    * configured by MooseBridgeHelper::SetDeviceAttribute, adds the device
@@ -82,3 +90,4 @@ private:
 
 
 #endif /* MOOSE_BRIDGE_HELPER_H */
+