-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPv6 multicast build method added to PeerAddress (#11368)
* PeerAddress: Added methods to construct the IPv6 Multicast Address. * PeerAddress: Code review comments applied.
- Loading branch information
1 parent
95a5422
commit 1434288
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* Copyright (c) 2016-2017 Nest Labs, Inc. | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __STDC_FORMAT_MACROS | ||
#define __STDC_FORMAT_MACROS | ||
#endif | ||
|
||
#ifndef __STDC_LIMIT_MACROS | ||
#define __STDC_LIMIT_MACROS | ||
#endif | ||
|
||
#include <inttypes.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include <inet/IPAddress.h> | ||
#include <lib/core/DataModelTypes.h> | ||
#include <lib/core/PeerId.h> | ||
#include <lib/support/UnitTestRegistration.h> | ||
#include <transport/raw/PeerAddress.h> | ||
|
||
#include <nlunit-test.h> | ||
|
||
using namespace chip; | ||
|
||
/** | ||
* Test correct identification of IPv6 multicast addresses. | ||
*/ | ||
void TestPeerAddressMulticast(nlTestSuite * inSuite, void * inContext) | ||
{ | ||
constexpr chip::FabricId fabric = 0xa1a2a4a8b1b2b4b8; | ||
constexpr chip::GroupId group = 0xe10f; | ||
chip::Transport::PeerAddress addr = chip::Transport::PeerAddress::Multicast(fabric, group); | ||
NL_TEST_ASSERT(inSuite, chip::Transport::Type::kUdp == addr.GetTransportType()); | ||
NL_TEST_ASSERT(inSuite, addr.IsMulticast()); | ||
|
||
const Inet::IPAddress & ip = addr.GetIPAddress(); | ||
NL_TEST_ASSERT(inSuite, ip.IsIPv6Multicast()); | ||
NL_TEST_ASSERT(inSuite, chip::Inet::IPAddressType::kIPv6 == ip.Type()); | ||
|
||
constexpr uint8_t expected[NL_INET_IPV6_ADDR_LEN_IN_BYTES] = { 0xff, 0x35, 0x00, 0x40, 0xfd, 0xa1, 0xa2, 0xa4, | ||
0xa8, 0xb1, 0xb2, 0xb4, 0xb8, 0x00, 0xe1, 0x0f }; | ||
uint8_t result[NL_INET_IPV6_ADDR_LEN_IN_BYTES]; | ||
uint8_t * p = result; | ||
ip.WriteAddress(p); | ||
NL_TEST_ASSERT(inSuite, !memcmp(expected, result, NL_INET_IPV6_ADDR_LEN_IN_BYTES)); | ||
} | ||
|
||
/** | ||
* Test Suite. It lists all the test functions. | ||
*/ | ||
|
||
// clang-format off | ||
static const nlTest sTests[] = | ||
{ | ||
NL_TEST_DEF("PeerAddress Multicast", TestPeerAddressMulticast), | ||
NL_TEST_SENTINEL() | ||
}; | ||
// clang-format on | ||
|
||
int TestPeerAddress(void) | ||
{ | ||
// clang-format off | ||
nlTestSuite theSuite = | ||
{ | ||
"PeerAddress", | ||
&sTests[0], | ||
nullptr, | ||
nullptr | ||
}; | ||
// clang-format on | ||
|
||
// Run test suit againt one context. | ||
nlTestRunner(&theSuite, nullptr); | ||
|
||
return (nlTestRunnerStats(&theSuite)); | ||
} | ||
|
||
CHIP_REGISTER_TEST_SUITE(TestPeerAddress) |