1993ea577SAkhil Goyal /* SPDX-License-Identifier: BSD-3-Clause 2993ea577SAkhil Goyal * Copyright(C) 2023 Marvell. 3993ea577SAkhil Goyal */ 4993ea577SAkhil Goyal 5993ea577SAkhil Goyal #include <stdio.h> 6993ea577SAkhil Goyal #include <inttypes.h> 7993ea577SAkhil Goyal 8993ea577SAkhil Goyal #include <rte_ethdev.h> 9993ea577SAkhil Goyal #include <rte_malloc.h> 10993ea577SAkhil Goyal #include <rte_security.h> 11993ea577SAkhil Goyal 12993ea577SAkhil Goyal #include "test.h" 13993ea577SAkhil Goyal #include "test_security_inline_macsec_vectors.h" 14993ea577SAkhil Goyal 15993ea577SAkhil Goyal #ifdef RTE_EXEC_ENV_WINDOWS 16993ea577SAkhil Goyal static int 17993ea577SAkhil Goyal test_inline_macsec(void) 18993ea577SAkhil Goyal { 19993ea577SAkhil Goyal printf("Inline MACsec not supported on Windows, skipping test\n"); 20993ea577SAkhil Goyal return TEST_SKIPPED; 21993ea577SAkhil Goyal } 22993ea577SAkhil Goyal 23993ea577SAkhil Goyal #else 24993ea577SAkhil Goyal 25993ea577SAkhil Goyal #define NB_ETHPORTS_USED 1 26993ea577SAkhil Goyal #define MEMPOOL_CACHE_SIZE 32 27993ea577SAkhil Goyal #define RTE_TEST_RX_DESC_DEFAULT 1024 28993ea577SAkhil Goyal #define RTE_TEST_TX_DESC_DEFAULT 1024 29993ea577SAkhil Goyal #define RTE_PORT_ALL (~(uint16_t)0x0) 30993ea577SAkhil Goyal 31993ea577SAkhil Goyal #define RX_PTHRESH 8 /**< Default values of RX prefetch threshold reg. */ 32993ea577SAkhil Goyal #define RX_HTHRESH 8 /**< Default values of RX host threshold reg. */ 33993ea577SAkhil Goyal #define RX_WTHRESH 0 /**< Default values of RX write-back threshold reg. */ 34993ea577SAkhil Goyal 35993ea577SAkhil Goyal #define TX_PTHRESH 32 /**< Default values of TX prefetch threshold reg. */ 36993ea577SAkhil Goyal #define TX_HTHRESH 0 /**< Default values of TX host threshold reg. */ 37993ea577SAkhil Goyal #define TX_WTHRESH 0 /**< Default values of TX write-back threshold reg. */ 38993ea577SAkhil Goyal 39993ea577SAkhil Goyal #define MAX_TRAFFIC_BURST 2048 40993ea577SAkhil Goyal #define NB_MBUF 10240 41993ea577SAkhil Goyal 42993ea577SAkhil Goyal #define MCS_INVALID_SA 0xFFFF 43993ea577SAkhil Goyal #define MCS_DEFAULT_PN_THRESHOLD 0xFFFFF 44993ea577SAkhil Goyal 45993ea577SAkhil Goyal static struct rte_mempool *mbufpool; 46993ea577SAkhil Goyal static struct rte_mempool *sess_pool; 47993ea577SAkhil Goyal /* ethernet addresses of ports */ 48993ea577SAkhil Goyal static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; 49993ea577SAkhil Goyal 50993ea577SAkhil Goyal struct mcs_test_opts { 51993ea577SAkhil Goyal int val_frames; 52993ea577SAkhil Goyal int nb_td; 53993ea577SAkhil Goyal uint16_t mtu; 54993ea577SAkhil Goyal uint8_t sa_in_use; 55993ea577SAkhil Goyal bool encrypt; 56993ea577SAkhil Goyal bool protect_frames; 57993ea577SAkhil Goyal uint8_t sectag_insert_mode; 58993ea577SAkhil Goyal uint8_t nb_vlan; 59993ea577SAkhil Goyal uint32_t replay_win_sz; 60993ea577SAkhil Goyal uint8_t replay_protect; 61993ea577SAkhil Goyal uint8_t rekey_en; 62993ea577SAkhil Goyal const struct mcs_test_vector *rekey_td; 63993ea577SAkhil Goyal bool dump_all_stats; 64993ea577SAkhil Goyal uint8_t check_untagged_rx; 65993ea577SAkhil Goyal uint8_t check_bad_tag_cnt; 66993ea577SAkhil Goyal uint8_t check_sa_not_in_use; 67993ea577SAkhil Goyal uint8_t check_decap_stats; 68993ea577SAkhil Goyal uint8_t check_verify_only_stats; 69993ea577SAkhil Goyal uint8_t check_pkts_invalid_stats; 70993ea577SAkhil Goyal uint8_t check_pkts_unchecked_stats; 71993ea577SAkhil Goyal uint8_t check_out_pkts_untagged; 72993ea577SAkhil Goyal uint8_t check_out_pkts_toolong; 73993ea577SAkhil Goyal uint8_t check_encap_stats; 74993ea577SAkhil Goyal uint8_t check_auth_only_stats; 75993ea577SAkhil Goyal uint8_t check_sectag_interrupts; 76993ea577SAkhil Goyal }; 77993ea577SAkhil Goyal 78993ea577SAkhil Goyal static struct rte_eth_conf port_conf = { 79993ea577SAkhil Goyal .rxmode = { 80993ea577SAkhil Goyal .mq_mode = RTE_ETH_MQ_RX_NONE, 81993ea577SAkhil Goyal .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 82993ea577SAkhil Goyal RTE_ETH_RX_OFFLOAD_MACSEC_STRIP, 83993ea577SAkhil Goyal }, 84993ea577SAkhil Goyal .txmode = { 85993ea577SAkhil Goyal .mq_mode = RTE_ETH_MQ_TX_NONE, 86993ea577SAkhil Goyal .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE | 87993ea577SAkhil Goyal RTE_ETH_TX_OFFLOAD_MACSEC_INSERT, 88993ea577SAkhil Goyal }, 89993ea577SAkhil Goyal .lpbk_mode = 1, /* enable loopback */ 90993ea577SAkhil Goyal }; 91993ea577SAkhil Goyal 92993ea577SAkhil Goyal static struct rte_eth_rxconf rx_conf = { 93993ea577SAkhil Goyal .rx_thresh = { 94993ea577SAkhil Goyal .pthresh = RX_PTHRESH, 95993ea577SAkhil Goyal .hthresh = RX_HTHRESH, 96993ea577SAkhil Goyal .wthresh = RX_WTHRESH, 97993ea577SAkhil Goyal }, 98993ea577SAkhil Goyal .rx_free_thresh = 32, 99993ea577SAkhil Goyal }; 100993ea577SAkhil Goyal 101993ea577SAkhil Goyal static struct rte_eth_txconf tx_conf = { 102993ea577SAkhil Goyal .tx_thresh = { 103993ea577SAkhil Goyal .pthresh = TX_PTHRESH, 104993ea577SAkhil Goyal .hthresh = TX_HTHRESH, 105993ea577SAkhil Goyal .wthresh = TX_WTHRESH, 106993ea577SAkhil Goyal }, 107993ea577SAkhil Goyal .tx_free_thresh = 32, /* Use PMD default values */ 108993ea577SAkhil Goyal .tx_rs_thresh = 32, /* Use PMD default values */ 109993ea577SAkhil Goyal }; 110993ea577SAkhil Goyal 111993ea577SAkhil Goyal static uint16_t port_id; 112993ea577SAkhil Goyal 113993ea577SAkhil Goyal static uint64_t link_mbps; 114993ea577SAkhil Goyal 115993ea577SAkhil Goyal static struct rte_flow *default_tx_flow[RTE_MAX_ETHPORTS]; 116993ea577SAkhil Goyal static struct rte_flow *default_rx_flow[RTE_MAX_ETHPORTS]; 117993ea577SAkhil Goyal 118993ea577SAkhil Goyal static struct rte_mbuf **tx_pkts_burst; 119993ea577SAkhil Goyal static struct rte_mbuf **rx_pkts_burst; 120993ea577SAkhil Goyal 121993ea577SAkhil Goyal static inline struct rte_mbuf * 122993ea577SAkhil Goyal init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len) 123993ea577SAkhil Goyal { 124993ea577SAkhil Goyal struct rte_mbuf *pkt; 125993ea577SAkhil Goyal 126993ea577SAkhil Goyal pkt = rte_pktmbuf_alloc(mp); 127993ea577SAkhil Goyal if (pkt == NULL) 128993ea577SAkhil Goyal return NULL; 129993ea577SAkhil Goyal 130993ea577SAkhil Goyal rte_memcpy(rte_pktmbuf_append(pkt, len), data, len); 131993ea577SAkhil Goyal 132993ea577SAkhil Goyal return pkt; 133993ea577SAkhil Goyal } 134993ea577SAkhil Goyal 135993ea577SAkhil Goyal static int 136993ea577SAkhil Goyal init_mempools(unsigned int nb_mbuf) 137993ea577SAkhil Goyal { 138993ea577SAkhil Goyal struct rte_security_ctx *sec_ctx; 139993ea577SAkhil Goyal uint16_t nb_sess = 512; 140993ea577SAkhil Goyal uint32_t sess_sz; 141993ea577SAkhil Goyal char s[64]; 142993ea577SAkhil Goyal 143993ea577SAkhil Goyal if (mbufpool == NULL) { 144993ea577SAkhil Goyal snprintf(s, sizeof(s), "mbuf_pool"); 145993ea577SAkhil Goyal mbufpool = rte_pktmbuf_pool_create(s, nb_mbuf, 146993ea577SAkhil Goyal MEMPOOL_CACHE_SIZE, 0, 147993ea577SAkhil Goyal RTE_MBUF_DEFAULT_BUF_SIZE, SOCKET_ID_ANY); 148993ea577SAkhil Goyal if (mbufpool == NULL) { 149993ea577SAkhil Goyal printf("Cannot init mbuf pool\n"); 150993ea577SAkhil Goyal return TEST_FAILED; 151993ea577SAkhil Goyal } 152993ea577SAkhil Goyal printf("Allocated mbuf pool\n"); 153993ea577SAkhil Goyal } 154993ea577SAkhil Goyal 155993ea577SAkhil Goyal sec_ctx = rte_eth_dev_get_sec_ctx(port_id); 156993ea577SAkhil Goyal if (sec_ctx == NULL) { 157993ea577SAkhil Goyal printf("Device does not support Security ctx\n"); 158993ea577SAkhil Goyal return TEST_SKIPPED; 159993ea577SAkhil Goyal } 160993ea577SAkhil Goyal sess_sz = rte_security_session_get_size(sec_ctx); 161993ea577SAkhil Goyal if (sess_pool == NULL) { 162993ea577SAkhil Goyal snprintf(s, sizeof(s), "sess_pool"); 163993ea577SAkhil Goyal sess_pool = rte_mempool_create(s, nb_sess, sess_sz, 164993ea577SAkhil Goyal MEMPOOL_CACHE_SIZE, 0, 165993ea577SAkhil Goyal NULL, NULL, NULL, NULL, 166993ea577SAkhil Goyal SOCKET_ID_ANY, 0); 167993ea577SAkhil Goyal if (sess_pool == NULL) { 168993ea577SAkhil Goyal printf("Cannot init sess pool\n"); 169993ea577SAkhil Goyal return TEST_FAILED; 170993ea577SAkhil Goyal } 171993ea577SAkhil Goyal printf("Allocated sess pool\n"); 172993ea577SAkhil Goyal } 173993ea577SAkhil Goyal 174993ea577SAkhil Goyal return 0; 175993ea577SAkhil Goyal } 176993ea577SAkhil Goyal 177993ea577SAkhil Goyal static void 178993ea577SAkhil Goyal fill_macsec_sa_conf(const struct mcs_test_vector *td, struct rte_security_macsec_sa *sa, 179993ea577SAkhil Goyal enum rte_security_macsec_direction dir, uint8_t an, uint8_t tci_off) 180993ea577SAkhil Goyal { 181993ea577SAkhil Goyal sa->dir = dir; 182993ea577SAkhil Goyal 183993ea577SAkhil Goyal sa->key.data = td->sa_key.data; 184993ea577SAkhil Goyal sa->key.length = td->sa_key.len; 185993ea577SAkhil Goyal 186993ea577SAkhil Goyal memcpy((uint8_t *)sa->salt, (const uint8_t *)td->salt, RTE_SECURITY_MACSEC_SALT_LEN); 187993ea577SAkhil Goyal 188993ea577SAkhil Goyal /* AN is set as per the value in secure packet in test vector */ 189993ea577SAkhil Goyal sa->an = an & RTE_MACSEC_AN_MASK; 190993ea577SAkhil Goyal 191993ea577SAkhil Goyal sa->ssci = td->ssci; 192993ea577SAkhil Goyal sa->xpn = td->xpn; 193993ea577SAkhil Goyal /* Starting packet number which is expected to come next. 194993ea577SAkhil Goyal * It is take from the test vector so that we can match the out packet. 195993ea577SAkhil Goyal */ 196993ea577SAkhil Goyal sa->next_pn = *(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]); 197993ea577SAkhil Goyal } 198993ea577SAkhil Goyal 199993ea577SAkhil Goyal static void 200993ea577SAkhil Goyal fill_macsec_sc_conf(const struct mcs_test_vector *td, 201993ea577SAkhil Goyal struct rte_security_macsec_sc *sc_conf, 202993ea577SAkhil Goyal const struct mcs_test_opts *opts, 203993ea577SAkhil Goyal enum rte_security_macsec_direction dir, 204993ea577SAkhil Goyal uint16_t sa_id[], uint8_t tci_off) 205993ea577SAkhil Goyal { 206993ea577SAkhil Goyal uint8_t i; 207993ea577SAkhil Goyal 208993ea577SAkhil Goyal sc_conf->dir = dir; 209993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) { 210993ea577SAkhil Goyal sc_conf->sc_tx.sa_id = sa_id[0]; 211993ea577SAkhil Goyal if (sa_id[1] != MCS_INVALID_SA) { 212993ea577SAkhil Goyal sc_conf->sc_tx.sa_id_rekey = sa_id[1]; 213993ea577SAkhil Goyal sc_conf->sc_tx.re_key_en = 1; 214993ea577SAkhil Goyal } 215993ea577SAkhil Goyal sc_conf->sc_tx.active = 1; 216993ea577SAkhil Goyal /* is SCI valid */ 217993ea577SAkhil Goyal if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) { 218993ea577SAkhil Goyal memcpy(&sc_conf->sc_tx.sci, &td->secure_pkt.data[tci_off + 6], 219993ea577SAkhil Goyal sizeof(sc_conf->sc_tx.sci)); 220993ea577SAkhil Goyal sc_conf->sc_tx.sci = rte_be_to_cpu_64(sc_conf->sc_tx.sci); 221993ea577SAkhil Goyal } else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) { 222993ea577SAkhil Goyal /* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */ 223993ea577SAkhil Goyal const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN; 224993ea577SAkhil Goyal uint8_t *ptr = (uint8_t *)&sc_conf->sc_tx.sci; 225993ea577SAkhil Goyal 226993ea577SAkhil Goyal ptr[0] = 0x01; 227993ea577SAkhil Goyal ptr[1] = 0; 228993ea577SAkhil Goyal for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) 229993ea577SAkhil Goyal ptr[2 + i] = smac[RTE_ETHER_ADDR_LEN - 1 - i]; 230993ea577SAkhil Goyal } else { 231993ea577SAkhil Goyal /* use some default SCI */ 232993ea577SAkhil Goyal sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d; 233993ea577SAkhil Goyal } 234993ea577SAkhil Goyal } else { 235993ea577SAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 236993ea577SAkhil Goyal sc_conf->sc_rx.sa_id[i] = sa_id[i]; 237993ea577SAkhil Goyal sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use; 238993ea577SAkhil Goyal } 239993ea577SAkhil Goyal sc_conf->sc_rx.active = 1; 240993ea577SAkhil Goyal } 241993ea577SAkhil Goyal } 242993ea577SAkhil Goyal 243993ea577SAkhil Goyal 244993ea577SAkhil Goyal /* Create Inline MACsec session */ 245993ea577SAkhil Goyal static int 246993ea577SAkhil Goyal fill_session_conf(const struct mcs_test_vector *td, uint16_t portid __rte_unused, 247993ea577SAkhil Goyal const struct mcs_test_opts *opts, 248993ea577SAkhil Goyal struct rte_security_session_conf *sess_conf, 249993ea577SAkhil Goyal enum rte_security_macsec_direction dir, 250993ea577SAkhil Goyal uint16_t sc_id, 251993ea577SAkhil Goyal uint8_t tci_off) 252993ea577SAkhil Goyal { 253993ea577SAkhil Goyal sess_conf->action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL; 254993ea577SAkhil Goyal sess_conf->protocol = RTE_SECURITY_PROTOCOL_MACSEC; 255993ea577SAkhil Goyal sess_conf->macsec.dir = dir; 256993ea577SAkhil Goyal sess_conf->macsec.alg = td->alg; 257993ea577SAkhil Goyal sess_conf->macsec.cipher_off = 0; 258993ea577SAkhil Goyal if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) { 259993ea577SAkhil Goyal sess_conf->macsec.sci = rte_be_to_cpu_64(*(const uint64_t *) 260993ea577SAkhil Goyal (&td->secure_pkt.data[tci_off + 6])); 261993ea577SAkhil Goyal } else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) { 262993ea577SAkhil Goyal /* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */ 263993ea577SAkhil Goyal const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN; 264993ea577SAkhil Goyal uint8_t *ptr = (uint8_t *)&sess_conf->macsec.sci; 265993ea577SAkhil Goyal uint8_t j; 266993ea577SAkhil Goyal 267993ea577SAkhil Goyal ptr[0] = 0x01; 268993ea577SAkhil Goyal ptr[1] = 0; 269993ea577SAkhil Goyal for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) 270993ea577SAkhil Goyal ptr[2 + j] = smac[RTE_ETHER_ADDR_LEN - 1 - j]; 271993ea577SAkhil Goyal } 272993ea577SAkhil Goyal sess_conf->macsec.sc_id = sc_id; 273993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) { 274993ea577SAkhil Goyal sess_conf->macsec.tx_secy.mtu = opts->mtu; 275993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_off = (opts->sectag_insert_mode == 1) ? 276993ea577SAkhil Goyal 2 * RTE_ETHER_ADDR_LEN : 277993ea577SAkhil Goyal RTE_VLAN_HLEN; 278993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_insert_mode = opts->sectag_insert_mode; 279993ea577SAkhil Goyal sess_conf->macsec.tx_secy.ctrl_port_enable = 1; 280993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_version = 0; 281993ea577SAkhil Goyal sess_conf->macsec.tx_secy.end_station = 282993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) >> 6; 283993ea577SAkhil Goyal sess_conf->macsec.tx_secy.send_sci = 284993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) >> 5; 285993ea577SAkhil Goyal sess_conf->macsec.tx_secy.scb = 286993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SCB) >> 4; 287993ea577SAkhil Goyal sess_conf->macsec.tx_secy.encrypt = opts->encrypt; 288993ea577SAkhil Goyal sess_conf->macsec.tx_secy.protect_frames = opts->protect_frames; 289993ea577SAkhil Goyal sess_conf->macsec.tx_secy.icv_include_da_sa = 1; 290993ea577SAkhil Goyal } else { 291993ea577SAkhil Goyal sess_conf->macsec.rx_secy.replay_win_sz = opts->replay_win_sz; 292993ea577SAkhil Goyal sess_conf->macsec.rx_secy.replay_protect = opts->replay_protect; 293993ea577SAkhil Goyal sess_conf->macsec.rx_secy.icv_include_da_sa = 1; 294993ea577SAkhil Goyal sess_conf->macsec.rx_secy.ctrl_port_enable = 1; 295993ea577SAkhil Goyal sess_conf->macsec.rx_secy.preserve_sectag = 0; 296993ea577SAkhil Goyal sess_conf->macsec.rx_secy.preserve_icv = 0; 297993ea577SAkhil Goyal sess_conf->macsec.rx_secy.validate_frames = opts->val_frames; 298993ea577SAkhil Goyal } 299993ea577SAkhil Goyal 300993ea577SAkhil Goyal return 0; 301993ea577SAkhil Goyal } 302993ea577SAkhil Goyal 303993ea577SAkhil Goyal static int 304993ea577SAkhil Goyal create_default_flow(const struct mcs_test_vector *td, uint16_t portid, 305993ea577SAkhil Goyal enum rte_security_macsec_direction dir, void *sess) 306993ea577SAkhil Goyal { 307993ea577SAkhil Goyal struct rte_flow_action action[2]; 308993ea577SAkhil Goyal struct rte_flow_item pattern[2]; 309993ea577SAkhil Goyal struct rte_flow_attr attr = {0}; 310993ea577SAkhil Goyal struct rte_flow_error err; 311993ea577SAkhil Goyal struct rte_flow *flow; 312993ea577SAkhil Goyal struct rte_flow_item_eth eth = { .hdr.ether_type = 0, }; 313993ea577SAkhil Goyal static const struct rte_flow_item_eth eth_mask = { 314993ea577SAkhil Goyal .hdr.dst_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00", 315993ea577SAkhil Goyal .hdr.src_addr.addr_bytes = "\x00\x00\x00\x00\x00\x00", 316993ea577SAkhil Goyal .hdr.ether_type = RTE_BE16(0x0000), 317993ea577SAkhil Goyal }; 318993ea577SAkhil Goyal 319993ea577SAkhil Goyal int ret; 320993ea577SAkhil Goyal 321993ea577SAkhil Goyal eth.has_vlan = 0; 322993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) 323993ea577SAkhil Goyal memcpy(ð.hdr, td->plain_pkt.data, RTE_ETHER_HDR_LEN); 324993ea577SAkhil Goyal else 325993ea577SAkhil Goyal memcpy(ð.hdr, td->secure_pkt.data, RTE_ETHER_HDR_LEN); 326993ea577SAkhil Goyal 327993ea577SAkhil Goyal pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; 328993ea577SAkhil Goyal pattern[0].spec = ð 329993ea577SAkhil Goyal pattern[0].mask = ð_mask; 330993ea577SAkhil Goyal pattern[0].last = NULL; 331993ea577SAkhil Goyal pattern[1].type = RTE_FLOW_ITEM_TYPE_END; 332993ea577SAkhil Goyal 333993ea577SAkhil Goyal action[0].type = RTE_FLOW_ACTION_TYPE_SECURITY; 334993ea577SAkhil Goyal action[0].conf = sess; 335993ea577SAkhil Goyal action[1].type = RTE_FLOW_ACTION_TYPE_END; 336993ea577SAkhil Goyal action[1].conf = NULL; 337993ea577SAkhil Goyal 338993ea577SAkhil Goyal attr.ingress = (dir == RTE_SECURITY_MACSEC_DIR_RX) ? 1 : 0; 339993ea577SAkhil Goyal attr.egress = (dir == RTE_SECURITY_MACSEC_DIR_TX) ? 1 : 0; 340993ea577SAkhil Goyal 341993ea577SAkhil Goyal ret = rte_flow_validate(portid, &attr, pattern, action, &err); 342993ea577SAkhil Goyal if (ret) { 343993ea577SAkhil Goyal printf("\nValidate flow failed, ret = %d\n", ret); 344993ea577SAkhil Goyal return -1; 345993ea577SAkhil Goyal } 346993ea577SAkhil Goyal flow = rte_flow_create(portid, &attr, pattern, action, &err); 347993ea577SAkhil Goyal if (flow == NULL) { 348993ea577SAkhil Goyal printf("\nDefault flow rule create failed\n"); 349993ea577SAkhil Goyal return -1; 350993ea577SAkhil Goyal } 351993ea577SAkhil Goyal 352993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) 353993ea577SAkhil Goyal default_tx_flow[portid] = flow; 354993ea577SAkhil Goyal else 355993ea577SAkhil Goyal default_rx_flow[portid] = flow; 356993ea577SAkhil Goyal 357993ea577SAkhil Goyal return 0; 358993ea577SAkhil Goyal } 359993ea577SAkhil Goyal 360993ea577SAkhil Goyal static void 361993ea577SAkhil Goyal destroy_default_flow(uint16_t portid) 362993ea577SAkhil Goyal { 363993ea577SAkhil Goyal struct rte_flow_error err; 364993ea577SAkhil Goyal int ret; 365993ea577SAkhil Goyal 366993ea577SAkhil Goyal if (default_tx_flow[portid]) { 367993ea577SAkhil Goyal ret = rte_flow_destroy(portid, default_tx_flow[portid], &err); 368993ea577SAkhil Goyal if (ret) { 369993ea577SAkhil Goyal printf("\nDefault Tx flow rule destroy failed\n"); 370993ea577SAkhil Goyal return; 371993ea577SAkhil Goyal } 372993ea577SAkhil Goyal default_tx_flow[portid] = NULL; 373993ea577SAkhil Goyal } 374993ea577SAkhil Goyal if (default_rx_flow[portid]) { 375993ea577SAkhil Goyal ret = rte_flow_destroy(portid, default_rx_flow[portid], &err); 376993ea577SAkhil Goyal if (ret) { 377993ea577SAkhil Goyal printf("\nDefault Rx flow rule destroy failed\n"); 378993ea577SAkhil Goyal return; 379993ea577SAkhil Goyal } 380993ea577SAkhil Goyal default_rx_flow[portid] = NULL; 381993ea577SAkhil Goyal } 382993ea577SAkhil Goyal } 383993ea577SAkhil Goyal 384993ea577SAkhil Goyal static void 385993ea577SAkhil Goyal print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 386993ea577SAkhil Goyal { 387993ea577SAkhil Goyal char buf[RTE_ETHER_ADDR_FMT_SIZE]; 388993ea577SAkhil Goyal rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 389993ea577SAkhil Goyal printf("%s%s", name, buf); 390993ea577SAkhil Goyal } 391993ea577SAkhil Goyal 392993ea577SAkhil Goyal /* Check the link status of all ports in up to 3s, and print them finally */ 393993ea577SAkhil Goyal static void 394993ea577SAkhil Goyal check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) 395993ea577SAkhil Goyal { 396993ea577SAkhil Goyal #define CHECK_INTERVAL 100 /* 100ms */ 397993ea577SAkhil Goyal #define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */ 398993ea577SAkhil Goyal uint16_t portid; 399993ea577SAkhil Goyal uint8_t count, all_ports_up, print_flag = 0; 400993ea577SAkhil Goyal struct rte_eth_link link; 401993ea577SAkhil Goyal int ret; 402993ea577SAkhil Goyal char link_status[RTE_ETH_LINK_MAX_STR_LEN]; 403993ea577SAkhil Goyal 404993ea577SAkhil Goyal printf("Checking link statuses...\n"); 405993ea577SAkhil Goyal fflush(stdout); 406993ea577SAkhil Goyal for (count = 0; count <= MAX_CHECK_TIME; count++) { 407993ea577SAkhil Goyal all_ports_up = 1; 408993ea577SAkhil Goyal for (portid = 0; portid < port_num; portid++) { 409993ea577SAkhil Goyal if ((port_mask & (1 << portid)) == 0) 410993ea577SAkhil Goyal continue; 411993ea577SAkhil Goyal memset(&link, 0, sizeof(link)); 412993ea577SAkhil Goyal ret = rte_eth_link_get_nowait(portid, &link); 413993ea577SAkhil Goyal if (ret < 0) { 414993ea577SAkhil Goyal all_ports_up = 0; 415993ea577SAkhil Goyal if (print_flag == 1) 416993ea577SAkhil Goyal printf("Port %u link get failed: %s\n", 417993ea577SAkhil Goyal portid, rte_strerror(-ret)); 418993ea577SAkhil Goyal continue; 419993ea577SAkhil Goyal } 420993ea577SAkhil Goyal 421993ea577SAkhil Goyal /* print link status if flag set */ 422993ea577SAkhil Goyal if (print_flag == 1) { 423993ea577SAkhil Goyal if (link.link_status && link_mbps == 0) 424993ea577SAkhil Goyal link_mbps = link.link_speed; 425993ea577SAkhil Goyal 426993ea577SAkhil Goyal rte_eth_link_to_str(link_status, 427993ea577SAkhil Goyal sizeof(link_status), &link); 428993ea577SAkhil Goyal printf("Port %d %s\n", portid, link_status); 429993ea577SAkhil Goyal continue; 430993ea577SAkhil Goyal } 431993ea577SAkhil Goyal /* clear all_ports_up flag if any link down */ 432993ea577SAkhil Goyal if (link.link_status == RTE_ETH_LINK_DOWN) { 433993ea577SAkhil Goyal all_ports_up = 0; 434993ea577SAkhil Goyal break; 435993ea577SAkhil Goyal } 436993ea577SAkhil Goyal } 437993ea577SAkhil Goyal /* after finally printing all link status, get out */ 438993ea577SAkhil Goyal if (print_flag == 1) 439993ea577SAkhil Goyal break; 440993ea577SAkhil Goyal 441993ea577SAkhil Goyal if (all_ports_up == 0) 442993ea577SAkhil Goyal fflush(stdout); 443993ea577SAkhil Goyal 444993ea577SAkhil Goyal /* set the print_flag if all ports up or timeout */ 445993ea577SAkhil Goyal if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) 446993ea577SAkhil Goyal print_flag = 1; 447993ea577SAkhil Goyal } 448993ea577SAkhil Goyal } 449993ea577SAkhil Goyal 450993ea577SAkhil Goyal static int 451993ea577SAkhil Goyal test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, 452993ea577SAkhil Goyal enum mcs_op op, uint8_t check_out_pkts_untagged) 453993ea577SAkhil Goyal { 454993ea577SAkhil Goyal const uint8_t *dptr; 455993ea577SAkhil Goyal uint16_t pkt_len; 456993ea577SAkhil Goyal 457993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 458993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY || 459993ea577SAkhil Goyal check_out_pkts_untagged == 1) { 460993ea577SAkhil Goyal dptr = td->plain_pkt.data; 461993ea577SAkhil Goyal pkt_len = td->plain_pkt.len; 462993ea577SAkhil Goyal } else { 463993ea577SAkhil Goyal dptr = td->secure_pkt.data; 464993ea577SAkhil Goyal pkt_len = td->secure_pkt.len; 465993ea577SAkhil Goyal } 466993ea577SAkhil Goyal 467993ea577SAkhil Goyal if (memcmp(rte_pktmbuf_mtod(m, uint8_t *), dptr, pkt_len)) { 468993ea577SAkhil Goyal printf("\nData comparison failed for td."); 469993ea577SAkhil Goyal rte_pktmbuf_dump(stdout, m, m->pkt_len); 470993ea577SAkhil Goyal rte_hexdump(stdout, "expected_data", dptr, pkt_len); 471993ea577SAkhil Goyal return TEST_FAILED; 472993ea577SAkhil Goyal } 473993ea577SAkhil Goyal 474993ea577SAkhil Goyal return TEST_SUCCESS; 475993ea577SAkhil Goyal } 476993ea577SAkhil Goyal 477993ea577SAkhil Goyal static void 478993ea577SAkhil Goyal mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op, 479993ea577SAkhil Goyal void *rx_sess, void *tx_sess, 480993ea577SAkhil Goyal uint8_t rx_sc_id, uint8_t tx_sc_id, 481993ea577SAkhil Goyal uint16_t rx_sa_id[], uint16_t tx_sa_id[]) 482993ea577SAkhil Goyal { 483993ea577SAkhil Goyal struct rte_security_stats sess_stats = {0}; 484993ea577SAkhil Goyal struct rte_security_macsec_secy_stats *secy_stat; 485993ea577SAkhil Goyal struct rte_security_macsec_sc_stats sc_stat = {0}; 486993ea577SAkhil Goyal struct rte_security_macsec_sa_stats sa_stat = {0}; 487993ea577SAkhil Goyal int i; 488993ea577SAkhil Goyal 489993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 490993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 491993ea577SAkhil Goyal printf("\n********* RX SECY STATS ************\n"); 492993ea577SAkhil Goyal rte_security_session_stats_get(ctx, rx_sess, &sess_stats); 493993ea577SAkhil Goyal secy_stat = &sess_stats.macsec; 494993ea577SAkhil Goyal 495993ea577SAkhil Goyal if (secy_stat->ctl_pkt_bcast_cnt) 496993ea577SAkhil Goyal printf("RX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 497993ea577SAkhil Goyal secy_stat->ctl_pkt_bcast_cnt); 498993ea577SAkhil Goyal if (secy_stat->ctl_pkt_mcast_cnt) 499993ea577SAkhil Goyal printf("RX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 500993ea577SAkhil Goyal secy_stat->ctl_pkt_mcast_cnt); 501993ea577SAkhil Goyal if (secy_stat->ctl_pkt_ucast_cnt) 502993ea577SAkhil Goyal printf("RX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 503993ea577SAkhil Goyal secy_stat->ctl_pkt_ucast_cnt); 504993ea577SAkhil Goyal if (secy_stat->ctl_octet_cnt) 505993ea577SAkhil Goyal printf("RX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt); 506993ea577SAkhil Goyal if (secy_stat->unctl_pkt_bcast_cnt) 507993ea577SAkhil Goyal printf("RX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 508993ea577SAkhil Goyal secy_stat->unctl_pkt_bcast_cnt); 509993ea577SAkhil Goyal if (secy_stat->unctl_pkt_mcast_cnt) 510993ea577SAkhil Goyal printf("RX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 511993ea577SAkhil Goyal secy_stat->unctl_pkt_mcast_cnt); 512993ea577SAkhil Goyal if (secy_stat->unctl_pkt_ucast_cnt) 513993ea577SAkhil Goyal printf("RX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 514993ea577SAkhil Goyal secy_stat->unctl_pkt_ucast_cnt); 515993ea577SAkhil Goyal if (secy_stat->unctl_octet_cnt) 516993ea577SAkhil Goyal printf("RX: unctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->unctl_octet_cnt); 517993ea577SAkhil Goyal /* Valid only for RX */ 518993ea577SAkhil Goyal if (secy_stat->octet_decrypted_cnt) 519993ea577SAkhil Goyal printf("RX: octet_decrypted_cnt: 0x%" PRIx64 "\n", 520993ea577SAkhil Goyal secy_stat->octet_decrypted_cnt); 521993ea577SAkhil Goyal if (secy_stat->octet_validated_cnt) 522993ea577SAkhil Goyal printf("RX: octet_validated_cnt: 0x%" PRIx64 "\n", 523993ea577SAkhil Goyal secy_stat->octet_validated_cnt); 524993ea577SAkhil Goyal if (secy_stat->pkt_port_disabled_cnt) 525993ea577SAkhil Goyal printf("RX: pkt_port_disabled_cnt: 0x%" PRIx64 "\n", 526993ea577SAkhil Goyal secy_stat->pkt_port_disabled_cnt); 527993ea577SAkhil Goyal if (secy_stat->pkt_badtag_cnt) 528993ea577SAkhil Goyal printf("RX: pkt_badtag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_badtag_cnt); 529993ea577SAkhil Goyal if (secy_stat->pkt_nosa_cnt) 530993ea577SAkhil Goyal printf("RX: pkt_nosa_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_nosa_cnt); 531993ea577SAkhil Goyal if (secy_stat->pkt_nosaerror_cnt) 532993ea577SAkhil Goyal printf("RX: pkt_nosaerror_cnt: 0x%" PRIx64 "\n", 533993ea577SAkhil Goyal secy_stat->pkt_nosaerror_cnt); 534993ea577SAkhil Goyal if (secy_stat->pkt_tagged_ctl_cnt) 535993ea577SAkhil Goyal printf("RX: pkt_tagged_ctl_cnt: 0x%" PRIx64 "\n", 536993ea577SAkhil Goyal secy_stat->pkt_tagged_ctl_cnt); 537993ea577SAkhil Goyal if (secy_stat->pkt_untaged_cnt) 538993ea577SAkhil Goyal printf("RX: pkt_untaged_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_untaged_cnt); 539993ea577SAkhil Goyal if (secy_stat->pkt_ctl_cnt) 540993ea577SAkhil Goyal printf("RX: pkt_ctl_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_ctl_cnt); 541993ea577SAkhil Goyal if (secy_stat->pkt_notag_cnt) 542993ea577SAkhil Goyal printf("RX: pkt_notag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_notag_cnt); 543993ea577SAkhil Goyal printf("\n"); 544993ea577SAkhil Goyal printf("\n********** RX SC[%u] STATS **************\n", rx_sc_id); 545993ea577SAkhil Goyal 546993ea577SAkhil Goyal rte_security_macsec_sc_stats_get(ctx, rx_sc_id, RTE_SECURITY_MACSEC_DIR_RX, 547993ea577SAkhil Goyal &sc_stat); 548993ea577SAkhil Goyal /* RX */ 549993ea577SAkhil Goyal if (sc_stat.hit_cnt) 550993ea577SAkhil Goyal printf("RX hit_cnt: 0x%" PRIx64 "\n", sc_stat.hit_cnt); 551993ea577SAkhil Goyal if (sc_stat.pkt_invalid_cnt) 552993ea577SAkhil Goyal printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_invalid_cnt); 553993ea577SAkhil Goyal if (sc_stat.pkt_late_cnt) 554993ea577SAkhil Goyal printf("RX pkt_late_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_late_cnt); 555993ea577SAkhil Goyal if (sc_stat.pkt_notvalid_cnt) 556993ea577SAkhil Goyal printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_notvalid_cnt); 557993ea577SAkhil Goyal if (sc_stat.pkt_unchecked_cnt) 558993ea577SAkhil Goyal printf("RX pkt_unchecked_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_unchecked_cnt); 559993ea577SAkhil Goyal if (sc_stat.pkt_delay_cnt) 560993ea577SAkhil Goyal printf("RX pkt_delay_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_delay_cnt); 561993ea577SAkhil Goyal if (sc_stat.pkt_ok_cnt) 562993ea577SAkhil Goyal printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_ok_cnt); 563993ea577SAkhil Goyal if (sc_stat.octet_decrypt_cnt) 564993ea577SAkhil Goyal printf("RX octet_decrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_decrypt_cnt); 565993ea577SAkhil Goyal if (sc_stat.octet_validate_cnt) 566993ea577SAkhil Goyal printf("RX octet_validate_cnt: 0x%" PRIx64 "\n", 567993ea577SAkhil Goyal sc_stat.octet_validate_cnt); 568993ea577SAkhil Goyal printf("\n"); 569993ea577SAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 570993ea577SAkhil Goyal printf("\n********** RX SA[%u] STATS ****************\n", rx_sa_id[i]); 571993ea577SAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 572993ea577SAkhil Goyal rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i], 573993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sa_stat); 574993ea577SAkhil Goyal 575993ea577SAkhil Goyal /* RX */ 576993ea577SAkhil Goyal if (sa_stat.pkt_invalid_cnt) 577993ea577SAkhil Goyal printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n", 578993ea577SAkhil Goyal sa_stat.pkt_invalid_cnt); 579993ea577SAkhil Goyal if (sa_stat.pkt_nosaerror_cnt) 580993ea577SAkhil Goyal printf("RX pkt_nosaerror_cnt: 0x%" PRIx64 "\n", 581993ea577SAkhil Goyal sa_stat.pkt_nosaerror_cnt); 582993ea577SAkhil Goyal if (sa_stat.pkt_notvalid_cnt) 583993ea577SAkhil Goyal printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n", 584993ea577SAkhil Goyal sa_stat.pkt_notvalid_cnt); 585993ea577SAkhil Goyal if (sa_stat.pkt_ok_cnt) 586993ea577SAkhil Goyal printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_ok_cnt); 587993ea577SAkhil Goyal if (sa_stat.pkt_nosa_cnt) 588993ea577SAkhil Goyal printf("RX pkt_nosa_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_nosa_cnt); 589993ea577SAkhil Goyal printf("\n"); 590993ea577SAkhil Goyal } 591993ea577SAkhil Goyal } 592993ea577SAkhil Goyal 593993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 594993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 595993ea577SAkhil Goyal memset(&sess_stats, 0, sizeof(struct rte_security_stats)); 596993ea577SAkhil Goyal rte_security_session_stats_get(ctx, tx_sess, &sess_stats); 597993ea577SAkhil Goyal secy_stat = &sess_stats.macsec; 598993ea577SAkhil Goyal 599993ea577SAkhil Goyal printf("\n********* TX SECY STATS ************\n"); 600993ea577SAkhil Goyal if (secy_stat->ctl_pkt_bcast_cnt) 601993ea577SAkhil Goyal printf("TX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 602993ea577SAkhil Goyal secy_stat->ctl_pkt_bcast_cnt); 603993ea577SAkhil Goyal if (secy_stat->ctl_pkt_mcast_cnt) 604993ea577SAkhil Goyal printf("TX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 605993ea577SAkhil Goyal secy_stat->ctl_pkt_mcast_cnt); 606993ea577SAkhil Goyal if (secy_stat->ctl_pkt_ucast_cnt) 607993ea577SAkhil Goyal printf("TX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 608993ea577SAkhil Goyal secy_stat->ctl_pkt_ucast_cnt); 609993ea577SAkhil Goyal if (secy_stat->ctl_octet_cnt) 610993ea577SAkhil Goyal printf("TX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt); 611993ea577SAkhil Goyal if (secy_stat->unctl_pkt_bcast_cnt) 612993ea577SAkhil Goyal printf("TX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 613993ea577SAkhil Goyal secy_stat->unctl_pkt_bcast_cnt); 614993ea577SAkhil Goyal if (secy_stat->unctl_pkt_mcast_cnt) 615993ea577SAkhil Goyal printf("TX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 616993ea577SAkhil Goyal secy_stat->unctl_pkt_mcast_cnt); 617993ea577SAkhil Goyal if (secy_stat->unctl_pkt_ucast_cnt) 618993ea577SAkhil Goyal printf("TX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 619993ea577SAkhil Goyal secy_stat->unctl_pkt_ucast_cnt); 620993ea577SAkhil Goyal if (secy_stat->unctl_octet_cnt) 621993ea577SAkhil Goyal printf("TX: unctl_octet_cnt: 0x%" PRIx64 "\n", 622993ea577SAkhil Goyal secy_stat->unctl_octet_cnt); 623993ea577SAkhil Goyal /* Valid only for TX */ 624993ea577SAkhil Goyal if (secy_stat->octet_encrypted_cnt) 625993ea577SAkhil Goyal printf("TX: octet_encrypted_cnt: 0x%" PRIx64 "\n", 626993ea577SAkhil Goyal secy_stat->octet_encrypted_cnt); 627993ea577SAkhil Goyal if (secy_stat->octet_protected_cnt) 628993ea577SAkhil Goyal printf("TX: octet_protected_cnt: 0x%" PRIx64 "\n", 629993ea577SAkhil Goyal secy_stat->octet_protected_cnt); 630993ea577SAkhil Goyal if (secy_stat->pkt_noactivesa_cnt) 631993ea577SAkhil Goyal printf("TX: pkt_noactivesa_cnt: 0x%" PRIx64 "\n", 632993ea577SAkhil Goyal secy_stat->pkt_noactivesa_cnt); 633993ea577SAkhil Goyal if (secy_stat->pkt_toolong_cnt) 634993ea577SAkhil Goyal printf("TX: pkt_toolong_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_toolong_cnt); 635993ea577SAkhil Goyal if (secy_stat->pkt_untagged_cnt) 636993ea577SAkhil Goyal printf("TX: pkt_untagged_cnt: 0x%" PRIx64 "\n", 637993ea577SAkhil Goyal secy_stat->pkt_untagged_cnt); 638993ea577SAkhil Goyal 639993ea577SAkhil Goyal 640993ea577SAkhil Goyal memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats)); 641993ea577SAkhil Goyal rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX, 642993ea577SAkhil Goyal &sc_stat); 643993ea577SAkhil Goyal printf("\n********** TX SC[%u] STATS **************\n", tx_sc_id); 644993ea577SAkhil Goyal if (sc_stat.pkt_encrypt_cnt) 645993ea577SAkhil Goyal printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_encrypt_cnt); 646993ea577SAkhil Goyal if (sc_stat.pkt_protected_cnt) 647993ea577SAkhil Goyal printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_protected_cnt); 648993ea577SAkhil Goyal if (sc_stat.octet_encrypt_cnt) 649993ea577SAkhil Goyal printf("TX octet_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_encrypt_cnt); 650993ea577SAkhil Goyal 651993ea577SAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 652993ea577SAkhil Goyal rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0], 653993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, &sa_stat); 654993ea577SAkhil Goyal printf("\n********** TX SA[%u] STATS ****************\n", tx_sa_id[0]); 655993ea577SAkhil Goyal if (sa_stat.pkt_encrypt_cnt) 656993ea577SAkhil Goyal printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_encrypt_cnt); 657993ea577SAkhil Goyal if (sa_stat.pkt_protected_cnt) 658993ea577SAkhil Goyal printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_protected_cnt); 659993ea577SAkhil Goyal } 660993ea577SAkhil Goyal } 661993ea577SAkhil Goyal 662993ea577SAkhil Goyal static int 6637c3b1decSAkhil Goyal mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op, 6647c3b1decSAkhil Goyal const struct mcs_test_opts *opts, 6657c3b1decSAkhil Goyal const struct mcs_test_vector *td, 6667c3b1decSAkhil Goyal void *rx_sess, void *tx_sess, 6677c3b1decSAkhil Goyal uint8_t rx_sc_id, uint8_t tx_sc_id, 6687c3b1decSAkhil Goyal uint16_t rx_sa_id[], uint16_t tx_sa_id[]) 6697c3b1decSAkhil Goyal { 6707c3b1decSAkhil Goyal struct rte_security_stats sess_stats = {0}; 6717c3b1decSAkhil Goyal struct rte_security_macsec_secy_stats *secy_stat; 6727c3b1decSAkhil Goyal struct rte_security_macsec_sc_stats sc_stat = {0}; 6737c3b1decSAkhil Goyal struct rte_security_macsec_sa_stats sa_stat = {0}; 6747c3b1decSAkhil Goyal int i; 6757c3b1decSAkhil Goyal 6767c3b1decSAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 6777c3b1decSAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 6787c3b1decSAkhil Goyal rte_security_session_stats_get(ctx, rx_sess, &sess_stats); 6797c3b1decSAkhil Goyal secy_stat = &sess_stats.macsec; 6807c3b1decSAkhil Goyal 6817c3b1decSAkhil Goyal if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) || 6827c3b1decSAkhil Goyal (opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1)) 6837c3b1decSAkhil Goyal return TEST_FAILED; 6847c3b1decSAkhil Goyal 6857c3b1decSAkhil Goyal if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1) 6867c3b1decSAkhil Goyal return TEST_FAILED; 6877c3b1decSAkhil Goyal 6887c3b1decSAkhil Goyal if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1) 6897c3b1decSAkhil Goyal return TEST_FAILED; 6907c3b1decSAkhil Goyal 6917c3b1decSAkhil Goyal if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt != 6927c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 6937c3b1decSAkhil Goyal return TEST_FAILED; 6947c3b1decSAkhil Goyal 6957c3b1decSAkhil Goyal if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt != 6967c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 6977c3b1decSAkhil Goyal return TEST_FAILED; 6987c3b1decSAkhil Goyal 6997c3b1decSAkhil Goyal rte_security_macsec_sc_stats_get(ctx, rx_sc_id, 7007c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sc_stat); 7017c3b1decSAkhil Goyal 7027c3b1decSAkhil Goyal if ((opts->check_decap_stats || opts->check_verify_only_stats) && 7037c3b1decSAkhil Goyal sc_stat.pkt_ok_cnt != 1) 7047c3b1decSAkhil Goyal return TEST_FAILED; 7057c3b1decSAkhil Goyal 7067c3b1decSAkhil Goyal if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1) 7077c3b1decSAkhil Goyal return TEST_FAILED; 7087c3b1decSAkhil Goyal 7097c3b1decSAkhil Goyal if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1) 7107c3b1decSAkhil Goyal return TEST_FAILED; 7117c3b1decSAkhil Goyal 7127c3b1decSAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 7137c3b1decSAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 7147c3b1decSAkhil Goyal rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i], 7157c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sa_stat); 7167c3b1decSAkhil Goyal 7177c3b1decSAkhil Goyal } 7187c3b1decSAkhil Goyal } 7197c3b1decSAkhil Goyal 7207c3b1decSAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 7217c3b1decSAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 7227c3b1decSAkhil Goyal memset(&sess_stats, 0, sizeof(struct rte_security_stats)); 7237c3b1decSAkhil Goyal rte_security_session_stats_get(ctx, tx_sess, &sess_stats); 7247c3b1decSAkhil Goyal secy_stat = &sess_stats.macsec; 7257c3b1decSAkhil Goyal 7267c3b1decSAkhil Goyal if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1) 7277c3b1decSAkhil Goyal return TEST_FAILED; 7287c3b1decSAkhil Goyal 7297c3b1decSAkhil Goyal if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1) 7307c3b1decSAkhil Goyal return TEST_FAILED; 7317c3b1decSAkhil Goyal 7327c3b1decSAkhil Goyal if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt != 7337c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7347c3b1decSAkhil Goyal return TEST_FAILED; 7357c3b1decSAkhil Goyal 7367c3b1decSAkhil Goyal if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt != 7377c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7387c3b1decSAkhil Goyal return TEST_FAILED; 7397c3b1decSAkhil Goyal 7407c3b1decSAkhil Goyal 7417c3b1decSAkhil Goyal memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats)); 7427c3b1decSAkhil Goyal rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX, 7437c3b1decSAkhil Goyal &sc_stat); 7447c3b1decSAkhil Goyal 7457c3b1decSAkhil Goyal if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1) 7467c3b1decSAkhil Goyal return TEST_FAILED; 7477c3b1decSAkhil Goyal 7487c3b1decSAkhil Goyal if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1) 7497c3b1decSAkhil Goyal return TEST_FAILED; 7507c3b1decSAkhil Goyal 7517c3b1decSAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 7527c3b1decSAkhil Goyal rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0], 7537c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, &sa_stat); 7547c3b1decSAkhil Goyal } 7557c3b1decSAkhil Goyal 7567c3b1decSAkhil Goyal return 0; 7577c3b1decSAkhil Goyal } 7587c3b1decSAkhil Goyal 7597c3b1decSAkhil Goyal static int 760*339b9354SAnkur Dwivedi test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type, 761*339b9354SAnkur Dwivedi void *param, void *ret_param) 762*339b9354SAnkur Dwivedi { 763*339b9354SAnkur Dwivedi struct mcs_err_vector *vector = (struct mcs_err_vector *)param; 764*339b9354SAnkur Dwivedi struct rte_eth_event_macsec_desc *event_desc = NULL; 765*339b9354SAnkur Dwivedi 766*339b9354SAnkur Dwivedi RTE_SET_USED(port_id); 767*339b9354SAnkur Dwivedi 768*339b9354SAnkur Dwivedi if (type != RTE_ETH_EVENT_MACSEC) 769*339b9354SAnkur Dwivedi return -1; 770*339b9354SAnkur Dwivedi 771*339b9354SAnkur Dwivedi event_desc = ret_param; 772*339b9354SAnkur Dwivedi if (event_desc == NULL) { 773*339b9354SAnkur Dwivedi printf("Event descriptor not set\n"); 774*339b9354SAnkur Dwivedi return -1; 775*339b9354SAnkur Dwivedi } 776*339b9354SAnkur Dwivedi vector->notify_event = true; 777*339b9354SAnkur Dwivedi 778*339b9354SAnkur Dwivedi switch (event_desc->type) { 779*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR: 780*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR; 781*339b9354SAnkur Dwivedi switch (event_desc->subtype) { 782*339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1: 783*339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1; 784*339b9354SAnkur Dwivedi break; 785*339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1: 786*339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1; 787*339b9354SAnkur Dwivedi break; 788*339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48: 789*339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48; 790*339b9354SAnkur Dwivedi break; 791*339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1: 792*339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1; 793*339b9354SAnkur Dwivedi break; 794*339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1: 795*339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1; 796*339b9354SAnkur Dwivedi break; 797*339b9354SAnkur Dwivedi default: 798*339b9354SAnkur Dwivedi printf("\nUnknown Macsec event subtype: %d", event_desc->subtype); 799*339b9354SAnkur Dwivedi } 800*339b9354SAnkur Dwivedi break; 801*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP: 802*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP; 803*339b9354SAnkur Dwivedi break; 804*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP: 805*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP; 806*339b9354SAnkur Dwivedi break; 807*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP: 808*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP; 809*339b9354SAnkur Dwivedi break; 810*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP: 811*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP; 812*339b9354SAnkur Dwivedi break; 813*339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID: 814*339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID; 815*339b9354SAnkur Dwivedi break; 816*339b9354SAnkur Dwivedi default: 817*339b9354SAnkur Dwivedi printf("Invalid MACsec event reported\n"); 818*339b9354SAnkur Dwivedi return -1; 819*339b9354SAnkur Dwivedi } 820*339b9354SAnkur Dwivedi 821*339b9354SAnkur Dwivedi return 0; 822*339b9354SAnkur Dwivedi } 823*339b9354SAnkur Dwivedi 824*339b9354SAnkur Dwivedi static int 825993ea577SAkhil Goyal test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts) 826993ea577SAkhil Goyal { 827993ea577SAkhil Goyal uint16_t rx_sa_id[MCS_MAX_FLOWS][RTE_SECURITY_MACSEC_NUM_AN] = {{0}}; 828993ea577SAkhil Goyal uint16_t tx_sa_id[MCS_MAX_FLOWS][2] = {{0}}; 829993ea577SAkhil Goyal uint16_t rx_sc_id[MCS_MAX_FLOWS] = {0}; 830993ea577SAkhil Goyal uint16_t tx_sc_id[MCS_MAX_FLOWS] = {0}; 831993ea577SAkhil Goyal void *rx_sess[MCS_MAX_FLOWS] = {0}; 832993ea577SAkhil Goyal void *tx_sess[MCS_MAX_FLOWS] = {0}; 833993ea577SAkhil Goyal struct rte_security_session_conf sess_conf = {0}; 834993ea577SAkhil Goyal struct rte_security_macsec_sa sa_conf = {0}; 835993ea577SAkhil Goyal struct rte_security_macsec_sc sc_conf = {0}; 836993ea577SAkhil Goyal struct rte_security_ctx *ctx; 837993ea577SAkhil Goyal int nb_rx = 0, nb_sent; 838993ea577SAkhil Goyal int i, j = 0, ret, id, an = 0; 839993ea577SAkhil Goyal uint8_t tci_off; 840993ea577SAkhil Goyal 841993ea577SAkhil Goyal memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td); 842993ea577SAkhil Goyal 843993ea577SAkhil Goyal ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx(port_id); 844993ea577SAkhil Goyal if (ctx == NULL) { 845993ea577SAkhil Goyal printf("Ethernet device doesn't support security features.\n"); 846993ea577SAkhil Goyal return TEST_SKIPPED; 847993ea577SAkhil Goyal } 848993ea577SAkhil Goyal 849993ea577SAkhil Goyal tci_off = (opts->sectag_insert_mode == 1) ? RTE_ETHER_HDR_LEN : 850993ea577SAkhil Goyal RTE_ETHER_HDR_LEN + (opts->nb_vlan * RTE_VLAN_HLEN); 851993ea577SAkhil Goyal 852993ea577SAkhil Goyal for (i = 0, j = 0; i < opts->nb_td; i++) { 853993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_VERIFY_ONLY) 854993ea577SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, td[i]->secure_pkt.data, 855993ea577SAkhil Goyal td[i]->secure_pkt.len); 856993ea577SAkhil Goyal else { 857993ea577SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, td[i]->plain_pkt.data, 858993ea577SAkhil Goyal td[i]->plain_pkt.len); 859993ea577SAkhil Goyal 860993ea577SAkhil Goyal tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC; 861993ea577SAkhil Goyal } 862993ea577SAkhil Goyal if (tx_pkts_burst[j] == NULL) { 863993ea577SAkhil Goyal while (j--) 864993ea577SAkhil Goyal rte_pktmbuf_free(tx_pkts_burst[j]); 865993ea577SAkhil Goyal ret = TEST_FAILED; 866993ea577SAkhil Goyal goto out; 867993ea577SAkhil Goyal } 868993ea577SAkhil Goyal j++; 869993ea577SAkhil Goyal 870993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 871993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 872993ea577SAkhil Goyal for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) { 873993ea577SAkhil Goyal /* For simplicity, using same SA conf for all AN */ 874993ea577SAkhil Goyal fill_macsec_sa_conf(td[i], &sa_conf, 875993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, an, tci_off); 876993ea577SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 877993ea577SAkhil Goyal if (id < 0) { 878993ea577SAkhil Goyal printf("MACsec SA create failed : %d.\n", id); 879993ea577SAkhil Goyal return TEST_FAILED; 880993ea577SAkhil Goyal } 881993ea577SAkhil Goyal rx_sa_id[i][an] = (uint16_t)id; 882993ea577SAkhil Goyal } 883993ea577SAkhil Goyal fill_macsec_sc_conf(td[i], &sc_conf, opts, 884993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sa_id[i], tci_off); 885993ea577SAkhil Goyal id = rte_security_macsec_sc_create(ctx, &sc_conf); 886993ea577SAkhil Goyal if (id < 0) { 887993ea577SAkhil Goyal printf("MACsec SC create failed : %d.\n", id); 888993ea577SAkhil Goyal goto out; 889993ea577SAkhil Goyal } 890993ea577SAkhil Goyal rx_sc_id[i] = (uint16_t)id; 891993ea577SAkhil Goyal 892993ea577SAkhil Goyal /* Create Inline IPsec session. */ 893993ea577SAkhil Goyal ret = fill_session_conf(td[i], port_id, opts, &sess_conf, 894993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sc_id[i], tci_off); 895993ea577SAkhil Goyal if (ret) 896993ea577SAkhil Goyal return TEST_FAILED; 897993ea577SAkhil Goyal 898993ea577SAkhil Goyal rx_sess[i] = rte_security_session_create(ctx, &sess_conf, 899993ea577SAkhil Goyal sess_pool); 900993ea577SAkhil Goyal if (rx_sess[i] == NULL) { 901993ea577SAkhil Goyal printf("SEC Session init failed.\n"); 902993ea577SAkhil Goyal return TEST_FAILED; 903993ea577SAkhil Goyal } 904993ea577SAkhil Goyal ret = create_default_flow(td[i], port_id, 905993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sess[i]); 906993ea577SAkhil Goyal if (ret) 907993ea577SAkhil Goyal goto out; 908993ea577SAkhil Goyal } 909993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 910993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 911993ea577SAkhil Goyal int id; 912993ea577SAkhil Goyal 913993ea577SAkhil Goyal fill_macsec_sa_conf(td[i], &sa_conf, 914993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, 915993ea577SAkhil Goyal td[i]->secure_pkt.data[tci_off] & RTE_MACSEC_AN_MASK, 916993ea577SAkhil Goyal tci_off); 917993ea577SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 918993ea577SAkhil Goyal if (id < 0) { 919993ea577SAkhil Goyal printf("MACsec SA create failed : %d.\n", id); 920993ea577SAkhil Goyal return TEST_FAILED; 921993ea577SAkhil Goyal } 922993ea577SAkhil Goyal tx_sa_id[i][0] = (uint16_t)id; 923993ea577SAkhil Goyal tx_sa_id[i][1] = MCS_INVALID_SA; 924993ea577SAkhil Goyal fill_macsec_sc_conf(td[i], &sc_conf, opts, 925993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off); 926993ea577SAkhil Goyal id = rte_security_macsec_sc_create(ctx, &sc_conf); 927993ea577SAkhil Goyal if (id < 0) { 928993ea577SAkhil Goyal printf("MACsec SC create failed : %d.\n", id); 929993ea577SAkhil Goyal goto out; 930993ea577SAkhil Goyal } 931993ea577SAkhil Goyal tx_sc_id[i] = (uint16_t)id; 932993ea577SAkhil Goyal 933993ea577SAkhil Goyal /* Create Inline IPsec session. */ 934993ea577SAkhil Goyal ret = fill_session_conf(td[i], port_id, opts, &sess_conf, 935993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sc_id[i], tci_off); 936993ea577SAkhil Goyal if (ret) 937993ea577SAkhil Goyal return TEST_FAILED; 938993ea577SAkhil Goyal 939993ea577SAkhil Goyal tx_sess[i] = rte_security_session_create(ctx, &sess_conf, 940993ea577SAkhil Goyal sess_pool); 941993ea577SAkhil Goyal if (tx_sess[i] == NULL) { 942993ea577SAkhil Goyal printf("SEC Session init failed.\n"); 943993ea577SAkhil Goyal return TEST_FAILED; 944993ea577SAkhil Goyal } 945993ea577SAkhil Goyal ret = create_default_flow(td[i], port_id, 946993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sess[i]); 947993ea577SAkhil Goyal if (ret) 948993ea577SAkhil Goyal goto out; 949993ea577SAkhil Goyal } 950993ea577SAkhil Goyal } 951993ea577SAkhil Goyal 952993ea577SAkhil Goyal /* Send packet to ethdev for inline MACsec processing. */ 953993ea577SAkhil Goyal nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, j); 954993ea577SAkhil Goyal 955993ea577SAkhil Goyal if (nb_sent != j) { 956993ea577SAkhil Goyal printf("\nUnable to TX %d packets, sent: %i", j, nb_sent); 957993ea577SAkhil Goyal for ( ; nb_sent < j; nb_sent++) 958993ea577SAkhil Goyal rte_pktmbuf_free(tx_pkts_burst[nb_sent]); 959993ea577SAkhil Goyal ret = TEST_FAILED; 960993ea577SAkhil Goyal goto out; 961993ea577SAkhil Goyal } 962993ea577SAkhil Goyal 963993ea577SAkhil Goyal rte_pause(); 964993ea577SAkhil Goyal 965993ea577SAkhil Goyal /* Receive back packet on loopback interface. */ 966993ea577SAkhil Goyal do { 967993ea577SAkhil Goyal nb_rx += rte_eth_rx_burst(port_id, 0, 968993ea577SAkhil Goyal &rx_pkts_burst[nb_rx], 969993ea577SAkhil Goyal nb_sent - nb_rx); 970993ea577SAkhil Goyal if (nb_rx >= nb_sent) 971993ea577SAkhil Goyal break; 972993ea577SAkhil Goyal rte_delay_ms(1); 973993ea577SAkhil Goyal } while (j++ < 5 && nb_rx == 0); 974993ea577SAkhil Goyal 975993ea577SAkhil Goyal if (nb_rx != nb_sent) { 976993ea577SAkhil Goyal printf("\nUnable to RX all %d packets, received(%i)", 977993ea577SAkhil Goyal nb_sent, nb_rx); 978993ea577SAkhil Goyal while (--nb_rx >= 0) 979993ea577SAkhil Goyal rte_pktmbuf_free(rx_pkts_burst[nb_rx]); 980993ea577SAkhil Goyal ret = TEST_FAILED; 981*339b9354SAnkur Dwivedi if (opts->check_sectag_interrupts == 1) 982*339b9354SAnkur Dwivedi ret = TEST_SUCCESS; 983993ea577SAkhil Goyal goto out; 984993ea577SAkhil Goyal } 985993ea577SAkhil Goyal 986993ea577SAkhil Goyal for (i = 0; i < nb_rx; i++) { 987993ea577SAkhil Goyal ret = test_macsec_post_process(rx_pkts_burst[i], td[i], op, 988993ea577SAkhil Goyal opts->check_out_pkts_untagged); 989993ea577SAkhil Goyal if (ret != TEST_SUCCESS) { 990993ea577SAkhil Goyal for ( ; i < nb_rx; i++) 991993ea577SAkhil Goyal rte_pktmbuf_free(rx_pkts_burst[i]); 992993ea577SAkhil Goyal goto out; 993993ea577SAkhil Goyal } 994993ea577SAkhil Goyal 995993ea577SAkhil Goyal rte_pktmbuf_free(rx_pkts_burst[i]); 996993ea577SAkhil Goyal rx_pkts_burst[i] = NULL; 997993ea577SAkhil Goyal } 998993ea577SAkhil Goyal out: 9997c3b1decSAkhil Goyal if (opts->check_out_pkts_toolong == 1 || 10007c3b1decSAkhil Goyal opts->check_sa_not_in_use == 1 || 10017c3b1decSAkhil Goyal opts->check_bad_tag_cnt == 1) 10027c3b1decSAkhil Goyal ret = TEST_SUCCESS; 10037c3b1decSAkhil Goyal 1004993ea577SAkhil Goyal for (i = 0; i < opts->nb_td; i++) { 1005993ea577SAkhil Goyal if (opts->dump_all_stats) { 1006993ea577SAkhil Goyal mcs_stats_dump(ctx, op, 1007993ea577SAkhil Goyal rx_sess[i], tx_sess[i], 1008993ea577SAkhil Goyal rx_sc_id[i], tx_sc_id[i], 1009993ea577SAkhil Goyal rx_sa_id[i], tx_sa_id[i]); 10107c3b1decSAkhil Goyal } else { 10117c3b1decSAkhil Goyal if (ret == TEST_SUCCESS) 10127c3b1decSAkhil Goyal ret = mcs_stats_check(ctx, op, opts, td[i], 10137c3b1decSAkhil Goyal rx_sess[i], tx_sess[i], 10147c3b1decSAkhil Goyal rx_sc_id[i], tx_sc_id[i], 10157c3b1decSAkhil Goyal rx_sa_id[i], tx_sa_id[i]); 1016993ea577SAkhil Goyal } 1017993ea577SAkhil Goyal } 1018993ea577SAkhil Goyal 1019993ea577SAkhil Goyal destroy_default_flow(port_id); 1020993ea577SAkhil Goyal 1021993ea577SAkhil Goyal /* Destroy session so that other cases can create the session again */ 1022993ea577SAkhil Goyal for (i = 0; i < opts->nb_td; i++) { 1023993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 1024993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 1025993ea577SAkhil Goyal rte_security_session_destroy(ctx, tx_sess[i]); 1026993ea577SAkhil Goyal tx_sess[i] = NULL; 1027993ea577SAkhil Goyal rte_security_macsec_sc_destroy(ctx, tx_sc_id[i], 1028993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1029993ea577SAkhil Goyal rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0], 1030993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1031993ea577SAkhil Goyal } 1032993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 1033993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 1034993ea577SAkhil Goyal rte_security_session_destroy(ctx, rx_sess[i]); 1035993ea577SAkhil Goyal rx_sess[i] = NULL; 1036993ea577SAkhil Goyal rte_security_macsec_sc_destroy(ctx, rx_sc_id[i], 1037993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX); 1038993ea577SAkhil Goyal for (j = 0; j < RTE_SECURITY_MACSEC_NUM_AN; j++) { 1039993ea577SAkhil Goyal rte_security_macsec_sa_destroy(ctx, rx_sa_id[i][j], 1040993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX); 1041993ea577SAkhil Goyal } 1042993ea577SAkhil Goyal } 1043993ea577SAkhil Goyal } 1044993ea577SAkhil Goyal 1045993ea577SAkhil Goyal return ret; 1046993ea577SAkhil Goyal } 1047993ea577SAkhil Goyal 1048993ea577SAkhil Goyal static int 1049993ea577SAkhil Goyal test_inline_macsec_encap_all(const void *data __rte_unused) 1050993ea577SAkhil Goyal { 1051993ea577SAkhil Goyal const struct mcs_test_vector *cur_td; 1052993ea577SAkhil Goyal struct mcs_test_opts opts = {0}; 1053993ea577SAkhil Goyal int err, all_err = 0; 1054993ea577SAkhil Goyal int i, size; 1055993ea577SAkhil Goyal 1056993ea577SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1057993ea577SAkhil Goyal opts.encrypt = true; 1058993ea577SAkhil Goyal opts.protect_frames = true; 1059993ea577SAkhil Goyal opts.sa_in_use = 1; 1060993ea577SAkhil Goyal opts.nb_td = 1; 1061993ea577SAkhil Goyal opts.sectag_insert_mode = 1; 1062993ea577SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1063993ea577SAkhil Goyal 1064993ea577SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1065993ea577SAkhil Goyal for (i = 0; i < size; i++) { 1066993ea577SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1067993ea577SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1068993ea577SAkhil Goyal if (err) { 1069993ea577SAkhil Goyal printf("\nCipher Auth Encryption case %d failed", cur_td->test_idx); 1070993ea577SAkhil Goyal err = -1; 1071993ea577SAkhil Goyal } else { 1072993ea577SAkhil Goyal printf("\nCipher Auth Encryption case %d Passed", cur_td->test_idx); 1073993ea577SAkhil Goyal err = 0; 1074993ea577SAkhil Goyal } 1075993ea577SAkhil Goyal all_err += err; 1076993ea577SAkhil Goyal } 1077993ea577SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1078993ea577SAkhil Goyal 1079993ea577SAkhil Goyal return all_err; 1080993ea577SAkhil Goyal } 1081993ea577SAkhil Goyal 1082993ea577SAkhil Goyal static int 1083993ea577SAkhil Goyal test_inline_macsec_decap_all(const void *data __rte_unused) 1084993ea577SAkhil Goyal { 1085993ea577SAkhil Goyal const struct mcs_test_vector *cur_td; 1086993ea577SAkhil Goyal struct mcs_test_opts opts = {0}; 1087993ea577SAkhil Goyal int err, all_err = 0; 1088993ea577SAkhil Goyal int i, size; 1089993ea577SAkhil Goyal 1090993ea577SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1091993ea577SAkhil Goyal opts.sa_in_use = 1; 1092993ea577SAkhil Goyal opts.nb_td = 1; 1093993ea577SAkhil Goyal opts.sectag_insert_mode = 1; 1094993ea577SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1095993ea577SAkhil Goyal 1096993ea577SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1097993ea577SAkhil Goyal for (i = 0; i < size; i++) { 1098993ea577SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1099993ea577SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1100993ea577SAkhil Goyal if (err) { 1101993ea577SAkhil Goyal printf("\nCipher Auth Decryption case %d failed", cur_td->test_idx); 1102993ea577SAkhil Goyal err = -1; 1103993ea577SAkhil Goyal } else { 1104993ea577SAkhil Goyal printf("\nCipher Auth Decryption case %d Passed", cur_td->test_idx); 1105993ea577SAkhil Goyal err = 0; 1106993ea577SAkhil Goyal } 1107993ea577SAkhil Goyal all_err += err; 1108993ea577SAkhil Goyal } 1109993ea577SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1110993ea577SAkhil Goyal 1111993ea577SAkhil Goyal return all_err; 1112993ea577SAkhil Goyal } 1113993ea577SAkhil Goyal 1114993ea577SAkhil Goyal static int 11152da0c0a7SAkhil Goyal test_inline_macsec_auth_only_all(const void *data __rte_unused) 11162da0c0a7SAkhil Goyal { 11172da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 11182da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 11192da0c0a7SAkhil Goyal int err, all_err = 0; 11202da0c0a7SAkhil Goyal int i, size; 11212da0c0a7SAkhil Goyal 11222da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 11232da0c0a7SAkhil Goyal opts.protect_frames = true; 11242da0c0a7SAkhil Goyal opts.sa_in_use = 1; 11252da0c0a7SAkhil Goyal opts.nb_td = 1; 11262da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 11272da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 11282da0c0a7SAkhil Goyal 11292da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 11302da0c0a7SAkhil Goyal 11312da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 11322da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 11332da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts); 11342da0c0a7SAkhil Goyal if (err) { 11352da0c0a7SAkhil Goyal printf("\nAuth Generate case %d failed", cur_td->test_idx); 11362da0c0a7SAkhil Goyal err = -1; 11372da0c0a7SAkhil Goyal } else { 11382da0c0a7SAkhil Goyal printf("\nAuth Generate case %d Passed", cur_td->test_idx); 11392da0c0a7SAkhil Goyal err = 0; 11402da0c0a7SAkhil Goyal } 11412da0c0a7SAkhil Goyal all_err += err; 11422da0c0a7SAkhil Goyal } 11432da0c0a7SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 11442da0c0a7SAkhil Goyal 11452da0c0a7SAkhil Goyal return all_err; 11462da0c0a7SAkhil Goyal } 11472da0c0a7SAkhil Goyal 11482da0c0a7SAkhil Goyal static int 11492da0c0a7SAkhil Goyal test_inline_macsec_verify_only_all(const void *data __rte_unused) 11502da0c0a7SAkhil Goyal { 11512da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 11522da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 11532da0c0a7SAkhil Goyal int err, all_err = 0; 11542da0c0a7SAkhil Goyal int i, size; 11552da0c0a7SAkhil Goyal 11562da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 11572da0c0a7SAkhil Goyal opts.sa_in_use = 1; 11582da0c0a7SAkhil Goyal opts.nb_td = 1; 11592da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 11602da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 11612da0c0a7SAkhil Goyal 11622da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 11632da0c0a7SAkhil Goyal 11642da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 11652da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 11662da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 11672da0c0a7SAkhil Goyal if (err) { 11682da0c0a7SAkhil Goyal printf("\nAuth Verify case %d failed", cur_td->test_idx); 11692da0c0a7SAkhil Goyal err = -1; 11702da0c0a7SAkhil Goyal } else { 11712da0c0a7SAkhil Goyal printf("\nAuth Verify case %d Passed", cur_td->test_idx); 11722da0c0a7SAkhil Goyal err = 0; 11732da0c0a7SAkhil Goyal } 11742da0c0a7SAkhil Goyal all_err += err; 11752da0c0a7SAkhil Goyal } 11762da0c0a7SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 11772da0c0a7SAkhil Goyal 11782da0c0a7SAkhil Goyal return all_err; 11792da0c0a7SAkhil Goyal } 11802da0c0a7SAkhil Goyal 11812da0c0a7SAkhil Goyal static int 11822da0c0a7SAkhil Goyal test_inline_macsec_encap_decap_all(const void *data __rte_unused) 11832da0c0a7SAkhil Goyal { 11842da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 11852da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 11862da0c0a7SAkhil Goyal int err, all_err = 0; 11872da0c0a7SAkhil Goyal int i, size; 11882da0c0a7SAkhil Goyal 11892da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 11902da0c0a7SAkhil Goyal opts.encrypt = true; 11912da0c0a7SAkhil Goyal opts.protect_frames = true; 11922da0c0a7SAkhil Goyal opts.sa_in_use = 1; 11932da0c0a7SAkhil Goyal opts.nb_td = 1; 11942da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 11952da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 11962da0c0a7SAkhil Goyal 11972da0c0a7SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 11982da0c0a7SAkhil Goyal 11992da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 12002da0c0a7SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 12012da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts); 12022da0c0a7SAkhil Goyal if (err) { 12032da0c0a7SAkhil Goyal printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx); 12042da0c0a7SAkhil Goyal err = -1; 12052da0c0a7SAkhil Goyal } else { 12062da0c0a7SAkhil Goyal printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx); 12072da0c0a7SAkhil Goyal err = 0; 12082da0c0a7SAkhil Goyal } 12092da0c0a7SAkhil Goyal all_err += err; 12102da0c0a7SAkhil Goyal } 12112da0c0a7SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 12122da0c0a7SAkhil Goyal 12132da0c0a7SAkhil Goyal return all_err; 12142da0c0a7SAkhil Goyal } 12152da0c0a7SAkhil Goyal 12162da0c0a7SAkhil Goyal 12172da0c0a7SAkhil Goyal static int 12182da0c0a7SAkhil Goyal test_inline_macsec_auth_verify_all(const void *data __rte_unused) 12192da0c0a7SAkhil Goyal { 12202da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 12212da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 12222da0c0a7SAkhil Goyal int err, all_err = 0; 12232da0c0a7SAkhil Goyal int i, size; 12242da0c0a7SAkhil Goyal 12252da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 12262da0c0a7SAkhil Goyal opts.protect_frames = true; 12272da0c0a7SAkhil Goyal opts.sa_in_use = 1; 12282da0c0a7SAkhil Goyal opts.nb_td = 1; 12292da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 12302da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 12312da0c0a7SAkhil Goyal 12322da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 12332da0c0a7SAkhil Goyal 12342da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 12352da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 12362da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts); 12372da0c0a7SAkhil Goyal if (err) { 12382da0c0a7SAkhil Goyal printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx); 12392da0c0a7SAkhil Goyal err = -1; 12402da0c0a7SAkhil Goyal } else { 12412da0c0a7SAkhil Goyal printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx); 12422da0c0a7SAkhil Goyal err = 0; 12432da0c0a7SAkhil Goyal } 12442da0c0a7SAkhil Goyal all_err += err; 12452da0c0a7SAkhil Goyal } 12462da0c0a7SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 12472da0c0a7SAkhil Goyal 12482da0c0a7SAkhil Goyal return all_err; 12492da0c0a7SAkhil Goyal } 12502da0c0a7SAkhil Goyal 12512da0c0a7SAkhil Goyal static int 1252e3d83ea4SAkhil Goyal test_inline_macsec_multi_flow(const void *data __rte_unused) 1253e3d83ea4SAkhil Goyal { 1254e3d83ea4SAkhil Goyal const struct mcs_test_vector *tv[MCS_MAX_FLOWS]; 1255e3d83ea4SAkhil Goyal struct mcs_test_vector iter[MCS_MAX_FLOWS]; 1256e3d83ea4SAkhil Goyal struct mcs_test_opts opts = {0}; 1257e3d83ea4SAkhil Goyal int i, err; 1258e3d83ea4SAkhil Goyal 1259e3d83ea4SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1260e3d83ea4SAkhil Goyal opts.encrypt = true; 1261e3d83ea4SAkhil Goyal opts.protect_frames = true; 1262e3d83ea4SAkhil Goyal opts.sa_in_use = 1; 1263e3d83ea4SAkhil Goyal opts.nb_td = MCS_MAX_FLOWS; 1264e3d83ea4SAkhil Goyal opts.sectag_insert_mode = 1; 1265e3d83ea4SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1266e3d83ea4SAkhil Goyal 1267e3d83ea4SAkhil Goyal for (i = 0; i < MCS_MAX_FLOWS; i++) { 1268e3d83ea4SAkhil Goyal memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ); 1269e3d83ea4SAkhil Goyal memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN); 1270e3d83ea4SAkhil Goyal memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data, 1271e3d83ea4SAkhil Goyal MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ); 1272e3d83ea4SAkhil Goyal memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN); 1273e3d83ea4SAkhil Goyal memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data, 1274e3d83ea4SAkhil Goyal MCS_MULTI_FLOW_TD_SECURE_DATA_SZ); 1275e3d83ea4SAkhil Goyal iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ; 1276e3d83ea4SAkhil Goyal iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ + 1277e3d83ea4SAkhil Goyal (2 * RTE_ETHER_ADDR_LEN); 1278e3d83ea4SAkhil Goyal iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ + 1279e3d83ea4SAkhil Goyal (2 * RTE_ETHER_ADDR_LEN); 1280e3d83ea4SAkhil Goyal iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128; 1281e3d83ea4SAkhil Goyal iter[i].ssci = 0x0; 1282e3d83ea4SAkhil Goyal iter[i].xpn = 0x0; 1283e3d83ea4SAkhil Goyal tv[i] = (const struct mcs_test_vector *)&iter[i]; 1284e3d83ea4SAkhil Goyal } 1285e3d83ea4SAkhil Goyal err = test_macsec(tv, MCS_ENCAP_DECAP, &opts); 1286e3d83ea4SAkhil Goyal if (err) { 1287e3d83ea4SAkhil Goyal printf("\nCipher Auth Encryption multi flow failed"); 1288e3d83ea4SAkhil Goyal err = -1; 1289e3d83ea4SAkhil Goyal } else { 1290e3d83ea4SAkhil Goyal printf("\nCipher Auth Encryption multi flow Passed"); 1291e3d83ea4SAkhil Goyal err = 0; 1292e3d83ea4SAkhil Goyal } 1293e3d83ea4SAkhil Goyal return err; 1294e3d83ea4SAkhil Goyal } 1295e3d83ea4SAkhil Goyal 1296e3d83ea4SAkhil Goyal static int 1297e67246cbSAkhil Goyal test_inline_macsec_with_vlan(const void *data __rte_unused) 1298e67246cbSAkhil Goyal { 1299e67246cbSAkhil Goyal const struct mcs_test_vector *cur_td; 1300e67246cbSAkhil Goyal struct mcs_test_opts opts = {0}; 1301e67246cbSAkhil Goyal int err, all_err = 0; 1302e67246cbSAkhil Goyal int i, size; 1303e67246cbSAkhil Goyal 1304e67246cbSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1305e67246cbSAkhil Goyal opts.protect_frames = true; 1306e67246cbSAkhil Goyal opts.sa_in_use = 1; 1307e67246cbSAkhil Goyal opts.nb_td = 1; 1308e67246cbSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1309e67246cbSAkhil Goyal 1310e67246cbSAkhil Goyal size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0])); 1311e67246cbSAkhil Goyal 1312e67246cbSAkhil Goyal for (i = 0; i < size; i++) { 1313e67246cbSAkhil Goyal cur_td = &list_mcs_vlan_vectors[i]; 1314e67246cbSAkhil Goyal if (i == 0) { 1315e67246cbSAkhil Goyal opts.sectag_insert_mode = 1; 1316e67246cbSAkhil Goyal } else if (i == 1) { 1317e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1318e67246cbSAkhil Goyal opts.nb_vlan = 1; 1319e67246cbSAkhil Goyal } else if (i == 2) { 1320e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1321e67246cbSAkhil Goyal opts.nb_vlan = 2; 1322e67246cbSAkhil Goyal } 1323e67246cbSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1324e67246cbSAkhil Goyal if (err) { 1325e67246cbSAkhil Goyal printf("\n VLAN Encap case %d failed", cur_td->test_idx); 1326e67246cbSAkhil Goyal err = -1; 1327e67246cbSAkhil Goyal } else { 1328e67246cbSAkhil Goyal printf("\n VLAN Encap case %d passed", cur_td->test_idx); 1329e67246cbSAkhil Goyal err = 0; 1330e67246cbSAkhil Goyal } 1331e67246cbSAkhil Goyal all_err += err; 1332e67246cbSAkhil Goyal } 1333e67246cbSAkhil Goyal for (i = 0; i < size; i++) { 1334e67246cbSAkhil Goyal cur_td = &list_mcs_vlan_vectors[i]; 1335e67246cbSAkhil Goyal if (i == 0) { 1336e67246cbSAkhil Goyal opts.sectag_insert_mode = 1; 1337e67246cbSAkhil Goyal } else if (i == 1) { 1338e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1339e67246cbSAkhil Goyal opts.nb_vlan = 1; 1340e67246cbSAkhil Goyal } else if (i == 2) { 1341e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1342e67246cbSAkhil Goyal opts.nb_vlan = 2; 1343e67246cbSAkhil Goyal } 1344e67246cbSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1345e67246cbSAkhil Goyal if (err) { 1346e67246cbSAkhil Goyal printf("\n VLAN Decap case %d failed", cur_td->test_idx); 1347e67246cbSAkhil Goyal err = -1; 1348e67246cbSAkhil Goyal } else { 1349e67246cbSAkhil Goyal printf("\n VLAN Decap case %d passed", cur_td->test_idx); 1350e67246cbSAkhil Goyal err = 0; 1351e67246cbSAkhil Goyal } 1352e67246cbSAkhil Goyal all_err += err; 1353e67246cbSAkhil Goyal } 1354e67246cbSAkhil Goyal 1355e67246cbSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, (2 * size) + all_err, -all_err); 1356e67246cbSAkhil Goyal return all_err; 1357e67246cbSAkhil Goyal } 1358e67246cbSAkhil Goyal 1359e67246cbSAkhil Goyal static int 13607c3b1decSAkhil Goyal test_inline_macsec_pkt_drop(const void *data __rte_unused) 13617c3b1decSAkhil Goyal { 13627c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 13637c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 13647c3b1decSAkhil Goyal int err, all_err = 0; 13657c3b1decSAkhil Goyal int i, size; 13667c3b1decSAkhil Goyal 13677c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 13687c3b1decSAkhil Goyal opts.encrypt = true; 13697c3b1decSAkhil Goyal opts.protect_frames = true; 13707c3b1decSAkhil Goyal opts.sa_in_use = 1; 13717c3b1decSAkhil Goyal opts.nb_td = 1; 13727c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 13737c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 13747c3b1decSAkhil Goyal 13757c3b1decSAkhil Goyal size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0])); 13767c3b1decSAkhil Goyal 13777c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 13787c3b1decSAkhil Goyal cur_td = &list_mcs_err_cipher_vectors[i]; 13797c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 13807c3b1decSAkhil Goyal if (err) { 13817c3b1decSAkhil Goyal printf("\nPacket drop case %d passed", cur_td->test_idx); 13827c3b1decSAkhil Goyal err = 0; 13837c3b1decSAkhil Goyal } else { 13847c3b1decSAkhil Goyal printf("\nPacket drop case %d failed", cur_td->test_idx); 13857c3b1decSAkhil Goyal err = -1; 13867c3b1decSAkhil Goyal } 13877c3b1decSAkhil Goyal all_err += err; 13887c3b1decSAkhil Goyal } 13897c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 13907c3b1decSAkhil Goyal 13917c3b1decSAkhil Goyal return all_err; 13927c3b1decSAkhil Goyal } 13937c3b1decSAkhil Goyal 13947c3b1decSAkhil Goyal static int 13957c3b1decSAkhil Goyal test_inline_macsec_untagged_rx(const void *data __rte_unused) 13967c3b1decSAkhil Goyal { 13977c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 13987c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 13997c3b1decSAkhil Goyal int err, all_err = 0; 14007c3b1decSAkhil Goyal int i, size; 14017c3b1decSAkhil Goyal 14027c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14037c3b1decSAkhil Goyal opts.sa_in_use = 1; 14047c3b1decSAkhil Goyal opts.nb_td = 1; 14057c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 14067c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14077c3b1decSAkhil Goyal opts.check_untagged_rx = 1; 14087c3b1decSAkhil Goyal 14097c3b1decSAkhil Goyal size = (sizeof(list_mcs_untagged_cipher_vectors) / 14107c3b1decSAkhil Goyal sizeof((list_mcs_untagged_cipher_vectors)[0])); 14117c3b1decSAkhil Goyal 14127c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 14137c3b1decSAkhil Goyal cur_td = &list_mcs_untagged_cipher_vectors[i]; 14147c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 14157c3b1decSAkhil Goyal if (err) 14167c3b1decSAkhil Goyal err = 0; 14177c3b1decSAkhil Goyal else 14187c3b1decSAkhil Goyal err = -1; 14197c3b1decSAkhil Goyal 14207c3b1decSAkhil Goyal all_err += err; 14217c3b1decSAkhil Goyal } 14227c3b1decSAkhil Goyal 14237c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD; 14247c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 14257c3b1decSAkhil Goyal cur_td = &list_mcs_untagged_cipher_vectors[i]; 14267c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 14277c3b1decSAkhil Goyal if (err) 14287c3b1decSAkhil Goyal err = 0; 14297c3b1decSAkhil Goyal else 14307c3b1decSAkhil Goyal err = -1; 14317c3b1decSAkhil Goyal 14327c3b1decSAkhil Goyal all_err += err; 14337c3b1decSAkhil Goyal } 14347c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 14357c3b1decSAkhil Goyal 14367c3b1decSAkhil Goyal return all_err; 14377c3b1decSAkhil Goyal } 14387c3b1decSAkhil Goyal 14397c3b1decSAkhil Goyal static int 14407c3b1decSAkhil Goyal test_inline_macsec_bad_tag_rx(const void *data __rte_unused) 14417c3b1decSAkhil Goyal { 14427c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 14437c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 14447c3b1decSAkhil Goyal int err, all_err = 0; 14457c3b1decSAkhil Goyal int i, size; 14467c3b1decSAkhil Goyal 14477c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14487c3b1decSAkhil Goyal opts.protect_frames = true; 14497c3b1decSAkhil Goyal opts.sa_in_use = 1; 14507c3b1decSAkhil Goyal opts.nb_td = 1; 14517c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 14527c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14537c3b1decSAkhil Goyal opts.check_bad_tag_cnt = 1; 14547c3b1decSAkhil Goyal 14557c3b1decSAkhil Goyal size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0])); 14567c3b1decSAkhil Goyal 14577c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 14587c3b1decSAkhil Goyal cur_td = &list_mcs_bad_tag_vectors[i]; 14597c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 14607c3b1decSAkhil Goyal if (err) 14617c3b1decSAkhil Goyal err = -1; 14627c3b1decSAkhil Goyal else 14637c3b1decSAkhil Goyal err = 0; 14647c3b1decSAkhil Goyal 14657c3b1decSAkhil Goyal all_err += err; 14667c3b1decSAkhil Goyal } 14677c3b1decSAkhil Goyal 14687c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 14697c3b1decSAkhil Goyal 14707c3b1decSAkhil Goyal return all_err; 14717c3b1decSAkhil Goyal } 14727c3b1decSAkhil Goyal 14737c3b1decSAkhil Goyal static int 14747c3b1decSAkhil Goyal test_inline_macsec_sa_not_in_use(const void *data __rte_unused) 14757c3b1decSAkhil Goyal { 14767c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 14777c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 14787c3b1decSAkhil Goyal int err, all_err = 0; 14797c3b1decSAkhil Goyal int i, size; 14807c3b1decSAkhil Goyal 14817c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14827c3b1decSAkhil Goyal opts.protect_frames = true; 14837c3b1decSAkhil Goyal opts.sa_in_use = 0; 14847c3b1decSAkhil Goyal opts.nb_td = 1; 14857c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 14867c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14877c3b1decSAkhil Goyal opts.check_sa_not_in_use = 1; 14887c3b1decSAkhil Goyal 14897c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 14907c3b1decSAkhil Goyal 14917c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 14927c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 14937c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 14947c3b1decSAkhil Goyal if (err) 14957c3b1decSAkhil Goyal err = -1; 14967c3b1decSAkhil Goyal else 14977c3b1decSAkhil Goyal err = 0; 14987c3b1decSAkhil Goyal 14997c3b1decSAkhil Goyal all_err += err; 15007c3b1decSAkhil Goyal } 15017c3b1decSAkhil Goyal 15027c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 15037c3b1decSAkhil Goyal 15047c3b1decSAkhil Goyal return all_err; 15057c3b1decSAkhil Goyal } 15067c3b1decSAkhil Goyal 15077c3b1decSAkhil Goyal static int 1508164757d6SAkhil Goyal test_inline_macsec_decap_stats(const void *data __rte_unused) 1509164757d6SAkhil Goyal { 1510164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1511164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1512164757d6SAkhil Goyal int err, all_err = 0; 1513164757d6SAkhil Goyal int i, size; 1514164757d6SAkhil Goyal 1515164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1516164757d6SAkhil Goyal opts.protect_frames = true; 1517164757d6SAkhil Goyal opts.sa_in_use = 1; 1518164757d6SAkhil Goyal opts.nb_td = 1; 1519164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1520164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1521164757d6SAkhil Goyal opts.check_decap_stats = 1; 1522164757d6SAkhil Goyal 1523164757d6SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1524164757d6SAkhil Goyal 1525164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1526164757d6SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1527164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1528164757d6SAkhil Goyal if (err) { 1529164757d6SAkhil Goyal printf("\nDecap stats case %d failed", cur_td->test_idx); 1530164757d6SAkhil Goyal err = -1; 1531164757d6SAkhil Goyal } else { 1532164757d6SAkhil Goyal printf("\nDecap stats case %d passed", cur_td->test_idx); 1533164757d6SAkhil Goyal err = 0; 1534164757d6SAkhil Goyal } 1535164757d6SAkhil Goyal all_err += err; 1536164757d6SAkhil Goyal } 1537164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1538164757d6SAkhil Goyal 1539164757d6SAkhil Goyal return all_err; 1540164757d6SAkhil Goyal } 1541164757d6SAkhil Goyal 1542164757d6SAkhil Goyal static int 1543164757d6SAkhil Goyal test_inline_macsec_verify_only_stats(const void *data __rte_unused) 1544164757d6SAkhil Goyal { 1545164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1546164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1547164757d6SAkhil Goyal int err, all_err = 0; 1548164757d6SAkhil Goyal int i, size; 1549164757d6SAkhil Goyal 1550164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1551164757d6SAkhil Goyal opts.protect_frames = true; 1552164757d6SAkhil Goyal opts.sa_in_use = 1; 1553164757d6SAkhil Goyal opts.nb_td = 1; 1554164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1555164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1556164757d6SAkhil Goyal opts.check_verify_only_stats = 1; 1557164757d6SAkhil Goyal 1558164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 1559164757d6SAkhil Goyal 1560164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1561164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 1562164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 1563164757d6SAkhil Goyal if (err) { 1564164757d6SAkhil Goyal printf("\nVerify only stats case %d failed", cur_td->test_idx); 1565164757d6SAkhil Goyal err = -1; 1566164757d6SAkhil Goyal } else { 1567164757d6SAkhil Goyal printf("\nVerify only stats case %d Passed", cur_td->test_idx); 1568164757d6SAkhil Goyal err = 0; 1569164757d6SAkhil Goyal } 1570164757d6SAkhil Goyal all_err += err; 1571164757d6SAkhil Goyal } 1572164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1573164757d6SAkhil Goyal 1574164757d6SAkhil Goyal return all_err; 1575164757d6SAkhil Goyal } 1576164757d6SAkhil Goyal 1577164757d6SAkhil Goyal static int 1578164757d6SAkhil Goyal test_inline_macsec_pkts_invalid_stats(const void *data __rte_unused) 1579164757d6SAkhil Goyal { 1580164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1581164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1582164757d6SAkhil Goyal int err, all_err = 0; 1583164757d6SAkhil Goyal int i, size; 1584164757d6SAkhil Goyal 1585164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1586164757d6SAkhil Goyal opts.protect_frames = true; 1587164757d6SAkhil Goyal opts.sa_in_use = 1; 1588164757d6SAkhil Goyal opts.nb_td = 1; 1589164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1590164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1591164757d6SAkhil Goyal 1592164757d6SAkhil Goyal size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0])); 1593164757d6SAkhil Goyal 1594164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1595164757d6SAkhil Goyal cur_td = &list_mcs_err_cipher_vectors[i]; 1596164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1597164757d6SAkhil Goyal if (err) 1598164757d6SAkhil Goyal err = 0; 1599164757d6SAkhil Goyal else 1600164757d6SAkhil Goyal err = -1; 1601164757d6SAkhil Goyal 1602164757d6SAkhil Goyal all_err += err; 1603164757d6SAkhil Goyal } 1604164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1605164757d6SAkhil Goyal return all_err; 1606164757d6SAkhil Goyal } 1607164757d6SAkhil Goyal 1608164757d6SAkhil Goyal static int 1609164757d6SAkhil Goyal test_inline_macsec_pkts_unchecked_stats(const void *data __rte_unused) 1610164757d6SAkhil Goyal { 1611164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1612164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1613164757d6SAkhil Goyal int err, all_err = 0; 1614164757d6SAkhil Goyal int i, size; 1615164757d6SAkhil Goyal 1616164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE; 1617164757d6SAkhil Goyal opts.protect_frames = true; 1618164757d6SAkhil Goyal opts.sa_in_use = 1; 1619164757d6SAkhil Goyal opts.nb_td = 1; 1620164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1621164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1622164757d6SAkhil Goyal opts.check_pkts_unchecked_stats = 1; 1623164757d6SAkhil Goyal 1624164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 1625164757d6SAkhil Goyal 1626164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1627164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 1628164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 1629164757d6SAkhil Goyal if (err) 1630164757d6SAkhil Goyal err = -1; 1631164757d6SAkhil Goyal else 1632164757d6SAkhil Goyal err = 0; 1633164757d6SAkhil Goyal 1634164757d6SAkhil Goyal all_err += err; 1635164757d6SAkhil Goyal } 1636164757d6SAkhil Goyal 1637164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1638164757d6SAkhil Goyal return all_err; 1639164757d6SAkhil Goyal } 1640164757d6SAkhil Goyal 1641164757d6SAkhil Goyal static int 16427c3b1decSAkhil Goyal test_inline_macsec_out_pkts_untagged(const void *data __rte_unused) 16437c3b1decSAkhil Goyal { 16447c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 16457c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 16467c3b1decSAkhil Goyal int err, all_err = 0; 16477c3b1decSAkhil Goyal int i, size; 16487c3b1decSAkhil Goyal 16497c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 16507c3b1decSAkhil Goyal opts.encrypt = false; 16517c3b1decSAkhil Goyal opts.protect_frames = false; 16527c3b1decSAkhil Goyal opts.sa_in_use = 1; 16537c3b1decSAkhil Goyal opts.nb_td = 1; 16547c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 16557c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 16567c3b1decSAkhil Goyal opts.check_out_pkts_untagged = 1; 16577c3b1decSAkhil Goyal 16587c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 16597c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 16607c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 16617c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 16627c3b1decSAkhil Goyal if (err) 16637c3b1decSAkhil Goyal err = -1; 16647c3b1decSAkhil Goyal else 16657c3b1decSAkhil Goyal err = 0; 16667c3b1decSAkhil Goyal 16677c3b1decSAkhil Goyal all_err += err; 16687c3b1decSAkhil Goyal } 16697c3b1decSAkhil Goyal 16707c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 16717c3b1decSAkhil Goyal return all_err; 16727c3b1decSAkhil Goyal } 16737c3b1decSAkhil Goyal 16747c3b1decSAkhil Goyal static int 16757c3b1decSAkhil Goyal test_inline_macsec_out_pkts_toolong(const void *data __rte_unused) 16767c3b1decSAkhil Goyal { 16777c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 16787c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 16797c3b1decSAkhil Goyal int err, all_err = 0; 16807c3b1decSAkhil Goyal int i, size; 16817c3b1decSAkhil Goyal 16827c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD; 16837c3b1decSAkhil Goyal opts.encrypt = true; 16847c3b1decSAkhil Goyal opts.protect_frames = true; 16857c3b1decSAkhil Goyal opts.sa_in_use = 1; 16867c3b1decSAkhil Goyal opts.nb_td = 1; 16877c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 16887c3b1decSAkhil Goyal opts.mtu = 50; 16897c3b1decSAkhil Goyal opts.check_out_pkts_toolong = 1; 16907c3b1decSAkhil Goyal 16917c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 16927c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 16937c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 16947c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 16957c3b1decSAkhil Goyal if (err) 16967c3b1decSAkhil Goyal err = -1; 16977c3b1decSAkhil Goyal else 16987c3b1decSAkhil Goyal err = 0; 16997c3b1decSAkhil Goyal 17007c3b1decSAkhil Goyal all_err += err; 17017c3b1decSAkhil Goyal } 17027c3b1decSAkhil Goyal 17037c3b1decSAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 17047c3b1decSAkhil Goyal return all_err; 17057c3b1decSAkhil Goyal } 17067c3b1decSAkhil Goyal 17077c3b1decSAkhil Goyal static int 1708164757d6SAkhil Goyal test_inline_macsec_encap_stats(const void *data __rte_unused) 1709164757d6SAkhil Goyal { 1710164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1711164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1712164757d6SAkhil Goyal int err, all_err = 0; 1713164757d6SAkhil Goyal int i, size; 1714164757d6SAkhil Goyal 1715164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1716164757d6SAkhil Goyal opts.encrypt = true; 1717164757d6SAkhil Goyal opts.protect_frames = true; 1718164757d6SAkhil Goyal opts.sa_in_use = 1; 1719164757d6SAkhil Goyal opts.nb_td = 1; 1720164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1721164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1722164757d6SAkhil Goyal opts.check_encap_stats = 1; 1723164757d6SAkhil Goyal 1724164757d6SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1725164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1726164757d6SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1727164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1728164757d6SAkhil Goyal if (err) 1729164757d6SAkhil Goyal err = -1; 1730164757d6SAkhil Goyal else 1731164757d6SAkhil Goyal err = 0; 1732164757d6SAkhil Goyal all_err += err; 1733164757d6SAkhil Goyal } 1734164757d6SAkhil Goyal 1735164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1736164757d6SAkhil Goyal return all_err; 1737164757d6SAkhil Goyal } 1738164757d6SAkhil Goyal 1739164757d6SAkhil Goyal static int 1740164757d6SAkhil Goyal test_inline_macsec_auth_only_stats(const void *data __rte_unused) 1741164757d6SAkhil Goyal { 1742164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1743164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1744164757d6SAkhil Goyal int err, all_err = 0; 1745164757d6SAkhil Goyal int i, size; 1746164757d6SAkhil Goyal 1747164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1748164757d6SAkhil Goyal opts.protect_frames = true; 1749164757d6SAkhil Goyal opts.sa_in_use = 1; 1750164757d6SAkhil Goyal opts.nb_td = 1; 1751164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1752164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1753164757d6SAkhil Goyal opts.check_auth_only_stats = 1; 1754164757d6SAkhil Goyal 1755164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 1756164757d6SAkhil Goyal 1757164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1758164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 1759164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts); 1760164757d6SAkhil Goyal if (err) 1761164757d6SAkhil Goyal err = -1; 1762164757d6SAkhil Goyal else 1763164757d6SAkhil Goyal err = 0; 1764164757d6SAkhil Goyal all_err += err; 1765164757d6SAkhil Goyal } 1766164757d6SAkhil Goyal 1767164757d6SAkhil Goyal printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1768164757d6SAkhil Goyal return all_err; 1769164757d6SAkhil Goyal } 1770164757d6SAkhil Goyal 1771164757d6SAkhil Goyal static int 1772*339b9354SAnkur Dwivedi test_inline_macsec_interrupts_all(const void *data __rte_unused) 1773*339b9354SAnkur Dwivedi { 1774*339b9354SAnkur Dwivedi struct mcs_err_vector err_vector = {0}; 1775*339b9354SAnkur Dwivedi const struct mcs_test_vector *cur_td; 1776*339b9354SAnkur Dwivedi struct mcs_test_opts opts = {0}; 1777*339b9354SAnkur Dwivedi int i, size; 1778*339b9354SAnkur Dwivedi int err, all_err = 0; 1779*339b9354SAnkur Dwivedi enum rte_eth_event_macsec_subtype subtype[] = { 1780*339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1, 1781*339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1, 1782*339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48, 1783*339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1, 1784*339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1, 1785*339b9354SAnkur Dwivedi }; 1786*339b9354SAnkur Dwivedi 1787*339b9354SAnkur Dwivedi opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1788*339b9354SAnkur Dwivedi opts.protect_frames = true; 1789*339b9354SAnkur Dwivedi opts.sa_in_use = 1; 1790*339b9354SAnkur Dwivedi opts.nb_td = 1; 1791*339b9354SAnkur Dwivedi opts.sectag_insert_mode = 1; 1792*339b9354SAnkur Dwivedi opts.mtu = RTE_ETHER_MTU; 1793*339b9354SAnkur Dwivedi opts.check_sectag_interrupts = 1; 1794*339b9354SAnkur Dwivedi 1795*339b9354SAnkur Dwivedi err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN; 1796*339b9354SAnkur Dwivedi err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN; 1797*339b9354SAnkur Dwivedi rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC, 1798*339b9354SAnkur Dwivedi test_macsec_event_callback, &err_vector); 1799*339b9354SAnkur Dwivedi 1800*339b9354SAnkur Dwivedi size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0])); 1801*339b9354SAnkur Dwivedi 1802*339b9354SAnkur Dwivedi for (i = 0; i < size; i++) { 1803*339b9354SAnkur Dwivedi cur_td = &list_mcs_intr_test_vectors[i]; 1804*339b9354SAnkur Dwivedi err = test_macsec(&cur_td, MCS_DECAP, &opts); 1805*339b9354SAnkur Dwivedi if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) && 1806*339b9354SAnkur Dwivedi (err_vector.event_subtype == subtype[i])) { 1807*339b9354SAnkur Dwivedi printf("\nSectag val err interrupt test case %d passed", 1808*339b9354SAnkur Dwivedi cur_td->test_idx); 1809*339b9354SAnkur Dwivedi err = 0; 1810*339b9354SAnkur Dwivedi } else { 1811*339b9354SAnkur Dwivedi printf("\nSectag val err interrupt test case %d failed", 1812*339b9354SAnkur Dwivedi cur_td->test_idx); 1813*339b9354SAnkur Dwivedi err = -1; 1814*339b9354SAnkur Dwivedi } 1815*339b9354SAnkur Dwivedi all_err += err; 1816*339b9354SAnkur Dwivedi } 1817*339b9354SAnkur Dwivedi rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC, 1818*339b9354SAnkur Dwivedi test_macsec_event_callback, &err_vector); 1819*339b9354SAnkur Dwivedi 1820*339b9354SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err); 1821*339b9354SAnkur Dwivedi return all_err; 1822*339b9354SAnkur Dwivedi } 1823*339b9354SAnkur Dwivedi 1824*339b9354SAnkur Dwivedi static int 1825993ea577SAkhil Goyal ut_setup_inline_macsec(void) 1826993ea577SAkhil Goyal { 1827993ea577SAkhil Goyal int ret; 1828993ea577SAkhil Goyal 1829993ea577SAkhil Goyal /* Start device */ 1830993ea577SAkhil Goyal ret = rte_eth_dev_start(port_id); 1831993ea577SAkhil Goyal if (ret < 0) { 1832993ea577SAkhil Goyal printf("rte_eth_dev_start: err=%d, port=%d\n", 1833993ea577SAkhil Goyal ret, port_id); 1834993ea577SAkhil Goyal return ret; 1835993ea577SAkhil Goyal } 1836993ea577SAkhil Goyal /* always enable promiscuous */ 1837993ea577SAkhil Goyal ret = rte_eth_promiscuous_enable(port_id); 1838993ea577SAkhil Goyal if (ret != 0) { 1839993ea577SAkhil Goyal printf("rte_eth_promiscuous_enable: err=%s, port=%d\n", 1840993ea577SAkhil Goyal rte_strerror(-ret), port_id); 1841993ea577SAkhil Goyal return ret; 1842993ea577SAkhil Goyal } 1843993ea577SAkhil Goyal 1844993ea577SAkhil Goyal check_all_ports_link_status(1, RTE_PORT_ALL); 1845993ea577SAkhil Goyal 1846993ea577SAkhil Goyal return 0; 1847993ea577SAkhil Goyal } 1848993ea577SAkhil Goyal 1849993ea577SAkhil Goyal static void 1850993ea577SAkhil Goyal ut_teardown_inline_macsec(void) 1851993ea577SAkhil Goyal { 1852993ea577SAkhil Goyal uint16_t portid; 1853993ea577SAkhil Goyal int ret; 1854993ea577SAkhil Goyal 1855993ea577SAkhil Goyal /* port tear down */ 1856993ea577SAkhil Goyal RTE_ETH_FOREACH_DEV(portid) { 1857993ea577SAkhil Goyal ret = rte_eth_dev_stop(portid); 1858993ea577SAkhil Goyal if (ret != 0) 1859993ea577SAkhil Goyal printf("rte_eth_dev_stop: err=%s, port=%u\n", 1860993ea577SAkhil Goyal rte_strerror(-ret), portid); 1861993ea577SAkhil Goyal 1862993ea577SAkhil Goyal } 1863993ea577SAkhil Goyal } 1864993ea577SAkhil Goyal 1865993ea577SAkhil Goyal static int 1866993ea577SAkhil Goyal inline_macsec_testsuite_setup(void) 1867993ea577SAkhil Goyal { 1868993ea577SAkhil Goyal uint16_t nb_rxd; 1869993ea577SAkhil Goyal uint16_t nb_txd; 1870993ea577SAkhil Goyal uint16_t nb_ports; 1871993ea577SAkhil Goyal int ret; 1872993ea577SAkhil Goyal uint16_t nb_rx_queue = 1, nb_tx_queue = 1; 1873993ea577SAkhil Goyal 1874993ea577SAkhil Goyal printf("Start inline MACsec test.\n"); 1875993ea577SAkhil Goyal 1876993ea577SAkhil Goyal nb_ports = rte_eth_dev_count_avail(); 1877993ea577SAkhil Goyal if (nb_ports < NB_ETHPORTS_USED) { 1878993ea577SAkhil Goyal printf("At least %u port(s) used for test\n", 1879993ea577SAkhil Goyal NB_ETHPORTS_USED); 1880993ea577SAkhil Goyal return TEST_SKIPPED; 1881993ea577SAkhil Goyal } 1882993ea577SAkhil Goyal 1883993ea577SAkhil Goyal ret = init_mempools(NB_MBUF); 1884993ea577SAkhil Goyal if (ret) 1885993ea577SAkhil Goyal return ret; 1886993ea577SAkhil Goyal 1887993ea577SAkhil Goyal if (tx_pkts_burst == NULL) { 1888993ea577SAkhil Goyal tx_pkts_burst = (struct rte_mbuf **)rte_calloc("tx_buff", 1889993ea577SAkhil Goyal MAX_TRAFFIC_BURST, 1890993ea577SAkhil Goyal sizeof(void *), 1891993ea577SAkhil Goyal RTE_CACHE_LINE_SIZE); 1892993ea577SAkhil Goyal if (!tx_pkts_burst) 1893993ea577SAkhil Goyal return TEST_FAILED; 1894993ea577SAkhil Goyal 1895993ea577SAkhil Goyal rx_pkts_burst = (struct rte_mbuf **)rte_calloc("rx_buff", 1896993ea577SAkhil Goyal MAX_TRAFFIC_BURST, 1897993ea577SAkhil Goyal sizeof(void *), 1898993ea577SAkhil Goyal RTE_CACHE_LINE_SIZE); 1899993ea577SAkhil Goyal if (!rx_pkts_burst) 1900993ea577SAkhil Goyal return TEST_FAILED; 1901993ea577SAkhil Goyal } 1902993ea577SAkhil Goyal 1903993ea577SAkhil Goyal printf("Generate %d packets\n", MAX_TRAFFIC_BURST); 1904993ea577SAkhil Goyal 1905993ea577SAkhil Goyal nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 1906993ea577SAkhil Goyal nb_txd = RTE_TEST_TX_DESC_DEFAULT; 1907993ea577SAkhil Goyal 1908993ea577SAkhil Goyal /* configuring port 0 for the test is enough */ 1909993ea577SAkhil Goyal port_id = 0; 1910993ea577SAkhil Goyal /* port configure */ 1911993ea577SAkhil Goyal ret = rte_eth_dev_configure(port_id, nb_rx_queue, 1912993ea577SAkhil Goyal nb_tx_queue, &port_conf); 1913993ea577SAkhil Goyal if (ret < 0) { 1914993ea577SAkhil Goyal printf("Cannot configure device: err=%d, port=%d\n", 1915993ea577SAkhil Goyal ret, port_id); 1916993ea577SAkhil Goyal return ret; 1917993ea577SAkhil Goyal } 1918993ea577SAkhil Goyal ret = rte_eth_macaddr_get(port_id, &ports_eth_addr[port_id]); 1919993ea577SAkhil Goyal if (ret < 0) { 1920993ea577SAkhil Goyal printf("Cannot get mac address: err=%d, port=%d\n", 1921993ea577SAkhil Goyal ret, port_id); 1922993ea577SAkhil Goyal return ret; 1923993ea577SAkhil Goyal } 1924993ea577SAkhil Goyal printf("Port %u ", port_id); 1925993ea577SAkhil Goyal print_ethaddr("Address:", &ports_eth_addr[port_id]); 1926993ea577SAkhil Goyal printf("\n"); 1927993ea577SAkhil Goyal 1928993ea577SAkhil Goyal /* tx queue setup */ 1929993ea577SAkhil Goyal ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd, 1930993ea577SAkhil Goyal SOCKET_ID_ANY, &tx_conf); 1931993ea577SAkhil Goyal if (ret < 0) { 1932993ea577SAkhil Goyal printf("rte_eth_tx_queue_setup: err=%d, port=%d\n", 1933993ea577SAkhil Goyal ret, port_id); 1934993ea577SAkhil Goyal return ret; 1935993ea577SAkhil Goyal } 1936993ea577SAkhil Goyal /* rx queue steup */ 1937993ea577SAkhil Goyal ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd, SOCKET_ID_ANY, 1938993ea577SAkhil Goyal &rx_conf, mbufpool); 1939993ea577SAkhil Goyal if (ret < 0) { 1940993ea577SAkhil Goyal printf("rte_eth_rx_queue_setup: err=%d, port=%d\n", 1941993ea577SAkhil Goyal ret, port_id); 1942993ea577SAkhil Goyal return ret; 1943993ea577SAkhil Goyal } 1944993ea577SAkhil Goyal 1945993ea577SAkhil Goyal return 0; 1946993ea577SAkhil Goyal } 1947993ea577SAkhil Goyal 1948993ea577SAkhil Goyal static void 1949993ea577SAkhil Goyal inline_macsec_testsuite_teardown(void) 1950993ea577SAkhil Goyal { 1951993ea577SAkhil Goyal uint16_t portid; 1952993ea577SAkhil Goyal int ret; 1953993ea577SAkhil Goyal 1954993ea577SAkhil Goyal /* port tear down */ 1955993ea577SAkhil Goyal RTE_ETH_FOREACH_DEV(portid) { 1956993ea577SAkhil Goyal ret = rte_eth_dev_reset(portid); 1957993ea577SAkhil Goyal if (ret != 0) 1958993ea577SAkhil Goyal printf("rte_eth_dev_reset: err=%s, port=%u\n", 1959993ea577SAkhil Goyal rte_strerror(-ret), port_id); 1960993ea577SAkhil Goyal } 1961993ea577SAkhil Goyal rte_free(tx_pkts_burst); 1962993ea577SAkhil Goyal rte_free(rx_pkts_burst); 1963993ea577SAkhil Goyal } 1964993ea577SAkhil Goyal 1965993ea577SAkhil Goyal 1966993ea577SAkhil Goyal static struct unit_test_suite inline_macsec_testsuite = { 1967993ea577SAkhil Goyal .suite_name = "Inline MACsec Ethernet Device Unit Test Suite", 1968993ea577SAkhil Goyal .unit_test_cases = { 1969993ea577SAkhil Goyal TEST_CASE_NAMED_ST( 1970e3d83ea4SAkhil Goyal "MACsec Encap + decap Multi flow", 1971e3d83ea4SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 1972e3d83ea4SAkhil Goyal test_inline_macsec_multi_flow), 1973e3d83ea4SAkhil Goyal TEST_CASE_NAMED_ST( 1974993ea577SAkhil Goyal "MACsec encap(Cipher+Auth) known vector", 1975993ea577SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 1976993ea577SAkhil Goyal test_inline_macsec_encap_all), 1977993ea577SAkhil Goyal TEST_CASE_NAMED_ST( 1978993ea577SAkhil Goyal "MACsec decap(De-cipher+verify) known vector", 1979993ea577SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 1980993ea577SAkhil Goyal test_inline_macsec_decap_all), 19812da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 19822da0c0a7SAkhil Goyal "MACsec auth only known vector", 19832da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 19842da0c0a7SAkhil Goyal test_inline_macsec_auth_only_all), 19852da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 19862da0c0a7SAkhil Goyal "MACsec verify only known vector", 19872da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 19882da0c0a7SAkhil Goyal test_inline_macsec_verify_only_all), 19892da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 19902da0c0a7SAkhil Goyal "MACsec encap + decap known vector", 19912da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 19922da0c0a7SAkhil Goyal test_inline_macsec_encap_decap_all), 19932da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 19942da0c0a7SAkhil Goyal "MACsec auth + verify known vector", 19952da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 19962da0c0a7SAkhil Goyal test_inline_macsec_auth_verify_all), 1997e67246cbSAkhil Goyal TEST_CASE_NAMED_ST( 1998e67246cbSAkhil Goyal "MACsec Encap and decap with VLAN", 1999e67246cbSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2000e67246cbSAkhil Goyal test_inline_macsec_with_vlan), 20017c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 20027c3b1decSAkhil Goyal "MACsec packet drop", 20037c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20047c3b1decSAkhil Goyal test_inline_macsec_pkt_drop), 20057c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 20067c3b1decSAkhil Goyal "MACsec untagged Rx", 20077c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20087c3b1decSAkhil Goyal test_inline_macsec_untagged_rx), 20097c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 20107c3b1decSAkhil Goyal "MACsec bad tag Rx", 20117c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20127c3b1decSAkhil Goyal test_inline_macsec_bad_tag_rx), 20137c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 20147c3b1decSAkhil Goyal "MACsec SA not in use", 20157c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20167c3b1decSAkhil Goyal test_inline_macsec_sa_not_in_use), 20177c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 2018164757d6SAkhil Goyal "MACsec decap stats", 2019164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2020164757d6SAkhil Goyal test_inline_macsec_decap_stats), 2021164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2022164757d6SAkhil Goyal "MACsec verify only stats", 2023164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2024164757d6SAkhil Goyal test_inline_macsec_verify_only_stats), 2025164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2026164757d6SAkhil Goyal "MACsec pkts invalid stats", 2027164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2028164757d6SAkhil Goyal test_inline_macsec_pkts_invalid_stats), 2029164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2030164757d6SAkhil Goyal "MACsec pkts unchecked stats", 2031164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2032164757d6SAkhil Goyal test_inline_macsec_pkts_unchecked_stats), 2033164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 20347c3b1decSAkhil Goyal "MACsec out pkts untagged", 20357c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20367c3b1decSAkhil Goyal test_inline_macsec_out_pkts_untagged), 20377c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 20387c3b1decSAkhil Goyal "MACsec out pkts too long", 20397c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 20407c3b1decSAkhil Goyal test_inline_macsec_out_pkts_toolong), 2041164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2042164757d6SAkhil Goyal "MACsec Encap stats", 2043164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2044164757d6SAkhil Goyal test_inline_macsec_encap_stats), 2045164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2046164757d6SAkhil Goyal "MACsec auth only stats", 2047164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2048164757d6SAkhil Goyal test_inline_macsec_auth_only_stats), 2049*339b9354SAnkur Dwivedi TEST_CASE_NAMED_ST( 2050*339b9354SAnkur Dwivedi "MACsec interrupts all", 2051*339b9354SAnkur Dwivedi ut_setup_inline_macsec, ut_teardown_inline_macsec, 2052*339b9354SAnkur Dwivedi test_inline_macsec_interrupts_all), 2053993ea577SAkhil Goyal 2054993ea577SAkhil Goyal TEST_CASES_END() /**< NULL terminate unit test array */ 2055993ea577SAkhil Goyal }, 2056993ea577SAkhil Goyal }; 2057993ea577SAkhil Goyal 2058993ea577SAkhil Goyal static int 2059993ea577SAkhil Goyal test_inline_macsec(void) 2060993ea577SAkhil Goyal { 2061993ea577SAkhil Goyal inline_macsec_testsuite.setup = inline_macsec_testsuite_setup; 2062993ea577SAkhil Goyal inline_macsec_testsuite.teardown = inline_macsec_testsuite_teardown; 2063993ea577SAkhil Goyal return unit_test_suite_runner(&inline_macsec_testsuite); 2064993ea577SAkhil Goyal } 2065993ea577SAkhil Goyal 2066993ea577SAkhil Goyal #endif /* !RTE_EXEC_ENV_WINDOWS */ 2067993ea577SAkhil Goyal 2068993ea577SAkhil Goyal REGISTER_TEST_COMMAND(inline_macsec_autotest, test_inline_macsec); 2069