bug 276: bridge netdevice has no helper class.
1.1 --- a/examples/csma-bridge.cc Sun Aug 10 15:45:27 2008 -0400
1.2 +++ b/examples/csma-bridge.cc Mon Aug 11 10:30:46 2008 -0700
1.3 @@ -94,14 +94,8 @@
1.4
1.5 // Create the bridge netdevice, which will do the packet switching
1.6 Ptr<Node> switchNode = csmaSwitch.Get (0);
1.7 - Ptr<BridgeNetDevice> bridgeDevice = CreateObject<BridgeNetDevice> ();
1.8 - switchNode->AddDevice (bridgeDevice);
1.9 -
1.10 - for (NetDeviceContainer::Iterator portIter = switchDevices.Begin ();
1.11 - portIter != switchDevices.End (); portIter++)
1.12 - {
1.13 - bridgeDevice->AddBridgePort (*portIter);
1.14 - }
1.15 + BridgeHelper bridge;
1.16 + bridge.Install (switchNode, switchDevices);
1.17
1.18 // Add internet stack to the terminals
1.19 InternetStackHelper internet;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/helper/bridge-helper.cc Mon Aug 11 10:30:46 2008 -0700
2.3 @@ -0,0 +1,34 @@
2.4 +#include "bridge-helper.h"
2.5 +
2.6 +#include "ns3/bridge-net-device.h"
2.7 +#include "ns3/node.h"
2.8 +
2.9 +namespace ns3 {
2.10 +
2.11 +BridgeHelper::BridgeHelper ()
2.12 +{
2.13 + m_deviceFactory.SetTypeId ("ns3::BridgeNetDevice");
2.14 +}
2.15 +
2.16 +void
2.17 +BridgeHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
2.18 +{
2.19 + m_deviceFactory.Set (n1, v1);
2.20 +}
2.21 +
2.22 +NetDeviceContainer
2.23 +BridgeHelper::Install (Ptr<Node> node, NetDeviceContainer c)
2.24 +{
2.25 + NetDeviceContainer devs;
2.26 + Ptr<BridgeNetDevice> dev = m_deviceFactory.Create<BridgeNetDevice> ();
2.27 + devs.Add (dev);
2.28 + node->AddDevice (dev);
2.29 +
2.30 + for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
2.31 + {
2.32 + dev->AddBridgePort (*i);
2.33 + }
2.34 + return devs;
2.35 +}
2.36 +
2.37 +} // namespace ns3
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/helper/bridge-helper.h Mon Aug 11 10:30:46 2008 -0700
3.3 @@ -0,0 +1,26 @@
3.4 +#ifndef BRIDGE_HELPER_H
3.5 +#define BRIDGE_HELPER_H
3.6 +
3.7 +#include "net-device-container.h"
3.8 +#include "ns3/object-factory.h"
3.9 +#include <string>
3.10 +
3.11 +namespace ns3 {
3.12 +
3.13 +class Node;
3.14 +class AttributeValue;
3.15 +
3.16 +class BridgeHelper
3.17 +{
3.18 +public:
3.19 + BridgeHelper ();
3.20 + void SetDeviceAttribute (std::string n1, const AttributeValue &v1);
3.21 + NetDeviceContainer Install (Ptr<Node> node, NetDeviceContainer c);
3.22 +private:
3.23 + ObjectFactory m_deviceFactory;
3.24 +};
3.25 +
3.26 +} // namespace ns3
3.27 +
3.28 +
3.29 +#endif /* BRIDGE_HELPER_H */
4.1 --- a/src/helper/wscript Sun Aug 10 15:45:27 2008 -0400
4.2 +++ b/src/helper/wscript Mon Aug 11 10:30:46 2008 -0700
4.3 @@ -20,6 +20,7 @@
4.4 'packet-socket-helper.cc',
4.5 'ipv4-interface-container.cc',
4.6 'udp-echo-helper.cc',
4.7 + 'bridge-helper.cc',
4.8 ]
4.9
4.10 headers = bld.create_obj('ns3header')
4.11 @@ -42,4 +43,5 @@
4.12 'packet-socket-helper.h',
4.13 'ipv4-interface-container.h',
4.14 'udp-echo-helper.h',
4.15 + 'bridge-helper.h',
4.16 ]