Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / messaging / tests / MessagingContext.h
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 #pragma once
18
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>
25
26 namespace chip {
27 namespace Test {
28
29 /**
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.
32  */
33 class MessagingContext : public IOContext
34 {
35 public:
36     MessagingContext() :
37         mPeer(Transport::PeerAddress::UDP(GetAddress(), CHIP_PORT)), mPairingPeerToLocal(GetLocalKeyId(), GetPeerKeyId()),
38         mPairingLocalToPeer(GetPeerKeyId(), GetLocalKeyId())
39     {}
40
41     /// Initialize the underlying layers and test suite pointer
42     CHIP_ERROR Init(nlTestSuite * suite, TransportMgrBase * transport);
43
44     // Shutdown all layers, finalize operations
45     CHIP_ERROR Shutdown();
46
47     static Inet::IPAddress GetAddress()
48     {
49         Inet::IPAddress addr;
50         Inet::IPAddress::FromString("127.0.0.1", addr);
51         return addr;
52     }
53     static constexpr NodeId GetSourceNodeId() { return 123654; }
54     static constexpr NodeId GetDestinationNodeId() { return 111222333; }
55
56     static constexpr uint16_t GetLocalKeyId() { return 1; }
57     static constexpr uint16_t GetPeerKeyId() { return 2; }
58     static constexpr uint16_t GetAdminId() { return 0; }
59
60     SecureSessionMgr & GetSecureSessionManager() { return mSecureSessionMgr; }
61     Messaging::ExchangeManager & GetExchangeManager() { return mExchangeManager; }
62
63     Messaging::ExchangeContext * NewExchangeToPeer(Messaging::ExchangeDelegate * delegate);
64     Messaging::ExchangeContext * NewExchangeToLocal(Messaging::ExchangeDelegate * delegate);
65
66 private:
67     SecureSessionMgr mSecureSessionMgr;
68     Messaging::ExchangeManager mExchangeManager;
69
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;
76 };
77
78 } // namespace Test
79 } // namespace chip