/** * Initialize loopback * * Initialize ODP queues to create our own idea of loopbacks, which allow * testing without physical interfaces. Interface name string will be of * the format "loopX" where X is the decimal number of the interface. * * @param intf Loopback interface name string */ #if 0 /* Temporarely disable loopback mode. Needs packet output event queues */ static void initialize_loop(char *intf) { int idx; odp_queue_t outq_def; odp_queue_t inq_def; char queue_name[ODP_QUEUE_NAME_LEN]; odp_queue_param_t qparam; uint8_t *mac; char mac_str[MAX_STRING]; /* Derive loopback interface index */ idx = loop_if_index(intf); if (idx < 0) { EXAMPLE_ERR("Error: loopback \"%s\" invalid\n", intf); exit(EXIT_FAILURE); } /* Create input queue */ odp_queue_param_init(&qparam); qparam.type = ODP_QUEUE_TYPE_SCHED; qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; qparam.sched.group = ODP_SCHED_GROUP_ALL; snprintf(queue_name, sizeof(queue_name), "%i-loop_inq_def", idx); queue_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; inq_def = queue_create(queue_name, &qparam); if (ODP_QUEUE_INVALID == inq_def) { EXAMPLE_ERR("Error: input queue creation failed for %s\n", intf); exit(EXIT_FAILURE); } /* Create output queue */ snprintf(queue_name, sizeof(queue_name), "%i-loop_outq_def", idx); queue_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; outq_def = queue_create(queue_name, NULL); if (ODP_QUEUE_INVALID == outq_def) { EXAMPLE_ERR("Error: output queue creation failed for %s\n", intf); exit(EXIT_FAILURE); } /* Initialize the loopback DB entry */ create_loopback_db_entry(idx, inq_def, outq_def, pkt_pool); mac = query_loopback_db_mac(idx); printf("Created loop:%02i, queue mode (ATOMIC queues)\n" " default loop%02i-INPUT queue:%" PRIu64 "\n" " default loop%02i-OUTPUT queue:%" PRIu64 "\n" " source mac address %s\n", idx, idx, odp_queue_to_u64(inq_def), idx, odp_queue_to_u64(outq_def), mac_addr_str(mac_str, mac)); /* Resolve any routes using this interface for output */ resolve_fwd_db(intf, outq_def, mac); }
int create_stream_db_entry(char *input) { int pos = 0; char *local; char *str; char *save; char *token; stream_db_entry_t *entry = &stream_db->array[stream_db->index]; /* Verify we have a good entry */ if (MAX_DB <= stream_db->index) return -1; /* Make a local copy */ local = malloc(strlen(input) + 1); if (NULL == local) return -1; strcpy(local, input); /* Setup for using "strtok_r" to search input string */ str = local; save = NULL; /* Parse tokens separated by ':' */ while (NULL != (token = strtok_r(str, ":", &save))) { str = NULL; /* reset str for subsequent strtok_r calls */ /* Parse token based on its position */ switch (pos) { case 0: parse_ipv4_string(token, &entry->src_ip, NULL); break; case 1: parse_ipv4_string(token, &entry->dst_ip, NULL); break; case 2: entry->input.loop = loop_if_index(token); if (entry->input.loop < 0) { EXAMPLE_ERR("Error: stream must have input" " loop\n"); exit(EXIT_FAILURE); } break; case 3: entry->output.loop = loop_if_index(token); break; case 4: entry->count = atoi(token); break; case 5: entry->length = atoi(token); if (entry->length < sizeof(stream_pkt_hdr_t)) entry->length = 0; else entry->length -= sizeof(stream_pkt_hdr_t); break; default: printf("ERROR: extra token \"%s\" at position %d\n", token, pos); break; } /* Advance to next position */ pos++; } /* Verify we parsed exactly the number of tokens we expected */ if (6 != pos) { printf("ERROR: \"%s\" contains %d tokens, expected 6\n", input, pos); free(local); return -1; } /* Add stream to the list */ entry->id = stream_db->index++; entry->next = stream_db->list; stream_db->list = entry; free(local); return 0; }