1*cfb92d14SAndroid Build Coastguard Worker /*
2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2016, The OpenThread Authors.
3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved.
4*cfb92d14SAndroid Build Coastguard Worker *
5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without
6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met:
7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright
8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer.
9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright
10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the
11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution.
12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the
13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products
14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission.
15*cfb92d14SAndroid Build Coastguard Worker *
16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17*cfb92d14SAndroid Build Coastguard Worker * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20*cfb92d14SAndroid Build Coastguard Worker * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21*cfb92d14SAndroid Build Coastguard Worker * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22*cfb92d14SAndroid Build Coastguard Worker * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23*cfb92d14SAndroid Build Coastguard Worker * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24*cfb92d14SAndroid Build Coastguard Worker * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25*cfb92d14SAndroid Build Coastguard Worker * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26*cfb92d14SAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE.
27*cfb92d14SAndroid Build Coastguard Worker */
28*cfb92d14SAndroid Build Coastguard Worker
29*cfb92d14SAndroid Build Coastguard Worker #include "test_lowpan.hpp"
30*cfb92d14SAndroid Build Coastguard Worker
31*cfb92d14SAndroid Build Coastguard Worker #include "test_platform.h"
32*cfb92d14SAndroid Build Coastguard Worker #include "test_util.hpp"
33*cfb92d14SAndroid Build Coastguard Worker
34*cfb92d14SAndroid Build Coastguard Worker namespace ot {
35*cfb92d14SAndroid Build Coastguard Worker
36*cfb92d14SAndroid Build Coastguard Worker Instance *sInstance;
37*cfb92d14SAndroid Build Coastguard Worker Ip6::Ip6 *sIp6;
38*cfb92d14SAndroid Build Coastguard Worker Lowpan::Lowpan *sLowpan;
39*cfb92d14SAndroid Build Coastguard Worker
GetCompressedStream(uint8_t * aIphc,uint16_t & aIphcLength)40*cfb92d14SAndroid Build Coastguard Worker void TestIphcVector::GetCompressedStream(uint8_t *aIphc, uint16_t &aIphcLength)
41*cfb92d14SAndroid Build Coastguard Worker {
42*cfb92d14SAndroid Build Coastguard Worker memcpy(aIphc, mIphcHeader.mData, mIphcHeader.mLength);
43*cfb92d14SAndroid Build Coastguard Worker memcpy(aIphc + mIphcHeader.mLength, mPayload.mData, mPayload.mLength);
44*cfb92d14SAndroid Build Coastguard Worker
45*cfb92d14SAndroid Build Coastguard Worker aIphcLength = mIphcHeader.mLength + mPayload.mLength;
46*cfb92d14SAndroid Build Coastguard Worker }
47*cfb92d14SAndroid Build Coastguard Worker
GetUncompressedStream(uint8_t * aIp6,uint16_t & aIp6Length)48*cfb92d14SAndroid Build Coastguard Worker void TestIphcVector::GetUncompressedStream(uint8_t *aIp6, uint16_t &aIp6Length)
49*cfb92d14SAndroid Build Coastguard Worker {
50*cfb92d14SAndroid Build Coastguard Worker aIp6Length = 0;
51*cfb92d14SAndroid Build Coastguard Worker
52*cfb92d14SAndroid Build Coastguard Worker memcpy(aIp6, reinterpret_cast<uint8_t *>(&mIpHeader), sizeof(mIpHeader));
53*cfb92d14SAndroid Build Coastguard Worker aIp6Length += sizeof(mIpHeader);
54*cfb92d14SAndroid Build Coastguard Worker
55*cfb92d14SAndroid Build Coastguard Worker if (mExtHeader.mLength)
56*cfb92d14SAndroid Build Coastguard Worker {
57*cfb92d14SAndroid Build Coastguard Worker memcpy(aIp6 + aIp6Length, mExtHeader.mData, mExtHeader.mLength);
58*cfb92d14SAndroid Build Coastguard Worker aIp6Length += mExtHeader.mLength;
59*cfb92d14SAndroid Build Coastguard Worker }
60*cfb92d14SAndroid Build Coastguard Worker
61*cfb92d14SAndroid Build Coastguard Worker if (mIpTunneledHeader.GetPayloadLength())
62*cfb92d14SAndroid Build Coastguard Worker {
63*cfb92d14SAndroid Build Coastguard Worker memcpy(aIp6 + aIp6Length, reinterpret_cast<uint8_t *>(&mIpTunneledHeader), sizeof(mIpTunneledHeader));
64*cfb92d14SAndroid Build Coastguard Worker aIp6Length += sizeof(mIpTunneledHeader);
65*cfb92d14SAndroid Build Coastguard Worker }
66*cfb92d14SAndroid Build Coastguard Worker
67*cfb92d14SAndroid Build Coastguard Worker if (mUdpHeader.GetLength())
68*cfb92d14SAndroid Build Coastguard Worker {
69*cfb92d14SAndroid Build Coastguard Worker memcpy(aIp6 + aIp6Length, reinterpret_cast<uint8_t *>(&mUdpHeader), sizeof(mUdpHeader));
70*cfb92d14SAndroid Build Coastguard Worker aIp6Length += sizeof(mUdpHeader);
71*cfb92d14SAndroid Build Coastguard Worker }
72*cfb92d14SAndroid Build Coastguard Worker
73*cfb92d14SAndroid Build Coastguard Worker memcpy(aIp6 + aIp6Length, mPayload.mData, mPayload.mLength);
74*cfb92d14SAndroid Build Coastguard Worker aIp6Length += mPayload.mLength;
75*cfb92d14SAndroid Build Coastguard Worker }
76*cfb92d14SAndroid Build Coastguard Worker
GetUncompressedStream(Message & aMessage)77*cfb92d14SAndroid Build Coastguard Worker void TestIphcVector::GetUncompressedStream(Message &aMessage)
78*cfb92d14SAndroid Build Coastguard Worker {
79*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(aMessage.Append(mIpHeader));
80*cfb92d14SAndroid Build Coastguard Worker
81*cfb92d14SAndroid Build Coastguard Worker if (mExtHeader.mLength)
82*cfb92d14SAndroid Build Coastguard Worker {
83*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(aMessage.AppendBytes(mExtHeader.mData, mExtHeader.mLength));
84*cfb92d14SAndroid Build Coastguard Worker }
85*cfb92d14SAndroid Build Coastguard Worker
86*cfb92d14SAndroid Build Coastguard Worker if (mIpTunneledHeader.GetPayloadLength())
87*cfb92d14SAndroid Build Coastguard Worker {
88*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(aMessage.Append(mIpTunneledHeader));
89*cfb92d14SAndroid Build Coastguard Worker }
90*cfb92d14SAndroid Build Coastguard Worker
91*cfb92d14SAndroid Build Coastguard Worker if (mUdpHeader.GetLength())
92*cfb92d14SAndroid Build Coastguard Worker {
93*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(aMessage.Append(mUdpHeader));
94*cfb92d14SAndroid Build Coastguard Worker }
95*cfb92d14SAndroid Build Coastguard Worker
96*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(aMessage.AppendBytes(mPayload.mData, mPayload.mLength));
97*cfb92d14SAndroid Build Coastguard Worker }
98*cfb92d14SAndroid Build Coastguard Worker
99*cfb92d14SAndroid Build Coastguard Worker /**
100*cfb92d14SAndroid Build Coastguard Worker * Initializes Thread Interface.
101*cfb92d14SAndroid Build Coastguard Worker *
102*cfb92d14SAndroid Build Coastguard Worker */
Init(void)103*cfb92d14SAndroid Build Coastguard Worker static void Init(void)
104*cfb92d14SAndroid Build Coastguard Worker {
105*cfb92d14SAndroid Build Coastguard Worker otMeshLocalPrefix meshLocalPrefix = {{0xfd, 0x00, 0xca, 0xfe, 0xfa, 0xce, 0x12, 0x34}};
106*cfb92d14SAndroid Build Coastguard Worker OffsetRange offsetRange;
107*cfb92d14SAndroid Build Coastguard Worker
108*cfb92d14SAndroid Build Coastguard Worker sInstance->Get<Mle::MleRouter>().SetMeshLocalPrefix(static_cast<Ip6::NetworkPrefix &>(meshLocalPrefix));
109*cfb92d14SAndroid Build Coastguard Worker
110*cfb92d14SAndroid Build Coastguard Worker // Emulate global prefixes with contextes.
111*cfb92d14SAndroid Build Coastguard Worker uint8_t mockNetworkData[] = {
112*cfb92d14SAndroid Build Coastguard Worker 0x0c, // MLE Network Data Type
113*cfb92d14SAndroid Build Coastguard Worker 0x20, // MLE Network Data Length
114*cfb92d14SAndroid Build Coastguard Worker
115*cfb92d14SAndroid Build Coastguard Worker // Prefix 2001:2:0:1::/64
116*cfb92d14SAndroid Build Coastguard Worker 0x03, 0x0e, // Prefix TLV
117*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x40, 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x07, 0x02, // 6LoWPAN Context ID TLV
118*cfb92d14SAndroid Build Coastguard Worker 0x11, 0x40, // Context ID = 1, C = TRUE
119*cfb92d14SAndroid Build Coastguard Worker
120*cfb92d14SAndroid Build Coastguard Worker // Prefix 2001:2:0:2::/64
121*cfb92d14SAndroid Build Coastguard Worker 0x03, 0x0e, // Prefix TLV
122*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x40, 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x07, 0x02, // 6LoWPAN Context ID TLV
123*cfb92d14SAndroid Build Coastguard Worker 0x02, 0x40 // Context ID = 2, C = FALSE
124*cfb92d14SAndroid Build Coastguard Worker };
125*cfb92d14SAndroid Build Coastguard Worker
126*cfb92d14SAndroid Build Coastguard Worker Message *message = sInstance->Get<MessagePool>().Allocate(Message::kTypeIp6);
127*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(message != nullptr, "Ip6::NewMessage failed");
128*cfb92d14SAndroid Build Coastguard Worker
129*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(message->AppendBytes(mockNetworkData, sizeof(mockNetworkData)));
130*cfb92d14SAndroid Build Coastguard Worker
131*cfb92d14SAndroid Build Coastguard Worker offsetRange.Init(2, 0x20);
132*cfb92d14SAndroid Build Coastguard Worker
133*cfb92d14SAndroid Build Coastguard Worker IgnoreError(
134*cfb92d14SAndroid Build Coastguard Worker sInstance->Get<NetworkData::Leader>().SetNetworkData(0, 0, NetworkData::kStableSubset, *message, offsetRange));
135*cfb92d14SAndroid Build Coastguard Worker }
136*cfb92d14SAndroid Build Coastguard Worker
137*cfb92d14SAndroid Build Coastguard Worker /**
138*cfb92d14SAndroid Build Coastguard Worker * Performs compression or/and decompression based on the given test vector.
139*cfb92d14SAndroid Build Coastguard Worker *
140*cfb92d14SAndroid Build Coastguard Worker * @note Performing decompression and compression on the same LOWPAN_IPHC frame may give different result.
141*cfb92d14SAndroid Build Coastguard Worker * This situation may occur when sender does not use the best possible compression,
142*cfb92d14SAndroid Build Coastguard Worker * e.g. doesn't use LOWPAN_NHC for UDP - which is still valid.
143*cfb92d14SAndroid Build Coastguard Worker *
144*cfb92d14SAndroid Build Coastguard Worker * @param aVector Test vector that has to be tested.
145*cfb92d14SAndroid Build Coastguard Worker * @param aCompress Set to TRUE, if compression should be tested.
146*cfb92d14SAndroid Build Coastguard Worker * @param aDecompress Set to TRUE, if decomrpession should be tested.
147*cfb92d14SAndroid Build Coastguard Worker */
Test(TestIphcVector & aVector,bool aCompress,bool aDecompress)148*cfb92d14SAndroid Build Coastguard Worker static void Test(TestIphcVector &aVector, bool aCompress, bool aDecompress)
149*cfb92d14SAndroid Build Coastguard Worker {
150*cfb92d14SAndroid Build Coastguard Worker Message *message = nullptr;
151*cfb92d14SAndroid Build Coastguard Worker uint8_t result[512];
152*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[512];
153*cfb92d14SAndroid Build Coastguard Worker uint8_t ip6[512];
154*cfb92d14SAndroid Build Coastguard Worker uint16_t iphcLength;
155*cfb92d14SAndroid Build Coastguard Worker uint16_t ip6Length;
156*cfb92d14SAndroid Build Coastguard Worker FrameData frameData;
157*cfb92d14SAndroid Build Coastguard Worker Error error;
158*cfb92d14SAndroid Build Coastguard Worker
159*cfb92d14SAndroid Build Coastguard Worker aVector.GetCompressedStream(iphc, iphcLength);
160*cfb92d14SAndroid Build Coastguard Worker aVector.GetUncompressedStream(ip6, ip6Length);
161*cfb92d14SAndroid Build Coastguard Worker
162*cfb92d14SAndroid Build Coastguard Worker printf("\n=== Test name: %s ===\n\n", aVector.mTestName);
163*cfb92d14SAndroid Build Coastguard Worker
164*cfb92d14SAndroid Build Coastguard Worker printf("Expected error -------------- %s\n", aVector.mError ? "yes" : "no");
165*cfb92d14SAndroid Build Coastguard Worker printf("UDP present ----------------- %s\n", aVector.mUdpHeader.GetLength() ? "yes" : "no");
166*cfb92d14SAndroid Build Coastguard Worker printf("Extension Headers present --- %s\n", aVector.mExtHeader.mLength ? "yes" : "no");
167*cfb92d14SAndroid Build Coastguard Worker printf("IP-in-IP present ------------ %s\n", aVector.mIpTunneledHeader.GetPayloadLength() ? "yes" : "no");
168*cfb92d14SAndroid Build Coastguard Worker printf("LOWPAN_IPHC length ---------- %d\n", aVector.mIphcHeader.mLength);
169*cfb92d14SAndroid Build Coastguard Worker printf("IPv6 uncompressed offset ---- %d\n\n", aVector.mPayloadOffset);
170*cfb92d14SAndroid Build Coastguard Worker
171*cfb92d14SAndroid Build Coastguard Worker DumpBuffer("Expected IPv6 uncompressed packet", ip6, ip6Length);
172*cfb92d14SAndroid Build Coastguard Worker DumpBuffer("Expected LOWPAN_IPHC compressed frame", iphc, iphcLength);
173*cfb92d14SAndroid Build Coastguard Worker
174*cfb92d14SAndroid Build Coastguard Worker if (aCompress)
175*cfb92d14SAndroid Build Coastguard Worker {
176*cfb92d14SAndroid Build Coastguard Worker FrameBuilder frameBuilder;
177*cfb92d14SAndroid Build Coastguard Worker Message *compressedMsg;
178*cfb92d14SAndroid Build Coastguard Worker Ip6::Ecn ecn;
179*cfb92d14SAndroid Build Coastguard Worker
180*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(result, 127);
181*cfb92d14SAndroid Build Coastguard Worker
182*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit((message = sInstance->Get<MessagePool>().Allocate(Message::kTypeIp6)) != nullptr);
183*cfb92d14SAndroid Build Coastguard Worker
184*cfb92d14SAndroid Build Coastguard Worker aVector.GetUncompressedStream(*message);
185*cfb92d14SAndroid Build Coastguard Worker
186*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(sLowpan->Compress(*message, aVector.mMacAddrs, frameBuilder) == aVector.mError);
187*cfb92d14SAndroid Build Coastguard Worker
188*cfb92d14SAndroid Build Coastguard Worker if (aVector.mError == kErrorNone)
189*cfb92d14SAndroid Build Coastguard Worker {
190*cfb92d14SAndroid Build Coastguard Worker uint16_t compressBytes = frameBuilder.GetLength();
191*cfb92d14SAndroid Build Coastguard Worker
192*cfb92d14SAndroid Build Coastguard Worker // Append payload to the LOWPAN_IPHC.
193*cfb92d14SAndroid Build Coastguard Worker message->ReadBytes(message->GetOffset(), result + compressBytes,
194*cfb92d14SAndroid Build Coastguard Worker message->GetLength() - message->GetOffset());
195*cfb92d14SAndroid Build Coastguard Worker
196*cfb92d14SAndroid Build Coastguard Worker DumpBuffer("Resulted LOWPAN_IPHC compressed frame", result,
197*cfb92d14SAndroid Build Coastguard Worker compressBytes + message->GetLength() - message->GetOffset());
198*cfb92d14SAndroid Build Coastguard Worker
199*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(compressBytes == aVector.mIphcHeader.mLength, "Lowpan::Compress failed");
200*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(message->GetOffset() == aVector.mPayloadOffset, "Lowpan::Compress failed");
201*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(iphc, result, iphcLength) == 0, "Lowpan::Compress failed");
202*cfb92d14SAndroid Build Coastguard Worker
203*cfb92d14SAndroid Build Coastguard Worker // Validate `DecompressEcn()` and `MarkCompressedEcn()`
204*cfb92d14SAndroid Build Coastguard Worker
205*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit((compressedMsg = sInstance->Get<MessagePool>().Allocate(Message::kTypeIp6)) != nullptr);
206*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(compressedMsg->AppendBytes(result, compressBytes));
207*cfb92d14SAndroid Build Coastguard Worker
208*cfb92d14SAndroid Build Coastguard Worker ecn = sLowpan->DecompressEcn(*compressedMsg, /* aOffset */ 0);
209*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(ecn == aVector.GetIpHeader().GetEcn());
210*cfb92d14SAndroid Build Coastguard Worker printf("Decompressed ECN is %d\n", ecn);
211*cfb92d14SAndroid Build Coastguard Worker
212*cfb92d14SAndroid Build Coastguard Worker if (ecn != Ip6::kEcnNotCapable)
213*cfb92d14SAndroid Build Coastguard Worker {
214*cfb92d14SAndroid Build Coastguard Worker sLowpan->MarkCompressedEcn(*compressedMsg, /*a aOffset */ 0);
215*cfb92d14SAndroid Build Coastguard Worker ecn = sLowpan->DecompressEcn(*compressedMsg, /* aOffset */ 0);
216*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(ecn == Ip6::kEcnMarked);
217*cfb92d14SAndroid Build Coastguard Worker printf("ECN is updated to %d\n", ecn);
218*cfb92d14SAndroid Build Coastguard Worker }
219*cfb92d14SAndroid Build Coastguard Worker
220*cfb92d14SAndroid Build Coastguard Worker compressedMsg->Free();
221*cfb92d14SAndroid Build Coastguard Worker }
222*cfb92d14SAndroid Build Coastguard Worker
223*cfb92d14SAndroid Build Coastguard Worker message->Free();
224*cfb92d14SAndroid Build Coastguard Worker message = nullptr;
225*cfb92d14SAndroid Build Coastguard Worker }
226*cfb92d14SAndroid Build Coastguard Worker
227*cfb92d14SAndroid Build Coastguard Worker if (aDecompress)
228*cfb92d14SAndroid Build Coastguard Worker {
229*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit((message = sInstance->Get<MessagePool>().Allocate(Message::kTypeIp6)) != nullptr);
230*cfb92d14SAndroid Build Coastguard Worker
231*cfb92d14SAndroid Build Coastguard Worker frameData.Init(iphc, iphcLength);
232*cfb92d14SAndroid Build Coastguard Worker
233*cfb92d14SAndroid Build Coastguard Worker error = sLowpan->Decompress(*message, aVector.mMacAddrs, frameData, 0);
234*cfb92d14SAndroid Build Coastguard Worker
235*cfb92d14SAndroid Build Coastguard Worker message->ReadBytes(0, result, message->GetLength());
236*cfb92d14SAndroid Build Coastguard Worker
237*cfb92d14SAndroid Build Coastguard Worker if (aVector.mError == kErrorNone)
238*cfb92d14SAndroid Build Coastguard Worker {
239*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(error, "Lowpan::Decompress failed");
240*cfb92d14SAndroid Build Coastguard Worker
241*cfb92d14SAndroid Build Coastguard Worker // Append payload to the IPv6 Packet.
242*cfb92d14SAndroid Build Coastguard Worker memcpy(result + message->GetLength(), frameData.GetBytes(), frameData.GetLength());
243*cfb92d14SAndroid Build Coastguard Worker
244*cfb92d14SAndroid Build Coastguard Worker DumpBuffer("Resulted IPv6 uncompressed packet", result, message->GetLength() + frameData.GetLength());
245*cfb92d14SAndroid Build Coastguard Worker
246*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit((frameData.GetBytes() - iphc) == aVector.mIphcHeader.mLength, "Lowpan::Decompress failed");
247*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(message->GetOffset() == aVector.mPayloadOffset, "Lowpan::Decompress failed");
248*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(message->GetOffset() == message->GetLength(), "Lowpan::Decompress failed");
249*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(ip6, result, ip6Length) == 0, "Lowpan::Decompress failed");
250*cfb92d14SAndroid Build Coastguard Worker }
251*cfb92d14SAndroid Build Coastguard Worker else
252*cfb92d14SAndroid Build Coastguard Worker {
253*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(error == kErrorParse, "Lowpan::Decompress failed");
254*cfb92d14SAndroid Build Coastguard Worker }
255*cfb92d14SAndroid Build Coastguard Worker
256*cfb92d14SAndroid Build Coastguard Worker message->Free();
257*cfb92d14SAndroid Build Coastguard Worker message = nullptr;
258*cfb92d14SAndroid Build Coastguard Worker }
259*cfb92d14SAndroid Build Coastguard Worker
260*cfb92d14SAndroid Build Coastguard Worker printf("PASS\n\n");
261*cfb92d14SAndroid Build Coastguard Worker }
262*cfb92d14SAndroid Build Coastguard Worker
263*cfb92d14SAndroid Build Coastguard Worker /***************************************************************************************************
264*cfb92d14SAndroid Build Coastguard Worker * @section Test constants.
265*cfb92d14SAndroid Build Coastguard Worker **************************************************************************************************/
266*cfb92d14SAndroid Build Coastguard Worker static const uint8_t sTestMacSourceDefaultLong[] = {0x00, 0x00, 0x5e, 0xef, 0x10, 0x22, 0x11, 0x00};
267*cfb92d14SAndroid Build Coastguard Worker static const uint8_t sTestMacDestinationDefaultLong[] = {0x00, 0x00, 0x5e, 0xef, 0x10, 0xaa, 0xbb, 0xcc};
268*cfb92d14SAndroid Build Coastguard Worker
269*cfb92d14SAndroid Build Coastguard Worker static uint16_t sTestMacSourceDefaultShort = 0x0000;
270*cfb92d14SAndroid Build Coastguard Worker static uint16_t sTestMacDestinationDefaultShort = 0xc003;
271*cfb92d14SAndroid Build Coastguard Worker static uint16_t sTestMacDestinationBroadcast = 0xffff;
272*cfb92d14SAndroid Build Coastguard Worker
273*cfb92d14SAndroid Build Coastguard Worker static const uint8_t sTestPayloadDefault[] = {0x80, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
274*cfb92d14SAndroid Build Coastguard Worker
275*cfb92d14SAndroid Build Coastguard Worker /***************************************************************************************************
276*cfb92d14SAndroid Build Coastguard Worker * @section Test cases.
277*cfb92d14SAndroid Build Coastguard Worker **************************************************************************************************/
278*cfb92d14SAndroid Build Coastguard Worker
TestFullyCompressableLongAddresses(void)279*cfb92d14SAndroid Build Coastguard Worker static void TestFullyCompressableLongAddresses(void)
280*cfb92d14SAndroid Build Coastguard Worker {
281*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 addresses using long MAC addresses");
282*cfb92d14SAndroid Build Coastguard Worker
283*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
284*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
285*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
286*cfb92d14SAndroid Build Coastguard Worker
287*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
288*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
289*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
290*cfb92d14SAndroid Build Coastguard Worker
291*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
292*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x33, 0x3a};
293*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
294*cfb92d14SAndroid Build Coastguard Worker
295*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
296*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
297*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
298*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
299*cfb92d14SAndroid Build Coastguard Worker
300*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
301*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
302*cfb92d14SAndroid Build Coastguard Worker }
303*cfb92d14SAndroid Build Coastguard Worker
TestFullyCompressableShortAddresses(void)304*cfb92d14SAndroid Build Coastguard Worker static void TestFullyCompressableShortAddresses(void)
305*cfb92d14SAndroid Build Coastguard Worker {
306*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 addresses using short MAC addresses");
307*cfb92d14SAndroid Build Coastguard Worker
308*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
309*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
310*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
311*cfb92d14SAndroid Build Coastguard Worker
312*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
313*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::ff:fe00:0000",
314*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
315*cfb92d14SAndroid Build Coastguard Worker
316*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
317*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x33, 0x3a};
318*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
319*cfb92d14SAndroid Build Coastguard Worker
320*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
321*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
322*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
323*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
324*cfb92d14SAndroid Build Coastguard Worker
325*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
326*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
327*cfb92d14SAndroid Build Coastguard Worker }
328*cfb92d14SAndroid Build Coastguard Worker
TestFullyCompressableShortLongAddresses(void)329*cfb92d14SAndroid Build Coastguard Worker static void TestFullyCompressableShortLongAddresses(void)
330*cfb92d14SAndroid Build Coastguard Worker {
331*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 addresses using short and long MAC addresses");
332*cfb92d14SAndroid Build Coastguard Worker
333*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
334*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
335*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
336*cfb92d14SAndroid Build Coastguard Worker
337*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
338*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::ff:fe00:0000",
339*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
340*cfb92d14SAndroid Build Coastguard Worker
341*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
342*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x33, 0x3a};
343*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
344*cfb92d14SAndroid Build Coastguard Worker
345*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
346*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
347*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
348*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
349*cfb92d14SAndroid Build Coastguard Worker
350*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
351*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
352*cfb92d14SAndroid Build Coastguard Worker }
353*cfb92d14SAndroid Build Coastguard Worker
TestFullyCompressableLongShortAddresses(void)354*cfb92d14SAndroid Build Coastguard Worker static void TestFullyCompressableLongShortAddresses(void)
355*cfb92d14SAndroid Build Coastguard Worker {
356*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 addresses using long and short MAC addresses");
357*cfb92d14SAndroid Build Coastguard Worker
358*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
359*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
360*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
361*cfb92d14SAndroid Build Coastguard Worker
362*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
363*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
364*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
365*cfb92d14SAndroid Build Coastguard Worker
366*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
367*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x33, 0x3a};
368*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
369*cfb92d14SAndroid Build Coastguard Worker
370*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
371*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
372*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
373*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
374*cfb92d14SAndroid Build Coastguard Worker
375*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
376*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
377*cfb92d14SAndroid Build Coastguard Worker }
378*cfb92d14SAndroid Build Coastguard Worker
TestSourceUnspecifiedAddress(void)379*cfb92d14SAndroid Build Coastguard Worker static void TestSourceUnspecifiedAddress(void)
380*cfb92d14SAndroid Build Coastguard Worker {
381*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Unspecified source IPv6 address");
382*cfb92d14SAndroid Build Coastguard Worker
383*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
384*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
385*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
386*cfb92d14SAndroid Build Coastguard Worker
387*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
388*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "::", "fe80::ff:fe00:c003");
389*cfb92d14SAndroid Build Coastguard Worker
390*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
391*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x43, 0x3a};
392*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
393*cfb92d14SAndroid Build Coastguard Worker
394*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
395*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
396*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
397*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
398*cfb92d14SAndroid Build Coastguard Worker
399*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
400*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
401*cfb92d14SAndroid Build Coastguard Worker }
402*cfb92d14SAndroid Build Coastguard Worker
TestSource128bitDestination128bitAddresses(void)403*cfb92d14SAndroid Build Coastguard Worker static void TestSource128bitDestination128bitAddresses(void)
404*cfb92d14SAndroid Build Coastguard Worker {
405*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IPv6 addresses inline");
406*cfb92d14SAndroid Build Coastguard Worker
407*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
408*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
409*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
410*cfb92d14SAndroid Build Coastguard Worker
411*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
412*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
413*cfb92d14SAndroid Build Coastguard Worker "2001:2:0:3:aaaa:bbbb:cccc:dddd", "2001:2:0:4::");
414*cfb92d14SAndroid Build Coastguard Worker
415*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
416*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x00, 0x3a, 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0xaa,
417*cfb92d14SAndroid Build Coastguard Worker 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0x20, 0x01, 0x00, 0x02, 0x00,
418*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
419*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
420*cfb92d14SAndroid Build Coastguard Worker
421*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
422*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
423*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
424*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
425*cfb92d14SAndroid Build Coastguard Worker
426*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
427*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
428*cfb92d14SAndroid Build Coastguard Worker }
429*cfb92d14SAndroid Build Coastguard Worker
TestSource64bitDestination64bitLongAddresses(void)430*cfb92d14SAndroid Build Coastguard Worker static void TestSource64bitDestination64bitLongAddresses(void)
431*cfb92d14SAndroid Build Coastguard Worker {
432*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IPv6 addresses 64-bit using long MAC addresses");
433*cfb92d14SAndroid Build Coastguard Worker
434*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
435*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
436*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
437*cfb92d14SAndroid Build Coastguard Worker
438*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
439*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1101",
440*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcd");
441*cfb92d14SAndroid Build Coastguard Worker
442*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
443*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x11, 0x3a, 0x02, 0x00, 0x5e, 0xef, 0x10, 0x22, 0x11,
444*cfb92d14SAndroid Build Coastguard Worker 0x01, 0x02, 0x00, 0x5e, 0xef, 0x10, 0xaa, 0xbb, 0xcd};
445*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
446*cfb92d14SAndroid Build Coastguard Worker
447*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
448*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
449*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
450*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
451*cfb92d14SAndroid Build Coastguard Worker
452*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
453*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
454*cfb92d14SAndroid Build Coastguard Worker }
455*cfb92d14SAndroid Build Coastguard Worker
TestSource64bitDestination64bitShortAddresses(void)456*cfb92d14SAndroid Build Coastguard Worker static void TestSource64bitDestination64bitShortAddresses(void)
457*cfb92d14SAndroid Build Coastguard Worker {
458*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IPv6 addresses 64-bit using short MAC addresses");
459*cfb92d14SAndroid Build Coastguard Worker
460*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
461*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
462*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
463*cfb92d14SAndroid Build Coastguard Worker
464*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
465*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1101",
466*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcd");
467*cfb92d14SAndroid Build Coastguard Worker
468*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
469*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x11, 0x3a, 0x02, 0x00, 0x5e, 0xef, 0x10, 0x22, 0x11,
470*cfb92d14SAndroid Build Coastguard Worker 0x01, 0x02, 0x00, 0x5e, 0xef, 0x10, 0xaa, 0xbb, 0xcd};
471*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
472*cfb92d14SAndroid Build Coastguard Worker
473*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
474*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
475*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
476*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
477*cfb92d14SAndroid Build Coastguard Worker
478*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
479*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
480*cfb92d14SAndroid Build Coastguard Worker }
481*cfb92d14SAndroid Build Coastguard Worker
TestSource16bitDestination16bitAddresses(void)482*cfb92d14SAndroid Build Coastguard Worker static void TestSource16bitDestination16bitAddresses(void)
483*cfb92d14SAndroid Build Coastguard Worker {
484*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IPv6 addresses 16-bit using short MAC addresses");
485*cfb92d14SAndroid Build Coastguard Worker
486*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
487*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
488*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
489*cfb92d14SAndroid Build Coastguard Worker
490*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
491*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::ff:fe00:0001",
492*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c004");
493*cfb92d14SAndroid Build Coastguard Worker
494*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
495*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x22, 0x3a, 0x00, 0x01, 0xc0, 0x04};
496*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
497*cfb92d14SAndroid Build Coastguard Worker
498*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
499*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
500*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
501*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
502*cfb92d14SAndroid Build Coastguard Worker
503*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
504*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
505*cfb92d14SAndroid Build Coastguard Worker }
506*cfb92d14SAndroid Build Coastguard Worker
TestSourceCompressedDestination16bitAddresses(void)507*cfb92d14SAndroid Build Coastguard Worker static void TestSourceCompressedDestination16bitAddresses(void)
508*cfb92d14SAndroid Build Coastguard Worker {
509*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 source and destination 16-bit using long MAC addresses");
510*cfb92d14SAndroid Build Coastguard Worker
511*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
512*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
513*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
514*cfb92d14SAndroid Build Coastguard Worker
515*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
516*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
517*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:beaf");
518*cfb92d14SAndroid Build Coastguard Worker
519*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
520*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x32, 0x3a, 0xbe, 0xaf};
521*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
522*cfb92d14SAndroid Build Coastguard Worker
523*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
524*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
525*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
526*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
527*cfb92d14SAndroid Build Coastguard Worker
528*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
529*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
530*cfb92d14SAndroid Build Coastguard Worker }
531*cfb92d14SAndroid Build Coastguard Worker
TestSourceCompressedDestination128bitAddresses(void)532*cfb92d14SAndroid Build Coastguard Worker static void TestSourceCompressedDestination128bitAddresses(void)
533*cfb92d14SAndroid Build Coastguard Worker {
534*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Fully compressible IPv6 source and destination inline using long MAC addresses");
535*cfb92d14SAndroid Build Coastguard Worker
536*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
537*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
538*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
539*cfb92d14SAndroid Build Coastguard Worker
540*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
541*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
542*cfb92d14SAndroid Build Coastguard Worker "2001:2:0:4::");
543*cfb92d14SAndroid Build Coastguard Worker
544*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
545*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x30, 0x3a, 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
546*cfb92d14SAndroid Build Coastguard Worker 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
547*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
548*cfb92d14SAndroid Build Coastguard Worker
549*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
550*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
551*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
552*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
553*cfb92d14SAndroid Build Coastguard Worker
554*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
555*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
556*cfb92d14SAndroid Build Coastguard Worker }
557*cfb92d14SAndroid Build Coastguard Worker
TestMulticast128bitAddress(void)558*cfb92d14SAndroid Build Coastguard Worker static void TestMulticast128bitAddress(void)
559*cfb92d14SAndroid Build Coastguard Worker {
560*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Multicast address inline");
561*cfb92d14SAndroid Build Coastguard Worker
562*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
563*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
564*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
565*cfb92d14SAndroid Build Coastguard Worker
566*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
567*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
568*cfb92d14SAndroid Build Coastguard Worker "ff05::100:0030:0001");
569*cfb92d14SAndroid Build Coastguard Worker
570*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
571*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x38, 0x3a, 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
572*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x30, 0x00, 0x01};
573*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
574*cfb92d14SAndroid Build Coastguard Worker
575*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
576*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
577*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
578*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
579*cfb92d14SAndroid Build Coastguard Worker
580*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
581*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
582*cfb92d14SAndroid Build Coastguard Worker }
583*cfb92d14SAndroid Build Coastguard Worker
TestMulticast48bitAddress(void)584*cfb92d14SAndroid Build Coastguard Worker static void TestMulticast48bitAddress(void)
585*cfb92d14SAndroid Build Coastguard Worker {
586*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Multicast address 48-bit");
587*cfb92d14SAndroid Build Coastguard Worker
588*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
589*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
590*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
591*cfb92d14SAndroid Build Coastguard Worker
592*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
593*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
594*cfb92d14SAndroid Build Coastguard Worker "ff05::1:0030:0001");
595*cfb92d14SAndroid Build Coastguard Worker
596*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
597*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x39, 0x3a, 0x05, 0x01, 0x00, 0x30, 0x00, 0x01};
598*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
599*cfb92d14SAndroid Build Coastguard Worker
600*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
601*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
602*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
603*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
604*cfb92d14SAndroid Build Coastguard Worker
605*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
606*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
607*cfb92d14SAndroid Build Coastguard Worker }
608*cfb92d14SAndroid Build Coastguard Worker
TestMulticast32bitAddress(void)609*cfb92d14SAndroid Build Coastguard Worker static void TestMulticast32bitAddress(void)
610*cfb92d14SAndroid Build Coastguard Worker {
611*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Multicast address 32-bit");
612*cfb92d14SAndroid Build Coastguard Worker
613*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
614*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
615*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
616*cfb92d14SAndroid Build Coastguard Worker
617*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
618*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
619*cfb92d14SAndroid Build Coastguard Worker "ff03::fc");
620*cfb92d14SAndroid Build Coastguard Worker
621*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
622*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x1a, 0x3a, 0x02, 0x00, 0x5e, 0xef, 0x10, 0x22, 0x11, 0x00, 0x03, 0x00, 0x00, 0xfc};
623*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
624*cfb92d14SAndroid Build Coastguard Worker
625*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
626*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
627*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
628*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
629*cfb92d14SAndroid Build Coastguard Worker
630*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
631*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
632*cfb92d14SAndroid Build Coastguard Worker }
633*cfb92d14SAndroid Build Coastguard Worker
TestMulticast8bitAddress(void)634*cfb92d14SAndroid Build Coastguard Worker static void TestMulticast8bitAddress(void)
635*cfb92d14SAndroid Build Coastguard Worker {
636*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Multicast address 8-bit");
637*cfb92d14SAndroid Build Coastguard Worker
638*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
639*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
640*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
641*cfb92d14SAndroid Build Coastguard Worker
642*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
643*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
644*cfb92d14SAndroid Build Coastguard Worker "ff02::2");
645*cfb92d14SAndroid Build Coastguard Worker
646*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
647*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x3b, 0x3a, 0x02};
648*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
649*cfb92d14SAndroid Build Coastguard Worker
650*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
651*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
652*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
653*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
654*cfb92d14SAndroid Build Coastguard Worker
655*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
656*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
657*cfb92d14SAndroid Build Coastguard Worker }
658*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSource64bitDestination64bitContext0(void)659*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSource64bitDestination64bitContext0(void)
660*cfb92d14SAndroid Build Coastguard Worker {
661*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source and destination addresses 64-bit, context 0");
662*cfb92d14SAndroid Build Coastguard Worker
663*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
664*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
665*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
666*cfb92d14SAndroid Build Coastguard Worker
667*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
668*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
669*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234:abcd:ef01:2345:6789", "fd00:cafe:face:1234:c31d:a702:0d41:beef");
670*cfb92d14SAndroid Build Coastguard Worker
671*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
672*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x55, 0x3a, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67,
673*cfb92d14SAndroid Build Coastguard Worker 0x89, 0xc3, 0x1d, 0xa7, 0x02, 0x0d, 0x41, 0xbe, 0xef};
674*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
675*cfb92d14SAndroid Build Coastguard Worker
676*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
677*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
678*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
679*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
680*cfb92d14SAndroid Build Coastguard Worker
681*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
682*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
683*cfb92d14SAndroid Build Coastguard Worker }
684*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSource64bitDestination64bitContext0IfContextInLine(void)685*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSource64bitDestination64bitContext0IfContextInLine(void)
686*cfb92d14SAndroid Build Coastguard Worker {
687*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source and destination addresses 64-bit, context 0 inline");
688*cfb92d14SAndroid Build Coastguard Worker
689*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
690*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
691*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
692*cfb92d14SAndroid Build Coastguard Worker
693*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
694*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
695*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234:abcd:ef01:2345:6789", "fd00:cafe:face:1234:c31d:a702:0d41:beef");
696*cfb92d14SAndroid Build Coastguard Worker
697*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
698*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0xd5, 0x00, 0x3a, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45,
699*cfb92d14SAndroid Build Coastguard Worker 0x67, 0x89, 0xc3, 0x1d, 0xa7, 0x02, 0x0d, 0x41, 0xbe, 0xef};
700*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
701*cfb92d14SAndroid Build Coastguard Worker
702*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
703*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
704*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
705*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
706*cfb92d14SAndroid Build Coastguard Worker
707*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test only.
708*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
709*cfb92d14SAndroid Build Coastguard Worker }
710*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSource16bitDestination16bitContext0(void)711*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSource16bitDestination16bitContext0(void)
712*cfb92d14SAndroid Build Coastguard Worker {
713*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source and destination addresses 16-bit, context 0");
714*cfb92d14SAndroid Build Coastguard Worker
715*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
716*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
717*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
718*cfb92d14SAndroid Build Coastguard Worker
719*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
720*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
721*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:fffc", "fd00:cafe:face:1234::ff:fe00:fffe");
722*cfb92d14SAndroid Build Coastguard Worker
723*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
724*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x66, 0x3a, 0xff, 0xfc, 0xff, 0xfe};
725*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
726*cfb92d14SAndroid Build Coastguard Worker
727*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
728*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
729*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
730*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
731*cfb92d14SAndroid Build Coastguard Worker
732*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
733*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
734*cfb92d14SAndroid Build Coastguard Worker }
735*cfb92d14SAndroid Build Coastguard Worker
TestStatefulCompressableLongAddressesContext0(void)736*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulCompressableLongAddressesContext0(void)
737*cfb92d14SAndroid Build Coastguard Worker {
738*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression compressible long addresses, context 0");
739*cfb92d14SAndroid Build Coastguard Worker
740*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
741*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
742*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
743*cfb92d14SAndroid Build Coastguard Worker
744*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
745*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
746*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234:0200:5eef:1022:1100", "fd00:cafe:face:1234:0200:5eef:10aa:bbcc");
747*cfb92d14SAndroid Build Coastguard Worker
748*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
749*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x77, 0x3a};
750*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
751*cfb92d14SAndroid Build Coastguard Worker
752*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
753*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
754*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
755*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
756*cfb92d14SAndroid Build Coastguard Worker
757*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
758*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
759*cfb92d14SAndroid Build Coastguard Worker }
760*cfb92d14SAndroid Build Coastguard Worker
TestStatefulCompressableShortAddressesContext0(void)761*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulCompressableShortAddressesContext0(void)
762*cfb92d14SAndroid Build Coastguard Worker {
763*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression compressible short addresses, context 0");
764*cfb92d14SAndroid Build Coastguard Worker
765*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
766*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
767*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
768*cfb92d14SAndroid Build Coastguard Worker
769*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
770*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
771*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "fd00:cafe:face:1234::ff:fe00:c003");
772*cfb92d14SAndroid Build Coastguard Worker
773*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
774*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x77, 0x3a};
775*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
776*cfb92d14SAndroid Build Coastguard Worker
777*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
778*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
779*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
780*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
781*cfb92d14SAndroid Build Coastguard Worker
782*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
783*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
784*cfb92d14SAndroid Build Coastguard Worker }
785*cfb92d14SAndroid Build Coastguard Worker
TestStatefulCompressableLongShortAddressesContext0(void)786*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulCompressableLongShortAddressesContext0(void)
787*cfb92d14SAndroid Build Coastguard Worker {
788*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression compressible long and short addresses, context 0");
789*cfb92d14SAndroid Build Coastguard Worker
790*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
791*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
792*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
793*cfb92d14SAndroid Build Coastguard Worker
794*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
795*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
796*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234:0200:5eef:1022:1100", "fd00:cafe:face:1234::ff:fe00:c003");
797*cfb92d14SAndroid Build Coastguard Worker
798*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
799*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x77, 0x3a};
800*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
801*cfb92d14SAndroid Build Coastguard Worker
802*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
803*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
804*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
805*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
806*cfb92d14SAndroid Build Coastguard Worker
807*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
808*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
809*cfb92d14SAndroid Build Coastguard Worker }
810*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSource64bitDestination128bitContext1(void)811*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSource64bitDestination128bitContext1(void)
812*cfb92d14SAndroid Build Coastguard Worker {
813*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source addresses 64-bit and destination inline, context 1");
814*cfb92d14SAndroid Build Coastguard Worker
815*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
816*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
817*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
818*cfb92d14SAndroid Build Coastguard Worker
819*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
820*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
821*cfb92d14SAndroid Build Coastguard Worker "2001:2:0:1:abcd:ef01:2345:6789", "2001:2:0:3:c31d:a702:0d41:beef");
822*cfb92d14SAndroid Build Coastguard Worker
823*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
824*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0xd0, 0x10, 0x3a, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0x20, 0x01,
825*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0xc3, 0x1d, 0xa7, 0x02, 0x0d, 0x41, 0xbe, 0xef};
826*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
827*cfb92d14SAndroid Build Coastguard Worker
828*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
829*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
830*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
831*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
832*cfb92d14SAndroid Build Coastguard Worker
833*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
834*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
835*cfb92d14SAndroid Build Coastguard Worker }
836*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSource64bitDestination64bitContext1(void)837*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSource64bitDestination64bitContext1(void)
838*cfb92d14SAndroid Build Coastguard Worker {
839*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source and destination addresses 64-bit, context 1");
840*cfb92d14SAndroid Build Coastguard Worker
841*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
842*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
843*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
844*cfb92d14SAndroid Build Coastguard Worker
845*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
846*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
847*cfb92d14SAndroid Build Coastguard Worker "2001:2:0:1:abcd:ef01:2345:6789", "2001:2:0:1:c31d:a702:0d41:beef");
848*cfb92d14SAndroid Build Coastguard Worker
849*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
850*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0xd5, 0x11, 0x3a, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45,
851*cfb92d14SAndroid Build Coastguard Worker 0x67, 0x89, 0xc3, 0x1d, 0xa7, 0x02, 0x0d, 0x41, 0xbe, 0xef};
852*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
853*cfb92d14SAndroid Build Coastguard Worker
854*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
855*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
856*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
857*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
858*cfb92d14SAndroid Build Coastguard Worker
859*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
860*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
861*cfb92d14SAndroid Build Coastguard Worker }
862*cfb92d14SAndroid Build Coastguard Worker
TestStatefulSourceDestinationInlineContext2CIDFalse(void)863*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulSourceDestinationInlineContext2CIDFalse(void)
864*cfb92d14SAndroid Build Coastguard Worker {
865*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression source and destination addresses inline, context 2 (C=FALSE)");
866*cfb92d14SAndroid Build Coastguard Worker
867*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
868*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
869*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
870*cfb92d14SAndroid Build Coastguard Worker
871*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
872*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
873*cfb92d14SAndroid Build Coastguard Worker "2001:2:0:2:abcd:ef01:2345:6789", "2001:2:0:2:c31d:a702:0d41:beef");
874*cfb92d14SAndroid Build Coastguard Worker
875*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
876*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x00, 0x3a, 0x20, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0xab,
877*cfb92d14SAndroid Build Coastguard Worker 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0x20, 0x01, 0x00, 0x02, 0x00,
878*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x00, 0x02, 0xc3, 0x1d, 0xa7, 0x02, 0x0d, 0x41, 0xbe, 0xef};
879*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
880*cfb92d14SAndroid Build Coastguard Worker
881*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
882*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
883*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
884*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
885*cfb92d14SAndroid Build Coastguard Worker
886*cfb92d14SAndroid Build Coastguard Worker // Perform compression test only.
887*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, false);
888*cfb92d14SAndroid Build Coastguard Worker }
889*cfb92d14SAndroid Build Coastguard Worker
TestStatefulMulticastDestination48bitContext0(void)890*cfb92d14SAndroid Build Coastguard Worker static void TestStatefulMulticastDestination48bitContext0(void)
891*cfb92d14SAndroid Build Coastguard Worker {
892*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Stateful compression multicast address, context 0");
893*cfb92d14SAndroid Build Coastguard Worker
894*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
895*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
896*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
897*cfb92d14SAndroid Build Coastguard Worker
898*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
899*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64,
900*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234:0200:5eef:1022:1100", "ff33:0040:fd00:cafe:face:1234:0000:0001");
901*cfb92d14SAndroid Build Coastguard Worker
902*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
903*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x7c, 0x3a, 0x33, 0x00, 0x00, 0x00, 0x00, 0x01};
904*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
905*cfb92d14SAndroid Build Coastguard Worker
906*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
907*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
908*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
909*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
910*cfb92d14SAndroid Build Coastguard Worker
911*cfb92d14SAndroid Build Coastguard Worker // Perform decompression tests.
912*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
913*cfb92d14SAndroid Build Coastguard Worker }
914*cfb92d14SAndroid Build Coastguard Worker
TestTrafficClassFlowLabel3Bytes(void)915*cfb92d14SAndroid Build Coastguard Worker static void TestTrafficClassFlowLabel3Bytes(void)
916*cfb92d14SAndroid Build Coastguard Worker {
917*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Traffic Class and Flow Label 3 bytes");
918*cfb92d14SAndroid Build Coastguard Worker
919*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
920*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
921*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
922*cfb92d14SAndroid Build Coastguard Worker
923*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
924*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x6011ac59, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
925*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
926*cfb92d14SAndroid Build Coastguard Worker
927*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
928*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x6a, 0x33, 0x41, 0xac, 0x59, 0x3a};
929*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
930*cfb92d14SAndroid Build Coastguard Worker
931*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
932*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
933*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
934*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
935*cfb92d14SAndroid Build Coastguard Worker
936*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
937*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
938*cfb92d14SAndroid Build Coastguard Worker }
939*cfb92d14SAndroid Build Coastguard Worker
TestTrafficClassFlowLabel1Byte(void)940*cfb92d14SAndroid Build Coastguard Worker static void TestTrafficClassFlowLabel1Byte(void)
941*cfb92d14SAndroid Build Coastguard Worker {
942*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Traffic Class and Flow Label 1 byte");
943*cfb92d14SAndroid Build Coastguard Worker
944*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
945*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
946*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
947*cfb92d14SAndroid Build Coastguard Worker
948*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
949*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60d00000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
950*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
951*cfb92d14SAndroid Build Coastguard Worker
952*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
953*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x72, 0x33, 0x43, 0x3a};
954*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
955*cfb92d14SAndroid Build Coastguard Worker
956*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
957*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
958*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
959*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
960*cfb92d14SAndroid Build Coastguard Worker
961*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
962*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
963*cfb92d14SAndroid Build Coastguard Worker }
964*cfb92d14SAndroid Build Coastguard Worker
TestTrafficClassFlowLabel1ByteEcnOnly(void)965*cfb92d14SAndroid Build Coastguard Worker static void TestTrafficClassFlowLabel1ByteEcnOnly(void)
966*cfb92d14SAndroid Build Coastguard Worker {
967*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Traffic Class and Flow Label 1 byte with ecn only");
968*cfb92d14SAndroid Build Coastguard Worker
969*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
970*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
971*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
972*cfb92d14SAndroid Build Coastguard Worker
973*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
974*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60100000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
975*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
976*cfb92d14SAndroid Build Coastguard Worker
977*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
978*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x72, 0x33, 0x40, 0x3a};
979*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
980*cfb92d14SAndroid Build Coastguard Worker
981*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
982*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
983*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
984*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
985*cfb92d14SAndroid Build Coastguard Worker
986*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
987*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
988*cfb92d14SAndroid Build Coastguard Worker }
989*cfb92d14SAndroid Build Coastguard Worker
TestTrafficClassFlowLabelInline(void)990*cfb92d14SAndroid Build Coastguard Worker static void TestTrafficClassFlowLabelInline(void)
991*cfb92d14SAndroid Build Coastguard Worker {
992*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Traffic Class and Flow Label inline");
993*cfb92d14SAndroid Build Coastguard Worker
994*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
995*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
996*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
997*cfb92d14SAndroid Build Coastguard Worker
998*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
999*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x6ea12345, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 64, "fe80::200:5eef:1022:1100",
1000*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
1001*cfb92d14SAndroid Build Coastguard Worker
1002*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1003*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x62, 0x33, 0xBA, 0x01, 0x23, 0x45, 0x3a};
1004*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1005*cfb92d14SAndroid Build Coastguard Worker
1006*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1007*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1008*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
1009*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1010*cfb92d14SAndroid Build Coastguard Worker
1011*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1012*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1013*cfb92d14SAndroid Build Coastguard Worker }
1014*cfb92d14SAndroid Build Coastguard Worker
TestHopLimit1(void)1015*cfb92d14SAndroid Build Coastguard Worker static void TestHopLimit1(void)
1016*cfb92d14SAndroid Build Coastguard Worker {
1017*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Hop Limit 1");
1018*cfb92d14SAndroid Build Coastguard Worker
1019*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1020*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1021*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
1022*cfb92d14SAndroid Build Coastguard Worker
1023*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1024*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 1, "fe80::ff:fe00:0000",
1025*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
1026*cfb92d14SAndroid Build Coastguard Worker
1027*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1028*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x79, 0x33, 0x3a};
1029*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1030*cfb92d14SAndroid Build Coastguard Worker
1031*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1032*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1033*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
1034*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1035*cfb92d14SAndroid Build Coastguard Worker
1036*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1037*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1038*cfb92d14SAndroid Build Coastguard Worker }
1039*cfb92d14SAndroid Build Coastguard Worker
TestHopLimit255(void)1040*cfb92d14SAndroid Build Coastguard Worker static void TestHopLimit255(void)
1041*cfb92d14SAndroid Build Coastguard Worker {
1042*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Hop Limit 255");
1043*cfb92d14SAndroid Build Coastguard Worker
1044*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1045*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1046*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
1047*cfb92d14SAndroid Build Coastguard Worker
1048*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1049*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 255, "fe80::ff:fe00:0000",
1050*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
1051*cfb92d14SAndroid Build Coastguard Worker
1052*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1053*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7B, 0x33, 0x3a};
1054*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1055*cfb92d14SAndroid Build Coastguard Worker
1056*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1057*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1058*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
1059*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1060*cfb92d14SAndroid Build Coastguard Worker
1061*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1062*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1063*cfb92d14SAndroid Build Coastguard Worker }
1064*cfb92d14SAndroid Build Coastguard Worker
TestHopLimitInline(void)1065*cfb92d14SAndroid Build Coastguard Worker static void TestHopLimitInline(void)
1066*cfb92d14SAndroid Build Coastguard Worker {
1067*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Hop Limit Inline");
1068*cfb92d14SAndroid Build Coastguard Worker
1069*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1070*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1071*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
1072*cfb92d14SAndroid Build Coastguard Worker
1073*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1074*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 63, "fe80::ff:fe00:0000",
1075*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
1076*cfb92d14SAndroid Build Coastguard Worker
1077*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1078*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x78, 0x33, 0x3a, 0x3f};
1079*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1080*cfb92d14SAndroid Build Coastguard Worker
1081*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1082*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1083*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
1084*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1085*cfb92d14SAndroid Build Coastguard Worker
1086*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1087*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1088*cfb92d14SAndroid Build Coastguard Worker }
1089*cfb92d14SAndroid Build Coastguard Worker
TestUdpSourceDestinationInline(void)1090*cfb92d14SAndroid Build Coastguard Worker static void TestUdpSourceDestinationInline(void)
1091*cfb92d14SAndroid Build Coastguard Worker {
1092*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP source and destination inline");
1093*cfb92d14SAndroid Build Coastguard Worker
1094*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1095*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1096*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1097*cfb92d14SAndroid Build Coastguard Worker
1098*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1099*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64, "fe80::200:5eef:1022:1100",
1100*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
1101*cfb92d14SAndroid Build Coastguard Worker
1102*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1103*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(5683, 5684, sizeof(sTestPayloadDefault) + 8, 0xbeef);
1104*cfb92d14SAndroid Build Coastguard Worker
1105*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1106*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xf0, 0x16, 0x33, 0x16, 0x34, 0xbe, 0xef};
1107*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1108*cfb92d14SAndroid Build Coastguard Worker
1109*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1110*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1111*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1112*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1113*cfb92d14SAndroid Build Coastguard Worker
1114*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1115*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1116*cfb92d14SAndroid Build Coastguard Worker }
1117*cfb92d14SAndroid Build Coastguard Worker
TestUdpSourceInlineDestination8bit(void)1118*cfb92d14SAndroid Build Coastguard Worker static void TestUdpSourceInlineDestination8bit(void)
1119*cfb92d14SAndroid Build Coastguard Worker {
1120*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP source inline destination 8-bit");
1121*cfb92d14SAndroid Build Coastguard Worker
1122*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1123*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1124*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1125*cfb92d14SAndroid Build Coastguard Worker
1126*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1127*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64, "fe80::200:5eef:1022:1100",
1128*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
1129*cfb92d14SAndroid Build Coastguard Worker
1130*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1131*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(5683, 61441, sizeof(sTestPayloadDefault) + 8, 0xbeef);
1132*cfb92d14SAndroid Build Coastguard Worker
1133*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1134*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xf1, 0x16, 0x33, 0x01, 0xbe, 0xef};
1135*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1136*cfb92d14SAndroid Build Coastguard Worker
1137*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1138*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1139*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1140*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1141*cfb92d14SAndroid Build Coastguard Worker
1142*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1143*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1144*cfb92d14SAndroid Build Coastguard Worker }
1145*cfb92d14SAndroid Build Coastguard Worker
TestUdpSource8bitDestinationInline(void)1146*cfb92d14SAndroid Build Coastguard Worker static void TestUdpSource8bitDestinationInline(void)
1147*cfb92d14SAndroid Build Coastguard Worker {
1148*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP source 8-bit destination 8-bit");
1149*cfb92d14SAndroid Build Coastguard Worker
1150*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1151*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1152*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1153*cfb92d14SAndroid Build Coastguard Worker
1154*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1155*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64, "fe80::200:5eef:1022:1100",
1156*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
1157*cfb92d14SAndroid Build Coastguard Worker
1158*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1159*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(61695, 5683, sizeof(sTestPayloadDefault) + 8, 0xbeef);
1160*cfb92d14SAndroid Build Coastguard Worker
1161*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1162*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xf2, 0xff, 0x16, 0x33, 0xbe, 0xef};
1163*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1164*cfb92d14SAndroid Build Coastguard Worker
1165*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1166*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1167*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1168*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1169*cfb92d14SAndroid Build Coastguard Worker
1170*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1171*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1172*cfb92d14SAndroid Build Coastguard Worker }
1173*cfb92d14SAndroid Build Coastguard Worker
TestUdpFullyCompressed(void)1174*cfb92d14SAndroid Build Coastguard Worker static void TestUdpFullyCompressed(void)
1175*cfb92d14SAndroid Build Coastguard Worker {
1176*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP fully compressed");
1177*cfb92d14SAndroid Build Coastguard Worker
1178*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1179*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1180*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1181*cfb92d14SAndroid Build Coastguard Worker
1182*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1183*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64, "fe80::200:5eef:1022:1100",
1184*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:10aa:bbcc");
1185*cfb92d14SAndroid Build Coastguard Worker
1186*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1187*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(61616, 61631, sizeof(sTestPayloadDefault) + 8, 0xface);
1188*cfb92d14SAndroid Build Coastguard Worker
1189*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1190*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xf3, 0x0f, 0xfa, 0xce};
1191*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1192*cfb92d14SAndroid Build Coastguard Worker
1193*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1194*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1195*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1196*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1197*cfb92d14SAndroid Build Coastguard Worker
1198*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1199*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1200*cfb92d14SAndroid Build Coastguard Worker }
1201*cfb92d14SAndroid Build Coastguard Worker
TestUdpFullyCompressedMulticast(void)1202*cfb92d14SAndroid Build Coastguard Worker static void TestUdpFullyCompressedMulticast(void)
1203*cfb92d14SAndroid Build Coastguard Worker {
1204*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP fully compressed with IP multicast");
1205*cfb92d14SAndroid Build Coastguard Worker
1206*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1207*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1208*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1209*cfb92d14SAndroid Build Coastguard Worker
1210*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1211*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64, "fe80::200:5eef:1022:1100",
1212*cfb92d14SAndroid Build Coastguard Worker "ff02::1");
1213*cfb92d14SAndroid Build Coastguard Worker
1214*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1215*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(61616, 61631, sizeof(sTestPayloadDefault) + 8, 0xface);
1216*cfb92d14SAndroid Build Coastguard Worker
1217*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1218*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x3b, 0x01, 0xf3, 0x0f, 0xfa, 0xce};
1219*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1220*cfb92d14SAndroid Build Coastguard Worker
1221*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1222*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1223*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1224*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1225*cfb92d14SAndroid Build Coastguard Worker
1226*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1227*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1228*cfb92d14SAndroid Build Coastguard Worker }
1229*cfb92d14SAndroid Build Coastguard Worker
TestUdpWithoutNhc(void)1230*cfb92d14SAndroid Build Coastguard Worker static void TestUdpWithoutNhc(void)
1231*cfb92d14SAndroid Build Coastguard Worker {
1232*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("UDP without LOWPAN_NHC compression");
1233*cfb92d14SAndroid Build Coastguard Worker
1234*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1235*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1236*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultShort);
1237*cfb92d14SAndroid Build Coastguard Worker
1238*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1239*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoUdp, 64, "fe80::ff:fe00:0000",
1240*cfb92d14SAndroid Build Coastguard Worker "fe80::ff:fe00:c003");
1241*cfb92d14SAndroid Build Coastguard Worker
1242*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1243*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x33, 0x11};
1244*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1245*cfb92d14SAndroid Build Coastguard Worker
1246*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1247*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1248*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(40);
1249*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1250*cfb92d14SAndroid Build Coastguard Worker
1251*cfb92d14SAndroid Build Coastguard Worker // Perform only decompression test.
1252*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1253*cfb92d14SAndroid Build Coastguard Worker }
1254*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopNoPadding(void)1255*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopNoPadding(void)
1256*cfb92d14SAndroid Build Coastguard Worker {
1257*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with no padding");
1258*cfb92d14SAndroid Build Coastguard Worker
1259*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1260*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1261*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1262*cfb92d14SAndroid Build Coastguard Worker
1263*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1264*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoHopOpts, 64,
1265*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1266*cfb92d14SAndroid Build Coastguard Worker
1267*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1268*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x00, 0x6d, 0x04, 0x60, 0x11, 0x00, 0x0c};
1269*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1270*cfb92d14SAndroid Build Coastguard Worker
1271*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1272*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x06, 0x6d, 0x04, 0x60, 0x11, 0x00, 0x0c};
1273*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1274*cfb92d14SAndroid Build Coastguard Worker
1275*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1276*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1277*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1278*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1279*cfb92d14SAndroid Build Coastguard Worker
1280*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1281*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1282*cfb92d14SAndroid Build Coastguard Worker }
1283*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPad1(void)1284*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPad1(void)
1285*cfb92d14SAndroid Build Coastguard Worker {
1286*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with Pad1");
1287*cfb92d14SAndroid Build Coastguard Worker
1288*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1289*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1290*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1291*cfb92d14SAndroid Build Coastguard Worker
1292*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1293*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoHopOpts, 64,
1294*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1295*cfb92d14SAndroid Build Coastguard Worker
1296*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1297*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x00, 0x6d, 0x03, 0x60, 0x11, 0x00, 0x00};
1298*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1299*cfb92d14SAndroid Build Coastguard Worker
1300*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1301*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x05, 0x6d, 0x03, 0x60, 0x11, 0x00};
1302*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1303*cfb92d14SAndroid Build Coastguard Worker
1304*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1305*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1306*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1307*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1308*cfb92d14SAndroid Build Coastguard Worker
1309*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1310*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1311*cfb92d14SAndroid Build Coastguard Worker }
1312*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN2(void)1313*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN2(void)
1314*cfb92d14SAndroid Build Coastguard Worker {
1315*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN2");
1316*cfb92d14SAndroid Build Coastguard Worker
1317*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1318*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1319*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1320*cfb92d14SAndroid Build Coastguard Worker
1321*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1322*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoHopOpts, 64,
1323*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1324*cfb92d14SAndroid Build Coastguard Worker
1325*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1326*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x00, 0x6d, 0x02, 0x60, 0x11, 0x01, 0x00};
1327*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1328*cfb92d14SAndroid Build Coastguard Worker
1329*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1330*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x04, 0x6d, 0x02, 0x60, 0x11};
1331*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1332*cfb92d14SAndroid Build Coastguard Worker
1333*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1334*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1335*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1336*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1337*cfb92d14SAndroid Build Coastguard Worker
1338*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1339*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1340*cfb92d14SAndroid Build Coastguard Worker }
1341*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN3(void)1342*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN3(void)
1343*cfb92d14SAndroid Build Coastguard Worker {
1344*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN3");
1345*cfb92d14SAndroid Build Coastguard Worker
1346*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1347*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1348*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1349*cfb92d14SAndroid Build Coastguard Worker
1350*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1351*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoHopOpts, 64,
1352*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1353*cfb92d14SAndroid Build Coastguard Worker
1354*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1355*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x00, 0x6d, 0x01, 0x60, 0x01, 0x01, 0x00};
1356*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1357*cfb92d14SAndroid Build Coastguard Worker
1358*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1359*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x03, 0x6d, 0x01, 0x60};
1360*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1361*cfb92d14SAndroid Build Coastguard Worker
1362*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1363*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1364*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1365*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1366*cfb92d14SAndroid Build Coastguard Worker
1367*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1368*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1369*cfb92d14SAndroid Build Coastguard Worker }
1370*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN4(void)1371*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN4(void)
1372*cfb92d14SAndroid Build Coastguard Worker {
1373*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN4");
1374*cfb92d14SAndroid Build Coastguard Worker
1375*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1376*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1377*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1378*cfb92d14SAndroid Build Coastguard Worker
1379*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1380*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoHopOpts, 64,
1381*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1382*cfb92d14SAndroid Build Coastguard Worker
1383*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1384*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x00, 0x6d, 0x00, 0x01, 0x02, 0x00, 0x00};
1385*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1386*cfb92d14SAndroid Build Coastguard Worker
1387*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1388*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x02, 0x6d, 0x00};
1389*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1390*cfb92d14SAndroid Build Coastguard Worker
1391*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1392*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1393*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(48);
1394*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1395*cfb92d14SAndroid Build Coastguard Worker
1396*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1397*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1398*cfb92d14SAndroid Build Coastguard Worker }
1399*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN5(void)1400*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN5(void)
1401*cfb92d14SAndroid Build Coastguard Worker {
1402*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN5");
1403*cfb92d14SAndroid Build Coastguard Worker
1404*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1405*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1406*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1407*cfb92d14SAndroid Build Coastguard Worker
1408*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1409*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 16, Ip6::kProtoHopOpts, 64,
1410*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1411*cfb92d14SAndroid Build Coastguard Worker
1412*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1413*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x01, 0x6d, 0x07, 0x01, 0x02, 0x01, 0x00,
1414*cfb92d14SAndroid Build Coastguard Worker 0x00, 0x00, 0x33, 0x01, 0x03, 0x00, 0x00, 0x00};
1415*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1416*cfb92d14SAndroid Build Coastguard Worker
1417*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1418*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x09,
1419*cfb92d14SAndroid Build Coastguard Worker 0x6d, 0x07, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x33};
1420*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1421*cfb92d14SAndroid Build Coastguard Worker
1422*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1423*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1424*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(56);
1425*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1426*cfb92d14SAndroid Build Coastguard Worker
1427*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1428*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1429*cfb92d14SAndroid Build Coastguard Worker }
1430*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN6(void)1431*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN6(void)
1432*cfb92d14SAndroid Build Coastguard Worker {
1433*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN6");
1434*cfb92d14SAndroid Build Coastguard Worker
1435*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1436*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1437*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1438*cfb92d14SAndroid Build Coastguard Worker
1439*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1440*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 24, Ip6::kProtoHopOpts, 64,
1441*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1442*cfb92d14SAndroid Build Coastguard Worker
1443*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1444*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x02, 0x6d, 0x0e, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x33, 0x01,
1445*cfb92d14SAndroid Build Coastguard Worker 0x03, 0x00, 0x00, 0x00, 0x11, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00};
1446*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1447*cfb92d14SAndroid Build Coastguard Worker
1448*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1449*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x10, 0x6d, 0x0e, 0x01, 0x02,
1450*cfb92d14SAndroid Build Coastguard Worker 0x01, 0x00, 0x00, 0x00, 0x33, 0x01, 0x03, 0x00, 0x00, 0x00, 0x11, 0x00};
1451*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1452*cfb92d14SAndroid Build Coastguard Worker
1453*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1454*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1455*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(64);
1456*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1457*cfb92d14SAndroid Build Coastguard Worker
1458*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1459*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1460*cfb92d14SAndroid Build Coastguard Worker }
1461*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN7(void)1462*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN7(void)
1463*cfb92d14SAndroid Build Coastguard Worker {
1464*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN7");
1465*cfb92d14SAndroid Build Coastguard Worker
1466*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1467*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1468*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1469*cfb92d14SAndroid Build Coastguard Worker
1470*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1471*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 24, Ip6::kProtoHopOpts, 64,
1472*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1473*cfb92d14SAndroid Build Coastguard Worker
1474*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1475*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x3a, 0x02, 0x6d, 0x0d, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x33, 0x01,
1476*cfb92d14SAndroid Build Coastguard Worker 0x03, 0x00, 0x00, 0x00, 0x11, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00};
1477*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1478*cfb92d14SAndroid Build Coastguard Worker
1479*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1480*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe0, 0x3a, 0x0f, 0x6d, 0x0d, 0x01,
1481*cfb92d14SAndroid Build Coastguard Worker 0x02, 0x01, 0x00, 0x00, 0x00, 0x33, 0x01, 0x03, 0x00, 0x00, 0x00, 0x11};
1482*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1483*cfb92d14SAndroid Build Coastguard Worker
1484*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1485*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1486*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(64);
1487*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1488*cfb92d14SAndroid Build Coastguard Worker
1489*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1490*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1491*cfb92d14SAndroid Build Coastguard Worker }
1492*cfb92d14SAndroid Build Coastguard Worker
TestExtensionHeaderHopByHopPadN2UdpFullyCompressed(void)1493*cfb92d14SAndroid Build Coastguard Worker static void TestExtensionHeaderHopByHopPadN2UdpFullyCompressed(void)
1494*cfb92d14SAndroid Build Coastguard Worker {
1495*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Extension Header - Hop-by-Hop with PadN2 and UDP");
1496*cfb92d14SAndroid Build Coastguard Worker
1497*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1498*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1499*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1500*cfb92d14SAndroid Build Coastguard Worker
1501*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1502*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 16, Ip6::kProtoHopOpts, 64,
1503*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::1");
1504*cfb92d14SAndroid Build Coastguard Worker
1505*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1506*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x11, 0x00, 0x6d, 0x02, 0x60, 0x11, 0x01, 0x00};
1507*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1508*cfb92d14SAndroid Build Coastguard Worker
1509*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1510*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(61616, 61631, sizeof(sTestPayloadDefault) + 8, 0xface);
1511*cfb92d14SAndroid Build Coastguard Worker
1512*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1513*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0x01, 0xe1, 0x04, 0x6d, 0x02, 0x60, 0x11, 0xf3, 0x0f, 0xfa, 0xce};
1514*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1515*cfb92d14SAndroid Build Coastguard Worker
1516*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1517*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1518*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(56);
1519*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1520*cfb92d14SAndroid Build Coastguard Worker
1521*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1522*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1523*cfb92d14SAndroid Build Coastguard Worker }
1524*cfb92d14SAndroid Build Coastguard Worker
TestIpInIpHopByHopPadN2UdpSourceDestinationInline(void)1525*cfb92d14SAndroid Build Coastguard Worker static void TestIpInIpHopByHopPadN2UdpSourceDestinationInline(void)
1526*cfb92d14SAndroid Build Coastguard Worker {
1527*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IP-in-IP with Hop-by-Hop with PadN2 and UDP");
1528*cfb92d14SAndroid Build Coastguard Worker
1529*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1530*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultShort);
1531*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationBroadcast);
1532*cfb92d14SAndroid Build Coastguard Worker
1533*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1534*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 56, Ip6::kProtoHopOpts, 64,
1535*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff03::fc");
1536*cfb92d14SAndroid Build Coastguard Worker
1537*cfb92d14SAndroid Build Coastguard Worker // Setup extension header.
1538*cfb92d14SAndroid Build Coastguard Worker uint8_t extHeader[] = {0x29, 0x00, 0x6d, 0x02, 0x00, 0x11, 0x01, 0x00};
1539*cfb92d14SAndroid Build Coastguard Worker testVector.SetExtHeader(extHeader, sizeof(extHeader));
1540*cfb92d14SAndroid Build Coastguard Worker
1541*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 tunneled header.
1542*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpTunneledHeader(0x60000000, sizeof(sTestPayloadDefault) + 8, Ip6::kProtoUdp, 64,
1543*cfb92d14SAndroid Build Coastguard Worker "fd00:cafe:face:1234::ff:fe00:0000", "ff05::1");
1544*cfb92d14SAndroid Build Coastguard Worker
1545*cfb92d14SAndroid Build Coastguard Worker // Setup UDP header.
1546*cfb92d14SAndroid Build Coastguard Worker testVector.SetUDPHeader(5683, 5684, sizeof(sTestPayloadDefault) + 8, 0xbeef);
1547*cfb92d14SAndroid Build Coastguard Worker
1548*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1549*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x7a, 0x03, 0x00, 0x00, 0xfc, 0xe1, 0x04, 0x6d, 0x02, 0x00, 0x11, 0xee,
1550*cfb92d14SAndroid Build Coastguard Worker 0x7e, 0x7a, 0x05, 0x00, 0x00, 0x01, 0xf0, 0x16, 0x33, 0x16, 0x34, 0xbe, 0xef};
1551*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1552*cfb92d14SAndroid Build Coastguard Worker
1553*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1554*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1555*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(96);
1556*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1557*cfb92d14SAndroid Build Coastguard Worker
1558*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1559*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1560*cfb92d14SAndroid Build Coastguard Worker }
1561*cfb92d14SAndroid Build Coastguard Worker
TestIpInIpWithoutExtensionHeader(void)1562*cfb92d14SAndroid Build Coastguard Worker static void TestIpInIpWithoutExtensionHeader(void)
1563*cfb92d14SAndroid Build Coastguard Worker {
1564*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("IP-in-IP without extension header");
1565*cfb92d14SAndroid Build Coastguard Worker
1566*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1567*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1568*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1569*cfb92d14SAndroid Build Coastguard Worker
1570*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 header.
1571*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpHeader(0x60000000, sizeof(sTestPayloadDefault) + 40, Ip6::kProtoIp6, 64, "fe80::200:5eef:1022:1100",
1572*cfb92d14SAndroid Build Coastguard Worker "ff03::1");
1573*cfb92d14SAndroid Build Coastguard Worker
1574*cfb92d14SAndroid Build Coastguard Worker // Setup IPv6 tunneled header.
1575*cfb92d14SAndroid Build Coastguard Worker testVector.SetIpTunneledHeader(0x60000000, sizeof(sTestPayloadDefault), Ip6::kProtoIcmp6, 1,
1576*cfb92d14SAndroid Build Coastguard Worker "fe80::200:5eef:1022:1100", "fe80::200:5eef:10aa:bbcc");
1577*cfb92d14SAndroid Build Coastguard Worker
1578*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1579*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x3a, 0x03, 0x00, 0x00, 0x01, 0xee, 0x79, 0x33, 0x3a};
1580*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1581*cfb92d14SAndroid Build Coastguard Worker
1582*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1583*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayload(sTestPayloadDefault, sizeof(sTestPayloadDefault));
1584*cfb92d14SAndroid Build Coastguard Worker testVector.SetPayloadOffset(80);
1585*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorNone);
1586*cfb92d14SAndroid Build Coastguard Worker
1587*cfb92d14SAndroid Build Coastguard Worker // Perform compression and decompression tests.
1588*cfb92d14SAndroid Build Coastguard Worker Test(testVector, true, true);
1589*cfb92d14SAndroid Build Coastguard Worker }
1590*cfb92d14SAndroid Build Coastguard Worker
TestErrorNoIphcDispatch(void)1591*cfb92d14SAndroid Build Coastguard Worker static void TestErrorNoIphcDispatch(void)
1592*cfb92d14SAndroid Build Coastguard Worker {
1593*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Invalid dispatch");
1594*cfb92d14SAndroid Build Coastguard Worker
1595*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1596*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1597*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1598*cfb92d14SAndroid Build Coastguard Worker
1599*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1600*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x40, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
1601*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1602*cfb92d14SAndroid Build Coastguard Worker
1603*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1604*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1605*cfb92d14SAndroid Build Coastguard Worker
1606*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1607*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1608*cfb92d14SAndroid Build Coastguard Worker }
1609*cfb92d14SAndroid Build Coastguard Worker
TestErrorTruncatedIphc(void)1610*cfb92d14SAndroid Build Coastguard Worker static void TestErrorTruncatedIphc(void)
1611*cfb92d14SAndroid Build Coastguard Worker {
1612*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Truncated LOWPAN_IPHC");
1613*cfb92d14SAndroid Build Coastguard Worker
1614*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1615*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1616*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1617*cfb92d14SAndroid Build Coastguard Worker
1618*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1619*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x00};
1620*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1621*cfb92d14SAndroid Build Coastguard Worker
1622*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1623*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1624*cfb92d14SAndroid Build Coastguard Worker
1625*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1626*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1627*cfb92d14SAndroid Build Coastguard Worker }
1628*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedValueDestination0100(void)1629*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedValueDestination0100(void)
1630*cfb92d14SAndroid Build Coastguard Worker {
1631*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of M-DAC-DAM - 0100");
1632*cfb92d14SAndroid Build Coastguard Worker
1633*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1634*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1635*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1636*cfb92d14SAndroid Build Coastguard Worker
1637*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1638*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x34, 0x3A};
1639*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1640*cfb92d14SAndroid Build Coastguard Worker
1641*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1642*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1643*cfb92d14SAndroid Build Coastguard Worker
1644*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1645*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1646*cfb92d14SAndroid Build Coastguard Worker }
1647*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedValueDestination1101(void)1648*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedValueDestination1101(void)
1649*cfb92d14SAndroid Build Coastguard Worker {
1650*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of M-DAC-DAM - 1101");
1651*cfb92d14SAndroid Build Coastguard Worker
1652*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1653*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1654*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1655*cfb92d14SAndroid Build Coastguard Worker
1656*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1657*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x3D, 0x3A};
1658*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1659*cfb92d14SAndroid Build Coastguard Worker
1660*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1661*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1662*cfb92d14SAndroid Build Coastguard Worker
1663*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1664*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1665*cfb92d14SAndroid Build Coastguard Worker }
1666*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedValueDestination1110(void)1667*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedValueDestination1110(void)
1668*cfb92d14SAndroid Build Coastguard Worker {
1669*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of M-DAC-DAM - 1110");
1670*cfb92d14SAndroid Build Coastguard Worker
1671*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1672*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1673*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1674*cfb92d14SAndroid Build Coastguard Worker
1675*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1676*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x3E, 0x3A};
1677*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1678*cfb92d14SAndroid Build Coastguard Worker
1679*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1680*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1681*cfb92d14SAndroid Build Coastguard Worker
1682*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1683*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1684*cfb92d14SAndroid Build Coastguard Worker }
1685*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedValueDestination1111(void)1686*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedValueDestination1111(void)
1687*cfb92d14SAndroid Build Coastguard Worker {
1688*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of M-DAC-DAM - 1111");
1689*cfb92d14SAndroid Build Coastguard Worker
1690*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1691*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1692*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1693*cfb92d14SAndroid Build Coastguard Worker
1694*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1695*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7a, 0x3F, 0x3A};
1696*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1697*cfb92d14SAndroid Build Coastguard Worker
1698*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1699*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1700*cfb92d14SAndroid Build Coastguard Worker
1701*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1702*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1703*cfb92d14SAndroid Build Coastguard Worker }
1704*cfb92d14SAndroid Build Coastguard Worker
TestErrorUnknownNhc(void)1705*cfb92d14SAndroid Build Coastguard Worker static void TestErrorUnknownNhc(void)
1706*cfb92d14SAndroid Build Coastguard Worker {
1707*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Unknown value of LOWPAN_NHC ID");
1708*cfb92d14SAndroid Build Coastguard Worker
1709*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1710*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1711*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1712*cfb92d14SAndroid Build Coastguard Worker
1713*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1714*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0x00};
1715*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1716*cfb92d14SAndroid Build Coastguard Worker
1717*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1718*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1719*cfb92d14SAndroid Build Coastguard Worker
1720*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1721*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1722*cfb92d14SAndroid Build Coastguard Worker }
1723*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedNhc5(void)1724*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedNhc5(void)
1725*cfb92d14SAndroid Build Coastguard Worker {
1726*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of LOWPAN_NHC EID - 0x05");
1727*cfb92d14SAndroid Build Coastguard Worker
1728*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1729*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1730*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1731*cfb92d14SAndroid Build Coastguard Worker
1732*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1733*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xea};
1734*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1735*cfb92d14SAndroid Build Coastguard Worker
1736*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1737*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1738*cfb92d14SAndroid Build Coastguard Worker
1739*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1740*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1741*cfb92d14SAndroid Build Coastguard Worker }
1742*cfb92d14SAndroid Build Coastguard Worker
TestErrorReservedNhc6(void)1743*cfb92d14SAndroid Build Coastguard Worker static void TestErrorReservedNhc6(void)
1744*cfb92d14SAndroid Build Coastguard Worker {
1745*cfb92d14SAndroid Build Coastguard Worker TestIphcVector testVector("Reserved value of LOWPAN_NHC EID - 0x06");
1746*cfb92d14SAndroid Build Coastguard Worker
1747*cfb92d14SAndroid Build Coastguard Worker // Setup MAC addresses.
1748*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacSource(sTestMacSourceDefaultLong);
1749*cfb92d14SAndroid Build Coastguard Worker testVector.SetMacDestination(sTestMacDestinationDefaultLong);
1750*cfb92d14SAndroid Build Coastguard Worker
1751*cfb92d14SAndroid Build Coastguard Worker // Set LOWPAN_IPHC header.
1752*cfb92d14SAndroid Build Coastguard Worker uint8_t iphc[] = {0x7e, 0x33, 0xec};
1753*cfb92d14SAndroid Build Coastguard Worker testVector.SetIphcHeader(iphc, sizeof(iphc));
1754*cfb92d14SAndroid Build Coastguard Worker
1755*cfb92d14SAndroid Build Coastguard Worker // Set payload and error.
1756*cfb92d14SAndroid Build Coastguard Worker testVector.SetError(kErrorParse);
1757*cfb92d14SAndroid Build Coastguard Worker
1758*cfb92d14SAndroid Build Coastguard Worker // Perform decompression test.
1759*cfb92d14SAndroid Build Coastguard Worker Test(testVector, false, true);
1760*cfb92d14SAndroid Build Coastguard Worker }
1761*cfb92d14SAndroid Build Coastguard Worker
1762*cfb92d14SAndroid Build Coastguard Worker /***************************************************************************************************
1763*cfb92d14SAndroid Build Coastguard Worker * @section Main test.
1764*cfb92d14SAndroid Build Coastguard Worker **************************************************************************************************/
1765*cfb92d14SAndroid Build Coastguard Worker
TestLowpanIphc(void)1766*cfb92d14SAndroid Build Coastguard Worker void TestLowpanIphc(void)
1767*cfb92d14SAndroid Build Coastguard Worker {
1768*cfb92d14SAndroid Build Coastguard Worker sInstance = testInitInstance();
1769*cfb92d14SAndroid Build Coastguard Worker
1770*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(sInstance != nullptr, "nullptr instance");
1771*cfb92d14SAndroid Build Coastguard Worker
1772*cfb92d14SAndroid Build Coastguard Worker sIp6 = &sInstance->Get<Ip6::Ip6>();
1773*cfb92d14SAndroid Build Coastguard Worker sLowpan = &sInstance->Get<Lowpan::Lowpan>();
1774*cfb92d14SAndroid Build Coastguard Worker
1775*cfb92d14SAndroid Build Coastguard Worker Init();
1776*cfb92d14SAndroid Build Coastguard Worker
1777*cfb92d14SAndroid Build Coastguard Worker // Stateless unicast addresses compression / decompression tests.
1778*cfb92d14SAndroid Build Coastguard Worker TestFullyCompressableLongAddresses();
1779*cfb92d14SAndroid Build Coastguard Worker TestFullyCompressableShortAddresses();
1780*cfb92d14SAndroid Build Coastguard Worker TestFullyCompressableShortLongAddresses();
1781*cfb92d14SAndroid Build Coastguard Worker TestFullyCompressableLongShortAddresses();
1782*cfb92d14SAndroid Build Coastguard Worker TestSourceUnspecifiedAddress();
1783*cfb92d14SAndroid Build Coastguard Worker TestSource128bitDestination128bitAddresses();
1784*cfb92d14SAndroid Build Coastguard Worker TestSource64bitDestination64bitLongAddresses();
1785*cfb92d14SAndroid Build Coastguard Worker TestSource64bitDestination64bitShortAddresses();
1786*cfb92d14SAndroid Build Coastguard Worker TestSource16bitDestination16bitAddresses();
1787*cfb92d14SAndroid Build Coastguard Worker TestSourceCompressedDestination16bitAddresses();
1788*cfb92d14SAndroid Build Coastguard Worker TestSourceCompressedDestination128bitAddresses();
1789*cfb92d14SAndroid Build Coastguard Worker
1790*cfb92d14SAndroid Build Coastguard Worker // Stateless multicast addresses compression / decompression tests.
1791*cfb92d14SAndroid Build Coastguard Worker TestMulticast128bitAddress();
1792*cfb92d14SAndroid Build Coastguard Worker TestMulticast48bitAddress();
1793*cfb92d14SAndroid Build Coastguard Worker TestMulticast32bitAddress();
1794*cfb92d14SAndroid Build Coastguard Worker TestMulticast8bitAddress();
1795*cfb92d14SAndroid Build Coastguard Worker
1796*cfb92d14SAndroid Build Coastguard Worker // Stateful unicast addresses compression / decompression tests.
1797*cfb92d14SAndroid Build Coastguard Worker TestStatefulSource64bitDestination64bitContext0();
1798*cfb92d14SAndroid Build Coastguard Worker TestStatefulSource64bitDestination64bitContext0IfContextInLine();
1799*cfb92d14SAndroid Build Coastguard Worker TestStatefulSource16bitDestination16bitContext0();
1800*cfb92d14SAndroid Build Coastguard Worker TestStatefulCompressableLongAddressesContext0();
1801*cfb92d14SAndroid Build Coastguard Worker TestStatefulCompressableShortAddressesContext0();
1802*cfb92d14SAndroid Build Coastguard Worker TestStatefulCompressableLongShortAddressesContext0();
1803*cfb92d14SAndroid Build Coastguard Worker TestStatefulSource64bitDestination128bitContext1();
1804*cfb92d14SAndroid Build Coastguard Worker TestStatefulSource64bitDestination64bitContext1();
1805*cfb92d14SAndroid Build Coastguard Worker TestStatefulSourceDestinationInlineContext2CIDFalse();
1806*cfb92d14SAndroid Build Coastguard Worker
1807*cfb92d14SAndroid Build Coastguard Worker // Stateful multicast addresses compression / decompression tests.
1808*cfb92d14SAndroid Build Coastguard Worker TestStatefulMulticastDestination48bitContext0();
1809*cfb92d14SAndroid Build Coastguard Worker
1810*cfb92d14SAndroid Build Coastguard Worker // Traffic Class and Flow Label compression / decompression tests.
1811*cfb92d14SAndroid Build Coastguard Worker TestTrafficClassFlowLabel3Bytes();
1812*cfb92d14SAndroid Build Coastguard Worker TestTrafficClassFlowLabel1Byte();
1813*cfb92d14SAndroid Build Coastguard Worker TestTrafficClassFlowLabel1ByteEcnOnly();
1814*cfb92d14SAndroid Build Coastguard Worker TestTrafficClassFlowLabelInline();
1815*cfb92d14SAndroid Build Coastguard Worker
1816*cfb92d14SAndroid Build Coastguard Worker // Hop Limit compression / decompression tests.
1817*cfb92d14SAndroid Build Coastguard Worker TestHopLimit1();
1818*cfb92d14SAndroid Build Coastguard Worker TestHopLimit255();
1819*cfb92d14SAndroid Build Coastguard Worker TestHopLimitInline();
1820*cfb92d14SAndroid Build Coastguard Worker
1821*cfb92d14SAndroid Build Coastguard Worker // UDP compression / decompression tests.
1822*cfb92d14SAndroid Build Coastguard Worker TestUdpSourceDestinationInline();
1823*cfb92d14SAndroid Build Coastguard Worker TestUdpSourceInlineDestination8bit();
1824*cfb92d14SAndroid Build Coastguard Worker TestUdpSource8bitDestinationInline();
1825*cfb92d14SAndroid Build Coastguard Worker TestUdpFullyCompressed();
1826*cfb92d14SAndroid Build Coastguard Worker TestUdpFullyCompressedMulticast();
1827*cfb92d14SAndroid Build Coastguard Worker TestUdpWithoutNhc();
1828*cfb92d14SAndroid Build Coastguard Worker
1829*cfb92d14SAndroid Build Coastguard Worker // Extension Headers compression / decompression tests.
1830*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopNoPadding();
1831*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPad1();
1832*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN2();
1833*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN3();
1834*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN4();
1835*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN5();
1836*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN6();
1837*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN7();
1838*cfb92d14SAndroid Build Coastguard Worker TestExtensionHeaderHopByHopPadN2UdpFullyCompressed();
1839*cfb92d14SAndroid Build Coastguard Worker
1840*cfb92d14SAndroid Build Coastguard Worker // IP-in-IP compression / decompression tests.
1841*cfb92d14SAndroid Build Coastguard Worker TestIpInIpHopByHopPadN2UdpSourceDestinationInline();
1842*cfb92d14SAndroid Build Coastguard Worker TestIpInIpWithoutExtensionHeader();
1843*cfb92d14SAndroid Build Coastguard Worker
1844*cfb92d14SAndroid Build Coastguard Worker // Invalid frame to be decompressed.
1845*cfb92d14SAndroid Build Coastguard Worker TestErrorNoIphcDispatch();
1846*cfb92d14SAndroid Build Coastguard Worker TestErrorTruncatedIphc();
1847*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedValueDestination0100();
1848*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedValueDestination1101();
1849*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedValueDestination1110();
1850*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedValueDestination1111();
1851*cfb92d14SAndroid Build Coastguard Worker TestErrorUnknownNhc();
1852*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedNhc5();
1853*cfb92d14SAndroid Build Coastguard Worker TestErrorReservedNhc6();
1854*cfb92d14SAndroid Build Coastguard Worker
1855*cfb92d14SAndroid Build Coastguard Worker testFreeInstance(sInstance);
1856*cfb92d14SAndroid Build Coastguard Worker }
1857*cfb92d14SAndroid Build Coastguard Worker
TestLowpanMeshHeader(void)1858*cfb92d14SAndroid Build Coastguard Worker void TestLowpanMeshHeader(void)
1859*cfb92d14SAndroid Build Coastguard Worker {
1860*cfb92d14SAndroid Build Coastguard Worker enum
1861*cfb92d14SAndroid Build Coastguard Worker {
1862*cfb92d14SAndroid Build Coastguard Worker kMaxFrameSize = 127,
1863*cfb92d14SAndroid Build Coastguard Worker kSourceAddr = 0x100,
1864*cfb92d14SAndroid Build Coastguard Worker kDestAddr = 0x200,
1865*cfb92d14SAndroid Build Coastguard Worker };
1866*cfb92d14SAndroid Build Coastguard Worker
1867*cfb92d14SAndroid Build Coastguard Worker const uint8_t kMeshHeader1[] = {0xb1, 0x01, 0x00, 0x02, 0x00}; // src:0x100, dest:0x200, hop:0x1
1868*cfb92d14SAndroid Build Coastguard Worker const uint8_t kMeshHeader2[] = {0xbf, 0x20, 0x01, 0x00, 0x02, 0x00}; // src:0x100, dest:0x200, hop:0x20
1869*cfb92d14SAndroid Build Coastguard Worker const uint8_t kMeshHeader3[] = {0xbf, 0x01, 0x01, 0x00, 0x02, 0x00}; // src:0x100, dest:0x200, hop:0x1 (deepHops)
1870*cfb92d14SAndroid Build Coastguard Worker
1871*cfb92d14SAndroid Build Coastguard Worker uint8_t frame[kMaxFrameSize];
1872*cfb92d14SAndroid Build Coastguard Worker uint16_t length;
1873*cfb92d14SAndroid Build Coastguard Worker FrameData frameData;
1874*cfb92d14SAndroid Build Coastguard Worker FrameBuilder frameBuilder;
1875*cfb92d14SAndroid Build Coastguard Worker Lowpan::MeshHeader meshHeader;
1876*cfb92d14SAndroid Build Coastguard Worker
1877*cfb92d14SAndroid Build Coastguard Worker meshHeader.Init(kSourceAddr, kDestAddr, 1);
1878*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetSource() == kSourceAddr, "failed after Init()");
1879*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetDestination() == kDestAddr, "failed after Init()");
1880*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetHopsLeft() == 1, "failed after Init()");
1881*cfb92d14SAndroid Build Coastguard Worker
1882*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
1883*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.AppendTo(frameBuilder));
1884*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
1885*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == meshHeader.GetHeaderLength());
1886*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(kMeshHeader1), "MeshHeader::AppendTo() returned length is incorrect");
1887*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kMeshHeader1, length) == 0, "MeshHeader::AppendTo() failed");
1888*cfb92d14SAndroid Build Coastguard Worker
1889*cfb92d14SAndroid Build Coastguard Worker memset(&meshHeader, 0, sizeof(meshHeader));
1890*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
1891*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(Lowpan::MeshHeader::IsMeshHeader(frameData));
1892*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.ParseFrom(frameData));
1893*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
1894*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - frame == length, "ParseFrom() did not skip over parsed content");
1895*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetSource() == kSourceAddr, "failed after ParseFrom()");
1896*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetDestination() == kDestAddr, "failed after ParseFrom()");
1897*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetHopsLeft() == 1, "failed after ParseFrom()");
1898*cfb92d14SAndroid Build Coastguard Worker
1899*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length - 1);
1900*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.ParseFrom(frameData) == kErrorParse,
1901*cfb92d14SAndroid Build Coastguard Worker "MeshHeader::ParseFrom() did not fail with incorrect length");
1902*cfb92d14SAndroid Build Coastguard Worker
1903*cfb92d14SAndroid Build Coastguard Worker //- - - - - - - - - - - - - - - - - - - - - - - - - -
1904*cfb92d14SAndroid Build Coastguard Worker
1905*cfb92d14SAndroid Build Coastguard Worker meshHeader.Init(kSourceAddr, kDestAddr, 0x20);
1906*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetSource() == kSourceAddr, "failed after Init()");
1907*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetDestination() == kDestAddr, "failed after Init()");
1908*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetHopsLeft() == 0x20, "failed after Init()");
1909*cfb92d14SAndroid Build Coastguard Worker
1910*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
1911*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.AppendTo(frameBuilder));
1912*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
1913*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(kMeshHeader2), "MeshHeader::AppendTo() returned length is incorrect");
1914*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == meshHeader.GetHeaderLength());
1915*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kMeshHeader2, length) == 0, "MeshHeader::AppendTo() failed");
1916*cfb92d14SAndroid Build Coastguard Worker
1917*cfb92d14SAndroid Build Coastguard Worker memset(&meshHeader, 0, sizeof(meshHeader));
1918*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
1919*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(Lowpan::MeshHeader::IsMeshHeader(frameData));
1920*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.ParseFrom(frameData));
1921*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
1922*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - frame == length, "ParseFrom() did not skip over parsed content");
1923*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetSource() == kSourceAddr, "failed after ParseFrom()");
1924*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetDestination() == kDestAddr, "failed after ParseFrom()");
1925*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetHopsLeft() == 0x20, "failed after ParseFrom()");
1926*cfb92d14SAndroid Build Coastguard Worker
1927*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length - 1);
1928*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.ParseFrom(frameData) == kErrorParse,
1929*cfb92d14SAndroid Build Coastguard Worker "MeshHeader::ParseFrom() did not fail with incorrect length");
1930*cfb92d14SAndroid Build Coastguard Worker
1931*cfb92d14SAndroid Build Coastguard Worker //- - - - - - - - - - - - - - - - - - - - - - - - - -
1932*cfb92d14SAndroid Build Coastguard Worker
1933*cfb92d14SAndroid Build Coastguard Worker length = sizeof(kMeshHeader3);
1934*cfb92d14SAndroid Build Coastguard Worker frameData.Init(kMeshHeader3, sizeof(kMeshHeader3));
1935*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.ParseFrom(frameData));
1936*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
1937*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - kMeshHeader3 == length, "ParseFrom() did not skip over parsed content");
1938*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetSource() == kSourceAddr, "failed after ParseFrom()");
1939*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetDestination() == kDestAddr, "failed after ParseFrom()");
1940*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.GetHopsLeft() == 1, "failed after ParseFrom()");
1941*cfb92d14SAndroid Build Coastguard Worker
1942*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
1943*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(meshHeader.AppendTo(frameBuilder));
1944*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameBuilder.GetLength() == sizeof(kMeshHeader1));
1945*cfb92d14SAndroid Build Coastguard Worker
1946*cfb92d14SAndroid Build Coastguard Worker frameData.Init(kMeshHeader3, sizeof(kMeshHeader3) - 1);
1947*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(meshHeader.ParseFrom(frameData) == kErrorParse,
1948*cfb92d14SAndroid Build Coastguard Worker "MeshHeader::ParseFrom() did not fail with incorrect length");
1949*cfb92d14SAndroid Build Coastguard Worker }
1950*cfb92d14SAndroid Build Coastguard Worker
TestLowpanFragmentHeader(void)1951*cfb92d14SAndroid Build Coastguard Worker void TestLowpanFragmentHeader(void)
1952*cfb92d14SAndroid Build Coastguard Worker {
1953*cfb92d14SAndroid Build Coastguard Worker static constexpr uint16_t kMaxFrameSize = 127;
1954*cfb92d14SAndroid Build Coastguard Worker static constexpr uint16_t kSize = 0x7ef;
1955*cfb92d14SAndroid Build Coastguard Worker static constexpr uint16_t kTag = 0x1234;
1956*cfb92d14SAndroid Build Coastguard Worker static constexpr uint16_t kOffset = (100 * 8);
1957*cfb92d14SAndroid Build Coastguard Worker
1958*cfb92d14SAndroid Build Coastguard Worker const uint8_t kFragHeader1[] = {0xc7, 0xef, 0x12, 0x34}; // size:0x7ef, tag:0x1234, offset:0 (first frag)
1959*cfb92d14SAndroid Build Coastguard Worker const uint8_t kFragHeader2[] = {0xe7, 0xef, 0x12, 0x34, 0x64}; // size:0x7ef, tag:0x1234, offset:100 (next frag)
1960*cfb92d14SAndroid Build Coastguard Worker const uint8_t kFragHeader3[] = {0xe7, 0xef, 0x12, 0x34, 0x00}; // size:0x7ef, tag:0x1234, offset:0 (next frag)
1961*cfb92d14SAndroid Build Coastguard Worker
1962*cfb92d14SAndroid Build Coastguard Worker const uint8_t kInvalidFragHeader1[] = {0xe8, 0xef, 0x12, 0x34, 0x64};
1963*cfb92d14SAndroid Build Coastguard Worker const uint8_t kInvalidFragHeader2[] = {0xd0, 0xef, 0x12, 0x34, 0x64};
1964*cfb92d14SAndroid Build Coastguard Worker const uint8_t kInvalidFragHeader3[] = {0x90, 0xef, 0x12, 0x34, 0x64};
1965*cfb92d14SAndroid Build Coastguard Worker
1966*cfb92d14SAndroid Build Coastguard Worker uint8_t frame[kMaxFrameSize];
1967*cfb92d14SAndroid Build Coastguard Worker uint16_t length;
1968*cfb92d14SAndroid Build Coastguard Worker FrameData frameData;
1969*cfb92d14SAndroid Build Coastguard Worker FrameBuilder frameBuilder;
1970*cfb92d14SAndroid Build Coastguard Worker Lowpan::FragmentHeader fragHeader;
1971*cfb92d14SAndroid Build Coastguard Worker Lowpan::FragmentHeader::FirstFrag firstFragHeader;
1972*cfb92d14SAndroid Build Coastguard Worker Lowpan::FragmentHeader::NextFrag nextFragHeader;
1973*cfb92d14SAndroid Build Coastguard Worker
1974*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
1975*cfb92d14SAndroid Build Coastguard Worker
1976*cfb92d14SAndroid Build Coastguard Worker firstFragHeader.Init(kSize, kTag);
1977*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(frameBuilder.Append(firstFragHeader));
1978*cfb92d14SAndroid Build Coastguard Worker
1979*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
1980*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(Lowpan::FragmentHeader::FirstFrag));
1981*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kFragHeader1, length) == 0);
1982*cfb92d14SAndroid Build Coastguard Worker
1983*cfb92d14SAndroid Build Coastguard Worker memset(&fragHeader, 0, sizeof(fragHeader));
1984*cfb92d14SAndroid Build Coastguard Worker
1985*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
1986*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(Lowpan::FragmentHeader::IsFragmentHeader(frameData));
1987*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(fragHeader.ParseFrom(frameData));
1988*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
1989*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - frame == length, "ParseFrom() did not skip over parsed content");
1990*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramSize() == kSize, "failed after ParseFrom()");
1991*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramTag() == kTag, "failed after ParseFrom()");
1992*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramOffset() == 0, "failed after ParseFrom()");
1993*cfb92d14SAndroid Build Coastguard Worker
1994*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length - 1);
1995*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) == kErrorParse,
1996*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with incorrect length");
1997*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length - 1);
1998*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
1999*cfb92d14SAndroid Build Coastguard Worker
2000*cfb92d14SAndroid Build Coastguard Worker //- - - - - - - - - - - - - - - - - - - - - - - - - -
2001*cfb92d14SAndroid Build Coastguard Worker
2002*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
2003*cfb92d14SAndroid Build Coastguard Worker nextFragHeader.Init(kSize, kTag, kOffset);
2004*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(frameBuilder.Append(nextFragHeader));
2005*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
2006*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(kFragHeader2));
2007*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kFragHeader2, length) == 0);
2008*cfb92d14SAndroid Build Coastguard Worker
2009*cfb92d14SAndroid Build Coastguard Worker // Check the truncation of offset (to be multiple of 8).
2010*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
2011*cfb92d14SAndroid Build Coastguard Worker nextFragHeader.Init(kSize, kTag, kOffset + 1);
2012*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(frameBuilder.Append(nextFragHeader));
2013*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
2014*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(kFragHeader2));
2015*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kFragHeader2, length) == 0);
2016*cfb92d14SAndroid Build Coastguard Worker
2017*cfb92d14SAndroid Build Coastguard Worker frameBuilder.Init(frame, sizeof(frame));
2018*cfb92d14SAndroid Build Coastguard Worker nextFragHeader.Init(kSize, kTag, kOffset + 7);
2019*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(frameBuilder.Append(nextFragHeader));
2020*cfb92d14SAndroid Build Coastguard Worker length = frameBuilder.GetLength();
2021*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(length == sizeof(kFragHeader2));
2022*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(memcmp(frame, kFragHeader2, length) == 0);
2023*cfb92d14SAndroid Build Coastguard Worker
2024*cfb92d14SAndroid Build Coastguard Worker memset(&fragHeader, 0, sizeof(fragHeader));
2025*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
2026*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(Lowpan::FragmentHeader::IsFragmentHeader(frameData));
2027*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(fragHeader.ParseFrom(frameData));
2028*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
2029*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - frame == length, "ParseFrom() did not skip over parsed content");
2030*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramSize() == kSize, "failed after ParseFrom()");
2031*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramTag() == kTag, "failed after ParseFrom()");
2032*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramOffset() == kOffset, "failed after ParseFrom()");
2033*cfb92d14SAndroid Build Coastguard Worker
2034*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length - 1);
2035*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) == kErrorParse,
2036*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with incorrect length");
2037*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length - 1);
2038*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
2039*cfb92d14SAndroid Build Coastguard Worker
2040*cfb92d14SAndroid Build Coastguard Worker //- - - - - - - - - - - - - - - - - - - - - - - - - -
2041*cfb92d14SAndroid Build Coastguard Worker
2042*cfb92d14SAndroid Build Coastguard Worker length = sizeof(kFragHeader3);
2043*cfb92d14SAndroid Build Coastguard Worker memcpy(frame, kFragHeader3, length);
2044*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
2045*cfb92d14SAndroid Build Coastguard Worker SuccessOrQuit(fragHeader.ParseFrom(frameData));
2046*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == 0, "ParseFrom() did not skip over parsed content");
2047*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() - frame == length, "ParseFrom() did not skip over parsed content");
2048*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramSize() == kSize, "failed after ParseFrom()");
2049*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramTag() == kTag, "failed after ParseFrom()");
2050*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.GetDatagramOffset() == 0, "failed after ParseFrom()");
2051*cfb92d14SAndroid Build Coastguard Worker
2052*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length - 1);
2053*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) == kErrorParse,
2054*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with incorrect length");
2055*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length - 1);
2056*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
2057*cfb92d14SAndroid Build Coastguard Worker
2058*cfb92d14SAndroid Build Coastguard Worker //- - - - - - - - - - - - - - - - - - - - - - - - - -
2059*cfb92d14SAndroid Build Coastguard Worker
2060*cfb92d14SAndroid Build Coastguard Worker length = sizeof(kInvalidFragHeader1);
2061*cfb92d14SAndroid Build Coastguard Worker memcpy(frame, kInvalidFragHeader1, length);
2062*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
2063*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(!Lowpan::FragmentHeader::IsFragmentHeader(frameData),
2064*cfb92d14SAndroid Build Coastguard Worker "IsFragmentHeader() did not detect invalid header");
2065*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) != kErrorNone,
2066*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with invalid header");
2067*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length);
2068*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
2069*cfb92d14SAndroid Build Coastguard Worker
2070*cfb92d14SAndroid Build Coastguard Worker length = sizeof(kInvalidFragHeader2);
2071*cfb92d14SAndroid Build Coastguard Worker memcpy(frame, kInvalidFragHeader2, length);
2072*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
2073*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(!Lowpan::FragmentHeader::IsFragmentHeader(frameData),
2074*cfb92d14SAndroid Build Coastguard Worker "IsFragmentHeader() did not detect invalid header");
2075*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) != kErrorNone,
2076*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with invalid header");
2077*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length);
2078*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
2079*cfb92d14SAndroid Build Coastguard Worker
2080*cfb92d14SAndroid Build Coastguard Worker length = sizeof(kInvalidFragHeader3);
2081*cfb92d14SAndroid Build Coastguard Worker memcpy(frame, kInvalidFragHeader3, length);
2082*cfb92d14SAndroid Build Coastguard Worker frameData.Init(frame, length);
2083*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(!Lowpan::FragmentHeader::IsFragmentHeader(frameData),
2084*cfb92d14SAndroid Build Coastguard Worker "IsFragmentHeader() did not detect invalid header");
2085*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(fragHeader.ParseFrom(frameData) != kErrorNone,
2086*cfb92d14SAndroid Build Coastguard Worker "FragmentHeader::ParseFrom() did not fail with invalid header");
2087*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetLength() == length);
2088*cfb92d14SAndroid Build Coastguard Worker VerifyOrQuit(frameData.GetBytes() == frame);
2089*cfb92d14SAndroid Build Coastguard Worker }
2090*cfb92d14SAndroid Build Coastguard Worker
2091*cfb92d14SAndroid Build Coastguard Worker } // namespace ot
2092*cfb92d14SAndroid Build Coastguard Worker
main(void)2093*cfb92d14SAndroid Build Coastguard Worker int main(void)
2094*cfb92d14SAndroid Build Coastguard Worker {
2095*cfb92d14SAndroid Build Coastguard Worker ot::TestLowpanIphc();
2096*cfb92d14SAndroid Build Coastguard Worker ot::TestLowpanMeshHeader();
2097*cfb92d14SAndroid Build Coastguard Worker ot::TestLowpanFragmentHeader();
2098*cfb92d14SAndroid Build Coastguard Worker
2099*cfb92d14SAndroid Build Coastguard Worker printf("All tests passed\n");
2100*cfb92d14SAndroid Build Coastguard Worker return 0;
2101*cfb92d14SAndroid Build Coastguard Worker }
2102