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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #include "llc-snap-header.h" 00022 #include "ns3/assert.h" 00023 #include <string> 00024 00025 namespace ns3 { 00026 00027 NS_OBJECT_ENSURE_REGISTERED (LlcSnapHeader); 00028 00029 LlcSnapHeader::LlcSnapHeader () 00030 {} 00031 00032 void 00033 LlcSnapHeader::SetType (uint16_t type) 00034 { 00035 m_etherType = type; 00036 } 00037 uint16_t 00038 LlcSnapHeader::GetType (void) 00039 { 00040 return m_etherType; 00041 } 00042 00043 uint32_t 00044 LlcSnapHeader::GetSerializedSize (void) const 00045 { 00046 return 1 + 1 + 1 + 3 + 2; 00047 } 00048 00049 TypeId 00050 LlcSnapHeader::GetTypeId (void) 00051 { 00052 static TypeId tid = TypeId ("ns3::LlcSnapHeader") 00053 .SetParent<Header> () 00054 .AddConstructor<LlcSnapHeader> () 00055 ; 00056 return tid; 00057 } 00058 TypeId 00059 LlcSnapHeader::GetInstanceTypeId (void) const 00060 { 00061 return GetTypeId (); 00062 } 00063 void 00064 LlcSnapHeader::Print (std::ostream &os) const 00065 { 00066 os << "type 0x"; 00067 os.setf (std::ios::hex, std::ios::basefield); 00068 os << m_etherType; 00069 os.setf (std::ios::dec, std::ios::basefield); 00070 } 00071 00072 void 00073 LlcSnapHeader::Serialize (Buffer::Iterator start) const 00074 { 00075 Buffer::Iterator i = start; 00076 uint8_t buf[] = {0xaa, 0xaa, 0x03, 0, 0, 0}; 00077 i.Write (buf, 6); 00078 i.WriteHtonU16 (m_etherType); 00079 } 00080 uint32_t 00081 LlcSnapHeader::Deserialize (Buffer::Iterator start) 00082 { 00083 Buffer::Iterator i = start; 00084 i.Next (5+1); 00085 m_etherType = i.ReadNtohU16 (); 00086 return GetSerializedSize (); 00087 } 00088 00089 00090 } // namespace ns3