View | Details | Raw Unified | Return to bug 2805
Collapse All | Expand All

(-)a/src/internet/model/icmpv6-header.h (-2 / +7 lines)
 Lines 68-74   public: Link Here 
68
    ICMPV6_MOBILITY_MOBILE_PREFIX_SOLICITATION,
68
    ICMPV6_MOBILITY_MOBILE_PREFIX_SOLICITATION,
69
    ICMPV6_SECURE_ND_CERTIFICATE_PATH_SOLICITATION,
69
    ICMPV6_SECURE_ND_CERTIFICATE_PATH_SOLICITATION,
70
    ICMPV6_SECURE_ND_CERTIFICATE_PATH_ADVERTISEMENT,
70
    ICMPV6_SECURE_ND_CERTIFICATE_PATH_ADVERTISEMENT,
71
    ICMPV6_EXPERIMENTAL_MOBILITY
71
    ICMPV6_EXPERIMENTAL_MOBILITY,
72
    ICMPV6_ND_DUPLICATE_ADDRESS_REQUEST = 157,
73
    ICMPV6_ND_DUPLICATE_ADDRESS_CONFIRM
72
  };
74
  };
73
75
74
  /**
76
  /**
 Lines 80-86   public: Link Here 
80
    ICMPV6_OPT_LINK_LAYER_TARGET,
82
    ICMPV6_OPT_LINK_LAYER_TARGET,
81
    ICMPV6_OPT_PREFIX,
83
    ICMPV6_OPT_PREFIX,
82
    ICMPV6_OPT_REDIRECTED,
84
    ICMPV6_OPT_REDIRECTED,
83
    ICMPV6_OPT_MTU
85
    ICMPV6_OPT_MTU,
86
    ICMPV6_OPT_ADDRESS_REGISTRATION = 33,
87
    ICMPV6_OPT_SIXLOWPAN_CONTEXT,
88
    ICMPV6_OPT_AUTHORITATIVE_BORDER_ROUTER
84
  };
89
  };
85
90
86
  /**
91
  /**
(-)a/src/internet/model/icmpv6-l4-protocol.cc (+6 lines)
 Lines 161-166   void Icmpv6L4Protocol::SetNode (Ptr<Node> node) Link Here 
161
  m_node = node;
161
  m_node = node;
162
}
162
}
163
163
164
Ptr<Node> Icmpv6L4Protocol::GetNode ()
165
{
166
  NS_LOG_FUNCTION (this);
167
  return m_node;
168
}
169
164
uint16_t Icmpv6L4Protocol::GetStaticProtocolNumber ()
170
uint16_t Icmpv6L4Protocol::GetStaticProtocolNumber ()
165
{
171
{
166
  NS_LOG_FUNCTION_NOARGS ();
172
  NS_LOG_FUNCTION_NOARGS ();
(-)a/src/internet/model/icmpv6-l4-protocol.h (-26 / +32 lines)
 Lines 115-120   public: Link Here 
115
   */
115
   */
116
  void SetNode (Ptr<Node> node);
116
  void SetNode (Ptr<Node> node);
117
117
118
  /**
119
   * \brief Get the node.
120
   * \return node
121
   */
122
  Ptr<Node> GetNode ();
123
118
  /**
124
  /**
119
   * \brief This method is called by AddAgregate and completes the aggregation
125
   * \brief This method is called by AddAgregate and completes the aggregation
120
   * by setting the node in the ICMPv6 stack and adding ICMPv6 factory to
126
   * by setting the node in the ICMPv6 stack and adding ICMPv6 factory to
 Lines 199-205   public: Link Here 
199
   * \param target target IPv6 address
205
   * \param target target IPv6 address
200
   * \param hardwareAddress our mac address
206
   * \param hardwareAddress our mac address
201
   */
207
   */
202
  void SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress);
208
  virtual void SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress);
203
209
204
  /**
210
  /**
205
   * \brief Send an error Destination Unreachable.
211
   * \brief Send an error Destination Unreachable.
 Lines 380-385   protected: Link Here 
380
   */
386
   */
381
  virtual void DoDispose ();
387
  virtual void DoDispose ();
382
388
389
  /**
390
   * \brief Get the cache corresponding to the device.
391
   * \param device the device
392
   * \returns the NdiscCache associated with the device
393
   */
394
  Ptr<NdiscCache> FindCache (Ptr<NetDevice> device);
395
396
  /**
397
   * \brief Receive Neighbor Advertisement method.
398
   * \param p the packet
399
   * \param src source address
400
   * \param dst destination address
401
   * \param interface the interface from which the packet is coming
402
   */
403
  void HandleNA (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
404
405
  /**
406
   * \brief Link layer address option processing.
407
   * \param lla LLA option
408
   * \param src source address
409
   * \param dst destination address
410
   * \param interface the interface from which the packet is coming
411
   */
412
  void ReceiveLLA (Icmpv6OptionLinkLayerAddress lla, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
413
383
private:
414
private:
384
  typedef std::list<Ptr<NdiscCache> > CacheList; //!< container of NdiscCaches
415
  typedef std::list<Ptr<NdiscCache> > CacheList; //!< container of NdiscCaches
385
416
 Lines 477-491   private: Link Here 
477
   */
508
   */
478
  void HandleEchoRequest (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
509
  void HandleEchoRequest (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
479
510
480
  /**
481
   * \brief Receive Neighbor Advertisement method.
482
   * \param p the packet
483
   * \param src source address
484
   * \param dst destination address
485
   * \param interface the interface from which the packet is coming
486
   */
487
  void HandleNA (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
488
489
  /**
511
  /**
490
   * \brief Receive Redirection method.
512
   * \brief Receive Redirection method.
491
   * \param p the packet
513
   * \param p the packet
 Lines 531-552   private: Link Here 
531
   */
553
   */
532
  void HandleParameterError (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
554
  void HandleParameterError (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
533
555
534
  /**
535
   * \brief Link layer address option processing.
536
   * \param lla LLA option
537
   * \param src source address
538
   * \param dst destination address
539
   * \param interface the interface from which the packet is coming
540
   */
541
  void ReceiveLLA (Icmpv6OptionLinkLayerAddress lla, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
542
543
  /**
544
   * \brief Get the cache corresponding to the device.
545
   * \param device the device
546
   * \returns the NdiscCache associated with the device
547
   */
548
  Ptr<NdiscCache> FindCache (Ptr<NetDevice> device);
549
550
  // From IpL4Protocol
556
  // From IpL4Protocol
551
  virtual void SetDownTarget (IpL4Protocol::DownTargetCallback cb);
557
  virtual void SetDownTarget (IpL4Protocol::DownTargetCallback cb);
552
  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
558
  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
(-)a/src/internet/model/ndisc-cache.h (-10 / +12 lines)
 Lines 342-347   public: Link Here 
342
     */
342
     */
343
    void SetIpv6Address (Ipv6Address ipv6Address);
343
    void SetIpv6Address (Ipv6Address ipv6Address);
344
344
345
protected:
346
    /**
347
     * \brief the NdiscCache associated.
348
     */
349
    NdiscCache* m_ndCache;
350
345
private:
351
private:
346
    /**
352
    /**
347
     * \brief The IPv6 address.
353
     * \brief The IPv6 address.
 Lines 366-376   private: Link Here 
366
     */
372
     */
367
    NdiscCacheEntryState_e m_state;
373
    NdiscCacheEntryState_e m_state;
368
374
369
    /**
370
     * \brief the NdiscCache associated.
371
     */
372
    NdiscCache* m_ndCache;
373
374
    /**
375
    /**
375
     * \brief The MAC address.
376
     * \brief The MAC address.
376
     */
377
     */
 Lines 402-407   private: Link Here 
402
    uint8_t m_nsRetransmit;
403
    uint8_t m_nsRetransmit;
403
  };
404
  };
404
405
406
protected:
407
  /**
408
   * \brief Dispose this object.
409
   */
410
  void DoDispose ();
411
405
private:
412
private:
406
  /**
413
  /**
407
   * \brief Neighbor Discovery Cache container
414
   * \brief Neighbor Discovery Cache container
 Lines 427-437   private: Link Here 
427
   */
434
   */
428
  NdiscCache& operator= (NdiscCache const &);
435
  NdiscCache& operator= (NdiscCache const &);
429
436
430
  /**
431
   * \brief Dispose this object.
432
   */
433
  void DoDispose ();
434
435
  /**
437
  /**
436
   * \brief The NetDevice.
438
   * \brief The NetDevice.
437
   */
439
   */
(-)a/src/sixlowpan/model/sixlowpan-nd-header.cc (+771 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#include "ns3/assert.h"
22
#include "ns3/address-utils.h"
23
#include "ns3/log.h"
24
25
#include "sixlowpan-nd-header.h"
26
27
namespace ns3
28
{
29
30
NS_LOG_COMPONENT_DEFINE ("SixLowPanNdHeader");
31
32
NS_OBJECT_ENSURE_REGISTERED (Icmpv6DuplicateAddress);
33
34
Icmpv6DuplicateAddress::Icmpv6DuplicateAddress ()
35
{
36
  NS_LOG_FUNCTION (this);
37
  SetType (Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_REQUEST);
38
  SetCode (0);
39
  SetChecksum (0);
40
  m_status = 0;
41
  m_reserved = 0;
42
  m_regTime = 0;
43
  m_eui64 = Mac64Address ("00:00:00:00:00:00");
44
  m_regAddress = Ipv6Address ("::");
45
}
46
47
Icmpv6DuplicateAddress::Icmpv6DuplicateAddress (bool request)
48
{
49
  NS_LOG_FUNCTION (this << request);
50
  SetType (request ? Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_REQUEST : Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_CONFIRM);
51
  SetCode (0);
52
  SetChecksum (0);
53
  m_status = 0;
54
  m_reserved = 0;
55
  m_regTime = 0;
56
  m_eui64 = Mac64Address ("00:00:00:00:00:00");
57
  m_regAddress = Ipv6Address ("::");
58
}
59
60
Icmpv6DuplicateAddress::Icmpv6DuplicateAddress (uint16_t time, Mac64Address eui, Ipv6Address address)
61
{
62
  NS_LOG_FUNCTION (this);
63
  SetType (Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_REQUEST);
64
  SetCode (0);
65
  SetChecksum (0);
66
  m_status = 0;
67
  m_reserved = 0;
68
  m_regTime = time;
69
  m_eui64 = eui;
70
  m_regAddress = address;
71
}
72
73
Icmpv6DuplicateAddress::Icmpv6DuplicateAddress (uint8_t status, uint16_t time, Mac64Address eui, Ipv6Address address)
74
{
75
  NS_LOG_FUNCTION (this);
76
  SetType (Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_CONFIRM);
77
  SetCode (0);
78
  SetChecksum (0);
79
  m_status = status;
80
  m_reserved = 0;
81
  m_regTime = time;
82
  m_eui64 = eui;
83
  m_regAddress = address;
84
}
85
86
Icmpv6DuplicateAddress::~Icmpv6DuplicateAddress ()
87
{
88
  NS_LOG_FUNCTION (this);
89
}
90
91
TypeId Icmpv6DuplicateAddress::GetTypeId ()
92
{
93
  static TypeId tid = TypeId ("ns3::Icmpv6DuplicateAddress")
94
        .SetParent<Icmpv6Header> ()
95
        .SetGroupName ("Internet")
96
        .AddConstructor<Icmpv6DuplicateAddress> ()
97
        ;
98
  return tid;
99
}
100
101
TypeId Icmpv6DuplicateAddress::GetInstanceTypeId () const
102
{
103
  NS_LOG_FUNCTION (this);
104
  return GetTypeId ();
105
}
106
107
uint8_t Icmpv6DuplicateAddress::GetStatus () const
108
{
109
  NS_LOG_FUNCTION (this);
110
  return m_status;
111
}
112
113
void Icmpv6DuplicateAddress::SetStatus (uint8_t status)
114
{
115
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (status));
116
  m_status = status;
117
}
118
119
uint8_t Icmpv6DuplicateAddress::GetReserved () const
120
{
121
  NS_LOG_FUNCTION (this);
122
  return m_reserved;
123
}
124
125
void Icmpv6DuplicateAddress::SetReserved (uint8_t reserved)
126
{
127
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (reserved));
128
  m_reserved = reserved;
129
}
130
131
uint16_t Icmpv6DuplicateAddress::GetRegTime () const
132
{
133
  NS_LOG_FUNCTION (this);
134
  return m_regTime;
135
}
136
137
void Icmpv6DuplicateAddress::SetRegTime (uint16_t time)
138
{
139
  NS_LOG_FUNCTION (this << time);
140
  m_regTime = time;
141
}
142
143
Mac64Address Icmpv6DuplicateAddress::GetEui64 () const
144
{
145
  NS_LOG_FUNCTION (this);
146
  return m_eui64;
147
}
148
149
void Icmpv6DuplicateAddress::SetEui64 (Mac64Address eui)
150
{
151
  NS_LOG_FUNCTION (this << eui);
152
  m_eui64 = eui;
153
}
154
155
Ipv6Address Icmpv6DuplicateAddress::GetRegAddress () const
156
{
157
  NS_LOG_FUNCTION (this);
158
  return m_regAddress;
159
}
160
161
void Icmpv6DuplicateAddress::SetRegAddress (Ipv6Address registered)
162
{
163
  NS_LOG_FUNCTION (this << registered);
164
  m_regAddress = registered;
165
}
166
167
void Icmpv6DuplicateAddress::Print (std::ostream& os) const
168
{
169
  NS_LOG_FUNCTION (this << &os);
170
  os << "( type = " << (uint32_t)GetType () << " code = " << (uint32_t)GetCode () << " status = " << (uint32_t)m_status << " lifetime = " << m_regTime << " EUI-64 = " << m_eui64 <<  " registered = " << m_regAddress << " checksum = " << (uint32_t)GetChecksum ()  << ")";
171
}
172
173
uint32_t Icmpv6DuplicateAddress::GetSerializedSize () const
174
{
175
  NS_LOG_FUNCTION (this);
176
  return 32;
177
}
178
179
void Icmpv6DuplicateAddress::Serialize (Buffer::Iterator start) const
180
{
181
  NS_LOG_FUNCTION (this << &start);
182
  uint8_t buf1[8];
183
  uint8_t buf2[16];
184
  uint16_t checksum = 0;
185
  Buffer::Iterator i = start;
186
187
  memset (buf1, 0x00, sizeof (buf1));
188
  memset (buf2, 0x0000, sizeof (buf2));
189
190
  i.WriteU8 (GetType ());
191
  i.WriteU8 (GetCode ());
192
  i.WriteU16 (checksum);
193
  i.WriteU8 (m_status);
194
  i.WriteU8 (m_reserved);
195
  i.WriteU16 (m_regTime);
196
197
  m_eui64.CopyTo (buf1);
198
  i.Write (buf1, 8);
199
200
  m_regAddress.Serialize (buf2);
201
  i.Write (buf2, 16);
202
203
  i = start;
204
  checksum = i.CalculateIpChecksum (i.GetSize (), GetChecksum ());
205
206
  i = start;
207
  i.Next (2);
208
  i.WriteU16 (checksum);
209
}
210
211
uint32_t Icmpv6DuplicateAddress::Deserialize (Buffer::Iterator start)
212
{
213
  NS_LOG_FUNCTION (this << &start);
214
  uint8_t buf1[8];
215
  uint8_t buf2[16];
216
  Buffer::Iterator i = start;
217
218
  memset (buf1, 0x00, sizeof (buf1));
219
  memset (buf2, 0x0000, sizeof (buf2));
220
221
  SetType (i.ReadU8 ());
222
  SetCode (i.ReadU8 ());
223
  SetChecksum (i.ReadU16 ());
224
  m_status = i.ReadU8 ();
225
  m_reserved = i.ReadU8 ();
226
  m_regTime = i.ReadU16 ();
227
228
  i.Read (buf1, 8);
229
  m_eui64.CopyFrom (buf1);
230
231
  i.Read (buf2, 16);
232
  m_regAddress.Deserialize (buf2);
233
234
  return GetSerializedSize ();
235
}
236
237
238
NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionAddressRegistration);
239
240
Icmpv6OptionAddressRegistration::Icmpv6OptionAddressRegistration ()
241
{
242
  NS_LOG_FUNCTION (this);
243
  SetType (Icmpv6Header::ICMPV6_OPT_ADDRESS_REGISTRATION);
244
  SetLength (2);
245
  m_status = 0;
246
  m_reserved1 = 0;
247
  m_reserved2 = 0;
248
  m_regTime = 0;
249
  m_eui64 = Mac64Address ("00:00:00:00:00:00");
250
}
251
252
Icmpv6OptionAddressRegistration::Icmpv6OptionAddressRegistration (uint16_t time, Mac64Address eui)
253
{
254
  NS_LOG_FUNCTION (this);
255
  SetType (Icmpv6Header::ICMPV6_OPT_ADDRESS_REGISTRATION);
256
  SetLength (2);
257
  m_status = 0;
258
  m_reserved1 = 0;
259
  m_reserved2 = 0;
260
  m_regTime = time;
261
  m_eui64 = eui;
262
}
263
264
Icmpv6OptionAddressRegistration::Icmpv6OptionAddressRegistration (uint8_t status, uint16_t time, Mac64Address eui)
265
{
266
  NS_LOG_FUNCTION (this);
267
  SetType (Icmpv6Header::ICMPV6_OPT_ADDRESS_REGISTRATION);
268
  SetLength (2);
269
  m_status = status;
270
  m_reserved1 = 0;
271
  m_reserved2 = 0;
272
  m_regTime = time;
273
  m_eui64 = eui;
274
}
275
276
Icmpv6OptionAddressRegistration::~Icmpv6OptionAddressRegistration ()
277
{
278
  NS_LOG_FUNCTION (this);
279
}
280
281
TypeId Icmpv6OptionAddressRegistration::GetTypeId ()
282
{
283
  static TypeId tid = TypeId ("ns3::Icmpv6OptionAddressRegistration")
284
        .SetParent<Icmpv6OptionHeader> ()
285
        .SetGroupName ("Internet")
286
        .AddConstructor<Icmpv6OptionAddressRegistration> ()
287
        ;
288
  return tid;
289
}
290
291
TypeId Icmpv6OptionAddressRegistration::GetInstanceTypeId () const
292
{
293
  NS_LOG_FUNCTION (this);
294
  return GetTypeId ();
295
}
296
297
uint8_t Icmpv6OptionAddressRegistration::GetStatus () const
298
{
299
  NS_LOG_FUNCTION (this);
300
  return m_status;
301
}
302
303
void Icmpv6OptionAddressRegistration::SetStatus (uint8_t status)
304
{
305
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (status));
306
  m_status = status;
307
}
308
309
uint8_t Icmpv6OptionAddressRegistration::GetReserved1 () const
310
{
311
  NS_LOG_FUNCTION (this);
312
  return m_reserved1;
313
}
314
315
void Icmpv6OptionAddressRegistration::SetReserved1 (uint8_t reserved)
316
{
317
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (reserved));
318
  m_reserved1 = reserved;
319
}
320
321
uint16_t Icmpv6OptionAddressRegistration::GetReserved2 () const
322
{
323
  NS_LOG_FUNCTION (this);
324
  return m_reserved2;
325
}
326
327
void Icmpv6OptionAddressRegistration::SetReserved2 (uint16_t reserved)
328
{
329
  NS_LOG_FUNCTION (this << reserved);
330
  m_reserved2 = reserved;
331
}
332
333
uint16_t Icmpv6OptionAddressRegistration::GetRegTime () const
334
{
335
  NS_LOG_FUNCTION (this);
336
  return m_regTime;
337
}
338
339
void Icmpv6OptionAddressRegistration::SetRegTime (uint16_t time)
340
{
341
  NS_LOG_FUNCTION (this << time);
342
  m_regTime = time;
343
}
344
345
Mac64Address Icmpv6OptionAddressRegistration::GetEui64 () const
346
{
347
  NS_LOG_FUNCTION (this);
348
  return m_eui64;
349
}
350
351
void Icmpv6OptionAddressRegistration::SetEui64 (Mac64Address eui)
352
{
353
  NS_LOG_FUNCTION (this << eui);
354
  m_eui64 = eui;
355
}
356
357
void Icmpv6OptionAddressRegistration::Print (std::ostream& os) const
358
{
359
  NS_LOG_FUNCTION (this << &os);
360
  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " status " << (uint32_t)m_status << " lifetime " << m_regTime << " EUI-64 " << m_eui64 << ")";
361
}
362
363
uint32_t Icmpv6OptionAddressRegistration::GetSerializedSize () const
364
{
365
  NS_LOG_FUNCTION (this);
366
  return 16;
367
}
368
369
void Icmpv6OptionAddressRegistration::Serialize (Buffer::Iterator start) const
370
{
371
  NS_LOG_FUNCTION (this << &start);
372
  Buffer::Iterator i = start;
373
  uint8_t buf[8];
374
375
  memset (buf, 0x00, sizeof (buf));
376
377
  i.WriteU8 (GetType ());
378
  i.WriteU8 (GetLength ());
379
  i.WriteU8 (m_status);
380
  i.WriteU8 (m_reserved1);
381
  i.WriteU16 (m_reserved2);
382
  i.WriteU16 (m_regTime);
383
384
  m_eui64.CopyTo (buf);
385
  i.Write (buf, 8);
386
}
387
388
uint32_t Icmpv6OptionAddressRegistration::Deserialize (Buffer::Iterator start)
389
{
390
  NS_LOG_FUNCTION (this << &start);
391
  Buffer::Iterator i = start;
392
  uint8_t buf[8];
393
394
  memset (buf, 0x00, sizeof (buf));
395
396
  SetType (i.ReadU8 ());
397
  SetLength (i.ReadU8 ());
398
  m_status = i.ReadU8 ();
399
  m_reserved1 = i.ReadU8 ();
400
  m_reserved2 = i.ReadU16 ();
401
  m_regTime = i.ReadU16 ();
402
403
  i.Read (buf, 8);
404
  m_eui64.CopyFrom (buf);
405
406
  return GetSerializedSize ();
407
}
408
409
410
NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionSixLowPanContext);
411
412
Icmpv6OptionSixLowPanContext::Icmpv6OptionSixLowPanContext ()
413
{
414
  NS_LOG_FUNCTION (this);
415
  SetType (Icmpv6Header::ICMPV6_OPT_SIXLOWPAN_CONTEXT);
416
  SetLength (0);
417
  m_contextLen = 0;
418
  m_reserved1 = 0;
419
  m_c = false;
420
  m_cid = 0;
421
  m_reserved2 = 0;
422
  m_validTime = 0;
423
  m_prefix = Ipv6Prefix ("::");
424
}
425
426
Icmpv6OptionSixLowPanContext::Icmpv6OptionSixLowPanContext (bool c, uint8_t cid, uint16_t time, Ipv6Prefix prefix)
427
{
428
  NS_LOG_FUNCTION (this);
429
  SetType (Icmpv6Header::ICMPV6_OPT_SIXLOWPAN_CONTEXT);
430
431
  if (prefix.GetPrefixLength () > 64)
432
    {
433
      SetLength (3);
434
    }
435
  else
436
    {
437
      SetLength (2);
438
    }
439
440
  m_contextLen = prefix.GetPrefixLength ();
441
  m_reserved1 = 0;
442
  m_c = c;
443
  m_cid = cid;
444
  m_reserved2 = 0;
445
  m_validTime = time;
446
  m_prefix = prefix;
447
}
448
449
Icmpv6OptionSixLowPanContext::~Icmpv6OptionSixLowPanContext ()
450
{
451
  NS_LOG_FUNCTION (this);
452
}
453
454
TypeId Icmpv6OptionSixLowPanContext::GetTypeId ()
455
{
456
  static TypeId tid = TypeId ("ns3::Icmpv6OptionSixLowPanContext")
457
            .SetParent<Icmpv6OptionHeader> ()
458
            .SetGroupName ("Internet")
459
            .AddConstructor<Icmpv6OptionSixLowPanContext> ()
460
            ;
461
  return tid;
462
}
463
464
TypeId Icmpv6OptionSixLowPanContext::GetInstanceTypeId () const
465
{
466
  NS_LOG_FUNCTION (this);
467
  return GetTypeId ();
468
}
469
470
uint8_t Icmpv6OptionSixLowPanContext::GetContextLen () const
471
{
472
  NS_LOG_FUNCTION (this);
473
  return m_contextLen;
474
}
475
476
void Icmpv6OptionSixLowPanContext::SetContextLen (uint8_t cLen)
477
{
478
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (cLen));
479
  NS_ASSERT (cLen <= 128);
480
  m_contextLen = cLen;
481
}
482
483
uint8_t Icmpv6OptionSixLowPanContext::GetReserved1 () const
484
{
485
  NS_LOG_FUNCTION (this);
486
  return m_reserved1;
487
}
488
489
void Icmpv6OptionSixLowPanContext::SetReserved1 (uint8_t reserved1)
490
{
491
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (reserved1));
492
  m_reserved1 = reserved1;
493
}
494
495
bool Icmpv6OptionSixLowPanContext::IsFlagC () const
496
{
497
  NS_LOG_FUNCTION (this);
498
  return m_c;
499
}
500
501
void Icmpv6OptionSixLowPanContext::SetFlagC (bool c)
502
{
503
  NS_LOG_FUNCTION (this << c);
504
  m_c = c;
505
}
506
507
uint8_t Icmpv6OptionSixLowPanContext::GetCid () const
508
{
509
  NS_LOG_FUNCTION (this);
510
  return m_cid;
511
}
512
513
void Icmpv6OptionSixLowPanContext::SetCid (uint8_t cid)
514
{
515
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (cid));
516
  NS_ASSERT (cid <= 15);
517
  m_cid = cid;
518
}
519
520
uint16_t Icmpv6OptionSixLowPanContext::GetReserved2 () const
521
{
522
  NS_LOG_FUNCTION (this);
523
  return m_reserved2;
524
}
525
526
void Icmpv6OptionSixLowPanContext::SetReserved2 (uint16_t reserved2)
527
{
528
  NS_LOG_FUNCTION (this << reserved2);
529
  m_reserved2 = reserved2;
530
}
531
532
uint16_t Icmpv6OptionSixLowPanContext::GetValidTime () const
533
{
534
  NS_LOG_FUNCTION (this);
535
  return m_validTime;
536
}
537
538
void Icmpv6OptionSixLowPanContext::SetValidTime (uint16_t time)
539
{
540
  NS_LOG_FUNCTION (this << time);
541
  m_validTime = time;
542
}
543
544
Ipv6Prefix Icmpv6OptionSixLowPanContext::GetContextPrefix () const
545
{
546
  NS_LOG_FUNCTION (this);
547
  return m_prefix;
548
}
549
550
void Icmpv6OptionSixLowPanContext::SetContextPrefix (Ipv6Prefix prefix)
551
{
552
  NS_LOG_FUNCTION (this << prefix);
553
  m_prefix = prefix;
554
}
555
556
void Icmpv6OptionSixLowPanContext::Print (std::ostream& os) const
557
{
558
  NS_LOG_FUNCTION (this << &os);
559
  os << "( type = " << (uint32_t)GetType () << " length = "
560
      << (uint32_t)GetLength () << " context length = "
561
      << (uint32_t)m_contextLen << " flag C = " << m_c << " CID = "
562
      << (uint32_t)m_cid << " lifetime = " << m_validTime
563
      << " context prefix = " << m_prefix << ")";
564
}
565
566
uint32_t Icmpv6OptionSixLowPanContext::GetSerializedSize () const
567
{
568
  NS_LOG_FUNCTION (this);
569
  uint8_t nb = GetLength() * 8;
570
  return nb;
571
}
572
573
void Icmpv6OptionSixLowPanContext::Serialize (Buffer::Iterator start) const
574
{
575
  NS_LOG_FUNCTION (this << &start);
576
  Buffer::Iterator i = start;
577
  uint8_t buf[16];
578
  uint8_t reserved = m_reserved1;
579
580
  memset (buf, 0x0000, sizeof (buf));
581
582
  i.WriteU8 (GetType ());
583
  i.WriteU8 (GetLength ());
584
  i.WriteU8 (m_contextLen);
585
586
  reserved |= m_cid;
587
  reserved |= (uint8_t)(m_c << 4);
588
589
  i.WriteU8 (reserved);
590
  i.WriteU16 (m_reserved2);
591
  i.WriteU16 (m_validTime);
592
593
  m_prefix.GetBytes (buf);
594
  i.Write (buf, 16);
595
}
596
597
uint32_t Icmpv6OptionSixLowPanContext::Deserialize (Buffer::Iterator start)
598
{
599
  NS_LOG_FUNCTION (this << &start);
600
  Buffer::Iterator i = start;
601
  uint8_t buf[16];
602
  uint8_t reserved;
603
604
  memset (buf, 0x0000, sizeof (buf));
605
606
  SetType (i.ReadU8 ());
607
  SetLength (i.ReadU8 ());
608
  SetContextLen (i.ReadU8 ());
609
610
  reserved = i.ReadU8 ();
611
  m_c = false;
612
  if (reserved & (uint8_t)(1 << 4))
613
    {
614
      m_c = true;
615
    }
616
  m_cid = reserved & 0xF;
617
  m_reserved1 = reserved >> 5;
618
619
  m_reserved2 = i.ReadU16 ();
620
  m_validTime = i.ReadNtohU16 ();
621
622
  i.Read (buf, 16);
623
  m_prefix = Ipv6Prefix (buf);
624
625
  return GetSerializedSize ();
626
}
627
628
629
NS_OBJECT_ENSURE_REGISTERED (Icmpv6OptionAuthoritativeBorderRouter);
630
631
Icmpv6OptionAuthoritativeBorderRouter::Icmpv6OptionAuthoritativeBorderRouter ()
632
{
633
  NS_LOG_FUNCTION (this);
634
  SetType (Icmpv6Header::ICMPV6_OPT_AUTHORITATIVE_BORDER_ROUTER);
635
  SetLength (3);
636
  m_version = 0;
637
  m_validTime = 0;
638
  m_routerAddress = Ipv6Address ("::");
639
}
640
641
Icmpv6OptionAuthoritativeBorderRouter::Icmpv6OptionAuthoritativeBorderRouter (uint32_t version, uint16_t time, Ipv6Address address)
642
{
643
  NS_LOG_FUNCTION (this);
644
  SetType (Icmpv6Header::ICMPV6_OPT_AUTHORITATIVE_BORDER_ROUTER);
645
  SetLength (3);
646
  m_version = version;
647
  m_validTime = time;
648
  m_routerAddress = address;
649
}
650
651
Icmpv6OptionAuthoritativeBorderRouter::~Icmpv6OptionAuthoritativeBorderRouter ()
652
{
653
  NS_LOG_FUNCTION (this);
654
}
655
656
TypeId Icmpv6OptionAuthoritativeBorderRouter::GetTypeId ()
657
{
658
  static TypeId tid = TypeId ("ns3::Icmpv6OptionAuthoritativeBorderRouter")
659
        .SetParent<Icmpv6OptionHeader> ()
660
        .SetGroupName ("Internet")
661
        .AddConstructor<Icmpv6OptionAuthoritativeBorderRouter> ()
662
        ;
663
  return tid;
664
}
665
666
TypeId Icmpv6OptionAuthoritativeBorderRouter::GetInstanceTypeId () const
667
{
668
  NS_LOG_FUNCTION (this);
669
  return GetTypeId ();
670
}
671
672
uint32_t Icmpv6OptionAuthoritativeBorderRouter::GetVersion () const
673
{
674
  NS_LOG_FUNCTION (this);
675
  return m_version;
676
}
677
678
void Icmpv6OptionAuthoritativeBorderRouter::SetVersion (uint32_t version)
679
{
680
  NS_LOG_FUNCTION (this << version);
681
  m_version = version;
682
}
683
684
uint16_t Icmpv6OptionAuthoritativeBorderRouter::GetValidTime () const
685
{
686
  NS_LOG_FUNCTION (this);
687
  return m_validTime;
688
}
689
690
void Icmpv6OptionAuthoritativeBorderRouter::SetValidTime (uint16_t time)
691
{
692
  NS_LOG_FUNCTION (this << time);
693
  m_validTime = time;
694
}
695
696
Ipv6Address Icmpv6OptionAuthoritativeBorderRouter::GetRouterAddress () const
697
{
698
  NS_LOG_FUNCTION (this);
699
  return m_routerAddress;
700
}
701
702
void Icmpv6OptionAuthoritativeBorderRouter::SetRouterAddress (Ipv6Address router)
703
{
704
  NS_LOG_FUNCTION (this << router);
705
  m_routerAddress = router;
706
}
707
708
void Icmpv6OptionAuthoritativeBorderRouter::Print (std::ostream& os) const
709
{
710
  NS_LOG_FUNCTION (this << &os);
711
  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " version = " << m_version << " lifetime = " << m_validTime << " router address = " << m_routerAddress << ")";
712
}
713
714
uint32_t Icmpv6OptionAuthoritativeBorderRouter::GetSerializedSize () const
715
{
716
  NS_LOG_FUNCTION (this);
717
  return 24;
718
}
719
720
void Icmpv6OptionAuthoritativeBorderRouter::Serialize (Buffer::Iterator start) const
721
{
722
  NS_LOG_FUNCTION (this << &start);
723
  Buffer::Iterator i = start;
724
  uint8_t buf[16];
725
  uint32_t versionL = m_version;
726
  uint32_t versionH = m_version;
727
728
  memset (buf, 0x0000, sizeof (buf));
729
730
  i.WriteU8 (GetType ());
731
  i.WriteU8 (GetLength ());
732
733
  versionL &= 0xFFFF;
734
  i.WriteU16 ((uint16_t)versionL);
735
  versionH >>= 16;
736
  versionH &= 0xFFFF;
737
  i.WriteU16 ((uint16_t)versionH);
738
739
  i.WriteU16 (m_validTime);
740
741
  m_routerAddress.Serialize (buf);
742
  i.Write (buf, 16);
743
}
744
745
uint32_t Icmpv6OptionAuthoritativeBorderRouter::Deserialize (Buffer::Iterator start)
746
{
747
  NS_LOG_FUNCTION (this << &start);
748
  Buffer::Iterator i = start;
749
  uint8_t buf[16];
750
  uint32_t versionL;
751
  uint32_t versionH;
752
753
  memset (buf, 0x0000, sizeof (buf));
754
755
  SetType (i.ReadU8 ());
756
  SetLength (i.ReadU8 ());
757
758
  versionL = (uint32_t)i.ReadU16 ();
759
  versionH = (uint32_t)i.ReadU16 ();
760
  versionH <<= 16;
761
  m_version = (versionL &= 0xFFFF) + (versionH &= 0xFFFF0000);
762
763
  m_validTime = i.ReadU16 ();
764
765
  i.Read (buf, 16);
766
  m_routerAddress.Deserialize (buf);
767
768
  return GetSerializedSize ();
769
}
770
771
} /* namespace ns3 */
(-)a/src/sixlowpan/model/sixlowpan-nd-header.h (+668 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#ifndef SIXLOWPAN_ND_HEADER_H
22
#define SIXLOWPAN_ND_HEADER_H
23
24
#include "ns3/header.h"
25
#include "ns3/ipv6-address.h"
26
#include "ns3/mac64-address.h"
27
#include "ns3/icmpv6-header.h"
28
29
namespace ns3
30
{
31
32
/**
33
 * \ingroup sixlowpan
34
 * \class Icmpv6DuplicateAddress
35
 * \brief ICMPv6 Duplicate Address header.
36
 */
37
class Icmpv6DuplicateAddress : public Icmpv6Header
38
{
39
public:
40
41
  /**
42
   * \brief Constructor.
43
   */
44
  Icmpv6DuplicateAddress ();
45
46
  /**
47
     * \brief Constructor.
48
     * \param request duplicate address request or duplicate address confirm
49
     */
50
  Icmpv6DuplicateAddress (bool request);
51
52
  /**
53
   * \brief Constructor (DAR).
54
   * \param time the registration lifetime (units of 60 seconds)
55
   * \param eui the EUI-64
56
   * \param address the registrered address
57
   */
58
  Icmpv6DuplicateAddress (uint16_t time, Mac64Address eui, Ipv6Address address);
59
60
  /**
61
   * \brief Constructor (DAC).
62
   * \param status the status (DAC)
63
   * \param time the registration lifetime (units of 60 seconds)
64
   * \param eui the EUI-64
65
   * \param address the registrered address
66
   */
67
  Icmpv6DuplicateAddress (uint8_t status, uint16_t time, Mac64Address eui, Ipv6Address address);
68
69
  /**
70
   * \brief Destructor.
71
   */
72
  virtual ~Icmpv6DuplicateAddress ();
73
74
  /**
75
   * \brief Get the UID of this class.
76
   * \return UID
77
   */
78
  static TypeId GetTypeId ();
79
80
  /**
81
   * \brief Get the instance type ID.
82
   * \return instance type ID
83
   */
84
  virtual TypeId GetInstanceTypeId () const;
85
86
  /**
87
   * \brief Get the status field.
88
   * \return status value
89
   */
90
  uint8_t GetStatus () const;
91
92
  /**
93
   * \brief Set the status field.
94
   * \param status the status value
95
   */
96
  void SetStatus (uint8_t status);
97
98
  /**
99
   * \brief Get the reserved field.
100
   * \return reserved value
101
   */
102
  uint8_t GetReserved () const;
103
104
  /**
105
   * \brief Set the reserved field.
106
   * \param reserved the reserved value
107
   */
108
  void SetReserved (uint8_t reserved);
109
110
  /**
111
   * \brief Get the registration lifetime field.
112
   * \return registration lifetime value (units of 60 seconds)
113
   */
114
  uint16_t GetRegTime () const;
115
116
  /**
117
   * \brief Set the registration lifetime field.
118
   * \param time the registration lifetime value (units of 60 seconds)
119
   */
120
  void SetRegTime (uint16_t time);
121
122
  /**
123
   * \brief Get the EUI-64 field.
124
   * \return EUI-64 value
125
   */
126
  Mac64Address GetEui64 () const;
127
128
  /**
129
   * \brief Set the EUI-64 field.
130
   * \param eui the EUI-64 value
131
   */
132
  void SetEui64 (Mac64Address eui);
133
134
  /**
135
   * \brief Get the registered address field.
136
   * \return registered address value
137
   */
138
  Ipv6Address GetRegAddress () const;
139
140
  /**
141
   * \brief Set the registered address field.
142
   * \param registered the registered address value
143
   */
144
  void SetRegAddress (Ipv6Address registered);
145
146
  /**
147
   * \brief Print informations.
148
   * \param os output stream
149
   */
150
  virtual void Print (std::ostream& os) const;
151
152
  /**
153
   * \brief Get the serialized size.
154
   * \return serialized size
155
   */
156
  virtual uint32_t GetSerializedSize () const;
157
158
  /**
159
   * \brief Serialize the packet.
160
   * \param start start offset
161
   */
162
  virtual void Serialize (Buffer::Iterator start) const;
163
164
  /**
165
   * \brief Deserialize the packet.
166
   * \param start start offset
167
   * \return length of packet
168
   */
169
  virtual uint32_t Deserialize (Buffer::Iterator start);
170
171
private:
172
173
  /**
174
   * \brief The status value.
175
   */
176
  uint8_t m_status;
177
178
  /**
179
   * \brief The reserved value.
180
   */
181
  uint8_t m_reserved;
182
183
  /**
184
   * \brief The registration lifetime value (units of 60 seconds).
185
   */
186
  uint16_t m_regTime;
187
188
  /**
189
   * \brief The EUI-64 value.
190
   */
191
  Mac64Address m_eui64;
192
193
  /**
194
   * \brief The registered address value.
195
   */
196
  Ipv6Address m_regAddress;
197
198
};
199
200
/**
201
 * \ingroup sixlowpan
202
 * \class Icmpv6OptionAddressRegistration
203
 * \brief ICMPv6 Address Registration Option header.
204
 */
205
class Icmpv6OptionAddressRegistration : public Icmpv6OptionHeader
206
{
207
public:
208
209
  /**
210
   * \brief Constructor.
211
   */
212
  Icmpv6OptionAddressRegistration ();
213
214
  /**
215
   * \brief Constructor.
216
   * \param time the registration lifetime (units of 60 seconds)
217
   * \param eui the EUI-64
218
   */
219
  Icmpv6OptionAddressRegistration (uint16_t time, Mac64Address eui);
220
221
  /**
222
   * \brief Constructor.
223
   * \param status the status value
224
   * \param time the registration lifetime (units of 60 seconds)
225
   * \param eui the EUI-64
226
   */
227
  Icmpv6OptionAddressRegistration (uint8_t status, uint16_t time, Mac64Address eui);
228
229
  /**
230
   * \brief Destructor.
231
   */
232
  virtual ~Icmpv6OptionAddressRegistration ();
233
234
  /**
235
   * \brief Get the UID of this class.
236
   * \return UID
237
   */
238
  static TypeId GetTypeId ();
239
240
  /**
241
   * \brief Get the instance type ID.
242
   * \return instance type ID
243
   */
244
  virtual TypeId GetInstanceTypeId () const;
245
246
  /**
247
   * \brief Get the status field.
248
   * \return status value
249
   */
250
  uint8_t GetStatus () const;
251
252
  /**
253
   * \brief Set the status field.
254
   * \param status the status value
255
   */
256
  void SetStatus (uint8_t status);
257
258
  /**
259
   * \brief Get the first reserved field.
260
   * \return first reserved value
261
   */
262
  uint8_t GetReserved1 () const;
263
264
  /**
265
   * \brief Set the first reserved field.
266
   * \param reserved the first reserved value
267
   */
268
  void SetReserved1 (uint8_t reserved);
269
270
  /**
271
   * \brief Get the second reserved field.
272
   * \return second reserved value
273
   */
274
  uint16_t GetReserved2 () const;
275
276
  /**
277
   * \brief Set the second reserved field.
278
   * \param reserved the second reserved value
279
   */
280
  void SetReserved2 (uint16_t reserved);
281
282
  /**
283
   * \brief Get the registration lifetime field.
284
   * \return registration lifetime value (units of 60 seconds)
285
   */
286
  uint16_t GetRegTime () const;
287
288
  /**
289
   * \brief Set the registration lifetime field.
290
   * \param time the registration lifetime value (units of 60 seconds)
291
   */
292
  void SetRegTime (uint16_t time);
293
294
  /**
295
   * \brief Get the EUI-64 field.
296
   * \return EUI-64 value
297
   */
298
  Mac64Address GetEui64 () const;
299
300
  /**
301
   * \brief Set the EUI-64 field.
302
   * \param eui the EUI-64 value
303
   */
304
  void SetEui64 (Mac64Address eui);
305
306
  /**
307
   * \brief Print informations.
308
   * \param os output stream
309
   */
310
  virtual void Print (std::ostream& os) const;
311
312
  /**
313
   * \brief Get the serialized size.
314
   * \return serialized size
315
   */
316
  virtual uint32_t GetSerializedSize () const;
317
318
  /**
319
   * \brief Serialize the packet.
320
   * \param start start offset
321
   */
322
  virtual void Serialize (Buffer::Iterator start) const;
323
324
  /**
325
   * \brief Deserialize the packet.
326
   * \param start start offset
327
   * \return length of packet
328
   */
329
  virtual uint32_t Deserialize (Buffer::Iterator start);
330
331
private:
332
333
  /**
334
   * \brief The status value.
335
   */
336
  uint8_t m_status;
337
338
  /**
339
   * \brief The first reserved value.
340
   */
341
  uint8_t m_reserved1;
342
343
  /**
344
   * \brief The second reserved value.
345
   */
346
  uint16_t m_reserved2;
347
348
  /**
349
   * \brief The registration lifetime value (units of 60 seconds).
350
   */
351
  uint16_t m_regTime;
352
353
  /**
354
   * \brief The EUI-64 value.
355
   */
356
  Mac64Address m_eui64;
357
358
};
359
360
/**
361
 * \ingroup sixlowpan
362
 * \class Icmpv6OptionSixLowPanContext
363
 * \brief ICMPv6 SixLowPan Context Option header.
364
 */
365
class Icmpv6OptionSixLowPanContext : public Icmpv6OptionHeader
366
{
367
public:
368
369
  /**
370
   * \brief Constructor.
371
   */
372
  Icmpv6OptionSixLowPanContext ();
373
374
  /**
375
   * \brief Constructor.
376
   * \param c the c flag
377
   * \param cid the context identifier
378
   * \param time the valid lifetime (units of 60 seconds)
379
   * \param prefix the context prefix
380
   */
381
  Icmpv6OptionSixLowPanContext (bool c, uint8_t cid, uint16_t time, Ipv6Prefix prefix);
382
383
  /**
384
   * \brief Destructor.
385
   */
386
  virtual ~Icmpv6OptionSixLowPanContext ();
387
388
  /**
389
   * \brief Get the UID of this class.
390
   * \return UID
391
   */
392
  static TypeId GetTypeId ();
393
394
  /**
395
   * \brief Get the instance type ID.
396
   * \return instance type ID
397
   */
398
  virtual TypeId GetInstanceTypeId () const;
399
400
  /**
401
   * \brief Get the context length field.
402
   * \return context length value
403
   */
404
  uint8_t GetContextLen () const;
405
406
  /**
407
   * \brief Set the context length field.
408
   * \param cLen the context length value
409
   */
410
  void SetContextLen (uint8_t cLen);
411
412
  /**
413
   * \brief Get the first reserved field.
414
   * \return first reserved value
415
   */
416
  uint8_t GetReserved1 () const;
417
418
  /**
419
   * \brief Set the first reserved field.
420
   * \param reserved the first reserved value
421
   */
422
  void SetReserved1 (uint8_t reserved1);
423
424
  /**
425
   * \brief Is compression flag ?
426
   * \return true if context is valid for use in compression, false otherwise
427
   */
428
  bool IsFlagC () const;
429
430
  /**
431
   * \brief Set the C flag.
432
   * \param c the C flag
433
   */
434
  void SetFlagC (bool c);
435
436
  /**
437
   * \brief Get the context identifier field.
438
   * \return context identifier value
439
   */
440
  uint8_t GetCid () const;
441
442
  /**
443
   * \brief Set the context identifier field.
444
   * \param cid the context identifier value
445
   */
446
  void SetCid (uint8_t cid);
447
448
  /**
449
   * \brief Get the second reserved field.
450
   * \return second reserved value
451
   */
452
  uint16_t GetReserved2 () const;
453
454
  /**
455
   * \brief Set the second reserved field.
456
   * \param reserved the second reserved value
457
   */
458
  void SetReserved2 (uint16_t reserved);
459
460
  /**
461
   * \brief Get the valid lifetime field.
462
   * \return valid lifetime value (units of 60 seconds)
463
   */
464
  uint16_t GetValidTime () const;
465
466
  /**
467
   * \brief Set the valid lifetime field.
468
   * \param time the valid lifetime value (units of 60 seconds)
469
   */
470
  void SetValidTime (uint16_t time);
471
472
  /**
473
   * \brief Get the context prefix field.
474
   * \return context prefix value
475
   */
476
  Ipv6Prefix GetContextPrefix () const;
477
478
  /**
479
   * \brief Set the context prefix field.
480
   * \param prefix the context prefix value
481
   */
482
  void SetContextPrefix (Ipv6Prefix prefix);
483
484
  /**
485
   * \brief Print informations.
486
   * \param os output stream
487
   */
488
  virtual void Print (std::ostream& os) const;
489
490
  /**
491
   * \brief Get the serialized size.
492
   * \return serialized size
493
   */
494
  virtual uint32_t GetSerializedSize () const;
495
496
  /**
497
   * \brief Serialize the packet.
498
   * \param start start offset
499
   */
500
  virtual void Serialize (Buffer::Iterator start) const;
501
502
  /**
503
   * \brief Deserialize the packet.
504
   * \param start start offset
505
   * \return length of packet
506
   */
507
  virtual uint32_t Deserialize (Buffer::Iterator start);
508
509
private:
510
511
  /**
512
   * \brief The context length value.
513
   */
514
  uint8_t m_contextLen;
515
516
  /**
517
   * \brief The first reserved value.
518
   */
519
  uint8_t m_reserved1;
520
521
  /**
522
   * \brief The compression flag, indicates that this context is valid for use in compression.
523
   */
524
  bool m_c;
525
526
  /**
527
   * \brief The context identifier value.
528
   */
529
  uint8_t m_cid;
530
531
  /**
532
   * \brief The second reserved value.
533
   */
534
  uint16_t m_reserved2;
535
536
  /**
537
   * \brief The valid lifetime value (units of 60 seconds).
538
   */
539
  uint16_t m_validTime;
540
541
  /**
542
   * \brief The context prefix value.
543
   */
544
  Ipv6Prefix m_prefix;
545
546
};
547
548
/**
549
 * \ingroup sixlowpan
550
 * \class Icmpv6OptionAuthoritativeBorderRouter
551
 * \brief ICMPv6 Authoritative Border Router Option header.
552
 */
553
class Icmpv6OptionAuthoritativeBorderRouter : public Icmpv6OptionHeader
554
{
555
public:
556
557
  /**
558
   * \brief Constructor.
559
   */
560
  Icmpv6OptionAuthoritativeBorderRouter ();
561
562
  /**
563
   * \brief Constructor.
564
   * \param version the version value
565
   * \param time the valid lifetime (units of 60 seconds)
566
   * \param address the 6LBR address
567
   */
568
  Icmpv6OptionAuthoritativeBorderRouter (uint32_t version, uint16_t time, Ipv6Address address);
569
570
  /**
571
   * \brief Destructor.
572
   */
573
  virtual ~Icmpv6OptionAuthoritativeBorderRouter ();
574
575
  /**
576
   * \brief Get the UID of this class.
577
   * \return UID
578
   */
579
  static TypeId GetTypeId ();
580
581
  /**
582
   * \brief Get the instance type ID.
583
   * \return instance type ID
584
   */
585
  virtual TypeId GetInstanceTypeId () const;
586
587
  /**
588
   * \brief Get the version field.
589
   * \return version value
590
   */
591
  uint32_t GetVersion () const;
592
593
  /**
594
   * \brief Set the version field.
595
   * \param version the version value
596
   */
597
  void SetVersion (uint32_t version);
598
599
  /**
600
   * \brief Get the valid lifetime field.
601
   * \return valid lifetime value (units of 60 seconds)
602
   */
603
  uint16_t GetValidTime () const;
604
605
  /**
606
   * \brief Set the valid lifetime field.
607
   * \param time the valid lifetime value (units of 60 seconds)
608
   */
609
  void SetValidTime (uint16_t time);
610
611
  /**
612
   * \brief Get the 6LB router address field.
613
   * \return 6LB router address value
614
   */
615
  Ipv6Address GetRouterAddress () const;
616
617
  /**
618
   * \brief Set the 6LB router address field.
619
   * \param router the 6LB router address value
620
   */
621
  void SetRouterAddress (Ipv6Address router);
622
623
  /**
624
   * \brief Print informations.
625
   * \param os output stream
626
   */
627
  virtual void Print (std::ostream& os) const;
628
629
  /**
630
   * \brief Get the serialized size.
631
   * \return serialized size
632
   */
633
  virtual uint32_t GetSerializedSize () const;
634
635
  /**
636
   * \brief Serialize the packet.
637
   * \param start start offset
638
   */
639
  virtual void Serialize (Buffer::Iterator start) const;
640
641
  /**
642
   * \brief Deserialize the packet.
643
   * \param start start offset
644
   * \return length of packet
645
   */
646
  virtual uint32_t Deserialize (Buffer::Iterator start);
647
648
private:
649
  /**
650
   * \brief The version value.
651
   */
652
  uint32_t m_version;
653
654
  /**
655
   * \brief The valid lifetime value (units of 60 seconds).
656
   */
657
  uint16_t m_validTime;
658
659
  /**
660
   * \brief The 6LB router address value.
661
   */
662
  Ipv6Address m_routerAddress;
663
664
};
665
666
} /* namespace ns3 */
667
668
#endif /* SIXLOWPAN_ND_HEADER_H */
(-)a/src/sixlowpan/model/sixlowpan-nd-protocol.cc (+1124 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19
 *         David Gross <gdavid.devel@gmail.com>
20
 *         Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
21
 *         Tommaso Pecorella <tommaso.pecorella@unifi.it>
22
 */
23
24
#include "ns3/log.h"
25
#include "ns3/ptr.h"
26
#include "ns3/assert.h"
27
#include "ns3/packet.h"
28
#include "ns3/node.h"
29
#include "ns3/boolean.h"
30
#include "ns3/ipv6-routing-protocol.h"
31
#include "ns3/ipv6-route.h"
32
#include "ns3/mac64-address.h"
33
#include "ns3/mac48-address.h"
34
#include "ns3/mac16-address.h"
35
#include "ns3/pointer.h"
36
#include "ns3/uinteger.h"
37
#include "ns3/string.h"
38
#include "ns3/sgi-hashmap.h"
39
#include "ns3/ipv6-l3-protocol.h"
40
#include "ns3/ipv6-interface.h"
41
42
#include "sixlowpan-nd-protocol.h"
43
#include "sixlowpan-ndisc-cache.h"
44
#include "sixlowpan-ndisc-ra-options.h"
45
#include "sixlowpan-nd-header.h"
46
#include "sixlowpan-net-device.h"
47
#include "src/network/model/packet.h"
48
#include "src/core/model/integer.h"
49
#include "src/core/model/nstime.h"
50
51
namespace ns3 {
52
53
NS_LOG_COMPONENT_DEFINE ("SixLowPanNdProtocol");
54
55
NS_OBJECT_ENSURE_REGISTERED (SixLowPanNdProtocol);
56
57
const uint16_t SixLowPanNdProtocol::MIN_CONTEXT_CHANGE_DELAY = 300;
58
59
const uint8_t SixLowPanNdProtocol::MAX_RTR_ADVERTISEMENTS = 3;
60
const uint8_t SixLowPanNdProtocol::MIN_DELAY_BETWEEN_RAS = 10;
61
const uint8_t SixLowPanNdProtocol::MAX_RA_DELAY_TIME = 2;
62
const uint8_t SixLowPanNdProtocol::TENTATIVE_NCE_LIFETIME = 20;
63
64
const uint8_t SixLowPanNdProtocol::MULTIHOP_HOPLIMIT = 64;
65
66
const uint8_t SixLowPanNdProtocol::RTR_SOLICITATION_INTERVAL = 10;
67
const uint8_t SixLowPanNdProtocol::MAX_RTR_SOLICITATIONS = 3;
68
const uint8_t SixLowPanNdProtocol::MAX_RTR_SOLICITATION_INTERVAL = 60;
69
70
SixLowPanNdProtocol::SixLowPanNdProtocol ()
71
: m_rsRetransmit (0),
72
  m_aroRetransmit (0)
73
{
74
  NS_LOG_FUNCTION (this);
75
}
76
77
SixLowPanNdProtocol::~SixLowPanNdProtocol ()
78
{
79
  NS_LOG_FUNCTION (this);
80
}
81
82
TypeId SixLowPanNdProtocol::GetTypeId ()
83
{
84
  static TypeId tid = TypeId ("ns3::SixLowPanNdProtocol")
85
            .SetParent<Icmpv6L4Protocol> ()
86
            .SetGroupName ("Internet")
87
            .AddConstructor<SixLowPanNdProtocol> ()
88
            .AddAttribute ("Border", "Is the node a 6LoWPAN Border Router.",
89
                           BooleanValue (false),
90
                           MakeBooleanAccessor (&SixLowPanNdProtocol::m_border),
91
                           MakeBooleanChecker ())
92
            .AddAttribute ("RegistrationLifeTime", "The amount of time (units of 60 seconds) that the router should retain the NCE for the node.",
93
                           UintegerValue (60),
94
                           MakeUintegerAccessor (&SixLowPanNdProtocol::m_regTime),
95
                           MakeUintegerChecker<uint16_t> ())
96
            .AddAttribute ("AdvanceTime", "The advance to perform maintaining of RA's information and registration.",
97
                           UintegerValue (5),
98
                           MakeUintegerAccessor (&SixLowPanNdProtocol::m_advance),
99
                           MakeUintegerChecker<uint16_t> ())
100
            ;
101
  return tid;
102
}
103
104
Ptr<Packet> SixLowPanNdProtocol::ForgeNA (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress, uint8_t flags)
105
{
106
  NS_LOG_FUNCTION (this << src << dst << hardwareAddress << (uint32_t)flags);
107
  Ptr<Packet> p = Create<Packet> ();
108
  Ipv6Header ipHeader;
109
  Icmpv6NA na;
110
  Icmpv6OptionLinkLayerAddress llOption (0, hardwareAddress);  /* we give our mac address in response */
111
112
  NS_LOG_LOGIC ("Send NA ( from " << src << " to " << dst << " target " << target << ")");
113
114
  /* forge the entire NA packet from IPv6 header to ICMPv6 link-layer option, so that the packet does not pass by Icmpv6L4Protocol::Lookup again */
115
116
  p->AddHeader (llOption);
117
  na.SetIpv6Target (target);
118
119
  if ((flags & 1))
120
    {
121
      na.SetFlagO (true);
122
    }
123
  if ((flags & 2) && src != Ipv6Address::GetAny ())
124
    {
125
      na.SetFlagS (true);
126
    }
127
  if ((flags & 4))
128
    {
129
      na.SetFlagR (true);
130
    }
131
132
  na.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + na.GetSerializedSize (), PROT_NUMBER);
133
  p->AddHeader (na);
134
135
  ipHeader.SetSourceAddress (src);
136
  ipHeader.SetDestinationAddress (dst);
137
  ipHeader.SetNextHeader (PROT_NUMBER);
138
  ipHeader.SetPayloadLength (p->GetSize ());
139
  ipHeader.SetHopLimit (255);
140
141
  p->AddHeader (ipHeader);
142
143
  return p;
144
}
145
146
void SixLowPanNdProtocol::SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target,
147
                                  Address linkAddr)
148
{
149
  NS_LOG_FUNCTION (this << src << dst << target << linkAddr);
150
151
  Ptr<Ipv6L3Protocol> ipv6 = GetNode ()->GetObject<Ipv6L3Protocol> ();
152
  uint32_t interfaceId = ipv6->GetInterfaceForAddress (src);
153
  Ptr<Ipv6Interface> interface = ipv6->GetInterface (interfaceId);
154
  Ptr<NdiscCache> cache = FindCache (interface->GetDevice ());
155
156
  if (src != Ipv6Address::GetAny ())
157
    {
158
      NS_LOG_WARN ("An unspecified source address MUST NOT be used in NS messages.");
159
      return;
160
    }
161
162
  // only send NS if the target is a router.
163
  NdiscCache::Entry *entry = cache->Lookup (dst);
164
  if (entry)
165
    {
166
      if (entry->IsRouter ())
167
        {
168
          Icmpv6L4Protocol::SendNS (interface->GetLinkLocalAddress ().GetAddress (), dst,
169
                                    target, linkAddr);
170
        }
171
    }
172
}
173
174
void SixLowPanNdProtocol::SendSixLowPanARO (Ipv6Address src, Ipv6Address dst, uint16_t time,
175
                                            Mac64Address eui, Address linkAddr)
176
{
177
  NS_LOG_FUNCTION (this << src << dst << time << eui << linkAddr);
178
179
  /* an unspecified src MUST NOT be used in NS */
180
181
  NS_ASSERT_MSG (src != Ipv6Address::GetAny (), "An unspecified source address MUST NOT be used in ARO messages.");
182
  NS_ASSERT_MSG (!dst.IsMulticast (), "Destination address must not be a multicast address in ARO messages.");
183
184
  Ptr<Packet> p = Create<Packet> ();
185
  Icmpv6NS ns (Ipv6Address::GetZero ());
186
187
  /* ARO (request) + SLLAO */
188
  Icmpv6OptionAddressRegistration arOption (time, eui);
189
  Icmpv6OptionLinkLayerAddress llOption (1, linkAddr);
190
191
  NS_LOG_LOGIC ("Send NS ( from " << src << " to " << dst << ")");
192
193
  p->AddHeader (arOption);
194
  p->AddHeader (llOption);
195
  ns.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + ns.GetSerializedSize (), PROT_NUMBER);
196
  p->AddHeader (ns);
197
198
  SendMessage (p, src, dst, 255);
199
}
200
201
void SixLowPanNdProtocol::SendSixLowPanARO (Ipv6Address src, Ipv6Address dst, uint8_t status,
202
                                            uint16_t time, Mac64Address eui)
203
{
204
  NS_LOG_FUNCTION (this << src << dst << static_cast<uint32_t> (status) << time << eui);
205
  Ptr<Packet> p = Create<Packet> ();
206
  Icmpv6NA na;
207
208
  /* ARO (response) */
209
  Icmpv6OptionAddressRegistration arOption (status, time, eui);
210
211
  NS_LOG_LOGIC ("Send NA ( from " << src << " to " << dst << ")");
212
213
  na.SetIpv6Target (Ipv6Address::GetZero ());
214
  na.SetFlagO (false);
215
  na.SetFlagS (true);
216
  na.SetFlagR (true);
217
218
  p->AddHeader (arOption);
219
  na.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + na.GetSerializedSize (), PROT_NUMBER);
220
  p->AddHeader (na);
221
222
  SendMessage (p, src, dst, 255);
223
}
224
225
void SixLowPanNdProtocol::SendSixLowPanRA (Ipv6Address src, Ipv6Address dst, Ptr<Ipv6Interface> interface)
226
{
227
  NS_LOG_FUNCTION (this << src << dst << interface);
228
229
  Ptr<SixLowPanNdiscCache> sixCache = FindSixLowPanCache (interface->GetDevice ());
230
  std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *> raCache = sixCache->GetRaCache ();
231
232
  for (std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *>::iterator it = raCache.begin ();
233
      it != raCache.end (); it++)
234
    {
235
      Icmpv6RA raHdr;
236
      Ipv6Header ipHeader;
237
238
      Ptr<Packet> p = Create<Packet> ();
239
240
      /* set RA header information */
241
      raHdr.SetFlagM (it->second->IsManagedFlag ());
242
      raHdr.SetFlagO (it->second->IsOtherConfigFlag ());
243
      raHdr.SetFlagH (it->second->IsHomeAgentFlag ());
244
      raHdr.SetCurHopLimit (it->second->GetCurHopLimit ());
245
      raHdr.SetLifeTime (it->second->GetRouterLifeTime ());
246
      raHdr.SetReachableTime (it->second->GetReachableTime ());
247
      raHdr.SetRetransmissionTime (it->second->GetRetransTimer ());
248
249
      /* Add ABRO */
250
      Icmpv6OptionAuthoritativeBorderRouter abroHdr;
251
      abroHdr.SetVersion (it->second->GetVersion ());
252
      abroHdr.SetValidTime (it->second->GetValidTime ());
253
      abroHdr.SetRouterAddress (it->second->GetBorderAddress ());
254
      p->AddHeader (abroHdr);
255
256
      /* Add SLLAO */
257
      Address addr = interface->GetDevice ()->GetAddress ();
258
      Icmpv6OptionLinkLayerAddress llaHdr (1, addr);
259
      p->AddHeader (llaHdr);
260
261
      /* Add PIOs */
262
      std::map<Ipv6Address, Ptr<SixLowPanPrefix> > prefixes = it->second->GetPrefixes ();
263
      for (std::map<Ipv6Address, Ptr<SixLowPanPrefix> >::iterator jt = prefixes.begin (); jt != prefixes.end (); jt++)
264
        {
265
          Icmpv6OptionPrefixInformation prefixHdr;
266
          prefixHdr.SetPrefixLength (jt->second->GetPrefixLength ());
267
          prefixHdr.SetFlags (jt->second->GetFlags ());
268
          prefixHdr.SetValidTime (jt->second->GetValidLifeTime ());
269
          prefixHdr.SetPreferredTime (jt->second->GetPreferredLifeTime ());
270
          prefixHdr.SetPrefix (jt->second->GetPrefix ());
271
          p->AddHeader (prefixHdr);
272
        }
273
274
      /* Add 6COs */
275
      std::map<uint8_t, Ptr<SixLowPanContext> > contexts = it->second->GetContexts ();
276
      for (std::map<uint8_t, Ptr<SixLowPanContext> >::iterator i = contexts.begin (); i != contexts.end (); i++)
277
        {
278
          Icmpv6OptionSixLowPanContext sixHdr;
279
          sixHdr.SetContextLen (i->second->GetContextLen ());
280
          sixHdr.SetFlagC (i->second->IsFlagC ());
281
          sixHdr.SetCid (i->second->GetCid ());
282
          sixHdr.SetValidTime (i->second->GetValidTime ());
283
          sixHdr.SetContextPrefix (i->second->GetContextPrefix ());
284
          p->AddHeader (sixHdr);
285
        }
286
287
      raHdr.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + raHdr.GetSerializedSize (), PROT_NUMBER);
288
      p->AddHeader (raHdr);
289
290
      ipHeader.SetSourceAddress (src);
291
      ipHeader.SetDestinationAddress (dst);
292
      ipHeader.SetNextHeader (PROT_NUMBER);
293
      ipHeader.SetPayloadLength (p->GetSize ());
294
      ipHeader.SetHopLimit (255);
295
296
      /* send RA */
297
      NS_LOG_LOGIC ("Send RA to " << dst);
298
      interface->Send (p, ipHeader, dst);
299
    }
300
}
301
302
void SixLowPanNdProtocol::SendSixLowPanDAR (Ipv6Address src, Ipv6Address dst, uint16_t time, Mac64Address eui,
303
                                            Ipv6Address registered)
304
{
305
  NS_LOG_FUNCTION (this << src << dst << time << eui << registered);
306
  Ptr<Packet> p = Create<Packet> ();
307
  Icmpv6DuplicateAddress dar (time, eui, registered);
308
309
  NS_LOG_LOGIC ("Send DAR ( from " << src << " to " << dst << ")");
310
311
  dar.CalculatePseudoHeaderChecksum (src, dst, p->GetSize () + dar.GetSerializedSize (), PROT_NUMBER);
312
  p->AddHeader (dar);
313
314
  SendMessage (p, src, dst, MULTIHOP_HOPLIMIT);
315
}
316
317
enum IpL4Protocol::RxStatus SixLowPanNdProtocol::Receive (Ptr<Packet> packet, Ipv6Header const &header,
318
                                                          Ptr<Ipv6Interface> interface)
319
{
320
  NS_LOG_FUNCTION (this << packet << header.GetSourceAddress () << header.GetDestinationAddress () <<
321
                   interface);
322
  Ptr<Ipv6> ipv6 = GetNode ()->GetObject<Ipv6> ();
323
  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (interface->GetDevice());
324
  NS_ASSERT_MSG (sixDevice != NULL, "SixLowPanNdProtocol cannot be installed on device different from SixLowPanNetDevice");
325
326
  uint8_t type;
327
  packet->CopyData (&type, sizeof(type));
328
329
  switch (type)
330
  {
331
    case Icmpv6Header::ICMPV6_ND_ROUTER_SOLICITATION:
332
      if (ipv6->IsForwarding (ipv6->GetInterfaceForDevice (sixDevice)))
333
        {
334
          HandleSixLowPanRS (packet, header.GetSourceAddress (), header.GetDestinationAddress (), interface);
335
        }
336
      break;
337
    case Icmpv6Header::ICMPV6_ND_ROUTER_ADVERTISEMENT:
338
      HandleSixLowPanRA (packet, header.GetSourceAddress (), header.GetDestinationAddress (), interface);
339
      break;
340
    case Icmpv6Header::ICMPV6_ND_NEIGHBOR_SOLICITATION:
341
      if (ipv6->IsForwarding (ipv6->GetInterfaceForDevice (sixDevice)))
342
        {
343
          HandleSixLowPanNS (packet, header.GetSourceAddress (), header.GetDestinationAddress (), interface);
344
        }
345
      break;
346
    case Icmpv6Header::ICMPV6_ND_NEIGHBOR_ADVERTISEMENT:
347
      HandleSixLowPanNA (packet, header.GetSourceAddress (), header.GetDestinationAddress (), interface);
348
      break;
349
    case Icmpv6Header::ICMPV6_ND_DUPLICATE_ADDRESS_CONFIRM:
350
      if (ipv6->IsForwarding (ipv6->GetInterfaceForDevice (sixDevice)))
351
        {
352
          HandleSixLowPanDAC (packet, header.GetSourceAddress (), header.GetDestinationAddress (), interface);
353
        }
354
      break;
355
    default:
356
      return Icmpv6L4Protocol::Receive (packet, header, interface);
357
      break;
358
  }
359
360
  return IpL4Protocol::RX_OK;
361
}
362
363
void SixLowPanNdProtocol::DoDispose ()
364
{
365
  NS_LOG_FUNCTION (this);
366
367
  for (SixLowPanCacheList::const_iterator it = m_sixlowCList.begin (); it != m_sixlowCList.end (); it++)
368
    {
369
      Ptr<SixLowPanNdiscCache> cache = *it;
370
      cache->Dispose ();
371
      cache = 0;
372
    }
373
  m_sixlowCList.clear ();
374
375
  Icmpv6L4Protocol::DoDispose ();
376
}
377
378
void SixLowPanNdProtocol::HandleSixLowPanNS (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
379
                                             Ptr<Ipv6Interface> interface)
380
{
381
  NS_LOG_FUNCTION (this << packet << src << dst << interface);
382
383
  Icmpv6NS nsHdr;
384
  packet->RemoveHeader (nsHdr);
385
  Ipv6Address target = nsHdr.GetIpv6Target ();
386
387
  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (interface->GetDevice());
388
  NS_ASSERT_MSG (sixDevice != NULL, "SixLowPanNdProtocol cannot be installed on device different from SixLowPanNetDevice");
389
390
  Icmpv6OptionLinkLayerAddress llaHdr (1); /* SLLAO */
391
  Icmpv6OptionAddressRegistration aroHdr;
392
393
  bool next = true;
394
  bool hasLla = false;
395
  bool hasAro = false;
396
397
  if (src != Ipv6Address::GetAny ())
398
    {
399
      /* search all options following the NS header */
400
      while (next == true)
401
        {
402
          uint8_t type;
403
          packet->CopyData (&type, sizeof(type));
404
405
          switch (type)
406
          {
407
            case Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE:
408
              if (!hasLla)
409
                {
410
                  packet->RemoveHeader (llaHdr);
411
                  hasLla = true;
412
                }
413
              break;
414
            case Icmpv6Header::ICMPV6_OPT_ADDRESS_REGISTRATION:
415
              if (!hasAro)
416
                {
417
                  packet->RemoveHeader (aroHdr);
418
                  hasAro = true;
419
                }
420
              break;
421
            default:
422
              /* unknow option, quit */
423
              next = false;
424
          }
425
        }
426
427
      if (!hasLla) /* error! */
428
        {
429
          NS_LOG_ERROR ("NS message MUST have source link layer option.");
430
          return;
431
        }
432
      else /* NS + SLLAO */
433
        {
434
          /* Update "ARPv6" table with information of src */
435
          Ptr<NdiscCache> cache = FindCache (sixDevice);
436
437
          NdiscCache::Entry* entry = 0;
438
          entry = cache->Lookup (src);
439
440
          if (!entry && src.IsLinkLocal())
441
            {
442
              entry = cache->Add (src);
443
              uint8_t buf[16];
444
              src.GetBytes (buf);
445
              Mac16Address address;
446
              address.CopyFrom (buf+14);
447
              entry->SetRouter (false);
448
              entry->SetMacAddress (llaHdr.GetAddress ());
449
              entry->MarkReachable ();
450
            }
451
          else if (!entry)
452
            {
453
              entry = cache->Add (src);
454
              entry->SetRouter (false);
455
              entry->MarkStale (llaHdr.GetAddress ());
456
            }
457
          else if (entry->GetMacAddress () != llaHdr.GetAddress ())
458
            {
459
              entry->MarkStale (llaHdr.GetAddress ());
460
            }
461
        }
462
463
      if (!hasAro) /* NS + SLLAO */
464
        {
465
          /* Send NA to src with information requested about target (in "ARPv6" table) */
466
          Ptr<NdiscCache> cache = FindCache (sixDevice);
467
468
          NdiscCache::Entry* entry = 0;
469
          entry = cache->Lookup (target);
470
          uint8_t flags;
471
472
          if (!entry)
473
            {
474
              NS_LOG_LOGIC ("No entry with address " << target);
475
              return;
476
            }
477
          else
478
            {
479
              if (entry->IsRouter ())
480
                {
481
                  flags = 7; /* R + S + O flag */
482
                }
483
              else
484
                {
485
                  flags = 3; /* S + O flags */
486
                }
487
488
              /* NA + TLLAO */
489
              Ptr<Packet> p = ForgeNA (interface->GetLinkLocalAddress ().GetAddress (), src, target,
490
                                       entry->GetMacAddress (), flags);
491
              Ipv6Header header;
492
              p->RemoveHeader (header);
493
              interface->Send (p, header, src);
494
            }
495
        }
496
      else /* NS + SLLAO + ARO */
497
        {
498
          /* Update NCE with information of src and ARO */
499
          Ptr<SixLowPanNdiscCache> nCache = FindSixLowPanCache (sixDevice);
500
501
          SixLowPanNdiscCache::SixLowPanEntry* nEntry = 0;
502
          nEntry = nCache->SixLowPanLookup (src);
503
504
          std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *> raCache = nCache->GetRaCache ();
505
506
          if (!nEntry) /* no entry, creating */
507
            {
508
              if (aroHdr.GetRegTime () != 0)
509
                {
510
                  nEntry = nCache->SixLowPanAdd (src);
511
                  nEntry->SetRouter (false);
512
                  nEntry->SetMacAddress (llaHdr.GetAddress ());
513
                  nEntry->SetEui64 (aroHdr.GetEui64 ());
514
                  nEntry->MarkReachable ();
515
516
                  if (m_multihopDad) /* multihop DAD used */
517
                    {
518
                      nEntry->MarkTentative ();
519
                      for (std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *>::iterator it = raCache.begin ();
520
                          it != raCache.end (); it++)
521
                        {
522
                          Ipv6Address destination = it->second->GetBorderAddress ();
523
                          SendSixLowPanDAR (interface->GetAddressMatchingDestination (destination).GetAddress (), destination,
524
                                            aroHdr.GetRegTime (), aroHdr.GetEui64 (), src);
525
                        }
526
                      return;
527
                    }
528
                  else  /* multihop DAD NOT used */
529
                    {
530
                      nEntry->MarkRegistered (aroHdr.GetRegTime ());
531
                      SendSixLowPanARO (interface->GetLinkLocalAddress ().GetAddress (), src, 0, aroHdr.GetRegTime (),
532
                                        aroHdr.GetEui64 ());
533
                      return;
534
                    }
535
                }
536
            }
537
          else if (nEntry->GetEui64 () == aroHdr.GetEui64 ()) /* entry found, same EUI-64, updating */
538
            {
539
              if (aroHdr.GetRegTime () != 0)
540
                {
541
                  nEntry->SetRouter (false);
542
                  nEntry->SetMacAddress (llaHdr.GetAddress ());
543
                  nEntry->MarkReachable ();
544
                  nEntry->MarkRegistered (aroHdr.GetRegTime ());
545
                  SendSixLowPanARO (interface->GetLinkLocalAddress ().GetAddress (), src, 0, aroHdr.GetRegTime (),
546
                                    aroHdr.GetEui64 ());
547
548
                  if (m_multihopDad)
549
                    {
550
                      for (std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *>::iterator it = raCache.begin ();
551
                          it != raCache.end (); it++)
552
                        {
553
                          Ipv6Address destination = it->second->GetBorderAddress ();
554
555
                          /* Send request to update entry from DAD table */
556
                          SendSixLowPanDAR (interface->GetAddressMatchingDestination (destination).GetAddress (), destination,
557
                                            aroHdr.GetRegTime (), aroHdr.GetEui64 (), src);
558
                        }
559
                    }
560
561
                  return;
562
                }
563
              else /* ARO's Registration Lifetime = 0 */
564
                {
565
                  if (m_multihopDad)
566
                    {
567
                      for (std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *>::iterator it = raCache.begin ();
568
                          it != raCache.end (); it++)
569
                        {
570
                          Ipv6Address destination = it->second->GetBorderAddress ();
571
572
                          /* Send request to remove entry from DAD table */
573
                          SendSixLowPanDAR (interface->GetAddressMatchingDestination (destination).GetAddress (), destination,
574
                                            aroHdr.GetRegTime (), aroHdr.GetEui64 (), src);
575
                        }
576
                    }
577
                  /* Remove the entry from Neighbor Cache */
578
                  nCache->SixLowPanRemove (nEntry);
579
580
                  /* Remove the entry from "ARPv6" table */
581
                  Ptr<NdiscCache> cache = FindCache (sixDevice);
582
583
                  NdiscCache::Entry* entry = 0;
584
                  entry = cache->Lookup (src);
585
                  cache->Remove (entry);
586
                  return;
587
                }
588
            }
589
          else /* entry found, different EUI-64 */
590
            {
591
              if (m_multihopDad && nEntry->IsRegistered ())
592
                {
593
                  SendSixLowPanARO (interface->GetLinkLocalAddress ().GetAddress (),
594
                                    sixDevice->MakeLinkLocalAddressFromMac (aroHdr.GetEui64 ()), 1,
595
                                    aroHdr.GetRegTime (), aroHdr.GetEui64 ());
596
                }
597
              else if (!m_multihopDad)
598
                {
599
                  SendSixLowPanARO (interface->GetLinkLocalAddress ().GetAddress (),
600
                                    sixDevice->MakeLinkLocalAddressFromMac (aroHdr.GetEui64 ()), 1,
601
                                    aroHdr.GetRegTime (), aroHdr.GetEui64 ());
602
                }
603
              return;
604
            }
605
        }
606
    }
607
  else
608
    {
609
      NS_LOG_ERROR ("An unspecified source address MUST NOT be used in NS messages.");
610
      return;
611
    }
612
}
613
614
void SixLowPanNdProtocol::HandleSixLowPanNA (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
615
                                             Ptr<Ipv6Interface> interface)
616
{
617
  NS_LOG_FUNCTION (this << packet << src << dst << interface);
618
619
  Ptr<Packet> p = packet->Copy ();
620
  Icmpv6NS naHdr;
621
  packet->RemoveHeader (naHdr);
622
  Ipv6Address target = naHdr.GetIpv6Target ();
623
624
  Icmpv6OptionLinkLayerAddress llaHdr (0); /* TLLAO */
625
  Icmpv6OptionAddressRegistration aroHdr;
626
627
  uint8_t type;
628
  packet->CopyData (&type, sizeof(type));
629
630
  switch (type)
631
  {
632
    case Icmpv6Header::ICMPV6_OPT_LINK_LAYER_TARGET: /* NA + TLLAO */
633
634
      HandleNA (p, target, dst, interface); /* Handle response of Address Resolution */
635
636
      break;
637
    case Icmpv6Header::ICMPV6_OPT_ADDRESS_REGISTRATION: /* NA + ARO */
638
639
      packet->RemoveHeader (aroHdr);
640
641
      m_aroRetransmit = 0;
642
643
      if (aroHdr.GetStatus () == 0) /* status=0, success! */
644
        {
645
          /* schedule a new ARO to maintain NCE in routers */
646
647
          Simulator::Schedule (Time (Minutes (aroHdr.GetRegTime () - m_advance)), &SixLowPanNdProtocol::RetransmitARO, this,
648
                               dst, src, aroHdr.GetRegTime (), aroHdr.GetEui64 (), interface->GetDevice ()->GetAddress ());
649
        }
650
      else /* status NOT 0, fail! */
651
        {
652
          NS_LOG_LOGIC ("ARO status is NOT 0, registration failed!");
653
          /// \todo implement method to remove address that generated error.
654
          return;
655
        }
656
      break;
657
    default:
658
      NS_LOG_ERROR ("NA message MUST have option.");
659
      return;
660
  }
661
}
662
663
void SixLowPanNdProtocol::HandleSixLowPanRS (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
664
                                             Ptr<Ipv6Interface> interface)
665
{
666
  NS_LOG_FUNCTION (this << packet << src << dst << interface);
667
668
  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (interface->GetDevice());
669
  NS_ASSERT_MSG (sixDevice != NULL, "SixLowPanNdProtocol cannot be installed on device different from SixLowPanNetDevice");
670
671
  Icmpv6RS rsHeader;
672
  Icmpv6OptionLinkLayerAddress lla (1);
673
674
  packet->RemoveHeader (rsHeader);
675
676
  if (src != Ipv6Address::GetAny ())
677
    {
678
      uint8_t type;
679
      packet->CopyData (&type, sizeof(type));
680
681
      if (type != Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE)
682
        {
683
          NS_LOG_ERROR ("RS message MUST have source link layer option.");
684
          return;
685
        }
686
687
      packet->RemoveHeader (lla);
688
689
      /* Update Neighbor Cache */
690
      Ptr<SixLowPanNdiscCache> sixCache = FindSixLowPanCache (sixDevice);
691
      SixLowPanNdiscCache::SixLowPanEntry* sixEntry = 0;
692
      sixEntry = sixCache->SixLowPanLookup (src);
693
      if (!sixEntry)
694
        {
695
          sixEntry = sixCache->SixLowPanAdd (src);
696
          sixEntry->SetRouter (false);
697
          sixEntry->MarkStale (lla.GetAddress ());
698
          sixEntry->MarkTentative ();
699
          NS_LOG_LOGIC ("Tentative entry created from RS");
700
        }
701
      else if (sixEntry->GetMacAddress () != lla.GetAddress ())
702
        {
703
          sixEntry->MarkStale (lla.GetAddress ());
704
        }
705
706
      /* Update "ARPv6" table */
707
      Ptr<NdiscCache> cache = FindCache (sixDevice);
708
      NdiscCache::Entry* entry = 0;
709
      entry = cache->Lookup (src);
710
      if (!entry)
711
        {
712
          entry = cache->Add (src);
713
          entry->SetRouter (false);
714
          entry->MarkStale (lla.GetAddress ());
715
        }
716
      else if (entry->GetMacAddress () != lla.GetAddress ())
717
        {
718
          entry->MarkStale (lla.GetAddress ());
719
        }
720
    }
721
722
  if (!m_border)
723
    {
724
      Address addr = lla.GetAddress ();
725
      Ipv6Address destination = sixDevice->MakeLinkLocalAddressFromMac(addr);
726
727
      SendSixLowPanRA (interface->GetLinkLocalAddress ().GetAddress (), destination, interface);
728
    }
729
}
730
731
void SixLowPanNdProtocol::HandleSixLowPanRA (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
732
                                             Ptr<Ipv6Interface> interface)
733
{
734
  NS_LOG_FUNCTION (this << packet << src << dst << interface);
735
736
  m_rsRetransmit = 0;
737
  m_receivedRA = true;
738
739
  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (interface->GetDevice());
740
  NS_ASSERT_MSG (sixDevice != NULL, "SixLowPanNdProtocol cannot be installed on device different from SixLowPanNetDevice");
741
742
  Address addr = sixDevice->GetAddress ();
743
744
  Icmpv6RA raHeader;
745
  Ptr<Ipv6L3Protocol> ipv6 = GetNode ()->GetObject<Ipv6L3Protocol> ();
746
747
  Icmpv6OptionAuthoritativeBorderRouter abrHdr; /* ABRO */
748
  Icmpv6OptionLinkLayerAddress llaHdr (1); /* SLLAO */
749
750
  bool next = true;
751
  Ptr<SixLowPanNdiscCache> sixCache = FindSixLowPanCache (sixDevice);
752
  SixLowPanNdiscCache::SixLowPanRaEntry* ra = 0;
753
754
  Ptr<NdiscCache> cache = FindCache (sixDevice);
755
  // sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash> ndiscCache = cache->GetNdiscCache ();
756
757
  uint32_t version;
758
  Ipv6Address border;
759
760
  packet->RemoveHeader (raHeader);
761
762
  Ipv6Address defaultRouter = Ipv6Address::GetZero ();
763
764
  if (raHeader.GetLifeTime())
765
    {
766
      defaultRouter = src;
767
    }
768
769
  std::list<Icmpv6OptionPrefixInformation> prefixList;
770
  std::list<Icmpv6OptionSixLowPanContext> contextList;
771
  Icmpv6OptionPrefixInformation prefixHdr;
772
  Icmpv6OptionSixLowPanContext contextHdr;
773
774
  // \todo check the stop condiiton
775
  while (next == true)
776
    {
777
      uint8_t type = 0;
778
      packet->CopyData (&type, sizeof(type));
779
780
      switch (type)
781
      {
782
        case Icmpv6Header::ICMPV6_OPT_PREFIX:
783
          packet->RemoveHeader (prefixHdr);
784
          prefixList.push_back (prefixHdr);
785
          break;
786
        case Icmpv6Header::ICMPV6_OPT_SIXLOWPAN_CONTEXT:
787
          packet->RemoveHeader (contextHdr);
788
          contextList.push_back (contextHdr);
789
          break;
790
        case Icmpv6Header::ICMPV6_OPT_AUTHORITATIVE_BORDER_ROUTER:
791
          packet->RemoveHeader (abrHdr);
792
          version = abrHdr.GetVersion ();
793
          border = abrHdr.GetRouterAddress ();
794
          break;
795
        case Icmpv6Header::ICMPV6_OPT_LINK_LAYER_SOURCE:
796
          packet->RemoveHeader (llaHdr);
797
          ReceiveLLA (llaHdr, src, dst, interface); // generates an entry in NDISC table with m_router = true
798
          break;
799
        default:
800
          /* Unknown option, quit */
801
          next = false;
802
          break;
803
      }
804
    }
805
806
  ra = sixCache->RaEntryLookup (border);
807
  if (!ra) // Create a new entry
808
    {
809
      ra = sixCache->AddRaEntry (border);
810
      ra->SetManagedFlag (raHeader.GetFlagM ());
811
      ra->SetOtherConfigFlag (raHeader.GetFlagO ());
812
      ra->SetHomeAgentFlag (raHeader.GetFlagH ());
813
      ra->SetReachableTime (raHeader.GetReachableTime ());
814
      ra->SetRouterLifeTime (raHeader.GetLifeTime ());
815
      ra->SetRetransTimer (raHeader.GetRetransmissionTime ());
816
      ra->SetCurHopLimit (raHeader.GetCurHopLimit ());
817
      ra->SetVersion (version);
818
      ra->SetValidTime (abrHdr.GetValidTime ());
819
820
//      for (std::list<Icmpv6OptionPrefixInformation>::iterator it = prefixList.begin (); it != prefixList.end (); it++)
821
//        {
822
//          Ptr<SixLowPanPrefix> prefix = new SixLowPanPrefix;
823
//          prefix->SetPrefixLength ((*it).GetPrefixLength ());
824
//          prefix->SetFlags ((*it).GetFlags ());
825
//          prefix->SetValidLifeTime ((*it).GetValidTime ());
826
//          prefix->SetPreferredLifeTime ((*it).GetPreferredTime ());
827
//          prefix->SetPrefix ((*it).GetPrefix ());
828
//
829
//          ra->AddPrefix (prefix);
830
//
831
//          ipv6->AddAutoconfiguredAddress (ipv6->GetInterfaceForDevice (sixDevice),
832
//                                          (*it).GetPrefix (),(*it).GetPrefixLength (),
833
//                                          (*it).GetFlags (), (*it).GetValidTime (),
834
//                                          (*it).GetPreferredTime (), defaultRouter);
835
//
836
//          for (sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator k = ndiscCache.begin ();
837
//              k != ndiscCache.end (); k++)
838
//            {
839
//              if (k->second->IsRouter ())
840
//                {
841
//                  SendSixLowPanARO (sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
842
//                                    k->second->GetIpv6Address (), m_regTime, Mac64Address::ConvertFrom (addr),
843
//                                    addr);
844
//
845
//                  Simulator::Schedule (Time (Minutes (m_regTime - m_advance)), &SixLowPanNdProtocol::RetransmitARO, this,
846
//                                       sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
847
//                                       k->second->GetIpv6Address (), m_regTime, Mac64Address::ConvertFrom (addr),
848
//                                       addr);
849
//                }
850
//            }
851
//        }
852
      // \todo quiet compiler
853
      NS_ASSERT (m_regTime);
854
855
      for (std::list<Icmpv6OptionSixLowPanContext>::iterator jt = contextList.begin (); jt != contextList.end (); jt++)
856
        {
857
          Ptr<SixLowPanContext> context = new SixLowPanContext;
858
          context->SetCid ((*jt).GetCid ());
859
          context->SetFlagC ((*jt).IsFlagC ());
860
          context->SetValidTime ((*jt).GetValidTime ());
861
          context->SetContextPrefix ((*jt).GetContextPrefix ());
862
863
          ra->AddContext (context);
864
        }
865
    }
866
  else if (ra && version > (ra->GetVersion ())) // Update existing entry from 6LBR with new information
867
    {
868
      ra->SetManagedFlag (raHeader.GetFlagM ());
869
      ra->SetOtherConfigFlag (raHeader.GetFlagO ());
870
      ra->SetHomeAgentFlag (raHeader.GetFlagH ());
871
      ra->SetReachableTime (raHeader.GetReachableTime ());
872
      ra->SetRouterLifeTime (raHeader.GetLifeTime ());
873
      ra->SetRetransTimer (raHeader.GetRetransmissionTime ());
874
      ra->SetCurHopLimit (raHeader.GetCurHopLimit ());
875
      ra->SetVersion (version);
876
      ra->SetValidTime (abrHdr.GetValidTime ());
877
878
      for (std::list<Icmpv6OptionPrefixInformation>::iterator it = prefixList.begin (); it != prefixList.end (); it++)
879
        {
880
          if (ra->GetPrefixes ().find ((*it).GetPrefix ()) == ra->GetPrefixes ().end ()) /* prefix NOT found */
881
            {
882
              Ptr<SixLowPanPrefix> prefix = new SixLowPanPrefix;
883
              prefix->SetPrefixLength ((*it).GetPrefixLength ());
884
              prefix->SetFlags ((*it).GetFlags ());
885
              prefix->SetValidLifeTime ((*it).GetValidTime ());
886
              prefix->SetPreferredLifeTime ((*it).GetPreferredTime ());
887
              prefix->SetPrefix ((*it).GetPrefix ());
888
889
              ra->AddPrefix (prefix);
890
891
              ipv6->AddAutoconfiguredAddress (ipv6->GetInterfaceForDevice (sixDevice),
892
                                              (*it).GetPrefix (), (*it).GetPrefixLength (),
893
                                              (*it).GetFlags (), (*it).GetValidTime (),
894
                                              (*it).GetPreferredTime (), defaultRouter);
895
//              for (sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator kt = ndiscCache.begin ();
896
//                  kt != ndiscCache.end (); kt++)
897
//                {
898
//                  if (kt->second->IsRouter ())
899
//                    {
900
//                      SendSixLowPanARO (sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
901
//                                        kt->second->GetIpv6Address (), m_regTime,
902
//                                        Mac64Address::ConvertFrom (addr), addr);
903
//
904
//                      Simulator::Schedule (Time (Minutes (m_regTime - m_advance)), &SixLowPanNdProtocol::RetransmitARO, this,
905
//                                           sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
906
//                                           kt->second->GetIpv6Address (), m_regTime, Mac64Address::ConvertFrom (addr),
907
//                                           addr);
908
//                    }
909
//                }
910
            }
911
          else /* prefix found, updating! */
912
            {
913
              Ptr<SixLowPanPrefix> prefix = (ra->GetPrefixes().find((*it).GetPrefix ()))->second;
914
915
              prefix->SetPrefixLength ((*it).GetPrefixLength ());
916
              prefix->SetFlags ((*it).GetFlags ());
917
              prefix->SetValidLifeTime ((*it).GetValidTime ());
918
              prefix->SetPreferredLifeTime ((*it).GetPreferredTime ());
919
920
              ipv6->AddAutoconfiguredAddress (ipv6->GetInterfaceForDevice (sixDevice),
921
                                              (*it).GetPrefix (), (*it).GetPrefixLength (),
922
                                              (*it).GetFlags (), (*it).GetValidTime (),
923
                                              (*it).GetPreferredTime (), defaultRouter);
924
//              for (sgi::hash_map<Ipv6Address, NdiscCache::Entry *, Ipv6AddressHash>::iterator lt = ndiscCache.begin ();
925
//                  lt != ndiscCache.end (); lt++)
926
//                {
927
//                  if (lt->second->IsRouter ())
928
//                    {
929
//                      SendSixLowPanARO (sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
930
//                                        lt->second->GetIpv6Address (), m_regTime, Mac64Address::ConvertFrom (addr),
931
//                                        addr);
932
//
933
//                      Simulator::Schedule (Time (Minutes (m_regTime - m_advance)), &SixLowPanNdProtocol::RetransmitARO, this,
934
//                                           sixDevice->MakeGlobalAddressFromMac(addr, (*it).GetPrefix ()),
935
//                                           lt->second->GetIpv6Address (), m_regTime, Mac64Address::ConvertFrom (addr),
936
//                                           addr);
937
//                    }
938
//                }
939
            }
940
        }
941
942
      for (std::list<Icmpv6OptionSixLowPanContext>::iterator jt = contextList.begin (); jt != contextList.end (); jt++)
943
        {
944
          if (ra->GetContexts ().find ((*jt).GetCid ()) == ra->GetContexts ().end ()) /* context NOT found */
945
            {
946
              Ptr<SixLowPanContext> context = new SixLowPanContext;
947
              context->SetCid ((*jt).GetCid ());
948
              context->SetFlagC ((*jt).IsFlagC ());
949
              context->SetValidTime ((*jt).GetValidTime ());
950
              context->SetContextPrefix ((*jt).GetContextPrefix ());
951
952
              ra->AddContext (context);
953
            }
954
          else
955
            {
956
              Ptr<SixLowPanContext> context = (ra->GetContexts ().find ((*jt).GetCid ()))->second;
957
958
              context->SetFlagC ((*jt).IsFlagC ());
959
              context->SetValidTime ((*jt).GetValidTime ());
960
              context->SetContextPrefix ((*jt).GetContextPrefix ());
961
            }
962
        }
963
    }
964
  else  // Old information, not updating
965
    {
966
      return;
967
    }
968
969
  uint32_t t = raHeader.GetLifeTime ();
970
971
  for (std::list<Icmpv6OptionPrefixInformation>::iterator it = prefixList.begin (); it != prefixList.end (); it++)
972
    {
973
      t = t < ((*it).GetValidTime ()) ? t : ((*it).GetValidTime ());
974
    }
975
  for (std::list<Icmpv6OptionSixLowPanContext>::iterator jt = contextList.begin (); jt != contextList.end (); jt++)
976
    {
977
      t = (60 * ((*jt).GetValidTime ())) < t ? (60 * ((*jt).GetValidTime ())) : t;
978
    }
979
980
  t -= (60 * m_advance);
981
982
  Simulator::Schedule (Time (Seconds (t - 1)), &SixLowPanNdProtocol::SetReceivedRA, this, false);
983
  Simulator::Schedule (Time (Seconds (t)), &SixLowPanNdProtocol::RetransmitRS, this,
984
                       interface->GetLinkLocalAddress ().GetAddress (), src, addr);
985
}
986
/// \todo da finire!! (controlla codice, controlla regTime)
987
988
void SixLowPanNdProtocol::HandleSixLowPanDAC (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
989
                                              Ptr<Ipv6Interface> interface)
990
{
991
  NS_LOG_FUNCTION (this << packet << src << dst << interface);
992
993
  Ptr<SixLowPanNetDevice> sixDevice = DynamicCast<SixLowPanNetDevice> (interface->GetDevice());
994
  NS_ASSERT_MSG (sixDevice != NULL, "SixLowPanNdProtocol cannot be installed on device different from SixLowPanNetDevice");
995
996
  Icmpv6DuplicateAddress dacHdr (0);
997
  packet->RemoveHeader (dacHdr);
998
999
  if (m_multihopDad)
1000
    {
1001
      Ipv6Address reg = dacHdr.GetRegAddress ();
1002
1003
      if (!reg.IsMulticast () && src != Ipv6Address::GetAny () && !src.IsMulticast ())
1004
        {
1005
          Ptr<SixLowPanNdiscCache> cache = FindSixLowPanCache (sixDevice);
1006
          SixLowPanNdiscCache::SixLowPanEntry* entry = 0;
1007
          entry = cache->SixLowPanLookup (reg);
1008
1009
          if (dacHdr.GetStatus () == 0) /* mark the entry as registered, send ARO with status=0 */
1010
            {
1011
              entry->MarkRegistered (dacHdr.GetRegTime ());
1012
1013
              SendSixLowPanARO (dst, dacHdr.GetRegAddress (), dacHdr.GetStatus (), dacHdr.GetRegTime (),
1014
                                dacHdr.GetEui64 ());
1015
            }
1016
          else /* remove the tentative entry, send ARO with error code */
1017
            {
1018
              cache->SixLowPanRemove (entry);
1019
1020
              Ipv6Address address = sixDevice->MakeLinkLocalAddressFromMac (dacHdr.GetEui64 ());
1021
1022
              SendSixLowPanARO (dst, address, dacHdr.GetStatus (), dacHdr.GetRegTime (), dacHdr.GetEui64 ());
1023
            }
1024
        }
1025
      else
1026
        {
1027
          NS_LOG_ERROR ("Validity checks for DAR not satisfied.");
1028
          return;
1029
        }
1030
    }
1031
}
1032
1033
Ptr<SixLowPanNdiscCache> SixLowPanNdProtocol::FindSixLowPanCache (Ptr<NetDevice> device)
1034
{
1035
  NS_LOG_FUNCTION (this << device);
1036
1037
  for (SixLowPanCacheList::const_iterator it = m_sixlowCList.begin (); it != m_sixlowCList.end (); it++)
1038
    {
1039
      if ((*it)->GetDevice () == device)
1040
        {
1041
          return *it;
1042
        }
1043
    }
1044
1045
  /* quiet compiler */
1046
  return 0;
1047
}
1048
1049
void SixLowPanNdProtocol::RetransmitARO (Ipv6Address src, Ipv6Address dst, uint16_t time,
1050
                                         Mac64Address eui, Address linkAddr)
1051
{
1052
  NS_LOG_FUNCTION (this << src << dst << time << eui << linkAddr);
1053
1054
  IntegerValue maxUnicastSolicit;
1055
  GetAttribute ("MaxUnicastSolicit", maxUnicastSolicit);
1056
  if (m_aroRetransmit < maxUnicastSolicit.Get ())
1057
    {
1058
      m_aroRetransmit++;
1059
1060
      SendSixLowPanARO (src, dst, time, eui, linkAddr);
1061
1062
      TimeValue retransmissionTime;
1063
      GetAttribute ("RetransmissionTime", retransmissionTime);
1064
1065
      Simulator::Schedule (retransmissionTime.Get (), &SixLowPanNdProtocol::RetransmitARO, this,
1066
                           src, dst, time, eui, linkAddr);
1067
      return;
1068
    }
1069
  else
1070
    {
1071
      return;
1072
    }
1073
}
1074
1075
void SixLowPanNdProtocol::RetransmitRS (Ipv6Address src, Ipv6Address dst, Address linkAddr)
1076
{
1077
  NS_LOG_FUNCTION (this << src << dst << linkAddr);
1078
1079
  /* if the source is NOT unspec, send a RS message + SLLA option */
1080
  if (src != Ipv6Address::GetAny ())
1081
    {
1082
      if (!m_receivedRA && m_rsRetransmit < MAX_RTR_SOLICITATIONS)
1083
        {
1084
          m_rsRetransmit++;
1085
1086
          SendRS (src, dst, linkAddr);
1087
1088
          Simulator::Schedule (Time (Seconds (RTR_SOLICITATION_INTERVAL)), &SixLowPanNdProtocol::RetransmitRS, this,
1089
                               src, dst, linkAddr);
1090
          return;
1091
        }
1092
      else if (!m_receivedRA)
1093
        {
1094
          m_rsRetransmit++;
1095
1096
          Ipv6Address destination = Ipv6Address::GetAllRoutersMulticast ();
1097
1098
          SendRS (src, destination, linkAddr);
1099
1100
          Simulator::Schedule (Time (Seconds (MAX_RTR_SOLICITATION_INTERVAL)), &SixLowPanNdProtocol::RetransmitRS, this,
1101
                               src, destination, linkAddr);
1102
          /* inserire truncated binary exponential backoff */
1103
          return;
1104
        }
1105
      else
1106
        {
1107
          return;
1108
        }
1109
    }
1110
  else
1111
    {
1112
      NS_LOG_ERROR ("An unspecified source address MUST NOT be used in RS messages.");
1113
      return;
1114
    }
1115
}
1116
/// \todo da finire!! (truncated binary exponential backoff)
1117
1118
void SixLowPanNdProtocol::SetReceivedRA (bool received)
1119
{
1120
  NS_LOG_FUNCTION (this << received);
1121
  m_receivedRA = received;
1122
}
1123
1124
} /* namespace ns3 */
(-)a/src/sixlowpan/model/sixlowpan-nd-protocol.h (+307 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#ifndef SIXLOWPAN_ND_PROTOCOL_H
22
#define SIXLOWPAN_ND_PROTOCOL_H
23
24
#include "ns3/ipv6-address.h"
25
#include "ns3/mac64-address.h"
26
#include "ns3/ip-l4-protocol.h"
27
#include "ns3/icmpv6-l4-protocol.h"
28
29
#include "sixlowpan-ndisc-cache.h"
30
31
namespace ns3 {
32
33
/**
34
 * \ingroup sixlowpan
35
 * \class SixLowPanNdProtocol
36
 * \brief An optimization of the ND protocol for 6LoWPANs.
37
 */
38
class SixLowPanNdProtocol : public Icmpv6L4Protocol
39
{
40
public:
41
  /**
42
   * \brief 6LBR constants : min context change delay.
43
   */
44
  static const uint16_t MIN_CONTEXT_CHANGE_DELAY;
45
46
  /**
47
   * \brief 6LR constants : max RA transmission.
48
   */
49
  static const uint8_t MAX_RTR_ADVERTISEMENTS;
50
51
  /**
52
   * \brief 6LR constants : min delay between RA.
53
   */
54
  static const uint8_t MIN_DELAY_BETWEEN_RAS;
55
56
  /**
57
   * \brief 6LR constants : max delay between RA.
58
   */
59
  static const uint8_t MAX_RA_DELAY_TIME;
60
61
  /**
62
   * \brief 6LR constants : tentative neighbor cache entry lifetime.
63
   */
64
  static const uint8_t TENTATIVE_NCE_LIFETIME;
65
66
  /**
67
   * \brief router constants : multihop hoplimit.
68
   */
69
  static const uint8_t MULTIHOP_HOPLIMIT;
70
71
  /**
72
   * \brief host constants : RS interval.
73
   */
74
  static const uint8_t RTR_SOLICITATION_INTERVAL;
75
76
  /**
77
   * \brief host constants : max RS transmission.
78
   */
79
  static const uint8_t MAX_RTR_SOLICITATIONS;
80
81
  /**
82
   * \brief host constants : max RS interval.
83
   */
84
  static const uint8_t MAX_RTR_SOLICITATION_INTERVAL;
85
86
  /**
87
   * \brief Constructor.
88
   */
89
  SixLowPanNdProtocol ();
90
91
  /**
92
   * \brief Destructor.
93
   */
94
  virtual ~SixLowPanNdProtocol ();
95
96
  /**
97
   * \brief Interface ID
98
   */
99
  static TypeId GetTypeId ();
100
101
  /**
102
   * \brief Forge a Neighbor Advertisement.
103
   * \param src source IPv6 address
104
   * \param dst destination IPv6 address
105
   * \param target target IPv6 address
106
   * \param hardwareAddress our mac address
107
   * \param flags flags (bitfield => R (4), S (2), O (1))
108
   * \return NA packet (with IPv6 header)
109
   */
110
  Ptr<Packet> ForgeNA (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress, uint8_t flags);
111
112
  /**
113
   * \brief Send a NS for 6LoWPAN ND (+ SLLAO).
114
   * \param src source IPv6 address
115
   * \param dst destination IPv6 address
116
   * \param target target IPv6 address
117
   * \param linkAddr link-layer address (SLLAO)
118
   */
119
  virtual void SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address linkAddr);
120
121
  /**
122
   * \brief Send a NS for 6LoWPAN ND (+ ARO, SLLAO).
123
   * \param src source IPv6 address
124
   * \param dst destination IPv6 address
125
   * \param time registration lifetime (ARO)
126
   * \param eui EUI-64 (ARO)
127
   * \param linkAddr link-layer address (SLLAO)
128
   */
129
  void SendSixLowPanARO (Ipv6Address src, Ipv6Address dst, uint16_t time, Mac64Address eui,
130
                         Address linkAddr);
131
132
  /**
133
   * \brief Send a NA for 6LoWPAN ND (+ ARO).
134
   * \param src source IPv6 address
135
   * \param dst destination IPv6 address
136
   * \param status status (ARO)
137
   * \param time registration lifetime (ARO)
138
   * \param eui EUI-64 (ARO)
139
   */
140
  void SendSixLowPanARO (Ipv6Address src, Ipv6Address dst, uint8_t status, uint16_t time,
141
                         Mac64Address eui);
142
143
  /**
144
   * \brief Send a RA for 6LoWPAN ND (+ PIO, 6CO, ABRO, SLLAO).
145
   * \param src source IPv6 address
146
   * \param dst destination IPv6 address
147
   * \param interface the interface from which the packet will be sent
148
   */
149
  void SendSixLowPanRA (Ipv6Address src, Ipv6Address dst, Ptr<Ipv6Interface> interface);
150
151
  /**
152
   * \brief Send a DAR for 6LoWPAN ND.
153
   * \param src source IPv6 address
154
   * \param dst destination IPv6 address
155
   * \param time registration lifetime
156
   * \param eui EUI-64
157
   * \param registered registered IPv6 address
158
   */
159
  void SendSixLowPanDAR (Ipv6Address src, Ipv6Address dst, uint16_t time, Mac64Address eui,
160
                      Ipv6Address registered);
161
162
  /**
163
   * \brief Receive method.
164
   * \param p the packet
165
   * \param header the IPv6 header
166
   * \param interface the interface from which the packet is coming
167
   * \returns the receive status
168
   */
169
  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
170
                                               Ipv6Header const &header,
171
                                               Ptr<Ipv6Interface> interface);
172
173
  /**
174
   * \brief Get the cache corresponding to the device.
175
   * \param device the device
176
   * \returns the SixLowPanNdiscCache associated with the device
177
   */
178
  Ptr<SixLowPanNdiscCache> FindSixLowPanCache (Ptr<NetDevice> device);
179
180
  /**
181
   * \brief Function called to send NS + ARO + SLLAO.
182
   * \param src source IPv6 address
183
   * \param dst destination IPv6 address
184
   * \param time registration lifetime (ARO)
185
   * \param eui EUI-64 (ARO)
186
   * \param linkAddr link-layer address (SLLAO)
187
   */
188
  void RetransmitARO (Ipv6Address src, Ipv6Address dst, uint16_t time, Mac64Address eui,
189
                      Address linkAddr);
190
191
  /**
192
   * \brief Function called to send RS + SLLAO.
193
   * \param src source IPv6 address
194
   * \param dst destination IPv6 address
195
   * \param linkAddress link-layer address (SLLAO)
196
   */
197
  void RetransmitRS (Ipv6Address src, Ipv6Address dst, Address linkAddr);
198
199
protected:
200
  /**
201
   * \brief Dispose this object.
202
   */
203
  virtual void DoDispose ();
204
205
private:
206
  typedef std::list<Ptr<SixLowPanNdiscCache> > SixLowPanCacheList; //!< container of SixLowPanNdiscCaches
207
208
  /**
209
   * \brief A list of cache by device.
210
   */
211
  SixLowPanCacheList m_sixlowCList;
212
213
  /**
214
   * \brief Use multihop DAD mechanism
215
   */
216
  bool m_multihopDad;
217
218
  /**
219
   * \brief Number of RS retransmission.
220
   */
221
  uint8_t m_rsRetransmit;
222
223
  /**
224
   * \brief Is an RA received.
225
   */
226
  bool m_receivedRA;
227
228
  /**
229
   * \brief Number of NS + ARO + SLLAO retransmission.
230
   */
231
  uint8_t m_aroRetransmit;
232
233
  /**
234
   * \brief The amount of time (units of 60 seconds) that the router should retain the NCE for the node.
235
   */
236
  uint16_t m_regTime;
237
238
  /**
239
   * \brief The advance to perform maintaining of RA's information and registration.
240
   */
241
  uint16_t m_advance;
242
243
  /**
244
   * \brief Is a 6LoWPAN Border router.
245
   */
246
  bool m_border;
247
248
  /**
249
   * \brief Receive NS for 6LoWPAN ND method.
250
   * \param p the packet
251
   * \param src source address
252
   * \param dst destination address
253
   * \param interface the interface from which the packet is coming
254
   */
255
  void HandleSixLowPanNS (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
256
                       Ptr<Ipv6Interface> interface);
257
258
  /**
259
   * \brief Receive NA for 6LoWPAN ND method.
260
   * \param p the packet
261
   * \param src source address
262
   * \param dst destination address
263
   * \param interface the interface from which the packet is coming
264
   */
265
  void HandleSixLowPanNA (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
266
                       Ptr<Ipv6Interface> interface);
267
268
  /**
269
   * \brief Receive RS for 6LoWPAN ND method.
270
   * \param p the packet
271
   * \param src source address
272
   * \param dst destination address
273
   * \param interface the interface from which the packet is coming
274
   */
275
  void HandleSixLowPanRS (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
276
                       Ptr<Ipv6Interface> interface);
277
278
  /**
279
   * \brief Receive RA for 6LoWPAN ND method.
280
   * \param p the packet
281
   * \param src source address
282
   * \param dst destination address
283
   * \param interface the interface from which the packet is coming
284
   */
285
  void HandleSixLowPanRA (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
286
                       Ptr<Ipv6Interface> interface);
287
288
  /**
289
   * \brief Receive DAC for 6LoWPAN ND method.
290
   * \param p the packet
291
   * \param src source address
292
   * \param dst destination address
293
   * \param interface the interface from which the packet is coming
294
   */
295
  void HandleSixLowPanDAC (Ptr<Packet> packet, Ipv6Address const &src, Ipv6Address const &dst,
296
                        Ptr<Ipv6Interface> interface);
297
298
  /**
299
   * \brief Set the m_receivedRA flag.
300
   * \param received value
301
   */
302
  void SetReceivedRA (bool received);
303
};
304
305
} /* namespace ns3 */
306
307
#endif
(-)a/src/sixlowpan/model/sixlowpan-ndisc-cache.cc (+545 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#include "ns3/log.h"
22
#include "ns3/uinteger.h"
23
#include "ns3/names.h"
24
#include "ns3/ipv6-address.h"
25
#include "ns3/mac64-address.h"
26
27
#include "sixlowpan-ndisc-cache.h"
28
#include "sixlowpan-nd-protocol.h"
29
#include "sixlowpan-ndisc-ra-options.h"
30
31
namespace ns3
32
{
33
34
NS_LOG_COMPONENT_DEFINE ("SixLowPanNdiscCache");
35
36
NS_OBJECT_ENSURE_REGISTERED (SixLowPanNdiscCache);
37
38
TypeId SixLowPanNdiscCache::GetTypeId ()
39
{
40
  static TypeId tid = TypeId ("ns3::SixLowPanNdiscCache")
41
    .SetParent<NdiscCache> ()
42
    .SetGroupName ("SixLowPan")
43
  ;
44
  return tid;
45
}
46
47
SixLowPanNdiscCache::SixLowPanNdiscCache ()
48
{
49
  NS_LOG_FUNCTION_NOARGS ();
50
}
51
52
SixLowPanNdiscCache::~SixLowPanNdiscCache ()
53
{
54
  NS_LOG_FUNCTION_NOARGS ();
55
  Flush ();
56
}
57
58
void SixLowPanNdiscCache::DoDispose ()
59
{
60
  NS_LOG_FUNCTION_NOARGS ();
61
62
  Flush ();
63
  FlushRaCache ();
64
  NdiscCache::DoDispose();
65
}
66
67
SixLowPanNdiscCache::SixLowPanEntry* SixLowPanNdiscCache::SixLowPanLookup (Ipv6Address dst)
68
{
69
  NS_LOG_FUNCTION (this << dst);
70
  SixLowPanNdiscCache::SixLowPanEntry* entry;
71
72
  if (m_sixlowNdCache.find (dst) != m_sixlowNdCache.end ())
73
    {
74
      entry = m_sixlowNdCache[dst];
75
    }
76
  else
77
    {
78
      entry = 0;
79
    }
80
  return entry;
81
}
82
83
SixLowPanNdiscCache::SixLowPanEntry* SixLowPanNdiscCache::SixLowPanAdd (Ipv6Address to)
84
{
85
  NS_LOG_FUNCTION (this << to);
86
  NS_ASSERT (m_sixlowNdCache.find (to) == m_sixlowNdCache.end ());
87
88
  SixLowPanNdiscCache::SixLowPanEntry* entry = new SixLowPanNdiscCache::SixLowPanEntry (this);
89
  entry->SetIpv6Address (to);
90
  m_sixlowNdCache[to] = entry;
91
  return entry;
92
}
93
94
void SixLowPanNdiscCache::SixLowPanRemove (SixLowPanNdiscCache::SixLowPanEntry* entry)
95
{
96
  NS_LOG_FUNCTION_NOARGS ();
97
98
  for (SixLowPanCacheI i = m_sixlowNdCache.begin (); i != m_sixlowNdCache.end (); i++)
99
    {
100
      if ((*i).second == entry)
101
        {
102
          m_sixlowNdCache.erase (i);
103
          entry->ClearWaitingPacket ();
104
          delete entry;
105
          return;
106
        }
107
    }
108
}
109
110
void SixLowPanNdiscCache::Flush ()
111
{
112
  NS_LOG_FUNCTION_NOARGS ();
113
114
  for (SixLowPanCacheI i = m_sixlowNdCache.begin (); i != m_sixlowNdCache.end (); i++)
115
    {
116
      delete (*i).second;
117
    }
118
119
  m_sixlowNdCache.erase (m_sixlowNdCache.begin (), m_sixlowNdCache.end ());
120
}
121
122
void SixLowPanNdiscCache::PrintNdiscCache (Ptr<OutputStreamWrapper> stream)
123
{
124
  NS_LOG_FUNCTION (this << stream);
125
  std::ostream* os = stream->GetStream ();
126
127
  for (SixLowPanCacheI i = m_sixlowNdCache.begin (); i != m_sixlowNdCache.end (); i++)
128
    {
129
      *os << i->first << " dev ";
130
      std::string found = Names::FindName (GetDevice ());
131
      if (Names::FindName (GetDevice ()) != "")
132
        {
133
          *os << found;
134
        }
135
      else
136
        {
137
          *os << static_cast<int> (GetDevice ()->GetIfIndex ());
138
        }
139
140
      *os << " lladdr " << i->second->GetMacAddress ();
141
142
      if (i->second->IsReachable ())
143
        {
144
          *os << " REACHABLE ";
145
        }
146
      else if (i->second->IsDelay ())
147
        {
148
          *os << " DELAY ";
149
        }
150
      else if (i->second->IsIncomplete ())
151
        {
152
          *os << " INCOMPLETE ";
153
        }
154
      else if (i->second->IsProbe ())
155
        {
156
          *os << " PROBE ";
157
        }
158
      else
159
        {
160
          *os << " STALE ";
161
        }
162
163
      if (i->second->IsRegistered ())
164
        {
165
          *os << " REGISTERED\n";
166
        }
167
      else if (i->second->IsTentative ())
168
        {
169
          *os << " TENTATIVE\n";
170
        }
171
      else
172
        {
173
          *os << " GARBAGE\n";
174
        }
175
    }
176
}
177
178
SixLowPanNdiscCache::SixLowPanEntry::SixLowPanEntry (NdiscCache* nd)
179
  : NdiscCache::Entry::Entry (nd),
180
    m_registeredTimer (Timer::CANCEL_ON_DESTROY),
181
	  m_tentativeTimer (Timer::CANCEL_ON_DESTROY)
182
{
183
  NS_LOG_FUNCTION_NOARGS ();
184
}
185
186
void SixLowPanNdiscCache::SixLowPanEntry::MarkRegistered (uint16_t time)
187
{
188
  NS_LOG_FUNCTION_NOARGS ();
189
  m_type = REGISTERED;
190
191
  if (m_registeredTimer.IsRunning ())
192
    {
193
      m_registeredTimer.Cancel ();
194
    }
195
  m_registeredTimer.SetFunction (&SixLowPanNdiscCache::SixLowPanEntry::FunctionTimeout, this);
196
  m_registeredTimer.SetDelay (Minutes (time));
197
  m_registeredTimer.Schedule ();
198
}
199
200
void SixLowPanNdiscCache::SixLowPanEntry::MarkTentative ()
201
{
202
  NS_LOG_FUNCTION_NOARGS ();
203
  m_type = TENTATIVE;
204
205
  if (m_tentativeTimer.IsRunning ())
206
    {
207
      m_tentativeTimer.Cancel ();
208
    }
209
  m_tentativeTimer.SetFunction (&SixLowPanNdiscCache::SixLowPanEntry::FunctionTimeout, this);
210
  m_tentativeTimer.SetDelay (Seconds (SixLowPanNdProtocol::TENTATIVE_NCE_LIFETIME));
211
  m_tentativeTimer.Schedule ();
212
}
213
214
void SixLowPanNdiscCache::SixLowPanEntry::MarkGarbage ()
215
{
216
  NS_LOG_FUNCTION_NOARGS ();
217
  m_type = GARBAGE;
218
}
219
220
bool SixLowPanNdiscCache::SixLowPanEntry::IsRegistered () const
221
{
222
  NS_LOG_FUNCTION_NOARGS ();
223
  return (m_type == REGISTERED);
224
}
225
226
bool SixLowPanNdiscCache::SixLowPanEntry::IsTentative () const
227
{
228
  NS_LOG_FUNCTION_NOARGS ();
229
  return (m_type == TENTATIVE);
230
}
231
232
bool SixLowPanNdiscCache::SixLowPanEntry::IsGarbage () const
233
{
234
  NS_LOG_FUNCTION_NOARGS ();
235
  return (m_type == GARBAGE);
236
}
237
238
void SixLowPanNdiscCache::SixLowPanEntry::FunctionTimeout ()
239
{
240
  NS_LOG_FUNCTION_NOARGS ();
241
242
  m_ndCache->Remove (this);
243
  return;
244
}
245
246
Mac64Address SixLowPanNdiscCache::SixLowPanEntry::GetEui64 () const
247
{
248
  NS_LOG_FUNCTION (this);
249
  return m_eui64;
250
}
251
252
void SixLowPanNdiscCache::SixLowPanEntry::SetEui64 (Mac64Address eui)
253
{
254
  NS_LOG_FUNCTION (this << eui);
255
  m_eui64 = eui;
256
}
257
258
SixLowPanNdiscCache::SixLowPanRaEntry* SixLowPanNdiscCache::RaEntryLookup (Ipv6Address border)
259
{
260
  NS_LOG_FUNCTION (this << border);
261
  SixLowPanNdiscCache::SixLowPanRaEntry* entry = 0;
262
263
  if (m_raCache.find (border) != m_raCache.end ())
264
    {
265
      entry = m_raCache[border];
266
    }
267
  return entry;
268
}
269
270
SixLowPanNdiscCache::SixLowPanRaEntry* SixLowPanNdiscCache::AddRaEntry (Ipv6Address border)
271
{
272
  NS_LOG_FUNCTION (this << border);
273
  NS_ASSERT (m_raCache.find (border) == m_raCache.end ());
274
275
  SixLowPanNdiscCache::SixLowPanRaEntry* entry = new SixLowPanNdiscCache::SixLowPanRaEntry (this);
276
  entry->SetBorderAddress (border);
277
  m_raCache[border] = entry;
278
  return entry;
279
}
280
281
void SixLowPanNdiscCache::RemoveRaEntry (SixLowPanNdiscCache::SixLowPanRaEntry* entry)
282
{
283
  NS_LOG_FUNCTION_NOARGS ();
284
285
  for (SixLowPanRaCacheI it = m_raCache.begin (); it != m_raCache.end (); it++)
286
    {
287
      if ((*it).second == entry)
288
        {
289
          m_raCache.erase (it);
290
          delete entry;
291
          return;
292
        }
293
    }
294
}
295
296
void SixLowPanNdiscCache::FlushRaCache ()
297
{
298
  NS_LOG_FUNCTION_NOARGS ();
299
300
  for (SixLowPanRaCacheI it = m_raCache.begin (); it != m_raCache.end (); it++)
301
    {
302
      delete (*it).second;
303
    }
304
305
  m_raCache.erase (m_raCache.begin (), m_raCache.end ());
306
}
307
308
void SixLowPanNdiscCache::PrintRaCache (Ptr<OutputStreamWrapper> stream)
309
{
310
  NS_LOG_FUNCTION (this << stream);
311
  std::ostream* os = stream->GetStream ();
312
313
  for (SixLowPanRaCacheI it = m_raCache.begin (); it != m_raCache.end (); it++)
314
    {
315
      *os << it->first << " RA ";
316
317
      *os << " Cur Hop Limit: " << it->second->GetCurHopLimit ();
318
319
      if (it->second->IsManagedFlag ())
320
        {
321
          *os << " M flag: true ";
322
        }
323
      else
324
        {
325
          *os << " M flag: false ";
326
        }
327
      if (it->second->IsOtherConfigFlag ())
328
        {
329
          *os << " O flag: true ";
330
        }
331
      else
332
        {
333
          *os << " O flag: false ";
334
        }
335
336
      *os << " Router Lifetime: " << it->second->GetRouterLifeTime ();
337
      *os << " Reachable Time: " << it->second->GetReachableTime ();
338
      *os << " Retrans Timer: " << it->second->GetRetransTimer ();
339
      *os << " (ABRO) Version: " << it->second->GetVersion ();
340
      *os << " (ABRO) Valid Lifetime: " << it->second->GetValidTime ();
341
      *os << " (ABRO) Border Router address: " << it->second->GetBorderAddress ();
342
343
      std::map<Ipv6Address, Ptr<SixLowPanPrefix> > prefixes = it->second->GetPrefixes ();
344
      for (std::map<Ipv6Address, Ptr<SixLowPanPrefix> >::iterator jt = prefixes.begin (); jt != prefixes.end (); jt++)
345
        {
346
          jt->second->PrintPrefix (stream);
347
        }
348
      std::map<uint8_t, Ptr<SixLowPanContext> > contexts = it->second->GetContexts ();
349
      for (std::map<uint8_t, Ptr<SixLowPanContext> >::iterator i = contexts.begin (); i != contexts.end (); i++)
350
        {
351
          i->second->PrintContext (stream);
352
        }
353
    }
354
}
355
356
std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *> SixLowPanNdiscCache::GetRaCache () const
357
{
358
  NS_LOG_FUNCTION (this);
359
  return m_raCache;
360
}
361
362
SixLowPanNdiscCache::SixLowPanRaEntry::SixLowPanRaEntry (SixLowPanNdiscCache* nd)
363
  //: m_cache (nd)
364
{
365
  NS_LOG_FUNCTION (this);
366
}
367
368
SixLowPanNdiscCache::SixLowPanRaEntry::~SixLowPanRaEntry ()
369
{
370
  NS_LOG_FUNCTION (this);
371
}
372
373
void SixLowPanNdiscCache::SixLowPanRaEntry::AddPrefix (Ptr<SixLowPanPrefix> prefix)
374
{
375
  NS_LOG_FUNCTION (this << prefix);
376
  m_prefixes.insert (std::pair<Ipv6Address, Ptr<SixLowPanPrefix> > (prefix->GetPrefix (), prefix));
377
}
378
379
void SixLowPanNdiscCache::SixLowPanRaEntry::RemovePrefix (Ptr<SixLowPanPrefix> prefix)
380
{
381
  NS_LOG_FUNCTION_NOARGS ();
382
383
  for (std::map<Ipv6Address, Ptr<SixLowPanPrefix> >::iterator it = m_prefixes.begin (); it != m_prefixes.end (); it++)
384
    {
385
      if (it->second == prefix)
386
        {
387
          m_prefixes.erase (it);
388
          return;
389
        }
390
    }
391
}
392
393
std::map<Ipv6Address, Ptr<SixLowPanPrefix> > SixLowPanNdiscCache::SixLowPanRaEntry::GetPrefixes () const
394
{
395
  NS_LOG_FUNCTION (this);
396
  return m_prefixes;
397
}
398
399
void SixLowPanNdiscCache::SixLowPanRaEntry::AddContext (Ptr<SixLowPanContext> context)
400
{
401
  NS_LOG_FUNCTION (this << context);
402
  m_contexts.insert (std::pair<uint8_t, Ptr<SixLowPanContext> > (context->GetCid (), context));
403
}
404
405
void SixLowPanNdiscCache::SixLowPanRaEntry::RemoveContext (Ptr<SixLowPanContext> context)
406
{
407
  NS_LOG_FUNCTION_NOARGS ();
408
409
  for (std::map<uint8_t, Ptr<SixLowPanContext> >::iterator it = m_contexts.begin (); it != m_contexts.end (); it++)
410
    {
411
      if (it->second == context)
412
        {
413
          m_contexts.erase (it);
414
          return;
415
        }
416
    }
417
}
418
419
std::map<uint8_t, Ptr<SixLowPanContext> > SixLowPanNdiscCache::SixLowPanRaEntry::GetContexts () const
420
{
421
  NS_LOG_FUNCTION (this);
422
  return m_contexts;
423
}
424
425
bool SixLowPanNdiscCache::SixLowPanRaEntry::IsManagedFlag () const
426
{
427
  NS_LOG_FUNCTION (this);
428
  return m_managedFlag;
429
}
430
431
void SixLowPanNdiscCache::SixLowPanRaEntry::SetManagedFlag (bool managedFlag)
432
{
433
  NS_LOG_FUNCTION (this << managedFlag);
434
  m_managedFlag = managedFlag;
435
}
436
437
bool SixLowPanNdiscCache::SixLowPanRaEntry::IsOtherConfigFlag () const
438
{
439
  NS_LOG_FUNCTION (this);
440
  return m_otherConfigFlag;
441
}
442
443
void SixLowPanNdiscCache::SixLowPanRaEntry::SetOtherConfigFlag (bool otherConfigFlag)
444
{
445
  NS_LOG_FUNCTION (this << otherConfigFlag);
446
  m_otherConfigFlag = otherConfigFlag;
447
}
448
449
bool SixLowPanNdiscCache::SixLowPanRaEntry::IsHomeAgentFlag () const
450
{
451
  NS_LOG_FUNCTION (this);
452
  return m_homeAgentFlag;
453
}
454
455
void SixLowPanNdiscCache::SixLowPanRaEntry::SetHomeAgentFlag (bool homeAgentFlag)
456
{
457
  NS_LOG_FUNCTION (this << homeAgentFlag);
458
  m_homeAgentFlag = homeAgentFlag;
459
}
460
461
uint32_t SixLowPanNdiscCache::SixLowPanRaEntry::GetReachableTime () const
462
{
463
  NS_LOG_FUNCTION (this);
464
  return m_reachableTime;
465
}
466
467
void SixLowPanNdiscCache::SixLowPanRaEntry::SetReachableTime (uint32_t time)
468
{
469
  NS_LOG_FUNCTION (this << time);
470
  m_reachableTime = time;
471
}
472
473
uint32_t SixLowPanNdiscCache::SixLowPanRaEntry::GetRouterLifeTime () const
474
{
475
  NS_LOG_FUNCTION (this);
476
  return m_routerLifeTime;
477
}
478
479
void SixLowPanNdiscCache::SixLowPanRaEntry::SetRouterLifeTime (uint32_t time)
480
{
481
  NS_LOG_FUNCTION (this << time);
482
  m_routerLifeTime = time;
483
}
484
485
uint32_t SixLowPanNdiscCache::SixLowPanRaEntry::GetRetransTimer () const
486
{
487
  NS_LOG_FUNCTION (this);
488
  return m_retransTimer;
489
}
490
491
void SixLowPanNdiscCache::SixLowPanRaEntry::SetRetransTimer (uint32_t timer)
492
{
493
  NS_LOG_FUNCTION (this << timer);
494
  m_retransTimer = timer;
495
}
496
497
uint8_t SixLowPanNdiscCache::SixLowPanRaEntry::GetCurHopLimit () const
498
{
499
  NS_LOG_FUNCTION (this);
500
  return m_curHopLimit;
501
}
502
503
void SixLowPanNdiscCache::SixLowPanRaEntry::SetCurHopLimit (uint8_t curHopLimit)
504
{
505
  NS_LOG_FUNCTION (this << curHopLimit);
506
  m_curHopLimit = curHopLimit;
507
}
508
509
uint32_t SixLowPanNdiscCache::SixLowPanRaEntry::GetVersion () const
510
{
511
  NS_LOG_FUNCTION (this);
512
  return m_version;
513
}
514
515
void SixLowPanNdiscCache::SixLowPanRaEntry::SetVersion (uint32_t version)
516
{
517
  NS_LOG_FUNCTION (this << version);
518
  m_version = version;
519
}
520
521
uint16_t SixLowPanNdiscCache::SixLowPanRaEntry::GetValidTime () const
522
{
523
  NS_LOG_FUNCTION (this);
524
  return m_validTime;
525
}
526
527
void SixLowPanNdiscCache::SixLowPanRaEntry::SetValidTime (uint16_t time)
528
{
529
  NS_LOG_FUNCTION (this << time);
530
  m_validTime = time;
531
}
532
533
Ipv6Address SixLowPanNdiscCache::SixLowPanRaEntry::GetBorderAddress () const
534
{
535
  NS_LOG_FUNCTION (this);
536
  return m_border;
537
}
538
539
void SixLowPanNdiscCache::SixLowPanRaEntry::SetBorderAddress (Ipv6Address border)
540
{
541
  NS_LOG_FUNCTION (this << border);
542
  m_border = border;
543
}
544
545
} /* namespace ns3 */
(-)a/src/sixlowpan/model/sixlowpan-ndisc-cache.h (+512 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#ifndef SIXLOW_NDISC_CACHE_H
22
#define SIXLOW_NDISC_CACHE_H
23
24
#include "ns3/ipv6-address.h"
25
#include "ns3/mac64-address.h"
26
#include "ns3/ptr.h"
27
#include "ns3/timer.h"
28
#include "ns3/sgi-hashmap.h"
29
#include "ns3/output-stream-wrapper.h"
30
#include "ns3/ndisc-cache.h"
31
32
// #include "sixlow-ndisc-ra-options.h"
33
34
namespace ns3
35
{
36
37
class SixLowPanPrefix;
38
class SixLowPanContext;
39
40
/**
41
 * \infroup sixlowpan
42
 * \class SixLowPanNdiscCache
43
 * \brief Neighbor Discovery cache for 6LoWPAN ND. Keeps also RAs, prefixes and contexts.
44
 */
45
class SixLowPanNdiscCache : public NdiscCache
46
{
47
public:
48
  class SixLowPanEntry;
49
50
  class SixLowPanRaEntry;
51
52
  /**
53
   * \brief Get the type ID
54
   * \return type ID
55
   */
56
  static TypeId GetTypeId ();
57
58
  /**
59
   * \brief Constructor.
60
   */
61
  SixLowPanNdiscCache ();
62
63
  /**
64
   * \brief Destructor.
65
   */
66
  ~SixLowPanNdiscCache ();
67
68
  /**
69
   * \brief Lookup in the cache.
70
   * \param dst destination address
71
   * \return the entry if found, 0 otherwise
72
   */
73
  SixLowPanNdiscCache::SixLowPanEntry* SixLowPanLookup (Ipv6Address dst);
74
75
  /**
76
   * \brief Add an entry.
77
   * \param to address to add
78
   * \return an new Entry
79
   */
80
  SixLowPanNdiscCache::SixLowPanEntry* SixLowPanAdd (Ipv6Address to);
81
82
  /**
83
   * \brief Delete an entry.
84
   * \param entry pointer to delete from the list.
85
   */
86
  void SixLowPanRemove (SixLowPanNdiscCache::SixLowPanEntry* entry);
87
88
  /**
89
   * \brief Flush the cache.
90
   */
91
  virtual void Flush ();
92
93
  /**
94
   * \brief Print the SixLowPanNdisc cache entries
95
   *
96
   * \param stream the ostream the SixLowPanNdisc cache entries is printed to
97
   */
98
  virtual void PrintNdiscCache (Ptr<OutputStreamWrapper> stream);
99
100
  /**
101
   * \class SixLowPanEntry
102
   * \brief A record that holds information about an SixLowPanNdiscCache entry.
103
   */
104
  class SixLowPanEntry : public NdiscCache::Entry
105
  {
106
  public:
107
    /**
108
     * \brief Constructor.
109
     * \param nd The NdiscCache this entry belongs to.
110
     */
111
    SixLowPanEntry (NdiscCache* nd);
112
113
    /**
114
     * \brief Changes the state to this entry to REGISTERED.
115
     * It starts the registered timer.
116
     * \param time the lifetime in units of 60 seconds (from ARO)
117
     */
118
    void MarkRegistered (uint16_t time);
119
120
    /**
121
     * \brief Changes the state to this entry to TENTATIVE.
122
     * It starts the tentative timer (20 seconds).
123
     */
124
    void MarkTentative ();
125
126
    /**
127
     * \brief Change the state to this entry to GARBAGE.
128
     */
129
    void MarkGarbage ();
130
131
    /**
132
     * \brief Is the entry REGISTERED.
133
     * \return true if the type of entry is REGISTERED, false otherwise
134
     */
135
    bool IsRegistered () const;
136
137
    /**
138
     * \brief Is the entry TENTATIVE.
139
     * \return true if the type of entry is TENTATIVE, false otherwise
140
     */
141
    bool IsTentative () const;
142
143
    /**
144
     * \brief Is the entry GARBAGE-COLLECTIBLE.
145
     * \return true if the type of entry GARBAGE-COLLECTIBLE, false otherwise
146
     */
147
    bool IsGarbage () const;
148
149
    /**
150
     * \brief Function called when timer timeout.
151
     */
152
    void FunctionTimeout ();
153
154
    /**
155
     * \brief Get the EUI-64 of this entry.
156
     * \return EUI-64 value
157
     */
158
    Mac64Address GetEui64 () const;
159
160
    /**
161
     * \brief Set the EUI-64.
162
     * \param eui the EUI-64 value
163
     */
164
    void SetEui64 (Mac64Address eui);
165
166
  private:
167
    /**
168
     * \brief The SixLowPanEntry type enumeration.
169
     */
170
    enum SixLowPanNdiscCacheEntryType_e
171
    {
172
      REGISTERED, /**< Have an explicit registered lifetime */
173
      TENTATIVE, /**< Have a short lifetime, typically get converted to REGISTERED */
174
      GARBAGE /**< Allow for garbage collection when low on memory */
175
    };
176
177
    /**
178
     * \brief The EUI-64 value.
179
     */
180
    Mac64Address m_eui64;
181
182
    /**
183
     * \brief The state of the entry.
184
     */
185
    SixLowPanNdiscCacheEntryType_e m_type;
186
187
    /**
188
     * \brief Timer (used for REGISTERED entries).
189
     */
190
    Timer m_registeredTimer;
191
192
    /**
193
     * \brief Timer (used for TENTATIVE entries).
194
     */
195
    Timer m_tentativeTimer;
196
  };
197
198
  /**
199
   * \brief Lookup in the RA cache.
200
   * \param border the Border Router address
201
   * \return the entry if found, 0 otherwise
202
   */
203
  SixLowPanNdiscCache::SixLowPanRaEntry* RaEntryLookup (Ipv6Address border);
204
205
  /**
206
   * \brief Add an entry to the RA cache.
207
   * \param border the Border Router address
208
   * \return a new SixLowPanContext
209
   */
210
  SixLowPanNdiscCache::SixLowPanRaEntry* AddRaEntry (Ipv6Address border);
211
212
  /**
213
   * \brief Delete an entry from the RA cache.
214
   * \param entry pointer to delete from the list.
215
   */
216
  void RemoveRaEntry (SixLowPanNdiscCache::SixLowPanRaEntry* entry);
217
218
  /**
219
   * \brief Flush the RA cache.
220
   */
221
  void FlushRaCache ();
222
223
  /**
224
   * \brief Print the RA cache entries
225
   *
226
   * \param stream the ostream the RA cache entries is printed to
227
   */
228
  void PrintRaCache (Ptr<OutputStreamWrapper> stream);
229
230
  /**
231
   * \brief Get list of RA received.
232
   * \return list of RA
233
   */
234
  std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *> GetRaCache () const;
235
236
  /**
237
   * \class SixLowPanRaEntry
238
   * \brief RA advertised from routers for 6LoWPAN ND.
239
   */
240
  class SixLowPanRaEntry
241
  {
242
  public:
243
    /**
244
     * \brief Constructor.
245
     * \param nd The NdiscCache this ra entry belongs to.
246
     */
247
    SixLowPanRaEntry (SixLowPanNdiscCache* nd);
248
249
    /**
250
     * \brief Destructor.
251
     */
252
    ~SixLowPanRaEntry ();
253
254
    /**
255
     * \brief Get list of prefixes advertised for this interface.
256
     * \return list of IPv6 prefixes
257
     */
258
    std::map<Ipv6Address, Ptr<SixLowPanPrefix> > GetPrefixes () const;
259
260
    /**
261
     * \brief Add a prefix to advertise on interface.
262
     * \param prefix prefix to advertise
263
     */
264
    void AddPrefix (Ptr<SixLowPanPrefix> prefix);
265
266
    /**
267
     * \brief Remove a prefix.
268
     * \param prefix prefix to remove
269
     */
270
    void RemovePrefix (Ptr<SixLowPanPrefix> prefix);
271
272
    /**
273
     * \brief Get list of 6LoWPAN contexts advertised for this interface.
274
     * \return list of 6LoWPAN contexts
275
     */
276
    std::map<uint8_t, Ptr<SixLowPanContext> > GetContexts () const;
277
278
    /**
279
     * \brief Add a 6LoWPAN context to advertise on interface.
280
     * \param context 6LoWPAN context to advertise
281
     */
282
    void AddContext (Ptr<SixLowPanContext> context);
283
284
    /**
285
     * \brief Remove a 6LoWPAN context.
286
     * \param context 6LoWPAN context to remove
287
     */
288
    void RemoveContext (Ptr<SixLowPanContext> context);
289
290
    /**
291
     * \brief Is managed flag enabled ?
292
     * \return managed flag
293
     */
294
    bool IsManagedFlag () const;
295
296
    /**
297
     * \brief Set managed flag
298
     * \param managedFlag value
299
     */
300
    void SetManagedFlag (bool managedFlag);
301
302
    /**
303
     * \brief Is "other config" flag enabled ?
304
     * \return other config flag
305
     */
306
    bool IsOtherConfigFlag () const;
307
308
    /**
309
     * \brief Is "home agent" flag enabled ?
310
     * \return "home agent" flag
311
     */
312
    bool IsHomeAgentFlag () const;
313
314
    /**
315
     * \brief Set "home agent" flag.
316
     * \param homeAgentFlag value
317
     */
318
    void SetHomeAgentFlag (bool homeAgentFlag);
319
320
    /**
321
     * \brief Set "other config" flag
322
     * \param otherConfigFlag value
323
     */
324
    void SetOtherConfigFlag (bool otherConfigFlag);
325
326
    /**
327
     * \brief Get reachable time.
328
     * \return reachable time
329
     */
330
    uint32_t GetReachableTime () const;
331
332
    /**
333
     * \brief Set reachable time.
334
     * \param time reachable time
335
     */
336
    void SetReachableTime (uint32_t itme);
337
338
    /**
339
     * \brief Get router lifetime.
340
     * \return router lifetime
341
     */
342
    uint32_t GetRouterLifeTime () const;
343
344
    /**
345
     * \brief Set router lifetime.
346
     * \param time router lifetime
347
     */
348
    void SetRouterLifeTime (uint32_t time);
349
350
    /**
351
     * \brief Get retransmission timer.
352
     * \return retransmission timer
353
     */
354
    uint32_t GetRetransTimer () const;
355
356
    /**
357
     * \brief Set retransmission timer.
358
     * \param timer retransmission timer
359
     */
360
    void SetRetransTimer (uint32_t timer);
361
362
    /**
363
     * \brief Get current hop limit.
364
     * \return current hop limit for the link
365
     */
366
    uint8_t GetCurHopLimit () const;
367
368
    /**
369
     * \brief Set current hop limit.
370
     * \param curHopLimit current hop limit for the link
371
     */
372
    void SetCurHopLimit (uint8_t curHopLimit);
373
374
    /**
375
     * \brief Get version value (ABRO).
376
     * \return the version value
377
     */
378
    uint32_t GetVersion () const;
379
380
    /**
381
     * \brief Set version value (ABRO).
382
     * \param version the version value
383
     */
384
    void SetVersion (uint32_t version);
385
386
    /**
387
     * \brief Get valid lifetime value (ABRO).
388
     * \return the valid lifetime (units of 60 seconds)
389
     */
390
    uint16_t GetValidTime () const;
391
392
    /**
393
     * \brief Set valid lifetime value (ABRO).
394
     * \param time the valid lifetime (units of 60 seconds)
395
     */
396
    void SetValidTime (uint16_t time);
397
398
    /**
399
     * \brief Get Border Router address (ABRO).
400
     * \return the Border Router address
401
     */
402
    Ipv6Address GetBorderAddress () const;
403
404
    /**
405
     * \brief Set Border Router address (ABRO).
406
     * \param border the Border Router address
407
     */
408
    void SetBorderAddress (Ipv6Address border);
409
410
  private:
411
    /**
412
     * \brief List of prefixes advertised.
413
     */
414
    std::map<Ipv6Address, Ptr<SixLowPanPrefix> > m_prefixes;
415
416
    /**
417
     * \brief List of 6LoWPAN contexts advertised.
418
     */
419
    std::map<uint8_t, Ptr<SixLowPanContext> > m_contexts;
420
421
    /**
422
     * \brief Managed flag. If true host use the stateful protocol for address autoconfiguration.
423
     */
424
    bool m_managedFlag;
425
426
    /**
427
     * \brief Other configuration flag. If true host use stateful protocol for other (non-address) information.
428
     */
429
    bool m_otherConfigFlag;
430
431
    /**
432
     * \brief Flag to add HA (home agent) flag in RA.
433
     */
434
    bool m_homeAgentFlag;
435
436
    /**
437
     * \brief Reachable time in milliseconds.
438
     */
439
    uint32_t m_reachableTime;
440
441
    /**
442
     * \brief Retransmission timer in milliseconds.
443
     */
444
    uint32_t m_retransTimer;
445
446
    /**
447
     * \brief Current hop limit (TTL).
448
     */
449
    uint32_t m_curHopLimit;
450
451
    /**
452
     * \brief Router life time in seconds.
453
     */
454
    uint32_t m_routerLifeTime;
455
456
    /**
457
     * \brief Version value for ABRO.
458
     */
459
    uint32_t m_version;
460
461
    /**
462
     * \brief Valid lifetime value for ABRO (units of 60 seconds).
463
     */
464
    uint16_t m_validTime;
465
466
    /**
467
     * \brief Border Router address for ABRO.
468
     */
469
    Ipv6Address m_border;
470
  };
471
472
  protected:
473
  /**
474
   * \brief Dispose this object.
475
   */
476
  virtual void DoDispose ();
477
478
  private:
479
  /**
480
   * \brief RA entry container
481
   */
482
  typedef std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *> SixLowPanRaCache;
483
484
  /**
485
   * \brief RA entry container iterator
486
   */
487
  typedef std::map<Ipv6Address, SixLowPanNdiscCache::SixLowPanRaEntry *>::iterator SixLowPanRaCacheI;
488
489
  /**
490
   * \brief A list of RA entry.
491
   */
492
  SixLowPanRaCache m_raCache;
493
494
  /**
495
   * \brief 6LoWPAN Neighbor Discovery Cache container
496
   */
497
  typedef sgi::hash_map<Ipv6Address, SixLowPanNdiscCache::SixLowPanEntry *, Ipv6AddressHash> SixLowPanCache;
498
499
  /**
500
   * \brief 6LoWPAN Neighbor Discovery Cache container iterator
501
   */
502
  typedef sgi::hash_map<Ipv6Address, SixLowPanNdiscCache::SixLowPanEntry *, Ipv6AddressHash>::iterator SixLowPanCacheI;
503
504
  /**
505
   * \brief A list of Entry.
506
   */
507
  SixLowPanCache m_sixlowNdCache;
508
};
509
510
} /* namespace ns3 */
511
512
#endif /* SIXLOW_NDISC_CACHE_H */
(-)a/src/sixlowpan/model/sixlowpan-ndisc-ra-options.cc (+287 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#include <ns3/log.h>
22
#include "ns3/simulator.h"
23
24
#include "sixlowpan-ndisc-ra-options.h"
25
26
27
namespace ns3
28
{
29
30
NS_LOG_COMPONENT_DEFINE ("SixLowPanNdiscRaOptions");
31
32
SixLowPanPrefix::SixLowPanPrefix ()
33
{
34
  NS_LOG_FUNCTION (this);
35
}
36
37
SixLowPanPrefix::SixLowPanPrefix (Ipv6Address prefix, uint8_t prefixLen, uint32_t prefTime, uint32_t validTime, uint8_t flags)
38
  : m_prefix (prefix),
39
    m_prefixLength (prefixLen),
40
    m_preferredLifeTime (prefTime),
41
    m_validLifeTime (validTime),
42
    m_flags (flags)
43
{
44
  NS_LOG_FUNCTION (this << prefix << prefixLen << prefTime << validTime << flags);
45
46
  m_setValidTime = Simulator::Now ();
47
  m_setPrefTime = Simulator::Now ();
48
}
49
50
SixLowPanPrefix::~SixLowPanPrefix ()
51
{
52
  NS_LOG_FUNCTION (this);
53
}
54
55
Ipv6Address SixLowPanPrefix::GetPrefix () const
56
{
57
  NS_LOG_FUNCTION (this);
58
  return m_prefix;
59
}
60
61
void SixLowPanPrefix::SetPrefix (Ipv6Address prefix)
62
{
63
  NS_LOG_FUNCTION (this << prefix);
64
  m_prefix = prefix;
65
}
66
67
uint8_t SixLowPanPrefix::GetPrefixLength () const
68
{
69
  NS_LOG_FUNCTION (this);
70
  return m_prefixLength;
71
}
72
73
void SixLowPanPrefix::SetPrefixLength (uint8_t prefixLen)
74
{
75
  NS_LOG_FUNCTION (this << prefixLen);
76
  m_prefixLength = prefixLen;
77
}
78
79
uint32_t SixLowPanPrefix::GetValidLifeTime () const
80
{
81
  NS_LOG_FUNCTION (this);
82
  double time = Simulator::Now ().GetSeconds () - m_setValidTime.GetSeconds ();
83
84
  return m_validLifeTime - static_cast<uint32_t> (time);
85
}
86
87
void SixLowPanPrefix::SetValidLifeTime (uint32_t validTime)
88
{
89
  NS_LOG_FUNCTION (this << validTime);
90
  m_validLifeTime = validTime;
91
92
  m_setValidTime = Simulator::Now ();
93
}
94
95
uint32_t SixLowPanPrefix::GetPreferredLifeTime () const
96
{
97
  NS_LOG_FUNCTION (this);
98
  double time = Simulator::Now ().GetSeconds () - m_setPrefTime.GetSeconds ();
99
100
  return m_preferredLifeTime - static_cast<uint32_t> (time);
101
}
102
103
void SixLowPanPrefix::SetPreferredLifeTime (uint32_t prefTime)
104
{
105
  NS_LOG_FUNCTION (this << prefTime);
106
  m_preferredLifeTime = prefTime;
107
108
  m_setPrefTime = Simulator::Now ();
109
}
110
111
uint8_t SixLowPanPrefix::GetFlags () const
112
{
113
  NS_LOG_FUNCTION (this);
114
  return m_flags;
115
}
116
117
void SixLowPanPrefix::SetFlags (uint8_t flags)
118
{
119
  NS_LOG_FUNCTION (this << flags);
120
  m_flags = flags;
121
}
122
123
void SixLowPanPrefix::PrintPrefix (Ptr<OutputStreamWrapper> stream)
124
{
125
  NS_LOG_FUNCTION (this << stream);
126
  std::ostream* os = stream->GetStream ();
127
128
  *os << " Prefix Length: " << GetPrefixLength ();
129
130
  if (GetFlags () & (1 << 7))
131
    {
132
      *os << " On-link flag: true ";
133
    }
134
  else
135
    {
136
      *os << " On-link flag: false ";
137
    }
138
  if (GetFlags () & (1 << 6))
139
    {
140
      *os << " Autonomous flag: true ";
141
    }
142
      else
143
    {
144
      *os << " Autonomous flag: false ";
145
    }
146
  if (GetFlags () & (1 << 5))
147
    {
148
      *os << " Router address flag: true ";
149
    }
150
  else
151
    {
152
      *os << " Router address flag: false ";
153
    }
154
155
  *os << " Valid Lifetime: " << GetValidLifeTime ();
156
  *os << " Preferred Lifetime: " << GetPreferredLifeTime ();
157
  *os << " Prefix: " << GetPrefix ();
158
}
159
160
SixLowPanContext::SixLowPanContext ()
161
{
162
  NS_LOG_FUNCTION (this);
163
}
164
165
SixLowPanContext::SixLowPanContext (bool flagC, uint8_t cid, uint16_t time, Ipv6Prefix context)
166
  : m_c (flagC),
167
    m_cid (cid),
168
    m_validTime (time),
169
    m_context (context)
170
{
171
  NS_LOG_FUNCTION (this << flagC << static_cast<uint32_t> (cid) << time << context);
172
173
  m_setTime = Simulator::Now ();
174
}
175
176
SixLowPanContext::~SixLowPanContext ()
177
{
178
  NS_LOG_FUNCTION (this);
179
}
180
181
uint8_t SixLowPanContext::GetContextLen () const
182
{
183
  NS_LOG_FUNCTION (this);
184
  return m_length;
185
}
186
187
void SixLowPanContext::SetContextLen (uint8_t length)
188
{
189
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (length));
190
  m_length = length;
191
}
192
193
bool SixLowPanContext::IsFlagC () const
194
{
195
  NS_LOG_FUNCTION (this);
196
  return m_c;
197
}
198
199
void SixLowPanContext::SetFlagC (bool c)
200
{
201
  NS_LOG_FUNCTION (this << c);
202
  m_c = c;
203
}
204
205
uint8_t SixLowPanContext::GetCid () const
206
{
207
  NS_LOG_FUNCTION (this);
208
  return m_cid;
209
}
210
211
void SixLowPanContext::SetCid (uint8_t cid)
212
{
213
  NS_LOG_FUNCTION (this << static_cast<uint32_t> (cid));
214
  NS_ASSERT (cid <= 15);
215
  m_cid = cid;
216
}
217
218
uint16_t SixLowPanContext::GetValidTime () const
219
{
220
  NS_LOG_FUNCTION (this);
221
222
  double time = Simulator::Now ().GetMinutes () - m_setTime.GetMinutes ();
223
224
  return m_validTime - static_cast<uint16_t> (time);
225
}
226
227
void SixLowPanContext::SetValidTime (uint16_t time)
228
{
229
  NS_LOG_FUNCTION (this << time);
230
  m_validTime = time;
231
232
  m_setTime = Simulator::Now ();
233
234
  Simulator::Schedule (Time (Minutes (time)), &SixLowPanContext::ValidTimeout, this);
235
}
236
237
Ipv6Prefix SixLowPanContext::GetContextPrefix () const
238
{
239
  NS_LOG_FUNCTION (this);
240
  return m_context;
241
}
242
243
void SixLowPanContext::SetContextPrefix (Ipv6Prefix context)
244
{
245
  NS_LOG_FUNCTION (this << context);
246
  m_context = context;
247
}
248
249
void SixLowPanContext::PrintContext (Ptr<OutputStreamWrapper> stream)
250
{
251
  NS_LOG_FUNCTION (this << stream);
252
  std::ostream* os = stream->GetStream ();
253
254
  *os << " Context Length: " << GetContextLen ();
255
256
  if (IsFlagC ())
257
    {
258
      *os << " Compression flag: true ";
259
    }
260
  else
261
    {
262
      *os << " Compression flag: false ";
263
    }
264
265
  *os << " Context Identifier: " << GetCid ();
266
  *os << " Valid Lifetime: " << GetValidTime ();
267
  *os << " Context Prefix: " << GetContextPrefix ();
268
}
269
270
void SixLowPanContext::ValidTimeout ()
271
{
272
  NS_LOG_FUNCTION_NOARGS ();
273
274
  m_c = false;
275
276
  Simulator::Schedule (Time (Seconds (2 * 1000 /*m_entry->GetRouterLifeTime ()*/)), &SixLowPanContext::RouterTimeout, this);
277
} /// \todo da finire!!!
278
279
void SixLowPanContext::RouterTimeout ()
280
{
281
  NS_LOG_FUNCTION_NOARGS ();
282
283
  //m_entry->RemoveContext (this);
284
  return;
285
} /// \todo da finire!!!
286
287
} /* namespace ns3 */
(-)a/src/sixlowpan/model/sixlowpan-ndisc-ra-options.h (+302 lines)
Line 0    Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2015 Università di Firenze, Italy
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: Alessio Bonadio <alessio.bonadio@gmail.com>
19
 */
20
21
#ifndef SIXLOW_NDISC_RA_OPTIONS_H
22
#define SIXLOW_NDISC_RA_OPTIONS_H
23
24
#include <stdint.h>
25
26
#include "ns3/nstime.h"
27
#include "ns3/ipv6-address.h"
28
#include "ns3/simple-ref-count.h"
29
#include "ns3/output-stream-wrapper.h"
30
31
namespace ns3
32
{
33
34
/**
35
 * \ingroup sixlowpan
36
 * \class SixLowPanPrefix
37
 * \brief Router prefix container for 6LoWPAN ND.
38
 */
39
class SixLowPanPrefix : public SimpleRefCount<SixLowPanPrefix>
40
{
41
public:
42
  /**
43
   * \brief Constructor.
44
   */
45
  SixLowPanPrefix ();
46
47
  /**
48
   * \brief Constructor.
49
   * \param prefix network prefix advertised
50
   * \param prefixLen prefix length ( 0 < x <= 128)
51
   * \param prefTime preferred life time in seconds (default 7 days)
52
   * \param validTime valid life time in seconds (default 30 days)
53
   * \param flags the flags (L = 128, A = 64, R = 32)
54
   */
55
  SixLowPanPrefix (Ipv6Address prefix, uint8_t prefixLen, uint32_t prefTime, uint32_t validTime, uint8_t flags);
56
57
  /**
58
   * \brief Destructor.
59
   */
60
  ~SixLowPanPrefix ();
61
62
   /**
63
   * \brief Get network prefix.
64
   * \return network prefix
65
   */
66
  Ipv6Address GetPrefix () const;
67
68
  /**
69
   * \brief Set network prefix.
70
   * \param network network prefix
71
   */
72
  void SetPrefix (Ipv6Address prefix);
73
74
  /**
75
   * \brief Get prefix length.
76
   * \return prefix length
77
   */
78
  uint8_t GetPrefixLength () const;
79
80
  /**
81
   * \brief Set prefix length.
82
   * \param prefixLen prefix length
83
   */
84
  void SetPrefixLength (uint8_t prefixLen);
85
86
  /**
87
   * \brief Get preferred lifetime.
88
   * \return lifetime
89
   */
90
  uint32_t GetPreferredLifeTime () const;
91
92
  /**
93
   * \brief Set preferred lifetime.
94
   * \param prefTime lifetime
95
   */
96
  void SetPreferredLifeTime (uint32_t prefTime);
97
98
  /**
99
   * \brief Get valid lifetime.
100
   * \return lifetime
101
   */
102
  uint32_t GetValidLifeTime () const;
103
104
  /**
105
   * \brief Set valid lifetime.
106
   * \param validTime lifetime
107
   */
108
  void SetValidLifeTime (uint32_t validTime);
109
110
  /**
111
   * \brief Get the flags.
112
   * \return the flags (L = 128, A = 64, R = 32)
113
   */
114
  uint8_t GetFlags () const;
115
116
  /**
117
   * \brief Set the flags.
118
   * \param flags the flags to set (L = 128, A = 64, R = 32)
119
   */
120
  void SetFlags (uint8_t flags);
121
122
  /**
123
   * \brief Print the prefix
124
   * \param stream the ostream the prefix is printed to
125
   */
126
  void PrintPrefix (Ptr<OutputStreamWrapper> stream);
127
128
private:
129
  /**
130
   * \brief Network prefix.
131
   */
132
  Ipv6Address m_prefix;
133
134
  /**
135
   * \brief Prefix length.
136
   */
137
  uint8_t m_prefixLength;
138
139
  /**
140
   * \brief Preferred time.
141
   */
142
  uint32_t m_preferredLifeTime;
143
144
  /**
145
   * \brief Valid time.
146
   */
147
  uint32_t m_validLifeTime;
148
149
  /**
150
   * \brief Flags.
151
   */
152
  uint8_t m_flags;
153
154
  /**
155
   * \brief Prefix valid lifetime set time.
156
   */
157
  Time m_setValidTime;
158
159
  /**
160
   * \brief Prefix preferred lifetime set time.
161
   */
162
  Time m_setPrefTime;
163
};
164
165
/**
166
 * \ingroup sixlowpan
167
 * \class SixLowPanContext
168
 * \brief 6LoWPAN context container for 6LoWPAN ND.
169
 */
170
class SixLowPanContext : public SimpleRefCount<SixLowPanContext>
171
{
172
public:
173
  /**
174
   * \brief Constructor.
175
   */
176
  SixLowPanContext ();
177
178
  /**
179
   * \brief Constructor.
180
   * \param flagC compression flag
181
   * \param cid context identifier ( 0 <= x <= 15)
182
   * \param time valid lifetime of context (units of 60 seconds)
183
   * \param context 6LoWPAN context advertised
184
   */
185
  SixLowPanContext (bool flagC, uint8_t cid, uint16_t time, Ipv6Prefix context);
186
187
  /**
188
   * \brief Destructor.
189
   */
190
  ~SixLowPanContext ();
191
192
  /**
193
   * \brief Get the context length.
194
   * \return context length value
195
   */
196
  uint8_t GetContextLen () const;
197
198
  /**
199
   * \brief Set the context length.
200
   * \param length the context length value
201
   */
202
  void SetContextLen (uint8_t length);
203
204
  /**
205
   * \brief Is compression flag ?
206
   * \return true if context is valid for use in compression, false otherwise
207
   */
208
  bool IsFlagC () const;
209
210
  /**
211
   * \brief Set the compression flag.
212
   * \param c the compression flag
213
   */
214
  void SetFlagC (bool c);
215
216
  /**
217
   * \brief Get the context identifier.
218
   * \return context identifier value
219
   */
220
  uint8_t GetCid () const;
221
222
  /**
223
   * \brief Set the context identifier.
224
   * \param cid the context identifier value
225
   */
226
  void SetCid (uint8_t cid);
227
228
  /**
229
   * \brief Get the valid lifetime.
230
   * \return valid lifetime value (units of 60 seconds)
231
   */
232
  uint16_t GetValidTime () const;
233
234
  /**
235
   * \brief Set the valid lifetime.
236
   * \param time the valid lifetime value (units of 60 seconds)
237
   */
238
  void SetValidTime (uint16_t time);
239
240
  /**
241
   * \brief Get the 6LoWPAN context prefix.
242
   * \return context prefix value
243
   */
244
  Ipv6Prefix GetContextPrefix () const;
245
246
  /**
247
   * \brief Set the 6LoWPAN context prefix.
248
   * \param prefix the context prefix value
249
   */
250
  void SetContextPrefix (Ipv6Prefix context);
251
252
  /**
253
   * \brief Print the 6LoWPAN context.
254
   * \param stream the ostream the 6LoWPAN context is printed to
255
   */
256
  void PrintContext (Ptr<OutputStreamWrapper> stream);
257
258
  /**
259
   * \brief Function called when valid lifetime timeout.
260
   */
261
  void ValidTimeout ();
262
263
  /**
264
   * \brief Function called when router lifetime timeout.
265
   */
266
  void RouterTimeout ();
267
268
private:
269
  /**
270
   * \brief The context length value.
271
   */
272
  uint8_t m_length;
273
274
  /**
275
   * \brief The compression flag, indicates that this context is valid for use in compression.
276
   */
277
  bool m_c;
278
279
  /**
280
   * \brief The context identifier value.
281
   */
282
  uint8_t m_cid;
283
284
  /**
285
   * \brief The valid lifetime value (units of 60 seconds).
286
   */
287
  uint16_t m_validTime;
288
289
  /**
290
   * \brief The context prefix value.
291
   */
292
  Ipv6Prefix m_context;
293
294
  /**
295
   * \brief Context set time.
296
   */
297
  Time m_setTime;
298
};
299
300
} /* namespace ns3 */
301
302
#endif /* SIXLOW_NDISC_RA_OPTIONS_H */
(-)a/src/sixlowpan/model/sixlowpan-net-device.h (-15 / +15 lines)
 Lines 145-150   public: Link Here 
145
   */
145
   */
146
  int64_t AssignStreams (int64_t stream);
146
  int64_t AssignStreams (int64_t stream);
147
147
148
  /**
149
   * \brief Make a link-local address from a MAC address.
150
   * \param [in] addr The MAC address.
151
   * \return The IPv6 link-local address.
152
   */
153
  Ipv6Address MakeLinkLocalAddressFromMac (Address const &addr);
154
155
  /**
156
   * \brief Make a global address from a MAC address.
157
   * \param [in] addr the MAC address.
158
   * \param [in] prefix The address prefix.
159
   * \return The IPv6 address.
160
   */
161
  Ipv6Address MakeGlobalAddressFromMac (Address const &addr, Ipv6Address prefix);
162
148
  /**
163
  /**
149
   * TracedCallback signature for packet send/receive events.
164
   * TracedCallback signature for packet send/receive events.
150
   *
165
   *
 Lines 272-292   private: Link Here 
272
   */
287
   */
273
  TracedCallback<DropReason, Ptr<const Packet>, Ptr<SixLowPanNetDevice>, uint32_t> m_dropTrace;
288
  TracedCallback<DropReason, Ptr<const Packet>, Ptr<SixLowPanNetDevice>, uint32_t> m_dropTrace;
274
289
275
  /**
276
   * \brief Make a link-local address from a MAC address.
277
   * \param [in] addr The MAC address.
278
   * \return The IPv6 link-local address.
279
   */
280
  Ipv6Address MakeLinkLocalAddressFromMac (Address const &addr);
281
282
  /**
283
   * \brief Make a global address from a MAC address.
284
   * \param [in] addr the MAC address.
285
   * \param [in] prefix The address prefix.
286
   * \return The IPv6 address.
287
   */
288
  Ipv6Address MakeGlobalAddressFromMac (Address const &addr, Ipv6Address prefix);
289
290
  /**
290
  /**
291
   * \brief Compress the headers according to HC1 compression.
291
   * \brief Compress the headers according to HC1 compression.
292
   * \param [in] packet The packet to be compressed.
292
   * \param [in] packet The packet to be compressed.
(-)a/src/sixlowpan/wscript (+8 lines)
 Lines 6-11   def build(bld): Link Here 
6
    module.source = [
6
    module.source = [
7
        'model/sixlowpan-net-device.cc',
7
        'model/sixlowpan-net-device.cc',
8
        'model/sixlowpan-header.cc',
8
        'model/sixlowpan-header.cc',
9
        'model/sixlowpan-ndisc-cache.cc',
10
        'model/sixlowpan-ndisc-ra-options.cc',
11
        'model/sixlowpan-nd-header.cc',
12
        'model/sixlowpan-nd-protocol.cc',
9
        'helper/sixlowpan-helper.cc',
13
        'helper/sixlowpan-helper.cc',
10
        ]
14
        ]
11
15
 Lines 22-27   def build(bld): Link Here 
22
    headers.source = [
26
    headers.source = [
23
        'model/sixlowpan-net-device.h',
27
        'model/sixlowpan-net-device.h',
24
        'model/sixlowpan-header.h',
28
        'model/sixlowpan-header.h',
29
        'model/sixlowpan-ndisc-cache.h',
30
        'model/sixlowpan-ndisc-ra-options.h',
31
        'model/sixlowpan-nd-header.h',
32
        'model/sixlowpan-nd-protocol.h',
25
        'helper/sixlowpan-helper.h',
33
        'helper/sixlowpan-helper.h',
26
        ]
34
        ]
27
35

Return to bug 2805