diff --git a/samples/main-header.cc b/samples/main-header.cc index 3094ee7ed..4c8f4920f 100644 --- a/samples/main-header.cc +++ b/samples/main-header.cc @@ -17,13 +17,13 @@ public: void SetData (uint16_t data); uint16_t GetData (void) const; -private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); - virtual uint32_t GetSerializedSize (void) const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); + uint32_t GetSerializedSize (void) const; +private: uint16_t m_data; }; @@ -47,14 +47,14 @@ MyHeader::GetUid (void) } std::string -MyHeader::DoGetName (void) const +MyHeader::GetName (void) const { // This string is used to identify the type of // my header by the packet printing routines. return "MYHEADER"; } void -MyHeader::PrintTo (std::ostream &os) const +MyHeader::Print (std::ostream &os) const { // This method is invoked by the packet printing // routines to print the content of my header. @@ -67,14 +67,14 @@ MyHeader::GetSerializedSize (void) const return 2; } void -MyHeader::SerializeTo (Buffer::Iterator start) const +MyHeader::Serialize (Buffer::Iterator start) const { // we can serialize two bytes at the start of the buffer. // we write them in network byte order. start.WriteHtonU16 (m_data); } uint32_t -MyHeader::DeserializeFrom (Buffer::Iterator start) +MyHeader::Deserialize (Buffer::Iterator start) { // we can deserialize two bytes from the start of the buffer. // we read them in network byte order and store them diff --git a/src/common/chunk.cc b/src/common/chunk-registry.cc similarity index 82% rename from src/common/chunk.cc rename to src/common/chunk-registry.cc index e582d884b..7186524ab 100644 --- a/src/common/chunk.cc +++ b/src/common/chunk-registry.cc @@ -19,55 +19,11 @@ * Author: Mathieu Lacage */ -#include "chunk.h" +#include "chunk-registry.h" #include "ns3/assert.h" namespace ns3 { -Chunk::Chunk () -{} - -Chunk::~Chunk () -{} - -std::string -Chunk::GetName (void) const -{ - return DoGetName (); -} -void -Chunk::Print (std::ostream &os) const -{ - PrintTo (os); -} -uint32_t -Chunk::GetSize (void) const -{ - return GetSerializedSize (); -} -void -Chunk::Serialize (Buffer::Iterator start) const -{ - SerializeTo (start); -} -uint32_t -Chunk::Deserialize (Buffer::Iterator start) -{ - uint32_t deserialized = DeserializeFrom (start); - return deserialized; -} -std::ostream& operator<< (std::ostream& os, Chunk const& chunk) -{ - chunk.Print (os); - return os; -} - - -/************************************** - * The Chunk Registry below - ***************************************/ - - ChunkRegistry::InfoVector * ChunkRegistry::GetInfoVector (void) { diff --git a/src/common/chunk.h b/src/common/chunk-registry.h similarity index 89% rename from src/common/chunk.h rename to src/common/chunk-registry.h index 193cb2bba..34e3e42ec 100644 --- a/src/common/chunk.h +++ b/src/common/chunk-registry.h @@ -19,8 +19,8 @@ * Author: Mathieu Lacage */ -#ifndef CHUNK_H -#define CHUNK_H +#ifndef CHUNK_REGISTRY_H +#define CHUNK_REGISTRY_H #include #include @@ -30,26 +30,6 @@ namespace ns3 { -class Chunk { -public: - Chunk (); - virtual ~Chunk (); - - std::string GetName (void) const; - void Print (std::ostream &os) const; - uint32_t GetSize (void) const; - void Serialize (Buffer::Iterator start) const; - uint32_t Deserialize (Buffer::Iterator start); -private: - virtual std::string DoGetName (void) const = 0; - virtual void PrintTo (std::ostream &os) const = 0; - virtual uint32_t GetSerializedSize (void) const = 0; - virtual void SerializeTo (Buffer::Iterator i) const = 0; - virtual uint32_t DeserializeFrom (Buffer::Iterator i) = 0; -}; - -std::ostream& operator<< (std::ostream& os, Chunk const& chunk); - /** * \brief this registry keeps track of all different * types of headers and trailers and assigns to each of them diff --git a/src/common/header.cc b/src/common/header.cc deleted file mode 100644 index 82bb25b09..000000000 --- a/src/common/header.cc +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005 INRIA - * All rights reserved. - * - * 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: Mathieu Lacage - */ - -#include "header.h" - -namespace ns3 { - -Header::~Header () -{} - -} // namespace ns3 diff --git a/src/common/header.h b/src/common/header.h index 39ff037c6..6d8db4575 100644 --- a/src/common/header.h +++ b/src/common/header.h @@ -22,7 +22,7 @@ #ifndef HEADER_H #define HEADER_H -#include "chunk.h" +#include "chunk-registry.h" /** * \relates Header @@ -87,12 +87,12 @@ namespace ns3 { * Sample code which shows how to create a new Header, and how to use it, * is shown in the sample file samples/main-header.cc */ -class Header : public Chunk { +class Header { public: - virtual ~Header (); protected: template static uint32_t Register (std::string uuid); +#if 0 private: /** * \returns a user-readable name to identify this type of header. @@ -143,6 +143,7 @@ private: * Packet::RemoveHeader */ virtual uint32_t DeserializeFrom (Buffer::Iterator start) = 0; +#endif }; } // namespace ns3 diff --git a/src/common/packet-metadata-test.cc b/src/common/packet-metadata-test.cc index 1196a7342..c3f829acc 100644 --- a/src/common/packet-metadata-test.cc +++ b/src/common/packet-metadata-test.cc @@ -38,12 +38,12 @@ public: static uint32_t GetUid (void); HistoryHeader (); bool IsOk (void) const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); bool m_ok; }; @@ -71,7 +71,7 @@ HistoryHeader::IsOk (void) const template std::string -HistoryHeader::DoGetName (void) const +HistoryHeader::GetName (void) const { std::ostringstream oss; oss << N; @@ -80,7 +80,7 @@ HistoryHeader::DoGetName (void) const template void -HistoryHeader::PrintTo (std::ostream &os) const +HistoryHeader::Print (std::ostream &os) const { NS_ASSERT (false); } @@ -92,13 +92,13 @@ HistoryHeader::GetSerializedSize (void) const } template void -HistoryHeader::SerializeTo (Buffer::Iterator start) const +HistoryHeader::Serialize (Buffer::Iterator start) const { start.WriteU8 (N, N); } template uint32_t -HistoryHeader::DeserializeFrom (Buffer::Iterator start) +HistoryHeader::Deserialize (Buffer::Iterator start) { m_ok = true; for (int i = 0; i < N; i++) @@ -118,12 +118,12 @@ public: static uint32_t GetUid (void); HistoryTrailer (); bool IsOk (void) const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); bool m_ok; }; @@ -152,7 +152,7 @@ HistoryTrailer::IsOk (void) const template std::string -HistoryTrailer::DoGetName (void) const +HistoryTrailer::GetName (void) const { std::ostringstream oss; oss << N; @@ -160,7 +160,7 @@ HistoryTrailer::DoGetName (void) const } template void -HistoryTrailer::PrintTo (std::ostream &os) const +HistoryTrailer::Print (std::ostream &os) const { NS_ASSERT (false); } @@ -172,14 +172,14 @@ HistoryTrailer::GetSerializedSize (void) const } template void -HistoryTrailer::SerializeTo (Buffer::Iterator start) const +HistoryTrailer::Serialize (Buffer::Iterator start) const { start.Prev (N); start.WriteU8 (N, N); } template uint32_t -HistoryTrailer::DeserializeFrom (Buffer::Iterator start) +HistoryTrailer::Deserialize (Buffer::Iterator start) { m_ok = true; start.Prev (N); diff --git a/src/common/packet-metadata.cc b/src/common/packet-metadata.cc index 6acbd2930..4229e15f8 100644 --- a/src/common/packet-metadata.cc +++ b/src/common/packet-metadata.cc @@ -23,8 +23,8 @@ #include "ns3/fatal-error.h" #include "ns3/debug.h" #include "packet-metadata.h" -#include "chunk.h" #include "buffer.h" +#include "chunk-registry.h" NS_DEBUG_COMPONENT_DEFINE ("PacketMetadata"); diff --git a/src/common/packet-printer.cc b/src/common/packet-printer.cc index b0c55b359..1419a0bb7 100644 --- a/src/common/packet-printer.cc +++ b/src/common/packet-printer.cc @@ -20,6 +20,7 @@ */ #include "packet-printer.h" +#include "chunk-registry.h" namespace ns3 { diff --git a/src/common/packet-printer.h b/src/common/packet-printer.h index 1799a3d67..22aede84c 100644 --- a/src/common/packet-printer.h +++ b/src/common/packet-printer.h @@ -24,7 +24,6 @@ #include "ns3/callback.h" #include "ns3/ptr.h" #include "buffer.h" -#include "chunk.h" #include namespace ns3 { diff --git a/src/common/packet.h b/src/common/packet.h index c9aa0beb2..b7f632641 100644 --- a/src/common/packet.h +++ b/src/common/packet.h @@ -118,7 +118,7 @@ public: uint32_t GetSize (void) const; /** * Add header to this packet. This method invokes the - * ns3::Chunk::GetSerializedSize and ns3::Chunk::SerializeTo + * ns3::Header::GetSerializedSize and ns3::Header::SerializeTo * methods to reserve space in the buffer and request the * header to serialize itself in the packet buffer. * @@ -128,7 +128,7 @@ public: void AddHeader (T const &header); /** * Deserialize and remove the header from the internal buffer. - * This method invokes ns3::Chunk::DeserializeFrom. + * This method invokes ns3::Header::DeserializeFrom. * * \param header a reference to the header to remove from the internal buffer. * \returns the number of bytes removed from the packet. @@ -137,7 +137,7 @@ public: uint32_t RemoveHeader (T &header); /** * Add trailer to this packet. This method invokes the - * ns3::Chunk::GetSerializedSize and ns3::Trailer::serializeTo + * ns3::Trailer::GetSerializedSize and ns3::Trailer::serializeTo * methods to reserve space in the buffer and request the trailer * to serialize itself in the packet buffer. * @@ -147,7 +147,7 @@ public: void AddTrailer (T const &trailer); /** * Remove a deserialized trailer from the internal buffer. - * This method invokes the ns3::Chunk::DeserializeFrom method. + * This method invokes the ns3::Trailer::DeserializeFrom method. * * \param trailer a reference to the trailer to remove from the internal buffer. * \returns the number of bytes removed from the end of the packet. @@ -416,9 +416,11 @@ template void Packet::AddHeader (T const &header) { - NS_ASSERT_MSG (dynamic_cast
(&header) != 0, - "Must pass Header subclass to Packet::AddHeader"); - uint32_t size = header.GetSize (); + const Header *testHeader; + // if the following assignment fails, it is because the + // input to this function is not a subclass of the Header class + testHeader = &header; + uint32_t size = header.GetSerializedSize (); m_buffer.AddAtStart (size); header.Serialize (m_buffer.Begin ()); m_metadata.AddHeader (header, size); @@ -427,8 +429,10 @@ template uint32_t Packet::RemoveHeader (T &header) { - NS_ASSERT_MSG (dynamic_cast
(&header) != 0, - "Must pass Header subclass to Packet::RemoveHeader"); + Header *testHeader; + // if the following assignment fails, it is because the + // input to this function is not a subclass of the Header class + testHeader = &header; uint32_t deserialized = header.Deserialize (m_buffer.Begin ()); m_buffer.RemoveAtStart (deserialized); m_metadata.RemoveHeader (header, deserialized); @@ -438,9 +442,11 @@ template void Packet::AddTrailer (T const &trailer) { - NS_ASSERT_MSG (dynamic_cast (&trailer) != 0, - "Must pass Trailer subclass to Packet::AddTrailer"); - uint32_t size = trailer.GetSize (); + const Trailer *testTrailer; + // if the following assignment fails, it is because the + // input to this function is not a subclass of the Trailer class + testTrailer = &trailer; + uint32_t size = trailer.GetSerializedSize (); m_buffer.AddAtEnd (size); Buffer::Iterator end = m_buffer.End (); trailer.Serialize (end); @@ -450,8 +456,10 @@ template uint32_t Packet::RemoveTrailer (T &trailer) { - NS_ASSERT_MSG (dynamic_cast (&trailer) != 0, - "Must pass Trailer subclass to Packet::RemoveTrailer"); + Trailer *testTrailer; + // if the following assignment fails, it is because the + // input to this function is not a subclass of the Trailer class + testTrailer = &trailer; uint32_t deserialized = trailer.Deserialize (m_buffer.End ()); m_buffer.RemoveAtEnd (deserialized); m_metadata.RemoveTrailer (trailer, deserialized); diff --git a/src/common/trailer.cc b/src/common/trailer.cc deleted file mode 100644 index 8026d2b92..000000000 --- a/src/common/trailer.cc +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005 INRIA - * All rights reserved. - * - * 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: Mathieu Lacage - */ - -#include "trailer.h" - -namespace ns3 { - -Trailer::~Trailer () -{} - -}; // namespace ns3 diff --git a/src/common/trailer.h b/src/common/trailer.h index b7a306a17..4b6b91fac 100644 --- a/src/common/trailer.h +++ b/src/common/trailer.h @@ -22,7 +22,7 @@ #ifndef TRAILER_H #define TRAILER_H -#include "chunk.h" +#include "chunk-registry.h" /** * \relates Trailer @@ -110,12 +110,12 @@ namespace ns3 { * trailers), the input iterator to DeserializeFrom and SerializeTo points * to the end of the trailer, and not its start. */ -class Trailer : public Chunk { +class Trailer { public: - virtual ~Trailer (); protected: template static uint32_t Register (std::string uidString); +#if 0 private: /** * \returns a user-readable name to identify this type of header. @@ -170,6 +170,7 @@ private: * amount when this method is invoked from Packet::RemoveTrailer */ virtual uint32_t DeserializeFrom (Buffer::Iterator end) = 0; +#endif }; } // namespace ns3 diff --git a/src/common/wscript b/src/common/wscript index fe34bd31c..432a81e2a 100644 --- a/src/common/wscript +++ b/src/common/wscript @@ -7,9 +7,7 @@ def build(bld): common.uselib_local = ['ns3-core', 'ns3-simulator'] common.source = [ 'buffer.cc', - 'chunk.cc', - 'header.cc', - 'trailer.cc', + 'chunk-registry.cc', 'packet-printer.cc', 'packet-metadata.cc', 'packet-metadata-test.cc', @@ -30,7 +28,7 @@ def build(bld): headers = bld.create_obj('ns3header') headers.source = [ 'buffer.h', - 'chunk.h', + 'chunk-registry.h', 'header.h', 'trailer.h', 'tags.h', diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma-cd/csma-cd-net-device.cc index a67552659..f5a526f06 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma-cd/csma-cd-net-device.cc @@ -203,7 +203,7 @@ CsmaCdNetDevice::AddHeader (Packet& p, Eui48Address dest, switch (m_encapMode) { case ETHERNET_V1: - lengthType = p.GetSize() + header.GetSize() + trailer.GetSize(); + lengthType = p.GetSize() + header.GetSerializedSize() + trailer.GetSerializedSize(); break; case IP_ARP: lengthType = protocolNumber; diff --git a/src/internet-node/arp-header.cc b/src/internet-node/arp-header.cc index dccf80f58..587c7d543 100644 --- a/src/internet-node/arp-header.cc +++ b/src/internet-node/arp-header.cc @@ -34,9 +34,6 @@ ArpHeader::GetUid (void) return uid; } -ArpHeader::~ArpHeader () -{} - void ArpHeader::SetRequest (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, @@ -93,13 +90,13 @@ ArpHeader::GetDestinationIpv4Address (void) } std::string -ArpHeader::DoGetName (void) const +ArpHeader::GetName (void) const { return "ARP"; } void -ArpHeader::PrintTo (std::ostream &os) const +ArpHeader::Print (std::ostream &os) const { if (IsRequest ()) { @@ -132,7 +129,7 @@ ArpHeader::GetSerializedSize (void) const } void -ArpHeader::SerializeTo (Buffer::Iterator start) const +ArpHeader::Serialize (Buffer::Iterator start) const { Buffer::Iterator i = start; NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ()); @@ -150,7 +147,7 @@ ArpHeader::SerializeTo (Buffer::Iterator start) const WriteTo (i, m_ipv4Dest); } uint32_t -ArpHeader::DeserializeFrom (Buffer::Iterator start) +ArpHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; i.Next (2+2); diff --git a/src/internet-node/arp-header.h b/src/internet-node/arp-header.h index 79695a329..509530991 100644 --- a/src/internet-node/arp-header.h +++ b/src/internet-node/arp-header.h @@ -36,8 +36,6 @@ class ArpHeader : public Header public: static uint32_t GetUid (void); - virtual ~ArpHeader (); - void SetRequest (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, Address destinationHardwareAddress, @@ -53,25 +51,11 @@ public: Ipv4Address GetSourceIpv4Address (void); Ipv4Address GetDestinationIpv4Address (void); -private: - virtual std::string DoGetName (void) const; - /** - * \param os - */ - virtual void PrintTo (std::ostream &os) const; - /** - * \return - */ - virtual uint32_t GetSerializedSize (void) const; - /** - * \param start - */ - virtual void SerializeTo (Buffer::Iterator start) const; - /** - * \param start - * \return - */ - virtual uint32_t DeserializeFrom (Buffer::Iterator start); + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); enum ArpType_e { ARP_TYPE_REQUEST = 1, diff --git a/src/internet-node/ipv4-header.cc b/src/internet-node/ipv4-header.cc index 6b834991d..00dc78ca6 100644 --- a/src/internet-node/ipv4-header.cc +++ b/src/internet-node/ipv4-header.cc @@ -49,8 +49,6 @@ Ipv4Header::Ipv4Header () m_fragmentOffset (0), m_goodChecksum (true) {} -Ipv4Header::~Ipv4Header () -{} void Ipv4Header::EnableChecksums (void) @@ -189,13 +187,13 @@ Ipv4Header::IsChecksumOk (void) const } std::string -Ipv4Header::DoGetName (void) const +Ipv4Header::GetName (void) const { return "IPV4"; } void -Ipv4Header::PrintTo (std::ostream &os) const +Ipv4Header::Print (std::ostream &os) const { // ipv4, right ? std::string flags; @@ -238,7 +236,7 @@ Ipv4Header::GetSerializedSize (void) const } void -Ipv4Header::SerializeTo (Buffer::Iterator start) const +Ipv4Header::Serialize (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -281,7 +279,7 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const } } uint32_t -Ipv4Header::DeserializeFrom (Buffer::Iterator start) +Ipv4Header::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; uint8_t verIhl = i.ReadU8 (); diff --git a/src/internet-node/ipv4-header.h b/src/internet-node/ipv4-header.h index 729da4f98..fe9317d7c 100644 --- a/src/internet-node/ipv4-header.h +++ b/src/internet-node/ipv4-header.h @@ -37,7 +37,6 @@ public: * \brief Construct a null IPv4 header */ Ipv4Header (); - virtual ~Ipv4Header (); /** * \brief Enable checksum calculation for IP (XXX currently has no effect) */ @@ -141,12 +140,12 @@ public: */ bool IsChecksumOk (void) const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); enum FlagsE { DONT_FRAGMENT = (1<<0), @@ -167,7 +166,7 @@ private: bool m_goodChecksum; }; -}; // namespace ns3 +} // namespace ns3 #endif /* IPV4_HEADER_H */ diff --git a/src/internet-node/udp-header.cc b/src/internet-node/udp-header.cc index 201ab16a1..a90a41215 100644 --- a/src/internet-node/udp-header.cc +++ b/src/internet-node/udp-header.cc @@ -93,7 +93,7 @@ UdpHeader::InitializeChecksum (Ipv4Address source, destination.Serialize (buf+4); buf[8] = 0; buf[9] = protocol; - uint16_t udpLength = m_payloadSize + GetSize (); + uint16_t udpLength = m_payloadSize + GetSerializedSize (); buf[10] = udpLength >> 8; buf[11] = udpLength & 0xff; @@ -101,16 +101,16 @@ UdpHeader::InitializeChecksum (Ipv4Address source, } std::string -UdpHeader::DoGetName (void) const +UdpHeader::GetName (void) const { return "UDP"; } void -UdpHeader::PrintTo (std::ostream &os) const +UdpHeader::Print (std::ostream &os) const { os << "(" - << "length: " << m_payloadSize + GetSize () + << "length: " << m_payloadSize + GetSerializedSize () << ") " << m_sourcePort << " > " << m_destinationPort ; @@ -123,12 +123,12 @@ UdpHeader::GetSerializedSize (void) const } void -UdpHeader::SerializeTo (Buffer::Iterator start) const +UdpHeader::Serialize (Buffer::Iterator start) const { Buffer::Iterator i = start; i.WriteHtonU16 (m_sourcePort); i.WriteHtonU16 (m_destinationPort); - i.WriteHtonU16 (m_payloadSize + GetSize ()); + i.WriteHtonU16 (m_payloadSize + GetSerializedSize ()); i.WriteU16 (0); if (m_calcChecksum) @@ -137,7 +137,7 @@ UdpHeader::SerializeTo (Buffer::Iterator start) const //XXXX uint16_t checksum = Ipv4ChecksumCalculate (m_initialChecksum, buffer->PeekData (), - GetSize () + m_payloadSize); + GetSerializedSize () + m_payloadSize); checksum = Ipv4ChecksumComplete (checksum); i = buffer->Begin (); i.Next (6); @@ -146,12 +146,12 @@ UdpHeader::SerializeTo (Buffer::Iterator start) const } } uint32_t -UdpHeader::DeserializeFrom (Buffer::Iterator start) +UdpHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; m_sourcePort = i.ReadNtohU16 (); m_destinationPort = i.ReadNtohU16 (); - m_payloadSize = i.ReadNtohU16 () - GetSize (); + m_payloadSize = i.ReadNtohU16 () - GetSerializedSize (); if (m_calcChecksum) { // XXX verify checksum. diff --git a/src/internet-node/udp-header.h b/src/internet-node/udp-header.h index 3ab6dc18f..70503ef91 100644 --- a/src/internet-node/udp-header.h +++ b/src/internet-node/udp-header.h @@ -42,7 +42,7 @@ public: * Creates a null header */ UdpHeader (); - virtual ~UdpHeader (); + ~UdpHeader (); /** * \brief Enable checksum calculation for UDP (XXX currently has no effect) @@ -84,13 +84,13 @@ public: Ipv4Address destination, uint8_t protocol); -private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); +private: uint16_t m_sourcePort; uint16_t m_destinationPort; uint16_t m_payloadSize; @@ -99,6 +99,6 @@ private: static bool m_calcChecksum; }; -}; // namespace ns3 +} // namespace ns3 #endif /* UDP_HEADER */ diff --git a/src/node/ethernet-header.cc b/src/node/ethernet-header.cc index 458696a9d..ebbf7cf72 100644 --- a/src/node/ethernet-header.cc +++ b/src/node/ethernet-header.cc @@ -48,9 +48,6 @@ EthernetHeader::EthernetHeader () m_lengthType (0) {} -EthernetHeader::~EthernetHeader () -{} - void EthernetHeader::SetLengthType (uint16_t lengthType) { @@ -108,13 +105,13 @@ EthernetHeader::GetHeaderSize (void) const } std::string -EthernetHeader::DoGetName (void) const +EthernetHeader::GetName (void) const { return "ETHERNET"; } void -EthernetHeader::PrintTo (std::ostream &os) const +EthernetHeader::Print (std::ostream &os) const { // ethernet, right ? if (m_enPreambleSfd) @@ -139,7 +136,7 @@ EthernetHeader::GetSerializedSize (void) const } void -EthernetHeader::SerializeTo (Buffer::Iterator start) const +EthernetHeader::Serialize (Buffer::Iterator start) const { Buffer::Iterator i = start; @@ -152,7 +149,7 @@ EthernetHeader::SerializeTo (Buffer::Iterator start) const i.WriteU16 (m_lengthType); } uint32_t -EthernetHeader::DeserializeFrom (Buffer::Iterator start) +EthernetHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; diff --git a/src/node/ethernet-header.h b/src/node/ethernet-header.h index a755bae79..b1b3d1998 100644 --- a/src/node/ethernet-header.h +++ b/src/node/ethernet-header.h @@ -62,7 +62,6 @@ public: * By default, does not add or remove an ethernet preamble */ EthernetHeader (); - virtual ~EthernetHeader (); /** * \param size The size of the payload in bytes */ @@ -104,17 +103,16 @@ public: */ uint32_t GetHeaderSize() const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); private: static const int PREAMBLE_SIZE = 8; /// size of the preamble_sfd header field static const int LENGTH_SIZE = 2; /// size of the length_type header field static const int MAC_ADDR_SIZE = 6; /// size of src/dest addr header fields - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); - /** * If false, the preamble/sfd are not serialised/deserialised. */ diff --git a/src/node/ethernet-trailer.cc b/src/node/ethernet-trailer.cc index d21b2c710..cf16bf2af 100644 --- a/src/node/ethernet-trailer.cc +++ b/src/node/ethernet-trailer.cc @@ -44,9 +44,6 @@ EthernetTrailer::EthernetTrailer () Init(); } -EthernetTrailer::~EthernetTrailer () -{} - void EthernetTrailer::Init() { m_fcs = 0; @@ -94,13 +91,13 @@ EthernetTrailer::GetTrailerSize (void) const return GetSerializedSize(); } std::string -EthernetTrailer::DoGetName (void) const +EthernetTrailer::GetName (void) const { return "ETHERNET"; } void -EthernetTrailer::PrintTo (std::ostream &os) const +EthernetTrailer::Print (std::ostream &os) const { os << " fcs=" << m_fcs; } @@ -111,7 +108,7 @@ EthernetTrailer::GetSerializedSize (void) const } void -EthernetTrailer::SerializeTo (Buffer::Iterator end) const +EthernetTrailer::Serialize (Buffer::Iterator end) const { Buffer::Iterator i = end; i.Prev(GetSerializedSize()); @@ -119,7 +116,7 @@ EthernetTrailer::SerializeTo (Buffer::Iterator end) const i.WriteU32 (m_fcs); } uint32_t -EthernetTrailer::DeserializeFrom (Buffer::Iterator end) +EthernetTrailer::Deserialize (Buffer::Iterator end) { Buffer::Iterator i = end; uint32_t size = GetSerializedSize(); diff --git a/src/node/ethernet-trailer.h b/src/node/ethernet-trailer.h index d8354d3fa..c6deeb6ab 100644 --- a/src/node/ethernet-trailer.h +++ b/src/node/ethernet-trailer.h @@ -43,7 +43,7 @@ public: * \brief Construct a null ethernet trailer */ EthernetTrailer (); - virtual ~EthernetTrailer (); + /** * \brief Enable or disabled FCS checking and calculations * \param enable If true, enables FCS calculations. @@ -81,12 +81,12 @@ public: */ uint32_t GetTrailerSize() const; + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator end) const; + uint32_t Deserialize (Buffer::Iterator end); private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator end) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator end); /** * Initializes the trailer parameters during construction. @@ -102,7 +102,7 @@ private: }; -}; // namespace ns3 +} // namespace ns3 #endif /* ETHERNET_TRAILER_H */ diff --git a/src/node/llc-snap-header.cc b/src/node/llc-snap-header.cc index 30b18d6a3..52a9021a8 100644 --- a/src/node/llc-snap-header.cc +++ b/src/node/llc-snap-header.cc @@ -38,8 +38,6 @@ LlcSnapHeader::GetUid (void) LlcSnapHeader::LlcSnapHeader () {} -LlcSnapHeader::~LlcSnapHeader () -{} void LlcSnapHeader::SetType (uint16_t type) { @@ -58,13 +56,13 @@ LlcSnapHeader::GetSerializedSize (void) const } std::string -LlcSnapHeader::DoGetName (void) const +LlcSnapHeader::GetName (void) const { return "LLCSNAP"; } void -LlcSnapHeader::PrintTo (std::ostream &os) const +LlcSnapHeader::Print (std::ostream &os) const { os << "(type 0x"; os.setf (std::ios::hex, std::ios::basefield); @@ -74,7 +72,7 @@ LlcSnapHeader::PrintTo (std::ostream &os) const } void -LlcSnapHeader::SerializeTo (Buffer::Iterator start) const +LlcSnapHeader::Serialize (Buffer::Iterator start) const { Buffer::Iterator i = start; uint8_t buf[] = {0xaa, 0xaa, 0x03, 0, 0, 0}; @@ -82,7 +80,7 @@ LlcSnapHeader::SerializeTo (Buffer::Iterator start) const i.WriteHtonU16 (m_etherType); } uint32_t -LlcSnapHeader::DeserializeFrom (Buffer::Iterator start) +LlcSnapHeader::Deserialize (Buffer::Iterator start) { Buffer::Iterator i = start; i.Next (5+1); @@ -91,4 +89,4 @@ LlcSnapHeader::DeserializeFrom (Buffer::Iterator start) } -}; // namespace ns3 +} // namespace ns3 diff --git a/src/node/llc-snap-header.h b/src/node/llc-snap-header.h index df86e5d8b..cfc9a5d9c 100644 --- a/src/node/llc-snap-header.h +++ b/src/node/llc-snap-header.h @@ -34,21 +34,19 @@ public: static uint32_t GetUid (void); LlcSnapHeader (); - virtual ~LlcSnapHeader (); - void SetType (uint16_t type); uint16_t GetType (void); + std::string GetName (void) const; + void Print (std::ostream &os) const; + uint32_t GetSerializedSize (void) const; + void Serialize (Buffer::Iterator start) const; + uint32_t Deserialize (Buffer::Iterator start); private: - virtual std::string DoGetName (void) const; - virtual void PrintTo (std::ostream &os) const; - virtual uint32_t GetSerializedSize (void) const; - virtual void SerializeTo (Buffer::Iterator start) const; - virtual uint32_t DeserializeFrom (Buffer::Iterator start); uint16_t m_etherType; }; -}; // namespace ns3 +} // namespace ns3 #endif /* LLC_SNAP_HEADER_H */