lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Problem receiving Multicast packet


From: Claudius Zingerli
Subject: Re: [lwip-users] Problem receiving Multicast packet
Date: Tue, 09 Jul 2013 18:26:33 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

Hi Seba,

Sounds like a lower layer problem.
If you are sure, the packets arrive at your STM32, check its MII counters, Interrupts (Flags+Breakpoint), DMA flags (RBUS!)

Claudius


On 7/9/2013 3:30 PM, address@hidden wrote:
Hi,

I don't clear this problem, I have difficulties to understand why the 
recvfrom() function still blocking when it receive about 2700 packet of data...

I have check all the buffer size, it seems it's a transmit message problem in 
the fonction netconn_recv_data() in this line :


sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0); // my thread still blocking here 
when about 2700 packet are transmitted yet




This is a part of my thread code, hope you can help me !




          while(1) {
             memset(rtp_recv_packet, 0, sizeof(rtp_recv_packet));
              sys_msleep(50);
//          rtphdr = NULL;
//          MEM_STATS_DISPLAY();
             fromlen = sizeof(from);
             result  = recvfrom(sock, rtp_recv_packet, sizeof(rtp_recv_packet), 
0,
               (struct sockaddr *)&from, (socklen_t *)&fromlen);
             //result  = recv(sock, rtp_recv_packet, sizeof(rtp_recv_packet), 
0);

             if (result >= sizeof(struct rtp_hdr)) {
               rtphdr = (struct rtp_hdr *)rtp_recv_packet;
               recvrtppackets++;
               if ((lastrtpseq == 0) || ((lastrtpseq + 1) == 
ntohs(rtphdr->seqNum))) {
                 RTP_RECV_PROCESSING((rtp_recv_packet + 
sizeof(rtp_hdr)),(result-sizeof(rtp_hdr)));

               } else {
                 lostrtppackets++;

               }
               lastrtpseq = ntohs(rtphdr->seqNum);
               if ((recvrtppackets % RTP_RECV_STATS) == 0) {
                 LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv %6i packet(s) / lost 
%4i packet(s) (%.4f%%)...\n", recvrtppackets, lostrtppackets, 
(lostrtppackets*100.0)/recvrtppackets));
               }
             } else {
               LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv timeout...\n"));
             }
           }




----- Mail original -----
De: "seba segura" <address@hidden>
À: "Mailing list for lwIP users" <address@hidden>
Envoyé: Mercredi 3 Juillet 2013 11:31:56
Objet: Re: [lwip-users] Problem receiving Multicast packet

I found the mistake, it was  a flag wich was not in the ETH register of the 
STM32F207 (PAM flag).

Now I am able to receive RTP packets. But there is another problem : It seems 
that a thread still blocking when I receive about 1 minute of data (2600 
packets), I think a thread is waiting for a semaphore. I increase the mailbox 
size but it not solve the problem.

Do you think there is a special config (for lwipopt.h or opt.h) ?

here my lwipopt.h :


#define SYS_LIGHTWEIGHT_PROT    0

#define ETHARP_TRUST_IP_MAC     0
#define IP_REASSEMBLY           0
#define IP_FRAG                 0
#define ARP_QUEUEING            0
#define TCP_LISTEN_BACKLOG      1

/**
  * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
  * use lwIP facilities.
  */
#define NO_SYS                  0

/* ---------- Memory options ---------- */
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
    lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
    byte alignment -> define MEM_ALIGNMENT to 2. */
#define MEM_ALIGNMENT           4

/* MEM_SIZE: the size of the heap memory. If the application will send
a lot of data that needs to be copied, this should be set high. */
#define MEM_SIZE                (10*1024)

/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
    sends a lot of data out of ROM (or other static memory), this
    should be set high. */
#define MEMP_NUM_PBUF           100
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
    per active UDP "connection". */
#define MEMP_NUM_UDP_PCB        64//6 (pour RTP)
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
    connections. */
#define MEMP_NUM_TCP_PCB        10
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
    connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 5
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
    segments. */
#define MEMP_NUM_TCP_SEG        20
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
    timeouts. */
#define MEMP_NUM_SYS_TIMEOUT    10


/* ---------- Pbuf options ---------- */
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
#define PBUF_POOL_SIZE          20

/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
#define PBUF_POOL_BUFSIZE       500


/* ---------- TCP options ---------- */
#define LWIP_TCP                1
#define TCP_TTL                 255

/* Controls if TCP should queue segments that arrive out of
    order. Define to 0 if your device is low on memory. */
#define TCP_QUEUE_OOSEQ         0

/* TCP Maximum segment size. */
#define TCP_MSS                 (1500 - 40)       /* TCP_MSS = (Ethernet MTU - 
IP header size - TCP header size) */

/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF             (2*TCP_MSS)

/*  TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
   as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */

#define TCP_SND_QUEUELEN        (2* TCP_SND_BUF/TCP_MSS)

/* TCP receive window. */
#define TCP_WND                 (2*TCP_MSS)


/* ---------- ICMP options ---------- */
#define LWIP_ICMP                       1


/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
    interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
    turning this on does currently not work. */
#define LWIP_DHCP               1


/* ---------- UDP options ---------- */
#define LWIP_UDP                1
#define UDP_TTL                 255


/* ---------- Statistics options ---------- */
#define LWIP_STATS 0
#define LWIP_PROVIDE_ERRNO 1


/*
    --------------------------------------
    ---------- Checksum options ----------
    --------------------------------------
*/

/*
The STM32F2x7 allows computing and verifying the IP, UDP, TCP and ICMP 
checksums by hardware:
  - To use this feature let the following define uncommented.
  - To disable it and process by CPU comment the  the checksum.
*/
#define CHECKSUM_BY_HARDWARE


#ifdef CHECKSUM_BY_HARDWARE
   /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP 
packets.*/
   #define CHECKSUM_GEN_IP                 0
   /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP 
packets.*/
   #define CHECKSUM_GEN_UDP                0
   /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP 
packets.*/
   #define CHECKSUM_GEN_TCP                0
   /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP 
packets.*/
   #define CHECKSUM_CHECK_IP               0
   /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP 
packets.*/
   #define CHECKSUM_CHECK_UDP              0
   /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP 
packets.*/
   #define CHECKSUM_CHECK_TCP              0
#else
   /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP 
packets.*/
   #define CHECKSUM_GEN_IP                 1
   /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP 
packets.*/
   #define CHECKSUM_GEN_UDP                1
   /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP 
packets.*/
   #define CHECKSUM_GEN_TCP                1
   /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP 
packets.*/
   #define CHECKSUM_CHECK_IP               1
   /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP 
packets.*/
   #define CHECKSUM_CHECK_UDP              1
   /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP 
packets.*/
   #define CHECKSUM_CHECK_TCP              1
#endif


/*
    ----------------------------------------------
    ---------- Sequential layer options ----------
    ----------------------------------------------
*/
/**
  * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
  */
#define LWIP_NETCONN                    1

/*
    ------------------------------------
    ---------- Socket options ----------
    ------------------------------------
*/
/**
  * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
  */
#define LWIP_SOCKET                     1

/*
    -----------------------------------
    ---------- DEBUG options ----------
    -----------------------------------
*/

//#define LWIP_DEBUG                      1


/*
    ---------------------------------
    ---------- OS options ----------
    ---------------------------------
*/

#define TCPIP_THREAD_STACKSIZE          1000
#define TCPIP_MBOX_SIZE                 5
#define DEFAULT_UDP_RECVMBOX_SIZE       2000
#define DEFAULT_TCP_RECVMBOX_SIZE       2000
#define DEFAULT_ACCEPTMBOX_SIZE         2000
#define DEFAULT_THREAD_STACKSIZE        500
#define TCPIP_THREAD_PRIO               (configMAX_PRIORITIES - 2)



----- Mail original -----
De: "seba segura" <address@hidden>
À: address@hidden
Envoyé: Lundi 1 Juillet 2013 17:10:44
Objet: [lwip-users] Problem receiving Multicast packet

Hello Everybody

I have some trouble to receive RTP packet with Lwip 1.4.0 using FreeRtos.

I send audio streaming data with VLC and I want to read them with my board.

This is my recv thread I commented where is the issue :


static void
rtp_recv_thread(void *arg)
{
   int                sock;
   struct sockaddr_in local;
   struct sockaddr_in from;
   int                fromlen;
   struct ip_mreq     ipmreq;
   struct rtp_hdr*    rtphdr;
   u32_t              rtp_stream_address;
   int                timeout;
   int                result;
   int                recvrtppackets  = 0;
   int                lostrtppackets  = 0;
   u16_t              lastrtpseq = 0;

   LWIP_UNUSED_ARG(arg);

   /* initialize RTP stream address */
   rtp_stream_address = RTP_STREAM_ADDRESS;
  sys_msleep(15000);
   /* if we got a valid RTP stream address... */
   if (rtp_stream_address != 0) {
     /* create new socket */
     sock = socket(AF_INET, SOCK_DGRAM, 0);
     if (sock >= 0) {
       /* prepare local address */
       memset(&local, 0, sizeof(local));
       local.sin_family      = AF_INET;
       local.sin_port        = PP_HTONS(RTP_STREAM_PORT);
       local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);

       /* bind to local address */
       if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
         /* set recv timeout */
         timeout = RTP_RECV_TIMEOUT;
         setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, 
sizeof(timeout));

         /* prepare multicast "ip_mreq" struct */
         ipmreq.imr_multiaddr.s_addr = rtp_stream_address;
         ipmreq.imr_interface.s_addr = PP_HTONL(INADDR_ANY);

         /* join multicast group */
         if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipmreq, 
sizeof(ipmreq)) == 0) {
           /* receive RTP packets */
           while(1) {
             fromlen = sizeof(from);
             result  = recvfrom(sock, rtp_recv_packet, sizeof(rtp_recv_packet), 
0,
               (struct sockaddr *)&from, (socklen_t *)&fromlen);

             // THE PROBLEM IS HERE result is ALWAYS = -1

             if (result >= sizeof(struct rtp_hdr)) {
               rtphdr = (struct rtp_hdr *)rtp_recv_packet;
               recvrtppackets++;
               if ((lastrtpseq == 0) || ((lastrtpseq + 1) == 
ntohs(rtphdr->seqNum))) {
                 RTP_RECV_PROCESSING((rtp_recv_packet + 
sizeof(rtp_hdr)),(result-sizeof(rtp_hdr)));
               } else {
                 lostrtppackets++;
               }
               lastrtpseq = ntohs(rtphdr->seqNum);
               if ((recvrtppackets % RTP_RECV_STATS) == 0) {
                 LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv %6i packet(s) / lost 
%4i packet(s) (%.4f%%)...\n", recvrtppackets, lostrtppackets, 
(lostrtppackets*100.0)/recvrtppackets));
               }
             } else {
               LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv timeout...\n"));
             }
           }

           /* leave multicast group */
           setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &ipmreq, 
sizeof(ipmreq));
         }
       }

       /* close the socket */
       closesocket(sock);
     }
   }
}


My problem is that the var result  = recvfrom(sock, rtp_recv_packet, 
sizeof(rtp_recv_packet), 0,(struct sockaddr *)&from, (socklen_t 
*)&fromlen);return always -1... I don't understand why, it seems that the main 
thread is waiting for a semaphore which never come...

Any idea ?

Best regards,

Sébastien

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users





reply via email to

[Prev in Thread] Current Thread [Next in Thread]