00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 Emmanuelle Laprise 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> 00019 */ 00020 00021 #ifndef ETHERNET_TRAILER_H 00022 #define ETHERNET_TRAILER_H 00023 00024 #include "ns3/trailer.h" 00025 #include <string> 00026 00027 namespace ns3 { 00028 00029 class Packet; 00030 00031 /** 00032 * \ingroup node 00033 * 00034 * \brief Packet trailer for Ethernet 00035 * 00036 * This class can be used to add and verify the FCS at the end of an 00037 * ethernet packet. The actual FCS functionality is not yet coded and 00038 * so this acts more as a placeholder. 00039 */ 00040 class EthernetTrailer : public Trailer 00041 { 00042 public: 00043 /** 00044 * \brief Construct a null ethernet trailer 00045 */ 00046 EthernetTrailer (); 00047 00048 /** 00049 * \brief Enable or disabled FCS checking and calculations 00050 * \param enable If true, enables FCS calculations. 00051 */ 00052 static void EnableFcs (bool enable); 00053 /** 00054 * \brief Updates the Fcs Field to the correct FCS 00055 * \param p Reference to a packet on which the FCS should be 00056 * calculated. The packet should not currently contain an FCS 00057 * trailer. 00058 */ 00059 void CalcFcs (Ptr<Packet> p); 00060 /** 00061 * \brief Sets the FCS to a new value 00062 * \param fcs New FCS value 00063 */ 00064 void SetFcs (uint32_t fcs); 00065 /** 00066 * \return the FCS contained in this trailer 00067 */ 00068 uint32_t GetFcs (); 00069 00070 /** 00071 * \param p Reference to the packet on which the FCS should be 00072 * calculated. The packet should not contain an FCS trailer. 00073 * \return Returns true if the packet fcs is correct, false otherwise. 00074 * 00075 * If FCS checking is disabled, this method will always 00076 * return true. 00077 */ 00078 bool CheckFcs (Ptr<Packet> p) const; 00079 00080 /** 00081 *\return Returns the size of the trailer 00082 */ 00083 uint32_t GetTrailerSize() const; 00084 00085 static TypeId GetTypeId (void); 00086 virtual TypeId GetInstanceTypeId (void) const; 00087 virtual void Print (std::ostream &os) const; 00088 virtual uint32_t GetSerializedSize (void) const; 00089 virtual void Serialize (Buffer::Iterator end) const; 00090 virtual uint32_t Deserialize (Buffer::Iterator end); 00091 private: 00092 00093 /** 00094 * Initializes the trailer parameters during construction. 00095 */ 00096 void Init (void); 00097 00098 /** 00099 * Enabled FCS calculations. If false, fcs is set to 0 and checkFCS 00100 * returns true. 00101 */ 00102 static bool m_calcFcs; 00103 uint32_t m_fcs; /// Value of the fcs contained in the trailer 00104 00105 }; 00106 00107 } // namespace ns3 00108 00109 00110 #endif /* ETHERNET_TRAILER_H */