Add Configuration BPDU implementation
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 21:05:53 +0000 (22:05 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 21:05:53 +0000 (22:05 +0100)
src/devices/bridge/model/bpdu-header.h
src/devices/bridge/model/configuration-bpdu-header.cc [new file with mode: 0644]
src/devices/bridge/wscript

index 18df92a4127ac7bf9d23fa9f666b7d6ce9a09482..e3744e3138ca71e51bf8978d377bf7259fa95c96 100644 (file)
@@ -81,6 +81,39 @@ public:
   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/configuration-bpdu-header.cc b/src/devices/bridge/model/configuration-bpdu-header.cc
new file mode 100644 (file)
index 0000000..1d744aa
--- /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("ConfigurationBpduHeader");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED(ConfigurationBpduHeader);
+
+uint8_t ConfigurationBpduHeader::GetFlags(){
+       return m_flags;
+}
+
+BpduBridgeIdentifier ConfigurationBpduHeader::GetRoot(){
+       return m_root;
+}
+
+uint32_t ConfigurationBpduHeader::GetRootCost(){
+       return m_rootPath;
+}
+
+BpduBridgeIdentifier ConfigurationBpduHeader::GetBridge(){
+       return m_bridge;
+}
+
+uint32_t ConfigurationBpduHeader::GetBridgeCost(){
+       return m_bridgePath;
+}
+
+uint16_t ConfigurationBpduHeader::GetPort(){
+       return m_port;
+}
+
+uint16_t ConfigurationBpduHeader::GetMessageAge(){
+       return m_messageAge;
+}
+
+uint16_t ConfigurationBpduHeader::GetMaxAge(){
+       return m_maxAge;
+}
+
+uint16_t ConfigurationBpduHeader::GetHelloTime(){
+       return m_helloTime;
+}
+
+uint16_t ConfigurationBpduHeader::GetForwardDelay(){
+       return m_forwardDelay;
+}
+
+void ConfigurationBpduHeader::SetFlags(uint8_t flags){
+       m_flags = flags;
+}
+
+void ConfigurationBpduHeader::SetRoot(BpduBridgeIdentifier root, uint32_t rootPath){
+       m_root = root; 
+       m_rootPath = rootPath;
+}
+
+void ConfigurationBpduHeader::SetBridge(BpduBridgeIdentifier bridge, uint32_t bridgePath){
+       m_bridge = bridge;
+       m_bridgePath = bridgePath;
+}
+
+void ConfigurationBpduHeader::SetPort(uint16_t port){
+       m_port = port;
+}
+
+void ConfigurationBpduHeader::SetMessageAge(uint16_t messageAge){
+       m_messageAge = messageAge;
+}
+
+void ConfigurationBpduHeader::SetMaxAge(uint16_t maxAge){
+       m_maxAge = maxAge;
+}
+
+void ConfigurationBpduHeader::SetHelloTime(uint16_t helloTime){
+       m_helloTime = helloTime;
+}
+
+void ConfigurationBpduHeader::SetForwardDelay(uint16_t forwardDelay){
+       m_forwardDelay = forwardDelay;
+}
+
+TypeId ConfigurationBpduHeader::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::ConfigurationBpduHeader")
+    .SetParent<Header> ()
+    .AddConstructor<ConfigurationBpduHeader> ()
+    ;
+  return tid;
+}
+
+TypeId ConfigurationBpduHeader::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void ConfigurationBpduHeader::Print (std::ostream &os) const
+{
+       os << "configuration "
+          << "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 ConfigurationBpduHeader::GetSerializedSize (void) const
+{
+  /* this is the size of a Configuration BPDU excluding the BPDU Header. */
+  return 31;
+}
+
+void ConfigurationBpduHeader::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);
+}
+uint32_t
+ConfigurationBpduHeader::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 ();
+
+  return GetSerializedSize ();
+}
+
+
+}
+
+
index 540f8622403bd13e16398df2f20e432ecf7346af..41a246bef69e1fe3c889973da6d72430e8992493 100644 (file)
@@ -10,7 +10,8 @@ def build(bld):
         'model/bridge-channel.cc',
        'helper/moose-bridge-helper.cc',
         'helper/bridge-helper.cc',
-       'model/bpdu-header.cc'
+       'model/bpdu-header.cc',
+       'model/configuration-bpdu-header.cc',
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'bridge'