From 5c7fa096dfadedd2f2927e931879c04b0f4450f6 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Sun, 8 May 2011 17:27:18 +0100 Subject: [PATCH] Add Rapid Spanning Tree Protocol base --- src/devices/bridge/model/rstp-l3-protocol.cc | 66 ++++++++++++++++++++ src/devices/bridge/model/rstp-l3-protocol.h | 53 ++++++++++++++++ src/devices/bridge/wscript | 2 + 3 files changed, 121 insertions(+) create mode 100644 src/devices/bridge/model/rstp-l3-protocol.cc create mode 100644 src/devices/bridge/model/rstp-l3-protocol.h diff --git a/src/devices/bridge/model/rstp-l3-protocol.cc b/src/devices/bridge/model/rstp-l3-protocol.cc new file mode 100644 index 0000000..172fd11 --- /dev/null +++ b/src/devices/bridge/model/rstp-l3-protocol.cc @@ -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 () + .AddConstructor (); + + return tid; +} + +RstpL3Protocol::RstpL3Protocol(){ + NS_LOG_FUNCTION(this); +} + +RstpL3Protocol::~RstpL3Protocol(){ + NS_LOG_FUNCTION(this); +} + +void RstpL3Protocol::SetBridge(Ptr bridge){ + NS_LOG_FUNCTION(this); + m_bridge = bridge; +} + +void RstpL3Protocol::SetNode(Ptr 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 = this->GetObject(); + + if(node != 0){ + this->SetNode(node); + } + } + if(m_bridge == 0){ + Ptr bridge = this->GetObject(); + + 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 index 0000000..5028cbe --- /dev/null +++ b/src/devices/bridge/model/rstp-l3-protocol.h @@ -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); + void SetBridge(Ptr bridge); + + /** + * \brief Recieve a packet + */ + + void Receive(Ptr device, Ptr 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 m_bridge; + Ptr m_node; + +}; + + +} + +#endif + diff --git a/src/devices/bridge/wscript b/src/devices/bridge/wscript index 26d8ea2..f404fd6 100644 --- a/src/devices/bridge/wscript +++ b/src/devices/bridge/wscript @@ -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', -- 2.34.1