Multiple UDP listener problems with uIP stack

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Multiple UDP listener problems with uIP stack

Post by BEBDigitalAudio »

Hi all,

I am fighting since three days with the TCP/IP stack (V1.3). Before reporting any bug, I prefer to submit to you all what I have seen.

I am trying to open four UDP listening sockets, using the following basic code :

Code: Select all

   
   xtcp_listen (tcp_svr, 5003, XTCP_PROTOCOL_UDP);
   xtcp_listen (tcp_svr, 5004, XTCP_PROTOCOL_UDP);
   xtcp_listen (tcp_svr, 5005, XTCP_PROTOCOL_UDP);
   xtcp_listen (tcp_svr, 5006, XTCP_PROTOCOL_UDP);

   xtcp_ask_for_event(tcp_svr);  // Check for initial event from xtcp server
  while(1) {
    select 
      {
      case xtcp_event(tcp_svr, conn):
        UDP_HandleEvent(tcp_svr, conn);
        xtcp_ask_for_event(tcp_svr);
        break;
      }
  }
}
I have set a message in the XTCP_NEW_CONNECTION event in my handler code, to confirm that each listener is created.

What is strange is that I see only two connection indications. And sometimes, I get immediately a report that I got a XTCP_CLOSED event.

More strange : only two listeners are created each time. If I send data using UDP to them, the XC2 receives it. But the two other ports do not receive anything.

Thus, I have activated a trace in the uip_xtcp.c file and I see that my application correctly sends the four listening requests.

Then I looked inside uip_process() function, where the UDP packets are processed. I found the following debug code, that I activated

Code: Select all

    UIP_LOG("udp: no matching connection found");
    printintln(HTONS(UDPBUF->srcport));
    printintln(HTONS(UDPBUF->destport));
and I see that two listeners are missing in my list (the corresponding entries are not created when I call xtcp_listen() in fact) :shock:

I checked the code within the listener creation function, and it follows exactly the suggestion coming from Adam Dunkels (the author of uIP). What frighten me is the comment he made on the uIP mailing list "It is possible to create a listening UDP connection in uIP, but it is a little tricky... If you have a cleaner solution, please post it for acception into uIP code" :o

As far as I can see, the TCP support in XTCP is perfect, but UDP is not very good.

Did somebody else experienced the same problems ?
I will look today in the uIP code, to try to understand why the listeners are not created properly (it seems to come clearly from uIP, not from XMOS port)


Note that if I try to open only one UDP socket, it works perfectly. The problem occurs as soon as I try to create more than one listener


Thanks to all by advance

Benoît


User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Post by BEBDigitalAudio »

After fighting with the uIP and XTCP source code for hours, I finally won :D

I found some inconsistencies in the XTCP UDP implementation (hummm... let's call them "bugs")
The current wrapper prevents the correct creation of the UIP listeners for UDP and it corrupts the listener table.
The TCP implementation is working perfectly in V1.3 (only UDP is affected)

I am working right now on a proper implementation of the necessary changes in XTCP.

I will publish my code proposal when everything will be tested (a busy weekend in perspective ;) )
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

Benoit,
This is actually a known issue at XMOS and the next release of the xtcp stack will fix the problem. Unfortunately I cannot say exactly when the next release will be but I think it is reasonable to expect it by the end of the year. Of course, it is up to you whether this affects you implementing your fix or not.

Regards,
Dave

P.S. The best way to make sure issues like this are noticed/logged is to raise a support ticket at xmos.com
User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Post by BEBDigitalAudio »

Hi Dave,

thank you for this information. Since you say that this is a known issue, I will not raise a ticket (I think they already have enough work not to process a new ticket ;) )

This problem has a good side anyway : I was able to picture completely how the stack is implemented and how it works. This was the first time I used uIP (I always worked with BSD-style stacks) and I needed to be sure that the problem was not coming from my code.

Since I need to port code from other applications I made for KissBox company, the current XTCP implementation represents a lot of work (especially because we use a lot UDP). That's why I started to code a different wrapper around XTCP and uIP, offering a socket based interface.

Any XCoder interested in this approach can contact me, I see no problem to share my work
kasbah
Member++
Posts: 17
Joined: Thu Oct 14, 2010 12:07 am

Post by kasbah »

I would be interested in taking a look at the socket based interface. Why not post it in a public-repo or as an xcore project?
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

I am curious about your fix Benoit as well as the socket based interface, perhaps you could add it to a git repo or something, I am sure others have also had to fix things in the network stack.

regards
Al
User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Post by BEBDigitalAudio »

Do not worry, my objective is to share my work. ;)

Right now, I coded everything very quickly (just to make sure that I was able to port my existing code to the XMOS) and I have to clean many, many things before it can be released.

My other objective is to write a kind of user's manual for it (maybe I am wrong, but I think that many users of XTCP are loosing time because the only existing documentation is the one from uIP, which does not take into account the XTCP wrapper)

I expect to be able to provide this code on the forum in the next two or three weeks.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

I look forward to seeing it Benoit
User avatar
BEBDigitalAudio
Experienced Member
Posts: 82
Joined: Thu Nov 11, 2010 7:45 pm

Post by BEBDigitalAudio »

The very, very first version of my stack port is available on the projects page. It supports only UDP for now (TCP support is on the way), it needs a lot of code cleanup, but at least, it works seamlessly with 8 UDP sockets (and more if you want ;) ), which was my very first goal.
User avatar
nassim
Experienced Member
Posts: 112
Joined: Sun Sep 05, 2010 3:39 pm

Post by nassim »

it's a great news :) ; I'm waiting with passion my XC2 kit to test your project and it will be great step to add TCP. we wait your new release of project :D .