Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 Accenture
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include "someip/NetworkResource.h"
14 : #include "someip/TcpConfig.h"
15 : #include "someip/TpConfig.h"
16 : #include "someip/UdpConfig.h"
17 :
18 : #include <etl/array.h>
19 : #include <cstdint>
20 :
21 : namespace someip
22 : {
23 : /**
24 : * The network configuration.
25 : */
26 : class NetworkConfig
27 : {
28 : public:
29 : NetworkConfig(NetworkConfig const&) = delete;
30 : NetworkConfig& operator=(NetworkConfig const&) = delete;
31 :
32 : ::ip::IPAddress _multicastIp;
33 : ::ip::IPAddress _localIp;
34 :
35 : UdpConfig& _udpConfig;
36 : TcpConfig& _tcpConfig;
37 : TpConfig& _tpConfig;
38 :
39 : uint8_t _subnetId;
40 : bool _useMagicCookie;
41 :
42 : protected:
43 : NetworkConfig(
44 : ::ip::IPAddress const& multicastIp,
45 : ::ip::IPAddress const& localIp,
46 : uint8_t subnetId,
47 : UdpConfig& udpConfig,
48 : TcpConfig& tcpConfig,
49 : TpConfig& tpConfig);
50 :
51 : ~NetworkConfig() = default;
52 : };
53 :
54 : namespace internal
55 : {
56 : /**
57 : * Internal network resources.
58 : */
59 : template<
60 : class UdpSocketType,
61 : uint8_t NumUdpSdSockets,
62 : uint8_t NumUdpRpcSockets,
63 : class TcpServerSocketType,
64 : uint8_t NumTcpServerSockets,
65 : class TcpSocketType,
66 : uint8_t NumTcpRpcSockets,
67 : size_t BufferSize,
68 : uint8_t NumTpStreams,
69 : size_t InternalTcpReassembleBufferSize = BufferSize>
70 : class NetworkResources : public NetworkConfig
71 : {
72 : protected:
73 20 : NetworkResources(
74 : ::ip::IPAddress const& multicastIp, ::ip::IPAddress const& localIp, uint8_t const subnetId)
75 : : NetworkConfig(
76 : multicastIp, localIp, subnetId, _udpConfigInstance, _tcpConfigInstance, _tpConfigInstance)
77 20 : , _inputBuffer()
78 20 : , _outputBuffer()
79 20 : , _udpConfigInstance(_inputBuffer, _outputBuffer)
80 20 : , _tcpConfigInstance(_inputBuffer, _outputBuffer)
81 40 : , _tpConfigInstance()
82 20 : {}
83 :
84 20 : ~NetworkResources() = default;
85 :
86 : private:
87 : ::etl::array<uint8_t, BufferSize> _inputBuffer;
88 : ::etl::array<uint8_t, BufferSize> _outputBuffer;
89 :
90 : internal::UdpResources<UdpSocketType, NumUdpSdSockets, NumUdpRpcSockets> _udpConfigInstance;
91 :
92 : internal::TcpResources<
93 : TcpServerSocketType,
94 : NumTcpServerSockets,
95 : TcpSocketType,
96 : NumTcpRpcSockets,
97 : InternalTcpReassembleBufferSize>
98 : _tcpConfigInstance;
99 :
100 : internal::TpResources<NumTpStreams, BufferSize> _tpConfigInstance;
101 : };
102 :
103 : } // namespace internal
104 :
105 : namespace declare
106 : {
107 : /**
108 : * Declares a network configuration with SD.
109 : */
110 : template<
111 : class UdpSocketType,
112 : uint8_t NumUdpRpcSockets,
113 : class TcpServerSocketType,
114 : uint8_t NumTcpServerSockets,
115 : class TcpSocketType,
116 : uint8_t NumTcpRpcSockets,
117 : size_t BufferSize,
118 : uint8_t NumTpStreams = 0U,
119 : bool SdEndpointOption = false,
120 : size_t InternalTcpReassembleBufferSize = BufferSize>
121 : class SdNetworkConfig
122 : : public internal::NetworkResources<
123 : UdpSocketType,
124 : (SdEndpointOption ? 2 : 1),
125 : NumUdpRpcSockets,
126 : TcpServerSocketType,
127 : NumTcpServerSockets,
128 : TcpSocketType,
129 : NumTcpRpcSockets,
130 : BufferSize,
131 : NumTpStreams,
132 : InternalTcpReassembleBufferSize>
133 : {
134 : public:
135 15 : constexpr SdNetworkConfig(
136 : ::ip::IPAddress const& multicastIp, ::ip::IPAddress const& localIp, uint8_t const subnetId)
137 : : internal::NetworkResources<
138 : UdpSocketType,
139 : (SdEndpointOption ? 2 : 1),
140 : NumUdpRpcSockets,
141 : TcpServerSocketType,
142 : NumTcpServerSockets,
143 : TcpSocketType,
144 : NumTcpRpcSockets,
145 : BufferSize,
146 : NumTpStreams,
147 15 : InternalTcpReassembleBufferSize>(multicastIp, localIp, subnetId)
148 15 : {}
149 : };
150 :
151 : /**
152 : * Declares a network configuration with RPC only.
153 : */
154 : template<
155 : class UdpSocketType,
156 : uint8_t NumUdpRpcSockets,
157 : class TcpServerSocketType,
158 : uint8_t NumTcpServerSockets,
159 : class TcpSocketType,
160 : uint8_t NumTcpRpcSockets,
161 : size_t BufferSize,
162 : uint8_t NumTpStreams = 0U,
163 : size_t InternalTcpReassembleBufferSize = BufferSize>
164 : class RpcNetworkConfig
165 : : public internal::NetworkResources<
166 : UdpSocketType,
167 : 0,
168 : NumUdpRpcSockets,
169 : TcpServerSocketType,
170 : NumTcpServerSockets,
171 : TcpSocketType,
172 : NumTcpRpcSockets,
173 : BufferSize,
174 : NumTpStreams,
175 : InternalTcpReassembleBufferSize>
176 : {
177 : public:
178 5 : RpcNetworkConfig(::ip::IPAddress const& localIp, uint8_t const subnetId)
179 : : internal::NetworkResources<
180 : UdpSocketType,
181 : 0,
182 : NumUdpRpcSockets,
183 : TcpServerSocketType,
184 : NumTcpServerSockets,
185 : TcpSocketType,
186 : NumTcpRpcSockets,
187 : BufferSize,
188 : NumTpStreams,
189 5 : InternalTcpReassembleBufferSize>(NetworkResource::INVALID_IP, localIp, subnetId)
190 5 : {}
191 : };
192 :
193 : } // namespace declare
194 : } // namespace someip
|