A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
sixlowpan-nd-context.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2015 Università di Firenze, Italy
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
*
7
*
8
* Author: Alessio Bonadio <alessio.bonadio@gmail.com>
9
* Tommaso Pecorella <tommaso.pecorella@unifi.it>
10
* Adnan Rashid <adnanrashidpk@gmail.com>
11
*/
12
13
#include "
sixlowpan-nd-context.h
"
14
15
#include "ns3/log.h"
16
#include "ns3/simulator.h"
17
18
namespace
ns3
19
{
20
21
NS_LOG_COMPONENT_DEFINE
(
"SixLowPanNdContext"
);
22
23
SixLowPanNdContext::SixLowPanNdContext
()
24
:
m_c
(false),
25
m_cid
(0),
26
m_validTime
(
Seconds
(0)),
27
m_context
(
Ipv6Prefix
())
28
{
29
NS_LOG_FUNCTION
(
this
);
30
}
31
32
SixLowPanNdContext::SixLowPanNdContext
(
bool
flagC, uint8_t cid,
Time
time,
Ipv6Prefix
context)
33
:
m_c
(flagC),
34
m_cid
(cid),
35
m_context
(context)
36
{
37
NS_LOG_FUNCTION
(
this
<< flagC <<
static_cast<
uint32_t
>
(cid) << time << context);
38
SetValidTime
(time);
39
}
40
41
SixLowPanNdContext::~SixLowPanNdContext
()
42
{
43
NS_LOG_FUNCTION
(
this
);
44
}
45
46
uint8_t
47
SixLowPanNdContext::GetContextLen
()
const
48
{
49
NS_LOG_FUNCTION
(
this
);
50
return
m_context
.GetPrefixLength();
51
}
52
53
bool
54
SixLowPanNdContext::IsFlagC
()
const
55
{
56
NS_LOG_FUNCTION
(
this
);
57
return
m_c
;
58
}
59
60
void
61
SixLowPanNdContext::SetFlagC
(
bool
c)
62
{
63
NS_LOG_FUNCTION
(
this
<< c);
64
m_c
= c;
65
}
66
67
uint8_t
68
SixLowPanNdContext::GetCid
()
const
69
{
70
NS_LOG_FUNCTION
(
this
);
71
return
m_cid
;
72
}
73
74
void
75
SixLowPanNdContext::SetCid
(uint8_t cid)
76
{
77
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint32_t
>
(cid));
78
NS_ASSERT
(cid <= 15);
79
m_cid
= cid;
80
}
81
82
Time
83
SixLowPanNdContext::GetValidTime
()
const
84
{
85
NS_LOG_FUNCTION
(
this
);
86
87
return
m_validTime
;
88
}
89
90
void
91
SixLowPanNdContext::SetValidTime
(
Time
time)
92
{
93
NS_LOG_FUNCTION
(
this
<< time);
94
95
uint64_t timeInMillisecs = time.GetMilliSeconds();
96
uint64_t
remainder
= timeInMillisecs % 60000;
97
98
if
(
remainder
)
99
{
100
NS_LOG_WARN
(
101
"ValidTime must be a multiple of 60 seconds, increasing to the next valid value "
);
102
m_validTime
+=
MilliSeconds
(60000 -
remainder
);
103
return
;
104
}
105
106
m_validTime
= time;
107
}
108
109
void
110
SixLowPanNdContext::SetLastUpdateTime
(
Time
time)
111
{
112
NS_LOG_FUNCTION
(
this
<< time);
113
m_lastUpdateTime
= time;
114
}
115
116
Time
117
SixLowPanNdContext::GetLastUpdateTime
()
118
{
119
NS_LOG_FUNCTION
(
this
);
120
return
m_lastUpdateTime
;
121
}
122
123
Ipv6Prefix
124
SixLowPanNdContext::GetContextPrefix
()
const
125
{
126
NS_LOG_FUNCTION
(
this
);
127
return
m_context
;
128
}
129
130
void
131
SixLowPanNdContext::SetContextPrefix
(
Ipv6Prefix
context)
132
{
133
NS_LOG_FUNCTION
(
this
<< context);
134
m_context
= context;
135
}
136
137
void
138
SixLowPanNdContext::PrintContext
(
Ptr<OutputStreamWrapper>
stream)
139
{
140
NS_LOG_FUNCTION
(
this
<< stream);
141
std::ostream* os = stream->GetStream();
142
143
*os <<
" Context Length: "
<<
GetContextLen
();
144
145
if
(
IsFlagC
())
146
{
147
*os <<
" Compression flag: true "
;
148
}
149
else
150
{
151
*os <<
" Compression flag: false "
;
152
}
153
154
*os <<
" Context Identifier: "
<<
GetCid
();
155
*os <<
" Valid Lifetime: "
<<
GetValidTime
();
156
*os <<
" Context Prefix: "
<<
GetContextPrefix
();
157
}
158
159
}
/* namespace ns3 */
remainder
cairo_uint64_t remainder
Definition
cairo-wideint.c:772
ns3::Ipv6Prefix
Describes an IPv6 prefix.
Definition
ipv6-address.h:469
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:70
ns3::SixLowPanNdContext::GetCid
uint8_t GetCid() const
Get the context identifier.
Definition
sixlowpan-nd-context.cc:68
ns3::SixLowPanNdContext::IsFlagC
bool IsFlagC() const
Is compression flag ?
Definition
sixlowpan-nd-context.cc:54
ns3::SixLowPanNdContext::m_validTime
Time m_validTime
The valid lifetime value.
Definition
sixlowpan-nd-context.h:138
ns3::SixLowPanNdContext::SixLowPanNdContext
SixLowPanNdContext()
Constructor.
Definition
sixlowpan-nd-context.cc:23
ns3::SixLowPanNdContext::~SixLowPanNdContext
~SixLowPanNdContext()
Destructor.
Definition
sixlowpan-nd-context.cc:41
ns3::SixLowPanNdContext::GetValidTime
Time GetValidTime() const
Get the valid lifetime.
Definition
sixlowpan-nd-context.cc:83
ns3::SixLowPanNdContext::m_context
Ipv6Prefix m_context
The context prefix value.
Definition
sixlowpan-nd-context.h:148
ns3::SixLowPanNdContext::SetFlagC
void SetFlagC(bool c)
Set the compression flag.
Definition
sixlowpan-nd-context.cc:61
ns3::SixLowPanNdContext::SetValidTime
void SetValidTime(Time time)
Set the valid lifetime.
Definition
sixlowpan-nd-context.cc:91
ns3::SixLowPanNdContext::GetContextLen
uint8_t GetContextLen() const
Get the context length.
Definition
sixlowpan-nd-context.cc:47
ns3::SixLowPanNdContext::m_lastUpdateTime
Time m_lastUpdateTime
The context last update time.
Definition
sixlowpan-nd-context.h:143
ns3::SixLowPanNdContext::PrintContext
void PrintContext(Ptr< OutputStreamWrapper > stream)
Print the 6LoWPAN context.
Definition
sixlowpan-nd-context.cc:138
ns3::SixLowPanNdContext::m_c
bool m_c
The compression flag, indicates that this context is valid for use in compression.
Definition
sixlowpan-nd-context.h:128
ns3::SixLowPanNdContext::SetCid
void SetCid(uint8_t cid)
Set the context identifier.
Definition
sixlowpan-nd-context.cc:75
ns3::SixLowPanNdContext::GetLastUpdateTime
Time GetLastUpdateTime()
Get the last update time.
Definition
sixlowpan-nd-context.cc:117
ns3::SixLowPanNdContext::SetContextPrefix
void SetContextPrefix(Ipv6Prefix context)
Set the 6LoWPAN context prefix.
Definition
sixlowpan-nd-context.cc:131
ns3::SixLowPanNdContext::SetLastUpdateTime
void SetLastUpdateTime(Time time)
Set the last update time.
Definition
sixlowpan-nd-context.cc:110
ns3::SixLowPanNdContext::GetContextPrefix
Ipv6Prefix GetContextPrefix() const
Get the 6LoWPAN context prefix.
Definition
sixlowpan-nd-context.cc:124
ns3::SixLowPanNdContext::m_cid
uint8_t m_cid
The context identifier value.
Definition
sixlowpan-nd-context.h:133
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:95
uint32_t
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition
assert.h:55
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:194
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:231
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition
log.h:253
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1273
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1290
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
sixlowpan-nd-context.h
src
sixlowpan
model
sixlowpan-nd-context.cc
Generated on
for ns-3 by
1.15.0