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.

[FAQ] MCU-PLUS-SDK-AM263X: How to configure CPSW 2G ALE to add static entries ?

Part Number: MCU-PLUS-SDK-AM263X

Hi Experts,

How do I configure CPSW 2G ALE to filter packets based on VLAN, Ethernet Type, Source MAC, Destination MAC, IP address etc?

  • The address lookup engine (ALE) is a sub-block of the CPSW Switch responsible for processing all received packets and determining the packet destination port(s). The ALE uses the incoming packet data to determine how the packet should be forwarded. The ALE outputs the port mask to the switch fabric that indicates the packet destination port(s).

    Programmers can use the features of ALE to set up complicated rules to:

    1. Filter packets based on VLAN, Ethernet Type, Source MAC, Destination MAC, IP address, etc (For a full list please see TRM and API Guide)
    2. Set up forwarding rules between ports (re-direct traffic)
    3. Perform rate limitation
    4. Implement Automotive security features such as
      1. Disallow IP fragmentation
      2. Drop invalid SA
      3. Setup black lists based on SA or DA
    5. Combine various features to setup complicated rules for forwarding/policing

    The basic steps include:

    • Step 2: Fill required parameters in the element of data structure like:
      • for vlan configurations parameters are vlan tag id, tag type and ingress check enabled or so(please check reference example and members of data structure for more details.) 
    • Step 3 : Call IOCTL by providing correct arguments( EnetHandle, core_id, ioctl_cmd, params, status)

    Example 1: Configuring ALE to filter packet based on VLAN:

    uint32_t vlan_id = 4U;
    /* Sample VLAN ALE entry Code. ALE will drop any packet without this VLAN ID tag*/
    /*Add inner/outer VLAN entry.
    IOCTL CMD: CPSW_ALE_IOCTL_ADD_VLAN
    IOCTL params:
    inArgs: CpswAle_VlanEntryInfo
    outArgs: uint32_t
    Calling context: Task*/
     
    void EnetApp_setVlanAle(EnetApp_PerCtxt *perCtxt)
    {
        int32_t status;
        Enet_IoctlPrms prms;
        CpswAle_VlanEntryInfo addVlanEntryAleInArgs;
        uint32_t outArgs;
     
        /* Set the Vlan configuration, Depending on need other parameters can also be used, Here we have used 3 params*/        
        addVlanEntryAleInArgs.vlanIdInfo.tagType = ENET_VLAN_TAG_TYPE_INNER;
        addVlanEntryAleInArgs.vlanIdInfo.vlanId =  vlan_id ;
        addVlanEntryAleInArgs.vidIngressCheck = 1U;  
       
        ENET_IOCTL_SET_INOUT_ARGS(&prms, &addVlanEntryAleInArgs, &outArgs);
        ENET_IOCTL(perCtxt->hEnet, gEnetApp.coreId,  CPSW_ALE_IOCTL_ADD_VLAN, &prms, status);
        if (status != ENET_SOK)
        {
            EnetAppUtils_print("\nEnetApp_setVlanAle() failed  CPSW_ALE_IOCTL_ADD_VLAN  : %d\n", status);
        }
        else
        {
            EnetAppUtils_print("\nFiltering Enabled for VLAN ID " , addVlanEntryAleInArgs.vlanIdInfo.vlanId));
        }
    }

    Example 2 : Configuring ALE to filter packet based on UCAST MAC address:

    static uint8_t testSrcAddr[ENET_MAC_ADDR_LEN] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x08 };
    /* Sample UCAST MAC ADDR ALE entry Code. ALE will drop any packet with src or dst address as this mac address */
    /*Add inner/outer VLAN entry.
    IOCTL CMD: CPSW_ALE_IOCTL_ADD_UCAST
    IOCTL params:
    inArgs: CpswAle_SetUcastEntryInArgs
    outArgs: uint32_t */
     
    void EnetApp_addUcastMacAddrAleEntry(EnetApp_PerCtxt *perCtxt)
    {
        int32_t status;
        Enet_IoctlPrms prms;    
        CpswAle_SetUcastEntryInArgs addUcastMacAleInArgs;
        uint32_t outArgs;
     
        /* Set the Vlan configuration, Depending on need other parameters can also be used, Here we have used 3 params*/          
        memcpy(&addUcastMacAleInArgs.addr.addr[0U], testSrcAddr, sizeof(addUcastMacAleInArgs.addr.addr));
        addUcastMacAleInArgs.blocked = 1U;
     
        ENET_IOCTL_SET_INOUT_ARGS(&prms, &addUcastMacAleInArgs, &outArgs);
        ENET_IOCTL(perCtxt->hEnet, gEnetApp.coreId,   CPSW_ALE_IOCTL_ADD_UCAST, &prms, status);
        if (status != ENET_SOK)
        {
            EnetAppUtils_print("\EnetApp_addUcastMacAddrAleEntry() failed   CPSW_ALE_IOCTL_ADD_UCAST  : %d\n", status);
        }
        else
        {   EnetAppUtils_print("\nFiltering Enabled on MAC Addr "));
            EnetAppUtils_printMacAddr(testSrcAddr);
    }