Rapid Spanning Tree BPDU
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 21:52:15 +0000 (22:52 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 21:52:15 +0000 (22:52 +0100)
src/devices/bridge/model/bpdu-header.h
src/devices/bridge/model/rst-bpdu-header.cc [new file with mode: 0644]
src/devices/bridge/wscript

index e3744e3138ca71e51bf8978d377bf7259fa95c96..333b4ff352d01790c63eb7ca61327c5caae9058e 100644 (file)
@@ -144,6 +144,48 @@ public:
 
 class RstBpduHeader : public Header {
 
+public:
+
+       static TypeId GetTypeId (void);
+       virtual TypeId GetInstanceTypeId (void) const;
+       virtual void Print (std::ostream &os) const;
+       virtual uint32_t GetSerializedSize (void) const;
+       virtual void Serialize (Buffer::Iterator start) const;
+       virtual uint32_t Deserialize (Buffer::Iterator start);
+
+       uint8_t GetFlags();
+       BpduBridgeIdentifier GetRoot();
+       uint32_t GetRootCost();
+       BpduBridgeIdentifier GetBridge();
+       uint32_t GetBridgeCost();
+       uint16_t GetPort();
+       uint16_t GetMessageAge();
+       uint16_t GetMaxAge();
+       uint16_t GetHelloTime();
+       uint16_t GetForwardDelay();
+
+       void SetFlags(uint8_t);
+       void SetRoot(BpduBridgeIdentifier, uint32_t);
+       void SetBridge(BpduBridgeIdentifier, uint32_t);
+       void SetPort(uint16_t);
+       void SetMessageAge(uint16_t);
+       void SetMaxAge(uint16_t);
+       void SetHelloTime(uint16_t);
+       void SetForwardDelay(uint16_t);
+
+private:
+
+       uint8_t m_flags;
+       BpduBridgeIdentifier m_root;
+       uint32_t m_rootPath;
+       BpduBridgeIdentifier m_bridge;
+       uint32_t m_bridgePath;
+       uint16_t m_port;
+       uint16_t m_messageAge;
+       uint16_t m_maxAge;
+       uint16_t m_helloTime;
+       uint16_t m_forwardDelay;
+
 };
 
 }
diff --git a/src/devices/bridge/model/rst-bpdu-header.cc b/src/devices/bridge/model/rst-bpdu-header.cc
new file mode 100644 (file)
index 0000000..54de2eb
--- /dev/null
@@ -0,0 +1,180 @@
+/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 Richard Whitehouse
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Richard Whitehouse <ns3@richardwhiuk.com>
+ */
+
+#include "bpdu-header.h"
+#include "ns3/address-utils.h"
+#include "ns3/log.h"
+
+NS_LOG_COMPONENT_DEFINE("RstBpduHeader");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED(RstBpduHeader);
+
+uint8_t RstBpduHeader::GetFlags(){
+       return m_flags;
+}
+
+BpduBridgeIdentifier RstBpduHeader::GetRoot(){
+       return m_root;
+}
+
+uint32_t RstBpduHeader::GetRootCost(){
+       return m_rootPath;
+}
+
+BpduBridgeIdentifier RstBpduHeader::GetBridge(){
+       return m_bridge;
+}
+
+uint32_t RstBpduHeader::GetBridgeCost(){
+       return m_bridgePath;
+}
+
+uint16_t RstBpduHeader::GetPort(){
+       return m_port;
+}
+
+uint16_t RstBpduHeader::GetMessageAge(){
+       return m_messageAge;
+}
+
+uint16_t RstBpduHeader::GetMaxAge(){
+       return m_maxAge;
+}
+
+uint16_t RstBpduHeader::GetHelloTime(){
+       return m_helloTime;
+}
+
+uint16_t RstBpduHeader::GetForwardDelay(){
+       return m_forwardDelay;
+}
+
+void RstBpduHeader::SetFlags(uint8_t flags){
+       m_flags = flags;
+}
+
+void RstBpduHeader::SetRoot(BpduBridgeIdentifier root, uint32_t rootPath){
+       m_root = root; 
+       m_rootPath = rootPath;
+}
+
+void RstBpduHeader::SetBridge(BpduBridgeIdentifier bridge, uint32_t bridgePath){
+       m_bridge = bridge;
+       m_bridgePath = bridgePath;
+}
+
+void RstBpduHeader::SetPort(uint16_t port){
+       m_port = port;
+}
+
+void RstBpduHeader::SetMessageAge(uint16_t messageAge){
+       m_messageAge = messageAge;
+}
+
+void RstBpduHeader::SetMaxAge(uint16_t maxAge){
+       m_maxAge = maxAge;
+}
+
+void RstBpduHeader::SetHelloTime(uint16_t helloTime){
+       m_helloTime = helloTime;
+}
+
+void RstBpduHeader::SetForwardDelay(uint16_t forwardDelay){
+       m_forwardDelay = forwardDelay;
+}
+
+TypeId RstBpduHeader::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::RstBpduHeader")
+    .SetParent<Header> ()
+    .AddConstructor<RstBpduHeader> ()
+    ;
+  return tid;
+}
+
+TypeId RstBpduHeader::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void RstBpduHeader::Print (std::ostream &os) const
+{
+       os << "rapid spanning tree "
+          << "flags: " << m_flags << " "
+          << "root: " << m_root.priority << " " << m_root.address
+          << "root path cost: " << m_rootPath << " "
+          << "bridge: " << m_bridge.priority << " " << m_bridge.address
+          << "bridge path cost: " << m_bridgePath << " "
+          << "port: " << m_port << " "
+          << "age: " << m_messageAge << "/" << m_maxAge << " "
+          << "hello: " << m_helloTime << " "
+          << "forward: " << m_forwardDelay << " "
+         ;
+}
+
+uint32_t RstBpduHeader::GetSerializedSize (void) const
+{
+  /* this is the size of a Configuration BPDU excluding the BPDU Header. */
+  return 32;
+}
+
+void RstBpduHeader::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+
+  i.WriteU8 (m_flags);
+  i.WriteHtonU16 (m_root.priority);
+  WriteTo(i, m_root.address);
+  i.WriteHtonU32 (m_rootPath);
+  i.WriteHtonU16 (m_bridge.priority);
+  WriteTo(i, m_bridge.address);
+  i.WriteHtonU32 (m_bridgePath);
+  i.WriteHtonU16 (m_port);
+  i.WriteHtonU16 (m_messageAge);
+  i.WriteHtonU16 (m_maxAge);
+  i.WriteHtonU16 (m_helloTime);
+  i.WriteHtonU16 (m_forwardDelay);
+  i.WriteU8 (0);
+}
+uint32_t
+RstBpduHeader::Deserialize (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  m_flags = i.ReadU8 ();
+  m_root.priority = i.ReadNtohU16 ();
+  ReadFrom (i, m_root.address);
+  m_rootPath = i.ReadNtohU32 ();
+  m_bridge.priority = i.ReadNtohU16 ();
+  ReadFrom (i, m_bridge.address);
+  m_bridgePath = i.ReadNtohU32 ();
+  m_port = i.ReadNtohU16 ();
+  m_messageAge = i.ReadNtohU16 ();
+  m_maxAge = i.ReadNtohU16 ();
+  m_helloTime = i.ReadNtohU16 ();
+  m_forwardDelay = i.ReadNtohU16 ();
+  i.ReadU8();
+
+  return GetSerializedSize ();
+}
+}
+
+
index 2c7acf8d3801ba5ae608de63c69769b15747a10e..3f1fe86b3adb5928ef8ffe8321cdc824e07063f9 100644 (file)
@@ -13,6 +13,7 @@ def build(bld):
        'model/bpdu-header.cc',
        'model/configuration-bpdu-header.cc',
        'model/tcn-bpdu-header.cc',
+       'model/rst-bpdu-header.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'bridge'