Implemented BpduHeader
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 17:17:22 +0000 (18:17 +0100)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 17 Apr 2011 17:17:22 +0000 (18:17 +0100)
src/devices/bridge/model/bpdu-header.cc [new file with mode: 0644]
src/devices/bridge/model/bpdu-header.h
src/devices/bridge/wscript

diff --git a/src/devices/bridge/model/bpdu-header.cc b/src/devices/bridge/model/bpdu-header.cc
new file mode 100644 (file)
index 0000000..3faf302
--- /dev/null
@@ -0,0 +1,104 @@
+/* -*-  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/log.h"
+
+NS_LOG_COMPONENT_DEFINE("BpduHeader");
+
+namespace ns3 {
+
+NS_OBJECT_ENSURE_REGISTERED(BpduHeader);
+
+void BpduHeader::SetProtocol(uint16_t protocolIdentifier){
+       m_protocolIdentifier = protocolIdentifier;
+}
+
+void BpduHeader::SetVersion(uint8_t versionIdentifier){
+       m_versionIdentifier = versionIdentifier;
+}
+
+void BpduHeader::SetType(uint8_t bpduType){
+       m_bpduType = bpduType;
+}
+
+uint16_t BpduHeader::GetProtocol(){
+       return m_protocolIdentifier;
+}
+
+uint8_t BpduHeader::GetVersion(){
+       return m_versionIdentifier;
+}
+
+uint8_t BpduHeader::GetType(){
+       return m_bpduType;
+}
+
+TypeId BpduHeader::GetTypeId (void)
+{
+  static TypeId tid = TypeId ("ns3::BpduHeader")
+    .SetParent<Header> ()
+    .AddConstructor<BpduHeader> ()
+    ;
+  return tid;
+}
+
+TypeId BpduHeader::GetInstanceTypeId (void) const
+{
+  return GetTypeId ();
+}
+
+void BpduHeader::Print (std::ostream &os) const
+{
+       os << "bpdu "
+          << "protocol: " << m_protocolIdentifier << " "
+          << "version: " << m_versionIdentifier << " "
+          << "type: " << m_bpduType << " "
+         ;
+}
+
+uint32_t BpduHeader::GetSerializedSize (void) const
+{
+  /* this is the size of a BPDU Header excluding the Type. */
+  return 4;
+}
+
+void BpduHeader::Serialize (Buffer::Iterator start) const
+{
+  Buffer::Iterator i = start;
+
+  i.WriteHtonU16 (m_protocolIdentifier);
+  i.WriteU8 (m_versionIdentifier);
+  i.WriteU8 (m_bpduType);
+}
+uint32_t
+BpduHeader::Deserialize (Buffer::Iterator start)
+{
+  Buffer::Iterator i = start;
+  m_protocolIdentifier = i.ReadNtohU16 ();
+  m_versionIdentifier = i.ReadU8 ();
+  m_bpduType = i.ReadU8 ();
+
+  return GetSerializedSize ();
+}
+
+
+}
+
index 5126ea79877d325c1597d572748dffa416865abe..eb2dc57404d93ff8cd3735de2776bad7f017db8f 100644 (file)
@@ -22,8 +22,6 @@
 #define BRIDGE_BPDU_HEADER_H
 
 #include "ns3/header.h"
-#include "ns3/address.h"
-#include "ns3/ipv4-address.h"
 #include <string>
 
 namespace ns3 {
@@ -36,26 +34,26 @@ class BpduHeader : public Header {
 
 public:
 
-       uint16_t getProtocol();
-       uint8_t getVersion();
-       uint8_t getType();
+       uint16_t GetProtocol();
+       uint8_t GetVersion();
+       uint8_t GetType();
 
-       void setProtocol(uint16_t);
-       void setVersion(uint8_t);
-       void setType(uint8_t);
+       void SetProtocol(uint16_t);
+       void SetVersion(uint8_t);
+       void SetType(uint8_t);
 
-  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);
+       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);
 
-private;
+private:
 
-       uint16_t protocolIdentifier;
-       uint8_t versionIdentifier;
-       uint8_t bpduType;
+       uint16_t m_protocolIdentifier;
+       uint8_t m_versionIdentifier;
+       uint8_t m_bpduType;
 
 
 };
@@ -70,9 +68,6 @@ class ConfigurationBpduHeader : public Header {
 
 public:
 
-  
-
-
   static TypeId GetTypeId (void);
   virtual TypeId GetInstanceTypeId (void) const;
   virtual void Print (std::ostream &os) const;
@@ -112,6 +107,7 @@ class RstBpduHeader : public Header {
 
 };
 
+}
 
 #endif
 
index 2cf17d14e0ce721eb12d9fca462f7b99b994a037..540f8622403bd13e16398df2f20e432ecf7346af 100644 (file)
@@ -10,6 +10,7 @@ def build(bld):
         'model/bridge-channel.cc',
        'helper/moose-bridge-helper.cc',
         'helper/bridge-helper.cc',
+       'model/bpdu-header.cc'
         ]
     headers = bld.new_task_gen('ns3header')
     headers.module = 'bridge'