/src/openthread/tests/nexus/platform/nexus_node.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, The OpenThread Authors. |
3 | | * All rights reserved. |
4 | | * |
5 | | * Redistribution and use in source and binary forms, with or without |
6 | | * modification, are permitted provided that the following conditions are met: |
7 | | * 1. Redistributions of source code must retain the above copyright |
8 | | * notice, this list of conditions and the following disclaimer. |
9 | | * 2. Redistributions in binary form must reproduce the above copyright |
10 | | * notice, this list of conditions and the following disclaimer in the |
11 | | * documentation and/or other materials provided with the distribution. |
12 | | * 3. Neither the name of the copyright holder nor the |
13 | | * names of its contributors may be used to endorse or promote products |
14 | | * derived from this software without specific prior written permission. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
20 | | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | | * POSSIBILITY OF SUCH DAMAGE. |
27 | | */ |
28 | | |
29 | | #include "nexus_node.hpp" |
30 | | #include "nexus_utils.hpp" |
31 | | |
32 | | namespace ot { |
33 | | namespace Nexus { |
34 | | |
35 | | void Node::Reset(void) |
36 | 0 | { |
37 | 0 | Instance *instance = &GetInstance(); |
38 | 0 | uint32_t id = GetId(); |
39 | |
|
40 | 0 | mRadio.Reset(); |
41 | 0 | mAlarm.Reset(); |
42 | 0 | mMdns.Reset(); |
43 | 0 | mPendingTasklet = false; |
44 | | #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE |
45 | | mTrel.Reset(); |
46 | | #endif |
47 | |
|
48 | 0 | instance->~Instance(); |
49 | |
|
50 | 0 | instance = new (instance) Instance(); |
51 | 0 | instance->SetId(id); |
52 | 0 | instance->AfterInit(); |
53 | 0 | } |
54 | | |
55 | | void Node::Form(void) |
56 | 6.64k | { |
57 | 6.64k | MeshCoP::Dataset::Info datasetInfo; |
58 | | |
59 | 6.64k | SuccessOrQuit(datasetInfo.GenerateRandom(*this)); |
60 | 6.64k | Get<MeshCoP::ActiveDatasetManager>().SaveLocal(datasetInfo); |
61 | | |
62 | 6.64k | Get<ThreadNetif>().Up(); |
63 | 6.64k | SuccessOrQuit(Get<Mle::Mle>().Start()); |
64 | 6.64k | } |
65 | | |
66 | | void Node::Join(Node &aNode, JoinMode aJoinMode) |
67 | 0 | { |
68 | 0 | MeshCoP::Dataset dataset; |
69 | 0 | Mle::DeviceMode mode(0); |
70 | |
|
71 | 0 | switch (aJoinMode) |
72 | 0 | { |
73 | 0 | case kAsFed: |
74 | 0 | SuccessOrQuit(Get<Mle::Mle>().SetRouterEligible(false)); |
75 | 0 | OT_FALL_THROUGH; |
76 | |
|
77 | 0 | case kAsFtd: |
78 | 0 | mode.Set(Mle::DeviceMode::kModeRxOnWhenIdle | Mle::DeviceMode::kModeFullThreadDevice | |
79 | 0 | Mle::DeviceMode::kModeFullNetworkData); |
80 | 0 | break; |
81 | 0 | case kAsMed: |
82 | 0 | mode.Set(Mle::DeviceMode::kModeRxOnWhenIdle | Mle::DeviceMode::kModeFullNetworkData); |
83 | 0 | break; |
84 | 0 | case kAsSed: |
85 | 0 | mode.Set(Mle::DeviceMode::kModeFullNetworkData); |
86 | 0 | break; |
87 | 0 | } |
88 | | |
89 | 0 | SuccessOrQuit(Get<Mle::Mle>().SetDeviceMode(mode)); |
90 | | |
91 | 0 | SuccessOrQuit(aNode.Get<MeshCoP::ActiveDatasetManager>().Read(dataset)); |
92 | 0 | Get<MeshCoP::ActiveDatasetManager>().SaveLocal(dataset); |
93 | |
|
94 | 0 | Get<ThreadNetif>().Up(); |
95 | 0 | SuccessOrQuit(Get<Mle::Mle>().Start()); |
96 | 0 | } |
97 | | |
98 | | void Node::AllowList(Node &aNode) |
99 | 0 | { |
100 | 0 | SuccessOrQuit(Get<Mac::Filter>().AddAddress(aNode.Get<Mac::Mac>().GetExtAddress())); |
101 | 0 | Get<Mac::Filter>().SetMode(Mac::Filter::kModeAllowlist); |
102 | 0 | } |
103 | | |
104 | 0 | void Node::UnallowList(Node &aNode) { Get<Mac::Filter>().RemoveAddress(aNode.Get<Mac::Mac>().GetExtAddress()); } |
105 | | |
106 | | #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE |
107 | | void Node::GetTrelSockAddr(Ip6::SockAddr &aSockAddr) const |
108 | | { |
109 | | aSockAddr.SetAddress(mMdns.mIfAddresses[0]); |
110 | | aSockAddr.SetPort(mTrel.mUdpPort); |
111 | | } |
112 | | #endif |
113 | | |
114 | | } // namespace Nexus |
115 | | } // namespace ot |