OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Telum (www.telum.ru) |
| 4 * |
| 5 * This program is free software; you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 2 as |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Denis Fakhriev <fakhriev@telum.ru> |
| 19 * Kirill Andreev <andreev@telum.ru> |
| 20 */ |
| 21 |
| 22 #include "ns3/log.h" |
| 23 #include "ns3/address-utils.h" |
| 24 #include "lrr-mac-header.h" |
| 25 |
| 26 NS_LOG_COMPONENT_DEFINE ("LrrMacHeader"); |
| 27 |
| 28 namespace ns3 { |
| 29 namespace lrr { |
| 30 |
| 31 NS_OBJECT_ENSURE_REGISTERED (MacHeader); |
| 32 // Setters and getters { |
| 33 MacHeader::MacHeader () |
| 34 : m_type (0), |
| 35 m_destination (Address ()), |
| 36 m_source (Address ()) |
| 37 {} |
| 38 |
| 39 void· |
| 40 MacHeader::SetType (uint16_t type) |
| 41 { |
| 42 m_type = type; |
| 43 } |
| 44 |
| 45 uint16_t· |
| 46 MacHeader::GetType () const |
| 47 { |
| 48 return m_type; |
| 49 } |
| 50 |
| 51 void· |
| 52 MacHeader::SetSource (Address source) |
| 53 { |
| 54 m_source = source; |
| 55 } |
| 56 |
| 57 Address |
| 58 MacHeader::GetSource () const |
| 59 { |
| 60 return m_source; |
| 61 } |
| 62 |
| 63 void· |
| 64 MacHeader::SetDestination (Address dst) |
| 65 { |
| 66 m_destination = dst; |
| 67 } |
| 68 |
| 69 Address |
| 70 MacHeader::GetDestination () const |
| 71 { |
| 72 return m_destination; |
| 73 } |
| 74 // } |
| 75 // Header base class methods: { |
| 76 TypeId |
| 77 MacHeader::GetTypeId () |
| 78 { |
| 79 static TypeId tid = TypeId ("ns3::lrr::MacHeader") |
| 80 .SetParent<Header> () |
| 81 .AddConstructor<MacHeader> () |
| 82 ; |
| 83 return tid; |
| 84 } |
| 85 |
| 86 TypeId· |
| 87 MacHeader::GetInstanceTypeId () const |
| 88 { |
| 89 return GetTypeId (); |
| 90 } |
| 91 |
| 92 void· |
| 93 MacHeader::Print (std::ostream &os) const |
| 94 { |
| 95 os << " type=0x" << std::hex << m_type << std::dec |
| 96 << ", source=" << m_source |
| 97 << ", destination=" << m_destination; |
| 98 } |
| 99 |
| 100 void |
| 101 MacHeader::Serialize (Buffer::Iterator start) const |
| 102 { |
| 103 Buffer::Iterator i = start; |
| 104 NS_ASSERT (m_source.GetLength () == m_destination.GetLength ()); |
| 105 i.WriteU8 (m_source.GetLength ()); |
| 106 WriteTo (i, m_destination); |
| 107 WriteTo (i, m_source); |
| 108 i.WriteHtonU16 (m_type); |
| 109 } |
| 110 |
| 111 uint32_t |
| 112 MacHeader::Deserialize (Buffer::Iterator start) |
| 113 { |
| 114 Buffer::Iterator i = start; |
| 115 uint32_t hardwareAddressLen = i.ReadU8 (); |
| 116 ReadFrom (i, m_destination, hardwareAddressLen); |
| 117 ReadFrom (i, m_source, hardwareAddressLen); |
| 118 m_type = i.ReadNtohU16 (); |
| 119 return GetSerializedSize (); |
| 120 } |
| 121 |
| 122 uint32_t |
| 123 MacHeader::GetSerializedSize () const |
| 124 { |
| 125 return 1 + m_source.GetLength () * 2 + 2; |
| 126 } |
| 127 // } |
| 128 } // namespace lrr |
| 129 } // namespace ns3 |
OLD | NEW |