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  ;
33 
35  : m_seq (0),
36  m_ts (Simulator::Now ().GetTimeStep ())
37 {
38  NS_LOG_FUNCTION (this);
39 }
40 
41 void
42 SeqTsHeader::SetSeq (uint32_t seq)
43 {
44  NS_LOG_FUNCTION (this << seq);
45  m_seq = seq;
46 }
47 uint32_t
48 SeqTsHeader::GetSeq (void) const
49 {
50  NS_LOG_FUNCTION (this);
51  return m_seq;
52 }
53 
54 Time
55 SeqTsHeader::GetTs (void) const
56 {
57  NS_LOG_FUNCTION (this);
58  return TimeStep (m_ts);
59 }
60 
61 TypeId
63 {
64  static TypeId tid = TypeId ("ns3::SeqTsHeader")
65  .SetParent<Header> ()
66  .AddConstructor<SeqTsHeader> ()
67  ;
68  return tid;
69 }
70 TypeId
72 {
73  return GetTypeId ();
74 }
75 void
76 SeqTsHeader::Print (std::ostream &os) const
77 {
78  NS_LOG_FUNCTION (this << &os);
79  os << "(seq=" << m_seq << " time=" << TimeStep (m_ts).GetSeconds () << ")";
80 }
81 uint32_t
83 {
84  NS_LOG_FUNCTION (this);
85  return 4+8;
86 }
87 
88 void
90 {
91  NS_LOG_FUNCTION (this << &start);
93  i.WriteHtonU32 (m_seq);
94  i.WriteHtonU64 (m_ts);
95 }
96 uint32_t
98 {
99  NS_LOG_FUNCTION (this << &start);
101  m_seq = i.ReadNtohU32 ();
102  m_ts = i.ReadNtohU64 ();
103  return GetSerializedSize ();
104 }
105 
106 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
void WriteHtonU64(uint64_t data)
Definition: buffer.cc:965
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
uint32_t GetSeq(void) const
Control the scheduling of simulation events.
Definition: simulator.h:62
Time TimeStep(uint64_t ts)
Definition: nstime.h:950
uint64_t ReadNtohU64(void)
Definition: buffer.cc:1068
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t ReadNtohU32(void)
Definition: buffer.h:791
iterator in a Buffer instance
Definition: buffer.h:98
double GetSeconds(void) const
Definition: nstime.h:274
uint64_t m_ts
Timestamp.
Definition: seq-ts-header.h:68
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_seq
Sequence number.
Definition: seq-ts-header.h:67
void WriteHtonU32(uint32_t data)
Definition: buffer.h:745
virtual uint32_t Deserialize(Buffer::Iterator start)
Time GetTs(void) const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void SetSeq(uint32_t seq)
virtual TypeId GetInstanceTypeId(void) const
virtual void Print(std::ostream &os) const
virtual void Serialize(Buffer::Iterator start) const
a unique identifier for an interface.
Definition: type-id.h:49
NS_LOG_COMPONENT_DEFINE("SeqTsHeader")
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
virtual uint32_t GetSerializedSize(void) const