bug 276: bridge netdevice has no helper class.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 11 Aug 2008 10:30:46 -0700
changeset 3524 028b7de98fb1
parent 3523 5c7524e89e10
child 3525 4b8ef7da0ac3
bug 276: bridge netdevice has no helper class.
examples/csma-bridge.cc
src/helper/bridge-helper.cc
src/helper/bridge-helper.h
src/helper/wscript
--- a/examples/csma-bridge.cc	Sun Aug 10 15:45:27 2008 -0400
+++ b/examples/csma-bridge.cc	Mon Aug 11 10:30:46 2008 -0700
@@ -94,14 +94,8 @@
 
   // Create the bridge netdevice, which will do the packet switching
   Ptr<Node> switchNode = csmaSwitch.Get (0);
-  Ptr<BridgeNetDevice> bridgeDevice = CreateObject<BridgeNetDevice> ();
-  switchNode->AddDevice (bridgeDevice);
-
-  for (NetDeviceContainer::Iterator portIter = switchDevices.Begin ();
-       portIter != switchDevices.End (); portIter++)
-    {
-      bridgeDevice->AddBridgePort (*portIter);
-    }
+  BridgeHelper bridge;
+  bridge.Install (switchNode, switchDevices);
 
   // Add internet stack to the terminals
   InternetStackHelper internet;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/bridge-helper.cc	Mon Aug 11 10:30:46 2008 -0700
@@ -0,0 +1,34 @@
+#include "bridge-helper.h"
+
+#include "ns3/bridge-net-device.h"
+#include "ns3/node.h"
+
+namespace ns3 {
+
+BridgeHelper::BridgeHelper ()
+{
+  m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
+}
+
+void 
+BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
+{
+  m_deviceFactory.Set (n1, v1);
+}
+
+NetDeviceContainer
+BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
+{
+  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)
+    {
+      dev->AddBridgePort (*i);
+    }
+  return devs;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/helper/bridge-helper.h	Mon Aug 11 10:30:46 2008 -0700
@@ -0,0 +1,26 @@
+#ifndef BRIDGE_HELPER_H
+#define BRIDGE_HELPER_H
+
+#include "net-device-container.h"
+#include "ns3/object-factory.h"
+#include <string>
+
+namespace ns3 {
+
+class Node;
+class AttributeValue;
+
+class BridgeHelper
+{
+public:
+  BridgeHelper ();
+  void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
+  NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
+private:
+  ObjectFactory m_deviceFactory;
+};
+
+} // namespace ns3
+
+
+#endif /* BRIDGE_HELPER_H */
--- a/src/helper/wscript	Sun Aug 10 15:45:27 2008 -0400
+++ b/src/helper/wscript	Mon Aug 11 10:30:46 2008 -0700
@@ -20,6 +20,7 @@
         'packet-socket-helper.cc',
         'ipv4-interface-container.cc',
         'udp-echo-helper.cc',
+        'bridge-helper.cc',
         ]
 
     headers = bld.create_obj('ns3header')
@@ -42,4 +43,5 @@
         'packet-socket-helper.h',
         'ipv4-interface-container.h',
         'udp-echo-helper.h',
+        'bridge-helper.h',
         ]