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:如何配置 CPSW 2G ALE 以添加静态条目?

Guru**** 651100 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1185526/faq-mcu-plus-sdk-am263x-how-to-configure-cpsw-2g-ale-to-add-static-entries

器件型号:MCU-PLUS-SDK-AM263X

各位专家:

如何配置 CPSW 2G ALE 以根据  VLAN、以太网类型、源 MAC、目标 MAC、IP 地址等过滤数据包?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    地址查找引擎(ALE)是 CPSW 开关的子块、负责 处理所有接收到的数据包并确定数据包目标端口。 ALE 使用 传入的数据包数据来确定应如何转发数据包。 ALE 将 端口掩码输出 到指示数据包目标端口的交换结构。

    程序员可以使用 ALE 的功能来设置复杂的规则、以便:

    1. 根据 VLAN、以太网类型、源 MAC、目标 MAC、IP 地址、 ETC (如需完整列表、请参阅 TRM 和 API 指南)
    2. 设置端口之间的转发规则(重新定向流量)
    3. 执行速率限制
    4. 实现汽车安全功能、例如
      1. 不允许 IP 碎片化
      2. 删除无效 SA
      3. 根据 SA 或 DA 设置黑色列表
    5. 结合各种功能来设置复杂的转发/管制规则

    基本步骤包括:

    • 步骤2:在数据结构的元素中填充所需的参数、例如:
      • VLAN 配置参数为 VLAN 标记 ID、标记类型和入口检查已启用或启用(有关更多 详细信息、请查看参考示例和数据结构成员。)  
    • 步骤3:通过提供正确的参数(EnetHandle、core_id、ioctl_cmd、params、status)来调用 IOCTL

    示例1:配置 ALE 以根据 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));
        }
    }

    示例 2:将 ALE 配置为根据 UCAST MAC 地址过滤数据包:

    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);
    }