A Discrete-Event Network Simulator
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
14
15#include "ns3/log.h"
16#include "ns3/simulator.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("SixLowPanNdContext");
22
31
32SixLowPanNdContext::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
45
46uint8_t
48{
49 NS_LOG_FUNCTION(this);
50 return m_context.GetPrefixLength();
51}
52
53bool
55{
56 NS_LOG_FUNCTION(this);
57 return m_c;
58}
59
60void
62{
63 NS_LOG_FUNCTION(this << c);
64 m_c = c;
65}
66
67uint8_t
69{
70 NS_LOG_FUNCTION(this);
71 return m_cid;
72}
73
74void
76{
77 NS_LOG_FUNCTION(this << static_cast<uint32_t>(cid));
78 NS_ASSERT(cid <= 15);
79 m_cid = cid;
80}
81
82Time
84{
85 NS_LOG_FUNCTION(this);
86
87 return m_validTime;
88}
89
90void
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 {
101 "ValidTime must be a multiple of 60 seconds, increasing to the next valid value ");
103 return;
104 }
105
106 m_validTime = time;
107}
108
109void
111{
112 NS_LOG_FUNCTION(this << time);
113 m_lastUpdateTime = time;
114}
115
116Time
122
125{
126 NS_LOG_FUNCTION(this);
127 return m_context;
128}
129
130void
132{
133 NS_LOG_FUNCTION(this << context);
134 m_context = context;
135}
136
137void
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 */
cairo_uint64_t remainder
Describes an IPv6 prefix.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
uint8_t GetCid() const
Get the context identifier.
bool IsFlagC() const
Is compression flag ?
Time m_validTime
The valid lifetime value.
Time GetValidTime() const
Get the valid lifetime.
Ipv6Prefix m_context
The context prefix value.
void SetFlagC(bool c)
Set the compression flag.
void SetValidTime(Time time)
Set the valid lifetime.
uint8_t GetContextLen() const
Get the context length.
Time m_lastUpdateTime
The context last update time.
void PrintContext(Ptr< OutputStreamWrapper > stream)
Print the 6LoWPAN context.
bool m_c
The compression flag, indicates that this context is valid for use in compression.
void SetCid(uint8_t cid)
Set the context identifier.
Time GetLastUpdateTime()
Get the last update time.
void SetContextPrefix(Ipv6Prefix context)
Set the 6LoWPAN context prefix.
void SetLastUpdateTime(Time time)
Set the last update time.
Ipv6Prefix GetContextPrefix() const
Get the 6LoWPAN context prefix.
uint8_t m_cid
The context identifier value.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:253
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
Every class exported by the ns3 library is enclosed in the ns3 namespace.