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) 2013 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 |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "ns3/mac48-address.h" | 34 #include "ns3/mac48-address.h" |
35 #include "ns3/mac64-address.h" | 35 #include "ns3/mac64-address.h" |
36 #include "ns3/unused.h" | 36 #include "ns3/unused.h" |
37 #include "ns3/ipv6-l3-protocol.h" | 37 #include "ns3/ipv6-l3-protocol.h" |
38 #include "ns3/ipv6-extension-header.h" | 38 #include "ns3/ipv6-extension-header.h" |
39 #include "ns3/udp-header.h" | 39 #include "ns3/udp-header.h" |
40 #include "ns3/udp-l4-protocol.h" | 40 #include "ns3/udp-l4-protocol.h" |
41 #include "sixlowpan-net-device.h" | 41 #include "sixlowpan-net-device.h" |
42 #include "sixlowpan-header.h" | 42 #include "sixlowpan-header.h" |
43 | 43 |
44 NS_LOG_COMPONENT_DEFINE ("SixLowPanNetDevice"); | 44 NS_LOG_COMPONENT_DEFINE ("SixLowPanNetDevice") |
| 45 ; |
45 | 46 |
46 namespace ns3 { | 47 namespace ns3 { |
47 namespace sixlowpan { | 48 |
48 | 49 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNetDevice) |
49 NS_OBJECT_ENSURE_REGISTERED (SixLowPanNetDevice); | 50 ; |
50 | 51 |
51 TypeId SixLowPanNetDevice::GetTypeId (void) | 52 TypeId SixLowPanNetDevice::GetTypeId (void) |
52 { | 53 { |
53 static TypeId tid = TypeId ("ns3::sixlowpan::SixLowPanNetDevice") | 54 static TypeId tid = TypeId ("ns3::SixLowPanNetDevice") |
54 .SetParent<NetDevice> () | 55 .SetParent<NetDevice> () |
55 .AddConstructor<SixLowPanNetDevice> () | 56 .AddConstructor<SixLowPanNetDevice> () |
56 .AddAttribute ("Rfc6282", "Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwi
se.", | 57 .AddAttribute ("Rfc6282", "Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwi
se.", |
57 BooleanValue (true), | 58 BooleanValue (true), |
58 MakeBooleanAccessor (&SixLowPanNetDevice::m_useIphc), | 59 MakeBooleanAccessor (&SixLowPanNetDevice::m_useIphc), |
59 MakeBooleanChecker ()) | 60 MakeBooleanChecker ()) |
60 .AddAttribute ("OmitUdpCecksum", | 61 .AddAttribute ("OmitUdpChecksum", |
61 "Omit the UDP checksum in IPHC compression.", | 62 "Omit the UDP checksum in IPHC compression.", |
62 BooleanValue (true), | 63 BooleanValue (true), |
63 MakeBooleanAccessor (&SixLowPanNetDevice::m_omitUdpChecksum), | 64 MakeBooleanAccessor (&SixLowPanNetDevice::m_omitUdpChecksum), |
64 MakeBooleanChecker ()) | 65 MakeBooleanChecker ()) |
65 .AddAttribute ("FragmentReassemblyListSize", "The maximum size of the reasse
mbly buffer (in packets). Zero meaning infinite.", | 66 .AddAttribute ("FragmentReassemblyListSize", "The maximum size of the reasse
mbly buffer (in packets). Zero meaning infinite.", |
66 UintegerValue (0), | 67 UintegerValue (0), |
67 MakeUintegerAccessor (&SixLowPanNetDevice::m_fragmentReassemb
lyListSize), | 68 MakeUintegerAccessor (&SixLowPanNetDevice::m_fragmentReassemb
lyListSize), |
68 MakeUintegerChecker<uint16_t> ()) | 69 MakeUintegerChecker<uint16_t> ()) |
69 .AddAttribute ("FragmentExpirationTimeout", | 70 .AddAttribute ("FragmentExpirationTimeout", |
70 "When this timeout expires, the fragments will be cleared fro
m the buffer.", | 71 "When this timeout expires, the fragments will be cleared fro
m the buffer.", |
71 TimeValue (Seconds (60)), | 72 TimeValue (Seconds (60)), |
72 MakeTimeAccessor (&SixLowPanNetDevice::m_fragmentExpirationTi
meout), | 73 MakeTimeAccessor (&SixLowPanNetDevice::m_fragmentExpirationTi
meout), |
73 MakeTimeChecker ()) | 74 MakeTimeChecker ()) |
74 .AddAttribute ("ForceEtherType", | 75 .AddAttribute ("ForceEtherType", |
75 "Force a specific EtherType in L2 frames.", | 76 "Force a specific EtherType in L2 frames.", |
76 BooleanValue (false), | 77 BooleanValue (false), |
77 MakeBooleanAccessor (&SixLowPanNetDevice::m_forceEtherType), | 78 MakeBooleanAccessor (&SixLowPanNetDevice::m_forceEtherType), |
78 MakeBooleanChecker ()) | 79 MakeBooleanChecker ()) |
79 .AddAttribute ("EtherType", | 80 .AddAttribute ("EtherType", |
80 "The specific EtherType to be used in L2 frames.", | 81 "The specific EtherType to be used in L2 frames.", |
81 UintegerValue (0xFFFF), | 82 UintegerValue (0xFFFF), |
82 MakeUintegerAccessor (&SixLowPanNetDevice::m_etherType), | 83 MakeUintegerAccessor (&SixLowPanNetDevice::m_etherType), |
83 MakeUintegerChecker<uint16_t> ()) | 84 MakeUintegerChecker<uint16_t> ()) |
84 .AddTraceSource ("Tx", "Send ipv6 packet to outgoing interface.", | 85 .AddTraceSource ("Tx", "Send - packet (including 6LoWPAN header), SixLoWPanN
etDevice Ptr, interface index.", |
85 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_txTrace)) | 86 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_txTrace)) |
86 .AddTraceSource ("Rx", "Receive ipv6 packet from incoming interface.", | 87 .AddTraceSource ("Rx", "Receive - packet (including 6LoWPAN header), SixLoWP
anNetDevice Ptr, interface index.", |
87 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_rxTrace)) | 88 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_rxTrace)) |
88 .AddTraceSource ("Drop", "Drop ipv6 packet", | 89 .AddTraceSource ("Drop", "Drop - DropReason, packet (including 6LoWPAN heade
r), SixLoWPanNetDevice Ptr, interface index.", |
89 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_dropTrace)) | 90 MakeTraceSourceAccessor (&SixLowPanNetDevice::m_dropTrace)) |
90 ; | 91 ; |
91 return tid; | 92 return tid; |
92 } | 93 } |
93 | 94 |
94 SixLowPanNetDevice::SixLowPanNetDevice () | 95 SixLowPanNetDevice::SixLowPanNetDevice () |
95 : m_node (0), | 96 : m_node (0), |
96 m_netDevice (0), | 97 m_netDevice (0), |
97 m_ifIndex (0) | 98 m_ifIndex (0) |
98 { | 99 { |
99 NS_LOG_FUNCTION (this); | 100 NS_LOG_FUNCTION (this); |
100 m_netDevice = 0; | 101 m_netDevice = 0; |
| 102 m_rng = CreateObject<UniformRandomVariable> (); |
101 } | 103 } |
102 | 104 |
103 Ptr<NetDevice> SixLowPanNetDevice::GetNetDevice () const | 105 Ptr<NetDevice> SixLowPanNetDevice::GetNetDevice () const |
104 { | 106 { |
105 NS_LOG_FUNCTION (this); | 107 NS_LOG_FUNCTION (this); |
106 return m_netDevice; | 108 return m_netDevice; |
107 } | 109 } |
108 | 110 |
109 void SixLowPanNetDevice::SetNetDevice (Ptr<NetDevice> device) | 111 void SixLowPanNetDevice::SetNetDevice (Ptr<NetDevice> device) |
110 { | 112 { |
111 NS_LOG_FUNCTION (this << device); | 113 NS_LOG_FUNCTION (this << device); |
112 m_netDevice = device; | 114 m_netDevice = device; |
113 | 115 |
114 NS_LOG_DEBUG ("RegisterProtocolHandler for " << device->GetInstanceTypeId ().G
etName ()); | 116 NS_LOG_DEBUG ("RegisterProtocolHandler for " << device->GetInstanceTypeId ().G
etName ()); |
115 | 117 |
116 uint16_t protocolType = 0; | 118 uint16_t protocolType = 0; |
117 if ( m_forceEtherType ) | 119 if ( m_forceEtherType ) |
118 { | 120 { |
119 protocolType = m_etherType; | 121 protocolType = m_etherType; |
120 } | 122 } |
121 m_node->RegisterProtocolHandler (MakeCallback (&SixLowPanNetDevice::ReceiveFro
mDevice, | 123 m_node->RegisterProtocolHandler (MakeCallback (&SixLowPanNetDevice::ReceiveFro
mDevice, |
122 this), | 124 this), |
123 protocolType, device, false); | 125 protocolType, device, false); |
124 } | 126 } |
125 | 127 |
| 128 int64_t SixLowPanNetDevice::AssignStreams (int64_t stream) |
| 129 { |
| 130 NS_LOG_FUNCTION (this << stream); |
| 131 m_rng->SetStream (stream); |
| 132 return 1; |
| 133 } |
| 134 |
126 void SixLowPanNetDevice::DoDispose () | 135 void SixLowPanNetDevice::DoDispose () |
127 { | 136 { |
128 NS_LOG_FUNCTION (this); | 137 NS_LOG_FUNCTION (this); |
129 | 138 |
130 m_netDevice = 0; | 139 m_netDevice = 0; |
131 m_node = 0; | 140 m_node = 0; |
132 | 141 |
133 for (MapFragmentsTimersI_t iter = m_fragmentsTimers.begin(); iter != m_fragmen
tsTimers.end(); iter ++) | 142 for (MapFragmentsTimersI_t iter = m_fragmentsTimers.begin (); iter != m_fragme
ntsTimers.end (); iter++) |
134 { | 143 { |
135 iter->second.Cancel (); | 144 iter->second.Cancel (); |
136 } | 145 } |
137 m_fragmentsTimers.clear (); | 146 m_fragmentsTimers.clear (); |
138 | 147 |
139 for (MapFragmentsI_t iter = m_fragments.begin(); iter != m_fragments.end(); it
er ++) | 148 for (MapFragmentsI_t iter = m_fragments.begin (); iter != m_fragments.end ();
iter++) |
140 { | 149 { |
141 iter->second = 0; | 150 iter->second = 0; |
142 } | 151 } |
143 m_fragments.clear (); | 152 m_fragments.clear (); |
144 | 153 |
145 NetDevice::DoDispose (); | 154 NetDevice::DoDispose (); |
146 } | 155 } |
147 | 156 |
148 void SixLowPanNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, | 157 void SixLowPanNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, |
149 Ptr<const Packet> packet, | 158 Ptr<const Packet> packet, |
150 uint16_t protocol, | 159 uint16_t protocol, |
151 Address const &src, | 160 Address const &src, |
152 Address const &dst, | 161 Address const &dst, |
153 PacketType packetType) | 162 PacketType packetType) |
154 { | 163 { |
155 NS_LOG_FUNCTION (this << incomingPort << packet << protocol << src << dst); | 164 NS_LOG_FUNCTION (this << incomingPort << packet << protocol << src << dst); |
156 NS_LOG_DEBUG ("UID is " << packet->GetUid ()); | 165 NS_LOG_DEBUG ("UID is " << packet->GetUid ()); |
157 | 166 |
158 uint8_t dispatchRawVal = 0; | 167 uint8_t dispatchRawVal = 0; |
159 SixLowPanDispatch::Dispatch_e dispatchVal; | 168 SixLowPanDispatch::Dispatch_e dispatchVal; |
160 Ptr<Packet> copyPkt = packet->Copy (); | 169 Ptr<Packet> copyPkt = packet->Copy (); |
161 | 170 |
| 171 m_rxTrace (copyPkt, m_node->GetObject<SixLowPanNetDevice> (), GetIfIndex ()); |
| 172 |
162 copyPkt->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); | 173 copyPkt->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
163 dispatchVal = SixLowPanDispatch::GetDispatchType (dispatchRawVal); | 174 dispatchVal = SixLowPanDispatch::GetDispatchType (dispatchRawVal); |
164 bool isPktDecompressed = false; | 175 bool isPktDecompressed = false; |
165 bool fragmented = false; | 176 bool fragmented = false; |
166 | 177 |
167 NS_LOG_DEBUG ( "Packet received: " << *copyPkt ); | 178 NS_LOG_DEBUG ( "Packet received: " << *copyPkt ); |
168 NS_LOG_DEBUG ( "Packet length: " << copyPkt->GetSize () ); | 179 NS_LOG_DEBUG ( "Packet length: " << copyPkt->GetSize () ); |
169 NS_LOG_DEBUG ( "Dispatches: " << int(dispatchRawVal) << " - " << int(dispatchV
al) ); | 180 NS_LOG_DEBUG ( "Dispatches: " << int(dispatchRawVal) << " - " << int(dispatchV
al) ); |
170 | 181 |
171 if ( dispatchVal == SixLowPanDispatch::LOWPAN_FRAG1 ) | 182 if ( dispatchVal == SixLowPanDispatch::LOWPAN_FRAG1 ) |
(...skipping 13 matching lines...) Expand all Loading... |
185 return; | 196 return; |
186 } | 197 } |
187 else | 198 else |
188 { | 199 { |
189 copyPkt->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); | 200 copyPkt->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
190 dispatchVal = SixLowPanDispatch::GetDispatchType (dispatchRawVal); | 201 dispatchVal = SixLowPanDispatch::GetDispatchType (dispatchRawVal); |
191 } | 202 } |
192 } | 203 } |
193 | 204 |
194 switch ( dispatchVal ) | 205 switch ( dispatchVal ) |
195 { | 206 { |
196 case SixLowPanDispatch::LOWPAN_MESH: | 207 case SixLowPanDispatch::LOWPAN_MESH: |
197 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: MESH, dropping."); | 208 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: MESH, dropping."); |
198 m_dropTrace (DROP_UNKNOWN_EXTENSION, m_node->GetObject<SixLowPanNetDevice>
(), GetIfIndex()); | 209 m_dropTrace (DROP_UNKNOWN_EXTENSION, copyPkt, m_node->GetObject<SixLowPanN
etDevice> (), GetIfIndex ()); |
199 break; | 210 break; |
200 case SixLowPanDispatch::LOWPAN_BC0: | 211 case SixLowPanDispatch::LOWPAN_BC0: |
201 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: BC0, dropping."); | 212 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: BC0, dropping."); |
202 m_dropTrace (DROP_UNKNOWN_EXTENSION, m_node->GetObject<SixLowPanNetDevice>
(), GetIfIndex()); | 213 m_dropTrace (DROP_UNKNOWN_EXTENSION, copyPkt, m_node->GetObject<SixLowPanN
etDevice> (), GetIfIndex ()); |
203 break; | 214 break; |
204 case SixLowPanDispatch::LOWPAN_NOTCOMPRESSED: | 215 case SixLowPanDispatch::LOWPAN_NOTCOMPRESSED: |
205 NS_LOG_DEBUG ( "Packet without compression:" << *copyPkt ); | 216 NS_LOG_DEBUG ( "Packet without compression:" << *copyPkt ); |
206 NS_LOG_DEBUG ( "Packet length:" << copyPkt->GetSize () ); | 217 NS_LOG_DEBUG ( "Packet length:" << copyPkt->GetSize () ); |
207 m_dropTrace (DROP_UNKNOWN_EXTENSION, m_node->GetObject<SixLowPanNetDevice>
(), GetIfIndex()); | 218 m_dropTrace (DROP_UNKNOWN_EXTENSION, copyPkt, m_node->GetObject<SixLowPanN
etDevice> (), GetIfIndex ()); |
208 break; | 219 break; |
209 case SixLowPanDispatch::LOWPAN_HC1: | 220 case SixLowPanDispatch::LOWPAN_HC1: |
210 DecompressLowPanHc1 (copyPkt, src, dst); | 221 DecompressLowPanHc1 (copyPkt, src, dst); |
211 isPktDecompressed = true; | 222 isPktDecompressed = true; |
212 break; | 223 break; |
213 case SixLowPanDispatch::LOWPAN_IPHC: | 224 case SixLowPanDispatch::LOWPAN_IPHC: |
214 DecompressLowPanIphc (copyPkt, src, dst); | 225 DecompressLowPanIphc (copyPkt, src, dst); |
215 isPktDecompressed = true; | 226 isPktDecompressed = true; |
216 break; | 227 break; |
217 default: | 228 default: |
218 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: dropping."); | 229 NS_LOG_DEBUG ("Unsupported 6LoWPAN encoding: dropping."); |
219 m_dropTrace (DROP_UNKNOWN_EXTENSION, m_node->GetObject<SixLowPanNetDevice>
(), GetIfIndex()); | 230 m_dropTrace (DROP_UNKNOWN_EXTENSION, copyPkt, m_node->GetObject<SixLowPanN
etDevice> (), GetIfIndex ()); |
220 break; | 231 break; |
221 } | 232 } |
222 | 233 |
223 if ( !isPktDecompressed ) | 234 if ( !isPktDecompressed ) |
224 { | 235 { |
225 return; | 236 return; |
226 } | 237 } |
227 | 238 |
228 NS_LOG_DEBUG ( "Packet decompressed length: " << copyPkt->GetSize () ); | 239 NS_LOG_DEBUG ( "Packet decompressed length: " << copyPkt->GetSize () ); |
229 NS_LOG_DEBUG ( "Packet decompressed received: " << *copyPkt ); | 240 NS_LOG_DEBUG ( "Packet decompressed received: " << *copyPkt ); |
230 | 241 |
231 if (!m_promiscRxCallback.IsNull ()) | 242 if (!m_promiscRxCallback.IsNull ()) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 { | 410 { |
400 NS_LOG_LOGIC ("Fragmentation: Packet size " << packet->GetSize () << " - M
tu " << m_netDevice->GetMtu () ); | 411 NS_LOG_LOGIC ("Fragmentation: Packet size " << packet->GetSize () << " - M
tu " << m_netDevice->GetMtu () ); |
401 // fragment | 412 // fragment |
402 std::list<Ptr<Packet> > fragmentList; | 413 std::list<Ptr<Packet> > fragmentList; |
403 DoFragmentation (packet, origPacketSize, origHdrSize, fragmentList); | 414 DoFragmentation (packet, origPacketSize, origHdrSize, fragmentList); |
404 std::list<Ptr<Packet> >::iterator it; | 415 std::list<Ptr<Packet> >::iterator it; |
405 bool success = true; | 416 bool success = true; |
406 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ ) | 417 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ ) |
407 { | 418 { |
408 NS_LOG_DEBUG ( "SixLowPanNetDevice::Send (Fragment) " << **it ); | 419 NS_LOG_DEBUG ( "SixLowPanNetDevice::Send (Fragment) " << **it ); |
| 420 m_txTrace (*it, m_node->GetObject<SixLowPanNetDevice> (), GetIfIndex (
)); |
409 success &= m_netDevice->Send (*it, dest, protocolNumber); | 421 success &= m_netDevice->Send (*it, dest, protocolNumber); |
410 } | 422 } |
411 ret = success; | 423 ret = success; |
412 } | 424 } |
413 else | 425 else |
414 { | 426 { |
415 NS_LOG_DEBUG ( "SixLowPanNetDevice::Send " << m_node->GetId () << " " << *
packet ); | 427 NS_LOG_DEBUG ( "SixLowPanNetDevice::Send " << m_node->GetId () << " " << *
packet ); |
| 428 m_txTrace (packet, m_node->GetObject<SixLowPanNetDevice> (), GetIfIndex ()
); |
416 ret = m_netDevice->Send (packet, dest, protocolNumber); | 429 ret = m_netDevice->Send (packet, dest, protocolNumber); |
417 } | 430 } |
418 | 431 |
419 return ret; | 432 return ret; |
420 } | 433 } |
421 | 434 |
422 bool SixLowPanNetDevice::SendFrom (Ptr<Packet> packet, | 435 bool SixLowPanNetDevice::SendFrom (Ptr<Packet> packet, |
423 const Address& src, | 436 const Address& src, |
424 const Address& dest, | 437 const Address& dest, |
425 uint16_t protocolNumber) | 438 uint16_t protocolNumber) |
(...skipping 22 matching lines...) Expand all Loading... |
448 if ( packet->GetSize () > m_netDevice->GetMtu () ) | 461 if ( packet->GetSize () > m_netDevice->GetMtu () ) |
449 { | 462 { |
450 // fragment | 463 // fragment |
451 std::list<Ptr<Packet> > fragmentList; | 464 std::list<Ptr<Packet> > fragmentList; |
452 DoFragmentation (packet, origPacketSize, origHdrSize, fragmentList); | 465 DoFragmentation (packet, origPacketSize, origHdrSize, fragmentList); |
453 std::list<Ptr<Packet> >::iterator it; | 466 std::list<Ptr<Packet> >::iterator it; |
454 bool err = false; | 467 bool err = false; |
455 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ ) | 468 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ ) |
456 { | 469 { |
457 NS_LOG_DEBUG ( "SixLowPanNetDevice::SendFrom (Fragment) " << **it ); | 470 NS_LOG_DEBUG ( "SixLowPanNetDevice::SendFrom (Fragment) " << **it ); |
| 471 m_txTrace (*it, m_node->GetObject<SixLowPanNetDevice> (), GetIfIndex (
)); |
458 err |= !(m_netDevice->SendFrom (*it, src, dest, protocolNumber)); | 472 err |= !(m_netDevice->SendFrom (*it, src, dest, protocolNumber)); |
459 } | 473 } |
460 ret = !err; | 474 ret = !err; |
461 } | 475 } |
462 else | 476 else |
463 { | 477 { |
464 NS_LOG_DEBUG ( "SixLowPanNetDevice::SendFrom " << *packet ); | 478 NS_LOG_DEBUG ( "SixLowPanNetDevice::SendFrom " << *packet ); |
| 479 m_txTrace (packet, m_node->GetObject<SixLowPanNetDevice> (), GetIfIndex ()
); |
465 ret = m_netDevice->SendFrom (packet, src, dest, protocolNumber); | 480 ret = m_netDevice->SendFrom (packet, src, dest, protocolNumber); |
466 } | 481 } |
467 | 482 |
468 return ret; | 483 return ret; |
469 } | 484 } |
470 | 485 |
471 Ptr<Node> SixLowPanNetDevice::GetNode (void) const | 486 Ptr<Node> SixLowPanNetDevice::GetNode (void) const |
472 { | 487 { |
473 NS_LOG_FUNCTION (this); | 488 NS_LOG_FUNCTION (this); |
474 return m_node; | 489 return m_node; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 iphcHeader.SetDscp ( ipHeader.GetTrafficClass () & 0x3F ); | 778 iphcHeader.SetDscp ( ipHeader.GetTrafficClass () & 0x3F ); |
764 } | 779 } |
765 else | 780 else |
766 { | 781 { |
767 iphcHeader.SetTf (SixLowPanIphc::TF_DSCP_ELIDED); | 782 iphcHeader.SetTf (SixLowPanIphc::TF_DSCP_ELIDED); |
768 iphcHeader.SetEcn ( (ipHeader.GetTrafficClass () & 0xC0) >> 6); | 783 iphcHeader.SetEcn ( (ipHeader.GetTrafficClass () & 0xC0) >> 6); |
769 iphcHeader.SetFlowLabel (ipHeader.GetFlowLabel ()); | 784 iphcHeader.SetFlowLabel (ipHeader.GetFlowLabel ()); |
770 } | 785 } |
771 | 786 |
772 // Set the NH field and NextHeader | 787 // Set the NH field and NextHeader |
| 788 |
773 uint8_t nextHeader = ipHeader.GetNextHeader (); | 789 uint8_t nextHeader = ipHeader.GetNextHeader (); |
774 if (nextHeader == Ipv6Header::IPV6_UDP) | 790 if (CanCompressLowPanNhc (nextHeader)) |
775 { | 791 { |
776 iphcHeader.SetNh (true); | 792 if (nextHeader == Ipv6Header::IPV6_UDP) |
777 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); | |
778 } | |
779 else | |
780 { | |
781 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader); | |
782 if (sizeNhc != 0) | |
783 { | 793 { |
784 iphcHeader.SetNh (true); | 794 iphcHeader.SetNh (true); |
785 size += sizeNhc; | 795 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); |
| 796 } |
| 797 else if (nextHeader == Ipv6Header::IPV6_IPV6) |
| 798 { |
| 799 iphcHeader.SetNh (true); |
| 800 size += CompressLowPanIphc (packet, src, dst); |
786 } | 801 } |
787 else | 802 else |
788 { | 803 { |
789 iphcHeader.SetNh (false); | 804 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader, src, dst
); |
790 iphcHeader.SetNextHeader (nextHeader); | 805 // the compression might fail due to Extension header size. |
791 } | 806 if (sizeNhc) |
792 } | 807 { |
| 808 iphcHeader.SetNh (true); |
| 809 size += sizeNhc; |
| 810 } |
| 811 else |
| 812 { |
| 813 iphcHeader.SetNh (false); |
| 814 iphcHeader.SetNextHeader (nextHeader); |
| 815 } |
| 816 } |
| 817 } |
| 818 else |
| 819 { |
| 820 iphcHeader.SetNh (false); |
| 821 iphcHeader.SetNextHeader (nextHeader); |
| 822 } |
| 823 |
793 | 824 |
794 // Set the HLIM field | 825 // Set the HLIM field |
795 if (ipHeader.GetHopLimit () == 1) | 826 if (ipHeader.GetHopLimit () == 1) |
796 { | 827 { |
797 iphcHeader.SetHlim (SixLowPanIphc::HLIM_COMPR_1); | 828 iphcHeader.SetHlim (SixLowPanIphc::HLIM_COMPR_1); |
798 } | 829 } |
799 else if (ipHeader.GetHopLimit () == 0x40) | 830 else if (ipHeader.GetHopLimit () == 0x40) |
800 { | 831 { |
801 iphcHeader.SetHlim (SixLowPanIphc::HLIM_COMPR_64); | 832 iphcHeader.SetHlim (SixLowPanIphc::HLIM_COMPR_64); |
802 } | 833 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 else if ( dstAddr.IsLinkLocal () ) | 920 else if ( dstAddr.IsLinkLocal () ) |
890 { | 921 { |
891 iphcHeader.SetDam (SixLowPanIphc::HC_COMPR_64); | 922 iphcHeader.SetDam (SixLowPanIphc::HC_COMPR_64); |
892 } | 923 } |
893 else | 924 else |
894 { | 925 { |
895 iphcHeader.SetDam (SixLowPanIphc::HC_INLINE); | 926 iphcHeader.SetDam (SixLowPanIphc::HC_INLINE); |
896 } | 927 } |
897 } | 928 } |
898 else | 929 else |
899 // Multicast address | 930 { |
900 // \todo: check, probably it's bugged | 931 // Multicast address |
901 { | |
902 uint8_t multicastAddrCheckerBuf[16]; | 932 uint8_t multicastAddrCheckerBuf[16]; |
903 Ipv6Address multicastCheckAddress = Ipv6Address ("ff02::1"); | 933 Ipv6Address multicastCheckAddress = Ipv6Address ("ff02::1"); |
904 multicastCheckAddress.GetBytes (multicastAddrCheckerBuf); | 934 multicastCheckAddress.GetBytes (multicastAddrCheckerBuf); |
905 | 935 |
906 // The address takes the form ff02::00XX. | 936 // The address takes the form ff02::00XX. |
907 if ( memcmp (addressBuf, multicastAddrCheckerBuf, 15) == 0 ) | 937 if ( memcmp (addressBuf, multicastAddrCheckerBuf, 15) == 0 ) |
908 { | 938 { |
909 iphcHeader.SetDam (SixLowPanIphc::HC_COMPR_0); | 939 iphcHeader.SetDam (SixLowPanIphc::HC_COMPR_0); |
910 } | 940 } |
911 // The address takes the form ffXX::00XX:XXXX. | 941 // The address takes the form ffXX::00XX:XXXX. |
(...skipping 20 matching lines...) Expand all Loading... |
932 NS_LOG_DEBUG ("IPHC Compression - packet size = " << packet->GetSize () ); | 962 NS_LOG_DEBUG ("IPHC Compression - packet size = " << packet->GetSize () ); |
933 | 963 |
934 packet->AddHeader (iphcHeader); | 964 packet->AddHeader (iphcHeader); |
935 | 965 |
936 NS_LOG_DEBUG ("Packet after IPHC compression: " << *packet); | 966 NS_LOG_DEBUG ("Packet after IPHC compression: " << *packet); |
937 | 967 |
938 return size; | 968 return size; |
939 } | 969 } |
940 | 970 |
941 return 0; | 971 return 0; |
| 972 } |
| 973 |
| 974 bool |
| 975 SixLowPanNetDevice::CanCompressLowPanNhc (uint8_t nextHeader) |
| 976 { |
| 977 bool ret = false; |
| 978 |
| 979 switch (nextHeader) |
| 980 { |
| 981 case Ipv6Header::IPV6_UDP: |
| 982 case Ipv6Header::IPV6_EXT_HOP_BY_HOP: |
| 983 case Ipv6Header::IPV6_EXT_ROUTING: |
| 984 case Ipv6Header::IPV6_EXT_FRAGMENTATION: |
| 985 case Ipv6Header::IPV6_IPV6: |
| 986 ret = true; |
| 987 break; |
| 988 case Ipv6Header::IPV6_EXT_MOBILITY: |
| 989 default: |
| 990 ret = false; |
| 991 } |
| 992 return ret; |
942 } | 993 } |
943 | 994 |
944 void | 995 void |
945 SixLowPanNetDevice::DecompressLowPanIphc (Ptr<Packet> packet, Address const &src
, Address const &dst) | 996 SixLowPanNetDevice::DecompressLowPanIphc (Ptr<Packet> packet, Address const &src
, Address const &dst) |
946 { | 997 { |
947 NS_LOG_FUNCTION (this << *packet << src << dst); | 998 NS_LOG_FUNCTION (this << *packet << src << dst); |
948 | 999 |
949 Ipv6Header ipHeader; | 1000 Ipv6Header ipHeader; |
950 SixLowPanIphc encoding; | 1001 SixLowPanIphc encoding; |
951 | 1002 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 traf = ( traf << 6 ) | encoding.GetDscp (); | 1078 traf = ( traf << 6 ) | encoding.GetDscp (); |
1028 ipHeader.SetTrafficClass (traf); | 1079 ipHeader.SetTrafficClass (traf); |
1029 ipHeader.SetFlowLabel (0); | 1080 ipHeader.SetFlowLabel (0); |
1030 break; | 1081 break; |
1031 case SixLowPanIphc::TF_ELIDED: | 1082 case SixLowPanIphc::TF_ELIDED: |
1032 ipHeader.SetFlowLabel (0); | 1083 ipHeader.SetFlowLabel (0); |
1033 ipHeader.SetTrafficClass (0); | 1084 ipHeader.SetTrafficClass (0); |
1034 break; | 1085 break; |
1035 } | 1086 } |
1036 | 1087 |
1037 // Next Header | |
1038 uint8_t dispatchRawVal = 0; | |
1039 SixLowPanDispatch::NhcDispatch_e dispatchVal; | |
1040 | |
1041 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); | |
1042 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); | |
1043 if ( encoding.GetNh () ) | 1088 if ( encoding.GetNh () ) |
1044 { | 1089 { |
| 1090 // Next Header |
| 1091 uint8_t dispatchRawVal = 0; |
| 1092 SixLowPanDispatch::NhcDispatch_e dispatchVal; |
| 1093 |
| 1094 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
| 1095 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); |
| 1096 |
1045 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) | 1097 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) |
1046 { | 1098 { |
1047 ipHeader.SetNextHeader (Ipv6Header::IPV6_UDP); | 1099 ipHeader.SetNextHeader (Ipv6Header::IPV6_UDP); |
1048 DecompressLowPanUdpNhc (packet, ipHeader.GetSourceAddress (), ipHeader
.GetDestinationAddress ()); | 1100 DecompressLowPanUdpNhc (packet, ipHeader.GetSourceAddress (), ipHeader
.GetDestinationAddress ()); |
1049 } | 1101 } |
1050 else | 1102 else |
1051 { | 1103 { |
1052 DecompressLowPanNhc (packet,encoding.GetNextHeader (),ipHeader); | 1104 ipHeader.SetNextHeader (DecompressLowPanNhc (packet, src, dst, ipHeade
r.GetSourceAddress (), ipHeader.GetDestinationAddress ())); |
1053 } | 1105 } |
1054 } | 1106 } |
1055 else | 1107 else |
1056 { | 1108 { |
1057 ipHeader.SetNextHeader (encoding.GetNextHeader ()); | 1109 ipHeader.SetNextHeader (encoding.GetNextHeader ()); |
1058 } | 1110 } |
1059 | 1111 |
1060 ipHeader.SetPayloadLength (packet->GetSize ()); | 1112 ipHeader.SetPayloadLength (packet->GetSize ()); |
1061 | 1113 |
1062 packet->AddHeader (ipHeader); | 1114 packet->AddHeader (ipHeader); |
1063 | 1115 |
1064 NS_LOG_DEBUG ( "Rebuilt packet: " << *packet << " Size " << packet->GetSize ()
); | 1116 NS_LOG_DEBUG ( "Rebuilt packet: " << *packet << " Size " << packet->GetSize ()
); |
1065 | 1117 |
1066 } | 1118 } |
1067 | 1119 |
1068 uint32_t | 1120 uint32_t |
1069 SixLowPanNetDevice::CompressLowPanNhc (Ptr<Packet> packet, uint8_t nextHeader) | 1121 SixLowPanNetDevice::CompressLowPanNhc (Ptr<Packet> packet, uint8_t headerType, A
ddress const &src, Address const &dst) |
1070 { | 1122 { |
1071 NS_LOG_FUNCTION (this << *packet << int(nextHeader)); | 1123 NS_LOG_FUNCTION (this << *packet << int(headerType)); |
1072 | 1124 |
1073 SixLowPanNhcExtension nhcHeader; | 1125 SixLowPanNhcExtension nhcHeader; |
| 1126 uint32_t size = 0; |
| 1127 Buffer blob; |
| 1128 |
| 1129 if (headerType == Ipv6Header::IPV6_EXT_HOP_BY_HOP) |
| 1130 { |
| 1131 Ipv6ExtensionHopByHopHeader hopHeader; |
| 1132 packet->PeekHeader (hopHeader); |
| 1133 if (hopHeader.GetLength () >= 0xff) |
| 1134 { |
| 1135 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " |
| 1136 "that have more than 255 octets following the Length fie
ld after compression. " |
| 1137 "Packet uncompressed."); |
| 1138 return 0; |
| 1139 } |
| 1140 |
| 1141 size += packet->RemoveHeader (hopHeader); |
| 1142 nhcHeader.SetEid (SixLowPanNhcExtension::EID_HOPBYHOP_OPTIONS_H); |
| 1143 |
| 1144 // recursively compress other headers |
| 1145 uint8_t nextHeader = hopHeader.GetNextHeader (); |
| 1146 if (CanCompressLowPanNhc (nextHeader)) |
| 1147 { |
| 1148 if (nextHeader == Ipv6Header::IPV6_UDP) |
| 1149 { |
| 1150 nhcHeader.SetNh (true); |
| 1151 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); |
| 1152 } |
| 1153 else if (nextHeader == Ipv6Header::IPV6_IPV6) |
| 1154 { |
| 1155 nhcHeader.SetNh (true); |
| 1156 size += CompressLowPanIphc (packet, src, dst); |
| 1157 } |
| 1158 else |
| 1159 { |
| 1160 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader, src, dst
); |
| 1161 // the compression might fail due to Extension header size. |
| 1162 if (sizeNhc) |
| 1163 { |
| 1164 nhcHeader.SetNh (true); |
| 1165 size += sizeNhc; |
| 1166 } |
| 1167 else |
| 1168 { |
| 1169 nhcHeader.SetNh (false); |
| 1170 nhcHeader.SetNextHeader (nextHeader); |
| 1171 } |
| 1172 } |
| 1173 } |
| 1174 else |
| 1175 { |
| 1176 nhcHeader.SetNh (false); |
| 1177 nhcHeader.SetNextHeader (nextHeader); |
| 1178 } |
| 1179 |
| 1180 uint32_t blobSize = hopHeader.GetSerializedSize (); |
| 1181 blob.AddAtStart (blobSize); |
| 1182 hopHeader.Serialize (blob.Begin ()); |
| 1183 blob.RemoveAtStart (2); |
| 1184 blobSize = blob.GetSize (); |
| 1185 nhcHeader.SetBlob (blob.PeekData (), blobSize); |
| 1186 } |
| 1187 else if (headerType == Ipv6Header::IPV6_EXT_ROUTING) |
| 1188 { |
| 1189 Ipv6ExtensionRoutingHeader routingHeader; |
| 1190 packet->PeekHeader (routingHeader); |
| 1191 if (routingHeader.GetLength () >= 0xff) |
| 1192 { |
| 1193 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " |
| 1194 "that have more than 255 octets following the Length fie
ld after compression. " |
| 1195 "Packet uncompressed."); |
| 1196 return 0; |
| 1197 } |
| 1198 |
| 1199 size += packet->RemoveHeader (routingHeader); |
| 1200 nhcHeader.SetEid (SixLowPanNhcExtension::EID_ROUTING_H); |
| 1201 |
| 1202 // recursively compress other headers |
| 1203 uint8_t nextHeader = routingHeader.GetNextHeader (); |
| 1204 if (CanCompressLowPanNhc (nextHeader)) |
| 1205 { |
| 1206 if (nextHeader == Ipv6Header::IPV6_UDP) |
| 1207 { |
| 1208 nhcHeader.SetNh (true); |
| 1209 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); |
| 1210 } |
| 1211 else if (nextHeader == Ipv6Header::IPV6_IPV6) |
| 1212 { |
| 1213 nhcHeader.SetNh (true); |
| 1214 size += CompressLowPanIphc (packet, src, dst); |
| 1215 } |
| 1216 else |
| 1217 { |
| 1218 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader, src, dst
); |
| 1219 // the compression might fail due to Extension header size. |
| 1220 if (sizeNhc) |
| 1221 { |
| 1222 nhcHeader.SetNh (true); |
| 1223 size += sizeNhc; |
| 1224 } |
| 1225 else |
| 1226 { |
| 1227 nhcHeader.SetNh (false); |
| 1228 nhcHeader.SetNextHeader (nextHeader); |
| 1229 } |
| 1230 } |
| 1231 } |
| 1232 else |
| 1233 { |
| 1234 nhcHeader.SetNh (false); |
| 1235 nhcHeader.SetNextHeader (nextHeader); |
| 1236 } |
| 1237 |
| 1238 uint32_t blobSize = routingHeader.GetSerializedSize (); |
| 1239 blob.AddAtStart (blobSize); |
| 1240 routingHeader.Serialize (blob.Begin ()); |
| 1241 blob.RemoveAtStart (2); |
| 1242 blobSize = blob.GetSize (); |
| 1243 nhcHeader.SetBlob (blob.PeekData (), blobSize); |
| 1244 } |
| 1245 else if (headerType == Ipv6Header::IPV6_EXT_FRAGMENTATION) |
| 1246 { |
| 1247 Ipv6ExtensionFragmentHeader fragHeader; |
| 1248 packet->PeekHeader (fragHeader); |
| 1249 if (fragHeader.GetLength () >= 0xff) |
| 1250 { |
| 1251 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " |
| 1252 "that have more than 255 octets following the Length fie
ld after compression. " |
| 1253 "Packet uncompressed."); |
| 1254 return 0; |
| 1255 } |
| 1256 size += packet->RemoveHeader (fragHeader); |
| 1257 nhcHeader.SetEid (SixLowPanNhcExtension::EID_FRAGMENTATION_H); |
| 1258 |
| 1259 // recursively compress other headers |
| 1260 uint8_t nextHeader = fragHeader.GetNextHeader (); |
| 1261 if (CanCompressLowPanNhc (nextHeader)) |
| 1262 { |
| 1263 if (nextHeader == Ipv6Header::IPV6_UDP) |
| 1264 { |
| 1265 nhcHeader.SetNh (true); |
| 1266 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); |
| 1267 } |
| 1268 else if (nextHeader == Ipv6Header::IPV6_IPV6) |
| 1269 { |
| 1270 nhcHeader.SetNh (true); |
| 1271 size += CompressLowPanIphc (packet, src, dst); |
| 1272 } |
| 1273 else |
| 1274 { |
| 1275 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader, src, dst
); |
| 1276 // the compression might fail due to Extension header size. |
| 1277 if (sizeNhc) |
| 1278 { |
| 1279 nhcHeader.SetNh (true); |
| 1280 size += sizeNhc; |
| 1281 } |
| 1282 else |
| 1283 { |
| 1284 nhcHeader.SetNh (false); |
| 1285 nhcHeader.SetNextHeader (nextHeader); |
| 1286 } |
| 1287 } |
| 1288 } |
| 1289 else |
| 1290 { |
| 1291 nhcHeader.SetNh (false); |
| 1292 nhcHeader.SetNextHeader (nextHeader); |
| 1293 } |
| 1294 |
| 1295 uint32_t blobSize = fragHeader.GetSerializedSize (); |
| 1296 blob.AddAtStart (blobSize); |
| 1297 fragHeader.Serialize (blob.Begin ()); |
| 1298 blob.RemoveAtStart (2); |
| 1299 blobSize = blob.GetSize (); |
| 1300 nhcHeader.SetBlob (blob.PeekData (), blobSize); |
| 1301 } |
| 1302 else if (headerType == Ipv6Header::IPV6_EXT_DESTINATION) |
| 1303 { |
| 1304 Ipv6ExtensionDestinationHeader destHeader; |
| 1305 packet->PeekHeader (destHeader); |
| 1306 if (destHeader.GetLength () >= 0xff) |
| 1307 { |
| 1308 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " |
| 1309 "that have more than 255 octets following the Length fie
ld after compression. " |
| 1310 "Packet uncompressed."); |
| 1311 return 0; |
| 1312 } |
| 1313 size += packet->RemoveHeader (destHeader); |
| 1314 nhcHeader.SetEid (SixLowPanNhcExtension::EID_DESTINATION_OPTIONS_H); |
| 1315 |
| 1316 // recursively compress other headers |
| 1317 uint8_t nextHeader = destHeader.GetNextHeader (); |
| 1318 if (CanCompressLowPanNhc (nextHeader)) |
| 1319 { |
| 1320 if (nextHeader == Ipv6Header::IPV6_UDP) |
| 1321 { |
| 1322 nhcHeader.SetNh (true); |
| 1323 size += CompressLowPanUdpNhc (packet, m_omitUdpChecksum); |
| 1324 } |
| 1325 else if (nextHeader == Ipv6Header::IPV6_IPV6) |
| 1326 { |
| 1327 nhcHeader.SetNh (true); |
| 1328 size += CompressLowPanIphc (packet, src, dst); |
| 1329 } |
| 1330 else |
| 1331 { |
| 1332 uint32_t sizeNhc = CompressLowPanNhc (packet, nextHeader, src, dst
); |
| 1333 // the compression might fail due to Extension header size. |
| 1334 if (sizeNhc) |
| 1335 { |
| 1336 nhcHeader.SetNh (true); |
| 1337 size += sizeNhc; |
| 1338 } |
| 1339 else |
| 1340 { |
| 1341 nhcHeader.SetNh (false); |
| 1342 nhcHeader.SetNextHeader (nextHeader); |
| 1343 } |
| 1344 } |
| 1345 } |
| 1346 else |
| 1347 { |
| 1348 nhcHeader.SetNh (false); |
| 1349 nhcHeader.SetNextHeader (nextHeader); |
| 1350 } |
| 1351 |
| 1352 uint32_t blobSize = destHeader.GetSerializedSize (); |
| 1353 blob.AddAtStart (blobSize); |
| 1354 destHeader.Serialize (blob.Begin ()); |
| 1355 blob.RemoveAtStart (2); |
| 1356 blobSize = blob.GetSize (); |
| 1357 nhcHeader.SetBlob (blob.PeekData (), blobSize); |
| 1358 } |
| 1359 else if (headerType == Ipv6Header::IPV6_EXT_MOBILITY) |
| 1360 { |
| 1361 // \todo: IPv6 Mobility Header is not supported in ns-3 |
| 1362 NS_ABORT_MSG ("IPv6 Mobility Header is not supported in ns-3 yet"); |
| 1363 return 0; |
| 1364 } |
| 1365 else |
| 1366 { |
| 1367 NS_ABORT_MSG ("Unexpected Extension Header"); |
| 1368 } |
| 1369 |
| 1370 NS_LOG_DEBUG ("NHC Compression - NHC header size = " << nhcHeader.GetSerialize
dSize () ); |
| 1371 NS_LOG_DEBUG ("NHC Compression - packet size = " << packet->GetSize () ); |
| 1372 |
| 1373 packet->AddHeader (nhcHeader); |
| 1374 |
| 1375 NS_LOG_DEBUG ("Packet after NHC compression: " << *packet); |
| 1376 return size; |
| 1377 } |
| 1378 |
| 1379 uint8_t |
| 1380 SixLowPanNetDevice::DecompressLowPanNhc (Ptr<Packet> packet, Address const &src,
Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress) |
| 1381 { |
| 1382 NS_LOG_FUNCTION (this << *packet); |
| 1383 |
| 1384 SixLowPanNhcExtension encoding; |
| 1385 |
| 1386 uint32_t ret = packet->RemoveHeader (encoding); |
| 1387 NS_LOG_DEBUG ("removed " << ret << " bytes - pkt is " << *packet); |
| 1388 NS_UNUSED (ret); |
| 1389 |
1074 Ipv6ExtensionHopByHopHeader hopHeader; | 1390 Ipv6ExtensionHopByHopHeader hopHeader; |
1075 Ipv6ExtensionRoutingHeader routingHeader; | 1391 Ipv6ExtensionRoutingHeader routingHeader; |
1076 Ipv6ExtensionFragmentHeader fragHeader; | 1392 Ipv6ExtensionFragmentHeader fragHeader; |
1077 Ipv6ExtensionDestinationHeader destHeader; | 1393 Ipv6ExtensionDestinationHeader destHeader; |
1078 uint32_t size = 0; | 1394 |
1079 | 1395 uint32_t blobSize; |
1080 switch (nextHeader) | 1396 uint8_t blobData[260]; |
1081 { | 1397 blobSize = encoding.CopyBlob (blobData + 2, 260); |
1082 uint32_t sizeNhc; | 1398 uint8_t paddingSize = 0; |
1083 | 1399 |
1084 case Ipv6Header::IPV6_EXT_HOP_BY_HOP: | 1400 uint8_t actualEncodedHeaderType = encoding.GetEid (); |
1085 if (hopHeader.GetLength () >= 0xff) | 1401 uint8_t actualHeaderType; |
1086 { | 1402 Buffer blob; |
1087 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " | 1403 |
1088 "that have more than 255 octets following the Length fie
ld after compression. " | 1404 switch (actualEncodedHeaderType) |
1089 "Packet uncompressed."); | 1405 { |
1090 } | 1406 case SixLowPanNhcExtension::EID_HOPBYHOP_OPTIONS_H: |
1091 else | 1407 actualHeaderType = Ipv6Header::IPV6_EXT_HOP_BY_HOP; |
1092 { | 1408 if ( encoding.GetNh () ) |
1093 size += packet->RemoveHeader (hopHeader); | 1409 { |
1094 nhcHeader.SetEid (SixLowPanNhcExtension::EID_HOPBYHOP_OPTIONS_H); | 1410 // Next Header |
1095 nhcHeader.SetNextHeader (hopHeader.GetNextHeader ()); | 1411 uint8_t dispatchRawVal = 0; |
1096 sizeNhc = CompressLowPanNhc (packet,hopHeader.GetNextHeader ()); | 1412 SixLowPanDispatch::NhcDispatch_e dispatchVal; |
1097 if (sizeNhc == 0) | 1413 |
1098 { | 1414 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
1099 nhcHeader.SetNh (false); | 1415 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); |
| 1416 |
| 1417 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) |
| 1418 { |
| 1419 blobData [0] = Ipv6Header::IPV6_UDP; |
| 1420 DecompressLowPanUdpNhc (packet, srcAddress, dstAddress); |
1100 } | 1421 } |
1101 else | 1422 else |
1102 { | 1423 { |
1103 nhcHeader.SetNh (true); | 1424 blobData [0] = DecompressLowPanNhc (packet, src, dst, srcAddress,
dstAddress); |
1104 size += sizeNhc; | 1425 } |
1105 } | 1426 } |
1106 } | 1427 else |
1107 break; | 1428 { |
1108 case Ipv6Header::IPV6_EXT_ROUTING: | 1429 blobData [0] = encoding.GetNextHeader (); |
1109 if (routingHeader.GetLength () >= 0xff) | 1430 } |
1110 { | 1431 |
1111 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " | 1432 // manually add some padding if needed |
1112 "that have more than 255 octets following the Length fie
ld after compression. " | 1433 if ((blobSize + 2) % 8 > 0) |
1113 "Packet uncompressed."); | 1434 { |
1114 } | 1435 paddingSize = 8 - (blobSize + 2) % 8; |
1115 else | 1436 } |
1116 { | 1437 if (paddingSize == 1) |
1117 size += packet->RemoveHeader (routingHeader); | 1438 { |
1118 nhcHeader.SetEid (SixLowPanNhcExtension::EID_ROUTING_H); | 1439 blobData[blobSize + 2] = 0; |
1119 nhcHeader.SetNextHeader (routingHeader.GetNextHeader ()); | 1440 } |
1120 sizeNhc = CompressLowPanNhc (packet,routingHeader.GetNextHeader ()); | 1441 else if (paddingSize > 1) |
1121 if (sizeNhc == 0) | 1442 { |
1122 { | 1443 blobData[blobSize + 2] = 1; |
1123 nhcHeader.SetNh (false); | 1444 blobData[blobSize + 2 + 1] = paddingSize - 2; |
| 1445 for (uint8_t i = 0; i < paddingSize - 2; i++) |
| 1446 { |
| 1447 blobData[blobSize + 2 + 2 + i] = 0; |
| 1448 } |
| 1449 } |
| 1450 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1; |
| 1451 blob.AddAtStart (blobSize + 2 + paddingSize); |
| 1452 blob.Begin ().Write (blobData, blobSize + 2 + paddingSize); |
| 1453 hopHeader.Deserialize (blob.Begin ()); |
| 1454 |
| 1455 packet->AddHeader (hopHeader); |
| 1456 break; |
| 1457 |
| 1458 case SixLowPanNhcExtension::EID_ROUTING_H: |
| 1459 actualHeaderType = Ipv6Header::IPV6_EXT_ROUTING; |
| 1460 if ( encoding.GetNh () ) |
| 1461 { |
| 1462 // Next Header |
| 1463 uint8_t dispatchRawVal = 0; |
| 1464 SixLowPanDispatch::NhcDispatch_e dispatchVal; |
| 1465 |
| 1466 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
| 1467 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); |
| 1468 |
| 1469 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) |
| 1470 { |
| 1471 blobData [0] = Ipv6Header::IPV6_UDP; |
| 1472 DecompressLowPanUdpNhc (packet, srcAddress, dstAddress); |
1124 } | 1473 } |
1125 else | 1474 else |
1126 { | 1475 { |
1127 nhcHeader.SetNh (true); | 1476 blobData [0] = DecompressLowPanNhc (packet, src, dst, srcAddress,
dstAddress); |
1128 size += sizeNhc; | 1477 } |
1129 } | 1478 } |
1130 } | 1479 else |
1131 break; | 1480 { |
1132 case Ipv6Header::IPV6_EXT_FRAGMENTATION: | 1481 blobData [0] = encoding.GetNextHeader (); |
1133 if (fragHeader.GetLength () >= 0xff) | 1482 } |
1134 { | 1483 blobData [1] = ((blobSize + 2) >> 3) - 1; |
1135 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " | 1484 blob.AddAtStart (blobSize + 2); |
1136 "that have more than 255 octets following the Length fie
ld after compression. " | 1485 blob.Begin ().Write (blobData, blobSize + 2); |
1137 "Packet uncompressed."); | 1486 routingHeader.Deserialize (blob.Begin ()); |
1138 } | 1487 packet->AddHeader (routingHeader); |
1139 else | 1488 break; |
1140 { | 1489 |
1141 size += packet->RemoveHeader (fragHeader); | 1490 case SixLowPanNhcExtension::EID_FRAGMENTATION_H: |
1142 nhcHeader.SetEid (SixLowPanNhcExtension::EID_FRAGMENTATION_H); | 1491 actualHeaderType = Ipv6Header::IPV6_EXT_FRAGMENTATION; |
1143 nhcHeader.SetNextHeader (fragHeader.GetNextHeader ()); | 1492 if ( encoding.GetNh () ) |
1144 sizeNhc = CompressLowPanNhc (packet,fragHeader.GetNextHeader ()); | 1493 { |
1145 if (sizeNhc == 0) | 1494 // Next Header |
1146 { | 1495 uint8_t dispatchRawVal = 0; |
1147 nhcHeader.SetNh (false); | 1496 SixLowPanDispatch::NhcDispatch_e dispatchVal; |
| 1497 |
| 1498 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
| 1499 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); |
| 1500 |
| 1501 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) |
| 1502 { |
| 1503 blobData [0] = Ipv6Header::IPV6_UDP; |
| 1504 DecompressLowPanUdpNhc (packet, srcAddress, dstAddress); |
1148 } | 1505 } |
1149 else | 1506 else |
1150 { | 1507 { |
1151 nhcHeader.SetNh (true); | 1508 blobData [0] = DecompressLowPanNhc (packet, src, dst, srcAddress,
dstAddress); |
1152 size += sizeNhc; | 1509 } |
1153 } | 1510 } |
1154 } | 1511 else |
1155 break; | 1512 { |
1156 case Ipv6Header::IPV6_EXT_DESTINATION: | 1513 blobData [0] = encoding.GetNextHeader (); |
1157 if (destHeader.GetLength () >= 0xff) | 1514 } |
1158 { | 1515 blobData [1] = 0; |
1159 NS_LOG_DEBUG ("LOWPAN_NHC MUST NOT be used to encode IPv6 Extension He
aders " | 1516 fragHeader.Deserialize (blob.Begin ()); |
1160 "that have more than 255 octets following the Length fie
ld after compression. " | 1517 packet->AddHeader (fragHeader); |
1161 "Packet uncompressed."); | 1518 break; |
1162 } | 1519 |
1163 else | 1520 case SixLowPanNhcExtension::EID_DESTINATION_OPTIONS_H: |
1164 { | 1521 actualHeaderType = Ipv6Header::IPV6_EXT_DESTINATION; |
1165 size += packet->RemoveHeader (destHeader); | 1522 if ( encoding.GetNh () ) |
1166 nhcHeader.SetEid (SixLowPanNhcExtension::EID_DESTINATION_OPTIONS_H); | 1523 { |
1167 nhcHeader.SetNextHeader (destHeader.GetNextHeader ()); | 1524 // Next Header |
1168 sizeNhc = CompressLowPanNhc (packet,destHeader.GetNextHeader ()); | 1525 uint8_t dispatchRawVal = 0; |
1169 if (sizeNhc == 0) | 1526 SixLowPanDispatch::NhcDispatch_e dispatchVal; |
1170 { | 1527 |
1171 nhcHeader.SetNh (false); | 1528 packet->CopyData (&dispatchRawVal, sizeof(dispatchRawVal)); |
| 1529 dispatchVal = SixLowPanDispatch::GetNhcDispatchType (dispatchRawVal); |
| 1530 |
| 1531 if (dispatchVal == SixLowPanDispatch::LOWPAN_UDPNHC) |
| 1532 { |
| 1533 blobData [0] = Ipv6Header::IPV6_UDP; |
| 1534 DecompressLowPanUdpNhc (packet, srcAddress, dstAddress); |
1172 } | 1535 } |
1173 else | 1536 else |
1174 { | 1537 { |
1175 nhcHeader.SetNh (true); | 1538 blobData [0] = DecompressLowPanNhc (packet, src, dst, srcAddress,
dstAddress); |
1176 size += sizeNhc; | 1539 } |
1177 } | 1540 } |
1178 } | 1541 else |
1179 break; | 1542 { |
1180 case Ipv6Header::IPV6_EXT_MOBILITY: | 1543 blobData [0] = encoding.GetNextHeader (); |
1181 // \todo: IPv6 Mobility Header is not supported in ns-3 | 1544 } |
1182 nhcHeader.SetEid (SixLowPanNhcExtension::EID_MOBILITY_H); | 1545 |
1183 NS_ABORT_MSG ("IPv6 Mobility Header is not supported in ns-3 yet"); | 1546 // manually add some padding if needed |
1184 break; | 1547 if ((blobSize + 2) % 8 > 0) |
1185 case Ipv6Header::IPV6_IPV6: | 1548 { |
1186 default: | 1549 paddingSize = 8 - (blobSize + 2) % 8; |
1187 return size; | 1550 } |
1188 break; | 1551 if (paddingSize == 1) |
1189 } | 1552 { |
1190 | 1553 blobData[blobSize + 2] = 0; |
1191 NS_LOG_DEBUG ("NHC Compression - NHC header size = " << nhcHeader.GetSerialize
dSize () ); | 1554 } |
1192 NS_LOG_DEBUG ("NHC Compression - packet size = " << packet->GetSize () ); | 1555 else if (paddingSize > 1) |
1193 | 1556 { |
1194 packet->AddHeader (nhcHeader); | 1557 blobData[blobSize + 2] = 1; |
1195 | 1558 blobData[blobSize + 2 + 1] = paddingSize - 2; |
1196 NS_LOG_DEBUG ("Packet after NHC compression: " << *packet); | 1559 for (uint8_t i = 0; i < paddingSize - 2; i++) |
1197 return size; | 1560 { |
1198 } | 1561 blobData[blobSize + 2 + 2 + i] = 0; |
1199 | 1562 } |
1200 void | 1563 } |
1201 SixLowPanNetDevice::DecompressLowPanNhc (Ptr<Packet> packet, uint8_t nextHeader,
Ipv6Header &ipHeader) | 1564 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1; |
1202 { | 1565 blob.AddAtStart (blobSize + 2 + paddingSize); |
1203 NS_LOG_FUNCTION (this << *packet << int(nextHeader)); | 1566 blob.Begin ().Write (blobData, blobSize + 2 + paddingSize); |
1204 | 1567 destHeader.Deserialize (blob.Begin ()); |
1205 SixLowPanNhcExtension encoding; | 1568 |
1206 | |
1207 uint32_t ret = packet->RemoveHeader (encoding); | |
1208 NS_LOG_DEBUG ("removed " << ret << " bytes - pkt is " << *packet); | |
1209 NS_UNUSED (ret); | |
1210 | |
1211 Ipv6ExtensionHopByHopHeader hopHeader; | |
1212 Ipv6ExtensionRoutingHeader routingHeader; | |
1213 Ipv6ExtensionFragmentHeader fragHeader; | |
1214 Ipv6ExtensionDestinationHeader destHeader; | |
1215 | |
1216 switch (encoding.GetEid ()) | |
1217 { | |
1218 case SixLowPanNhcExtension::EID_HOPBYHOP_OPTIONS_H: | |
1219 hopHeader.SetNextHeader (encoding.GetNextHeader ()); | |
1220 ipHeader.SetNextHeader (Ipv6Header::IPV6_EXT_HOP_BY_HOP); | |
1221 if ( encoding.GetNh () ) | |
1222 { | |
1223 DecompressLowPanNhc (packet,encoding.GetNextHeader (),ipHeader); | |
1224 } | |
1225 packet->AddHeader (hopHeader); | |
1226 break; | |
1227 case SixLowPanNhcExtension::EID_ROUTING_H: | |
1228 routingHeader.SetNextHeader (encoding.GetNextHeader ()); | |
1229 ipHeader.SetNextHeader (Ipv6Header::IPV6_EXT_ROUTING); | |
1230 if ( encoding.GetNh () ) | |
1231 { | |
1232 DecompressLowPanNhc (packet,encoding.GetNextHeader (),ipHeader); | |
1233 } | |
1234 packet->AddHeader (routingHeader); | |
1235 break; | |
1236 case SixLowPanNhcExtension::EID_FRAGMENTATION_H: | |
1237 fragHeader.SetNextHeader (encoding.GetNextHeader ()); | |
1238 ipHeader.SetNextHeader (Ipv6Header::IPV6_EXT_FRAGMENTATION); | |
1239 if ( encoding.GetNh () ) | |
1240 { | |
1241 DecompressLowPanNhc (packet,encoding.GetNextHeader (),ipHeader); | |
1242 } | |
1243 packet->AddHeader (fragHeader); | |
1244 break; | |
1245 case SixLowPanNhcExtension::EID_DESTINATION_OPTIONS_H: | |
1246 destHeader.SetNextHeader (encoding.GetNextHeader ()); | |
1247 ipHeader.SetNextHeader (Ipv6Header::IPV6_EXT_DESTINATION); | |
1248 if ( encoding.GetNh () ) | |
1249 { | |
1250 DecompressLowPanNhc (packet,encoding.GetNextHeader (),ipHeader); | |
1251 } | |
1252 packet->AddHeader (destHeader); | 1569 packet->AddHeader (destHeader); |
1253 break; | 1570 break; |
1254 case SixLowPanNhcExtension::EID_MOBILITY_H: | 1571 case SixLowPanNhcExtension::EID_MOBILITY_H: |
1255 // \todo: IPv6 Mobility Header is not supported in ns-3 | 1572 // \todo: IPv6 Mobility Header is not supported in ns-3 |
1256 ipHeader.SetNextHeader (Ipv6Header::IPV6_EXT_MOBILITY); | |
1257 NS_ABORT_MSG ("IPv6 Mobility Header is not supported in ns-3 yet"); | 1573 NS_ABORT_MSG ("IPv6 Mobility Header is not supported in ns-3 yet"); |
1258 break; | 1574 break; |
1259 case SixLowPanNhcExtension::EID_IPv6_H: | 1575 case SixLowPanNhcExtension::EID_IPv6_H: |
| 1576 actualHeaderType = Ipv6Header::IPV6_IPV6; |
| 1577 DecompressLowPanIphc (packet, src, dst); |
| 1578 break; |
1260 default: | 1579 default: |
| 1580 NS_ABORT_MSG ("Trying to decode unknown Extension Header"); |
1261 break; | 1581 break; |
1262 } | 1582 } |
1263 | 1583 |
1264 NS_LOG_DEBUG ( "Rebuilt packet: " << *packet << " Size " << packet->GetSize ()
); | 1584 NS_LOG_DEBUG ( "Rebuilt packet: " << *packet << " Size " << packet->GetSize ()
); |
1265 | 1585 return actualHeaderType; |
1266 } | 1586 } |
1267 | 1587 |
1268 uint32_t | 1588 uint32_t |
1269 SixLowPanNetDevice::CompressLowPanUdpNhc (Ptr<Packet> packet, bool elideChecksum
) | 1589 SixLowPanNetDevice::CompressLowPanUdpNhc (Ptr<Packet> packet, bool omitChecksum) |
1270 { | 1590 { |
1271 NS_LOG_FUNCTION (this << *packet << int(elideChecksum)); | 1591 NS_LOG_FUNCTION (this << *packet << int(omitChecksum)); |
1272 | 1592 |
1273 UdpHeader udpHeader; | 1593 UdpHeader udpHeader; |
1274 SixLowPanUdpNhcExtension udpNhcHeader; | 1594 SixLowPanUdpNhcExtension udpNhcHeader; |
1275 uint32_t size = 0; | 1595 uint32_t size = 0; |
1276 | 1596 |
1277 if ( packet->PeekHeader (udpHeader) != 0 ) | 1597 NS_ASSERT_MSG (packet->PeekHeader (udpHeader) != 0, "UDP header not found, abo
rt"); |
1278 { | 1598 |
1279 size += packet->RemoveHeader (udpHeader); | 1599 size += packet->RemoveHeader (udpHeader); |
1280 | 1600 |
1281 // Set the C field and checksum | 1601 // Set the C field and checksum |
1282 udpNhcHeader.SetC (false); | 1602 udpNhcHeader.SetC (false); |
1283 uint16_t checksum = udpHeader.GetChecksum (); | 1603 uint16_t checksum = udpHeader.GetChecksum (); |
1284 udpNhcHeader.SetChecksum (checksum); | 1604 udpNhcHeader.SetChecksum (checksum); |
1285 | 1605 |
1286 if (elideChecksum && udpHeader.IsChecksumOk ()) | 1606 if (omitChecksum && udpHeader.IsChecksumOk ()) |
1287 { | 1607 { |
1288 udpNhcHeader.SetC (true); | 1608 udpNhcHeader.SetC (true); |
1289 } | 1609 } |
1290 | 1610 |
1291 // Set the value of the ports | 1611 // Set the value of the ports |
1292 udpNhcHeader.SetSrcPort (udpHeader.GetSourcePort ()); | 1612 udpNhcHeader.SetSrcPort (udpHeader.GetSourcePort ()); |
1293 udpNhcHeader.SetDstPort (udpHeader.GetDestinationPort ()); | 1613 udpNhcHeader.SetDstPort (udpHeader.GetDestinationPort ()); |
1294 | 1614 |
1295 //Set the P field | 1615 //Set the P field |
1296 if ( (udpHeader.GetSourcePort () >> 4 ) == 0xf0b && (udpHeader.GetDestinat
ionPort () >> 4 ) == 0xf0b ) | 1616 if ( (udpHeader.GetSourcePort () >> 4 ) == 0xf0b && (udpHeader.GetDestinationP
ort () >> 4 ) == 0xf0b ) |
1297 { | 1617 { |
1298 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_LAST_SRC_LAST_D
ST); | 1618 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_LAST_SRC_LAST_DST); |
1299 } | 1619 } |
1300 else if ( (udpHeader.GetSourcePort () >> 8 ) == 0xf0 && (udpHeader.GetDest
inationPort () >> 8 ) != 0xf0 ) | 1620 else if ( (udpHeader.GetSourcePort () >> 8 ) == 0xf0 && (udpHeader.GetDestinat
ionPort () >> 8 ) != 0xf0 ) |
1301 { | 1621 { |
1302 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_LAST_SRC_ALL_DS
T); | 1622 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_LAST_SRC_ALL_DST); |
1303 } | 1623 } |
1304 else if ( (udpHeader.GetSourcePort () >> 8 ) != 0xf0 && (udpHeader.GetDest
inationPort () >> 8 ) == 0xf0 ) | 1624 else if ( (udpHeader.GetSourcePort () >> 8 ) != 0xf0 && (udpHeader.GetDestinat
ionPort () >> 8 ) == 0xf0 ) |
1305 { | 1625 { |
1306 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_ALL_SRC_LAST_DS
T); | 1626 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_ALL_SRC_LAST_DST); |
1307 } | 1627 } |
1308 else | 1628 else |
1309 { | 1629 { |
1310 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_INLINE); | 1630 udpNhcHeader.SetPorts (SixLowPanUdpNhcExtension::PORTS_INLINE); |
1311 } | 1631 } |
1312 | 1632 |
1313 NS_LOG_DEBUG ("UDP_NHC Compression - UDP_NHC header size = " << udpNhcHead
er.GetSerializedSize () ); | 1633 NS_LOG_DEBUG ("UDP_NHC Compression - UDP_NHC header size = " << udpNhcHeader.G
etSerializedSize () ); |
1314 NS_LOG_DEBUG ("UDP_NHC Compression - packet size = " << packet->GetSize ()
); | 1634 NS_LOG_DEBUG ("UDP_NHC Compression - packet size = " << packet->GetSize () ); |
1315 | 1635 |
1316 packet->AddHeader (udpNhcHeader); | 1636 packet->AddHeader (udpNhcHeader); |
1317 | 1637 |
1318 NS_LOG_DEBUG ("Packet after UDP_NHC compression: " << *packet); | 1638 NS_LOG_DEBUG ("Packet after UDP_NHC compression: " << *packet); |
1319 | 1639 |
1320 return size; | 1640 return size; |
1321 } | |
1322 return 0; | |
1323 } | 1641 } |
1324 | 1642 |
1325 void | 1643 void |
1326 SixLowPanNetDevice::DecompressLowPanUdpNhc (Ptr<Packet> packet, Ipv6Address sadd
r, Ipv6Address daddr) | 1644 SixLowPanNetDevice::DecompressLowPanUdpNhc (Ptr<Packet> packet, Ipv6Address sadd
r, Ipv6Address daddr) |
1327 { | 1645 { |
1328 NS_LOG_FUNCTION (this << *packet); | 1646 NS_LOG_FUNCTION (this << *packet); |
1329 | 1647 |
1330 UdpHeader udpHeader; | 1648 UdpHeader udpHeader; |
1331 SixLowPanUdpNhcExtension encoding; | 1649 SixLowPanUdpNhcExtension encoding; |
1332 | 1650 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 NS_LOG_FUNCTION (this << *packet); | 1718 NS_LOG_FUNCTION (this << *packet); |
1401 | 1719 |
1402 Ptr<Packet> p = packet->Copy (); | 1720 Ptr<Packet> p = packet->Copy (); |
1403 | 1721 |
1404 uint16_t offsetData = 0; | 1722 uint16_t offsetData = 0; |
1405 uint16_t offset = 0; | 1723 uint16_t offset = 0; |
1406 uint16_t l2Mtu = m_netDevice->GetMtu (); | 1724 uint16_t l2Mtu = m_netDevice->GetMtu (); |
1407 uint32_t packetSize = packet->GetSize (); | 1725 uint32_t packetSize = packet->GetSize (); |
1408 uint32_t compressedHeaderSize = packetSize - (origPacketSize - origHdrSize); | 1726 uint32_t compressedHeaderSize = packetSize - (origPacketSize - origHdrSize); |
1409 | 1727 |
1410 UniformVariable cd (0,65535); | 1728 uint16_t tag = uint16_t (m_rng->GetValue (0, 65535)); |
1411 uint16_t tag; | |
1412 tag = cd.GetValue (); | |
1413 NS_LOG_LOGIC ("random tag " << tag << " - test " << packetSize ); | 1729 NS_LOG_LOGIC ("random tag " << tag << " - test " << packetSize ); |
1414 | 1730 |
1415 // first fragment | 1731 // first fragment |
1416 SixLowPanFrag1 frag1Hdr; | 1732 SixLowPanFrag1 frag1Hdr; |
1417 frag1Hdr.SetDatagramTag (tag); | 1733 frag1Hdr.SetDatagramTag (tag); |
1418 | 1734 |
1419 uint32_t size; | 1735 uint32_t size; |
1420 NS_ASSERT_MSG ( l2Mtu > frag1Hdr.GetSerializedSize (), | 1736 NS_ASSERT_MSG ( l2Mtu > frag1Hdr.GetSerializedSize (), |
1421 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MT
U"); | 1737 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MT
U"); |
1422 | 1738 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 MapFragmentsTimers_t::iterator iter; | 1854 MapFragmentsTimers_t::iterator iter; |
1539 MapFragmentsTimers_t::iterator iterFound = m_fragmentsTimers.begin (); | 1855 MapFragmentsTimers_t::iterator iterFound = m_fragmentsTimers.begin (); |
1540 for ( iter = m_fragmentsTimers.begin (); iter != m_fragmentsTimers.end
(); iter++) | 1856 for ( iter = m_fragmentsTimers.begin (); iter != m_fragmentsTimers.end
(); iter++) |
1541 { | 1857 { |
1542 if ( iter->second.GetTs () < iterFound->second.GetTs () ) | 1858 if ( iter->second.GetTs () < iterFound->second.GetTs () ) |
1543 { | 1859 { |
1544 iterFound = iter; | 1860 iterFound = iter; |
1545 } | 1861 } |
1546 } | 1862 } |
1547 FragmentKey oldestKey = iterFound->first; | 1863 FragmentKey oldestKey = iterFound->first; |
| 1864 |
| 1865 std::list< Ptr<Packet> > storedFragments = m_fragments[oldestKey]->Get
Framents (); |
| 1866 for (std::list< Ptr<Packet> >::iterator fragIter = storedFragments.beg
in (); |
| 1867 fragIter != storedFragments.end (); fragIter++) |
| 1868 { |
| 1869 m_dropTrace (DROP_FRAGMENT_BUFFER_FULL, *fragIter, m_node->GetObje
ct<SixLowPanNetDevice> (), GetIfIndex ()); |
| 1870 } |
| 1871 |
1548 m_fragmentsTimers[oldestKey].Cancel (); | 1872 m_fragmentsTimers[oldestKey].Cancel (); |
1549 m_fragmentsTimers.erase (oldestKey); | 1873 m_fragmentsTimers.erase (oldestKey); |
1550 m_fragments[oldestKey] = 0; | 1874 m_fragments[oldestKey] = 0; |
1551 m_fragments.erase (oldestKey); | 1875 m_fragments.erase (oldestKey); |
1552 m_dropTrace (DROP_FRAGMENT_BUFFERFULL, m_node->GetObject<SixLowPanNetD
evice> (), GetIfIndex ()); | 1876 |
1553 } | 1877 } |
1554 fragments = Create<Fragments> (); | 1878 fragments = Create<Fragments> (); |
1555 fragments->SetPacketSize (packetSize); | 1879 fragments->SetPacketSize (packetSize); |
1556 m_fragments.insert (std::make_pair (key, fragments)); | 1880 m_fragments.insert (std::make_pair (key, fragments)); |
1557 uint32_t ifIndex = GetIfIndex (); | 1881 uint32_t ifIndex = GetIfIndex (); |
1558 m_fragmentsTimers[key] = Simulator::Schedule (m_fragmentExpirationTimeout, | 1882 m_fragmentsTimers[key] = Simulator::Schedule (m_fragmentExpirationTimeout, |
1559 &SixLowPanNetDevice::HandleF
ragmentsTimeout, this, | 1883 &SixLowPanNetDevice::HandleF
ragmentsTimeout, this, |
1560 key, ifIndex); | 1884 key, ifIndex); |
1561 } | 1885 } |
1562 else | 1886 else |
1563 { | 1887 { |
1564 fragments = it->second; | 1888 fragments = it->second; |
1565 } | 1889 } |
1566 | 1890 |
1567 fragments->AddFragment (p, offset); | 1891 fragments->AddFragment (p, offset); |
| 1892 |
1568 // add the very first fragment so we can correctly decode the packet once is r
ebuilt. | 1893 // add the very first fragment so we can correctly decode the packet once is r
ebuilt. |
1569 // this is needed because otherwise the UDP header length and checksum can not
be calculated. | 1894 // this is needed because otherwise the UDP header length and checksum can not
be calculated. |
1570 if ( isFirst ) | 1895 if ( isFirst ) |
1571 { | 1896 { |
1572 fragments->AddFirstFragment (packet); | 1897 fragments->AddFirstFragment (packet); |
1573 } | 1898 } |
1574 | 1899 |
1575 if ( fragments->IsEntire () ) | 1900 if ( fragments->IsEntire () ) |
1576 { | 1901 { |
1577 packet = fragments->GetPacket (); | 1902 packet = fragments->GetPacket (); |
(...skipping 26 matching lines...) Expand all Loading... |
1604 SixLowPanNetDevice::Fragments::~Fragments () | 1929 SixLowPanNetDevice::Fragments::~Fragments () |
1605 { | 1930 { |
1606 NS_LOG_FUNCTION (this); | 1931 NS_LOG_FUNCTION (this); |
1607 } | 1932 } |
1608 | 1933 |
1609 void SixLowPanNetDevice::Fragments::AddFragment (Ptr<Packet> fragment, uint16_t
fragmentOffset) | 1934 void SixLowPanNetDevice::Fragments::AddFragment (Ptr<Packet> fragment, uint16_t
fragmentOffset) |
1610 { | 1935 { |
1611 NS_LOG_FUNCTION (this << fragmentOffset << *fragment); | 1936 NS_LOG_FUNCTION (this << fragmentOffset << *fragment); |
1612 | 1937 |
1613 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it; | 1938 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it; |
| 1939 bool duplicate = false; |
1614 | 1940 |
1615 for (it = m_fragments.begin (); it != m_fragments.end (); it++) | 1941 for (it = m_fragments.begin (); it != m_fragments.end (); it++) |
1616 { | 1942 { |
1617 if (it->second > fragmentOffset) | 1943 if (it->second > fragmentOffset) |
1618 { | 1944 { |
1619 break; | 1945 break; |
1620 } | 1946 } |
1621 } | 1947 if (it->second == fragmentOffset) |
1622 | 1948 { |
1623 m_fragments.insert (it, std::make_pair<Ptr<Packet>, uint16_t> (fragment, fragm
entOffset)); | 1949 duplicate = true; |
| 1950 NS_ASSERT_MSG(fragment->GetSize () == it->first->GetSize (), "Duplicat
e fragment size differs. Aborting."); |
| 1951 break; |
| 1952 } |
| 1953 } |
| 1954 if (!duplicate) |
| 1955 { |
| 1956 m_fragments.insert (it, std::make_pair<Ptr<Packet>, uint16_t> (fragment, f
ragmentOffset)); |
| 1957 } |
1624 } | 1958 } |
1625 | 1959 |
1626 void SixLowPanNetDevice::Fragments::AddFirstFragment (Ptr<Packet> fragment) | 1960 void SixLowPanNetDevice::Fragments::AddFirstFragment (Ptr<Packet> fragment) |
1627 { | 1961 { |
1628 NS_LOG_FUNCTION (this << *fragment); | 1962 NS_LOG_FUNCTION (this << *fragment); |
1629 | 1963 |
1630 m_firstFragment = fragment; | 1964 m_firstFragment = fragment; |
1631 } | 1965 } |
1632 | 1966 |
1633 bool SixLowPanNetDevice::Fragments::IsEntire () const | 1967 bool SixLowPanNetDevice::Fragments::IsEntire () const |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 | 2025 |
1692 return p; | 2026 return p; |
1693 } | 2027 } |
1694 | 2028 |
1695 void SixLowPanNetDevice::Fragments::SetPacketSize (uint32_t packetSize) | 2029 void SixLowPanNetDevice::Fragments::SetPacketSize (uint32_t packetSize) |
1696 { | 2030 { |
1697 NS_LOG_FUNCTION (this << packetSize); | 2031 NS_LOG_FUNCTION (this << packetSize); |
1698 m_packetSize = packetSize; | 2032 m_packetSize = packetSize; |
1699 } | 2033 } |
1700 | 2034 |
| 2035 std::list< Ptr<Packet> > SixLowPanNetDevice::Fragments::GetFraments () const |
| 2036 { |
| 2037 std::list< Ptr<Packet> > fragments; |
| 2038 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator iter; |
| 2039 for( iter = m_fragments.begin (); iter != m_fragments.end (); iter ++) |
| 2040 { |
| 2041 fragments.push_back (iter->first); |
| 2042 } |
| 2043 return fragments; |
| 2044 } |
| 2045 |
1701 void SixLowPanNetDevice::HandleFragmentsTimeout (FragmentKey key, uint32_t iif) | 2046 void SixLowPanNetDevice::HandleFragmentsTimeout (FragmentKey key, uint32_t iif) |
1702 { | 2047 { |
1703 NS_LOG_FUNCTION (this); | 2048 NS_LOG_FUNCTION (this); |
1704 | 2049 |
1705 MapFragments_t::iterator it = m_fragments.find (key); | 2050 MapFragments_t::iterator it = m_fragments.find (key); |
1706 | 2051 std::list< Ptr<Packet> > storedFragments = it->second->GetFraments (); |
1707 m_dropTrace (DROP_FRAGMENT_TIMEOUT, m_node->GetObject<SixLowPanNetDevice> (),
iif); | 2052 for (std::list< Ptr<Packet> >::iterator fragIter = storedFragments.begin (); |
1708 | 2053 fragIter != storedFragments.end (); fragIter++) |
| 2054 { |
| 2055 m_dropTrace (DROP_FRAGMENT_TIMEOUT, *fragIter, m_node->GetObject<SixLowPan
NetDevice> (), iif); |
| 2056 } |
1709 // clear the buffers | 2057 // clear the buffers |
1710 it->second = 0; | 2058 it->second = 0; |
1711 | 2059 |
1712 m_fragments.erase (key); | 2060 m_fragments.erase (key); |
1713 m_fragmentsTimers.erase (key); | 2061 m_fragmentsTimers.erase (key); |
1714 } | 2062 } |
1715 | 2063 |
1716 Ipv6Address SixLowPanNetDevice::MakeLinkLocalAddressFromMac (Address const &addr
) | 2064 Ipv6Address SixLowPanNetDevice::MakeLinkLocalAddressFromMac (Address const &addr
) |
1717 { | 2065 { |
1718 Ipv6Address ipv6Addr = Ipv6Address::GetAny(); | 2066 Ipv6Address ipv6Addr = Ipv6Address::GetAny (); |
1719 | 2067 |
1720 if (m_forceEtherType && Mac48Address::IsMatchingType (addr)) | 2068 if (m_forceEtherType && Mac48Address::IsMatchingType (addr)) |
1721 { | 2069 { |
1722 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac48Address::
ConvertFrom (addr)); | 2070 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac48Address::
ConvertFrom (addr)); |
1723 } | 2071 } |
1724 else | 2072 else |
1725 { | 2073 { |
1726 if (Mac64Address::IsMatchingType (addr)) | 2074 if (Mac64Address::IsMatchingType (addr)) |
1727 { | 2075 { |
1728 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac64Addre
ss::ConvertFrom (addr)); | 2076 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac64Addre
ss::ConvertFrom (addr)); |
1729 } | 2077 } |
1730 else if (Mac16Address::IsMatchingType (addr)) | 2078 else if (Mac16Address::IsMatchingType (addr)) |
1731 { | 2079 { |
1732 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac16Addre
ss::ConvertFrom (addr)); | 2080 ipv6Addr = Ipv6Address::MakeAutoconfiguredLinkLocalAddress (Mac16Addre
ss::ConvertFrom (addr)); |
1733 } | 2081 } |
1734 } | 2082 } |
1735 if (ipv6Addr.IsAny()) | 2083 if (ipv6Addr.IsAny ()) |
1736 { | 2084 { |
1737 NS_ABORT_MSG ("Unknown address type"); | 2085 NS_ABORT_MSG ("Unknown address type"); |
1738 } | 2086 } |
1739 return ipv6Addr; | 2087 return ipv6Addr; |
1740 } | 2088 } |
1741 | 2089 |
1742 Ipv6Address SixLowPanNetDevice::MakeGlobalAddressFromMac (Address const &addr, I
pv6Address prefix) | 2090 Ipv6Address SixLowPanNetDevice::MakeGlobalAddressFromMac (Address const &addr, I
pv6Address prefix) |
1743 { | 2091 { |
1744 Ipv6Address ipv6Addr = Ipv6Address::GetAny(); | 2092 Ipv6Address ipv6Addr = Ipv6Address::GetAny (); |
1745 | 2093 |
1746 if (m_forceEtherType && Mac48Address::IsMatchingType (addr)) | 2094 if (m_forceEtherType && Mac48Address::IsMatchingType (addr)) |
1747 { | 2095 { |
1748 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac48Address::ConvertFr
om (addr), Ipv6Address (prefix) ); | 2096 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac48Address::ConvertFr
om (addr), Ipv6Address (prefix) ); |
1749 } | 2097 } |
1750 else | 2098 else |
1751 { | 2099 { |
1752 if (Mac64Address::IsMatchingType (addr)) | 2100 if (Mac64Address::IsMatchingType (addr)) |
1753 { | 2101 { |
1754 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac64Address::Conve
rtFrom (addr), Ipv6Address (prefix)); | 2102 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac64Address::Conve
rtFrom (addr), Ipv6Address (prefix)); |
1755 } | 2103 } |
1756 else if (Mac16Address::IsMatchingType (addr)) | 2104 else if (Mac16Address::IsMatchingType (addr)) |
1757 { | 2105 { |
1758 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac16Address::Conve
rtFrom (addr), Ipv6Address (prefix) ); | 2106 ipv6Addr = Ipv6Address::MakeAutoconfiguredAddress (Mac16Address::Conve
rtFrom (addr), Ipv6Address (prefix) ); |
1759 } | 2107 } |
1760 } | 2108 } |
1761 if (ipv6Addr.IsAny()) | 2109 if (ipv6Addr.IsAny ()) |
1762 { | 2110 { |
1763 NS_ABORT_MSG ("Unknown address type"); | 2111 NS_ABORT_MSG ("Unknown address type"); |
1764 } | 2112 } |
1765 return ipv6Addr; | 2113 return ipv6Addr; |
1766 } | 2114 } |
1767 | 2115 |
1768 } | 2116 } |
1769 } | |
1770 | 2117 |
1771 // namespace ns3 | 2118 // namespace ns3 |
LEFT | RIGHT |