[En-Nut-Discussion] unreliable tcp

Szemző András saam at kometa.hu
Wed Apr 9 10:47:06 CEST 2008


Hi,

It seems increasing the lower boundary of the tcp retransmission time from
200ms to 2sec solved the problem,
as the modul is online after 17h, without a single reconnect, compared with
the 10-30min, without this
modification in NutTcpCalcRtt() in tcputil.c

Regards,
Andras

-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Szemző András
Sent: Tuesday, April 08, 2008 5:29 PM
To: 'Ethernut User Chat (English)'
Subject: Re: [En-Nut-Discussion] unreliable tcp

Hi guys,

I captured the error situation and made a picture about it, maybe it will
help somebody with better tcp/ip knowledge than I have to track down what is
going on here :)

http://www.esh.hu/nut_err.jpg

(blue is the nut board, red is the linux server app)

Thanks a lot
Andras

-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Szemző András
Sent: Tuesday, April 08, 2008 2:44 PM
To: 'Ethernut User Chat (English)'
Subject: Re: [En-Nut-Discussion] unreliable tcp


Harald, thanks your answer.

Ok, it seems my english was not enough good to explain my problem completly
:)

Here is a connect handler,log sender and reader part of the main() thread:

		// Disconnected state, try to connect to Server
		if ( Timer.Num[TIMERCONNECT] == 0 ) {
			if ( SkyConnect(NetStatus.UsedServer) ==
SKY_CONNECT_OK ) {				
				NetStatus.TCPConnectCount=0;

				Timer.Num[TIMERCONNECT] = -1;

				Timer.Num[TIMERLOGALIVE] =
MainConfig.TcpTestTime;		
				NetStatus.TcpConnectionState =
TCP_CONNECTED;	
				if ( NetStatus.UsedServer != 0 ) {
					Timer.Num[PRIMARYIPRESTORE] = 900;
				} else {
					Timer.Num[PRIMARYIPRESTORE] = -1;

				}
			} else {

				NetStatus.TCPConnectCount++;
				Timer.Num[TIMERCONNECT] =
CfgTCPConnectWaitTime;	
			}
		}
		
		....

		// Log sender
		if ( NetStatus.TcpConnectionState == TCP_CONNECTED ) {
			rc = SendELogPacket(); 
			if ( rc == -1) {
				Timer.Num[TIMERRESENDLOG] =
CfgTCPResendLogTime;		// reload timer
				NetStatus.TCPResendCount++;
				#ifdef _MODUL_DEBUG_
					puts("LOG_SEND_ERR");
fflush(stdout);
				#endif
			} 
			if ( rc == 1 ) { 
				#ifdef _MODUL_DEBUG_
					puts("LOG_SEND_OK"); fflush(stdout);
				#endif
				Timer.Num[TIMERRESENDLOG] = -1;
				NetStatus.TCPResendCount = 0;
			}
			if ( StatusSend == ENABLED ) {
				StatusSend = DISABLED;
				SkySendStatus(TCP_PACKET_STATUS_NEW,
GetRandomNum());
				#ifdef _MODUL_DEBUG_
					printf("Statussend\r\n");
fflush(stdout);
				#endif				
			}
		}

		// TCP reader		
		if ( NetStatus.TcpConnectionState == TCP_CONNECTED ) {	
			tmo=100;			
			NutTcpSetSockOpt(sock, SO_RCVTIMEO, &tmo,
sizeof(tmo));

			rc = NutTcpReceive(sock, receivebuff,
sizeof(receivebuff));					// see if we get
something
			if ( rc == 16) {

				NetStatusIn(receivebuff);
			} else { 
				if ( rc == -1) {
// Cannot read socket
					#ifdef _MODUL_DEBUG_
						printf("READ ERROR,
Disconnected\n"); fflush(stdout);
					#endif
					SkyDisconnect();
					NetStatus.TcpConnectionState =
TCP_DISCONNECTED; 
					Timer.Num[TIMERCONNECT] =
CfgTCPConnectWaitTime;				// set reconnect timer
					Timer.Num[TIMERLOGALIVE] = -1;

				} 
			}
			tmo=2000;			
			NutTcpSetSockOpt(sock, SO_RCVTIMEO, &tmo,
sizeof(tmo));
		} 


I have about 38K free heap, so I think not that's the problem. I have no
problems with app level reconnects, this code will deal with that.
As I cannot post pictures, I put a retransmission debug to here:
http://www.esh.hu/nut.jpg ( the blue is the nut board ) In this case, the
nut board doesn't reconnect, becouse after a couple of retransmission it
gets answered.

In the case of error, the situation is that, after the retransmission
(sending started by the SkySendStatus(TCP_PACKET_STATUS_NEW,
GetRandomNum()); ), the server not send answer (PUSH ACK) back, but it send
a FIN tcp packet, and this is why nut abort the socket.

And after that,

rc = NutTcpReceive(sock, receivebuff, sizeof(receivebuff)); // see if we get
something

Return -1, what is ok, becouse the socket died.

I'll make some debug picture about the disconnect evening.

The question is, what can be wrong, as a very similar logic used ethernut
based GPRS board can keep alive 2 days on this server, With the same code in
local net this board can keep alive weeks, but on an adsl line this happens.
   
Regards,
Andras

-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Harald Kipp
Sent: Tuesday, April 08, 2008 1:22 PM
To: Ethernut User Chat (English)
Subject: Re: [En-Nut-Discussion] unreliable tcp

Hi András,

Szemző András wrote:
>  
> I tried to use Commview to capture packets, and I see the sam7x 
> doesn't get answer within a time. Normally it sends a PUSH ACK, get 
> answer PUSH ACK, and send ACK. I see when there are problems, it tries 
> to send PUSH ACK with retransmission, and if it gets answer it doesn't
reconnect.
> My app's loop send a packet if it needs, than read back the answer, 
> and with 100ms RECV timeout tries to read to see, if he got some 
> incoming
packets.
> I see when there are reconnects, the NutTcpReceive() will return with 
> -1, wich means socket is disconnected. (sock->so_state will be 0 in 
> this case)

The reconnect _must_ have been initiated by your application. The stack by
itself will not reconnect. Probably because of the -1 returned by
NutTcpReceive().

NutTcpReceive will return -1 only in case of fatal errors (e.g. out of
memory) or if it receives a connection close (FIN) or connection reject
(RST).

What does NutHeapAvailable() return?


Harald
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


 _____________ NOD32 3009 (20080408) Információ _____________

Az üzenetet a NOD32 antivirus system megvizsgálta.
http://www.nod32.hu



----
Kometa 99 Élelmiszeripari ZRt.
Székhely: 7400 Kaposvár, Pécsi u. 67-69., Levelezési cím: 7401 Kaposvár, Pf.
58
Cégszám: Somogy Megyei Bíróság mint Cégbíróság 14-10-300239
Adószám: 13749619-2-44
Telefon: 82/502-400, Fax: 82/502-415
http://www.kometa.hu
http://www.kemencessult.hu

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


 _____________ NOD32 3009 (20080408) Információ _____________

Az üzenetet a NOD32 antivirus system megvizsgálta.
http://www.nod32.hu



----
Kometa 99 Élelmiszeripari ZRt.
Székhely: 7400 Kaposvár, Pécsi u. 67-69., Levelezési cím: 7401 Kaposvár, Pf.
58
Cégszám: Somogy Megyei Bíróság mint Cégbíróság 14-10-300239
Adószám: 13749619-2-44
Telefon: 82/502-400, Fax: 82/502-415
http://www.kometa.hu
http://www.kemencessult.hu

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion


 _____________ NOD32 3010 (20080408) Információ _____________

Az üzenetet a NOD32 antivirus system megvizsgálta.
http://www.nod32.hu



----
Kometa 99 Élelmiszeripari ZRt.
Székhely: 7400 Kaposvár, Pécsi u. 67-69., Levelezési cím: 7401 Kaposvár, Pf. 58
Cégszám: Somogy Megyei Bíróság mint Cégbíróság 14-10-300239
Adószám: 13749619-2-44
Telefon: 82/502-400, Fax: 82/502-415
http://www.kometa.hu
http://www.kemencessult.hu




More information about the En-Nut-Discussion mailing list