1 /* 2 * FreeRTOS+TCP <DEVELOPMENT BRANCH> 3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * SPDX-License-Identifier: MIT 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 * this software and associated documentation files (the "Software"), to deal in 9 * the Software without restriction, including without limitation the rights to 10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 * the Software, and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in all 15 * copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * http://aws.amazon.com/freertos 25 * http://www.FreeRTOS.org 26 */ 27 28 #ifndef TCP_NETSTAT_H 29 30 #define TCP_NETSTAT_H 31 32 #ifndef nstatMAX_UDP_PORTS 33 #define nstatMAX_UDP_PORTS 12U 34 #endif 35 36 #ifndef nstatMAX_TCP_PORTS 37 #define nstatMAX_TCP_PORTS 12U 38 #endif 39 40 #ifndef nstatMAX_UDP_SOCKETS 41 #define nstatMAX_UDP_SOCKETS 12U 42 #endif 43 44 #ifndef nstatMAX_TCP_SOCKETS 45 #define nstatMAX_TCP_SOCKETS 12U 46 #endif 47 48 typedef struct xIOCounters 49 { 50 size_t uxByteCount; 51 size_t uxPacketCount; 52 } IOCounters_t; 53 54 extern IOCounters_t xInputCounters, xOutputCounters; 55 56 typedef struct 57 { 58 uint16_t usUDPPortList[ nstatMAX_UDP_PORTS ]; 59 size_t uxCount; 60 } UDPPortList_t; 61 62 typedef struct 63 { 64 uint16_t usTCPPortList[ nstatMAX_TCP_PORTS ]; 65 size_t uxCount; 66 } TCPPortList_t; 67 68 69 typedef struct 70 { 71 uint16_t usLocalPort; 72 uint16_t usRemotePort; 73 uint32_t ulRemoteIP; 74 } TCPEntry_t; 75 76 typedef struct 77 { 78 TCPEntry_t xTCPList[ nstatMAX_TCP_SOCKETS ]; 79 size_t uxCount; 80 } TCPSocketList_t; 81 82 typedef struct 83 { 84 uint16_t usLocalPort; 85 } UDPEntry_t; 86 87 typedef struct 88 { 89 UDPEntry_t xUDPList[ nstatMAX_UDP_SOCKETS ]; 90 size_t uxCount; 91 } UDPSocketList_t; 92 93 typedef struct 94 { 95 UDPPortList_t xUDPPortList; 96 TCPPortList_t xTCPPortList; 97 TCPSocketList_t xTCPSocketList; 98 UDPSocketList_t xUDPSocketList; 99 IOCounters_t xInput; 100 IOCounters_t xOutput; 101 } MetricsType_t; 102 103 extern BaseType_t vGetMetrics( MetricsType_t * pxMetrics ); 104 extern void vShowMetrics( const MetricsType_t * pxMetrics ); 105 106 107 #define iptraceNETWORK_INTERFACE_INPUT( uxDataLength, pucEthernetBuffer ) \ 108 xInputCounters.uxByteCount += uxDataLength; \ 109 xInputCounters.uxPacketCount++; 110 111 #define iptraceNETWORK_INTERFACE_OUTPUT( uxDataLength, pucEthernetBuffer ) \ 112 xOutputCounters.uxByteCount += uxDataLength; \ 113 xOutputCounters.uxPacketCount++; 114 115 116 #endif /* TCP_NETSTAT_H */ 117