请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:MCU-PLUS-SDK-AM263X 各位专家:
如何配置 CPSW 2G ALE 以根据 VLAN、以太网类型、源 MAC、目标 MAC、IP 地址等过滤数据包?
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.
各位专家:
如何配置 CPSW 2G ALE 以根据 VLAN、以太网类型、源 MAC、目标 MAC、IP 地址等过滤数据包?
地址查找引擎(ALE)是 CPSW 开关的子块、负责 处理所有接收到的数据包并确定数据包目标端口。 ALE 使用 传入的数据包数据来确定应如何转发数据包。 ALE 将 端口掩码输出 到指示数据包目标端口的交换结构。

程序员可以使用 ALE 的功能来设置复杂的规则、以便:
基本步骤包括:
示例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);
}