aboutsummaryrefslogtreecommitdiffstats
path: root/tests/vpp/perf/crypto/10ge2p1x710-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr.robot
blob: 4fe12ae3a8f90f35939d44bb7db4d8ebd1f607fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright (c) 2019 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

*** Settings ***
| Resource | resources/libraries/robot/performance/performance_setup.robot
| Resource | resources/libraries/robot/crypto/ipsec.robot
| ...
| Force Tags | 3_NODE_SINGLE_LINK_TOPO | PERFTEST | HW_ENV | NDRPDR
| ... | IP4FWD | IPSEC | IPSECHW | IPSECINT | NIC_Intel-X710 | BASE
| ... | AES_128_GCM | AES
| ...
| Suite Setup | Run Keywords
| ... | Set up IPSec performance test suite | L3 | ${nic_name} | HW_DH895xcc
| ... | AND | Set up performance test suite with crypto ipsecmb
| Suite Teardown | Tear down 3-node performance topology
| ...
| Test Setup | Set up performance test
| Test Teardown | Tear down performance test
| ...
| Test Template | Local Template
| ...
| Documentation | *RFC2544: Pkt throughput IPv4 IPsec tunnel mode.*
| ...
| ... | *[Top] Network Topologies:* TG-DUT1-DUT2-TG 3-node circular topology
| ... | with single links between nodes.
| ... | *[Enc] Packet Encapsulations:* Eth-IPv4 on TG-DUTn,
| ... | Eth-IPv4-IPSec on DUT1-DUT2
| ... | *[Cfg] DUT configuration:* DUT1 and DUT2 are configured with multiple
| ... | IPsec tunnels between them. DUTs get IPv4 traffic from TG, encrypt it
| ... | and send to another DUT, where packets are decrypted and sent back to TG
| ... | *[Ver] TG verification:* TG finds and reports throughput NDR (Non Drop\
| ... | Rate) with zero packet loss tolerance and throughput PDR (Partial Drop\
| ... | Rate) with non-zero packet loss tolerance (LT) expressed in percentage\
| ... | of packets transmitted. NDR and PDR are discovered for different\
| ... | Ethernet L2 frame sizes using MLRsearch library.\
| ... | Test packets are generated by TG on
| ... | links to DUTs. TG traffic profile contains two L3 flow-groups
| ... | (flow-group per direction, number of flows per flow-group equals to
| ... | number of IPSec tunnels) with all packets
| ... | containing Ethernet header, IPv4 header with IP protocol=61 and
| ... | static payload. MAC addresses are matching MAC addresses of the TG
| ... | node interfaces. Incrementing of IP.dst (IPv4 destination address) field
| ... | is applied to both streams.
| ... | *[Ref] Applicable standard specifications:* RFC4303 and RFC2544.

*** Variables ***
| ${nic_name}= | Intel-X710
| ${overhead}= | ${54}
| ${tg_if1_ip4}= | 192.168.10.2
| ${dut1_if1_ip4}= | 192.168.10.1
| ${dut1_if2_ip4}= | 100.0.0.1
| ${dut2_if1_ip4}= | 100.0.0.2
| ${dut2_if2_ip4}= | 192.168.20.1
| ${tg_if2_ip4}= | 192.168.20.2
| ${raddr_ip4}= | 20.0.0.0
| ${laddr_ip4}= | 10.0.0.0
| ${addr_range}= | ${24}
| ${n_tunnels}= | ${1}
# Traffic profile:
| ${traffic_profile}= | trex-sl-3n-ethip4-ip4dst${n_tunnels}

*** Keywords ***
| Local Template
| | [Documentation]
| | ... | [Cfg] DUT runs IPSec tunneling AES_128_GCM config.
| | ... | Each DUT uses ${phy_cores} physical core(s) for worker threads.
| | ... | [Ver] Measure NDR and PDR values using MLRsearch algorithm.\
| | ...
| | ... | *Arguments:*
| | ... | - frame_size - Framesize in Bytes in integer or string (IMIX_v4_1).
| | ... | Type: integer, string
| | ... | - phy_cores - Number of physical cores. Type: integer
| | ... | - rxq - Number of RX queues, default value: ${None}. Type: integer
| | ...
| | [Arguments] | ${frame_size} | ${phy_cores} | ${rxq}=${None}
| | ...
| | Set Test Variable | \${frame_size}
| | ...
| | # These are enums (not strings) so they cannot be in Variables table.
| | ${encr_alg}= | Crypto Alg AES GCM 128
| | ${auth_alg}= | Integ Alg AES GCM 128
| | ${ipsec_proto}= | IPsec Proto ESP
| | ...
| | Given Add worker threads and rxqueues to all DUTs | ${phy_cores} | ${rxq}
| | And Add PCI devices to all DUTs
| | Set Max Rate And Jumbo And Handle Multi Seg
| | And Add cryptodev to all DUTs | ${phy_cores}
| | And Apply startup configuration on all VPP DUTs
| | And VPP IPsec Select Backend | ${dut1} | ${ipsec_proto} | index=${1}
| | And VPP IPsec Select Backend | ${dut2} | ${ipsec_proto} | index=${1}
| | And Initialize IPSec in 3-node circular topology
| | And VPP IPsec Create Tunnel Interfaces
| | ... | ${nodes} | ${dut1_if2_ip4} | ${dut2_if1_ip4} | ${dut1_if2}
| | ... | ${dut2_if1} | ${n_tunnels} | ${encr_alg} | ${auth_alg}
| | ... | ${laddr_ip4} | ${raddr_ip4} | ${addr_range}
| | Then Find NDR and PDR intervals using optimized search

*** Test Cases ***
| tc01-64B-1c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 64B | 1C
| | frame_size=${64} | phy_cores=${1}

| tc02-64B-2c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 64B | 2C
| | frame_size=${64} | phy_cores=${2}

| tc03-64B-4c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 64B | 4C
| | frame_size=${64} | phy_cores=${4}

| tc04-1518B-1c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 1518B | 1C
| | frame_size=${1518} | phy_cores=${1}

| tc05-1518B-2c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 1518B | 2C
| | frame_size=${1518} | phy_cores=${2}

| tc06-1518B-4c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 1518B | 4C
| | frame_size=${1518} | phy_cores=${4}

| tc07-9000B-1c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 9000B | 1C
| | frame_size=${9000} | phy_cores=${1}

| tc08-9000B-2c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 9000B | 2C
| | frame_size=${9000} | phy_cores=${2}

| tc09-9000B-4c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | 9000B | 4C
| | frame_size=${9000} | phy_cores=${4}

| tc10-IMIX-1c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | IMIX | 1C
| | frame_size=IMIX_v4_1 | phy_cores=${1}

| tc11-IMIX-2c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | IMIX | 2C
| | frame_size=IMIX_v4_1 | phy_cores=${2}

| tc12-IMIX-4c-ethip4ipsecbasetnl-ip4base-int-aes128gcm-ndrpdr
| | [Tags] | IMIX | 4C
| | frame_size=IMIX_v4_1 | phy_cores=${4}
t; 24) #define RTE_LPM6_TBL8_GROUP_NUM_ENTRIES 256 #define RTE_LPM6_TBL8_MAX_NUM_GROUPS (1 << 21) #define RTE_LPM6_VALID_EXT_ENTRY_BITMASK 0xA0000000 #define RTE_LPM6_LOOKUP_SUCCESS 0x20000000 #define RTE_LPM6_TBL8_BITMASK 0x001FFFFF #define ADD_FIRST_BYTE 3 #define LOOKUP_FIRST_BYTE 4 #define BYTE_SIZE 8 #define BYTES2_SIZE 16 #define lpm6_tbl8_gindex next_hop /** Flags for setting an entry as valid/invalid. */ enum valid_flag { INVALID = 0, VALID }; TAILQ_HEAD(rte_lpm6_list, rte_tailq_entry); static struct rte_tailq_elem rte_lpm6_tailq = { .name = "RTE_LPM6", }; EAL_REGISTER_TAILQ(rte_lpm6_tailq) /** Tbl entry structure. It is the same for both tbl24 and tbl8 */ struct rte_lpm6_tbl_entry { uint32_t next_hop: 21; /**< Next hop / next table to be checked. */ uint32_t depth :8; /**< Rule depth. */ /* Flags. */ uint32_t valid :1; /**< Validation flag. */ uint32_t valid_group :1; /**< Group validation flag. */ uint32_t ext_entry :1; /**< External entry. */ }; /** Rules tbl entry structure. */ struct rte_lpm6_rule { uint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */ uint8_t next_hop; /**< Rule next hop. */ uint8_t depth; /**< Rule depth. */ }; /** LPM6 structure. */ struct rte_lpm6 { /* LPM metadata. */ char name[RTE_LPM6_NAMESIZE]; /**< Name of the lpm. */ uint32_t max_rules; /**< Max number of rules. */ uint32_t used_rules; /**< Used rules so far. */ uint32_t number_tbl8s; /**< Number of tbl8s to allocate. */ uint32_t next_tbl8; /**< Next tbl8 to be used. */ /* LPM Tables. */ struct rte_lpm6_rule *rules_tbl; /**< LPM rules. */ struct rte_lpm6_tbl_entry tbl24[RTE_LPM6_TBL24_NUM_ENTRIES] __rte_cache_aligned; /**< LPM tbl24 table. */ struct rte_lpm6_tbl_entry tbl8[0] __rte_cache_aligned; /**< LPM tbl8 table. */ }; /* * Takes an array of uint8_t (IPv6 address) and masks it using the depth. * It leaves untouched one bit per unit in the depth variable * and set the rest to 0. */ static inline void mask_ip(uint8_t *ip, uint8_t depth) { int16_t part_depth, mask; int i; part_depth = depth; for (i = 0; i < RTE_LPM6_IPV6_ADDR_SIZE; i++) { if (part_depth < BYTE_SIZE && part_depth >= 0) { mask = (uint16_t)(~(UINT8_MAX >> part_depth)); ip[i] = (uint8_t)(ip[i] & mask); } else if (part_depth < 0) { ip[i] = 0; } part_depth -= BYTE_SIZE; } } /* * Allocates memory for LPM object */ struct rte_lpm6 * rte_lpm6_create(const char *name, int socket_id, const struct rte_lpm6_config *config) { char mem_name[RTE_LPM6_NAMESIZE]; struct rte_lpm6 *lpm = NULL; struct rte_tailq_entry *te; uint64_t mem_size, rules_size; struct rte_lpm6_list *lpm_list; lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list); RTE_BUILD_BUG_ON(sizeof(struct rte_lpm6_tbl_entry) != sizeof(uint32_t)); /* Check user arguments. */ if ((name == NULL) || (socket_id < -1) || (config == NULL) || (config->max_rules == 0) || config->number_tbl8s > RTE_LPM6_TBL8_MAX_NUM_GROUPS) { rte_errno = EINVAL; return NULL; } snprintf(mem_name, sizeof(mem_name), "LPM_%s", name); /* Determine the amount of memory to allocate. */ mem_size = sizeof(*lpm) + (sizeof(lpm->tbl8[0]) * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES * config->number_tbl8s); rules_size = sizeof(struct rte_lpm6_rule) * config->max_rules; rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); /* Guarantee there's no existing */ TAILQ_FOREACH(te, lpm_list, next) { lpm = (struct rte_lpm6 *) te->data; if (strncmp(name, lpm->name, RTE_LPM6_NAMESIZE) == 0) break; } lpm = NULL; if (te != NULL) { rte_errno = EEXIST; goto exit; } /* allocate tailq entry */ te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { RTE_LOG(ERR, LPM, "Failed to allocate tailq entry!\n"); goto exit; } /* Allocate memory to store the LPM data structures. */ lpm = (struct rte_lpm6 *)rte_zmalloc_socket(mem_name, (size_t)mem_size, RTE_CACHE_LINE_SIZE, socket_id); if (lpm == NULL) { RTE_LOG(ERR, LPM, "LPM memory allocation failed\n"); rte_free(te); goto exit; } lpm->rules_tbl = (struct rte_lpm6_rule *)rte_zmalloc_socket(NULL, (size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id); if (lpm->rules_tbl == NULL) { RTE_LOG(ERR, LPM, "LPM rules_tbl allocation failed\n"); rte_free(lpm); lpm = NULL; rte_free(te); goto exit; } /* Save user arguments. */ lpm->max_rules = config->max_rules; lpm->number_tbl8s = config->number_tbl8s; snprintf(lpm->name, sizeof(lpm->name), "%s", name); te->data = (void *) lpm; TAILQ_INSERT_TAIL(lpm_list, te, next); exit: rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); return lpm; } /* * Find an existing lpm table and return a pointer to it. */ struct rte_lpm6 * rte_lpm6_find_existing(const char *name) { struct rte_lpm6 *l = NULL; struct rte_tailq_entry *te; struct rte_lpm6_list *lpm_list; lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list); rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); TAILQ_FOREACH(te, lpm_list, next) { l = (struct rte_lpm6 *) te->data; if (strncmp(name, l->name, RTE_LPM6_NAMESIZE) == 0) break; } rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK); if (te == NULL) { rte_errno = ENOENT; return NULL; } return l; } /* * Deallocates memory for given LPM table. */ void rte_lpm6_free(struct rte_lpm6 *lpm) { struct rte_lpm6_list *lpm_list; struct rte_tailq_entry *te; /* Check user arguments. */ if (lpm == NULL) return; lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list); rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK); /* find our tailq entry */ TAILQ_FOREACH(te, lpm_list, next) { if (te->data == (void *) lpm) break; } if (te != NULL) TAILQ_REMOVE(lpm_list, te, next); rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); rte_free(lpm->rules_tbl); rte_free(lpm); rte_free(te); } /* * Checks if a rule already exists in the rules table and updates * the nexthop if so. Otherwise it adds a new rule if enough space is available. */ static inline int32_t rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t next_hop, uint8_t depth) { uint32_t rule_index; /* Scan through rule list to see if rule already exists. */ for (rule_index = 0; rule_index < lpm->used_rules; rule_index++) { /* If rule already exists update its next_hop and return. */ if ((memcmp (lpm->rules_tbl[rule_index].ip, ip, RTE_LPM6_IPV6_ADDR_SIZE) == 0) && lpm->rules_tbl[rule_index].depth == depth) { lpm->rules_tbl[rule_index].next_hop = next_hop; return rule_index; } } /* * If rule does not exist check if there is space to add a new rule to * this rule group. If there is no space return error. */ if (lpm->used_rules == lpm->max_rules) { return -ENOSPC; } /* If there is space for the new rule add it. */ rte_memcpy(lpm->rules_tbl[rule_index].ip, ip, RTE_LPM6_IPV6_ADDR_SIZE); lpm->rules_tbl[rule_index].next_hop = next_hop; lpm->rules_tbl[rule_index].depth = depth; /* Increment the used rules counter for this rule group. */ lpm->used_rules++; return rule_index; } /* * Function that expands a rule across the data structure when a less-generic * one has been added before. It assures that every possible combination of bits * in the IP address returns a match. */ static void expand_rule(struct rte_lpm6 *lpm, uint32_t tbl8_gindex, uint8_t depth, uint8_t next_hop) { uint32_t tbl8_group_end, tbl8_gindex_next, j; tbl8_group_end = tbl8_gindex + RTE_LPM6_TBL8_GROUP_NUM_ENTRIES; struct rte_lpm6_tbl_entry new_tbl8_entry = { .valid = VALID, .valid_group = VALID, .depth = depth, .next_hop = next_hop, .ext_entry = 0, }; for (j = tbl8_gindex; j < tbl8_group_end; j++) { if (!lpm->tbl8[j].valid || (lpm->tbl8[j].ext_entry == 0 && lpm->tbl8[j].depth <= depth)) { lpm->tbl8[j] = new_tbl8_entry; } else if (lpm->tbl8[j].ext_entry == 1) { tbl8_gindex_next = lpm->tbl8[j].lpm6_tbl8_gindex * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES; expand_rule(lpm, tbl8_gindex_next, depth, next_hop); } } } /* * Partially adds a new route to the data structure (tbl24+tbl8s). * It returns 0 on success, a negative number on failure, or 1 if * the process needs to be continued by calling the function again. */ static inline int add_step(struct rte_lpm6 *lpm, struct rte_lpm6_tbl_entry *tbl, struct rte_lpm6_tbl_entry **tbl_next, uint8_t *ip, uint8_t bytes, uint8_t first_byte, uint8_t depth, uint8_t next_hop) { uint32_t tbl_index, tbl_range, tbl8_group_start, tbl8_group_end, i; int32_t tbl8_gindex; int8_t bitshift; uint8_t bits_covered; /* * Calculate index to the table based on the number and position * of the bytes being inspected in this step. */ tbl_index = 0; for (i = first_byte; i < (uint32_t)(first_byte + bytes); i++) { bitshift = (int8_t)((bytes - i)*BYTE_SIZE); if (bitshift < 0) bitshift = 0; tbl_index = tbl_index | ip[i-1] << bitshift; } /* Number of bits covered in this step */ bits_covered = (uint8_t)((bytes+first_byte-1)*BYTE_SIZE); /* * If depth if smaller than this number (ie this is the last step) * expand the rule across the relevant positions in the table. */ if (depth <= bits_covered) { tbl_range = 1 << (bits_covered - depth); for (i = tbl_index; i < (tbl_index + tbl_range); i++) { if (!tbl[i].valid || (tbl[i].ext_entry == 0 && tbl[i].depth <= depth)) { struct rte_lpm6_tbl_entry new_tbl_entry = { .next_hop = next_hop, .depth = depth, .valid = VALID, .valid_group = VALID, .ext_entry = 0, }; tbl[i] = new_tbl_entry; } else if (tbl[i].ext_entry == 1) { /* * If tbl entry is valid and extended calculate the index * into next tbl8 and expand the rule across the data structure. */ tbl8_gindex = tbl[i].lpm6_tbl8_gindex * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES; expand_rule(lpm, tbl8_gindex, depth, next_hop); } } return 0; } /* * If this is not the last step just fill one position * and calculate the index to the next table. */ else { /* If it's invalid a new tbl8 is needed */ if (!tbl[tbl_index].valid) { if (lpm->next_tbl8 < lpm->number_tbl8s) tbl8_gindex = (lpm->next_tbl8)++; else return -ENOSPC; struct rte_lpm6_tbl_entry new_tbl_entry = { .lpm6_tbl8_gindex = tbl8_gindex, .depth = 0, .valid = VALID, .valid_group = VALID, .ext_entry = 1, }; tbl[tbl_index] = new_tbl_entry; } /* * If it's valid but not extended the rule that was stored * * here needs to be moved to the next table. */ else if (tbl[tbl_index].ext_entry == 0) { /* Search for free tbl8 group. */ if (lpm->next_tbl8 < lpm->number_tbl8s) tbl8_gindex = (lpm->next_tbl8)++; else return -ENOSPC; tbl8_group_start = tbl8_gindex * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES; tbl8_group_end = tbl8_group_start + RTE_LPM6_TBL8_GROUP_NUM_ENTRIES; /* Populate new tbl8 with tbl value. */ for (i = tbl8_group_start; i < tbl8_group_end; i++) { lpm->tbl8[i].valid = VALID; lpm->tbl8[i].depth = tbl[tbl_index].depth; lpm->tbl8[i].next_hop = tbl[tbl_index].next_hop; lpm->tbl8[i].ext_entry = 0; } /* * Update tbl entry to point to new tbl8 entry. Note: The * ext_flag and tbl8_index need to be updated simultaneously, * so assign whole structure in one go. */ struct rte_lpm6_tbl_entry new_tbl_entry = { .lpm6_tbl8_gindex = tbl8_gindex, .depth = 0, .valid = VALID, .valid_group = VALID, .ext_entry = 1, }; tbl[tbl_index] = new_tbl_entry; } *tbl_next = &(lpm->tbl8[tbl[tbl_index].lpm6_tbl8_gindex * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES]); } return 1; } /* * Add a route */ int rte_lpm6_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint8_t next_hop) { struct rte_lpm6_tbl_entry *tbl; struct rte_lpm6_tbl_entry *tbl_next; int32_t rule_index; int status; uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE]; int i; /* Check user arguments. */ if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) return -EINVAL; /* Copy the IP and mask it to avoid modifying user's input data. */ memcpy(masked_ip, ip, RTE_LPM6_IPV6_ADDR_SIZE); mask_ip(masked_ip, depth); /* Add the rule to the rule table. */ rule_index = rule_add(lpm, masked_ip, next_hop, depth); /* If there is no space available for new rule return error. */ if (rule_index < 0) { return rule_index; } /* Inspect the first three bytes through tbl24 on the first step. */ tbl = lpm->tbl24; status = add_step (lpm, tbl, &tbl_next, masked_ip, ADD_FIRST_BYTE, 1, depth, next_hop); if (status < 0) { rte_lpm6_delete(lpm, masked_ip, depth); return status; } /* * Inspect one by one the rest of the bytes until * the process is completed. */ for (i = ADD_FIRST_BYTE; i < RTE_LPM6_IPV6_ADDR_SIZE && status == 1; i++) { tbl = tbl_next; status = add_step (lpm, tbl, &tbl_next, masked_ip, 1, (uint8_t)(i+1), depth, next_hop); if (status < 0) { rte_lpm6_delete(lpm, masked_ip, depth); return status; } } return status; } /* * Takes a pointer to a table entry and inspect one level. * The function returns 0 on lookup success, ENOENT if no match was found * or 1 if the process needs to be continued by calling the function again. */ static inline int lookup_step(const struct rte_lpm6 *lpm, const struct rte_lpm6_tbl_entry *tbl, const struct rte_lpm6_tbl_entry **tbl_next, uint8_t *ip, uint8_t first_byte, uint8_t *next_hop) { uint32_t tbl8_index, tbl_entry; /* Take the integer value from the pointer. */ tbl_entry = *(const uint32_t *)tbl; /* If it is valid and extended we calculate the new pointer to return. */ if ((tbl_entry & RTE_LPM6_VALID_EXT_ENTRY_BITMASK) == RTE_LPM6_VALID_EXT_ENTRY_BITMASK) { tbl8_index = ip[first_byte-1] + ((tbl_entry & RTE_LPM6_TBL8_BITMASK) * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES); *tbl_next = &lpm->tbl8[tbl8_index]; return 1; } else { /* If not extended then we can have a match. */ *next_hop = (uint8_t)tbl_entry; return (tbl_entry & RTE_LPM6_LOOKUP_SUCCESS) ? 0 : -ENOENT; } } /* * Looks up an IP */ int rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop) { const struct rte_lpm6_tbl_entry *tbl; const struct rte_lpm6_tbl_entry *tbl_next; int status; uint8_t first_byte; uint32_t tbl24_index; /* DEBUG: Check user input arguments. */ if ((lpm == NULL) || (ip == NULL) || (next_hop == NULL)) { return -EINVAL; } first_byte = LOOKUP_FIRST_BYTE; tbl24_index = (ip[0] << BYTES2_SIZE) | (ip[1] << BYTE_SIZE) | ip[2]; /* Calculate pointer to the first entry to be inspected */ tbl = &lpm->tbl24[tbl24_index]; do { /* Continue inspecting following levels until success or failure */ status = lookup_step(lpm, tbl, &tbl_next, ip, first_byte++, next_hop); tbl = tbl_next; } while (status == 1); return status; } /* * Looks up a group of IP addresses */ int rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm, uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], int16_t * next_hops, unsigned n) { unsigned i; const struct rte_lpm6_tbl_entry *tbl; const struct rte_lpm6_tbl_entry *tbl_next; uint32_t tbl24_index; uint8_t first_byte, next_hop; int status; /* DEBUG: Check user input arguments. */ if ((lpm == NULL) || (ips == NULL) || (next_hops == NULL)) { return -EINVAL; } for (i = 0; i < n; i++) { first_byte = LOOKUP_FIRST_BYTE; tbl24_index = (ips[i][0] << BYTES2_SIZE) | (ips[i][1] << BYTE_SIZE) | ips[i][2]; /* Calculate pointer to the first entry to be inspected */ tbl = &lpm->tbl24[tbl24_index]; do { /* Continue inspecting following levels until success or failure */ status = lookup_step(lpm, tbl, &tbl_next, ips[i], first_byte++, &next_hop); tbl = tbl_next; } while (status == 1); if (status < 0) next_hops[i] = -1; else next_hops[i] = next_hop; } return 0; } /* * Finds a rule in rule table. * NOTE: Valid range for depth parameter is 1 .. 128 inclusive. */ static inline int32_t rule_find(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth) { uint32_t rule_index; /* Scan used rules at given depth to find rule. */ for (rule_index = 0; rule_index < lpm->used_rules; rule_index++) { /* If rule is found return the rule index. */ if ((memcmp (lpm->rules_tbl[rule_index].ip, ip, RTE_LPM6_IPV6_ADDR_SIZE) == 0) && lpm->rules_tbl[rule_index].depth == depth) { return rule_index; } } /* If rule is not found return -ENOENT. */ return -ENOENT; } /* * Look for a rule in the high-level rules table */ int rte_lpm6_is_rule_present(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint8_t *next_hop) { uint8_t ip_masked[RTE_LPM6_IPV6_ADDR_SIZE]; int32_t rule_index; /* Check user arguments. */ if ((lpm == NULL) || next_hop == NULL || ip == NULL || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) return -EINVAL; /* Copy the IP and mask it to avoid modifying user's input data. */ memcpy(ip_masked, ip, RTE_LPM6_IPV6_ADDR_SIZE); mask_ip(ip_masked, depth); /* Look for the rule using rule_find. */ rule_index = rule_find(lpm, ip_masked, depth); if (rule_index >= 0) { *next_hop = lpm->rules_tbl[rule_index].next_hop; return 1; } /* If rule is not found return 0. */ return 0; } /* * Delete a rule from the rule table. * NOTE: Valid range for depth parameter is 1 .. 128 inclusive. */ static inline void rule_delete(struct rte_lpm6 *lpm, int32_t rule_index) { /* * Overwrite redundant rule with last rule in group and decrement rule * counter. */ lpm->rules_tbl[rule_index] = lpm->rules_tbl[lpm->used_rules-1]; lpm->used_rules--; } /* * Deletes a rule */ int rte_lpm6_delete(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth) { int32_t rule_to_delete_index; uint8_t ip_masked[RTE_LPM6_IPV6_ADDR_SIZE]; unsigned i; /* * Check input arguments. */ if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) { return -EINVAL; } /* Copy the IP and mask it to avoid modifying user's input data. */ memcpy(ip_masked, ip, RTE_LPM6_IPV6_ADDR_SIZE); mask_ip(ip_masked, depth); /* * Find the index of the input rule, that needs to be deleted, in the * rule table. */ rule_to_delete_index = rule_find(lpm, ip_masked, depth); /* * Check if rule_to_delete_index was found. If no rule was found the * function rule_find returns -ENOENT. */ if (rule_to_delete_index < 0) return rule_to_delete_index; /* Delete the rule from the rule table. */ rule_delete(lpm, rule_to_delete_index); /* * Set all the table entries to 0 (ie delete every rule * from the data structure. */ lpm->next_tbl8 = 0; memset(lpm->tbl24, 0, sizeof(lpm->tbl24)); memset(lpm->tbl8, 0, sizeof(lpm->tbl8[0]) * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES * lpm->number_tbl8s); /* * Add every rule again (except for the one that was removed from * the rules table). */ for (i = 0; i < lpm->used_rules; i++) { rte_lpm6_add(lpm, lpm->rules_tbl[i].ip, lpm->rules_tbl[i].depth, lpm->rules_tbl[i].next_hop); } return 0; } /* * Deletes a group of rules */ int rte_lpm6_delete_bulk_func(struct rte_lpm6 *lpm, uint8_t ips[][RTE_LPM6_IPV6_ADDR_SIZE], uint8_t *depths, unsigned n) { int32_t rule_to_delete_index; uint8_t ip_masked[RTE_LPM6_IPV6_ADDR_SIZE]; unsigned i; /* * Check input arguments. */ if ((lpm == NULL) || (ips == NULL) || (depths == NULL)) { return -EINVAL; } for (i = 0; i < n; i++) { /* Copy the IP and mask it to avoid modifying user's input data. */ memcpy(ip_masked, ips[i], RTE_LPM6_IPV6_ADDR_SIZE); mask_ip(ip_masked, depths[i]); /* * Find the index of the input rule, that needs to be deleted, in the * rule table. */ rule_to_delete_index = rule_find(lpm, ip_masked, depths[i]); /* * Check if rule_to_delete_index was found. If no rule was found the * function rule_find returns -ENOENT. */ if (rule_to_delete_index < 0) continue; /* Delete the rule from the rule table. */ rule_delete(lpm, rule_to_delete_index); } /* * Set all the table entries to 0 (ie delete every rule * from the data structure. */ lpm->next_tbl8 = 0; memset(lpm->tbl24, 0, sizeof(lpm->tbl24)); memset(lpm->tbl8, 0, sizeof(lpm->tbl8[0]) * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES * lpm->number_tbl8s); /* * Add every rule again (except for the ones that were removed from * the rules table). */ for (i = 0; i < lpm->used_rules; i++) { rte_lpm6_add(lpm, lpm->rules_tbl[i].ip, lpm->rules_tbl[i].depth, lpm->rules_tbl[i].next_hop); } return 0; } /* * Delete all rules from the LPM table. */ void rte_lpm6_delete_all(struct rte_lpm6 *lpm) { /* Zero used rules counter. */ lpm->used_rules = 0; /* Zero next tbl8 index. */ lpm->next_tbl8 = 0; /* Zero tbl24. */ memset(lpm->tbl24, 0, sizeof(lpm->tbl24)); /* Zero tbl8. */ memset(lpm->tbl8, 0, sizeof(lpm->tbl8[0]) * RTE_LPM6_TBL8_GROUP_NUM_ENTRIES * lpm->number_tbl8s); /* Delete all rules form the rules table. */ memset(lpm->rules_tbl, 0, sizeof(struct rte_lpm6_rule) * lpm->max_rules); }