Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions source/FreeRTOS_TCP_Transmission.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,10 +1004,30 @@

pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_ACK;

if( lDataLen != 0L )
#if ( ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY == ipconfigENABLE )
{
pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_PSH;
/* Peers like Linux send an ACK at once for every segment that carries PSH.
* Like Linux, also push after half the peer's window, for receivers that wait for PSH. */
if( lDataLen != 0L )
{
pxSocket->u.xTCP.ulUnpushedBytes += ( uint32_t ) lDataLen;

if( ( uxStreamBufferDistance( pxSocket->u.xTCP.txStream, ( size_t ) lStreamPos, pxSocket->u.xTCP.txStream->uxHead ) == ( size_t ) lDataLen ) ||
( pxSocket->u.xTCP.ulUnpushedBytes > ( pxSocket->u.xTCP.ulWindowSize / 2U ) ) )
{
pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_PSH;
pxSocket->u.xTCP.ulUnpushedBytes = 0U;
}
}
}
#else
{
if( lDataLen != 0L )
{
pxProtocolHeaders->xTCPHeader.ucTCPFlags |= ( uint8_t ) tcpTCP_FLAG_PSH;
}
}
#endif /* if ( ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY == ipconfigENABLE ) */

uxIntermediateResult = uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength;
lDataLen += ( int32_t ) uxIntermediateResult;
Expand Down
28 changes: 27 additions & 1 deletion source/FreeRTOS_TCP_Transmission_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,38 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
pvCopySource = &pxEthernetHeader->xSourceAddress;
ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;

eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &pxEndPoint );
#if ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U )
{
/* A socket's header template holds the peer MAC, which is trusted while
* the socket was active recently (RFC 1122 2.3.2.1). */
if( ( pxSocket != NULL ) && ( ( xTaskGetTickCount() - pxSocket->u.xTCP.xLastActTime ) < pdMS_TO_TICKS( ipconfigTCP_SKIP_ARP_LOOKUP_MS ) ) )
{
eResult = eResolutionCacheMiss;
}
else
{
eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &pxEndPoint );
}
}
#else /* if ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U ) */
{
eResult = eARPGetCacheEntry( &ulDestinationIPAddress, &xMACAddress, &pxEndPoint );
}
#endif /* if ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U ) */

if( eResult == eResolutionCacheHit )
{
pvCopySource = &xMACAddress;
pxNetworkBuffer->pxEndPoint = pxEndPoint;

#if ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U )
{
if( pxSocket != NULL )
{
( void ) memcpy( ( ( TCPPacket_t * ) pxSocket->u.xTCP.xPacket.u.ucLastPacket )->xEthernetHeader.xSourceAddress.ucBytes, xMACAddress.ucBytes, ipMAC_ADDRESS_LENGTH_BYTES );
}
}
#endif
}
else
{
Expand Down
59 changes: 59 additions & 0 deletions source/include/FreeRTOSIPConfigDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,33 @@ STATIC_ASSERT( ipconfigTCP_KEEP_ALIVE_INTERVAL <= ( portMAX_DELAY / configTICK_R

/*---------------------------------------------------------------------------*/

/*
* ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY
*
* Type: BaseType_t ( ipconfigENABLE | ipconfigDISABLE )
*
* When enabled, the stack sets the PSH flag only on the TCP segment that
* carries the last byte queued for sending, and on the segment that takes the
* data sent since the last PSH over half the peer's window, as Linux does. The
* second rule keeps a receiver that waits for PSH delivering data while the
* send queue never empties. When disabled, it sets PSH on every segment that
* carries data.
*
* Peers such as Linux send an ACK at once for every segment that carries PSH.
* With this enabled, a peer acknowledges a run of segments with one ACK, which
* leaves the IP task more time for sending.
*/

#ifndef ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY
#define ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY ipconfigDISABLE
#endif

#if ( ( ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY != ipconfigDISABLE ) && ( ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY != ipconfigENABLE ) )
#error Invalid ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY configuration
#endif

/*---------------------------------------------------------------------------*/

/*
* ipconfigTCP_MSS
*
Expand Down Expand Up @@ -1484,6 +1511,38 @@ STATIC_ASSERT( ipconfigTCP_KEEP_ALIVE_INTERVAL <= ( portMAX_DELAY / configTICK_R

/*---------------------------------------------------------------------------*/

/*
* ipconfigTCP_SKIP_ARP_LOOKUP_MS
*
* Type: uint32_t
* Unit: milliseconds
*
* A connected TCP socket sends its segments to the peer MAC address in its
* header template, without searching the ARP cache, while the socket received
* a segment or changed state within this time. After that, each sent segment
* searches the ARP cache again, and a hit replaces the MAC address in the
* template. RFC 1122 section 2.3.2.1 allows this, since the peer's replies
* show that its address still works.
*
* Searching the ARP cache for every sent segment can limit TCP throughput on a
* slow CPU. Segments that have no socket, such as resets, always search the
* cache.
*
* The default is 0, which searches the ARP cache for every segment. A value
* above 0 needs ipconfigTCP_HANG_PROTECTION, which keeps the time of the last
* activity.
*/

#ifndef ipconfigTCP_SKIP_ARP_LOOKUP_MS
#define ipconfigTCP_SKIP_ARP_LOOKUP_MS 0U
#endif

#if ( ( ipconfigTCP_SKIP_ARP_LOOKUP_MS > 0U ) && ( ipconfigTCP_HANG_PROTECTION != ipconfigENABLE ) )
#error ipconfigTCP_SKIP_ARP_LOOKUP_MS needs ipconfigTCP_HANG_PROTECTION
#endif

/*---------------------------------------------------------------------------*/

/*
* ipconfigTCP_RX_BUFFER_LENGTH
*
Expand Down
3 changes: 3 additions & 0 deletions source/include/FreeRTOS_IP_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ BaseType_t xIPIsNetworkTaskReady( void );
FOnConnected_t pxHandleConnected; /**< Actually type: typedef void (* FOnConnected_t) (Socket_t xSocket, BaseType_t ulConnected ); */
#endif /* ipconfigUSE_CALLBACKS */
uint32_t ulWindowSize; /**< Current Window size advertised by peer */
#if ( ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY == ipconfigENABLE )
uint32_t ulUnpushedBytes; /**< Bytes sent since the last segment that carried PSH */
#endif
size_t uxRxWinSize; /**< Fixed value: size of the TCP reception window */
size_t uxTxWinSize; /**< Fixed value: size of the TCP transmit window */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,30 @@
],
"DEF":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
{
"default":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
]
},
{
"PSH_ON_LAST_SEGMENT_ONLY":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL",
"ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY=1"
]
},
{
"PSH_AND_SKIP_ARP_LOOKUP":
[
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL",
"ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY=1",
"ipconfigTCP_SKIP_ARP_LOOKUP_MS=1000"
]
}
],
"INC":
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,33 @@
],
"DEF":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
{
"default":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL"
]
},
{
"SKIP_ARP_LOOKUP":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL",
"ipconfigTCP_SKIP_ARP_LOOKUP_MS=1000"
]
},
{
"PSH_AND_SKIP_ARP_LOOKUP":
[
"ipconfigUSE_LINKED_RX_MESSAGES={RX_MESSAGES}",
"FREERTOS_TCP_ENABLE_VERIFICATION",
"CBMC_REQUIRE_NETWORKBUFFER_ETHERNETBUFFER_NONNULL",
"ipconfigTCP_PSH_ON_LAST_SEGMENT_ONLY=1",
"ipconfigTCP_SKIP_ARP_LOOKUP_MS=1000"
]
}
],
"INC":
[
Expand Down
6 changes: 6 additions & 0 deletions test/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling_IPv4/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_State_Handling_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Transmission/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Transmission_DiffConfig/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Transmission_IPv6/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Utils/ut.cmake )
include( ${UNIT_TEST_DIR}/FreeRTOS_TCP_Utils_IPv6/ut.cmake )
Expand Down Expand Up @@ -416,6 +417,11 @@ add_custom_target( coverage
FreeRTOS_TCP_State_Handling_IPv4_utest
FreeRTOS_TCP_State_Handling_IPv6_utest
FreeRTOS_TCP_Transmission_utest
FreeRTOS_TCP_Transmission_DiffConfig_utest
FreeRTOS_TCP_Transmission_DiffConfig_PSHOnly_utest
FreeRTOS_TCP_Transmission_DiffConfig_ARPOnly_utest
FreeRTOS_TCP_Transmission_DiffConfig_Disabled_utest
FreeRTOS_TCP_Transmission_DiffConfig_Defaults_utest
FreeRTOS_TCP_Transmission_IPv6_utest
FreeRTOS_TCP_Utils_utest
FreeRTOS_TCP_Utils_IPv6_utest
Expand Down
124 changes: 124 additions & 0 deletions test/unit-test/FreeRTOS_TCP_Transmission_DiffConfig/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* FreeRTOS+TCP
* Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include <assert.h>

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See
* http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 1
#define configUSE_DAEMON_TASK_STARTUP_HOOK 1
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 52 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 20
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0
#define configUSE_QUEUE_SETS 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configINITIAL_TICK_COUNT ( ( TickType_t ) 0 ) /* For test. */
#define configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN 1 /* As there are a lot of tasks running. */

/* Software timer related configuration options. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 20
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )

#define configMAX_PRIORITIES ( 7 )
#define configENABLE_MPU 0

/* Run time stats gathering configuration options. */

#define configGENERATE_RUN_TIME_STATS 1

/* This demo makes use of one or more example stats formatting functions. These
* format the raw data provided by the uxTaskGetSystemState() function in to human
* readable ASCII form. See the notes in the implementation of vTaskList() within
* FreeRTOS/Source/tasks.c for limitations. */
#define configUSE_STATS_FORMATTING_FUNCTIONS 1

/* Set the following definitions to 1 to include the API function, or zero
* to exclude the API function. In most cases the linker will remove unused
* functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1

/* It is a good idea to define configASSERT() while developing. configASSERT()
* uses the same semantics as the standard C assert() macro. */
extern void vAssertCalled( unsigned long ulLine,
const char * const pcFileName );
#define configASSERT( x ) assert( x )

#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0
#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 )
extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer );
#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */

/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */
/* #include "trcRecorder.h" */

#endif /* FREERTOS_CONFIG_H */
Loading