@@ -2748,6 +2748,56 @@ void test_FreeRTOS_MatchingEndpoint_MatchIPv4Address()
27482748 TEST_ASSERT_EQUAL ( & xEndPoint , pxEndPoint );
27492749}
27502750
2751+ /**
2752+ * @brief FreeRTOS_MatchingEndpoint returns the endpoint with same NetMask.
2753+ *
2754+ * pxNetworkInterfaces is a global variable using in FreeRTOS_Routing as link list head of all interfaces.
2755+ * pxNetworkEndPoints is a global variable using in FreeRTOS_Routing as link list head of all endpoints.
2756+ *
2757+ * Test step:
2758+ * - Create 1 interface and 1 endpoint.
2759+ * - Put interface & endpoint into the list.
2760+ * - Assign 192.168.123.223 (IPV4_DEFAULT_ADDRESS) to the endpoint.
2761+ * - Assign ab:cd:ef:11:22:33 (ucDefaultMACAddress_IPv4) to the endpoint.
2762+ * - Attach endpoint to interface.
2763+ * - Create a network buffer and set IPv4 packet with source and destination address (IPV4_DEFAULT_GATEWAY),
2764+ * and different MAC address.
2765+ * - Call FreeRTOS_MatchingEndpoint and check if returned endpoint is same.
2766+ */
2767+ void test_FreeRTOS_MatchingEndpoint_MatchNetMask ()
2768+ {
2769+ NetworkInterface_t xNetworkInterface ;
2770+ NetworkEndPoint_t xEndPoint ;
2771+ NetworkEndPoint_t * pxEndPoint = NULL ;
2772+ uint8_t * pcNetworkBuffer [ sizeof ( ProtocolPacket_t ) + 4 ] __attribute__( ( aligned ( 32 ) ) );
2773+ ProtocolPacket_t * pxProtocolPacket = ( ProtocolPacket_t * ) ( ( uintptr_t ) ( pcNetworkBuffer ) + 2U );
2774+ const uint8_t ucLocalMACAddress_IPv4 [ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0x11 , 0x11 , 0x11 , 0x11 , 0x11 , 0x11 };
2775+
2776+ /* Initialize network interface. */
2777+ memset ( & xNetworkInterface , 0 , sizeof ( NetworkInterface_t ) );
2778+ pxNetworkInterfaces = & xNetworkInterface ;
2779+
2780+ /* Initialize endpoint. */
2781+ memset ( & xEndPoint , 0 , sizeof ( NetworkEndPoint_t ) );
2782+ xEndPoint .ipv4_settings .ulIPAddress = IPV4_DEFAULT_ADDRESS ;
2783+ memcpy ( xEndPoint .xMACAddress .ucBytes , ucDefaultMACAddress_IPv4 , sizeof ( ucDefaultMACAddress_IPv4 ) );
2784+ xEndPoint .pxNetworkInterface = & xNetworkInterface ;
2785+ pxNetworkEndPoints = & xEndPoint ;
2786+
2787+ /* Initialize network buffer. */
2788+ memset ( pcNetworkBuffer , 0 , sizeof ( pcNetworkBuffer ) );
2789+ /* Ethernet part. */
2790+ memcpy ( pxProtocolPacket -> xTCPPacket .xEthernetHeader .xDestinationAddress .ucBytes , ucLocalMACAddress_IPv4 , sizeof ( ucLocalMACAddress_IPv4 ) );
2791+ memcpy ( pxProtocolPacket -> xTCPPacket .xEthernetHeader .xSourceAddress .ucBytes , ucLocalMACAddress_IPv4 , sizeof ( ucLocalMACAddress_IPv4 ) );
2792+ pxProtocolPacket -> xTCPPacket .xEthernetHeader .usFrameType = ipIPv4_FRAME_TYPE ;
2793+ /* IP part. */
2794+ pxProtocolPacket -> xTCPPacket .xIPHeader .ulSourceIPAddress = IPV4_DEFAULT_GATEWAY ;
2795+ pxProtocolPacket -> xTCPPacket .xIPHeader .ulDestinationIPAddress = IPV4_DEFAULT_GATEWAY ;
2796+
2797+ pxEndPoint = FreeRTOS_MatchingEndpoint ( & xNetworkInterface , ( const uint8_t * ) ( pxProtocolPacket ) );
2798+ TEST_ASSERT_EQUAL ( & xEndPoint , pxEndPoint );
2799+ }
2800+
27512801/**
27522802 * @brief FreeRTOS_MatchingEndpoint returns the endpoint with same MAC address.
27532803 *
0 commit comments