Add ability to disable ports in order to form a tree.
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 07:05:57 +0000 (07:05 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 20 Feb 2011 07:05:57 +0000 (07:05 +0000)
code/src/devices/bridge/model/bridge-port-net-device.cc
code/src/devices/bridge/model/bridge-port-net-device.h

index 5a68c8f5a994bd2f825d6c3733cdb1afc63dff51..6406e852b43b4d6b9c16d182126e736127fbb38f 100644 (file)
@@ -40,7 +40,7 @@ BridgePortNetDevice::GetTypeId (void)
 }
 
 
-BridgePortNetDevice::BridgePortNetDevice(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node) : m_bridge(bridge), m_device(device){
+BridgePortNetDevice::BridgePortNetDevice(Ptr<BridgeNetDevice> bridge, Ptr<NetDevice> device, Ptr<Node> node) : m_bridge(bridge), m_device(device), m_enabled(true){
   NS_LOG_FUNCTION_NOARGS ();
 
   if (!Mac48Address::IsMatchingType (device->GetAddress()))
@@ -62,10 +62,16 @@ BridgePortNetDevice::~BridgePortNetDevice(){
   NS_LOG_FUNCTION_NOARGS ();
 }
 
+void BridgePortNetDevice::SetEnabled(bool enabled){
+       m_enabled = enabled;
+}
+
 void BridgePortNetDevice::Send(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber){
        NS_LOG_FUNCTION_NOARGS ();
-       NS_LOG_LOGIC("SendingPacket(src=" << source << ", dest=" << dest << ")");
-       m_device->SendFrom(packet->Copy(), source, dest, protocolNumber);
+       if(m_enabled){
+               NS_LOG_LOGIC("SendingPacket(src=" << source << ", dest=" << dest << ")");
+               m_device->SendFrom(packet->Copy(), source, dest, protocolNumber);
+       }
 }
 
 Ptr<NetDevice> BridgePortNetDevice::GetDevice(){
@@ -81,6 +87,9 @@ BridgePortNetDevice::Receive (Ptr<NetDevice> incomingPort, Ptr<const Packet> pac
                                     Address const &src, Address const &dst, NetDevice::PacketType packetType)
 {
   NS_LOG_FUNCTION_NOARGS ();
+
+  if(m_enabled){
+
   NS_LOG_LOGIC ("UID is " << packet->GetUid ());
 
   NS_LOG_LOGIC ("LearningBridgeForward (incomingPort=" << incomingPort->GetInstanceTypeId ().GetName ()
@@ -91,6 +100,8 @@ BridgePortNetDevice::Receive (Ptr<NetDevice> incomingPort, Ptr<const Packet> pac
 
   m_bridge->Forward(this, packet, protocol, src, dst, packetType);
 
+  }
+
 }
 
 }
index 58b05f1ffe388dd0475ae2046cb7d795a3440528..3239454dcd43344281243d42bb6e38c7acf73b0c 100644 (file)
@@ -47,11 +47,14 @@ public:
 
   virtual void Send (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber);
 
+  virtual void SetEnabled(bool enabled);
+
 protected:
   virtual void Receive (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, Address const &source, Address const &destination, NetDevice::PacketType packetType);
   
   Ptr<BridgeNetDevice> m_bridge;
   Ptr<NetDevice> m_device;
+  bool m_enabled;
 
 };