LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 Universita' di Firenze, Italy | 3 * Copyright (c) 2013 Universita' di Firenze, Italy |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> | 18 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it> |
19 * Michele Muccio <michelemuccio@virgilio.it> | 19 * Michele Muccio <michelemuccio@virgilio.it> |
20 */ | 20 */ |
21 | 21 |
22 #include "ns3/assert.h" | 22 #include "ns3/assert.h" |
23 #include "ns3/log.h" | 23 #include "ns3/log.h" |
24 #include "ns3/abort.h" | 24 #include "ns3/abort.h" |
25 #include "ns3/address-utils.h" | 25 #include "ns3/address-utils.h" |
26 #include "sixlowpan-header.h" | 26 #include "sixlowpan-header.h" |
27 | 27 |
28 | 28 |
29 namespace ns3 { | 29 namespace ns3 { |
30 namespace sixlowpan { | |
31 | 30 |
32 /* | 31 /* |
33 * SixLowPanDispatch | 32 * SixLowPanDispatch |
34 */ | 33 */ |
35 | 34 |
36 NS_OBJECT_ENSURE_REGISTERED (SixLowPanDispatch); | |
37 | 35 |
38 SixLowPanDispatch::SixLowPanDispatch () | 36 SixLowPanDispatch::SixLowPanDispatch () |
39 { | 37 { |
40 } | 38 } |
41 | 39 |
42 SixLowPanDispatch::SixLowPanDispatch ( SixLowPanDispatch::Dispatch_e dispatch ) | |
43 { | |
44 } | |
45 | |
46 TypeId SixLowPanDispatch::GetTypeId (void) | |
47 { | |
48 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanDispatch").SetParent<Hea
der> ().AddConstructor<SixLowPanDispatch> (); | |
49 return tid; | |
50 } | |
51 | |
52 TypeId SixLowPanDispatch::GetInstanceTypeId (void) const | |
53 { | |
54 return GetTypeId (); | |
55 } | |
56 | |
57 SixLowPanDispatch::Dispatch_e | |
58 SixLowPanDispatch::GetDispatchType (void) const | |
59 { | |
60 return LOWPAN_NALP; | |
61 } | |
62 | 40 |
63 SixLowPanDispatch::Dispatch_e | 41 SixLowPanDispatch::Dispatch_e |
64 SixLowPanDispatch::GetDispatchType (uint8_t dispatch) | 42 SixLowPanDispatch::GetDispatchType (uint8_t dispatch) |
65 { | 43 { |
66 if (dispatch <= LOWPAN_NALP_N) | 44 if (dispatch <= LOWPAN_NALP_N) |
67 { | 45 { |
68 return LOWPAN_NALP; | 46 return LOWPAN_NALP; |
69 } | 47 } |
70 else if (dispatch == LOWPAN_NOTCOMPRESSED) | 48 else if (dispatch == LOWPAN_NOTCOMPRESSED) |
71 { | 49 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 { | 81 { |
104 if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N)) | 82 if ((dispatch >= LOWPAN_NHC) && (dispatch <= LOWPAN_NHC_N)) |
105 { | 83 { |
106 return LOWPAN_NHC; | 84 return LOWPAN_NHC; |
107 } | 85 } |
108 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N)) | 86 else if ((dispatch >= LOWPAN_UDPNHC) && (dispatch <= LOWPAN_UDPNHC_N)) |
109 { | 87 { |
110 return LOWPAN_UDPNHC; | 88 return LOWPAN_UDPNHC; |
111 } | 89 } |
112 return LOWPAN_NHCUNSUPPORTED; | 90 return LOWPAN_NHCUNSUPPORTED; |
113 } | |
114 | |
115 | |
116 void SixLowPanDispatch::Print (std::ostream & os) const | |
117 { | |
118 } | |
119 | |
120 uint32_t SixLowPanDispatch::GetSerializedSize () const | |
121 { | |
122 return 0; | |
123 } | |
124 | |
125 void SixLowPanDispatch::Serialize (Buffer::Iterator start) const | |
126 { | |
127 } | |
128 | |
129 uint32_t SixLowPanDispatch::Deserialize (Buffer::Iterator start) | |
130 { | |
131 return GetSerializedSize (); | |
132 } | |
133 | |
134 | |
135 std::ostream & operator << (std::ostream & os, const SixLowPanDispatch & h) | |
136 { | |
137 h.Print (os); | |
138 return os; | |
139 } | 91 } |
140 | 92 |
141 | 93 |
142 /* | 94 /* |
143 * SixLowPanHc1 | 95 * SixLowPanHc1 |
144 */ | 96 */ |
145 NS_OBJECT_ENSURE_REGISTERED (SixLowPanHc1); | 97 NS_OBJECT_ENSURE_REGISTERED (SixLowPanHc1) |
| 98 ; |
146 | 99 |
147 SixLowPanHc1::SixLowPanHc1 () | 100 SixLowPanHc1::SixLowPanHc1 () |
148 : m_hopLimit (0) | 101 : m_hopLimit (0) |
149 { | 102 { |
150 } | 103 } |
151 | 104 |
152 TypeId SixLowPanHc1::GetTypeId (void) | 105 TypeId SixLowPanHc1::GetTypeId (void) |
153 { | 106 { |
154 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanHc1").SetParent<Header>
().AddConstructor<SixLowPanHc1> (); | 107 static TypeId tid = TypeId ("ns3::SixLowPanHc1").SetParent<Header> ().AddConst
ructor<SixLowPanHc1> (); |
155 return tid; | 108 return tid; |
156 } | 109 } |
157 | 110 |
158 TypeId SixLowPanHc1::GetInstanceTypeId (void) const | 111 TypeId SixLowPanHc1::GetInstanceTypeId (void) const |
159 { | 112 { |
160 return GetTypeId (); | 113 return GetTypeId (); |
161 } | 114 } |
162 | 115 |
163 void SixLowPanHc1::Print (std::ostream & os) const | 116 void SixLowPanHc1::Print (std::ostream & os) const |
164 { | 117 { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 encoding = m_srcCompression; | 182 encoding = m_srcCompression; |
230 encoding <<= 2; | 183 encoding <<= 2; |
231 encoding |= m_dstCompression; | 184 encoding |= m_dstCompression; |
232 encoding <<= 1; | 185 encoding <<= 1; |
233 encoding |= m_tcflCompression; | 186 encoding |= m_tcflCompression; |
234 encoding <<= 2; | 187 encoding <<= 2; |
235 encoding |= m_nextHeaderCompression; | 188 encoding |= m_nextHeaderCompression; |
236 encoding <<= 1; | 189 encoding <<= 1; |
237 encoding |= m_hc2HeaderPresent; | 190 encoding |= m_hc2HeaderPresent; |
238 | 191 |
239 i.WriteU8 (LOWPAN_HC1); | 192 i.WriteU8 (SixLowPanDispatch::LOWPAN_HC1); |
240 i.WriteU8 (encoding); | 193 i.WriteU8 (encoding); |
241 i.WriteU8 (m_hopLimit); | 194 i.WriteU8 (m_hopLimit); |
242 switch (m_srcCompression) | 195 switch (m_srcCompression) |
243 { | 196 { |
244 case HC1_PIII: | 197 case HC1_PIII: |
245 for ( int j = 0; j < 8; j++ ) | 198 for ( int j = 0; j < 8; j++ ) |
246 { | 199 { |
247 i.WriteU8 (m_srcPrefix[j]); | 200 i.WriteU8 (m_srcPrefix[j]); |
248 } | 201 } |
249 for ( int j = 0; j < 8; j++ ) | 202 for ( int j = 0; j < 8; j++ ) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // TODO: HC2 is not yet supported. Should be. | 265 // TODO: HC2 is not yet supported. Should be. |
313 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Ve
ry sorry." ); | 266 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Ve
ry sorry." ); |
314 } | 267 } |
315 | 268 |
316 uint32_t SixLowPanHc1::Deserialize (Buffer::Iterator start) | 269 uint32_t SixLowPanHc1::Deserialize (Buffer::Iterator start) |
317 { | 270 { |
318 Buffer::Iterator i = start; | 271 Buffer::Iterator i = start; |
319 uint32_t serializedSize = 3; | 272 uint32_t serializedSize = 3; |
320 | 273 |
321 uint8_t dispatch = i.ReadU8 (); | 274 uint8_t dispatch = i.ReadU8 (); |
322 if (dispatch != LOWPAN_HC1) | 275 if (dispatch != SixLowPanDispatch::LOWPAN_HC1) |
323 { | 276 { |
324 return 0; | 277 return 0; |
325 } | 278 } |
326 | 279 |
327 uint8_t encoding = i.ReadU8 (); | 280 uint8_t encoding = i.ReadU8 (); |
328 m_hopLimit = i.ReadU8 (); | 281 m_hopLimit = i.ReadU8 (); |
329 | 282 |
330 m_srcCompression = LowPanHc1Addr_e (encoding >> 6); | 283 m_srcCompression = LowPanHc1Addr_e (encoding >> 6); |
331 m_dstCompression = LowPanHc1Addr_e ( (encoding >> 4) & 0x3); | 284 m_dstCompression = LowPanHc1Addr_e ( (encoding >> 4) & 0x3); |
332 m_tcflCompression = (encoding >> 3) & 0x1; | 285 m_tcflCompression = (encoding >> 3) & 0x1; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 case HC1_ICMP: | 373 case HC1_ICMP: |
421 m_nextHeader = Ipv6Header::IPV6_ICMPV6; | 374 m_nextHeader = Ipv6Header::IPV6_ICMPV6; |
422 break; | 375 break; |
423 } | 376 } |
424 | 377 |
425 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Ve
ry sorry." ); | 378 NS_ASSERT_MSG ( m_hc2HeaderPresent != true, "Can not compress HC2, exiting. Ve
ry sorry." ); |
426 | 379 |
427 return GetSerializedSize (); | 380 return GetSerializedSize (); |
428 } | 381 } |
429 | 382 |
430 SixLowPanDispatch::Dispatch_e | |
431 SixLowPanHc1::GetDispatchType (void) const | |
432 { | |
433 return LOWPAN_HC1; | |
434 } | |
435 | |
436 void SixLowPanHc1::SetHopLimit (uint8_t limit) | 383 void SixLowPanHc1::SetHopLimit (uint8_t limit) |
437 { | 384 { |
438 m_hopLimit = limit; | 385 m_hopLimit = limit; |
439 } | 386 } |
440 | 387 |
441 uint8_t SixLowPanHc1::GetHopLimit () const | 388 uint8_t SixLowPanHc1::GetHopLimit () const |
442 { | 389 { |
443 return m_hopLimit; | 390 return m_hopLimit; |
444 } | 391 } |
445 | 392 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 532 |
586 std::ostream & operator << (std::ostream & os, const SixLowPanHc1 & h) | 533 std::ostream & operator << (std::ostream & os, const SixLowPanHc1 & h) |
587 { | 534 { |
588 h.Print (os); | 535 h.Print (os); |
589 return os; | 536 return os; |
590 } | 537 } |
591 | 538 |
592 /* | 539 /* |
593 * SixLowPanFrag1 | 540 * SixLowPanFrag1 |
594 */ | 541 */ |
595 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFrag1); | 542 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFrag1) |
| 543 ; |
596 | 544 |
597 SixLowPanFrag1::SixLowPanFrag1 () | 545 SixLowPanFrag1::SixLowPanFrag1 () |
598 : m_datagramSize (0), | 546 : m_datagramSize (0), |
599 m_datagramTag (0) | 547 m_datagramTag (0) |
600 { | 548 { |
601 } | 549 } |
602 | 550 |
603 TypeId SixLowPanFrag1::GetTypeId (void) | 551 TypeId SixLowPanFrag1::GetTypeId (void) |
604 { | 552 { |
605 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanFrag1").SetParent<Header
> ().AddConstructor<SixLowPanFrag1> (); | 553 static TypeId tid = TypeId ("ns3::SixLowPanFrag1").SetParent<Header> ().AddCon
structor<SixLowPanFrag1> (); |
606 return tid; | 554 return tid; |
607 } | 555 } |
608 | 556 |
609 TypeId SixLowPanFrag1::GetInstanceTypeId (void) const | 557 TypeId SixLowPanFrag1::GetInstanceTypeId (void) const |
610 { | 558 { |
611 return GetTypeId (); | 559 return GetTypeId (); |
612 } | 560 } |
613 | 561 |
614 SixLowPanDispatch::Dispatch_e | |
615 SixLowPanFrag1::GetDispatchType (void) const | |
616 { | |
617 return LOWPAN_FRAG1; | |
618 } | |
619 | |
620 void SixLowPanFrag1::Print (std::ostream & os) const | 562 void SixLowPanFrag1::Print (std::ostream & os) const |
621 { | 563 { |
622 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag; | 564 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag; |
623 } | 565 } |
624 | 566 |
625 uint32_t SixLowPanFrag1::GetSerializedSize () const | 567 uint32_t SixLowPanFrag1::GetSerializedSize () const |
626 { | 568 { |
627 return 4; | 569 return 4; |
628 } | 570 } |
629 | 571 |
630 void SixLowPanFrag1::Serialize (Buffer::Iterator start) const | 572 void SixLowPanFrag1::Serialize (Buffer::Iterator start) const |
631 { | 573 { |
632 Buffer::Iterator i = start; | 574 Buffer::Iterator i = start; |
633 | 575 |
634 uint16_t temp = m_datagramSize | ( uint16_t (LOWPAN_FRAG1) << 8 ); | 576 uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAG1)
<< 8 ); |
635 | 577 |
636 i.WriteU8 (uint8_t (temp >> 8)); | 578 i.WriteU8 (uint8_t (temp >> 8)); |
637 i.WriteU8 (uint8_t (temp & 0xff)); | 579 i.WriteU8 (uint8_t (temp & 0xff)); |
638 | 580 |
639 i.WriteU16 (m_datagramTag); | 581 i.WriteU16 (m_datagramTag); |
640 } | 582 } |
641 | 583 |
642 uint32_t SixLowPanFrag1::Deserialize (Buffer::Iterator start) | 584 uint32_t SixLowPanFrag1::Deserialize (Buffer::Iterator start) |
643 { | 585 { |
644 Buffer::Iterator i = start; | 586 Buffer::Iterator i = start; |
(...skipping 30 matching lines...) Expand all Loading... |
675 { | 617 { |
676 h.Print (os); | 618 h.Print (os); |
677 return os; | 619 return os; |
678 } | 620 } |
679 | 621 |
680 | 622 |
681 /* | 623 /* |
682 * SixLowPanFragN | 624 * SixLowPanFragN |
683 */ | 625 */ |
684 | 626 |
685 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFragN); | 627 NS_OBJECT_ENSURE_REGISTERED (SixLowPanFragN) |
| 628 ; |
686 | 629 |
687 SixLowPanFragN::SixLowPanFragN () | 630 SixLowPanFragN::SixLowPanFragN () |
688 : m_datagramSize (0), | 631 : m_datagramSize (0), |
689 m_datagramTag (0), | 632 m_datagramTag (0), |
690 m_datagramOffset (0) | 633 m_datagramOffset (0) |
691 { | 634 { |
692 } | 635 } |
693 /* | 636 /* |
694 * SixLowPanFragmentOffset | 637 * SixLowPanFragmentOffset |
695 */ | 638 */ |
696 TypeId SixLowPanFragN::GetTypeId (void) | 639 TypeId SixLowPanFragN::GetTypeId (void) |
697 { | 640 { |
698 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanFragN").SetParent<Header
> ().AddConstructor<SixLowPanFragN> (); | 641 static TypeId tid = TypeId ("ns3::SixLowPanFragN").SetParent<Header> ().AddCon
structor<SixLowPanFragN> (); |
699 return tid; | 642 return tid; |
700 } | 643 } |
701 | 644 |
702 TypeId SixLowPanFragN::GetInstanceTypeId (void) const | 645 TypeId SixLowPanFragN::GetInstanceTypeId (void) const |
703 { | 646 { |
704 return GetTypeId (); | 647 return GetTypeId (); |
705 } | 648 } |
706 | 649 |
707 void SixLowPanFragN::Print (std::ostream & os) const | 650 void SixLowPanFragN::Print (std::ostream & os) const |
708 { | 651 { |
709 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offs
et " << int(m_datagramOffset); | 652 os << "datagram size " << m_datagramSize << " tag " << m_datagramTag << " offs
et " << int(m_datagramOffset); |
710 } | 653 } |
711 | 654 |
712 uint32_t SixLowPanFragN::GetSerializedSize () const | 655 uint32_t SixLowPanFragN::GetSerializedSize () const |
713 { | 656 { |
714 return 5; | 657 return 5; |
715 } | 658 } |
716 | 659 |
717 void SixLowPanFragN::Serialize (Buffer::Iterator start) const | 660 void SixLowPanFragN::Serialize (Buffer::Iterator start) const |
718 { | 661 { |
719 Buffer::Iterator i = start; | 662 Buffer::Iterator i = start; |
720 | 663 |
721 uint16_t temp = m_datagramSize | ( uint16_t (LOWPAN_FRAGN) << 8 ); | 664 uint16_t temp = m_datagramSize | ( uint16_t (SixLowPanDispatch::LOWPAN_FRAGN)
<< 8 ); |
722 | 665 |
723 i.WriteU8 (uint8_t (temp >> 8)); | 666 i.WriteU8 (uint8_t (temp >> 8)); |
724 i.WriteU8 (uint8_t (temp & 0xff)); | 667 i.WriteU8 (uint8_t (temp & 0xff)); |
725 | 668 |
726 i.WriteU16 (m_datagramTag); | 669 i.WriteU16 (m_datagramTag); |
727 i.WriteU8 (m_datagramOffset); | 670 i.WriteU8 (m_datagramOffset); |
728 } | 671 } |
729 | 672 |
730 uint32_t SixLowPanFragN::Deserialize (Buffer::Iterator start) | 673 uint32_t SixLowPanFragN::Deserialize (Buffer::Iterator start) |
731 { | 674 { |
732 Buffer::Iterator i = start; | 675 Buffer::Iterator i = start; |
733 | 676 |
734 uint8_t temp = i.ReadU8 (); | 677 uint8_t temp = i.ReadU8 (); |
735 m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 (); | 678 m_datagramSize = (uint16_t (temp) << 8) | i.ReadU8 (); |
736 m_datagramSize &= 0x7FF; | 679 m_datagramSize &= 0x7FF; |
737 | 680 |
738 m_datagramTag = i.ReadU16 (); | 681 m_datagramTag = i.ReadU16 (); |
739 m_datagramOffset = i.ReadU8 (); | 682 m_datagramOffset = i.ReadU8 (); |
740 | 683 |
741 return GetSerializedSize (); | 684 return GetSerializedSize (); |
742 } | 685 } |
743 | 686 |
744 SixLowPanDispatch::Dispatch_e | |
745 SixLowPanFragN::GetDispatchType (void) const | |
746 { | |
747 return LOWPAN_FRAGN; | |
748 } | |
749 | |
750 void SixLowPanFragN::SetDatagramSize (uint16_t datagramSize) | 687 void SixLowPanFragN::SetDatagramSize (uint16_t datagramSize) |
751 { | 688 { |
752 m_datagramSize = datagramSize & 0x7FF; | 689 m_datagramSize = datagramSize & 0x7FF; |
753 } | 690 } |
754 | 691 |
755 uint16_t SixLowPanFragN::GetDatagramSize () const | 692 uint16_t SixLowPanFragN::GetDatagramSize () const |
756 { | 693 { |
757 return m_datagramSize & 0x7FF; | 694 return m_datagramSize & 0x7FF; |
758 } | 695 } |
759 | 696 |
(...skipping 19 matching lines...) Expand all Loading... |
779 | 716 |
780 std::ostream & operator << (std::ostream & os, const SixLowPanFragN & h) | 717 std::ostream & operator << (std::ostream & os, const SixLowPanFragN & h) |
781 { | 718 { |
782 h.Print (os); | 719 h.Print (os); |
783 return os; | 720 return os; |
784 } | 721 } |
785 | 722 |
786 /* | 723 /* |
787 * SixLowPanIphcHeader | 724 * SixLowPanIphcHeader |
788 */ | 725 */ |
789 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIphc); | 726 NS_OBJECT_ENSURE_REGISTERED (SixLowPanIphc) |
| 727 ; |
790 | 728 |
791 SixLowPanIphc::SixLowPanIphc () | 729 SixLowPanIphc::SixLowPanIphc () |
792 { | 730 { |
793 // 011x xxxx xxxx xxxx | 731 // 011x xxxx xxxx xxxx |
794 m_baseFormat = 0x6000; | 732 m_baseFormat = 0x6000; |
795 } | 733 } |
796 | 734 |
797 SixLowPanIphc::SixLowPanIphc (uint8_t dispatch) | 735 SixLowPanIphc::SixLowPanIphc (uint8_t dispatch) |
798 { | 736 { |
799 // 011x xxxx xxxx xxxx | 737 // 011x xxxx xxxx xxxx |
800 m_baseFormat = dispatch; | 738 m_baseFormat = dispatch; |
801 m_baseFormat <<= 8; | 739 m_baseFormat <<= 8; |
802 } | 740 } |
803 | 741 |
804 TypeId SixLowPanIphc::GetTypeId (void) | 742 TypeId SixLowPanIphc::GetTypeId (void) |
805 { | 743 { |
806 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanIphc").SetParent<Header>
().AddConstructor<SixLowPanIphc> (); | 744 static TypeId tid = TypeId ("ns3::SixLowPanIphc").SetParent<Header> ().AddCons
tructor<SixLowPanIphc> (); |
807 return tid; | 745 return tid; |
808 } | 746 } |
809 | 747 |
810 TypeId SixLowPanIphc::GetInstanceTypeId (void) const | 748 TypeId SixLowPanIphc::GetInstanceTypeId (void) const |
811 { | 749 { |
812 return GetTypeId (); | 750 return GetTypeId (); |
813 } | 751 } |
814 | 752 |
815 void SixLowPanIphc::Print (std::ostream & os) const | 753 void SixLowPanIphc::Print (std::ostream & os) const |
816 { | 754 { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 break; | 1197 break; |
1260 } | 1198 } |
1261 } | 1199 } |
1262 if ( GetDac () == true ) | 1200 if ( GetDac () == true ) |
1263 { | 1201 { |
1264 PostProcessDac (); | 1202 PostProcessDac (); |
1265 } | 1203 } |
1266 return GetSerializedSize (); | 1204 return GetSerializedSize (); |
1267 } | 1205 } |
1268 | 1206 |
1269 SixLowPanDispatch::Dispatch_e | |
1270 SixLowPanIphc::GetDispatchType (void) const | |
1271 { | |
1272 return LOWPAN_IPHC; | |
1273 } | |
1274 | |
1275 void SixLowPanIphc::SetTf (TrafficClassFlowLabel_e tfField) | 1207 void SixLowPanIphc::SetTf (TrafficClassFlowLabel_e tfField) |
1276 { | 1208 { |
1277 uint16_t field = tfField; | 1209 uint16_t field = tfField; |
1278 m_baseFormat |= (field << 11); | 1210 m_baseFormat |= (field << 11); |
1279 } | 1211 } |
1280 | 1212 |
1281 SixLowPanIphc::TrafficClassFlowLabel_e SixLowPanIphc::GetTf (void) const | 1213 SixLowPanIphc::TrafficClassFlowLabel_e SixLowPanIphc::GetTf (void) const |
1282 { | 1214 { |
1283 return TrafficClassFlowLabel_e ((m_baseFormat >> 11) & 0x3); | 1215 return TrafficClassFlowLabel_e ((m_baseFormat >> 11) & 0x3); |
1284 } | 1216 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 | 1412 |
1481 std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h) | 1413 std::ostream & operator << (std::ostream & os, const SixLowPanIphc & h) |
1482 { | 1414 { |
1483 h.Print (os); | 1415 h.Print (os); |
1484 return os; | 1416 return os; |
1485 } | 1417 } |
1486 | 1418 |
1487 /* | 1419 /* |
1488 * SixLowPanNhcExtensionHeader | 1420 * SixLowPanNhcExtensionHeader |
1489 */ | 1421 */ |
1490 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension); | 1422 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNhcExtension) |
| 1423 ; |
1491 | 1424 |
1492 SixLowPanNhcExtension::SixLowPanNhcExtension () | 1425 SixLowPanNhcExtension::SixLowPanNhcExtension () |
1493 { | 1426 { |
1494 // 1110 xxxx | 1427 // 1110 xxxx |
1495 m_nhcExtensionHeader = 0xE0; | 1428 m_nhcExtensionHeader = 0xE0; |
| 1429 m_nhcNextHeader = 0; |
| 1430 m_nhcBlobLength = 0; |
1496 } | 1431 } |
1497 | 1432 |
1498 TypeId SixLowPanNhcExtension::GetTypeId (void) | 1433 TypeId SixLowPanNhcExtension::GetTypeId (void) |
1499 { | 1434 { |
1500 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanNhcExtension") | 1435 static TypeId tid = TypeId ("ns3::SixLowPanNhcExtension") |
1501 .SetParent<Header> () | 1436 .SetParent<Header> () |
1502 .AddConstructor<SixLowPanNhcExtension> (); | 1437 .AddConstructor<SixLowPanNhcExtension> (); |
1503 return tid; | 1438 return tid; |
1504 } | 1439 } |
1505 | 1440 |
1506 TypeId SixLowPanNhcExtension::GetInstanceTypeId (void) const | 1441 TypeId SixLowPanNhcExtension::GetInstanceTypeId (void) const |
1507 { | 1442 { |
1508 return GetTypeId (); | 1443 return GetTypeId (); |
1509 } | 1444 } |
1510 | 1445 |
1511 void SixLowPanNhcExtension::Print (std::ostream & os) const | 1446 void SixLowPanNhcExtension::Print (std::ostream & os) const |
1512 { | 1447 { |
1513 os << "Compression kind: " << uint8_t (m_nhcExtensionHeader); | 1448 os << "Compression kind: " << int (m_nhcExtensionHeader) << " Size: " << int(G
etSerializedSize ()); |
1514 } | 1449 } |
1515 | 1450 |
1516 uint32_t SixLowPanNhcExtension::GetSerializedSize () const | 1451 uint32_t SixLowPanNhcExtension::GetSerializedSize () const |
1517 { | 1452 { |
1518 uint32_t serializedSize = 1; | 1453 uint32_t serializedSize = 2; |
1519 if ( m_nhcExtensionHeader & 0x1 ) | 1454 if ( GetNh () == false ) |
1520 { | 1455 { |
1521 serializedSize++; | 1456 serializedSize++; |
1522 } | 1457 } |
1523 return serializedSize; | 1458 return serializedSize + m_nhcBlobLength; |
1524 } | 1459 } |
1525 | 1460 |
1526 void SixLowPanNhcExtension::Serialize (Buffer::Iterator start) const | 1461 void SixLowPanNhcExtension::Serialize (Buffer::Iterator start) const |
1527 { | 1462 { |
1528 Buffer::Iterator i = start; | 1463 Buffer::Iterator i = start; |
1529 i.WriteU8 (m_nhcExtensionHeader); | 1464 i.WriteU8 (m_nhcExtensionHeader); |
1530 if ( m_nhcExtensionHeader & 0x1 ) | 1465 if ( GetNh () == false ) |
1531 { | 1466 { |
1532 i.WriteU8 (m_nhcNextHeader); | 1467 i.WriteU8 (m_nhcNextHeader); |
1533 } | 1468 } |
| 1469 i.WriteU8 (m_nhcBlobLength); |
| 1470 i.Write (m_nhcBlob, m_nhcBlobLength); |
1534 } | 1471 } |
1535 | 1472 |
1536 uint32_t SixLowPanNhcExtension::Deserialize (Buffer::Iterator start) | 1473 uint32_t SixLowPanNhcExtension::Deserialize (Buffer::Iterator start) |
1537 { | 1474 { |
1538 Buffer::Iterator i = start; | 1475 Buffer::Iterator i = start; |
1539 m_nhcExtensionHeader = i.ReadU8 (); | 1476 m_nhcExtensionHeader = i.ReadU8 (); |
1540 if ( m_nhcExtensionHeader & 0x1 ) | 1477 if ( GetNh () == false ) |
1541 { | 1478 { |
1542 m_nhcNextHeader = i.ReadU8 (); | 1479 m_nhcNextHeader = i.ReadU8 (); |
1543 } | 1480 } |
| 1481 m_nhcBlobLength = i.ReadU8 (); |
| 1482 i.Read (m_nhcBlob, m_nhcBlobLength); |
1544 | 1483 |
1545 return GetSerializedSize (); | 1484 return GetSerializedSize (); |
1546 } | 1485 } |
1547 | 1486 |
1548 SixLowPanDispatch::NhcDispatch_e | 1487 SixLowPanDispatch::NhcDispatch_e |
1549 SixLowPanNhcExtension::GetNhcDispatchType (void) const | 1488 SixLowPanNhcExtension::GetNhcDispatchType (void) const |
1550 { | 1489 { |
1551 return LOWPAN_NHC; | 1490 return SixLowPanDispatch::LOWPAN_NHC; |
1552 } | 1491 } |
1553 | 1492 |
1554 void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType) | 1493 void SixLowPanNhcExtension::SetEid (Eid_e extensionHeaderType) |
1555 { | 1494 { |
1556 uint8_t field = extensionHeaderType; | 1495 uint8_t field = extensionHeaderType; |
1557 m_nhcExtensionHeader |= (field << 1); | 1496 m_nhcExtensionHeader |= (field << 1); |
1558 } | 1497 } |
1559 | 1498 |
1560 SixLowPanNhcExtension::Eid_e SixLowPanNhcExtension::GetEid (void) const | 1499 SixLowPanNhcExtension::Eid_e SixLowPanNhcExtension::GetEid (void) const |
1561 { | 1500 { |
(...skipping 11 matching lines...) Expand all Loading... |
1573 } | 1512 } |
1574 | 1513 |
1575 void SixLowPanNhcExtension::SetNh (bool nhField) | 1514 void SixLowPanNhcExtension::SetNh (bool nhField) |
1576 { | 1515 { |
1577 uint8_t field = nhField; | 1516 uint8_t field = nhField; |
1578 m_nhcExtensionHeader |= field; | 1517 m_nhcExtensionHeader |= field; |
1579 } | 1518 } |
1580 | 1519 |
1581 bool SixLowPanNhcExtension::GetNh (void) const | 1520 bool SixLowPanNhcExtension::GetNh (void) const |
1582 { | 1521 { |
1583 return m_nhcNextHeader & 0x01; | 1522 return m_nhcExtensionHeader & 0x01; |
| 1523 } |
| 1524 |
| 1525 void SixLowPanNhcExtension::SetBlob (const uint8_t* blob, uint32_t size) |
| 1526 { |
| 1527 NS_ASSERT_MSG ( size < 255, "Buffer too long" ); |
| 1528 |
| 1529 m_nhcBlobLength = size; |
| 1530 std::memcpy (m_nhcBlob, blob, size); |
| 1531 } |
| 1532 |
| 1533 uint32_t SixLowPanNhcExtension::CopyBlob (uint8_t* blob, uint32_t size) const |
| 1534 { |
| 1535 NS_ASSERT_MSG ( size > m_nhcBlobLength, "Buffer too short" ); |
| 1536 |
| 1537 std::memcpy (blob, m_nhcBlob, m_nhcBlobLength); |
| 1538 return m_nhcBlobLength; |
| 1539 } |
| 1540 |
| 1541 std::ostream & operator << (std::ostream & os, const SixLowPanNhcExtension & h) |
| 1542 { |
| 1543 h.Print (os); |
| 1544 return os; |
1584 } | 1545 } |
1585 | 1546 |
1586 /* | 1547 /* |
1587 * SixLowPanUdpNhcExtension | 1548 * SixLowPanUdpNhcExtension |
1588 */ | 1549 */ |
1589 NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension); | 1550 NS_OBJECT_ENSURE_REGISTERED (SixLowPanUdpNhcExtension) |
| 1551 ; |
1590 | 1552 |
1591 SixLowPanUdpNhcExtension::SixLowPanUdpNhcExtension () | 1553 SixLowPanUdpNhcExtension::SixLowPanUdpNhcExtension () |
1592 { | 1554 { |
1593 // 1111 0xxx | 1555 // 1111 0xxx |
1594 m_baseFormat = 0xF0; | 1556 m_baseFormat = 0xF0; |
1595 m_checksum = 0; | 1557 m_checksum = 0; |
| 1558 m_srcPort = 0; |
| 1559 m_dstPort = 0; |
1596 } | 1560 } |
1597 | 1561 |
1598 TypeId SixLowPanUdpNhcExtension::GetTypeId (void) | 1562 TypeId SixLowPanUdpNhcExtension::GetTypeId (void) |
1599 { | 1563 { |
1600 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanUdpNhcExtension") | 1564 static TypeId tid = TypeId ("ns3::SixLowPanUdpNhcExtension") |
1601 .SetParent<Header> () | 1565 .SetParent<Header> () |
1602 .AddConstructor<SixLowPanUdpNhcExtension> (); | 1566 .AddConstructor<SixLowPanUdpNhcExtension> (); |
1603 return tid; | 1567 return tid; |
1604 } | 1568 } |
1605 | 1569 |
1606 TypeId SixLowPanUdpNhcExtension::GetInstanceTypeId (void) const | 1570 TypeId SixLowPanUdpNhcExtension::GetInstanceTypeId (void) const |
1607 { | 1571 { |
1608 return GetTypeId (); | 1572 return GetTypeId (); |
1609 } | 1573 } |
1610 | 1574 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 { | 1674 { |
1711 m_checksum = i.ReadU16 (); | 1675 m_checksum = i.ReadU16 (); |
1712 } | 1676 } |
1713 | 1677 |
1714 return GetSerializedSize (); | 1678 return GetSerializedSize (); |
1715 } | 1679 } |
1716 | 1680 |
1717 SixLowPanDispatch::NhcDispatch_e | 1681 SixLowPanDispatch::NhcDispatch_e |
1718 SixLowPanUdpNhcExtension::GetNhcDispatchType (void) const | 1682 SixLowPanUdpNhcExtension::GetNhcDispatchType (void) const |
1719 { | 1683 { |
1720 return LOWPAN_UDPNHC; | 1684 return SixLowPanDispatch::LOWPAN_UDPNHC; |
1721 } | 1685 } |
1722 | 1686 |
1723 void SixLowPanUdpNhcExtension::SetPorts (Ports_e ports) | 1687 void SixLowPanUdpNhcExtension::SetPorts (Ports_e ports) |
1724 { | 1688 { |
1725 uint16_t field = ports; | 1689 uint16_t field = ports; |
1726 m_baseFormat |= field; | 1690 m_baseFormat |= field; |
1727 } | 1691 } |
1728 | 1692 |
1729 SixLowPanUdpNhcExtension::Ports_e SixLowPanUdpNhcExtension::GetPorts (void) cons
t | 1693 SixLowPanUdpNhcExtension::Ports_e SixLowPanUdpNhcExtension::GetPorts (void) cons
t |
1730 { | 1694 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 void SixLowPanUdpNhcExtension::SetChecksum (uint16_t checksum) | 1729 void SixLowPanUdpNhcExtension::SetChecksum (uint16_t checksum) |
1766 { | 1730 { |
1767 m_checksum = checksum; | 1731 m_checksum = checksum; |
1768 } | 1732 } |
1769 | 1733 |
1770 uint16_t SixLowPanUdpNhcExtension::GetChecksum (void) const | 1734 uint16_t SixLowPanUdpNhcExtension::GetChecksum (void) const |
1771 { | 1735 { |
1772 return m_checksum; | 1736 return m_checksum; |
1773 } | 1737 } |
1774 | 1738 |
1775 } | 1739 std::ostream & operator << (std::ostream & os, const SixLowPanUdpNhcExtension &
h) |
1776 } | 1740 { |
| 1741 h.Print (os); |
| 1742 return os; |
| 1743 } |
| 1744 |
| 1745 |
| 1746 } |
| 1747 |
LEFT | RIGHT |