forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestInetLayerCommon.hpp
161 lines (119 loc) · 5 KB
/
TestInetLayerCommon.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Google LLC
* 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.
*/
/**
* @file
* This file defines common preprocessor defintions, constants,
* functions, and globals for unit and functional tests for the
* Inet layer.
*
*/
#ifndef CHIP_TEST_INETLAYER_COMMON_HPP
#define CHIP_TEST_INETLAYER_COMMON_HPP
#include <stddef.h>
#include <stdint.h>
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/UDPEndPoint.h>
#include <system/SystemLayer.h>
#include <system/SystemPacketBuffer.h>
// Preprocessor Macros
#define SetStatusFailed(aTestStatus) \
do \
{ \
(aTestStatus).mFailed = true; \
fprintf(stderr, "Test failed at %s:%u!\n", __func__, __LINE__); \
} while (0)
#define kToolOptBase 1000
#define kToolOptInterface 'I'
#define kToolOptIPv4Only '4'
#define kToolOptIPv6Only '6'
#define kToolOptInterval 'i'
#define kToolOptListen 'l'
#define kToolOptSendSize 's'
#define kToolOptUDPIP 'u'
// Type Definitions
enum OptFlagsCommon
{
kOptFlagUseIPv4 = 0x00000001,
kOptFlagUseIPv6 = 0x00000002,
kOptFlagUseUDPIP = 0x00000008,
kOptFlagListen = 0x00000010,
};
enum kICMPTypeIndex
{
kICMP_EchoRequestIndex = 0,
kICMP_EchoReplyIndex = 1
};
struct Stats
{
uint32_t mExpected;
uint32_t mActual;
};
struct TransferStats
{
struct Stats mReceive;
struct Stats mTransmit;
};
struct TestStatus
{
bool mFailed;
bool mSucceeded;
};
// Global Variables
static const uint16_t kUDPPort = 4242;
static const size_t kICMPv4_FilterTypes = 2;
static const size_t kICMPv6_FilterTypes = 2;
extern const uint8_t gICMPv4Types[kICMPv4_FilterTypes];
extern const uint8_t gICMPv6Types[kICMPv6_FilterTypes];
extern bool gSendIntervalExpired;
extern uint32_t gSendIntervalMs;
extern const char * gInterfaceName;
extern chip::Inet::InterfaceId gInterfaceId;
extern uint16_t gSendSize;
extern uint32_t gOptFlags;
// Function Prototypes
namespace Common {
extern bool IsReceiver();
extern bool IsSender();
extern bool IsTesting(const TestStatus & aTestStatus);
extern bool WasSuccessful(const TestStatus & aTestStatus);
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength, uint8_t aFirstValue);
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength);
extern chip::System::PacketBufferHandle MakeICMPv4DataBuffer(uint16_t aDesiredUserLength);
extern chip::System::PacketBufferHandle MakeICMPv6DataBuffer(uint16_t aDesiredUserLength);
extern bool HandleDataReceived(const chip::System::PacketBufferHandle & aBuffer, TransferStats & aStats, bool aStatsByPacket,
bool aCheckBuffer, uint8_t aFirstValue);
extern bool HandleDataReceived(const chip::System::PacketBufferHandle & aBuffer, TransferStats & aStats, bool aStatsByPacket,
bool aCheckBuffer);
extern bool HandleICMPv4DataReceived(chip::System::PacketBufferHandle && aBuffer, TransferStats & aStats, bool aStatsByPacket,
bool aCheckBuffer);
extern bool HandleICMPv6DataReceived(chip::System::PacketBufferHandle && aBuffer, TransferStats & aStats, bool aStatsByPacket,
bool aCheckBuffer);
// Timer Callback Handler
extern void HandleSendTimerComplete(chip::System::Layer * aSystemLayer, void * aAppState);
// UDP Endpoint Callback Handlers
extern void HandleUDPMessageReceived(const chip::Inet::UDPEndPoint * aEndPoint, const chip::System::PacketBufferHandle & aBuffer,
const chip::Inet::IPPacketInfo * aPacketInfo);
extern void HandleUDPReceiveError(const chip::Inet::UDPEndPoint * aEndPoint, const CHIP_ERROR & aError,
const chip::Inet::IPPacketInfo * aPacketInfo);
} // namespace Common
// Period send function to be implemented by individual tests but
// referenced by common code.
extern void DriveSend();
#endif // CHIP_TEST_INETLAYER_COMMON_HPP