00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 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 #include "ns3/assert.h" 00022 #include "ns3/log.h" 00023 #include "ns3/trailer.h" 00024 #include "ethernet-trailer.h" 00025 00026 NS_LOG_COMPONENT_DEFINE ("EthernetTrailer"); 00027 00028 namespace ns3 { 00029 00030 NS_OBJECT_ENSURE_REGISTERED (EthernetTrailer); 00031 00032 bool EthernetTrailer::m_calcFcs = false; 00033 00034 EthernetTrailer::EthernetTrailer () 00035 { 00036 Init(); 00037 } 00038 00039 void EthernetTrailer::Init() 00040 { 00041 m_fcs = 0; 00042 } 00043 00044 void 00045 EthernetTrailer::EnableFcs (bool enable) 00046 { 00047 m_calcFcs = enable; 00048 } 00049 00050 bool 00051 EthernetTrailer::CheckFcs (Ptr<Packet> p) const 00052 { 00053 if (!m_calcFcs) 00054 { 00055 return true; 00056 } 00057 else 00058 { 00059 NS_LOG_WARN ("FCS calculation is not yet enabled"); 00060 return false; 00061 } 00062 } 00063 00064 void 00065 EthernetTrailer::CalcFcs (Ptr<Packet> p) 00066 { 00067 NS_LOG_WARN ("FCS calculation is not yet enabled"); 00068 } 00069 00070 void 00071 EthernetTrailer::SetFcs (uint32_t fcs) 00072 { 00073 m_fcs = fcs; 00074 } 00075 00076 uint32_t 00077 EthernetTrailer::GetFcs (void) 00078 { 00079 return m_fcs; 00080 } 00081 00082 uint32_t 00083 EthernetTrailer::GetTrailerSize (void) const 00084 { 00085 return GetSerializedSize(); 00086 } 00087 00088 TypeId 00089 EthernetTrailer::GetTypeId (void) 00090 { 00091 static TypeId tid = TypeId ("ns3::EthernetTrailer") 00092 .SetParent<Trailer> () 00093 .AddConstructor<EthernetTrailer> () 00094 ; 00095 return tid; 00096 } 00097 TypeId 00098 EthernetTrailer::GetInstanceTypeId (void) const 00099 { 00100 return GetTypeId (); 00101 } 00102 void 00103 EthernetTrailer::Print (std::ostream &os) const 00104 { 00105 os << "fcs=" << m_fcs; 00106 } 00107 uint32_t 00108 EthernetTrailer::GetSerializedSize (void) const 00109 { 00110 return 4; 00111 } 00112 00113 void 00114 EthernetTrailer::Serialize (Buffer::Iterator end) const 00115 { 00116 Buffer::Iterator i = end; 00117 i.Prev(GetSerializedSize()); 00118 00119 i.WriteU32 (m_fcs); 00120 } 00121 uint32_t 00122 EthernetTrailer::Deserialize (Buffer::Iterator end) 00123 { 00124 Buffer::Iterator i = end; 00125 uint32_t size = GetSerializedSize(); 00126 i.Prev(size); 00127 00128 m_fcs = i.ReadU32 (); 00129 00130 return size; 00131 } 00132 00133 }; // namespace ns3