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.

AM3352: CPSW switch configuration

Part Number: AM3352

Hi,

We are using AM3352 processor and Linux Kernel 4.9.59 in our product and we have configured CPSW in Ethernet Switch Mode.

We want to use Link Layer Discovery Protocol (LLDP) to discover the topology in which our products are connected.

To achieve Topology Discovery using LLDP, Common Platform Ethernet Switch(CPSW) should behave as follow:
1> Any incoming LLDP packet received at Port 1 (Slave port 0) and Port 2(Slave Port 1) should be forwarded to Port 0(Host Port).
2> LLDP packet send from AM335x processor which gets received on CPSW Port 0 (Host port) should get forwarded to Port 1 and Port 2.

I am able to add LLDP multicast address in CPSW(using CONFIG_SWITCH_ADD_MULTICAST) to forward all incoming LLDP packet to Port 0(Host port). I have checked using wireshark that all incoming LLDP packet are getting forwarded to Port 0, But when I send LLDP packet from AM335x processor, I am not able to see LLDP packet on Port 1 and Port 2.

Is there a way to configure CPSW to behave as mention in point 1 and 2?

If yes then How to make CPSW behave as mentioned in point 1 and 2?

Regards
Rohit Savaliya

  • Please post what software you are using, and which version.

  • We are using Linux Kernel 4.9.59.

    Let me know if you need more information.

  • Hi,

    Is the LLDP a stack that you are using an open source one? Do you happen to know if it is expecting to communicate with a MAC or a switch?

    The ALE might be configurable by adding specific entries/rules to support the traffic but that may not interface well for what you are looking at higher up the stack. 

    Best Regards,

    Schuyler

  • Hi,

    I am not using any Open Source LLDP code. I have written small application which opens socket on eth0 port and send LLDP packet.

    Below are the steps used to open a socket:

    1> pRawsDesc->rawsFd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_LLDP_PROTO));

    2> setsockopt(pRawsDesc->rawsFd, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr)

    3> memset(&socket_address, 0, sizeof (socket_address));

         socket_address.sll_family = AF_PACKET;
         socket_address.sll_ifindex = if_nametoindex((const char *)pRawsDesc->deviceName); // Device name is 'eth0'
         socket_address.sll_protocol = htons(ETH_LLDP_PROTO);

         bind(pRawsDesc->rawsFd, (struct sockaddr*)&socket_address, sizeof(socket_address);

    4> /* Bind socket with LLDP multicast address */

         pkt_mreq.mr_ifindex = if_nametoindex((const char *)pRawsDesc->deviceName); /* interface index */ 
         pkt_mreq.mr_type = PACKET_MR_MULTICAST; /* action */
         pkt_mreq.mr_alen = ETH_ALEN; /* address length */
         memcpy(pkt_mreq.mr_address, lldp_mac_addr, sizeof(lldp_mac_addr)); /* lldp_mac_addr contains physical-layer address of lldp 01-80-C2-00-00-0E */
         setsockopt(pRawsDesc->rawsFd, SOL_SOCKET, PACKET_ADD_MEMBERSHIP, &pkt_mreq, sizeof(pkt_mreq));

    Below are the steps to send lldp packet on opened socket:

    1> memset(&socket_address, 0, sizeof (socket_address));

         socket_address.sll_family = AF_PACKET;
         socket_address.sll_ifindex = if_nametoindex((const char *)pRawsDesc->deviceName);
         socket_address.sll_protocol = htons(ETH_LLDP_PROTO);
         memcpy(socket_address.sll_addr, lldp_mac_addr, sizeof(lldp_mac_addr)); /* physical-layer address of lldp 01-80-C2-00-00-0E */
         socket_address.sll_halen = ETH_ALEN;
         sendto(pRawsDesc->rawsFd, pDataBuf, dtaBufLen, 0, (const struct sockaddr *)&socket_address, sizeof(socket_address)); // pDataBuf contains lldp payload

    Please also find below code which I have used to add LLDP multicast entry in CPSW.

    int main(void)
    {
          struct net_switch_config cmd_struct;
          struct ifreq ifr;
          int sockfd;
          strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
          ifr.ifr_data = (char*)&cmd_struct;
          if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
               printf("Can't open the socket\n");
               return -1;
         }
         memset(&cmd_struct, 0, sizeof(struct net_switch_config));

         //initialise cmd_struct with switch commands
         cmd_struct.cmd = CONFIG_SWITCH_ADD_MULTICAST;
         cmd_struct.addr[0] = 0x01;
         cmd_struct.addr[1] = 0x80;
         cmd_struct.addr[2] = 0xC2;
         cmd_struct.addr[3] = 0x00;
         cmd_struct.addr[4] = 0x00;
         cmd_struct.addr[5] = 0x0E;
         cmd_struct.port = 1;
         cmd_struct.vid = 0;
         cmd_struct.super = 0;

         if (ioctl(sockfd, SIOCSWITCHCONFIG, &ifr) < 0) {
              printf("Command failed\n");
              close(sockfd);
              return -1;
         }
         printf("command success\n");
         close(sockfd);
         return 0;
    }

    Regards

    Rohit Savaliya

  • Hi,

    Please have a look to the code I posted. If I configure the CPSW with lldp multicast address and forward all packet with lldp packet (lldp multicast address as destination in packet) to Port 0(Host port) of CPSW switch. In this condition what would happen if Port 0 receives any lldp packet.

    Does CPSW forward this incoming lldp packet on Port 0 to Port 1 and Port 2?

    My requirement is that when CPSW is configured as explained above, I want lldp packet coming at Port 0 to be forwarded to Port 1 and Port 2.

    Regards

    Rohit Savaliya

  • Hi,

    I will not be able to review the source code except for the switch config call. If understand your question correctly you will want to change .port field of the structure being passed in the ioctl from a 1 to a 3, this should enable the traffic you are looking for port 0-1 and 0-2. The link below describes the structure and the bit fields, this is also described in the TRM for the part.

    Link CPSW section of SW developer guide

    I recommend using wireshark to check if the packets make it out of each port simultaneously.

    Best Regards,

    Schuyler

  • Hi,

    I am using ioctl mentioned in Link CPSW section of SW developer guide to configure CPSW.

    Let me explain my requirement with below diagram:

    1> All incoming Layer 2 packet with destination address as 01-80-C2-00-00-0E (LLDP multicast address) should be forwarded to Port 0(Host Port).

    2> Layer 2 packet with destination address as 01-80-C2-00-00-0E(LLDP multicast address) received on Port 0 (Host port) should get forwarded to Port 1 and Port 2.

    Query:

    Can I configure CPSW to achieve both scenario as shown above?

    I do not want to change CPSW configuration at run time to achieve each scenario at a time. I want to configure CPSW once and It should behave as shown in above two case.

    Regards

    Rohit Savaliya

  • Hi,

    I apologize for the delay in responding. You should be able to configure the switch per your diagrams. 

    Best Regards,

    Schuyler