Alexander Afanasyev | 6b997c5 | 2011-08-08 12:55:25 -0700 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
Ilya Moiseenko | 59c6221 | 2011-08-04 19:04:24 -0700 | [diff] [blame] | 20 | |
| 21 | #include "ndn_timeoutheader.h" |
| 22 | |
| 23 | namespace ns3 |
| 24 | { |
| 25 | namespace NDNabstraction |
| 26 | { |
| 27 | NS_OBJECT_ENSURE_REGISTERED (TimeoutHeader); |
| 28 | |
| 29 | TimeoutHeader::TimeoutHeader() |
| 30 | { |
| 31 | m_value = 4000; |
| 32 | } |
| 33 | |
| 34 | TimeoutHeader::TimeoutHeader (uint32_t timeout) |
| 35 | { |
| 36 | m_value = timeout; |
| 37 | } |
| 38 | |
| 39 | TypeId |
| 40 | TimeoutHeader::GetTypeId () |
| 41 | { |
| 42 | static TypeId tid = TypeId ("ns3::NDNabstraction::TimeoutHeader") |
| 43 | .SetParent<Header> () |
| 44 | .AddConstructor<TimeoutHeader> () |
| 45 | ; |
| 46 | return tid; |
| 47 | } |
| 48 | |
| 49 | TypeId |
| 50 | TimeoutHeader::GetInstanceTypeId () const |
| 51 | { |
| 52 | return GetTypeId (); |
| 53 | } |
| 54 | |
| 55 | uint32_t |
| 56 | TimeoutHeader::GetSerializedSize () const |
| 57 | { |
| 58 | return 4; |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | TimeoutHeader::Serialize (Buffer::Iterator i) const |
| 63 | { |
| 64 | i.WriteU32 ((uint32_t) m_value); |
| 65 | } |
| 66 | |
| 67 | uint32_t |
| 68 | TimeoutHeader::Deserialize (Buffer::Iterator start) |
| 69 | { |
| 70 | Buffer::Iterator i = start; |
| 71 | m_value = i.ReadU32 (); |
| 72 | |
| 73 | uint32_t dist = i.GetDistanceFrom (start); |
| 74 | NS_ASSERT (dist == GetSerializedSize ()); |
| 75 | return dist; |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | TimeoutHeader::Print (std::ostream &os) const |
| 80 | { |
| 81 | os << m_value; |
| 82 | } |
| 83 | |
| 84 | uint32_t |
| 85 | TimeoutHeader::GetValue() |
| 86 | { |
| 87 | return m_value; |
| 88 | } |
| 89 | } |
Alexander Afanasyev | 6b997c5 | 2011-08-08 12:55:25 -0700 | [diff] [blame^] | 90 | } |