blob: 7d26a7d5738d3e4fb83addb9bf42aef4eeef9383 [file] [log] [blame]
Ilya Moiseenko59c62212011-08-04 19:04:24 -07001//
2// ndn_nonceheader.cpp
3// Abstraction
4//
5// Created by Ilya Moiseenko on 04.08.11.
6// Copyright 2011 UCLA. All rights reserved.
7//
8
9#include "ndn_nonceheader.h"
10
11
12namespace ns3
13{
14 namespace NDNabstraction
15 {
16 NS_OBJECT_ENSURE_REGISTERED (NonceHeader);
17
18 NonceHeader::NonceHeader()
19 {
20 m_value = 0;
21 }
22
23 NonceHeader::NonceHeader (uint32_t nonce)
24 {
25 m_value = nonce;
26 }
27
28 TypeId
29 NonceHeader::GetTypeId ()
30 {
31 static TypeId tid = TypeId ("ns3::NDNabstraction::NonceHeader")
32 .SetParent<Header> ()
33 .AddConstructor<NonceHeader> ()
34 ;
35 return tid;
36 }
37
38 TypeId
39 NonceHeader::GetInstanceTypeId () const
40 {
41 return GetTypeId ();
42 }
43
44 uint32_t
45 NonceHeader::GetSerializedSize () const
46 {
47 return 4;
48 }
49
50 void
51 NonceHeader::Serialize (Buffer::Iterator i) const
52 {
53 i.WriteU32 ((uint32_t) m_value);
54 }
55
56 uint32_t
57 NonceHeader::Deserialize (Buffer::Iterator start)
58 {
59 Buffer::Iterator i = start;
60 m_value = i.ReadU32 ();
61
62 uint32_t dist = i.GetDistanceFrom (start);
63 NS_ASSERT (dist == GetSerializedSize ());
64 return dist;
65 }
66
67 void
68 NonceHeader::Print (std::ostream &os) const
69 {
70 os << m_value;
71 }
72
73 uint32_t
74 NonceHeader::GetValue()
75 {
76 return m_value;
77 }
78 }
79}