3 * Copyright (c) 2021 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <messaging/ExchangeContext.h>
20 #include <messaging/ExchangeMgr.h>
21 #include <transport/AdminPairingTable.h>
22 #include <transport/SecureSessionMgr.h>
23 #include <transport/TransportMgr.h>
24 #include <transport/raw/tests/NetworkTestHelpers.h>
30 * @brief The context of test cases for messaging layer. It wil initialize network layer and system layer, and create
31 * two secure sessions, connected with each other. Exchanges can be created for each secure session.
33 class MessagingContext : public IOContext
37 mPeer(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT)), mPairingPeerToLocal(GetLocalKeyId(), GetPeerKeyId()),
38 mPairingLocalToPeer(GetPeerKeyId(), GetLocalKeyId())
41 /// Initialize the underlying layers and test suite pointer
42 CHIP_ERROR Init(nlTestSuite * suite, TransportMgrBase * transport);
44 // Shutdown all layers, finalize operations
45 CHIP_ERROR Shutdown();
47 static Inet::IPAddress GetAddress()
50 Inet::IPAddress::FromString("127.0.0.1", addr);
53 static constexpr NodeId GetSourceNodeId() { return 123654; }
54 static constexpr NodeId GetDestinationNodeId() { return 111222333; }
56 static constexpr uint16_t GetLocalKeyId() { return 1; }
57 static constexpr uint16_t GetPeerKeyId() { return 2; }
58 static constexpr uint16_t GetAdminId() { return 0; }
60 SecureSessionMgr & GetSecureSessionManager() { return mSecureSessionMgr; }
61 Messaging::ExchangeManager & GetExchangeManager() { return mExchangeManager; }
63 Messaging::ExchangeContext * NewExchangeToPeer(Messaging::ExchangeDelegate * delegate);
64 Messaging::ExchangeContext * NewExchangeToLocal(Messaging::ExchangeDelegate * delegate);
67 SecureSessionMgr mSecureSessionMgr;
68 Messaging::ExchangeManager mExchangeManager;
70 Optional<Transport::PeerAddress> mPeer;
71 SecurePairingUsingTestSecret mPairingPeerToLocal;
72 SecurePairingUsingTestSecret mPairingLocalToPeer;
73 Transport::AdminPairingTable mAdmins;
74 Transport::AdminId mSrcAdminId = 0;
75 Transport::AdminId mDestAdminId = 1;