/** * 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_inputs(void) { int created = 0; odp_pool_t pkt_pool; stream_db_entry_t *stream = NULL; /* Lookup the packet pool */ pkt_pool = odp_pool_lookup("packet_pool"); if (pkt_pool == ODP_POOL_INVALID) { EXAMPLE_ERR("Error: pkt_pool not found\n"); exit(EXIT_FAILURE); } /* For each stream create corresponding input packets */ for (stream = stream_db->list; NULL != stream; stream = stream->next) { int count; uint8_t *dmac = query_loopback_db_mac(stream->input.loop); odp_queue_t queue = query_loopback_db_inq(stream->input.loop); for (count = stream->count; count > 0; count--) { odp_packet_t pkt; pkt = create_ipv4_packet(stream, dmac, pkt_pool); if (ODP_PACKET_INVALID == pkt) { printf("Packet buffers exhausted\n"); break; } stream->created++; if (odp_queue_enq(queue, odp_packet_to_event(pkt))) { odp_packet_free(pkt); printf("Queue enqueue failed\n"); break; } /* Count this stream when we create first packet */ if (1 == stream->created) created++; } } return created; }