Add function to take enabled ports and disable as required
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 07:06:31 +0000 (07:06 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 07:06:31 +0000 (07:06 +0000)
code/src/devices/bridge/helper/bridge-helper.cc
code/src/devices/bridge/helper/bridge-helper.h

index 01f12c0a72fea2cbff2067cf54005ab7d4375a36..b74ca8b0381706269c3c5b9d73e693d6cc950ffe 100644 (file)
@@ -39,6 +39,29 @@ BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
   m_deviceFactory.Set (n1, v1);
 }
 
+NetDeviceContainer
+BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled)
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  NS_LOG_LOGIC ("**** Install bridge device on node " << node->GetId ());
+
+  NetDeviceContainer devs;
+  Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
+  devs.Add (dev);
+  node->AddDevice (dev);
+
+  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
+    {
+      NS_LOG_LOGIC ("**** Add BridgePort "<< *i);
+      Ptr<BridgePortNetDevice> port = dev->AddBridgePort (*i);
+      if(portsEnabled.find(*i) != portsEnabled.end()){
+         port->SetEnabled(portsEnabled[*i]);
+      }
+    }
+  return devs;
+}
+
+
 NetDeviceContainer
 BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
 {
index 49af32974ee16ec53d19caaefdc990ef0f87156a..bd00d4efacc4a3ea4b21b5d72477db8d8d22720e 100644 (file)
@@ -24,6 +24,7 @@
 #include "ns3/net-device-container.h"
 #include "ns3/object-factory.h"
 #include <string>
+#include <map>
 
 namespace ns3 {
 
@@ -48,6 +49,21 @@ public:
    * \param v1 the value of the attribute to set
    */
   void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
+
+  /**
+   * This method creates an ns3::BridgeNetDevice with the attributes
+   * configured by BridgeHelper::SetDeviceAttribute, adds the device
+   * to the node, and attaches the given NetDevices as ports of the
+   * bridge.
+   *
+   * This version uses static spanning tree to disable loops.
+   *
+   * \param node The node to install the device in
+   * \param c Container of NetDevices to add as bridge ports
+   * \returns A container holding the added net device.
+   */
+  NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c, std::map<Ptr<NetDevice>, bool> portsEnabled);
+
   /**
    * This method creates an ns3::BridgeNetDevice with the attributes
    * configured by BridgeHelper::SetDeviceAttribute, adds the device