This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6678: UDP multicast cannot receive data

Part Number: TMS320C6678

Hi team,

Here's an issue from the customer may need your help:

UDP multicast is used in 6678 and 6672 chips.

The current unicast function is good. Multicast is sent to the multicast group normally, and data is able to be received on the PC port. While when multicast sends data through the PC to the DSP's multicast group, the DSP is unable to receive the data.

Multicast send Code: Create a new Send Task in the UDP routine of the NDK, create a new socket in the Send Task, and socket bind the local IP (192.168.4.156). Then setsocket joins the multicast group (224.1.2.4) and sends data out through this socket, which will be sent normally.

Multicast receive Code: Create a new receive Task in the UDP routine of the NDK, create a new socket in the receive Task, socket binding local IP (192.168.4.156). Setsocket then joins the multicast group (224.1.2.4) and gets it through the while(1) {recvfrom();} function. However, the code is stuck in the recvfrom function and cannot continue execution with no return value.

1) In the 667X family, can the DSP theoretically implement UDP multicast reception?

2) Is there a UDP multicast receive routine for reference? Or is the multicast receive code above incorrect?

3) Can UDP multicast reception create processes like unicast reception and trigger processes directly after receiving data?

Could you help check this case? Thanks.

Best Regards,

Cherry

  • Hi,

    May I know is there any updates?

    Thanks and regards,

    Cherry

  • Cherry,

    Rajan is working on your query.

    He will get back to you soon.

    Regards

    Shankari G

  • Hi Cherry Zhou,

    I apologize for the delay. Please refer to the Multicast test code which uses Multicast send and receive functions ("contest.c"),

    /*---------------------------------------------------------------------- */
    /* MulticastTest() */
    /* Test the Multicast socket API. */
    /*---------------------------------------------------------------------- */
    static void MulticastTest (void)
    {
        SOCKET          sudp1 = INVALID_SOCKET;
        SOCKET          sudp2 = INVALID_SOCKET;
        struct sockaddr_in sin1;
        char            buffer[1000];
        int             reuse = 1;
        struct ip_mreq  group;
        NDK_fd_set      msockets;
        int             iterations = 0;
        int             cnt;
        CI_IPNET        NA;
    
        ConPrintf ("=== Executing Multicast Test on Interface 1 ===\n");
    
        /* Create our UDP Multicast socket1 */
        sudp1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if( sudp1 == INVALID_SOCKET )
        {
            ConPrintf ("Error: Unable to create socket\n");
            return;
        }
    
        /* Create our UDP Multicast socket1 */
        sudp2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if( sudp2 == INVALID_SOCKET )
        {
            ConPrintf ("Error: Unable to create socket\n");
            return;
        }
    
        /* Set Port = 4040, leaving IP address = Any */
        memset( &sin1, 0, sizeof(struct sockaddr_in) );
        sin1.sin_family = AF_INET;
        sin1.sin_port   = NDK_htons(4040);
    
        /* Print the IP address information only if one is present. */
        if (CfgGetImmediate( 0, CFGTAG_IPNET, 1, 1, sizeof(NA), (unsigned char *)&NA) != sizeof(NA))
        {
            ConPrintf ("Error: Unable to get IP Address Information\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Set the Reuse Ports Socket Option for both the sockets.  */
        if (setsockopt(sudp1, SOL_SOCKET, SO_REUSEPORT, (char *)&reuse, sizeof(reuse)) < 0)
        {
            ConPrintf ("Error: Unable to set the reuse port socket option\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        /* Reuse the ports; since multiple multicast clients will be executing. */
        if (setsockopt(sudp2, SOL_SOCKET, SO_REUSEPORT, (char *)&reuse, sizeof(reuse)) < 0)
        {
            ConPrintf ("Error: Unable to set the reuse port socket option\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Now bind both the sockets. */
        if (bind (sudp1, (struct sockaddr *) &sin1, sizeof(sin1)) < 0)
        {
            ConPrintf ("Error: Unable to bind the socket.\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        if (bind (sudp2, (struct sockaddr *) &sin1, sizeof(sin1)) < 0)
        {
            ConPrintf ("Error: Unable to bind the socket.\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Now we join the groups for socket1
         *  Group: 224.1.2.4
         *  Group: 224.1.2.5 */
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.4");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp1, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.5");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp1, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        ConPrintf ("-----------------------------------------\n");
        ConPrintf ("Socket Identifier %d has joined the following:-\n", sudp1);
        ConPrintf (" - Group 224.1.2.4\n");
        ConPrintf (" - Group 224.1.2.5\n");
        ConPrintf ("-----------------------------------------\n");
    
        /* Now we join the groups for socket2
         *  Group: 224.1.2.5
         *  Group: 224.1.2.6 */
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.5");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp2, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.6");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp2, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        ConPrintf ("-----------------------------------------\n");
        ConPrintf ("Socket Identifier %d has joined the following:-\n", sudp2);
        ConPrintf (" - Group 224.1.2.5\n");
        ConPrintf (" - Group 224.1.2.6\n");
        ConPrintf ("-----------------------------------------\n");
    
        while (iterations < 4)
        {
            /* Initialize the FD Set. */
            NDK_FD_ZERO(&msockets);
            NDK_FD_SET(sudp1, &msockets);
            NDK_FD_SET(sudp2, &msockets);
    
            /* Wait for the multicast packets to arrive. */
            /* fdSelect 1st arg is a don't care, pass 0 64-bit compatibility */
            cnt = fdSelect( 0, &msockets, 0, 0 , 0);
    
            if(NDK_FD_ISSET(sudp1, &msockets))
            {
                cnt = (int)recv (sudp1, (void *)&buffer, sizeof(buffer), 0);
                if( cnt >= 0 )
                    ConPrintf ("Socket Identifier %d received %d bytes of multicast data\n", sudp1, cnt);
                else
                    ConPrintf ("Error: Unable to receive data\n");
    
                /* Increment the iterations. */
                iterations++;
            }
            if(NDK_FD_ISSET(sudp2, &msockets))
            {
                cnt = (int)recv (sudp2, (void *)&buffer, sizeof(buffer), 0);
                if( cnt >= 0 )
                    ConPrintf ("Socket Identifier %d received %d bytes of multicast data\n", sudp2, cnt);
                else
                    ConPrintf ("Error: Unable to receive data\n");
    
                /* Increment the iterations. */
                iterations++;
            }
        }
    
        /* Once the packet has been received. Leave the Multicast group! */
        if (setsockopt (sudp2, IPPROTO_IP, IP_DROP_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to leave multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Leave only one of the multicast groups through the proper API. */
        NtIPN2Str (group.imr_multiaddr.s_addr, &buffer[0]);
        ConPrintf ("Leaving group %s through IP_DROP_MEMBERSHIP\n", buffer);
    
        /* Once we get out of the loop close socket2; this should internally leave all the groups. */
        fdClose (sudp1);
        fdClose (sudp2);
        ConPrintf("== End Multicast Test ==\n\n");
    }

     The File is located in "C:\ti\ndk_3_61_01_01\packages\ti\ndk\tools\console".

    Further NDK API reference for Multicast has been mentioned in the API guide, NDK API guide. Using "NDK_setsockopt()" we can set the option as "SO_REUSEPORT" for UDP Multicast send and receive. Please use "NDK_recvfrom()" (NDK API function) to receive multicast and triggered by Interrupt.

    Also, There is an option to enable Multicast replies on,

    1. Icmp.xml 
          /*!
           *  Enable or disable replies to multicast.
           *  
           *  When enabled, the stack *does not* reply to ICMP echo request packets
           *  sent to multicast addresses.
           */ 
          config Bool icmpDontReplyToMcast = defaultIcmpMcastReply;
    2. Ip.xdc 
      <tr>
               <td colspan="2"><control type="checkbox" 
                   label="Disable multicast replies"
                   value="value:ti.ndk.config.Ip.icmpDontReplyToMcast" 
                   tooltip="value:ti.ndk.config.Ip.icmpDontReplyToMcast.$summary"/></td>
            </tr>

    Files are located in the "C:\ti\ndk_3_61_01_01\packages\ti\ndk\config" folder. There as no Multicast example project available in Processor SDK, Please try these examples and provide your feedback.

    Thanks,

    Rajarajan U