Skip to content
Open

Ops #33

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion p4src/includes/headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ header_type fabric_header_mirror_t {
}
}

#define CPU_REASON_CODE_SFLOW 0x106 // must match switch_hostif.h reson_code
#define CPU_REASON_CODE_SFLOW 0x4 // must match switch_hostif.h reson_code

header_type fabric_header_cpu_t {
fields {
Expand Down
90 changes: 51 additions & 39 deletions switchapi/inc/switchapi/switch_hostif.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,57 @@ extern "C" {

/** switch hostif reason code */
typedef enum switch_hostif_reason_code_ {
/*
* Reason code groups must start on power of 2 boundary since
* rx_net_filters are setup to use masks
*/
/* generic reason codes 0x0-0x0FF */
SWITCH_HOSTIF_REASON_CODE_NONE = 0x0,
SWITCH_HOSTIF_REASON_CODE_STP = 0x1,
SWITCH_HOSTIF_REASON_CODE_LACP = 0x2,
SWITCH_HOSTIF_REASON_CODE_EAPOL = 0x3,
SWITCH_HOSTIF_REASON_CODE_LLDP = 0x4,
SWITCH_HOSTIF_REASON_CODE_PVRST = 0x5,
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_QUERY = 0x6,
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_LEAVE = 0x7,
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V1_REPORT = 0x8,
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V2_REPORT = 0x9,
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V3_REPORT = 0xa,
SWITCH_HOSTIF_REASON_CODE_SAMPLEPACKET = 0xb,
SWITCH_HOSTIF_REASON_CODE_ARP_REQUEST = 0xc,
SWITCH_HOSTIF_REASON_CODE_ARP_RESPONSE = 0xd,
SWITCH_HOSTIF_REASON_CODE_DHCP = 0xe,
SWITCH_HOSTIF_REASON_CODE_OSPF = 0xf,
SWITCH_HOSTIF_REASON_CODE_PIM = 0x10,
SWITCH_HOSTIF_REASON_CODE_VRRP = 0x11,
SWITCH_HOSTIF_REASON_CODE_BGP = 0x12,
SWITCH_HOSTIF_REASON_CODE_DHCPV6 = 0x13,
SWITCH_HOSTIF_REASON_CODE_OSPFV6 = 0x14,
SWITCH_HOSTIF_REASON_CODE_VRRPV6 = 0x15,
SWITCH_HOSTIF_REASON_CODE_BGPV6 = 0x16,
SWITCH_HOSTIF_REASON_CODE_IPV6_NEIGHBOR_DISCOVERY = 0x17,
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_V2 = 0x18,
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_REPORT = 0x19,
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_DONE = 0x1a,
SWITCH_HOSTIF_REASON_CODE_MLD_V2_REPORT = 0x1b,
SWITCH_HOSTIF_REASON_CODE_L3_MTU_ERROR = 0x1c,
SWITCH_HOSTIF_REASON_CODE_TTL_ERROR = 0x1d,

SWITCH_HOSTIF_REASON_CODE_CUSTOM = 0x100,
SWITCH_HOSTIF_REASON_CODE_GLEAN = 0x101,
SWITCH_HOSTIF_REASON_CODE_MYIP = 0x102,
SWITCH_HOSTIF_REASON_CODE_DROP = 0x103,
SWITCH_HOSTIF_REASON_CODE_NULL_DROP = 0x103,
SWITCH_HOSTIF_REASON_CODE_ICMP_REDIRECT = 0x104,
SWITCH_HOSTIF_REASON_CODE_SRC_IS_LINK_LOCAL = 0x105,
SWITCH_HOSTIF_REASON_CODE_SFLOW_SAMPLE = 0x106, /* must match the value in headers.p4 */
SWITCH_HOSTIF_REASON_CODE_MAX = 0x200,
SWITCH_HOSTIF_REASON_CODE_CUSTOM = 0x1,
SWITCH_HOSTIF_REASON_CODE_DROP = 0x2,
SWITCH_HOSTIF_REASON_CODE_NULL_DROP = 0x3,
SWITCH_HOSTIF_REASON_CODE_SFLOW_SAMPLE = 0x4, /* must match the value in headers.p4 */

/* L2 reason codes 0x100 - 0x1FF */
SWITCH_HOSTIF_REASON_CODE_L2_START = 0x100,
SWITCH_HOSTIF_REASON_CODE_STP = SWITCH_HOSTIF_REASON_CODE_L2_START,
SWITCH_HOSTIF_REASON_CODE_LACP, /* 0x101 */
SWITCH_HOSTIF_REASON_CODE_EAPOL, /* 0x102 */
SWITCH_HOSTIF_REASON_CODE_LLDP, /* 0x103 */
SWITCH_HOSTIF_REASON_CODE_PVRST, /* 0x104 */
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_QUERY, /* 0x105 */
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_LEAVE, /* 0x106 */
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V1_REPORT, /* 0x107 */
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V2_REPORT, /* 0x108 */
SWITCH_HOSTIF_REASON_CODE_IGMP_TYPE_V3_REPORT, /* 0x109 */

/* L3 reason codes 0x200-0x2FF */
SWITCH_HOSTIF_REASON_CODE_L3_START = 0x200,
SWITCH_HOSTIF_REASON_CODE_SAMPLEPACKET = SWITCH_HOSTIF_REASON_CODE_L3_START,
SWITCH_HOSTIF_REASON_CODE_ARP_REQUEST, /* 0x201 */
SWITCH_HOSTIF_REASON_CODE_ARP_RESPONSE, /* 0x202 */
SWITCH_HOSTIF_REASON_CODE_DHCP, /* 0x203 */
SWITCH_HOSTIF_REASON_CODE_OSPF, /* 0x204 */
SWITCH_HOSTIF_REASON_CODE_PIM, /* 0x205 */
SWITCH_HOSTIF_REASON_CODE_VRRP, /* 0x206 */
SWITCH_HOSTIF_REASON_CODE_BGP, /* 0x207 */
SWITCH_HOSTIF_REASON_CODE_DHCPV6, /* 0x208 */
SWITCH_HOSTIF_REASON_CODE_OSPFV6, /* 0x209 */
SWITCH_HOSTIF_REASON_CODE_VRRPV6, /* 0x20a */
SWITCH_HOSTIF_REASON_CODE_BGPV6, /* 0x20b */
SWITCH_HOSTIF_REASON_CODE_IPV6_NEIGHBOR_DISCOVERY, /* 0x20c */
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_V2, /* 0x20d */
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_REPORT, /* 0x20e */
SWITCH_HOSTIF_REASON_CODE_IPV6_MLD_V1_DONE, /* 0x20f */
SWITCH_HOSTIF_REASON_CODE_MLD_V2_REPORT, /* 0x210 */
SWITCH_HOSTIF_REASON_CODE_L3_MTU_ERROR, /* 0x211 */
SWITCH_HOSTIF_REASON_CODE_TTL_ERROR, /* 0x212 */
SWITCH_HOSTIF_REASON_CODE_GLEAN, /* 0x213 */
SWITCH_HOSTIF_REASON_CODE_MYIP, /* 0x214 */
SWITCH_HOSTIF_REASON_CODE_ICMP_REDIRECT, /* 0x215 */
SWITCH_HOSTIF_REASON_CODE_SRC_IS_LINK_LOCAL, /* 0x216 */

SWITCH_HOSTIF_REASON_CODE_MAX,
} switch_hostif_reason_code_t;

/** switch channel */
Expand Down Expand Up @@ -225,6 +236,7 @@ typedef struct switch_packet_rx_key_ {
switch_handle_t handle; /**< bd or interface handle */
bool reason_code_valid;
switch_hostif_reason_code_t reason_code; /**< reason code */
uint32_t reason_code_mask; /**< reason code mask */
uint32_t priority;
} switch_packet_rx_key_t;

Expand Down
5 changes: 3 additions & 2 deletions switchapi/src/switch_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,13 @@ switch_api_init_default_acl_entries(switch_device_t device)
acl_kvp[1].mask.u.mask = 0xFFFFFFFF;
memset(&action_params, 0, sizeof(switch_acl_action_params_t));
action_params.cpu_redirect.reason_code = 0;
switch_api_acl_rule_create(device, acl_handle, priority++, 2,
switch_api_acl_rule_create(device, acl_handle,
2000, /* keep priority lower than reason-codes */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a predefined reason code for this in switch_hostif.c as well.

2,
acl_kvp, SWITCH_ACL_ACTION_COPY_TO_CPU,
&action_params,
&opt_action_params,
&handle);

// egress l3_mtu_check
acl_handle = switch_api_acl_list_create(device,
SWITCH_ACL_TYPE_EGRESS_SYSTEM);
Expand Down
39 changes: 13 additions & 26 deletions switchapi/src/switch_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,7 @@ switch_packet_tx_filter_priority_compare(
tx_entry1 = (switch_packet_tx_entry_t *) key1;
tx_entry2 = (switch_packet_tx_entry_t *) key2;

if (tx_entry1->priority == tx_entry2->priority) {
return 0;
} else if (tx_entry1->priority > tx_entry2->priority) {
return 1;
} else {
return -1;
}
return (int32_t)tx_entry1->priority - (int32_t)tx_entry2->priority;
}

switch_status_t
Expand Down Expand Up @@ -767,13 +761,7 @@ switch_packet_rx_compare(
rx_entry1 = (switch_packet_rx_entry_t *) key1;
rx_entry2 = (switch_packet_rx_entry_t *) key2;

if (rx_entry1->priority == rx_entry2->priority) {
return 0;
} else if (rx_entry1->priority > rx_entry2->priority) {
return 1;
} else {
return -1;
}
return (int32_t)rx_entry1->priority - (int32_t)rx_entry2->priority;
}

switch_status_t
Expand Down Expand Up @@ -987,14 +975,14 @@ switch_packet_rx_info_get(
while (node) {
tmp_rx_info = (switch_packet_rx_info_t *) node->data;
tmp_rx_entry = &tmp_rx_info->rx_entry;
if (((tmp_rx_entry->port_valid && tmp_rx_entry->port == rx_entry->port) ||
!tmp_rx_entry->port_valid) &&
((tmp_rx_entry->ifindex_valid && tmp_rx_entry->ifindex == rx_entry->ifindex) ||
!tmp_rx_entry->ifindex_valid) &&
((tmp_rx_entry->bd_valid && tmp_rx_entry->bd == rx_entry->bd) ||
!tmp_rx_entry->bd_valid) &&
((tmp_rx_entry->reason_code_valid && tmp_rx_entry->reason_code == rx_entry->reason_code) ||
!tmp_rx_entry->reason_code_valid)) {

if ((!tmp_rx_entry->port_valid || tmp_rx_entry->port == rx_entry->port) &&
(!tmp_rx_entry->ifindex_valid || tmp_rx_entry->ifindex == rx_entry->ifindex) &&
(!tmp_rx_entry->bd_valid || tmp_rx_entry->bd == rx_entry->bd) &&
(!tmp_rx_entry->reason_code_valid ||
(tmp_rx_entry->reason_code & tmp_rx_entry->reason_code_mask) ==
(rx_entry->reason_code & tmp_rx_entry->reason_code_mask))) {

*rx_info = tmp_rx_info;
status = SWITCH_STATUS_SUCCESS;
break;
Expand All @@ -1021,10 +1009,9 @@ switch_packet_tx_info_get(
while (node) {
tmp_tx_info = (switch_packet_tx_info_t *) node->data;
tmp_tx_entry = &tmp_tx_info->tx_entry;
if (((tmp_tx_entry->fd_valid && tmp_tx_entry->intf_fd == tx_entry->intf_fd) ||
!tmp_tx_entry->fd_valid) &&
((tmp_tx_entry->vlan_valid && tmp_tx_entry->vlan_id == tx_entry->vlan_id) ||
!tmp_tx_entry->vlan_valid)) {
if ((!tmp_tx_entry->fd_valid || tmp_tx_entry->intf_fd == tx_entry->intf_fd) &&
(!tmp_tx_entry->vlan_valid || tmp_tx_entry->vlan_id == tx_entry->vlan_id)) {

*tx_info = tmp_tx_info;
status = SWITCH_STATUS_SUCCESS;
break;
Expand Down
1 change: 1 addition & 0 deletions switchapi/src/switch_packet_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct switch_packet_rx_entry_ {
uint16_t bd;
bool bd_valid;
switch_hostif_reason_code_t reason_code;
uint32_t reason_code_mask;
bool reason_code_valid;
uint32_t priority;
} switch_packet_rx_entry_t;
Expand Down