blob: 419b5abfb1d4aa43ddf9f784ffa1819197ed7a8c [file] [log] [blame]
Alexander Afanasyev6b997c52011-08-08 12:55:25 -07001/* -*- 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 Moiseenko59c62212011-08-04 19:04:24 -070020
21#include "ndn_nonceheader.h"
22
23
24namespace ns3
25{
26 namespace NDNabstraction
27 {
28 NS_OBJECT_ENSURE_REGISTERED (NonceHeader);
29
30 NonceHeader::NonceHeader()
31 {
32 m_value = 0;
33 }
34
35 NonceHeader::NonceHeader (uint32_t nonce)
36 {
37 m_value = nonce;
38 }
39
40 TypeId
41 NonceHeader::GetTypeId ()
42 {
43 static TypeId tid = TypeId ("ns3::NDNabstraction::NonceHeader")
44 .SetParent<Header> ()
45 .AddConstructor<NonceHeader> ()
46 ;
47 return tid;
48 }
49
50 TypeId
51 NonceHeader::GetInstanceTypeId () const
52 {
53 return GetTypeId ();
54 }
55
56 uint32_t
57 NonceHeader::GetSerializedSize () const
58 {
59 return 4;
60 }
61
62 void
63 NonceHeader::Serialize (Buffer::Iterator i) const
64 {
65 i.WriteU32 ((uint32_t) m_value);
66 }
67
68 uint32_t
69 NonceHeader::Deserialize (Buffer::Iterator start)
70 {
71 Buffer::Iterator i = start;
72 m_value = i.ReadU32 ();
73
74 uint32_t dist = i.GetDistanceFrom (start);
75 NS_ASSERT (dist == GetSerializedSize ());
76 return dist;
77 }
78
79 void
80 NonceHeader::Print (std::ostream &os) const
81 {
82 os << m_value;
83 }
84
85 uint32_t
86 NonceHeader::GetValue()
87 {
88 return m_value;
89 }
90 }
Alexander Afanasyev6b997c52011-08-08 12:55:25 -070091}