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; 632a3a153eSAnkur Dwivedi const struct mcs_test_vector *ar_td[3]; 64993ea577SAkhil Goyal bool dump_all_stats; 65993ea577SAkhil Goyal uint8_t check_untagged_rx; 66993ea577SAkhil Goyal uint8_t check_bad_tag_cnt; 67993ea577SAkhil Goyal uint8_t check_sa_not_in_use; 68993ea577SAkhil Goyal uint8_t check_decap_stats; 69993ea577SAkhil Goyal uint8_t check_verify_only_stats; 70993ea577SAkhil Goyal uint8_t check_pkts_invalid_stats; 71993ea577SAkhil Goyal uint8_t check_pkts_unchecked_stats; 72993ea577SAkhil Goyal uint8_t check_out_pkts_untagged; 73993ea577SAkhil Goyal uint8_t check_out_pkts_toolong; 74993ea577SAkhil Goyal uint8_t check_encap_stats; 75993ea577SAkhil Goyal uint8_t check_auth_only_stats; 76993ea577SAkhil Goyal uint8_t check_sectag_interrupts; 77993ea577SAkhil Goyal }; 78993ea577SAkhil Goyal 79993ea577SAkhil Goyal static struct rte_eth_conf port_conf = { 80993ea577SAkhil Goyal .rxmode = { 81993ea577SAkhil Goyal .mq_mode = RTE_ETH_MQ_RX_NONE, 82993ea577SAkhil Goyal .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM | 83993ea577SAkhil Goyal RTE_ETH_RX_OFFLOAD_MACSEC_STRIP, 84993ea577SAkhil Goyal }, 85993ea577SAkhil Goyal .txmode = { 86993ea577SAkhil Goyal .mq_mode = RTE_ETH_MQ_TX_NONE, 87993ea577SAkhil Goyal .offloads = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE | 88993ea577SAkhil Goyal RTE_ETH_TX_OFFLOAD_MACSEC_INSERT, 89993ea577SAkhil Goyal }, 90993ea577SAkhil Goyal .lpbk_mode = 1, /* enable loopback */ 91993ea577SAkhil Goyal }; 92993ea577SAkhil Goyal 93993ea577SAkhil Goyal static struct rte_eth_rxconf rx_conf = { 94993ea577SAkhil Goyal .rx_thresh = { 95993ea577SAkhil Goyal .pthresh = RX_PTHRESH, 96993ea577SAkhil Goyal .hthresh = RX_HTHRESH, 97993ea577SAkhil Goyal .wthresh = RX_WTHRESH, 98993ea577SAkhil Goyal }, 99993ea577SAkhil Goyal .rx_free_thresh = 32, 100993ea577SAkhil Goyal }; 101993ea577SAkhil Goyal 102993ea577SAkhil Goyal static struct rte_eth_txconf tx_conf = { 103993ea577SAkhil Goyal .tx_thresh = { 104993ea577SAkhil Goyal .pthresh = TX_PTHRESH, 105993ea577SAkhil Goyal .hthresh = TX_HTHRESH, 106993ea577SAkhil Goyal .wthresh = TX_WTHRESH, 107993ea577SAkhil Goyal }, 108993ea577SAkhil Goyal .tx_free_thresh = 32, /* Use PMD default values */ 109993ea577SAkhil Goyal .tx_rs_thresh = 32, /* Use PMD default values */ 110993ea577SAkhil Goyal }; 111993ea577SAkhil Goyal 112993ea577SAkhil Goyal static uint16_t port_id; 113993ea577SAkhil Goyal 114993ea577SAkhil Goyal static uint64_t link_mbps; 115993ea577SAkhil Goyal 116993ea577SAkhil Goyal static struct rte_flow *default_tx_flow[RTE_MAX_ETHPORTS]; 117993ea577SAkhil Goyal static struct rte_flow *default_rx_flow[RTE_MAX_ETHPORTS]; 118993ea577SAkhil Goyal 119993ea577SAkhil Goyal static struct rte_mbuf **tx_pkts_burst; 120993ea577SAkhil Goyal static struct rte_mbuf **rx_pkts_burst; 121993ea577SAkhil Goyal 122993ea577SAkhil Goyal static inline struct rte_mbuf * 123993ea577SAkhil Goyal init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len) 124993ea577SAkhil Goyal { 125993ea577SAkhil Goyal struct rte_mbuf *pkt; 126993ea577SAkhil Goyal 127993ea577SAkhil Goyal pkt = rte_pktmbuf_alloc(mp); 128993ea577SAkhil Goyal if (pkt == NULL) 129993ea577SAkhil Goyal return NULL; 130993ea577SAkhil Goyal 131993ea577SAkhil Goyal rte_memcpy(rte_pktmbuf_append(pkt, len), data, len); 132993ea577SAkhil Goyal 133993ea577SAkhil Goyal return pkt; 134993ea577SAkhil Goyal } 135993ea577SAkhil Goyal 136993ea577SAkhil Goyal static int 137993ea577SAkhil Goyal init_mempools(unsigned int nb_mbuf) 138993ea577SAkhil Goyal { 13979bdb787SAkhil Goyal void *sec_ctx; 140993ea577SAkhil Goyal uint16_t nb_sess = 512; 141993ea577SAkhil Goyal uint32_t sess_sz; 142993ea577SAkhil Goyal char s[64]; 143993ea577SAkhil Goyal 144993ea577SAkhil Goyal if (mbufpool == NULL) { 145993ea577SAkhil Goyal snprintf(s, sizeof(s), "mbuf_pool"); 146993ea577SAkhil Goyal mbufpool = rte_pktmbuf_pool_create(s, nb_mbuf, 147993ea577SAkhil Goyal MEMPOOL_CACHE_SIZE, 0, 148993ea577SAkhil Goyal RTE_MBUF_DEFAULT_BUF_SIZE, SOCKET_ID_ANY); 149993ea577SAkhil Goyal if (mbufpool == NULL) { 150993ea577SAkhil Goyal printf("Cannot init mbuf pool\n"); 151993ea577SAkhil Goyal return TEST_FAILED; 152993ea577SAkhil Goyal } 153993ea577SAkhil Goyal printf("Allocated mbuf pool\n"); 154993ea577SAkhil Goyal } 155993ea577SAkhil Goyal 156993ea577SAkhil Goyal sec_ctx = rte_eth_dev_get_sec_ctx(port_id); 157993ea577SAkhil Goyal if (sec_ctx == NULL) { 158993ea577SAkhil Goyal printf("Device does not support Security ctx\n"); 159993ea577SAkhil Goyal return TEST_SKIPPED; 160993ea577SAkhil Goyal } 161993ea577SAkhil Goyal sess_sz = rte_security_session_get_size(sec_ctx); 162993ea577SAkhil Goyal if (sess_pool == NULL) { 163993ea577SAkhil Goyal snprintf(s, sizeof(s), "sess_pool"); 164993ea577SAkhil Goyal sess_pool = rte_mempool_create(s, nb_sess, sess_sz, 165993ea577SAkhil Goyal MEMPOOL_CACHE_SIZE, 0, 166993ea577SAkhil Goyal NULL, NULL, NULL, NULL, 167993ea577SAkhil Goyal SOCKET_ID_ANY, 0); 168993ea577SAkhil Goyal if (sess_pool == NULL) { 169993ea577SAkhil Goyal printf("Cannot init sess pool\n"); 170993ea577SAkhil Goyal return TEST_FAILED; 171993ea577SAkhil Goyal } 172993ea577SAkhil Goyal printf("Allocated sess pool\n"); 173993ea577SAkhil Goyal } 174993ea577SAkhil Goyal 175993ea577SAkhil Goyal return 0; 176993ea577SAkhil Goyal } 177993ea577SAkhil Goyal 178993ea577SAkhil Goyal static void 179993ea577SAkhil Goyal fill_macsec_sa_conf(const struct mcs_test_vector *td, struct rte_security_macsec_sa *sa, 180993ea577SAkhil Goyal enum rte_security_macsec_direction dir, uint8_t an, uint8_t tci_off) 181993ea577SAkhil Goyal { 182993ea577SAkhil Goyal sa->dir = dir; 183993ea577SAkhil Goyal 184993ea577SAkhil Goyal sa->key.data = td->sa_key.data; 185993ea577SAkhil Goyal sa->key.length = td->sa_key.len; 186993ea577SAkhil Goyal 187993ea577SAkhil Goyal memcpy((uint8_t *)sa->salt, (const uint8_t *)td->salt, RTE_SECURITY_MACSEC_SALT_LEN); 188993ea577SAkhil Goyal 189993ea577SAkhil Goyal /* AN is set as per the value in secure packet in test vector */ 190993ea577SAkhil Goyal sa->an = an & RTE_MACSEC_AN_MASK; 191993ea577SAkhil Goyal 192993ea577SAkhil Goyal sa->ssci = td->ssci; 193993ea577SAkhil Goyal sa->xpn = td->xpn; 194993ea577SAkhil Goyal /* Starting packet number which is expected to come next. 195993ea577SAkhil Goyal * It is take from the test vector so that we can match the out packet. 196993ea577SAkhil Goyal */ 197993ea577SAkhil Goyal sa->next_pn = *(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]); 198993ea577SAkhil Goyal } 199993ea577SAkhil Goyal 200993ea577SAkhil Goyal static void 201993ea577SAkhil Goyal fill_macsec_sc_conf(const struct mcs_test_vector *td, 202993ea577SAkhil Goyal struct rte_security_macsec_sc *sc_conf, 203993ea577SAkhil Goyal const struct mcs_test_opts *opts, 204993ea577SAkhil Goyal enum rte_security_macsec_direction dir, 205993ea577SAkhil Goyal uint16_t sa_id[], uint8_t tci_off) 206993ea577SAkhil Goyal { 207993ea577SAkhil Goyal uint8_t i; 208993ea577SAkhil Goyal 209993ea577SAkhil Goyal sc_conf->dir = dir; 210ad344741SAkhil Goyal sc_conf->pn_threshold = ((uint64_t)td->xpn << 32) | 211ad344741SAkhil Goyal rte_be_to_cpu_32(*(const uint32_t *)(&td->secure_pkt.data[tci_off + 2])); 212993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) { 213993ea577SAkhil Goyal sc_conf->sc_tx.sa_id = sa_id[0]; 214993ea577SAkhil Goyal if (sa_id[1] != MCS_INVALID_SA) { 215993ea577SAkhil Goyal sc_conf->sc_tx.sa_id_rekey = sa_id[1]; 216993ea577SAkhil Goyal sc_conf->sc_tx.re_key_en = 1; 217993ea577SAkhil Goyal } 218993ea577SAkhil Goyal sc_conf->sc_tx.active = 1; 219993ea577SAkhil Goyal /* is SCI valid */ 220993ea577SAkhil Goyal if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) { 221993ea577SAkhil Goyal memcpy(&sc_conf->sc_tx.sci, &td->secure_pkt.data[tci_off + 6], 222993ea577SAkhil Goyal sizeof(sc_conf->sc_tx.sci)); 223993ea577SAkhil Goyal sc_conf->sc_tx.sci = rte_be_to_cpu_64(sc_conf->sc_tx.sci); 224993ea577SAkhil Goyal } else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) { 225993ea577SAkhil Goyal /* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */ 226993ea577SAkhil Goyal const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN; 227993ea577SAkhil Goyal uint8_t *ptr = (uint8_t *)&sc_conf->sc_tx.sci; 228993ea577SAkhil Goyal 229993ea577SAkhil Goyal ptr[0] = 0x01; 230993ea577SAkhil Goyal ptr[1] = 0; 231993ea577SAkhil Goyal for (i = 0; i < RTE_ETHER_ADDR_LEN; i++) 232993ea577SAkhil Goyal ptr[2 + i] = smac[RTE_ETHER_ADDR_LEN - 1 - i]; 233993ea577SAkhil Goyal } else { 234993ea577SAkhil Goyal /* use some default SCI */ 235993ea577SAkhil Goyal sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d; 236993ea577SAkhil Goyal } 237ad344741SAkhil Goyal if (td->xpn > 0) 238ad344741SAkhil Goyal sc_conf->sc_tx.is_xpn = 1; 239993ea577SAkhil Goyal } else { 240993ea577SAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 241993ea577SAkhil Goyal sc_conf->sc_rx.sa_id[i] = sa_id[i]; 242993ea577SAkhil Goyal sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use; 243993ea577SAkhil Goyal } 244993ea577SAkhil Goyal sc_conf->sc_rx.active = 1; 245ad344741SAkhil Goyal if (td->xpn > 0) 246ad344741SAkhil Goyal sc_conf->sc_rx.is_xpn = 1; 247993ea577SAkhil Goyal } 248993ea577SAkhil Goyal } 249993ea577SAkhil Goyal 250993ea577SAkhil Goyal 251993ea577SAkhil Goyal /* Create Inline MACsec session */ 252993ea577SAkhil Goyal static int 253993ea577SAkhil Goyal fill_session_conf(const struct mcs_test_vector *td, uint16_t portid __rte_unused, 254993ea577SAkhil Goyal const struct mcs_test_opts *opts, 255993ea577SAkhil Goyal struct rte_security_session_conf *sess_conf, 256993ea577SAkhil Goyal enum rte_security_macsec_direction dir, 257993ea577SAkhil Goyal uint16_t sc_id, 258993ea577SAkhil Goyal uint8_t tci_off) 259993ea577SAkhil Goyal { 260993ea577SAkhil Goyal sess_conf->action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL; 261993ea577SAkhil Goyal sess_conf->protocol = RTE_SECURITY_PROTOCOL_MACSEC; 262993ea577SAkhil Goyal sess_conf->macsec.dir = dir; 263993ea577SAkhil Goyal sess_conf->macsec.alg = td->alg; 264993ea577SAkhil Goyal sess_conf->macsec.cipher_off = 0; 265993ea577SAkhil Goyal if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) { 266993ea577SAkhil Goyal sess_conf->macsec.sci = rte_be_to_cpu_64(*(const uint64_t *) 267993ea577SAkhil Goyal (&td->secure_pkt.data[tci_off + 6])); 268993ea577SAkhil Goyal } else if (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) { 269993ea577SAkhil Goyal /* sci = source_mac + port_id when ES.bit = 1 & SC.bit = 0 */ 270993ea577SAkhil Goyal const uint8_t *smac = td->plain_pkt.data + RTE_ETHER_ADDR_LEN; 271993ea577SAkhil Goyal uint8_t *ptr = (uint8_t *)&sess_conf->macsec.sci; 272993ea577SAkhil Goyal uint8_t j; 273993ea577SAkhil Goyal 274993ea577SAkhil Goyal ptr[0] = 0x01; 275993ea577SAkhil Goyal ptr[1] = 0; 276993ea577SAkhil Goyal for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) 277993ea577SAkhil Goyal ptr[2 + j] = smac[RTE_ETHER_ADDR_LEN - 1 - j]; 278993ea577SAkhil Goyal } 279993ea577SAkhil Goyal sess_conf->macsec.sc_id = sc_id; 280993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) { 281993ea577SAkhil Goyal sess_conf->macsec.tx_secy.mtu = opts->mtu; 282993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_off = (opts->sectag_insert_mode == 1) ? 283993ea577SAkhil Goyal 2 * RTE_ETHER_ADDR_LEN : 284993ea577SAkhil Goyal RTE_VLAN_HLEN; 285993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_insert_mode = opts->sectag_insert_mode; 286993ea577SAkhil Goyal sess_conf->macsec.tx_secy.ctrl_port_enable = 1; 287993ea577SAkhil Goyal sess_conf->macsec.tx_secy.sectag_version = 0; 288993ea577SAkhil Goyal sess_conf->macsec.tx_secy.end_station = 289993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_ES) >> 6; 290993ea577SAkhil Goyal sess_conf->macsec.tx_secy.send_sci = 291993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SC) >> 5; 292993ea577SAkhil Goyal sess_conf->macsec.tx_secy.scb = 293993ea577SAkhil Goyal (td->secure_pkt.data[tci_off] & RTE_MACSEC_TCI_SCB) >> 4; 294993ea577SAkhil Goyal sess_conf->macsec.tx_secy.encrypt = opts->encrypt; 295993ea577SAkhil Goyal sess_conf->macsec.tx_secy.protect_frames = opts->protect_frames; 296993ea577SAkhil Goyal sess_conf->macsec.tx_secy.icv_include_da_sa = 1; 297993ea577SAkhil Goyal } else { 298993ea577SAkhil Goyal sess_conf->macsec.rx_secy.replay_win_sz = opts->replay_win_sz; 299993ea577SAkhil Goyal sess_conf->macsec.rx_secy.replay_protect = opts->replay_protect; 300993ea577SAkhil Goyal sess_conf->macsec.rx_secy.icv_include_da_sa = 1; 301993ea577SAkhil Goyal sess_conf->macsec.rx_secy.ctrl_port_enable = 1; 302993ea577SAkhil Goyal sess_conf->macsec.rx_secy.preserve_sectag = 0; 303993ea577SAkhil Goyal sess_conf->macsec.rx_secy.preserve_icv = 0; 304993ea577SAkhil Goyal sess_conf->macsec.rx_secy.validate_frames = opts->val_frames; 305993ea577SAkhil Goyal } 306993ea577SAkhil Goyal 307993ea577SAkhil Goyal return 0; 308993ea577SAkhil Goyal } 309993ea577SAkhil Goyal 310993ea577SAkhil Goyal static int 311993ea577SAkhil Goyal create_default_flow(const struct mcs_test_vector *td, uint16_t portid, 312993ea577SAkhil Goyal enum rte_security_macsec_direction dir, void *sess) 313993ea577SAkhil Goyal { 314993ea577SAkhil Goyal struct rte_flow_action action[2]; 315993ea577SAkhil Goyal struct rte_flow_item pattern[2]; 316993ea577SAkhil Goyal struct rte_flow_attr attr = {0}; 317993ea577SAkhil Goyal struct rte_flow_error err; 318993ea577SAkhil Goyal struct rte_flow *flow; 319993ea577SAkhil Goyal struct rte_flow_item_eth eth = { .hdr.ether_type = 0, }; 320993ea577SAkhil Goyal static const struct rte_flow_item_eth eth_mask = { 321*e0d947a1SFerruh Yigit .hdr.dst_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 322*e0d947a1SFerruh Yigit .hdr.src_addr.addr_bytes = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 323993ea577SAkhil Goyal .hdr.ether_type = RTE_BE16(0x0000), 324993ea577SAkhil Goyal }; 325993ea577SAkhil Goyal 326993ea577SAkhil Goyal int ret; 327993ea577SAkhil Goyal 328993ea577SAkhil Goyal eth.has_vlan = 0; 329993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) 330993ea577SAkhil Goyal memcpy(ð.hdr, td->plain_pkt.data, RTE_ETHER_HDR_LEN); 331993ea577SAkhil Goyal else 332993ea577SAkhil Goyal memcpy(ð.hdr, td->secure_pkt.data, RTE_ETHER_HDR_LEN); 333993ea577SAkhil Goyal 334993ea577SAkhil Goyal pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; 335993ea577SAkhil Goyal pattern[0].spec = ð 336993ea577SAkhil Goyal pattern[0].mask = ð_mask; 337993ea577SAkhil Goyal pattern[0].last = NULL; 338993ea577SAkhil Goyal pattern[1].type = RTE_FLOW_ITEM_TYPE_END; 339993ea577SAkhil Goyal 340993ea577SAkhil Goyal action[0].type = RTE_FLOW_ACTION_TYPE_SECURITY; 341993ea577SAkhil Goyal action[0].conf = sess; 342993ea577SAkhil Goyal action[1].type = RTE_FLOW_ACTION_TYPE_END; 343993ea577SAkhil Goyal action[1].conf = NULL; 344993ea577SAkhil Goyal 345993ea577SAkhil Goyal attr.ingress = (dir == RTE_SECURITY_MACSEC_DIR_RX) ? 1 : 0; 346993ea577SAkhil Goyal attr.egress = (dir == RTE_SECURITY_MACSEC_DIR_TX) ? 1 : 0; 347993ea577SAkhil Goyal 348993ea577SAkhil Goyal ret = rte_flow_validate(portid, &attr, pattern, action, &err); 349993ea577SAkhil Goyal if (ret) { 350993ea577SAkhil Goyal printf("\nValidate flow failed, ret = %d\n", ret); 351993ea577SAkhil Goyal return -1; 352993ea577SAkhil Goyal } 353993ea577SAkhil Goyal flow = rte_flow_create(portid, &attr, pattern, action, &err); 354993ea577SAkhil Goyal if (flow == NULL) { 355993ea577SAkhil Goyal printf("\nDefault flow rule create failed\n"); 356993ea577SAkhil Goyal return -1; 357993ea577SAkhil Goyal } 358993ea577SAkhil Goyal 359993ea577SAkhil Goyal if (dir == RTE_SECURITY_MACSEC_DIR_TX) 360993ea577SAkhil Goyal default_tx_flow[portid] = flow; 361993ea577SAkhil Goyal else 362993ea577SAkhil Goyal default_rx_flow[portid] = flow; 363993ea577SAkhil Goyal 364993ea577SAkhil Goyal return 0; 365993ea577SAkhil Goyal } 366993ea577SAkhil Goyal 367993ea577SAkhil Goyal static void 368993ea577SAkhil Goyal destroy_default_flow(uint16_t portid) 369993ea577SAkhil Goyal { 370993ea577SAkhil Goyal struct rte_flow_error err; 371993ea577SAkhil Goyal int ret; 372993ea577SAkhil Goyal 373993ea577SAkhil Goyal if (default_tx_flow[portid]) { 374993ea577SAkhil Goyal ret = rte_flow_destroy(portid, default_tx_flow[portid], &err); 375993ea577SAkhil Goyal if (ret) { 376993ea577SAkhil Goyal printf("\nDefault Tx flow rule destroy failed\n"); 377993ea577SAkhil Goyal return; 378993ea577SAkhil Goyal } 379993ea577SAkhil Goyal default_tx_flow[portid] = NULL; 380993ea577SAkhil Goyal } 381993ea577SAkhil Goyal if (default_rx_flow[portid]) { 382993ea577SAkhil Goyal ret = rte_flow_destroy(portid, default_rx_flow[portid], &err); 383993ea577SAkhil Goyal if (ret) { 384993ea577SAkhil Goyal printf("\nDefault Rx flow rule destroy failed\n"); 385993ea577SAkhil Goyal return; 386993ea577SAkhil Goyal } 387993ea577SAkhil Goyal default_rx_flow[portid] = NULL; 388993ea577SAkhil Goyal } 389993ea577SAkhil Goyal } 390993ea577SAkhil Goyal 391993ea577SAkhil Goyal static void 392993ea577SAkhil Goyal print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 393993ea577SAkhil Goyal { 394993ea577SAkhil Goyal char buf[RTE_ETHER_ADDR_FMT_SIZE]; 395993ea577SAkhil Goyal rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 396993ea577SAkhil Goyal printf("%s%s", name, buf); 397993ea577SAkhil Goyal } 398993ea577SAkhil Goyal 399993ea577SAkhil Goyal /* Check the link status of all ports in up to 3s, and print them finally */ 400993ea577SAkhil Goyal static void 401993ea577SAkhil Goyal check_all_ports_link_status(uint16_t port_num, uint32_t port_mask) 402993ea577SAkhil Goyal { 403993ea577SAkhil Goyal #define CHECK_INTERVAL 100 /* 100ms */ 404993ea577SAkhil Goyal #define MAX_CHECK_TIME 30 /* 3s (30 * 100ms) in total */ 405993ea577SAkhil Goyal uint16_t portid; 406993ea577SAkhil Goyal uint8_t count, all_ports_up, print_flag = 0; 407993ea577SAkhil Goyal struct rte_eth_link link; 408993ea577SAkhil Goyal int ret; 409993ea577SAkhil Goyal char link_status[RTE_ETH_LINK_MAX_STR_LEN]; 410993ea577SAkhil Goyal 411993ea577SAkhil Goyal printf("Checking link statuses...\n"); 412993ea577SAkhil Goyal fflush(stdout); 413993ea577SAkhil Goyal for (count = 0; count <= MAX_CHECK_TIME; count++) { 414993ea577SAkhil Goyal all_ports_up = 1; 415993ea577SAkhil Goyal for (portid = 0; portid < port_num; portid++) { 416993ea577SAkhil Goyal if ((port_mask & (1 << portid)) == 0) 417993ea577SAkhil Goyal continue; 418993ea577SAkhil Goyal memset(&link, 0, sizeof(link)); 419993ea577SAkhil Goyal ret = rte_eth_link_get_nowait(portid, &link); 420993ea577SAkhil Goyal if (ret < 0) { 421993ea577SAkhil Goyal all_ports_up = 0; 422993ea577SAkhil Goyal if (print_flag == 1) 423993ea577SAkhil Goyal printf("Port %u link get failed: %s\n", 424993ea577SAkhil Goyal portid, rte_strerror(-ret)); 425993ea577SAkhil Goyal continue; 426993ea577SAkhil Goyal } 427993ea577SAkhil Goyal 428993ea577SAkhil Goyal /* print link status if flag set */ 429993ea577SAkhil Goyal if (print_flag == 1) { 430993ea577SAkhil Goyal if (link.link_status && link_mbps == 0) 431993ea577SAkhil Goyal link_mbps = link.link_speed; 432993ea577SAkhil Goyal 433993ea577SAkhil Goyal rte_eth_link_to_str(link_status, 434993ea577SAkhil Goyal sizeof(link_status), &link); 435993ea577SAkhil Goyal printf("Port %d %s\n", portid, link_status); 436993ea577SAkhil Goyal continue; 437993ea577SAkhil Goyal } 438993ea577SAkhil Goyal /* clear all_ports_up flag if any link down */ 439993ea577SAkhil Goyal if (link.link_status == RTE_ETH_LINK_DOWN) { 440993ea577SAkhil Goyal all_ports_up = 0; 441993ea577SAkhil Goyal break; 442993ea577SAkhil Goyal } 443993ea577SAkhil Goyal } 444993ea577SAkhil Goyal /* after finally printing all link status, get out */ 445993ea577SAkhil Goyal if (print_flag == 1) 446993ea577SAkhil Goyal break; 447993ea577SAkhil Goyal 448993ea577SAkhil Goyal if (all_ports_up == 0) 449993ea577SAkhil Goyal fflush(stdout); 450993ea577SAkhil Goyal 451993ea577SAkhil Goyal /* set the print_flag if all ports up or timeout */ 452993ea577SAkhil Goyal if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) 453993ea577SAkhil Goyal print_flag = 1; 454993ea577SAkhil Goyal } 455993ea577SAkhil Goyal } 456993ea577SAkhil Goyal 457993ea577SAkhil Goyal static int 458993ea577SAkhil Goyal test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, 459993ea577SAkhil Goyal enum mcs_op op, uint8_t check_out_pkts_untagged) 460993ea577SAkhil Goyal { 461993ea577SAkhil Goyal const uint8_t *dptr; 462993ea577SAkhil Goyal uint16_t pkt_len; 463993ea577SAkhil Goyal 464993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 465993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY || 466993ea577SAkhil Goyal check_out_pkts_untagged == 1) { 467993ea577SAkhil Goyal dptr = td->plain_pkt.data; 468993ea577SAkhil Goyal pkt_len = td->plain_pkt.len; 469993ea577SAkhil Goyal } else { 470993ea577SAkhil Goyal dptr = td->secure_pkt.data; 471993ea577SAkhil Goyal pkt_len = td->secure_pkt.len; 472993ea577SAkhil Goyal } 473993ea577SAkhil Goyal 474993ea577SAkhil Goyal if (memcmp(rte_pktmbuf_mtod(m, uint8_t *), dptr, pkt_len)) { 475993ea577SAkhil Goyal printf("\nData comparison failed for td."); 476993ea577SAkhil Goyal rte_pktmbuf_dump(stdout, m, m->pkt_len); 477993ea577SAkhil Goyal rte_hexdump(stdout, "expected_data", dptr, pkt_len); 478993ea577SAkhil Goyal return TEST_FAILED; 479993ea577SAkhil Goyal } 480993ea577SAkhil Goyal 481993ea577SAkhil Goyal return TEST_SUCCESS; 482993ea577SAkhil Goyal } 483993ea577SAkhil Goyal 484993ea577SAkhil Goyal static void 48579bdb787SAkhil Goyal mcs_stats_dump(void *ctx, enum mcs_op op, 486993ea577SAkhil Goyal void *rx_sess, void *tx_sess, 487993ea577SAkhil Goyal uint8_t rx_sc_id, uint8_t tx_sc_id, 488993ea577SAkhil Goyal uint16_t rx_sa_id[], uint16_t tx_sa_id[]) 489993ea577SAkhil Goyal { 490993ea577SAkhil Goyal struct rte_security_stats sess_stats = {0}; 491993ea577SAkhil Goyal struct rte_security_macsec_secy_stats *secy_stat; 492993ea577SAkhil Goyal struct rte_security_macsec_sc_stats sc_stat = {0}; 493993ea577SAkhil Goyal struct rte_security_macsec_sa_stats sa_stat = {0}; 494993ea577SAkhil Goyal int i; 495993ea577SAkhil Goyal 496993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 497993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 498993ea577SAkhil Goyal printf("\n********* RX SECY STATS ************\n"); 499993ea577SAkhil Goyal rte_security_session_stats_get(ctx, rx_sess, &sess_stats); 500993ea577SAkhil Goyal secy_stat = &sess_stats.macsec; 501993ea577SAkhil Goyal 502993ea577SAkhil Goyal if (secy_stat->ctl_pkt_bcast_cnt) 503993ea577SAkhil Goyal printf("RX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 504993ea577SAkhil Goyal secy_stat->ctl_pkt_bcast_cnt); 505993ea577SAkhil Goyal if (secy_stat->ctl_pkt_mcast_cnt) 506993ea577SAkhil Goyal printf("RX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 507993ea577SAkhil Goyal secy_stat->ctl_pkt_mcast_cnt); 508993ea577SAkhil Goyal if (secy_stat->ctl_pkt_ucast_cnt) 509993ea577SAkhil Goyal printf("RX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 510993ea577SAkhil Goyal secy_stat->ctl_pkt_ucast_cnt); 511993ea577SAkhil Goyal if (secy_stat->ctl_octet_cnt) 512993ea577SAkhil Goyal printf("RX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt); 513993ea577SAkhil Goyal if (secy_stat->unctl_pkt_bcast_cnt) 514993ea577SAkhil Goyal printf("RX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 515993ea577SAkhil Goyal secy_stat->unctl_pkt_bcast_cnt); 516993ea577SAkhil Goyal if (secy_stat->unctl_pkt_mcast_cnt) 517993ea577SAkhil Goyal printf("RX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 518993ea577SAkhil Goyal secy_stat->unctl_pkt_mcast_cnt); 519993ea577SAkhil Goyal if (secy_stat->unctl_pkt_ucast_cnt) 520993ea577SAkhil Goyal printf("RX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 521993ea577SAkhil Goyal secy_stat->unctl_pkt_ucast_cnt); 522993ea577SAkhil Goyal if (secy_stat->unctl_octet_cnt) 523993ea577SAkhil Goyal printf("RX: unctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->unctl_octet_cnt); 524993ea577SAkhil Goyal /* Valid only for RX */ 525993ea577SAkhil Goyal if (secy_stat->octet_decrypted_cnt) 526993ea577SAkhil Goyal printf("RX: octet_decrypted_cnt: 0x%" PRIx64 "\n", 527993ea577SAkhil Goyal secy_stat->octet_decrypted_cnt); 528993ea577SAkhil Goyal if (secy_stat->octet_validated_cnt) 529993ea577SAkhil Goyal printf("RX: octet_validated_cnt: 0x%" PRIx64 "\n", 530993ea577SAkhil Goyal secy_stat->octet_validated_cnt); 531993ea577SAkhil Goyal if (secy_stat->pkt_port_disabled_cnt) 532993ea577SAkhil Goyal printf("RX: pkt_port_disabled_cnt: 0x%" PRIx64 "\n", 533993ea577SAkhil Goyal secy_stat->pkt_port_disabled_cnt); 534993ea577SAkhil Goyal if (secy_stat->pkt_badtag_cnt) 535993ea577SAkhil Goyal printf("RX: pkt_badtag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_badtag_cnt); 536993ea577SAkhil Goyal if (secy_stat->pkt_nosa_cnt) 537993ea577SAkhil Goyal printf("RX: pkt_nosa_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_nosa_cnt); 538993ea577SAkhil Goyal if (secy_stat->pkt_nosaerror_cnt) 539993ea577SAkhil Goyal printf("RX: pkt_nosaerror_cnt: 0x%" PRIx64 "\n", 540993ea577SAkhil Goyal secy_stat->pkt_nosaerror_cnt); 541993ea577SAkhil Goyal if (secy_stat->pkt_tagged_ctl_cnt) 542993ea577SAkhil Goyal printf("RX: pkt_tagged_ctl_cnt: 0x%" PRIx64 "\n", 543993ea577SAkhil Goyal secy_stat->pkt_tagged_ctl_cnt); 544993ea577SAkhil Goyal if (secy_stat->pkt_untaged_cnt) 545993ea577SAkhil Goyal printf("RX: pkt_untaged_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_untaged_cnt); 546993ea577SAkhil Goyal if (secy_stat->pkt_ctl_cnt) 547993ea577SAkhil Goyal printf("RX: pkt_ctl_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_ctl_cnt); 548993ea577SAkhil Goyal if (secy_stat->pkt_notag_cnt) 549993ea577SAkhil Goyal printf("RX: pkt_notag_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_notag_cnt); 550993ea577SAkhil Goyal printf("\n"); 551993ea577SAkhil Goyal printf("\n********** RX SC[%u] STATS **************\n", rx_sc_id); 552993ea577SAkhil Goyal 553993ea577SAkhil Goyal rte_security_macsec_sc_stats_get(ctx, rx_sc_id, RTE_SECURITY_MACSEC_DIR_RX, 554993ea577SAkhil Goyal &sc_stat); 555993ea577SAkhil Goyal /* RX */ 556993ea577SAkhil Goyal if (sc_stat.hit_cnt) 557993ea577SAkhil Goyal printf("RX hit_cnt: 0x%" PRIx64 "\n", sc_stat.hit_cnt); 558993ea577SAkhil Goyal if (sc_stat.pkt_invalid_cnt) 559993ea577SAkhil Goyal printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_invalid_cnt); 560993ea577SAkhil Goyal if (sc_stat.pkt_late_cnt) 561993ea577SAkhil Goyal printf("RX pkt_late_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_late_cnt); 562993ea577SAkhil Goyal if (sc_stat.pkt_notvalid_cnt) 563993ea577SAkhil Goyal printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_notvalid_cnt); 564993ea577SAkhil Goyal if (sc_stat.pkt_unchecked_cnt) 565993ea577SAkhil Goyal printf("RX pkt_unchecked_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_unchecked_cnt); 566993ea577SAkhil Goyal if (sc_stat.pkt_delay_cnt) 567993ea577SAkhil Goyal printf("RX pkt_delay_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_delay_cnt); 568993ea577SAkhil Goyal if (sc_stat.pkt_ok_cnt) 569993ea577SAkhil Goyal printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_ok_cnt); 570993ea577SAkhil Goyal if (sc_stat.octet_decrypt_cnt) 571993ea577SAkhil Goyal printf("RX octet_decrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_decrypt_cnt); 572993ea577SAkhil Goyal if (sc_stat.octet_validate_cnt) 573993ea577SAkhil Goyal printf("RX octet_validate_cnt: 0x%" PRIx64 "\n", 574993ea577SAkhil Goyal sc_stat.octet_validate_cnt); 575993ea577SAkhil Goyal printf("\n"); 576993ea577SAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 577993ea577SAkhil Goyal printf("\n********** RX SA[%u] STATS ****************\n", rx_sa_id[i]); 578993ea577SAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 579993ea577SAkhil Goyal rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i], 580993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sa_stat); 581993ea577SAkhil Goyal 582993ea577SAkhil Goyal /* RX */ 583993ea577SAkhil Goyal if (sa_stat.pkt_invalid_cnt) 584993ea577SAkhil Goyal printf("RX pkt_invalid_cnt: 0x%" PRIx64 "\n", 585993ea577SAkhil Goyal sa_stat.pkt_invalid_cnt); 586993ea577SAkhil Goyal if (sa_stat.pkt_nosaerror_cnt) 587993ea577SAkhil Goyal printf("RX pkt_nosaerror_cnt: 0x%" PRIx64 "\n", 588993ea577SAkhil Goyal sa_stat.pkt_nosaerror_cnt); 589993ea577SAkhil Goyal if (sa_stat.pkt_notvalid_cnt) 590993ea577SAkhil Goyal printf("RX pkt_notvalid_cnt: 0x%" PRIx64 "\n", 591993ea577SAkhil Goyal sa_stat.pkt_notvalid_cnt); 592993ea577SAkhil Goyal if (sa_stat.pkt_ok_cnt) 593993ea577SAkhil Goyal printf("RX pkt_ok_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_ok_cnt); 594993ea577SAkhil Goyal if (sa_stat.pkt_nosa_cnt) 595993ea577SAkhil Goyal printf("RX pkt_nosa_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_nosa_cnt); 596993ea577SAkhil Goyal printf("\n"); 597993ea577SAkhil Goyal } 598993ea577SAkhil Goyal } 599993ea577SAkhil Goyal 600993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 601993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 602993ea577SAkhil Goyal memset(&sess_stats, 0, sizeof(struct rte_security_stats)); 603993ea577SAkhil Goyal rte_security_session_stats_get(ctx, tx_sess, &sess_stats); 604993ea577SAkhil Goyal secy_stat = &sess_stats.macsec; 605993ea577SAkhil Goyal 606993ea577SAkhil Goyal printf("\n********* TX SECY STATS ************\n"); 607993ea577SAkhil Goyal if (secy_stat->ctl_pkt_bcast_cnt) 608993ea577SAkhil Goyal printf("TX: ctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 609993ea577SAkhil Goyal secy_stat->ctl_pkt_bcast_cnt); 610993ea577SAkhil Goyal if (secy_stat->ctl_pkt_mcast_cnt) 611993ea577SAkhil Goyal printf("TX: ctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 612993ea577SAkhil Goyal secy_stat->ctl_pkt_mcast_cnt); 613993ea577SAkhil Goyal if (secy_stat->ctl_pkt_ucast_cnt) 614993ea577SAkhil Goyal printf("TX: ctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 615993ea577SAkhil Goyal secy_stat->ctl_pkt_ucast_cnt); 616993ea577SAkhil Goyal if (secy_stat->ctl_octet_cnt) 617993ea577SAkhil Goyal printf("TX: ctl_octet_cnt: 0x%" PRIx64 "\n", secy_stat->ctl_octet_cnt); 618993ea577SAkhil Goyal if (secy_stat->unctl_pkt_bcast_cnt) 619993ea577SAkhil Goyal printf("TX: unctl_pkt_bcast_cnt: 0x%" PRIx64 "\n", 620993ea577SAkhil Goyal secy_stat->unctl_pkt_bcast_cnt); 621993ea577SAkhil Goyal if (secy_stat->unctl_pkt_mcast_cnt) 622993ea577SAkhil Goyal printf("TX: unctl_pkt_mcast_cnt: 0x%" PRIx64 "\n", 623993ea577SAkhil Goyal secy_stat->unctl_pkt_mcast_cnt); 624993ea577SAkhil Goyal if (secy_stat->unctl_pkt_ucast_cnt) 625993ea577SAkhil Goyal printf("TX: unctl_pkt_ucast_cnt: 0x%" PRIx64 "\n", 626993ea577SAkhil Goyal secy_stat->unctl_pkt_ucast_cnt); 627993ea577SAkhil Goyal if (secy_stat->unctl_octet_cnt) 628993ea577SAkhil Goyal printf("TX: unctl_octet_cnt: 0x%" PRIx64 "\n", 629993ea577SAkhil Goyal secy_stat->unctl_octet_cnt); 630993ea577SAkhil Goyal /* Valid only for TX */ 631993ea577SAkhil Goyal if (secy_stat->octet_encrypted_cnt) 632993ea577SAkhil Goyal printf("TX: octet_encrypted_cnt: 0x%" PRIx64 "\n", 633993ea577SAkhil Goyal secy_stat->octet_encrypted_cnt); 634993ea577SAkhil Goyal if (secy_stat->octet_protected_cnt) 635993ea577SAkhil Goyal printf("TX: octet_protected_cnt: 0x%" PRIx64 "\n", 636993ea577SAkhil Goyal secy_stat->octet_protected_cnt); 637993ea577SAkhil Goyal if (secy_stat->pkt_noactivesa_cnt) 638993ea577SAkhil Goyal printf("TX: pkt_noactivesa_cnt: 0x%" PRIx64 "\n", 639993ea577SAkhil Goyal secy_stat->pkt_noactivesa_cnt); 640993ea577SAkhil Goyal if (secy_stat->pkt_toolong_cnt) 641993ea577SAkhil Goyal printf("TX: pkt_toolong_cnt: 0x%" PRIx64 "\n", secy_stat->pkt_toolong_cnt); 642993ea577SAkhil Goyal if (secy_stat->pkt_untagged_cnt) 643993ea577SAkhil Goyal printf("TX: pkt_untagged_cnt: 0x%" PRIx64 "\n", 644993ea577SAkhil Goyal secy_stat->pkt_untagged_cnt); 645993ea577SAkhil Goyal 646993ea577SAkhil Goyal 647993ea577SAkhil Goyal memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats)); 648993ea577SAkhil Goyal rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX, 649993ea577SAkhil Goyal &sc_stat); 650993ea577SAkhil Goyal printf("\n********** TX SC[%u] STATS **************\n", tx_sc_id); 651993ea577SAkhil Goyal if (sc_stat.pkt_encrypt_cnt) 652993ea577SAkhil Goyal printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_encrypt_cnt); 653993ea577SAkhil Goyal if (sc_stat.pkt_protected_cnt) 654993ea577SAkhil Goyal printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sc_stat.pkt_protected_cnt); 655993ea577SAkhil Goyal if (sc_stat.octet_encrypt_cnt) 656993ea577SAkhil Goyal printf("TX octet_encrypt_cnt: 0x%" PRIx64 "\n", sc_stat.octet_encrypt_cnt); 657993ea577SAkhil Goyal 658993ea577SAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 659993ea577SAkhil Goyal rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0], 660993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, &sa_stat); 661993ea577SAkhil Goyal printf("\n********** TX SA[%u] STATS ****************\n", tx_sa_id[0]); 662993ea577SAkhil Goyal if (sa_stat.pkt_encrypt_cnt) 663993ea577SAkhil Goyal printf("TX pkt_encrypt_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_encrypt_cnt); 664993ea577SAkhil Goyal if (sa_stat.pkt_protected_cnt) 665993ea577SAkhil Goyal printf("TX pkt_protected_cnt: 0x%" PRIx64 "\n", sa_stat.pkt_protected_cnt); 666993ea577SAkhil Goyal } 667993ea577SAkhil Goyal } 668993ea577SAkhil Goyal 669993ea577SAkhil Goyal static int 67079bdb787SAkhil Goyal mcs_stats_check(void *ctx, enum mcs_op op, 6717c3b1decSAkhil Goyal const struct mcs_test_opts *opts, 6727c3b1decSAkhil Goyal const struct mcs_test_vector *td, 6737c3b1decSAkhil Goyal void *rx_sess, void *tx_sess, 6747c3b1decSAkhil Goyal uint8_t rx_sc_id, uint8_t tx_sc_id, 6757c3b1decSAkhil Goyal uint16_t rx_sa_id[], uint16_t tx_sa_id[]) 6767c3b1decSAkhil Goyal { 6777c3b1decSAkhil Goyal struct rte_security_stats sess_stats = {0}; 6787c3b1decSAkhil Goyal struct rte_security_macsec_secy_stats *secy_stat; 6797c3b1decSAkhil Goyal struct rte_security_macsec_sc_stats sc_stat = {0}; 6807c3b1decSAkhil Goyal struct rte_security_macsec_sa_stats sa_stat = {0}; 6817c3b1decSAkhil Goyal int i; 6827c3b1decSAkhil Goyal 6837c3b1decSAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 6847c3b1decSAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 6857c3b1decSAkhil Goyal rte_security_session_stats_get(ctx, rx_sess, &sess_stats); 6867c3b1decSAkhil Goyal secy_stat = &sess_stats.macsec; 6877c3b1decSAkhil Goyal 6887c3b1decSAkhil Goyal if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) || 6897c3b1decSAkhil Goyal (opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1)) 6907c3b1decSAkhil Goyal return TEST_FAILED; 6917c3b1decSAkhil Goyal 6927c3b1decSAkhil Goyal if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1) 6937c3b1decSAkhil Goyal return TEST_FAILED; 6947c3b1decSAkhil Goyal 6957c3b1decSAkhil Goyal if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1) 6967c3b1decSAkhil Goyal return TEST_FAILED; 6977c3b1decSAkhil Goyal 6987c3b1decSAkhil Goyal if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt != 6997c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7007c3b1decSAkhil Goyal return TEST_FAILED; 7017c3b1decSAkhil Goyal 7027c3b1decSAkhil Goyal if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt != 7037c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7047c3b1decSAkhil Goyal return TEST_FAILED; 7057c3b1decSAkhil Goyal 7067c3b1decSAkhil Goyal rte_security_macsec_sc_stats_get(ctx, rx_sc_id, 7077c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sc_stat); 7087c3b1decSAkhil Goyal 7097c3b1decSAkhil Goyal if ((opts->check_decap_stats || opts->check_verify_only_stats) && 7107c3b1decSAkhil Goyal sc_stat.pkt_ok_cnt != 1) 7117c3b1decSAkhil Goyal return TEST_FAILED; 7127c3b1decSAkhil Goyal 7137c3b1decSAkhil Goyal if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1) 7147c3b1decSAkhil Goyal return TEST_FAILED; 7157c3b1decSAkhil Goyal 7167c3b1decSAkhil Goyal if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1) 7177c3b1decSAkhil Goyal return TEST_FAILED; 7187c3b1decSAkhil Goyal 7192a3a153eSAnkur Dwivedi if (opts->replay_protect) { 7202a3a153eSAnkur Dwivedi if (opts->replay_win_sz == 0 && 7212a3a153eSAnkur Dwivedi sc_stat.pkt_late_cnt != 2) 7222a3a153eSAnkur Dwivedi return TEST_FAILED; 7232a3a153eSAnkur Dwivedi else if (opts->replay_win_sz == 32 && 7242a3a153eSAnkur Dwivedi sc_stat.pkt_late_cnt != 1) 7252a3a153eSAnkur Dwivedi return TEST_FAILED; 7262a3a153eSAnkur Dwivedi } 7272a3a153eSAnkur Dwivedi 7287c3b1decSAkhil Goyal for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) { 7297c3b1decSAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 7307c3b1decSAkhil Goyal rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i], 7317c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, &sa_stat); 7327c3b1decSAkhil Goyal 7337c3b1decSAkhil Goyal } 7347c3b1decSAkhil Goyal } 7357c3b1decSAkhil Goyal 7367c3b1decSAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 7377c3b1decSAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 7387c3b1decSAkhil Goyal memset(&sess_stats, 0, sizeof(struct rte_security_stats)); 7397c3b1decSAkhil Goyal rte_security_session_stats_get(ctx, tx_sess, &sess_stats); 7407c3b1decSAkhil Goyal secy_stat = &sess_stats.macsec; 7417c3b1decSAkhil Goyal 7427c3b1decSAkhil Goyal if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1) 7437c3b1decSAkhil Goyal return TEST_FAILED; 7447c3b1decSAkhil Goyal 7457c3b1decSAkhil Goyal if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1) 7467c3b1decSAkhil Goyal return TEST_FAILED; 7477c3b1decSAkhil Goyal 7487c3b1decSAkhil Goyal if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt != 7497c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7507c3b1decSAkhil Goyal return TEST_FAILED; 7517c3b1decSAkhil Goyal 7527c3b1decSAkhil Goyal if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt != 7537c3b1decSAkhil Goyal (uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN)) 7547c3b1decSAkhil Goyal return TEST_FAILED; 7557c3b1decSAkhil Goyal 7567c3b1decSAkhil Goyal 7577c3b1decSAkhil Goyal memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats)); 7587c3b1decSAkhil Goyal rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX, 7597c3b1decSAkhil Goyal &sc_stat); 7607c3b1decSAkhil Goyal 7617c3b1decSAkhil Goyal if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1) 7627c3b1decSAkhil Goyal return TEST_FAILED; 7637c3b1decSAkhil Goyal 7647c3b1decSAkhil Goyal if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1) 7657c3b1decSAkhil Goyal return TEST_FAILED; 7667c3b1decSAkhil Goyal 7677c3b1decSAkhil Goyal memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats)); 7687c3b1decSAkhil Goyal rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0], 7697c3b1decSAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, &sa_stat); 7707c3b1decSAkhil Goyal } 7717c3b1decSAkhil Goyal 7727c3b1decSAkhil Goyal return 0; 7737c3b1decSAkhil Goyal } 7747c3b1decSAkhil Goyal 7757c3b1decSAkhil Goyal static int 776339b9354SAnkur Dwivedi test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type, 777339b9354SAnkur Dwivedi void *param, void *ret_param) 778339b9354SAnkur Dwivedi { 779339b9354SAnkur Dwivedi struct mcs_err_vector *vector = (struct mcs_err_vector *)param; 780339b9354SAnkur Dwivedi struct rte_eth_event_macsec_desc *event_desc = NULL; 781339b9354SAnkur Dwivedi 782339b9354SAnkur Dwivedi RTE_SET_USED(port_id); 783339b9354SAnkur Dwivedi 784339b9354SAnkur Dwivedi if (type != RTE_ETH_EVENT_MACSEC) 785339b9354SAnkur Dwivedi return -1; 786339b9354SAnkur Dwivedi 787339b9354SAnkur Dwivedi event_desc = ret_param; 788339b9354SAnkur Dwivedi if (event_desc == NULL) { 789339b9354SAnkur Dwivedi printf("Event descriptor not set\n"); 790339b9354SAnkur Dwivedi return -1; 791339b9354SAnkur Dwivedi } 792339b9354SAnkur Dwivedi vector->notify_event = true; 793339b9354SAnkur Dwivedi 794339b9354SAnkur Dwivedi switch (event_desc->type) { 795339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR: 796339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR; 797339b9354SAnkur Dwivedi switch (event_desc->subtype) { 798339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1: 799339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1; 800339b9354SAnkur Dwivedi break; 801339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1: 802339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1; 803339b9354SAnkur Dwivedi break; 804339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48: 805339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48; 806339b9354SAnkur Dwivedi break; 807339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1: 808339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1; 809339b9354SAnkur Dwivedi break; 810339b9354SAnkur Dwivedi case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1: 811339b9354SAnkur Dwivedi vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1; 812339b9354SAnkur Dwivedi break; 813339b9354SAnkur Dwivedi default: 814339b9354SAnkur Dwivedi printf("\nUnknown Macsec event subtype: %d", event_desc->subtype); 815339b9354SAnkur Dwivedi } 816339b9354SAnkur Dwivedi break; 817339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP: 818339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP; 819339b9354SAnkur Dwivedi break; 820339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP: 821339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP; 822339b9354SAnkur Dwivedi break; 823339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP: 824339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP; 825339b9354SAnkur Dwivedi break; 826339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP: 827339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP; 828339b9354SAnkur Dwivedi break; 829339b9354SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID: 830339b9354SAnkur Dwivedi vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID; 831339b9354SAnkur Dwivedi break; 832339b9354SAnkur Dwivedi default: 833339b9354SAnkur Dwivedi printf("Invalid MACsec event reported\n"); 834339b9354SAnkur Dwivedi return -1; 835339b9354SAnkur Dwivedi } 836339b9354SAnkur Dwivedi 837339b9354SAnkur Dwivedi return 0; 838339b9354SAnkur Dwivedi } 839339b9354SAnkur Dwivedi 840339b9354SAnkur Dwivedi static int 841b15d5134SAnkur Dwivedi test_macsec_sec_caps_verify(const struct mcs_test_opts *opts, 842b15d5134SAnkur Dwivedi const struct rte_security_capability *sec_cap, bool silent) 843b15d5134SAnkur Dwivedi { 844b15d5134SAnkur Dwivedi if (opts->mtu > sec_cap->macsec.mtu) { 845b15d5134SAnkur Dwivedi if (!silent) 846b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "MTU size is not supported\n"); 847b15d5134SAnkur Dwivedi return -ENOTSUP; 848b15d5134SAnkur Dwivedi } 849b15d5134SAnkur Dwivedi 850b15d5134SAnkur Dwivedi if (opts->replay_protect == 1 && sec_cap->macsec.anti_replay == 0) { 851b15d5134SAnkur Dwivedi if (!silent) 852b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "Anti replay is not supported\n"); 853b15d5134SAnkur Dwivedi return -ENOTSUP; 854b15d5134SAnkur Dwivedi } 855b15d5134SAnkur Dwivedi 856b15d5134SAnkur Dwivedi if (opts->replay_win_sz > sec_cap->macsec.replay_win_sz) { 857b15d5134SAnkur Dwivedi if (!silent) 858b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "Replay window size is not " 859b15d5134SAnkur Dwivedi "supported\n"); 860b15d5134SAnkur Dwivedi return -ENOTSUP; 861b15d5134SAnkur Dwivedi } 862b15d5134SAnkur Dwivedi 863b15d5134SAnkur Dwivedi if (opts->rekey_en == 1 && sec_cap->macsec.re_key == 0) { 864b15d5134SAnkur Dwivedi if (!silent) 865b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "Rekey is not supported\n"); 866b15d5134SAnkur Dwivedi return -ENOTSUP; 867b15d5134SAnkur Dwivedi } 868b15d5134SAnkur Dwivedi 869b15d5134SAnkur Dwivedi if (opts->sectag_insert_mode == 0 && 870b15d5134SAnkur Dwivedi sec_cap->macsec.relative_sectag_insert == 0) { 871b15d5134SAnkur Dwivedi if (!silent) 872b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "Relative offset sectag insert " 873b15d5134SAnkur Dwivedi "not supported\n"); 874b15d5134SAnkur Dwivedi return -ENOTSUP; 875b15d5134SAnkur Dwivedi } 876b15d5134SAnkur Dwivedi 877b15d5134SAnkur Dwivedi if (opts->sectag_insert_mode == 1 && 878b15d5134SAnkur Dwivedi sec_cap->macsec.fixed_sectag_insert == 0) { 879b15d5134SAnkur Dwivedi if (!silent) 880b15d5134SAnkur Dwivedi RTE_LOG(INFO, USER1, "Fixed offset sectag insert " 881b15d5134SAnkur Dwivedi "not supported\n"); 882b15d5134SAnkur Dwivedi return -ENOTSUP; 883b15d5134SAnkur Dwivedi } 884b15d5134SAnkur Dwivedi 885b15d5134SAnkur Dwivedi return 0; 886b15d5134SAnkur Dwivedi } 887b15d5134SAnkur Dwivedi 888b15d5134SAnkur Dwivedi static int 889993ea577SAkhil Goyal test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts) 890993ea577SAkhil Goyal { 891993ea577SAkhil Goyal uint16_t rx_sa_id[MCS_MAX_FLOWS][RTE_SECURITY_MACSEC_NUM_AN] = {{0}}; 892b15d5134SAnkur Dwivedi struct rte_security_capability_idx sec_cap_idx; 893b15d5134SAnkur Dwivedi const struct rte_security_capability *sec_cap; 894993ea577SAkhil Goyal uint16_t tx_sa_id[MCS_MAX_FLOWS][2] = {{0}}; 895993ea577SAkhil Goyal uint16_t rx_sc_id[MCS_MAX_FLOWS] = {0}; 896993ea577SAkhil Goyal uint16_t tx_sc_id[MCS_MAX_FLOWS] = {0}; 897993ea577SAkhil Goyal void *rx_sess[MCS_MAX_FLOWS] = {0}; 898993ea577SAkhil Goyal void *tx_sess[MCS_MAX_FLOWS] = {0}; 899993ea577SAkhil Goyal struct rte_security_session_conf sess_conf = {0}; 900993ea577SAkhil Goyal struct rte_security_macsec_sa sa_conf = {0}; 901993ea577SAkhil Goyal struct rte_security_macsec_sc sc_conf = {0}; 902ad344741SAkhil Goyal struct mcs_err_vector err_vector = {0}; 90379bdb787SAkhil Goyal void *ctx; 904993ea577SAkhil Goyal int nb_rx = 0, nb_sent; 905993ea577SAkhil Goyal int i, j = 0, ret, id, an = 0; 906993ea577SAkhil Goyal uint8_t tci_off; 9072a3a153eSAnkur Dwivedi int k; 908993ea577SAkhil Goyal 909993ea577SAkhil Goyal memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td); 910993ea577SAkhil Goyal 91179bdb787SAkhil Goyal ctx = rte_eth_dev_get_sec_ctx(port_id); 912993ea577SAkhil Goyal if (ctx == NULL) { 913993ea577SAkhil Goyal printf("Ethernet device doesn't support security features.\n"); 914993ea577SAkhil Goyal return TEST_SKIPPED; 915993ea577SAkhil Goyal } 916993ea577SAkhil Goyal 917b15d5134SAnkur Dwivedi sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL; 918b15d5134SAnkur Dwivedi sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_MACSEC; 919b15d5134SAnkur Dwivedi sec_cap_idx.macsec.alg = td[0]->alg; 920b15d5134SAnkur Dwivedi sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 921b15d5134SAnkur Dwivedi if (sec_cap == NULL) { 922b15d5134SAnkur Dwivedi printf("No capabilities registered\n"); 923b15d5134SAnkur Dwivedi return TEST_SKIPPED; 924b15d5134SAnkur Dwivedi } 925b15d5134SAnkur Dwivedi 926b15d5134SAnkur Dwivedi if (test_macsec_sec_caps_verify(opts, sec_cap, false) != 0) 927b15d5134SAnkur Dwivedi return TEST_SKIPPED; 928b15d5134SAnkur Dwivedi 929b15d5134SAnkur Dwivedi if (opts->rekey_en) { 930b15d5134SAnkur Dwivedi /* Verify the rekey td */ 931b15d5134SAnkur Dwivedi sec_cap_idx.macsec.alg = opts->rekey_td->alg; 932b15d5134SAnkur Dwivedi sec_cap = rte_security_capability_get(ctx, &sec_cap_idx); 933b15d5134SAnkur Dwivedi if (sec_cap == NULL) { 934b15d5134SAnkur Dwivedi printf("No capabilities registered\n"); 935b15d5134SAnkur Dwivedi return TEST_SKIPPED; 936b15d5134SAnkur Dwivedi } 937b15d5134SAnkur Dwivedi if (test_macsec_sec_caps_verify(opts, sec_cap, false) != 0) 938b15d5134SAnkur Dwivedi return TEST_SKIPPED; 939b15d5134SAnkur Dwivedi } 940b15d5134SAnkur Dwivedi 941993ea577SAkhil Goyal tci_off = (opts->sectag_insert_mode == 1) ? RTE_ETHER_HDR_LEN : 942993ea577SAkhil Goyal RTE_ETHER_HDR_LEN + (opts->nb_vlan * RTE_VLAN_HLEN); 943993ea577SAkhil Goyal 944993ea577SAkhil Goyal for (i = 0, j = 0; i < opts->nb_td; i++) { 945993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_VERIFY_ONLY) 946993ea577SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, td[i]->secure_pkt.data, 947993ea577SAkhil Goyal td[i]->secure_pkt.len); 948993ea577SAkhil Goyal else { 949993ea577SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, td[i]->plain_pkt.data, 950993ea577SAkhil Goyal td[i]->plain_pkt.len); 951993ea577SAkhil Goyal 952993ea577SAkhil Goyal tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC; 953993ea577SAkhil Goyal } 954993ea577SAkhil Goyal if (tx_pkts_burst[j] == NULL) { 955295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 956993ea577SAkhil Goyal ret = TEST_FAILED; 957993ea577SAkhil Goyal goto out; 958993ea577SAkhil Goyal } 959993ea577SAkhil Goyal j++; 960993ea577SAkhil Goyal 9612a3a153eSAnkur Dwivedi if (opts->replay_protect) { 9622a3a153eSAnkur Dwivedi for (k = 0; k < 3; k++, j++) { 9632a3a153eSAnkur Dwivedi tx_pkts_burst[j] = init_packet(mbufpool, 9642a3a153eSAnkur Dwivedi opts->ar_td[k]->secure_pkt.data, 9652a3a153eSAnkur Dwivedi opts->ar_td[k]->secure_pkt.len); 9662a3a153eSAnkur Dwivedi if (tx_pkts_burst[j] == NULL) { 967295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 9682a3a153eSAnkur Dwivedi ret = TEST_FAILED; 9692a3a153eSAnkur Dwivedi goto out; 9702a3a153eSAnkur Dwivedi } 9712a3a153eSAnkur Dwivedi } 9722a3a153eSAnkur Dwivedi } 9732a3a153eSAnkur Dwivedi 974ad344741SAkhil Goyal if (opts->rekey_en) { 975ad344741SAkhil Goyal 976ad344741SAkhil Goyal err_vector.td = td[i]; 977ad344741SAkhil Goyal err_vector.rekey_td = opts->rekey_td; 978ad344741SAkhil Goyal err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN; 979ad344741SAkhil Goyal err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN; 980ad344741SAkhil Goyal rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC, 981ad344741SAkhil Goyal test_macsec_event_callback, &err_vector); 982ad344741SAkhil Goyal if (op == MCS_DECAP || op == MCS_VERIFY_ONLY) 983ad344741SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, 984ad344741SAkhil Goyal opts->rekey_td->secure_pkt.data, 985ad344741SAkhil Goyal opts->rekey_td->secure_pkt.len); 986ad344741SAkhil Goyal else { 987ad344741SAkhil Goyal tx_pkts_burst[j] = init_packet(mbufpool, 988ad344741SAkhil Goyal opts->rekey_td->plain_pkt.data, 989ad344741SAkhil Goyal opts->rekey_td->plain_pkt.len); 990ad344741SAkhil Goyal 991ad344741SAkhil Goyal tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC; 992ad344741SAkhil Goyal } 993ad344741SAkhil Goyal if (tx_pkts_burst[j] == NULL) { 994295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 995ad344741SAkhil Goyal ret = TEST_FAILED; 996ad344741SAkhil Goyal goto out; 997ad344741SAkhil Goyal } 998ad344741SAkhil Goyal j++; 999ad344741SAkhil Goyal } 1000ad344741SAkhil Goyal 1001993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 1002993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 1003993ea577SAkhil Goyal for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) { 10044885ba24SAnkur Dwivedi if (opts->rekey_en && an == 10054885ba24SAnkur Dwivedi (opts->rekey_td->secure_pkt.data[tci_off] & 10064885ba24SAnkur Dwivedi RTE_MACSEC_AN_MASK)) 10074885ba24SAnkur Dwivedi fill_macsec_sa_conf(opts->rekey_td, &sa_conf, 10084885ba24SAnkur Dwivedi RTE_SECURITY_MACSEC_DIR_RX, an, tci_off); 10094885ba24SAnkur Dwivedi else 1010993ea577SAkhil Goyal /* For simplicity, using same SA conf for all AN */ 1011993ea577SAkhil Goyal fill_macsec_sa_conf(td[i], &sa_conf, 1012993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, an, tci_off); 1013993ea577SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 1014993ea577SAkhil Goyal if (id < 0) { 1015993ea577SAkhil Goyal printf("MACsec SA create failed : %d.\n", id); 1016295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1017295a1de2SAkhil Goyal ret = TEST_FAILED; 1018295a1de2SAkhil Goyal goto out; 1019993ea577SAkhil Goyal } 1020993ea577SAkhil Goyal rx_sa_id[i][an] = (uint16_t)id; 1021993ea577SAkhil Goyal } 1022993ea577SAkhil Goyal fill_macsec_sc_conf(td[i], &sc_conf, opts, 1023993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sa_id[i], tci_off); 1024993ea577SAkhil Goyal id = rte_security_macsec_sc_create(ctx, &sc_conf); 1025993ea577SAkhil Goyal if (id < 0) { 1026993ea577SAkhil Goyal printf("MACsec SC create failed : %d.\n", id); 1027295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1028295a1de2SAkhil Goyal ret = TEST_FAILED; 1029993ea577SAkhil Goyal goto out; 1030993ea577SAkhil Goyal } 1031993ea577SAkhil Goyal rx_sc_id[i] = (uint16_t)id; 1032993ea577SAkhil Goyal 1033993ea577SAkhil Goyal /* Create Inline IPsec session. */ 1034993ea577SAkhil Goyal ret = fill_session_conf(td[i], port_id, opts, &sess_conf, 1035993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sc_id[i], tci_off); 1036295a1de2SAkhil Goyal if (ret) { 1037295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1038295a1de2SAkhil Goyal ret = TEST_FAILED; 1039295a1de2SAkhil Goyal goto out; 1040295a1de2SAkhil Goyal } 1041993ea577SAkhil Goyal rx_sess[i] = rte_security_session_create(ctx, &sess_conf, 1042993ea577SAkhil Goyal sess_pool); 1043993ea577SAkhil Goyal if (rx_sess[i] == NULL) { 1044993ea577SAkhil Goyal printf("SEC Session init failed.\n"); 1045295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1046295a1de2SAkhil Goyal ret = TEST_FAILED; 1047295a1de2SAkhil Goyal goto out; 1048993ea577SAkhil Goyal } 1049993ea577SAkhil Goyal ret = create_default_flow(td[i], port_id, 1050993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX, rx_sess[i]); 1051295a1de2SAkhil Goyal if (ret) { 1052295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1053295a1de2SAkhil Goyal ret = TEST_FAILED; 1054993ea577SAkhil Goyal goto out; 1055993ea577SAkhil Goyal } 1056295a1de2SAkhil Goyal } 1057993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 1058993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 1059993ea577SAkhil Goyal int id; 1060993ea577SAkhil Goyal 1061993ea577SAkhil Goyal fill_macsec_sa_conf(td[i], &sa_conf, 1062993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, 1063993ea577SAkhil Goyal td[i]->secure_pkt.data[tci_off] & RTE_MACSEC_AN_MASK, 1064993ea577SAkhil Goyal tci_off); 1065993ea577SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 1066993ea577SAkhil Goyal if (id < 0) { 1067993ea577SAkhil Goyal printf("MACsec SA create failed : %d.\n", id); 1068295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1069295a1de2SAkhil Goyal ret = TEST_FAILED; 1070295a1de2SAkhil Goyal goto out; 1071993ea577SAkhil Goyal } 1072993ea577SAkhil Goyal tx_sa_id[i][0] = (uint16_t)id; 1073993ea577SAkhil Goyal tx_sa_id[i][1] = MCS_INVALID_SA; 1074ad344741SAkhil Goyal if (opts->rekey_en) { 1075ad344741SAkhil Goyal memset(&sa_conf, 0, sizeof(struct rte_security_macsec_sa)); 1076ad344741SAkhil Goyal fill_macsec_sa_conf(opts->rekey_td, &sa_conf, 1077ad344741SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, 1078ad344741SAkhil Goyal opts->rekey_td->secure_pkt.data[tci_off] & 1079ad344741SAkhil Goyal RTE_MACSEC_AN_MASK, 1080ad344741SAkhil Goyal tci_off); 1081ad344741SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 1082ad344741SAkhil Goyal if (id < 0) { 1083ad344741SAkhil Goyal printf("MACsec rekey SA create failed : %d.\n", id); 1084295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1085295a1de2SAkhil Goyal ret = TEST_FAILED; 1086ad344741SAkhil Goyal goto out; 1087ad344741SAkhil Goyal } 1088ad344741SAkhil Goyal tx_sa_id[i][1] = (uint16_t)id; 1089ad344741SAkhil Goyal } 1090993ea577SAkhil Goyal fill_macsec_sc_conf(td[i], &sc_conf, opts, 1091993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off); 1092993ea577SAkhil Goyal id = rte_security_macsec_sc_create(ctx, &sc_conf); 1093993ea577SAkhil Goyal if (id < 0) { 1094993ea577SAkhil Goyal printf("MACsec SC create failed : %d.\n", id); 1095295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1096295a1de2SAkhil Goyal ret = TEST_FAILED; 1097993ea577SAkhil Goyal goto out; 1098993ea577SAkhil Goyal } 1099993ea577SAkhil Goyal tx_sc_id[i] = (uint16_t)id; 1100993ea577SAkhil Goyal 1101993ea577SAkhil Goyal /* Create Inline IPsec session. */ 1102993ea577SAkhil Goyal ret = fill_session_conf(td[i], port_id, opts, &sess_conf, 1103993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sc_id[i], tci_off); 1104295a1de2SAkhil Goyal if (ret) { 1105295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1106295a1de2SAkhil Goyal ret = TEST_FAILED; 1107295a1de2SAkhil Goyal goto out; 1108295a1de2SAkhil Goyal } 1109993ea577SAkhil Goyal tx_sess[i] = rte_security_session_create(ctx, &sess_conf, 1110993ea577SAkhil Goyal sess_pool); 1111993ea577SAkhil Goyal if (tx_sess[i] == NULL) { 1112993ea577SAkhil Goyal printf("SEC Session init failed.\n"); 1113295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1114295a1de2SAkhil Goyal ret = TEST_FAILED; 1115295a1de2SAkhil Goyal goto out; 1116993ea577SAkhil Goyal } 1117993ea577SAkhil Goyal ret = create_default_flow(td[i], port_id, 1118993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, tx_sess[i]); 1119295a1de2SAkhil Goyal if (ret) { 1120295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(tx_pkts_burst, j); 1121295a1de2SAkhil Goyal ret = TEST_FAILED; 1122993ea577SAkhil Goyal goto out; 1123993ea577SAkhil Goyal } 1124993ea577SAkhil Goyal } 1125295a1de2SAkhil Goyal } 1126993ea577SAkhil Goyal 1127993ea577SAkhil Goyal /* Send packet to ethdev for inline MACsec processing. */ 1128993ea577SAkhil Goyal nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, j); 1129993ea577SAkhil Goyal 1130993ea577SAkhil Goyal if (nb_sent != j) { 1131993ea577SAkhil Goyal printf("\nUnable to TX %d packets, sent: %i", j, nb_sent); 1132993ea577SAkhil Goyal for ( ; nb_sent < j; nb_sent++) 1133993ea577SAkhil Goyal rte_pktmbuf_free(tx_pkts_burst[nb_sent]); 1134993ea577SAkhil Goyal ret = TEST_FAILED; 1135993ea577SAkhil Goyal goto out; 1136993ea577SAkhil Goyal } 1137993ea577SAkhil Goyal 1138993ea577SAkhil Goyal rte_pause(); 1139993ea577SAkhil Goyal 1140295a1de2SAkhil Goyal j = 0; 1141993ea577SAkhil Goyal /* Receive back packet on loopback interface. */ 1142993ea577SAkhil Goyal do { 1143993ea577SAkhil Goyal nb_rx += rte_eth_rx_burst(port_id, 0, 1144993ea577SAkhil Goyal &rx_pkts_burst[nb_rx], 1145993ea577SAkhil Goyal nb_sent - nb_rx); 1146993ea577SAkhil Goyal if (nb_rx >= nb_sent) 1147993ea577SAkhil Goyal break; 1148993ea577SAkhil Goyal rte_delay_ms(1); 1149993ea577SAkhil Goyal } while (j++ < 5 && nb_rx == 0); 1150993ea577SAkhil Goyal 1151993ea577SAkhil Goyal if (nb_rx != nb_sent) { 1152993ea577SAkhil Goyal printf("\nUnable to RX all %d packets, received(%i)", 1153993ea577SAkhil Goyal nb_sent, nb_rx); 1154295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(rx_pkts_burst, nb_rx); 1155993ea577SAkhil Goyal ret = TEST_FAILED; 1156339b9354SAnkur Dwivedi if (opts->check_sectag_interrupts == 1) 1157339b9354SAnkur Dwivedi ret = TEST_SUCCESS; 1158993ea577SAkhil Goyal goto out; 1159993ea577SAkhil Goyal } 1160993ea577SAkhil Goyal 1161ad344741SAkhil Goyal if (opts->rekey_en) { 1162ad344741SAkhil Goyal switch (err_vector.event) { 1163ad344741SAkhil Goyal case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP: 1164ad344741SAkhil Goyal printf("Received RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP event\n"); 1165ad344741SAkhil Goyal /* The first sa is active now, so the 0th sa can be 1166ad344741SAkhil Goyal * reconfigured. Using the same key as zeroeth sa, but 1167ad344741SAkhil Goyal * other key can also be configured. 1168ad344741SAkhil Goyal */ 1169ad344741SAkhil Goyal rte_security_macsec_sa_destroy(ctx, tx_sa_id[0][0], 1170ad344741SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1171ad344741SAkhil Goyal fill_macsec_sa_conf(td[0], &sa_conf, 1172ad344741SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX, 1173ad344741SAkhil Goyal td[0]->secure_pkt.data[tci_off] & 1174ad344741SAkhil Goyal RTE_MACSEC_AN_MASK, tci_off); 1175ad344741SAkhil Goyal id = rte_security_macsec_sa_create(ctx, &sa_conf); 1176ad344741SAkhil Goyal if (id < 0) { 1177ad344741SAkhil Goyal printf("MACsec SA create failed : %d.\n", id); 1178295a1de2SAkhil Goyal rte_pktmbuf_free_bulk(rx_pkts_burst, nb_rx); 1179295a1de2SAkhil Goyal ret = TEST_FAILED; 1180295a1de2SAkhil Goyal goto out; 1181ad344741SAkhil Goyal } 1182ad344741SAkhil Goyal tx_sa_id[0][0] = (uint16_t)id; 1183ad344741SAkhil Goyal break; 11844885ba24SAnkur Dwivedi case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP: 11854885ba24SAnkur Dwivedi printf("Received RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP event\n"); 11864885ba24SAnkur Dwivedi break; 1187ad344741SAkhil Goyal default: 1188ad344741SAkhil Goyal printf("Received unsupported event\n"); 1189ad344741SAkhil Goyal } 1190ad344741SAkhil Goyal } 1191ad344741SAkhil Goyal 11922a3a153eSAnkur Dwivedi if (opts->replay_protect) { 11932a3a153eSAnkur Dwivedi for (i = 0; i < nb_rx; i++) { 11942a3a153eSAnkur Dwivedi rte_pktmbuf_free(rx_pkts_burst[i]); 11952a3a153eSAnkur Dwivedi rx_pkts_burst[i] = NULL; 11962a3a153eSAnkur Dwivedi } 11972a3a153eSAnkur Dwivedi ret = TEST_SUCCESS; 11982a3a153eSAnkur Dwivedi goto out; 11992a3a153eSAnkur Dwivedi } 12002a3a153eSAnkur Dwivedi 1201993ea577SAkhil Goyal for (i = 0; i < nb_rx; i++) { 1202ad344741SAkhil Goyal if (opts->rekey_en && i == 1) { 1203ad344741SAkhil Goyal /* The second received packet is matched with 1204ad344741SAkhil Goyal * rekey td 1205ad344741SAkhil Goyal */ 1206ad344741SAkhil Goyal ret = test_macsec_post_process(rx_pkts_burst[i], 1207ad344741SAkhil Goyal opts->rekey_td, op, 1208993ea577SAkhil Goyal opts->check_out_pkts_untagged); 1209ad344741SAkhil Goyal } else { 1210ad344741SAkhil Goyal ret = test_macsec_post_process(rx_pkts_burst[i], td[i], 1211ad344741SAkhil Goyal op, opts->check_out_pkts_untagged); 1212ad344741SAkhil Goyal } 1213993ea577SAkhil Goyal if (ret != TEST_SUCCESS) { 1214993ea577SAkhil Goyal for ( ; i < nb_rx; i++) 1215993ea577SAkhil Goyal rte_pktmbuf_free(rx_pkts_burst[i]); 1216993ea577SAkhil Goyal goto out; 1217993ea577SAkhil Goyal } 1218993ea577SAkhil Goyal 1219993ea577SAkhil Goyal rte_pktmbuf_free(rx_pkts_burst[i]); 1220993ea577SAkhil Goyal rx_pkts_burst[i] = NULL; 1221993ea577SAkhil Goyal } 1222993ea577SAkhil Goyal out: 12237c3b1decSAkhil Goyal if (opts->check_out_pkts_toolong == 1 || 12247c3b1decSAkhil Goyal opts->check_sa_not_in_use == 1 || 12257c3b1decSAkhil Goyal opts->check_bad_tag_cnt == 1) 12267c3b1decSAkhil Goyal ret = TEST_SUCCESS; 12277c3b1decSAkhil Goyal 1228993ea577SAkhil Goyal for (i = 0; i < opts->nb_td; i++) { 1229993ea577SAkhil Goyal if (opts->dump_all_stats) { 1230993ea577SAkhil Goyal mcs_stats_dump(ctx, op, 1231993ea577SAkhil Goyal rx_sess[i], tx_sess[i], 1232993ea577SAkhil Goyal rx_sc_id[i], tx_sc_id[i], 1233993ea577SAkhil Goyal rx_sa_id[i], tx_sa_id[i]); 12347c3b1decSAkhil Goyal } else { 12357c3b1decSAkhil Goyal if (ret == TEST_SUCCESS) 12367c3b1decSAkhil Goyal ret = mcs_stats_check(ctx, op, opts, td[i], 12377c3b1decSAkhil Goyal rx_sess[i], tx_sess[i], 12387c3b1decSAkhil Goyal rx_sc_id[i], tx_sc_id[i], 12397c3b1decSAkhil Goyal rx_sa_id[i], tx_sa_id[i]); 1240993ea577SAkhil Goyal } 1241993ea577SAkhil Goyal } 1242993ea577SAkhil Goyal 1243993ea577SAkhil Goyal destroy_default_flow(port_id); 1244993ea577SAkhil Goyal 1245ad344741SAkhil Goyal if (opts->rekey_en) 1246ad344741SAkhil Goyal rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC, 1247ad344741SAkhil Goyal test_macsec_event_callback, &err_vector); 1248ad344741SAkhil Goyal 1249993ea577SAkhil Goyal /* Destroy session so that other cases can create the session again */ 1250993ea577SAkhil Goyal for (i = 0; i < opts->nb_td; i++) { 1251993ea577SAkhil Goyal if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP || 1252993ea577SAkhil Goyal op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) { 1253993ea577SAkhil Goyal rte_security_session_destroy(ctx, tx_sess[i]); 1254993ea577SAkhil Goyal tx_sess[i] = NULL; 1255993ea577SAkhil Goyal rte_security_macsec_sc_destroy(ctx, tx_sc_id[i], 1256993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1257993ea577SAkhil Goyal rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0], 1258993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1259ad344741SAkhil Goyal if (opts->rekey_en) { 1260ad344741SAkhil Goyal rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][1], 1261ad344741SAkhil Goyal RTE_SECURITY_MACSEC_DIR_TX); 1262ad344741SAkhil Goyal } 1263993ea577SAkhil Goyal } 1264993ea577SAkhil Goyal if (op == MCS_DECAP || op == MCS_ENCAP_DECAP || 1265993ea577SAkhil Goyal op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) { 1266993ea577SAkhil Goyal rte_security_session_destroy(ctx, rx_sess[i]); 1267993ea577SAkhil Goyal rx_sess[i] = NULL; 1268993ea577SAkhil Goyal rte_security_macsec_sc_destroy(ctx, rx_sc_id[i], 1269993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX); 1270993ea577SAkhil Goyal for (j = 0; j < RTE_SECURITY_MACSEC_NUM_AN; j++) { 1271993ea577SAkhil Goyal rte_security_macsec_sa_destroy(ctx, rx_sa_id[i][j], 1272993ea577SAkhil Goyal RTE_SECURITY_MACSEC_DIR_RX); 1273993ea577SAkhil Goyal } 1274993ea577SAkhil Goyal } 1275993ea577SAkhil Goyal } 1276993ea577SAkhil Goyal 1277993ea577SAkhil Goyal return ret; 1278993ea577SAkhil Goyal } 1279993ea577SAkhil Goyal 1280993ea577SAkhil Goyal static int 128163bf81a6SAnatoly Burakov test_inline_macsec_encap_all(void) 1282993ea577SAkhil Goyal { 1283993ea577SAkhil Goyal const struct mcs_test_vector *cur_td; 1284993ea577SAkhil Goyal struct mcs_test_opts opts = {0}; 1285993ea577SAkhil Goyal int err, all_err = 0; 1286b15d5134SAnkur Dwivedi int skipped = 0; 1287993ea577SAkhil Goyal int i, size; 1288993ea577SAkhil Goyal 1289993ea577SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1290993ea577SAkhil Goyal opts.encrypt = true; 1291993ea577SAkhil Goyal opts.protect_frames = true; 1292993ea577SAkhil Goyal opts.sa_in_use = 1; 1293993ea577SAkhil Goyal opts.nb_td = 1; 1294993ea577SAkhil Goyal opts.sectag_insert_mode = 1; 1295993ea577SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1296993ea577SAkhil Goyal 1297993ea577SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1298993ea577SAkhil Goyal for (i = 0; i < size; i++) { 1299993ea577SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1300993ea577SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1301b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1302b15d5134SAnkur Dwivedi printf("Cipher Auth Encryption case %d skipped\n", cur_td->test_idx); 1303b15d5134SAnkur Dwivedi skipped += 1; 1304b15d5134SAnkur Dwivedi err = 0; 1305b15d5134SAnkur Dwivedi } else if (err) { 1306993ea577SAkhil Goyal printf("\nCipher Auth Encryption case %d failed", cur_td->test_idx); 1307993ea577SAkhil Goyal err = -1; 1308993ea577SAkhil Goyal } else { 1309993ea577SAkhil Goyal printf("\nCipher Auth Encryption case %d Passed", cur_td->test_idx); 1310993ea577SAkhil Goyal err = 0; 1311993ea577SAkhil Goyal } 1312993ea577SAkhil Goyal all_err += err; 1313993ea577SAkhil Goyal } 1314b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1315b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1316993ea577SAkhil Goyal 1317b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1318993ea577SAkhil Goyal } 1319993ea577SAkhil Goyal 1320993ea577SAkhil Goyal static int 132163bf81a6SAnatoly Burakov test_inline_macsec_decap_all(void) 1322993ea577SAkhil Goyal { 1323993ea577SAkhil Goyal const struct mcs_test_vector *cur_td; 1324993ea577SAkhil Goyal struct mcs_test_opts opts = {0}; 1325993ea577SAkhil Goyal int err, all_err = 0; 1326b15d5134SAnkur Dwivedi int skipped = 0; 1327993ea577SAkhil Goyal int i, size; 1328993ea577SAkhil Goyal 1329993ea577SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1330993ea577SAkhil Goyal opts.sa_in_use = 1; 1331993ea577SAkhil Goyal opts.nb_td = 1; 1332993ea577SAkhil Goyal opts.sectag_insert_mode = 1; 1333993ea577SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1334993ea577SAkhil Goyal 1335993ea577SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1336993ea577SAkhil Goyal for (i = 0; i < size; i++) { 1337993ea577SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1338993ea577SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1339b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1340b15d5134SAnkur Dwivedi printf("Cipher Auth Decryption case %d skipped\n", cur_td->test_idx); 1341b15d5134SAnkur Dwivedi skipped += 1; 1342b15d5134SAnkur Dwivedi err = 0; 1343b15d5134SAnkur Dwivedi } else if (err) { 1344993ea577SAkhil Goyal printf("\nCipher Auth Decryption case %d failed", cur_td->test_idx); 1345993ea577SAkhil Goyal err = -1; 1346993ea577SAkhil Goyal } else { 1347993ea577SAkhil Goyal printf("\nCipher Auth Decryption case %d Passed", cur_td->test_idx); 1348993ea577SAkhil Goyal err = 0; 1349993ea577SAkhil Goyal } 1350993ea577SAkhil Goyal all_err += err; 1351993ea577SAkhil Goyal } 1352b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1353b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1354993ea577SAkhil Goyal 1355b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1356993ea577SAkhil Goyal } 1357993ea577SAkhil Goyal 1358993ea577SAkhil Goyal static int 135963bf81a6SAnatoly Burakov test_inline_macsec_auth_only_all(void) 13602da0c0a7SAkhil Goyal { 13612da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 13622da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 13632da0c0a7SAkhil Goyal int err, all_err = 0; 1364b15d5134SAnkur Dwivedi int skipped = 0; 13652da0c0a7SAkhil Goyal int i, size; 13662da0c0a7SAkhil Goyal 13672da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 13682da0c0a7SAkhil Goyal opts.protect_frames = true; 13692da0c0a7SAkhil Goyal opts.sa_in_use = 1; 13702da0c0a7SAkhil Goyal opts.nb_td = 1; 13712da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 13722da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 13732da0c0a7SAkhil Goyal 13742da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 13752da0c0a7SAkhil Goyal 13762da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 13772da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 13782da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts); 1379b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1380b15d5134SAnkur Dwivedi printf("Auth Generate case %d skipped\n", cur_td->test_idx); 1381b15d5134SAnkur Dwivedi skipped += 1; 1382b15d5134SAnkur Dwivedi err = 0; 1383b15d5134SAnkur Dwivedi } else if (err) { 13842da0c0a7SAkhil Goyal printf("\nAuth Generate case %d failed", cur_td->test_idx); 13852da0c0a7SAkhil Goyal err = -1; 13862da0c0a7SAkhil Goyal } else { 13872da0c0a7SAkhil Goyal printf("\nAuth Generate case %d Passed", cur_td->test_idx); 13882da0c0a7SAkhil Goyal err = 0; 13892da0c0a7SAkhil Goyal } 13902da0c0a7SAkhil Goyal all_err += err; 13912da0c0a7SAkhil Goyal } 1392b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1393b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 13942da0c0a7SAkhil Goyal 1395b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 13962da0c0a7SAkhil Goyal } 13972da0c0a7SAkhil Goyal 13982da0c0a7SAkhil Goyal static int 139963bf81a6SAnatoly Burakov test_inline_macsec_verify_only_all(void) 14002da0c0a7SAkhil Goyal { 14012da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 14022da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 14032da0c0a7SAkhil Goyal int err, all_err = 0; 1404b15d5134SAnkur Dwivedi int skipped = 0; 14052da0c0a7SAkhil Goyal int i, size; 14062da0c0a7SAkhil Goyal 14072da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14082da0c0a7SAkhil Goyal opts.sa_in_use = 1; 14092da0c0a7SAkhil Goyal opts.nb_td = 1; 14102da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 14112da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14122da0c0a7SAkhil Goyal 14132da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 14142da0c0a7SAkhil Goyal 14152da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 14162da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 14172da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 1418b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1419b15d5134SAnkur Dwivedi printf("Auth Verify case %d skipped\n", cur_td->test_idx); 1420b15d5134SAnkur Dwivedi skipped += 1; 1421b15d5134SAnkur Dwivedi err = 0; 1422b15d5134SAnkur Dwivedi } else if (err) { 14232da0c0a7SAkhil Goyal printf("\nAuth Verify case %d failed", cur_td->test_idx); 14242da0c0a7SAkhil Goyal err = -1; 14252da0c0a7SAkhil Goyal } else { 14262da0c0a7SAkhil Goyal printf("\nAuth Verify case %d Passed", cur_td->test_idx); 14272da0c0a7SAkhil Goyal err = 0; 14282da0c0a7SAkhil Goyal } 14292da0c0a7SAkhil Goyal all_err += err; 14302da0c0a7SAkhil Goyal } 1431b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1432b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 14332da0c0a7SAkhil Goyal 1434b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 14352da0c0a7SAkhil Goyal } 14362da0c0a7SAkhil Goyal 14372da0c0a7SAkhil Goyal static int 143863bf81a6SAnatoly Burakov test_inline_macsec_encap_decap_all(void) 14392da0c0a7SAkhil Goyal { 14402da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 14412da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 14422da0c0a7SAkhil Goyal int err, all_err = 0; 1443b15d5134SAnkur Dwivedi int skipped = 0; 14442da0c0a7SAkhil Goyal int i, size; 14452da0c0a7SAkhil Goyal 14462da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14472da0c0a7SAkhil Goyal opts.encrypt = true; 14482da0c0a7SAkhil Goyal opts.protect_frames = true; 14492da0c0a7SAkhil Goyal opts.sa_in_use = 1; 14502da0c0a7SAkhil Goyal opts.nb_td = 1; 14512da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 14522da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14532da0c0a7SAkhil Goyal 14542da0c0a7SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 14552da0c0a7SAkhil Goyal 14562da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 14572da0c0a7SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 14582da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts); 1459b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1460b15d5134SAnkur Dwivedi printf("Cipher Auth Encap-decap case %d skipped\n", cur_td->test_idx); 1461b15d5134SAnkur Dwivedi skipped += 1; 1462b15d5134SAnkur Dwivedi err = 0; 1463b15d5134SAnkur Dwivedi } else if (err) { 14642da0c0a7SAkhil Goyal printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx); 14652da0c0a7SAkhil Goyal err = -1; 14662da0c0a7SAkhil Goyal } else { 14672da0c0a7SAkhil Goyal printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx); 14682da0c0a7SAkhil Goyal err = 0; 14692da0c0a7SAkhil Goyal } 14702da0c0a7SAkhil Goyal all_err += err; 14712da0c0a7SAkhil Goyal } 1472b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1473b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 14742da0c0a7SAkhil Goyal 1475b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 14762da0c0a7SAkhil Goyal } 14772da0c0a7SAkhil Goyal 14782da0c0a7SAkhil Goyal 14792da0c0a7SAkhil Goyal static int 148063bf81a6SAnatoly Burakov test_inline_macsec_auth_verify_all(void) 14812da0c0a7SAkhil Goyal { 14822da0c0a7SAkhil Goyal const struct mcs_test_vector *cur_td; 14832da0c0a7SAkhil Goyal struct mcs_test_opts opts = {0}; 14842da0c0a7SAkhil Goyal int err, all_err = 0; 1485b15d5134SAnkur Dwivedi int skipped = 0; 14862da0c0a7SAkhil Goyal int i, size; 14872da0c0a7SAkhil Goyal 14882da0c0a7SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 14892da0c0a7SAkhil Goyal opts.protect_frames = true; 14902da0c0a7SAkhil Goyal opts.sa_in_use = 1; 14912da0c0a7SAkhil Goyal opts.nb_td = 1; 14922da0c0a7SAkhil Goyal opts.sectag_insert_mode = 1; 14932da0c0a7SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 14942da0c0a7SAkhil Goyal 14952da0c0a7SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 14962da0c0a7SAkhil Goyal 14972da0c0a7SAkhil Goyal for (i = 0; i < size; i++) { 14982da0c0a7SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 14992da0c0a7SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts); 1500b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1501b15d5134SAnkur Dwivedi printf("Auth Generate + Verify case %d skipped\n", cur_td->test_idx); 1502b15d5134SAnkur Dwivedi skipped += 1; 1503b15d5134SAnkur Dwivedi err = 0; 1504b15d5134SAnkur Dwivedi } else if (err) { 15052da0c0a7SAkhil Goyal printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx); 15062da0c0a7SAkhil Goyal err = -1; 15072da0c0a7SAkhil Goyal } else { 15082da0c0a7SAkhil Goyal printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx); 15092da0c0a7SAkhil Goyal err = 0; 15102da0c0a7SAkhil Goyal } 15112da0c0a7SAkhil Goyal all_err += err; 15122da0c0a7SAkhil Goyal } 1513b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1514b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 15152da0c0a7SAkhil Goyal 1516b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 15172da0c0a7SAkhil Goyal } 15182da0c0a7SAkhil Goyal 15192da0c0a7SAkhil Goyal static int 152063bf81a6SAnatoly Burakov test_inline_macsec_multi_flow(void) 1521e3d83ea4SAkhil Goyal { 1522e3d83ea4SAkhil Goyal const struct mcs_test_vector *tv[MCS_MAX_FLOWS]; 1523e3d83ea4SAkhil Goyal struct mcs_test_vector iter[MCS_MAX_FLOWS]; 1524e3d83ea4SAkhil Goyal struct mcs_test_opts opts = {0}; 1525e3d83ea4SAkhil Goyal int i, err; 1526e3d83ea4SAkhil Goyal 1527e3d83ea4SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1528e3d83ea4SAkhil Goyal opts.encrypt = true; 1529e3d83ea4SAkhil Goyal opts.protect_frames = true; 1530e3d83ea4SAkhil Goyal opts.sa_in_use = 1; 1531e3d83ea4SAkhil Goyal opts.nb_td = MCS_MAX_FLOWS; 1532e3d83ea4SAkhil Goyal opts.sectag_insert_mode = 1; 1533e3d83ea4SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1534e3d83ea4SAkhil Goyal 1535e3d83ea4SAkhil Goyal for (i = 0; i < MCS_MAX_FLOWS; i++) { 1536e3d83ea4SAkhil Goyal memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ); 1537e3d83ea4SAkhil Goyal memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN); 1538e3d83ea4SAkhil Goyal memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data, 1539e3d83ea4SAkhil Goyal MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ); 1540e3d83ea4SAkhil Goyal memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN); 1541e3d83ea4SAkhil Goyal memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data, 1542e3d83ea4SAkhil Goyal MCS_MULTI_FLOW_TD_SECURE_DATA_SZ); 1543e3d83ea4SAkhil Goyal iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ; 1544e3d83ea4SAkhil Goyal iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ + 1545e3d83ea4SAkhil Goyal (2 * RTE_ETHER_ADDR_LEN); 1546e3d83ea4SAkhil Goyal iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ + 1547e3d83ea4SAkhil Goyal (2 * RTE_ETHER_ADDR_LEN); 1548e3d83ea4SAkhil Goyal iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128; 1549e3d83ea4SAkhil Goyal iter[i].ssci = 0x0; 1550e3d83ea4SAkhil Goyal iter[i].xpn = 0x0; 1551e3d83ea4SAkhil Goyal tv[i] = (const struct mcs_test_vector *)&iter[i]; 1552e3d83ea4SAkhil Goyal } 1553e3d83ea4SAkhil Goyal err = test_macsec(tv, MCS_ENCAP_DECAP, &opts); 1554b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1555b15d5134SAnkur Dwivedi printf("Cipher Auth Encryption multi flow skipped\n"); 1556b15d5134SAnkur Dwivedi } else if (err) { 1557e3d83ea4SAkhil Goyal printf("\nCipher Auth Encryption multi flow failed"); 1558e3d83ea4SAkhil Goyal err = -1; 1559e3d83ea4SAkhil Goyal } else { 1560e3d83ea4SAkhil Goyal printf("\nCipher Auth Encryption multi flow Passed"); 1561e3d83ea4SAkhil Goyal err = 0; 1562e3d83ea4SAkhil Goyal } 1563e3d83ea4SAkhil Goyal return err; 1564e3d83ea4SAkhil Goyal } 1565e3d83ea4SAkhil Goyal 1566e3d83ea4SAkhil Goyal static int 156763bf81a6SAnatoly Burakov test_inline_macsec_with_vlan(void) 1568e67246cbSAkhil Goyal { 1569e67246cbSAkhil Goyal const struct mcs_test_vector *cur_td; 1570e67246cbSAkhil Goyal struct mcs_test_opts opts = {0}; 1571e67246cbSAkhil Goyal int err, all_err = 0; 1572b15d5134SAnkur Dwivedi int skipped = 0; 1573e67246cbSAkhil Goyal int i, size; 1574e67246cbSAkhil Goyal 1575e67246cbSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1576e67246cbSAkhil Goyal opts.protect_frames = true; 1577e67246cbSAkhil Goyal opts.sa_in_use = 1; 1578e67246cbSAkhil Goyal opts.nb_td = 1; 1579e67246cbSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1580e67246cbSAkhil Goyal 1581e67246cbSAkhil Goyal size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0])); 1582e67246cbSAkhil Goyal 1583e67246cbSAkhil Goyal for (i = 0; i < size; i++) { 1584e67246cbSAkhil Goyal cur_td = &list_mcs_vlan_vectors[i]; 1585e67246cbSAkhil Goyal if (i == 0) { 1586e67246cbSAkhil Goyal opts.sectag_insert_mode = 1; 1587e67246cbSAkhil Goyal } else if (i == 1) { 1588e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1589e67246cbSAkhil Goyal opts.nb_vlan = 1; 1590e67246cbSAkhil Goyal } else if (i == 2) { 1591e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1592e67246cbSAkhil Goyal opts.nb_vlan = 2; 1593e67246cbSAkhil Goyal } 1594e67246cbSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1595b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1596b15d5134SAnkur Dwivedi printf("VLAN Encap case %d skipped", cur_td->test_idx); 1597b15d5134SAnkur Dwivedi skipped += 1; 1598b15d5134SAnkur Dwivedi err = 0; 1599b15d5134SAnkur Dwivedi } else if (err) { 1600e67246cbSAkhil Goyal printf("\n VLAN Encap case %d failed", cur_td->test_idx); 1601e67246cbSAkhil Goyal err = -1; 1602e67246cbSAkhil Goyal } else { 1603e67246cbSAkhil Goyal printf("\n VLAN Encap case %d passed", cur_td->test_idx); 1604e67246cbSAkhil Goyal err = 0; 1605e67246cbSAkhil Goyal } 1606e67246cbSAkhil Goyal all_err += err; 1607e67246cbSAkhil Goyal } 1608e67246cbSAkhil Goyal for (i = 0; i < size; i++) { 1609e67246cbSAkhil Goyal cur_td = &list_mcs_vlan_vectors[i]; 1610e67246cbSAkhil Goyal if (i == 0) { 1611e67246cbSAkhil Goyal opts.sectag_insert_mode = 1; 1612e67246cbSAkhil Goyal } else if (i == 1) { 1613e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1614e67246cbSAkhil Goyal opts.nb_vlan = 1; 1615e67246cbSAkhil Goyal } else if (i == 2) { 1616e67246cbSAkhil Goyal opts.sectag_insert_mode = 0; /* offset from special E-type */ 1617e67246cbSAkhil Goyal opts.nb_vlan = 2; 1618e67246cbSAkhil Goyal } 1619e67246cbSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1620b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1621b15d5134SAnkur Dwivedi printf("VLAN Decap case %d skipped", cur_td->test_idx); 1622b15d5134SAnkur Dwivedi skipped += 1; 1623b15d5134SAnkur Dwivedi err = 0; 1624b15d5134SAnkur Dwivedi } else if (err) { 1625e67246cbSAkhil Goyal printf("\n VLAN Decap case %d failed", cur_td->test_idx); 1626e67246cbSAkhil Goyal err = -1; 1627e67246cbSAkhil Goyal } else { 1628e67246cbSAkhil Goyal printf("\n VLAN Decap case %d passed", cur_td->test_idx); 1629e67246cbSAkhil Goyal err = 0; 1630e67246cbSAkhil Goyal } 1631e67246cbSAkhil Goyal all_err += err; 1632e67246cbSAkhil Goyal } 1633e67246cbSAkhil Goyal 1634b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1635b15d5134SAnkur Dwivedi 2 * size + all_err - skipped, -all_err, skipped); 1636b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1637e67246cbSAkhil Goyal } 1638e67246cbSAkhil Goyal 1639e67246cbSAkhil Goyal static int 164063bf81a6SAnatoly Burakov test_inline_macsec_pkt_drop(void) 16417c3b1decSAkhil Goyal { 16427c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 16437c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 16447c3b1decSAkhil Goyal int err, all_err = 0; 1645b15d5134SAnkur Dwivedi int skipped = 0; 16467c3b1decSAkhil Goyal int i, size; 16477c3b1decSAkhil Goyal 16487c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 16497c3b1decSAkhil Goyal opts.encrypt = true; 16507c3b1decSAkhil Goyal opts.protect_frames = true; 16517c3b1decSAkhil Goyal opts.sa_in_use = 1; 16527c3b1decSAkhil Goyal opts.nb_td = 1; 16537c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 16547c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 16557c3b1decSAkhil Goyal 16567c3b1decSAkhil Goyal size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0])); 16577c3b1decSAkhil Goyal 16587c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 16597c3b1decSAkhil Goyal cur_td = &list_mcs_err_cipher_vectors[i]; 16607c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1661b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1662b15d5134SAnkur Dwivedi printf("Packet drop case %d skipped", cur_td->test_idx); 1663b15d5134SAnkur Dwivedi skipped += 1; 1664b15d5134SAnkur Dwivedi err = 0; 1665b15d5134SAnkur Dwivedi } else if (err) { 16667c3b1decSAkhil Goyal printf("\nPacket drop case %d passed", cur_td->test_idx); 16677c3b1decSAkhil Goyal err = 0; 16687c3b1decSAkhil Goyal } else { 16697c3b1decSAkhil Goyal printf("\nPacket drop case %d failed", cur_td->test_idx); 16707c3b1decSAkhil Goyal err = -1; 16717c3b1decSAkhil Goyal } 16727c3b1decSAkhil Goyal all_err += err; 16737c3b1decSAkhil Goyal } 1674b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1675b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 16767c3b1decSAkhil Goyal 1677b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 16787c3b1decSAkhil Goyal } 16797c3b1decSAkhil Goyal 16807c3b1decSAkhil Goyal static int 168163bf81a6SAnatoly Burakov test_inline_macsec_untagged_rx(void) 16827c3b1decSAkhil Goyal { 16837c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 16847c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 16857c3b1decSAkhil Goyal int err, all_err = 0; 1686b15d5134SAnkur Dwivedi int skipped = 0; 16877c3b1decSAkhil Goyal int i, size; 16887c3b1decSAkhil Goyal 16897c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 16907c3b1decSAkhil Goyal opts.sa_in_use = 1; 16917c3b1decSAkhil Goyal opts.nb_td = 1; 16927c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 16937c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 16947c3b1decSAkhil Goyal opts.check_untagged_rx = 1; 16957c3b1decSAkhil Goyal 16967c3b1decSAkhil Goyal size = (sizeof(list_mcs_untagged_cipher_vectors) / 16977c3b1decSAkhil Goyal sizeof((list_mcs_untagged_cipher_vectors)[0])); 16987c3b1decSAkhil Goyal 16997c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 17007c3b1decSAkhil Goyal cur_td = &list_mcs_untagged_cipher_vectors[i]; 17017c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1702b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1703b15d5134SAnkur Dwivedi skipped += 1; 1704b15d5134SAnkur Dwivedi err = 0; 1705b15d5134SAnkur Dwivedi } else if (err) 17067c3b1decSAkhil Goyal err = 0; 17077c3b1decSAkhil Goyal else 17087c3b1decSAkhil Goyal err = -1; 17097c3b1decSAkhil Goyal 17107c3b1decSAkhil Goyal all_err += err; 17117c3b1decSAkhil Goyal } 17127c3b1decSAkhil Goyal 17137c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD; 17147c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 17157c3b1decSAkhil Goyal cur_td = &list_mcs_untagged_cipher_vectors[i]; 17167c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1717b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1718b15d5134SAnkur Dwivedi skipped += 1; 1719b15d5134SAnkur Dwivedi err = 0; 1720b15d5134SAnkur Dwivedi } else if (err) 17217c3b1decSAkhil Goyal err = 0; 17227c3b1decSAkhil Goyal else 17237c3b1decSAkhil Goyal err = -1; 17247c3b1decSAkhil Goyal 17257c3b1decSAkhil Goyal all_err += err; 17267c3b1decSAkhil Goyal } 1727b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1728b15d5134SAnkur Dwivedi 2 * size + all_err - skipped, -all_err, skipped); 17297c3b1decSAkhil Goyal 1730b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 17317c3b1decSAkhil Goyal } 17327c3b1decSAkhil Goyal 17337c3b1decSAkhil Goyal static int 173463bf81a6SAnatoly Burakov test_inline_macsec_bad_tag_rx(void) 17357c3b1decSAkhil Goyal { 17367c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 17377c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 17387c3b1decSAkhil Goyal int err, all_err = 0; 1739b15d5134SAnkur Dwivedi int skipped = 0; 17407c3b1decSAkhil Goyal int i, size; 17417c3b1decSAkhil Goyal 17427c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 17437c3b1decSAkhil Goyal opts.protect_frames = true; 17447c3b1decSAkhil Goyal opts.sa_in_use = 1; 17457c3b1decSAkhil Goyal opts.nb_td = 1; 17467c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 17477c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 17487c3b1decSAkhil Goyal opts.check_bad_tag_cnt = 1; 17497c3b1decSAkhil Goyal 17507c3b1decSAkhil Goyal size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0])); 17517c3b1decSAkhil Goyal 17527c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 17537c3b1decSAkhil Goyal cur_td = &list_mcs_bad_tag_vectors[i]; 17547c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1755b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1756b15d5134SAnkur Dwivedi skipped += 1; 1757b15d5134SAnkur Dwivedi err = 0; 1758b15d5134SAnkur Dwivedi } else if (err) 17597c3b1decSAkhil Goyal err = -1; 17607c3b1decSAkhil Goyal else 17617c3b1decSAkhil Goyal err = 0; 17627c3b1decSAkhil Goyal 17637c3b1decSAkhil Goyal all_err += err; 17647c3b1decSAkhil Goyal } 17657c3b1decSAkhil Goyal 1766b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1767b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 17687c3b1decSAkhil Goyal 1769b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 17707c3b1decSAkhil Goyal } 17717c3b1decSAkhil Goyal 17727c3b1decSAkhil Goyal static int 177363bf81a6SAnatoly Burakov test_inline_macsec_sa_not_in_use(void) 17747c3b1decSAkhil Goyal { 17757c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 17767c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 17777c3b1decSAkhil Goyal int err, all_err = 0; 1778b15d5134SAnkur Dwivedi int skipped = 0; 17797c3b1decSAkhil Goyal int i, size; 17807c3b1decSAkhil Goyal 17817c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 17827c3b1decSAkhil Goyal opts.protect_frames = true; 17837c3b1decSAkhil Goyal opts.sa_in_use = 0; 17847c3b1decSAkhil Goyal opts.nb_td = 1; 17857c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 17867c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 17877c3b1decSAkhil Goyal opts.check_sa_not_in_use = 1; 17887c3b1decSAkhil Goyal 17897c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 17907c3b1decSAkhil Goyal 17917c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 17927c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 17937c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1794b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1795b15d5134SAnkur Dwivedi skipped += 1; 1796b15d5134SAnkur Dwivedi err = 0; 1797b15d5134SAnkur Dwivedi } else if (err) 17987c3b1decSAkhil Goyal err = -1; 17997c3b1decSAkhil Goyal else 18007c3b1decSAkhil Goyal err = 0; 18017c3b1decSAkhil Goyal 18027c3b1decSAkhil Goyal all_err += err; 18037c3b1decSAkhil Goyal } 18047c3b1decSAkhil Goyal 1805b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1806b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 18077c3b1decSAkhil Goyal 1808b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 18097c3b1decSAkhil Goyal } 18107c3b1decSAkhil Goyal 18117c3b1decSAkhil Goyal static int 181263bf81a6SAnatoly Burakov test_inline_macsec_decap_stats(void) 1813164757d6SAkhil Goyal { 1814164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1815164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1816164757d6SAkhil Goyal int err, all_err = 0; 1817b15d5134SAnkur Dwivedi int skipped = 0; 1818164757d6SAkhil Goyal int i, size; 1819164757d6SAkhil Goyal 1820164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1821164757d6SAkhil Goyal opts.protect_frames = true; 1822164757d6SAkhil Goyal opts.sa_in_use = 1; 1823164757d6SAkhil Goyal opts.nb_td = 1; 1824164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1825164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1826164757d6SAkhil Goyal opts.check_decap_stats = 1; 1827164757d6SAkhil Goyal 1828164757d6SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 1829164757d6SAkhil Goyal 1830164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1831164757d6SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 1832164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1833b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1834b15d5134SAnkur Dwivedi printf("Decap stats case %d skipped\n", cur_td->test_idx); 1835b15d5134SAnkur Dwivedi skipped += 1; 1836b15d5134SAnkur Dwivedi err = 0; 1837b15d5134SAnkur Dwivedi } else if (err) { 1838164757d6SAkhil Goyal printf("\nDecap stats case %d failed", cur_td->test_idx); 1839164757d6SAkhil Goyal err = -1; 1840164757d6SAkhil Goyal } else { 1841164757d6SAkhil Goyal printf("\nDecap stats case %d passed", cur_td->test_idx); 1842164757d6SAkhil Goyal err = 0; 1843164757d6SAkhil Goyal } 1844164757d6SAkhil Goyal all_err += err; 1845164757d6SAkhil Goyal } 1846b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1847b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1848164757d6SAkhil Goyal 1849b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1850164757d6SAkhil Goyal } 1851164757d6SAkhil Goyal 1852164757d6SAkhil Goyal static int 185363bf81a6SAnatoly Burakov test_inline_macsec_verify_only_stats(void) 1854164757d6SAkhil Goyal { 1855164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1856164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1857164757d6SAkhil Goyal int err, all_err = 0; 1858b15d5134SAnkur Dwivedi int skipped = 0; 1859164757d6SAkhil Goyal int i, size; 1860164757d6SAkhil Goyal 1861164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1862164757d6SAkhil Goyal opts.protect_frames = true; 1863164757d6SAkhil Goyal opts.sa_in_use = 1; 1864164757d6SAkhil Goyal opts.nb_td = 1; 1865164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1866164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1867164757d6SAkhil Goyal opts.check_verify_only_stats = 1; 1868164757d6SAkhil Goyal 1869164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 1870164757d6SAkhil Goyal 1871164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1872164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 1873164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 1874b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1875b15d5134SAnkur Dwivedi printf("Verify only stats case %d skipped\n", cur_td->test_idx); 1876b15d5134SAnkur Dwivedi skipped += 1; 1877b15d5134SAnkur Dwivedi err = 0; 1878b15d5134SAnkur Dwivedi } else if (err) { 1879164757d6SAkhil Goyal printf("\nVerify only stats case %d failed", cur_td->test_idx); 1880164757d6SAkhil Goyal err = -1; 1881164757d6SAkhil Goyal } else { 1882164757d6SAkhil Goyal printf("\nVerify only stats case %d Passed", cur_td->test_idx); 1883164757d6SAkhil Goyal err = 0; 1884164757d6SAkhil Goyal } 1885164757d6SAkhil Goyal all_err += err; 1886164757d6SAkhil Goyal } 1887b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1888b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1889164757d6SAkhil Goyal 1890b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1891164757d6SAkhil Goyal } 1892164757d6SAkhil Goyal 1893164757d6SAkhil Goyal static int 189463bf81a6SAnatoly Burakov test_inline_macsec_pkts_invalid_stats(void) 1895164757d6SAkhil Goyal { 1896164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1897164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1898164757d6SAkhil Goyal int err, all_err = 0; 1899b15d5134SAnkur Dwivedi int skipped = 0; 1900164757d6SAkhil Goyal int i, size; 1901164757d6SAkhil Goyal 1902164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 1903164757d6SAkhil Goyal opts.protect_frames = true; 1904164757d6SAkhil Goyal opts.sa_in_use = 1; 1905164757d6SAkhil Goyal opts.nb_td = 1; 1906164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1907164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1908164757d6SAkhil Goyal 1909164757d6SAkhil Goyal size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0])); 1910164757d6SAkhil Goyal 1911164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1912164757d6SAkhil Goyal cur_td = &list_mcs_err_cipher_vectors[i]; 1913164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_DECAP, &opts); 1914b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1915b15d5134SAnkur Dwivedi skipped += 1; 1916b15d5134SAnkur Dwivedi err = 0; 1917b15d5134SAnkur Dwivedi } else if (err) 1918164757d6SAkhil Goyal err = 0; 1919164757d6SAkhil Goyal else 1920164757d6SAkhil Goyal err = -1; 1921164757d6SAkhil Goyal 1922164757d6SAkhil Goyal all_err += err; 1923164757d6SAkhil Goyal } 1924b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1925b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1926b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1927164757d6SAkhil Goyal } 1928164757d6SAkhil Goyal 1929164757d6SAkhil Goyal static int 193063bf81a6SAnatoly Burakov test_inline_macsec_pkts_unchecked_stats(void) 1931164757d6SAkhil Goyal { 1932164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 1933164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 1934164757d6SAkhil Goyal int err, all_err = 0; 1935b15d5134SAnkur Dwivedi int skipped = 0; 1936164757d6SAkhil Goyal int i, size; 1937164757d6SAkhil Goyal 1938164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE; 1939164757d6SAkhil Goyal opts.protect_frames = true; 1940164757d6SAkhil Goyal opts.sa_in_use = 1; 1941164757d6SAkhil Goyal opts.nb_td = 1; 1942164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 1943164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 1944164757d6SAkhil Goyal opts.check_pkts_unchecked_stats = 1; 1945164757d6SAkhil Goyal 1946164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 1947164757d6SAkhil Goyal 1948164757d6SAkhil Goyal for (i = 0; i < size; i++) { 1949164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 1950164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts); 1951b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1952b15d5134SAnkur Dwivedi skipped += 1; 1953b15d5134SAnkur Dwivedi err = 0; 1954b15d5134SAnkur Dwivedi } else if (err) 1955164757d6SAkhil Goyal err = -1; 1956164757d6SAkhil Goyal else 1957164757d6SAkhil Goyal err = 0; 1958164757d6SAkhil Goyal 1959164757d6SAkhil Goyal all_err += err; 1960164757d6SAkhil Goyal } 1961164757d6SAkhil Goyal 1962b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 1963b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 1964b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 1965164757d6SAkhil Goyal } 1966164757d6SAkhil Goyal 1967164757d6SAkhil Goyal static int 196863bf81a6SAnatoly Burakov test_inline_macsec_out_pkts_untagged(void) 19697c3b1decSAkhil Goyal { 19707c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 19717c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 19727c3b1decSAkhil Goyal int err, all_err = 0; 1973b15d5134SAnkur Dwivedi int skipped = 0; 19747c3b1decSAkhil Goyal int i, size; 19757c3b1decSAkhil Goyal 19767c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 19777c3b1decSAkhil Goyal opts.encrypt = false; 19787c3b1decSAkhil Goyal opts.protect_frames = false; 19797c3b1decSAkhil Goyal opts.sa_in_use = 1; 19807c3b1decSAkhil Goyal opts.nb_td = 1; 19817c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 19827c3b1decSAkhil Goyal opts.mtu = RTE_ETHER_MTU; 19837c3b1decSAkhil Goyal opts.check_out_pkts_untagged = 1; 19847c3b1decSAkhil Goyal 19857c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 19867c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 19877c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 19887c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 1989b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 1990b15d5134SAnkur Dwivedi skipped += 1; 1991b15d5134SAnkur Dwivedi err = 0; 1992b15d5134SAnkur Dwivedi } else if (err) 19937c3b1decSAkhil Goyal err = -1; 19947c3b1decSAkhil Goyal else 19957c3b1decSAkhil Goyal err = 0; 19967c3b1decSAkhil Goyal 19977c3b1decSAkhil Goyal all_err += err; 19987c3b1decSAkhil Goyal } 19997c3b1decSAkhil Goyal 2000b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2001b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 2002b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 20037c3b1decSAkhil Goyal } 20047c3b1decSAkhil Goyal 20057c3b1decSAkhil Goyal static int 200663bf81a6SAnatoly Burakov test_inline_macsec_out_pkts_toolong(void) 20077c3b1decSAkhil Goyal { 20087c3b1decSAkhil Goyal const struct mcs_test_vector *cur_td; 20097c3b1decSAkhil Goyal struct mcs_test_opts opts = {0}; 20107c3b1decSAkhil Goyal int err, all_err = 0; 2011b15d5134SAnkur Dwivedi int skipped = 0; 20127c3b1decSAkhil Goyal int i, size; 20137c3b1decSAkhil Goyal 20147c3b1decSAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD; 20157c3b1decSAkhil Goyal opts.encrypt = true; 20167c3b1decSAkhil Goyal opts.protect_frames = true; 20177c3b1decSAkhil Goyal opts.sa_in_use = 1; 20187c3b1decSAkhil Goyal opts.nb_td = 1; 20197c3b1decSAkhil Goyal opts.sectag_insert_mode = 1; 20207c3b1decSAkhil Goyal opts.mtu = 50; 20217c3b1decSAkhil Goyal opts.check_out_pkts_toolong = 1; 20227c3b1decSAkhil Goyal 20237c3b1decSAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 20247c3b1decSAkhil Goyal for (i = 0; i < size; i++) { 20257c3b1decSAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 20267c3b1decSAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 2027b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2028b15d5134SAnkur Dwivedi skipped += 1; 2029b15d5134SAnkur Dwivedi err = 0; 2030b15d5134SAnkur Dwivedi } else if (err) 20317c3b1decSAkhil Goyal err = -1; 20327c3b1decSAkhil Goyal else 20337c3b1decSAkhil Goyal err = 0; 20347c3b1decSAkhil Goyal 20357c3b1decSAkhil Goyal all_err += err; 20367c3b1decSAkhil Goyal } 20377c3b1decSAkhil Goyal 2038b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2039b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 2040b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 20417c3b1decSAkhil Goyal } 20427c3b1decSAkhil Goyal 20437c3b1decSAkhil Goyal static int 204463bf81a6SAnatoly Burakov test_inline_macsec_encap_stats(void) 2045164757d6SAkhil Goyal { 2046164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 2047164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 2048164757d6SAkhil Goyal int err, all_err = 0; 2049b15d5134SAnkur Dwivedi int skipped = 0; 2050164757d6SAkhil Goyal int i, size; 2051164757d6SAkhil Goyal 2052164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 2053164757d6SAkhil Goyal opts.encrypt = true; 2054164757d6SAkhil Goyal opts.protect_frames = true; 2055164757d6SAkhil Goyal opts.sa_in_use = 1; 2056164757d6SAkhil Goyal opts.nb_td = 1; 2057164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 2058164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 2059164757d6SAkhil Goyal opts.check_encap_stats = 1; 2060164757d6SAkhil Goyal 2061164757d6SAkhil Goyal size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0])); 2062164757d6SAkhil Goyal for (i = 0; i < size; i++) { 2063164757d6SAkhil Goyal cur_td = &list_mcs_cipher_vectors[i]; 2064164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 2065b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2066b15d5134SAnkur Dwivedi skipped += 1; 2067b15d5134SAnkur Dwivedi err = 0; 2068b15d5134SAnkur Dwivedi } else if (err) 2069164757d6SAkhil Goyal err = -1; 2070164757d6SAkhil Goyal else 2071164757d6SAkhil Goyal err = 0; 2072b15d5134SAnkur Dwivedi 2073164757d6SAkhil Goyal all_err += err; 2074164757d6SAkhil Goyal } 2075164757d6SAkhil Goyal 2076b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2077b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 2078b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 2079164757d6SAkhil Goyal } 2080164757d6SAkhil Goyal 2081164757d6SAkhil Goyal static int 208263bf81a6SAnatoly Burakov test_inline_macsec_auth_only_stats(void) 2083164757d6SAkhil Goyal { 2084164757d6SAkhil Goyal const struct mcs_test_vector *cur_td; 2085164757d6SAkhil Goyal struct mcs_test_opts opts = {0}; 2086164757d6SAkhil Goyal int err, all_err = 0; 2087b15d5134SAnkur Dwivedi int skipped = 0; 2088164757d6SAkhil Goyal int i, size; 2089164757d6SAkhil Goyal 2090164757d6SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 2091164757d6SAkhil Goyal opts.protect_frames = true; 2092164757d6SAkhil Goyal opts.sa_in_use = 1; 2093164757d6SAkhil Goyal opts.nb_td = 1; 2094164757d6SAkhil Goyal opts.sectag_insert_mode = 1; 2095164757d6SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 2096164757d6SAkhil Goyal opts.check_auth_only_stats = 1; 2097164757d6SAkhil Goyal 2098164757d6SAkhil Goyal size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0])); 2099164757d6SAkhil Goyal 2100164757d6SAkhil Goyal for (i = 0; i < size; i++) { 2101164757d6SAkhil Goyal cur_td = &list_mcs_integrity_vectors[i]; 2102164757d6SAkhil Goyal err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts); 2103b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2104b15d5134SAnkur Dwivedi skipped += 1; 2105b15d5134SAnkur Dwivedi err = 0; 2106b15d5134SAnkur Dwivedi } else if (err) 2107164757d6SAkhil Goyal err = -1; 2108164757d6SAkhil Goyal else 2109164757d6SAkhil Goyal err = 0; 2110b15d5134SAnkur Dwivedi 2111164757d6SAkhil Goyal all_err += err; 2112164757d6SAkhil Goyal } 2113164757d6SAkhil Goyal 2114b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2115b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 2116b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 2117164757d6SAkhil Goyal } 2118164757d6SAkhil Goyal 2119164757d6SAkhil Goyal static int 212063bf81a6SAnatoly Burakov test_inline_macsec_interrupts_all(void) 2121339b9354SAnkur Dwivedi { 2122339b9354SAnkur Dwivedi struct mcs_err_vector err_vector = {0}; 2123339b9354SAnkur Dwivedi const struct mcs_test_vector *cur_td; 2124339b9354SAnkur Dwivedi struct mcs_test_opts opts = {0}; 2125b15d5134SAnkur Dwivedi int skipped = 0; 2126339b9354SAnkur Dwivedi int i, size; 2127339b9354SAnkur Dwivedi int err, all_err = 0; 2128339b9354SAnkur Dwivedi enum rte_eth_event_macsec_subtype subtype[] = { 2129339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1, 2130339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1, 2131339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48, 2132339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1, 2133339b9354SAnkur Dwivedi RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1, 2134339b9354SAnkur Dwivedi }; 2135339b9354SAnkur Dwivedi 2136339b9354SAnkur Dwivedi opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 2137339b9354SAnkur Dwivedi opts.protect_frames = true; 2138339b9354SAnkur Dwivedi opts.sa_in_use = 1; 2139339b9354SAnkur Dwivedi opts.nb_td = 1; 2140339b9354SAnkur Dwivedi opts.sectag_insert_mode = 1; 2141339b9354SAnkur Dwivedi opts.mtu = RTE_ETHER_MTU; 2142339b9354SAnkur Dwivedi opts.check_sectag_interrupts = 1; 2143339b9354SAnkur Dwivedi 2144339b9354SAnkur Dwivedi err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN; 2145339b9354SAnkur Dwivedi err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN; 2146339b9354SAnkur Dwivedi rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC, 2147339b9354SAnkur Dwivedi test_macsec_event_callback, &err_vector); 2148339b9354SAnkur Dwivedi 2149339b9354SAnkur Dwivedi size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0])); 2150339b9354SAnkur Dwivedi 2151339b9354SAnkur Dwivedi for (i = 0; i < size; i++) { 2152339b9354SAnkur Dwivedi cur_td = &list_mcs_intr_test_vectors[i]; 2153339b9354SAnkur Dwivedi err = test_macsec(&cur_td, MCS_DECAP, &opts); 2154b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2155b15d5134SAnkur Dwivedi printf("Sectag val err interrupt test case %d skipped", 2156b15d5134SAnkur Dwivedi cur_td->test_idx); 2157b15d5134SAnkur Dwivedi skipped += 1; 2158b15d5134SAnkur Dwivedi err = 0; 2159b15d5134SAnkur Dwivedi } else if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) && 2160339b9354SAnkur Dwivedi (err_vector.event_subtype == subtype[i])) { 2161339b9354SAnkur Dwivedi printf("\nSectag val err interrupt test case %d passed", 2162339b9354SAnkur Dwivedi cur_td->test_idx); 2163339b9354SAnkur Dwivedi err = 0; 2164339b9354SAnkur Dwivedi } else { 2165339b9354SAnkur Dwivedi printf("\nSectag val err interrupt test case %d failed", 2166339b9354SAnkur Dwivedi cur_td->test_idx); 2167339b9354SAnkur Dwivedi err = -1; 2168339b9354SAnkur Dwivedi } 2169339b9354SAnkur Dwivedi all_err += err; 2170339b9354SAnkur Dwivedi } 2171339b9354SAnkur Dwivedi rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC, 2172339b9354SAnkur Dwivedi test_macsec_event_callback, &err_vector); 2173339b9354SAnkur Dwivedi 2174b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2175b15d5134SAnkur Dwivedi size + all_err - skipped, -all_err, skipped); 2176b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 2177339b9354SAnkur Dwivedi } 2178339b9354SAnkur Dwivedi 2179339b9354SAnkur Dwivedi static int 218063bf81a6SAnatoly Burakov test_inline_macsec_rekey_tx(void) 2181ad344741SAkhil Goyal { 2182ad344741SAkhil Goyal const struct mcs_test_vector *cur_td; 2183ad344741SAkhil Goyal struct mcs_test_opts opts = {0}; 2184ad344741SAkhil Goyal int err, all_err = 0; 2185b15d5134SAnkur Dwivedi int skipped = 0; 2186ad344741SAkhil Goyal int i, size; 2187ad344741SAkhil Goyal 2188ad344741SAkhil Goyal opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 2189ad344741SAkhil Goyal opts.protect_frames = true; 2190ad344741SAkhil Goyal opts.encrypt = true; 2191ad344741SAkhil Goyal opts.sa_in_use = 1; 2192ad344741SAkhil Goyal opts.nb_td = 1; 2193ad344741SAkhil Goyal opts.sectag_insert_mode = 1; 2194ad344741SAkhil Goyal opts.mtu = RTE_ETHER_MTU; 2195ad344741SAkhil Goyal opts.rekey_en = 1; 2196ad344741SAkhil Goyal 2197ad344741SAkhil Goyal size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0])); 2198ad344741SAkhil Goyal 2199ad344741SAkhil Goyal for (i = 0; i < size; i++) { 2200ad344741SAkhil Goyal cur_td = &list_mcs_rekey_vectors[i]; 2201ad344741SAkhil Goyal opts.rekey_td = &list_mcs_rekey_vectors[++i]; 2202ad344741SAkhil Goyal err = test_macsec(&cur_td, MCS_ENCAP, &opts); 2203b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2204b15d5134SAnkur Dwivedi printf("Tx hw rekey test case %d skipped\n", i); 2205b15d5134SAnkur Dwivedi skipped += 1; 2206b15d5134SAnkur Dwivedi err = 0; 2207b15d5134SAnkur Dwivedi } else if (err) { 2208ad344741SAkhil Goyal printf("Tx hw rekey test case %d failed\n", i); 2209ad344741SAkhil Goyal err = -1; 2210ad344741SAkhil Goyal } else { 2211ad344741SAkhil Goyal printf("Tx hw rekey test case %d passed\n", i); 2212ad344741SAkhil Goyal err = 0; 2213ad344741SAkhil Goyal } 2214ad344741SAkhil Goyal all_err += err; 2215ad344741SAkhil Goyal } 2216ad344741SAkhil Goyal 2217b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2218b15d5134SAnkur Dwivedi size / 2 + all_err - skipped, -all_err, skipped); 2219b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 2220ad344741SAkhil Goyal } 2221ad344741SAkhil Goyal 2222ad344741SAkhil Goyal static int 222363bf81a6SAnatoly Burakov test_inline_macsec_rekey_rx(void) 22244885ba24SAnkur Dwivedi { 22254885ba24SAnkur Dwivedi const struct mcs_test_vector *cur_td; 22264885ba24SAnkur Dwivedi struct mcs_test_opts opts = {0}; 22274885ba24SAnkur Dwivedi int err, all_err = 0; 2228b15d5134SAnkur Dwivedi int skipped = 0; 22294885ba24SAnkur Dwivedi int i, size; 22304885ba24SAnkur Dwivedi 22314885ba24SAnkur Dwivedi opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 22324885ba24SAnkur Dwivedi opts.protect_frames = true; 22334885ba24SAnkur Dwivedi opts.sa_in_use = 1; 22344885ba24SAnkur Dwivedi opts.nb_td = 1; 22354885ba24SAnkur Dwivedi opts.sectag_insert_mode = 1; 22364885ba24SAnkur Dwivedi opts.mtu = RTE_ETHER_MTU; 22374885ba24SAnkur Dwivedi opts.rekey_en = 1; 22384885ba24SAnkur Dwivedi 22394885ba24SAnkur Dwivedi size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0])); 22404885ba24SAnkur Dwivedi for (i = 0; i < size; i++) { 22414885ba24SAnkur Dwivedi cur_td = &list_mcs_rekey_vectors[i]; 22424885ba24SAnkur Dwivedi opts.rekey_td = &list_mcs_rekey_vectors[++i]; 22434885ba24SAnkur Dwivedi err = test_macsec(&cur_td, MCS_DECAP, &opts); 2244b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2245b15d5134SAnkur Dwivedi printf("Rx rekey test case %d skipped\n", i); 2246b15d5134SAnkur Dwivedi skipped += 1; 2247b15d5134SAnkur Dwivedi err = 0; 2248b15d5134SAnkur Dwivedi } else if (err) { 22494885ba24SAnkur Dwivedi printf("Rx rekey test case %d failed\n", i); 22504885ba24SAnkur Dwivedi err = -1; 22514885ba24SAnkur Dwivedi } else { 22524885ba24SAnkur Dwivedi printf("Rx rekey test case %d passed\n", i); 22534885ba24SAnkur Dwivedi err = 0; 22544885ba24SAnkur Dwivedi } 22554885ba24SAnkur Dwivedi all_err += err; 22564885ba24SAnkur Dwivedi } 22574885ba24SAnkur Dwivedi 2258b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2259b15d5134SAnkur Dwivedi size / 2 + all_err - skipped, -all_err, skipped); 2260b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 22614885ba24SAnkur Dwivedi } 22624885ba24SAnkur Dwivedi 22634885ba24SAnkur Dwivedi static int 226463bf81a6SAnatoly Burakov test_inline_macsec_anti_replay(void) 22652a3a153eSAnkur Dwivedi { 22662a3a153eSAnkur Dwivedi const struct mcs_test_vector *cur_td; 22672a3a153eSAnkur Dwivedi struct mcs_test_opts opts = {0}; 22682a3a153eSAnkur Dwivedi uint16_t replay_win_sz[2] = {32, 0}; 22692a3a153eSAnkur Dwivedi int err, all_err = 0; 2270b15d5134SAnkur Dwivedi int skipped = 0; 22712a3a153eSAnkur Dwivedi int i, size; 22722a3a153eSAnkur Dwivedi int j; 22732a3a153eSAnkur Dwivedi 22742a3a153eSAnkur Dwivedi opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT; 22752a3a153eSAnkur Dwivedi opts.sa_in_use = 1; 22762a3a153eSAnkur Dwivedi opts.nb_td = 1; 22772a3a153eSAnkur Dwivedi opts.sectag_insert_mode = 1; 22782a3a153eSAnkur Dwivedi opts.replay_protect = 1; 22792a3a153eSAnkur Dwivedi 22802a3a153eSAnkur Dwivedi size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0])); 22812a3a153eSAnkur Dwivedi 22822a3a153eSAnkur Dwivedi for (j = 0; j < 2; j++) { 22832a3a153eSAnkur Dwivedi opts.replay_win_sz = replay_win_sz[j]; 22842a3a153eSAnkur Dwivedi 22852a3a153eSAnkur Dwivedi for (i = 0; i < size; i++) { 22862a3a153eSAnkur Dwivedi cur_td = &list_mcs_anti_replay_vectors[i]; 22872a3a153eSAnkur Dwivedi opts.ar_td[0] = &list_mcs_anti_replay_vectors[++i]; 22882a3a153eSAnkur Dwivedi opts.ar_td[1] = &list_mcs_anti_replay_vectors[++i]; 22892a3a153eSAnkur Dwivedi opts.ar_td[2] = &list_mcs_anti_replay_vectors[++i]; 22902a3a153eSAnkur Dwivedi err = test_macsec(&cur_td, MCS_DECAP, &opts); 2291b15d5134SAnkur Dwivedi if (err == TEST_SKIPPED) { 2292b15d5134SAnkur Dwivedi printf("Replay window: %u, Anti replay test " 2293b15d5134SAnkur Dwivedi "case %d skipped\n", opts.replay_win_sz, 2294b15d5134SAnkur Dwivedi i); 2295b15d5134SAnkur Dwivedi skipped += 1; 2296b15d5134SAnkur Dwivedi err = 0; 2297b15d5134SAnkur Dwivedi } else if (err) { 2298b15d5134SAnkur Dwivedi printf("Replay window: %u, Anti replay test " 2299b15d5134SAnkur Dwivedi "case %d failed\n", opts.replay_win_sz, 2300b15d5134SAnkur Dwivedi i); 23012a3a153eSAnkur Dwivedi err = -1; 23022a3a153eSAnkur Dwivedi } else { 2303b15d5134SAnkur Dwivedi printf("Replay window: %u, Anti replay test " 2304b15d5134SAnkur Dwivedi "case %d passed\n", opts.replay_win_sz, 2305b15d5134SAnkur Dwivedi i); 23062a3a153eSAnkur Dwivedi err = 0; 23072a3a153eSAnkur Dwivedi } 23082a3a153eSAnkur Dwivedi all_err += err; 23092a3a153eSAnkur Dwivedi } 23102a3a153eSAnkur Dwivedi } 23112a3a153eSAnkur Dwivedi 2312b15d5134SAnkur Dwivedi printf("\n%s: Success: %d, Failure: %d, Skipped: %d\n", __func__, 2313b15d5134SAnkur Dwivedi size / 2 + all_err - skipped, -all_err, skipped); 2314b15d5134SAnkur Dwivedi return skipped > 0 ? TEST_SKIPPED : all_err; 23152a3a153eSAnkur Dwivedi } 23162a3a153eSAnkur Dwivedi 23172a3a153eSAnkur Dwivedi static int 2318993ea577SAkhil Goyal ut_setup_inline_macsec(void) 2319993ea577SAkhil Goyal { 2320993ea577SAkhil Goyal int ret; 2321993ea577SAkhil Goyal 2322993ea577SAkhil Goyal /* Start device */ 2323993ea577SAkhil Goyal ret = rte_eth_dev_start(port_id); 2324993ea577SAkhil Goyal if (ret < 0) { 2325993ea577SAkhil Goyal printf("rte_eth_dev_start: err=%d, port=%d\n", 2326993ea577SAkhil Goyal ret, port_id); 2327993ea577SAkhil Goyal return ret; 2328993ea577SAkhil Goyal } 2329993ea577SAkhil Goyal /* always enable promiscuous */ 2330993ea577SAkhil Goyal ret = rte_eth_promiscuous_enable(port_id); 2331993ea577SAkhil Goyal if (ret != 0) { 2332993ea577SAkhil Goyal printf("rte_eth_promiscuous_enable: err=%s, port=%d\n", 2333993ea577SAkhil Goyal rte_strerror(-ret), port_id); 2334993ea577SAkhil Goyal return ret; 2335993ea577SAkhil Goyal } 2336993ea577SAkhil Goyal 2337993ea577SAkhil Goyal check_all_ports_link_status(1, RTE_PORT_ALL); 2338993ea577SAkhil Goyal 2339993ea577SAkhil Goyal return 0; 2340993ea577SAkhil Goyal } 2341993ea577SAkhil Goyal 2342993ea577SAkhil Goyal static void 2343993ea577SAkhil Goyal ut_teardown_inline_macsec(void) 2344993ea577SAkhil Goyal { 2345993ea577SAkhil Goyal uint16_t portid; 2346993ea577SAkhil Goyal int ret; 2347993ea577SAkhil Goyal 2348993ea577SAkhil Goyal /* port tear down */ 2349993ea577SAkhil Goyal RTE_ETH_FOREACH_DEV(portid) { 2350993ea577SAkhil Goyal ret = rte_eth_dev_stop(portid); 2351993ea577SAkhil Goyal if (ret != 0) 2352993ea577SAkhil Goyal printf("rte_eth_dev_stop: err=%s, port=%u\n", 2353993ea577SAkhil Goyal rte_strerror(-ret), portid); 2354993ea577SAkhil Goyal 2355993ea577SAkhil Goyal } 2356993ea577SAkhil Goyal } 2357993ea577SAkhil Goyal 2358993ea577SAkhil Goyal static int 2359993ea577SAkhil Goyal inline_macsec_testsuite_setup(void) 2360993ea577SAkhil Goyal { 2361993ea577SAkhil Goyal uint16_t nb_rxd; 2362993ea577SAkhil Goyal uint16_t nb_txd; 2363993ea577SAkhil Goyal uint16_t nb_ports; 2364993ea577SAkhil Goyal int ret; 2365993ea577SAkhil Goyal uint16_t nb_rx_queue = 1, nb_tx_queue = 1; 2366993ea577SAkhil Goyal 2367993ea577SAkhil Goyal printf("Start inline MACsec test.\n"); 2368993ea577SAkhil Goyal 2369993ea577SAkhil Goyal nb_ports = rte_eth_dev_count_avail(); 2370993ea577SAkhil Goyal if (nb_ports < NB_ETHPORTS_USED) { 2371993ea577SAkhil Goyal printf("At least %u port(s) used for test\n", 2372993ea577SAkhil Goyal NB_ETHPORTS_USED); 2373993ea577SAkhil Goyal return TEST_SKIPPED; 2374993ea577SAkhil Goyal } 2375993ea577SAkhil Goyal 2376993ea577SAkhil Goyal ret = init_mempools(NB_MBUF); 2377993ea577SAkhil Goyal if (ret) 2378993ea577SAkhil Goyal return ret; 2379993ea577SAkhil Goyal 2380993ea577SAkhil Goyal if (tx_pkts_burst == NULL) { 2381993ea577SAkhil Goyal tx_pkts_burst = (struct rte_mbuf **)rte_calloc("tx_buff", 2382993ea577SAkhil Goyal MAX_TRAFFIC_BURST, 2383993ea577SAkhil Goyal sizeof(void *), 2384993ea577SAkhil Goyal RTE_CACHE_LINE_SIZE); 2385993ea577SAkhil Goyal if (!tx_pkts_burst) 2386993ea577SAkhil Goyal return TEST_FAILED; 2387993ea577SAkhil Goyal 2388993ea577SAkhil Goyal rx_pkts_burst = (struct rte_mbuf **)rte_calloc("rx_buff", 2389993ea577SAkhil Goyal MAX_TRAFFIC_BURST, 2390993ea577SAkhil Goyal sizeof(void *), 2391993ea577SAkhil Goyal RTE_CACHE_LINE_SIZE); 2392993ea577SAkhil Goyal if (!rx_pkts_burst) 2393993ea577SAkhil Goyal return TEST_FAILED; 2394993ea577SAkhil Goyal } 2395993ea577SAkhil Goyal 2396993ea577SAkhil Goyal printf("Generate %d packets\n", MAX_TRAFFIC_BURST); 2397993ea577SAkhil Goyal 2398993ea577SAkhil Goyal nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 2399993ea577SAkhil Goyal nb_txd = RTE_TEST_TX_DESC_DEFAULT; 2400993ea577SAkhil Goyal 2401993ea577SAkhil Goyal /* configuring port 0 for the test is enough */ 2402993ea577SAkhil Goyal port_id = 0; 2403993ea577SAkhil Goyal /* port configure */ 2404993ea577SAkhil Goyal ret = rte_eth_dev_configure(port_id, nb_rx_queue, 2405993ea577SAkhil Goyal nb_tx_queue, &port_conf); 2406993ea577SAkhil Goyal if (ret < 0) { 2407993ea577SAkhil Goyal printf("Cannot configure device: err=%d, port=%d\n", 2408993ea577SAkhil Goyal ret, port_id); 2409993ea577SAkhil Goyal return ret; 2410993ea577SAkhil Goyal } 2411993ea577SAkhil Goyal ret = rte_eth_macaddr_get(port_id, &ports_eth_addr[port_id]); 2412993ea577SAkhil Goyal if (ret < 0) { 2413993ea577SAkhil Goyal printf("Cannot get mac address: err=%d, port=%d\n", 2414993ea577SAkhil Goyal ret, port_id); 2415993ea577SAkhil Goyal return ret; 2416993ea577SAkhil Goyal } 2417993ea577SAkhil Goyal printf("Port %u ", port_id); 2418993ea577SAkhil Goyal print_ethaddr("Address:", &ports_eth_addr[port_id]); 2419993ea577SAkhil Goyal printf("\n"); 2420993ea577SAkhil Goyal 2421993ea577SAkhil Goyal /* tx queue setup */ 2422993ea577SAkhil Goyal ret = rte_eth_tx_queue_setup(port_id, 0, nb_txd, 2423993ea577SAkhil Goyal SOCKET_ID_ANY, &tx_conf); 2424993ea577SAkhil Goyal if (ret < 0) { 2425993ea577SAkhil Goyal printf("rte_eth_tx_queue_setup: err=%d, port=%d\n", 2426993ea577SAkhil Goyal ret, port_id); 2427993ea577SAkhil Goyal return ret; 2428993ea577SAkhil Goyal } 2429993ea577SAkhil Goyal /* rx queue steup */ 2430993ea577SAkhil Goyal ret = rte_eth_rx_queue_setup(port_id, 0, nb_rxd, SOCKET_ID_ANY, 2431993ea577SAkhil Goyal &rx_conf, mbufpool); 2432993ea577SAkhil Goyal if (ret < 0) { 2433993ea577SAkhil Goyal printf("rte_eth_rx_queue_setup: err=%d, port=%d\n", 2434993ea577SAkhil Goyal ret, port_id); 2435993ea577SAkhil Goyal return ret; 2436993ea577SAkhil Goyal } 2437993ea577SAkhil Goyal 2438993ea577SAkhil Goyal return 0; 2439993ea577SAkhil Goyal } 2440993ea577SAkhil Goyal 2441993ea577SAkhil Goyal static void 2442993ea577SAkhil Goyal inline_macsec_testsuite_teardown(void) 2443993ea577SAkhil Goyal { 2444993ea577SAkhil Goyal uint16_t portid; 2445993ea577SAkhil Goyal int ret; 2446993ea577SAkhil Goyal 2447993ea577SAkhil Goyal /* port tear down */ 2448993ea577SAkhil Goyal RTE_ETH_FOREACH_DEV(portid) { 2449993ea577SAkhil Goyal ret = rte_eth_dev_reset(portid); 2450993ea577SAkhil Goyal if (ret != 0) 2451993ea577SAkhil Goyal printf("rte_eth_dev_reset: err=%s, port=%u\n", 2452993ea577SAkhil Goyal rte_strerror(-ret), port_id); 2453993ea577SAkhil Goyal } 2454993ea577SAkhil Goyal rte_free(tx_pkts_burst); 2455993ea577SAkhil Goyal rte_free(rx_pkts_burst); 2456993ea577SAkhil Goyal } 2457993ea577SAkhil Goyal 2458993ea577SAkhil Goyal 2459993ea577SAkhil Goyal static struct unit_test_suite inline_macsec_testsuite = { 2460993ea577SAkhil Goyal .suite_name = "Inline MACsec Ethernet Device Unit Test Suite", 2461993ea577SAkhil Goyal .unit_test_cases = { 2462993ea577SAkhil Goyal TEST_CASE_NAMED_ST( 2463e3d83ea4SAkhil Goyal "MACsec Encap + decap Multi flow", 2464e3d83ea4SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2465e3d83ea4SAkhil Goyal test_inline_macsec_multi_flow), 2466e3d83ea4SAkhil Goyal TEST_CASE_NAMED_ST( 2467993ea577SAkhil Goyal "MACsec encap(Cipher+Auth) known vector", 2468993ea577SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2469993ea577SAkhil Goyal test_inline_macsec_encap_all), 2470993ea577SAkhil Goyal TEST_CASE_NAMED_ST( 2471993ea577SAkhil Goyal "MACsec decap(De-cipher+verify) known vector", 2472993ea577SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2473993ea577SAkhil Goyal test_inline_macsec_decap_all), 24742da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 24752da0c0a7SAkhil Goyal "MACsec auth only known vector", 24762da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 24772da0c0a7SAkhil Goyal test_inline_macsec_auth_only_all), 24782da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 24792da0c0a7SAkhil Goyal "MACsec verify only known vector", 24802da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 24812da0c0a7SAkhil Goyal test_inline_macsec_verify_only_all), 24822da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 24832da0c0a7SAkhil Goyal "MACsec encap + decap known vector", 24842da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 24852da0c0a7SAkhil Goyal test_inline_macsec_encap_decap_all), 24862da0c0a7SAkhil Goyal TEST_CASE_NAMED_ST( 24872da0c0a7SAkhil Goyal "MACsec auth + verify known vector", 24882da0c0a7SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 24892da0c0a7SAkhil Goyal test_inline_macsec_auth_verify_all), 2490e67246cbSAkhil Goyal TEST_CASE_NAMED_ST( 2491e67246cbSAkhil Goyal "MACsec Encap and decap with VLAN", 2492e67246cbSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2493e67246cbSAkhil Goyal test_inline_macsec_with_vlan), 24947c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 24957c3b1decSAkhil Goyal "MACsec packet drop", 24967c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 24977c3b1decSAkhil Goyal test_inline_macsec_pkt_drop), 24987c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 24997c3b1decSAkhil Goyal "MACsec untagged Rx", 25007c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 25017c3b1decSAkhil Goyal test_inline_macsec_untagged_rx), 25027c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 25037c3b1decSAkhil Goyal "MACsec bad tag Rx", 25047c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 25057c3b1decSAkhil Goyal test_inline_macsec_bad_tag_rx), 25067c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 25077c3b1decSAkhil Goyal "MACsec SA not in use", 25087c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 25097c3b1decSAkhil Goyal test_inline_macsec_sa_not_in_use), 25107c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 2511164757d6SAkhil Goyal "MACsec decap stats", 2512164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2513164757d6SAkhil Goyal test_inline_macsec_decap_stats), 2514164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2515164757d6SAkhil Goyal "MACsec verify only stats", 2516164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2517164757d6SAkhil Goyal test_inline_macsec_verify_only_stats), 2518164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2519164757d6SAkhil Goyal "MACsec pkts invalid stats", 2520164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2521164757d6SAkhil Goyal test_inline_macsec_pkts_invalid_stats), 2522164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2523164757d6SAkhil Goyal "MACsec pkts unchecked stats", 2524164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2525164757d6SAkhil Goyal test_inline_macsec_pkts_unchecked_stats), 2526164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 25277c3b1decSAkhil Goyal "MACsec out pkts untagged", 25287c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 25297c3b1decSAkhil Goyal test_inline_macsec_out_pkts_untagged), 25307c3b1decSAkhil Goyal TEST_CASE_NAMED_ST( 25317c3b1decSAkhil Goyal "MACsec out pkts too long", 25327c3b1decSAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 25337c3b1decSAkhil Goyal test_inline_macsec_out_pkts_toolong), 2534164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2535164757d6SAkhil Goyal "MACsec Encap stats", 2536164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2537164757d6SAkhil Goyal test_inline_macsec_encap_stats), 2538164757d6SAkhil Goyal TEST_CASE_NAMED_ST( 2539164757d6SAkhil Goyal "MACsec auth only stats", 2540164757d6SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2541164757d6SAkhil Goyal test_inline_macsec_auth_only_stats), 2542339b9354SAnkur Dwivedi TEST_CASE_NAMED_ST( 2543339b9354SAnkur Dwivedi "MACsec interrupts all", 2544339b9354SAnkur Dwivedi ut_setup_inline_macsec, ut_teardown_inline_macsec, 2545339b9354SAnkur Dwivedi test_inline_macsec_interrupts_all), 2546ad344741SAkhil Goyal TEST_CASE_NAMED_ST( 2547ad344741SAkhil Goyal "MACsec re-key Tx", 2548ad344741SAkhil Goyal ut_setup_inline_macsec, ut_teardown_inline_macsec, 2549ad344741SAkhil Goyal test_inline_macsec_rekey_tx), 25504885ba24SAnkur Dwivedi TEST_CASE_NAMED_ST( 25514885ba24SAnkur Dwivedi "MACsec re-key Rx", 25524885ba24SAnkur Dwivedi ut_setup_inline_macsec, ut_teardown_inline_macsec, 25534885ba24SAnkur Dwivedi test_inline_macsec_rekey_rx), 25542a3a153eSAnkur Dwivedi TEST_CASE_NAMED_ST( 25552a3a153eSAnkur Dwivedi "MACsec anti-replay", 25562a3a153eSAnkur Dwivedi ut_setup_inline_macsec, ut_teardown_inline_macsec, 25572a3a153eSAnkur Dwivedi test_inline_macsec_anti_replay), 2558993ea577SAkhil Goyal 2559993ea577SAkhil Goyal TEST_CASES_END() /**< NULL terminate unit test array */ 2560993ea577SAkhil Goyal }, 2561993ea577SAkhil Goyal }; 2562993ea577SAkhil Goyal 2563993ea577SAkhil Goyal static int 2564993ea577SAkhil Goyal test_inline_macsec(void) 2565993ea577SAkhil Goyal { 2566993ea577SAkhil Goyal inline_macsec_testsuite.setup = inline_macsec_testsuite_setup; 2567993ea577SAkhil Goyal inline_macsec_testsuite.teardown = inline_macsec_testsuite_teardown; 2568993ea577SAkhil Goyal return unit_test_suite_runner(&inline_macsec_testsuite); 2569993ea577SAkhil Goyal } 2570993ea577SAkhil Goyal 2571993ea577SAkhil Goyal #endif /* !RTE_EXEC_ENV_WINDOWS */ 2572993ea577SAkhil Goyal 2573993ea577SAkhil Goyal REGISTER_TEST_COMMAND(inline_macsec_autotest, test_inline_macsec); 2574