Ping Utility with FreeRTOS

shaanktn wrote on Wednesday, December 28, 2016:

I am using FreeRTOS-TCP on customized platform.
RTOS is UP and able to ping the board(where RTOS is deployed) from device on network, and able to capture packets on WireShark.
But, my requirement is to ping to any system on network from board. For this I am using “FreeRTOS_SendPingRequest()” with my required IP and other parameters as default(as given here: http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/FreeRTOS_SendPingRequest.shtml). I am able to receive the “usRequestSequenceNumber” incremented, but no packet is captured in WireShark.
Am I missing something with Wireshark or any RTOS configuration ?
Any Input will be helpful.

Thanks,

rtel wrote on Wednesday, December 28, 2016:

If I understand you correctly, outgoing pings are working from the
FreeRTOS+TCP device, but you just aren’t seeing them in Wireshark. Are
you seeing any pings in Wireshark? If not then maybe Wireshark is
configured to filter out ICMP messages.

shaanktn wrote on Monday, January 02, 2017:

Thanks.
Looks like some issue with other thread of my platform, which is not allowing packet to be transmitted.
I am able to see ping packets in wireshark if requested from PC. But was not seen if requested from board.
But now I am able to capture it after some time.

shaanktn wrote on Wednesday, January 18, 2017:

Hi all,
I have one more issue now. As I told I am using “FreeRTOS_SendPingRequest” for ping test. I am able to ping it without any problem for some 900-1000 packets(I track sequence number in Wireshark) but after that the API wil return NULL. When I tracked the flow, observed that “xSemaphoreTake()” is failing. I am using BufferAllocation_2. Any input will be helpful.
Thanks,

heinbali01 wrote on Wednesday, January 18, 2017:

Hi,

What platform are you using?

How often are you calling FreeRTOS_SendPingRequest()? You might want to call uxGetNumberOfFreeNetworkBuffers() before sending a ping to know if there is enough space. Maybe you’re asking too much of the interface?

If you’re not sending too often, please check uxGetMinimumFreeNetworkBuffers() regularly to see if the number of free buffers is gradually decreasing.

Are you using the latest release 160919?

shaanktn wrote on Wednesday, January 18, 2017:

Hi Hein,
That was useful.
I am usign STM32F on customised platform.
uxGetNumberOfFreeNetworkBuffers() went on decreasing, and yeah no more freebuffers.
Any way to refresh it or release the buffer back after ping ? I can use “vReleaseNetworkBufferAndDescriptor() ?”. Why not the buffers are being released in my case ? That supposed to happen I believe ?
I am just checking ping, so it is like contineously sending and receiving packets, I can say it is non stopping!
No, I am using 160112.

Thanks,

heinbali01 wrote on Wednesday, January 18, 2017:

Thanks for reporting back.I rarely ping from an embedded device, so I will first check FreeRTOS_SendPingRequest(), see if it is ‘leaking’ Network Buffers. As you can see in the code, it passes every buffer to the IP-task. If passing fails, the allocated Network Buffer will be released by calling vReleaseNetworkBufferAndDescriptor() :

BaseType_t FreeRTOS_SendPingRequest( uint32_t ulIPAddress, size_t xNumberOfBytesToSend, TickType_t xBlockTimeTicks )
{
    ...
    if( xSendEventStructToIPTask( &xStackTxEvent, xBlockTimeTicks) != pdPASS )
    {
        vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
        iptraceSTACK_TX_EVENT_LOST( ipSTACK_TX_EVENT );
    }
    else
    {
        xReturn = usSequenceNumber;
    }

Hein

shaanktn wrote on Wednesday, January 18, 2017:

Hi Hein,
Yea that was my initial thought that it should be cleared there. I believe the leak is not present in that place for me, I somehow feel the leak is happening in “prvNetworkInterfaceInput()”. I need to confirm it, any ways will update you the observations.
Thanks,

heinbali01 wrote on Wednesday, January 18, 2017:

Hi Shaank,

I can not find a leakage. What I just did is implement this hook:

void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )

As soon as it is called (i.e. my ping has been replied), it will wake-up the task that calls FreeRTOS_SendPingRequest().

So it becomes a chain:

    void vPingTask( void *pvArgument )
	{
		for (;;)
		{
			ulTaskNotifyTake( pdFALSE, ulMaxBlockTime );
			FreeRTOS_SendPingRequest();
		}
	}
	void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
	{
		if (eStatus == eSuccess)
		{
			xTaskNotifyGive( xPingTaskHandle );
		}
	}

In this way I’m able to exchange thousands of ICMP messages, without ever running out of Network Buffers.
ulMaxBlockTime makes sure that if a ping doesn’t get answered, the chain won’t be broken because a next ping will be sent.

Could you try something like the above and see what happens?

shaanktn wrote on Thursday, January 19, 2017:

Hi,
Thanks Hein,
Currently I am having it like,

//THIS WILL BE CALLED IN LOOP FROM MY CODE...
 RequestSequenceNum = FreeRTOS_SendPingRequest(..);
  if( RequestSequenceNum == pdFAIL )
    {
    }
    else
    {
	    //custom code..
        if( xQueueReceive( xPingReplyQueue,
                           &ReplySequenceNum,
                           200 / portTICK_PERIOD_MS ) == pdPASS )
        {
            if( RequestSequenceNum == ReplySequenceNum )
            {
               //custom code..
            }
		}

And in "vApplicationPingReplyHook() " I am just updating the queue like

		if (eStatus == eSuccess)
        {
           xQueueSend( xPingReplyQueue, &usIdentifier, 10 / portTICK_PERIOD_MS );
        }

Any issues ?
Thanks,

shaanktn wrote on Thursday, May 04, 2017:

Hi all,
There is no issue as such with the available code. Later I got that the leak is happening with the other modules added by me. Ping works well for days!
Thanks,
Shaank