- printf ("%s%02X:%02X:%02X:%02X:%02X:%02X", name,
- eth_addr->addr_bytes[0],
- eth_addr->addr_bytes[1],
- eth_addr->addr_bytes[2],
- eth_addr->addr_bytes[3],
- eth_addr->addr_bytes[4],
- eth_addr->addr_bytes[5]);
-}
-
-#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
-static void
-setup_hash(int socketid)
-{
- struct rte_hash_parameters ipv4_l3fwd_hash_params = {
- .name = NULL,
- .entries = L3FWD_HASH_ENTRIES,
- .bucket_entries = 4,
- .key_len = sizeof(struct ipv4_5tuple),
- .hash_func = DEFAULT_HASH_FUNC,
- .hash_func_init_val = 0,
- };
-
- struct rte_hash_parameters ipv6_l3fwd_hash_params = {
- .name = NULL,
- .entries = L3FWD_HASH_ENTRIES,
- .bucket_entries = 4,
- .key_len = sizeof(struct ipv6_5tuple),
- .hash_func = DEFAULT_HASH_FUNC,
- .hash_func_init_val = 0,
- };
-
- unsigned i;
- int ret;
- char s[64];
-
- /* create ipv4 hash */
- rte_snprintf(s, sizeof(s), "ipv4_l3fwd_hash_%d", socketid);
- ipv4_l3fwd_hash_params.name = s;
- ipv4_l3fwd_hash_params.socket_id = socketid;
- ipv4_l3fwd_lookup_struct[socketid] = rte_hash_create(&ipv4_l3fwd_hash_params);
- if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
- rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
- "socket %d\n", socketid);
-
- /* create ipv6 hash */
- rte_snprintf(s, sizeof(s), "ipv6_l3fwd_hash_%d", socketid);
- ipv6_l3fwd_hash_params.name = s;
- ipv6_l3fwd_hash_params.socket_id = socketid;
- ipv6_l3fwd_lookup_struct[socketid] = rte_hash_create(&ipv6_l3fwd_hash_params);
- if (ipv6_l3fwd_lookup_struct[socketid] == NULL)
- rte_exit(EXIT_FAILURE, "Unable to create the l3fwd hash on "
- "socket %d\n", socketid);
-
-
- /* populate the ipv4 hash */
- for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
- ret = rte_hash_add_key (ipv4_l3fwd_lookup_struct[socketid],
- (void *) &ipv4_l3fwd_route_array[i].key);
- if (ret < 0) {
- rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
- "l3fwd hash on socket %d\n", i, socketid);
- }
- ipv4_l3fwd_out_if[ret] = ipv4_l3fwd_route_array[i].if_out;
- printf("Hash: Adding key\n");
- print_ipv4_key(ipv4_l3fwd_route_array[i].key);
- }
-
- /* populate the ipv6 hash */
- for (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {
- ret = rte_hash_add_key (ipv6_l3fwd_lookup_struct[socketid],
- (void *) &ipv6_l3fwd_route_array[i].key);
- if (ret < 0) {
- rte_exit(EXIT_FAILURE, "Unable to add entry %u to the"
- "l3fwd hash on socket %d\n", i, socketid);
- }
- ipv6_l3fwd_out_if[ret] = ipv6_l3fwd_route_array[i].if_out;
- printf("Hash: Adding key\n");
- print_ipv6_key(ipv6_l3fwd_route_array[i].key);
- }
-}
-#endif
-
-#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
-static void
-setup_lpm(int socketid)
-{
- struct rte_lpm6_config config;
- unsigned i;
- int ret;
- char s[64];
-
- /* create the LPM table */
- rte_snprintf(s, sizeof(s), "IPV4_L3FWD_LPM_%d", socketid);
- ipv4_l3fwd_lookup_struct[socketid] = rte_lpm_create(s, socketid,
- IPV4_L3FWD_LPM_MAX_RULES, 0);
- if (ipv4_l3fwd_lookup_struct[socketid] == NULL)
- rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
- " on socket %d\n", socketid);
-
- /* populate the LPM table */
- for (i = 0; i < IPV4_L3FWD_NUM_ROUTES; i++) {
- ret = rte_lpm_add(ipv4_l3fwd_lookup_struct[socketid],
- ipv4_l3fwd_route_array[i].ip,
- ipv4_l3fwd_route_array[i].depth,
- ipv4_l3fwd_route_array[i].if_out);
-
- if (ret < 0) {
- rte_exit(EXIT_FAILURE, "Unable to add entry %u to the "
- "l3fwd LPM table on socket %d\n",
- i, socketid);
- }
-
- printf("LPM: Adding route 0x%08x / %d (%d)\n",
- (unsigned)ipv4_l3fwd_route_array[i].ip,
- ipv4_l3fwd_route_array[i].depth,
- ipv4_l3fwd_route_array[i].if_out);
- }
-
- /* create the LPM6 table */
- rte_snprintf(s, sizeof(s), "IPV6_L3FWD_LPM_%d", socketid);
-
- config.max_rules = IPV6_L3FWD_LPM_MAX_RULES;
- config.number_tbl8s = IPV6_L3FWD_LPM_NUMBER_TBL8S;
- config.flags = 0;
- ipv6_l3fwd_lookup_struct[socketid] = rte_lpm6_create(s, socketid,
- &config);
- if (ipv6_l3fwd_lookup_struct[socketid] == NULL)
- rte_exit(EXIT_FAILURE, "Unable to create the l3fwd LPM table"
- " on socket %d\n", socketid);
-
- /* populate the LPM table */
- for (i = 0; i < IPV6_L3FWD_NUM_ROUTES; i++) {
- ret = rte_lpm6_add(ipv6_l3fwd_lookup_struct[socketid],
- ipv6_l3fwd_route_array[i].ip,
- ipv6_l3fwd_route_array[i].depth,
- ipv6_l3fwd_route_array[i].if_out);
-
- if (ret < 0) {
- rte_exit(EXIT_FAILURE, "Unable to add entry %u to the "
- "l3fwd LPM table on socket %d\n",
- i, socketid);
- }
-
- printf("LPM: Adding route %s / %d (%d)\n",
- "IPV6",
- ipv6_l3fwd_route_array[i].depth,
- ipv6_l3fwd_route_array[i].if_out);
- }
-}
-#endif
-
-static int
-init_mem(void)
-{
- struct lcore_conf *qconf;
- int socketid;
- unsigned lcore_id;
-
- for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
- if (rte_lcore_is_enabled(lcore_id) == 0)
- continue;
-
- if (numa_on)
- socketid = rte_lcore_to_socket_id(lcore_id);
- else
- socketid = 0;
-
- if (socketid >= NB_SOCKETS) {
- rte_exit(EXIT_FAILURE,
- "Socket %d of lcore %u is out of range %d\n",
- socketid, lcore_id, NB_SOCKETS);
- }
-
-#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
- setup_lpm(socketid);
-#else
- setup_hash(socketid);
-#endif
- qconf = &lcore_conf[lcore_id];
- qconf->ipv4_lookup_struct = ipv4_l3fwd_lookup_struct[socketid];
- qconf->ipv6_lookup_struct = ipv6_l3fwd_lookup_struct[socketid];
- }
- return 0;