Add Rapid Spanning Tree Protocol base
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 8 May 2011 16:27:18 +0000 (17:27 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 8 May 2011 16:27:18 +0000 (17:27 +0100)
src/devices/bridge/model/rstp-l3-protocol.cc [new file with mode: 0644]
src/devices/bridge/model/rstp-l3-protocol.h [new file with mode: 0644]
src/devices/bridge/wscript

diff --git a/src/devices/bridge/model/rstp-l3-protocol.cc b/src/devices/bridge/model/rstp-l3-protocol.cc
new file mode 100644 (file)
index 0000000..172fd11
--- /dev/null
@@ -0,0 +1,66 @@
+
+#include "ns3/packet.h"
+#include "ns3/log.h"
+#include "ns3/node.h"
+#include "rstp-l3-protocol.h"
+
+NS_LOG_COMPONENT_DEFINE("RstpL3Protocol");
+
+namespace ns3 {
+
+const uint16_t RstpL3Protocol::PROT_NUMBER = 0x0; // TODO
+
+NS_OBJECT_ENSURE_REGISTERED (RstpL3Protocol);
+
+TypeId RstpL3Protocol::GetTypeId(void){
+       static TypeId tid = TypeId("ns3::RstpL3Protocol")
+               .SetParent<Object> ()
+               .AddConstructor<RstpL3Protocol> ();
+
+       return tid;
+}
+
+RstpL3Protocol::RstpL3Protocol(){
+       NS_LOG_FUNCTION(this);
+}
+
+RstpL3Protocol::~RstpL3Protocol(){
+       NS_LOG_FUNCTION(this);
+}
+
+void RstpL3Protocol::SetBridge(Ptr<EthernetBridgeNetDevice> bridge){
+       NS_LOG_FUNCTION(this);
+       m_bridge = bridge;
+}
+
+void RstpL3Protocol::SetNode(Ptr<Node> node){
+       NS_LOG_FUNCTION(this);
+       m_node = node;
+}
+
+void RstpL3Protocol::DoDispose(){
+       NS_LOG_FUNCTION(this);
+       m_node = 0;
+       Object::DoDispose();
+}
+
+void RstpL3Protocol::NotifyNewAggregate(){
+       if(m_node == 0){
+               Ptr<Node> node = this->GetObject<Node>();
+
+               if(node != 0){
+                       this->SetNode(node);
+               }
+       }
+       if(m_bridge == 0){
+               Ptr<EthernetBridgeNetDevice> bridge = this->GetObject<EthernetBridgeNetDevice>();
+               
+               if(bridge != 0){
+                       this->SetBridge(bridge);
+               }
+       }
+       Object::NotifyNewAggregate();
+}
+
+}
+
diff --git a/src/devices/bridge/model/rstp-l3-protocol.h b/src/devices/bridge/model/rstp-l3-protocol.h
new file mode 100644 (file)
index 0000000..5028cbe
--- /dev/null
@@ -0,0 +1,53 @@
+
+#ifndef RSTP_L3_PROTOCOL_H
+#define RSTP_L3_PROTOCOL_H
+
+#include "ethernet-bridge-net-device.h"
+
+namespace ns3 {
+
+/**
+ * \ingroup bridge
+ * \brief Implement the Rapid Spanning Tree Protocol (RSTP)
+ *
+ * This is the implementation of RSTP
+**/
+
+class RstpL3Protocol : public Object {
+
+public:
+       static TypeId GetTypeId (void);
+       static const uint16_t PROT_NUMBER;
+       
+       RstpL3Protocol ();
+       virtual ~RstpL3Protocol ();
+       
+       void SetNode(Ptr<Node> node);
+       void SetBridge(Ptr<EthernetBridgeNetDevice> bridge);
+
+       /**
+        * \brief Recieve a packet
+        */
+
+       void Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType);
+
+protected:
+
+       virtual void DoDispose();
+       virtual void NotifyNewAggregate();
+
+private:
+
+       RstpL3Protocol(const RstpL3Protocol &o);
+       RstpL3Protocol &operator=(const RstpL3Protocol &o);
+
+       Ptr<EthernetBridgeNetDevice> m_bridge;
+       Ptr<Node> m_node;
+
+};
+
+
+}
+
+#endif
+
index 26d8ea2a51f2bc672da18fd3a279bddeca932991..f404fd695c861c9513c31aab173a3eb2798350dc 100644 (file)
@@ -17,12 +17,14 @@ def build(bld):
        'model/configuration-bpdu-header.cc',
        'model/tcn-bpdu-header.cc',
        'model/rst-bpdu-header.cc',
+       'model/rstp-l3-protocol.cc',
         'helper/ethernet-bridge-helper.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'bridge'
     headers.source = [
        'model/bpdu-header.h',
+       'model/rstp-l3-protocol.h',
        'model/ethernet-bridge-state.h',
        'model/ethernet-bridge-port-net-device.h',
        'model/ethernet-bridge-net-device.h',