A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
seq-ts-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/header.h"
24 #include "ns3/simulator.h"
25 #include "seq-ts-header.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("SeqTsHeader");
28 
29 namespace ns3 {
30 
31 NS_OBJECT_ENSURE_REGISTERED (SeqTsHeader);
32 
34  : m_seq (0),
35  m_ts (Simulator::Now ().GetTimeStep ())
36 {
37 }
38 
39 void
40 SeqTsHeader::SetSeq (uint32_t seq)
41 {
42  m_seq = seq;
43 }
44 uint32_t
45 SeqTsHeader::GetSeq (void) const
46 {
47  return m_seq;
48 }
49 
50 Time
51 SeqTsHeader::GetTs (void) const
52 {
53  return TimeStep (m_ts);
54 }
55 
56 TypeId
58 {
59  static TypeId tid = TypeId ("ns3::SeqTsHeader")
60  .SetParent<Header> ()
61  .AddConstructor<SeqTsHeader> ()
62  ;
63  return tid;
64 }
65 TypeId
67 {
68  return GetTypeId ();
69 }
70 void
71 SeqTsHeader::Print (std::ostream &os) const
72 {
73  os << "(seq=" << m_seq << " time=" << TimeStep (m_ts).GetSeconds () << ")";
74 }
75 uint32_t
77 {
78  return 4+8;
79 }
80 
81 void
83 {
85  i.WriteHtonU32 (m_seq);
86  i.WriteHtonU64 (m_ts);
87 }
88 uint32_t
90 {
92  m_seq = i.ReadNtohU32 ();
93  m_ts = i.ReadNtohU64 ();
94  return GetSerializedSize ();
95 }
96 
97 } // namespace ns3