static void inside_to_vxlan(void) { struct pg_error *error = NULL; struct pg_brick *vtep; struct pg_bench bench; struct pg_bench_stats stats; struct pg_brick *inside_nop; struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}}; struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}}; struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}}; uint32_t len; pg_bench_init(&bench); vtep = pg_vtep_new("vtep", 1, 1, EAST_SIDE, inet_addr("192.168.0.1"), mac3, NO_PACKETS_CLEANUP | NO_COPY | NO_INNERMAC_CKECK, &error); g_assert(!error); inside_nop = pg_nop_new("nop-input", &error); bench.input_brick = inside_nop; bench.input_side = WEST_SIDE; bench.output_brick = vtep; bench.output_side = EAST_SIDE; bench.output_poll = false; bench.max_burst_cnt = 3000000; bench.count_brick = pg_nop_new("nop-inside", &error); bench.post_burst_op = remove_vtep_hdr; g_assert(!error); pg_brick_link(inside_nop, vtep, &error); g_assert(!error); pg_brick_link(vtep, bench.count_brick, &error); g_assert(!error); pg_vtep_add_vni(vtep, inside_nop, 0, inet_addr("224.0.0.5"), &error); g_assert(!error); bench.pkts_nb = 64; bench.pkts_mask = pg_mask_firsts(64); bench.pkts = pg_packets_create(bench.pkts_mask); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac1, &mac2, ETHER_TYPE_IPv4); len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1356; pg_packets_append_ipv4( bench.pkts, bench.pkts_mask, 0x000000EE, 0x000000CC, len, 17); bench.pkts = pg_packets_append_udp( bench.pkts, bench.pkts_mask, 1000, 2000, 1356); bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1356); //g_assert(pg_bench_run(&bench, &stats, &error)); pg_bench_run(&bench, &stats, &error); pg_error_print(error); /* We know that this brick burst all packets. */ stats.pkts_burst = stats.pkts_sent; printf("[inside] ==> [vtep] ==> [count] (VXLAN side)\n"); g_assert(pg_bench_print(&stats, NULL)); pg_packets_free(bench.pkts, bench.pkts_mask); pg_brick_destroy(vtep); pg_brick_destroy(inside_nop); pg_brick_destroy(bench.count_brick); }
static void vxlan_to_inside(void) { struct pg_error *error = NULL; struct pg_brick *vtep; struct pg_bench bench; struct pg_bench_stats stats; struct pg_brick *outside_nop; struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}}; struct ether_addr mac4 = {{0x52,0x54,0x00,0x12,0x34,0x41}}; static struct ether_addr mac_vtep = {{0xb0,0xb1,0xb2,0xb3,0xb4,0xb5}}; uint32_t len; vtep = pg_vtep_new("vtep", 1, 1, WEST_SIDE, 0x000000EE, mac_vtep, NO_INNERMAC_CKECK | NO_PACKETS_CLEANUP | NO_COPY, &error); g_assert(!error); pg_bench_init(&bench); outside_nop = pg_nop_new("nop-outside", &error); bench.input_brick = outside_nop; bench.input_side = WEST_SIDE; bench.output_brick = vtep; bench.output_side = EAST_SIDE; bench.output_poll = false; bench.max_burst_cnt = 1000000; bench.count_brick = pg_nop_new("nop-bench", &error); bench.post_burst_op = add_vtep_hdr; g_assert(!error); pg_brick_link(outside_nop, vtep, &error); g_assert(!error); pg_brick_link(vtep, bench.count_brick, &error); g_assert(!error); pg_vtep_add_vni(vtep, bench.count_brick, 1, inet_addr("224.0.0.1"), &error); pg_error_print(error); g_assert(!error); bench.pkts_nb = 64; bench.pkts_mask = pg_mask_firsts(64); bench.pkts = pg_packets_create(bench.pkts_mask); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac_vtep, &mac_vtep, ETHER_TYPE_IPv4); len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr) + 1400; pg_packets_append_ipv4( bench.pkts, bench.pkts_mask, 0x000000EE, 0x000000CC, len, 17); bench.pkts = pg_packets_append_udp( bench.pkts, bench.pkts_mask, 1000, 2000, 1400); pg_packets_append_vxlan(bench.pkts, bench.pkts_mask, 1); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac3, &mac4, ETHER_TYPE_IPv4); bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400); memcpy(vxlan_hdr, rte_pktmbuf_mtod(bench.pkts[0], void *), len - 1400); vxlan_hdr[sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr)] = '\0'; g_assert(pg_bench_run(&bench, &stats, &error)); /* We know that this brick burst all packets. */ stats.pkts_burst = stats.pkts_sent; printf("[outside] ==> [vtep] ==> [count] (no VXLAN side)\n"); g_assert(pg_bench_print(&stats, NULL)); pg_packets_free(bench.pkts, bench.pkts_mask); pg_brick_destroy(vtep); pg_brick_destroy(outside_nop); pg_brick_destroy(bench.count_brick); }
static void inside_to_vxlan(int argc, char **argv) { struct pg_error *error = NULL; struct pg_brick *vtep; struct pg_bench bench; struct pg_bench_stats stats; struct pg_brick *inside_nop; struct ether_addr mac1 = {{0x52,0x54,0x00,0x12,0x34,0x11}}; struct ether_addr mac2 = {{0x52,0x54,0x00,0x12,0x34,0x21}}; struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}}; uint32_t len; g_assert(!pg_bench_init(&bench, "vtep inside to vxlan", argc, argv, &error)); vtep = pg_vtep_new("vtep", 1, 1, EAST_SIDE, inet_addr("192.168.0.1"), mac3, PG_VTEP_DST_PORT, ALL_OPTI, &error); g_assert(!error); inside_nop = pg_nop_new("nop-input", &error); bench.input_brick = inside_nop; bench.input_side = WEST_SIDE; bench.output_brick = vtep; bench.output_side = EAST_SIDE; bench.output_poll = false; bench.max_burst_cnt = 3000000; bench.count_brick = pg_nop_new("nop-inside", &error); bench.post_burst_op = remove_vtep_hdr; g_assert(!error); pg_brick_link(inside_nop, vtep, &error); g_assert(!error); pg_brick_link(vtep, bench.count_brick, &error); g_assert(!error); pg_vtep_add_vni(vtep, inside_nop, 0, inet_addr("224.0.0.5"), &error); g_assert(!error); bench.pkts_nb = 64; bench.pkts_mask = pg_mask_firsts(64); bench.pkts = pg_packets_create(bench.pkts_mask); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac1, &mac2, ETHER_TYPE_IPv4); len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + 1356; pg_packets_append_ipv4( bench.pkts, bench.pkts_mask, 0x000000EE, 0x000000CC, len, 17); bench.pkts = pg_packets_append_udp( bench.pkts, bench.pkts_mask, 1000, PG_VTEP_DST_PORT, 1356); bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1356); bench.brick_full_burst = 1; //g_assert(pg_bench_run(&bench, &stats, &error)); pg_bench_run(&bench, &stats, &error); g_assert(!pg_error_is_set(&error)); pg_bench_print(&stats); pg_packets_free(bench.pkts, bench.pkts_mask); pg_brick_destroy(vtep); pg_brick_destroy(inside_nop); pg_brick_destroy(bench.count_brick); }
static int start_loop(uint32_t vtep_ip, struct ether_addr *vtep_mac, struct ether_addr *inner_mac, GList *neighbor_macs) { struct pg_error *error = NULL; struct pg_brick *nic_east, *nic_west, *vtep_east, *vtep_west; struct pg_brick *print_east, *print_west, *print_middle; /* * Here is an ascii graph of the links: * NIC = nic * VT = vtep * * [NIC] - [PRINT] - [VT] -- [PRINT] -- [VT] -- [PRINT] -- [NIC] */ nic_east = pg_nic_new_by_id("nic-e", 1, 1, EAST_SIDE, 0, &error); CHECK_ERROR(error); nic_west = pg_nic_new_by_id("nic-w", 1, 1, WEST_SIDE, 1, &error); CHECK_ERROR(error); vtep_east = pg_vtep_new("vt-e", 1, 1, WEST_SIDE, vtep_ip, *vtep_mac, 1, &error); CHECK_ERROR(error); inverse_mac(vtep_mac); pg_print_mac(vtep_mac); printf("\n"); vtep_west = pg_vtep_new("vt-w", 1, 1, EAST_SIDE, ~vtep_ip, *vtep_mac, 1, &error); CHECK_ERROR(error); print_west = pg_print_new("west", 1, 1, NULL, PG_PRINT_FLAG_MAX, NULL, &error); CHECK_ERROR(error); print_east = pg_print_new("east", 1, 1, NULL, PG_PRINT_FLAG_MAX, NULL, &error); CHECK_ERROR(error); print_middle = pg_print_new("middle", 1, 1, NULL, PG_PRINT_FLAG_MAX, NULL, &error); CHECK_ERROR(error); /* If you want to print transmiting pkts uncomment this and coment * the bellow pg_brick_chained_links * Attention: this may slow down the transmition */ /* pg_brick_chained_links(&error, nic_west, print_west, */ /* vtep_west, print_middle, vtep_east, */ /* print_east, nic_east); */ pg_brick_chained_links(&error, nic_west, vtep_west, vtep_east, nic_east); CHECK_ERROR(error); pg_vtep_add_vni(vtep_west, nic_west, 0, inet_addr("225.0.0.43"), &error); CHECK_ERROR(error); pg_vtep_add_vni(vtep_east, nic_east, 0, inet_addr("225.0.0.43"), &error); CHECK_ERROR(error); while (!quit) { uint16_t nb_send_pkts; g_assert(pg_brick_poll(nic_west, &nb_send_pkts, &error)); usleep(1); g_assert(pg_brick_poll(nic_east, &nb_send_pkts, &error)); usleep(1); } pg_brick_destroy(nic_west); pg_brick_destroy(print_west); pg_brick_destroy(vtep_west); pg_brick_destroy(print_middle); pg_brick_destroy(vtep_east); pg_brick_destroy(print_east); pg_brick_destroy(nic_east); return 0; }
static void vxlan_to_inside(int flags, const char *title, int argc, char **argv) { struct pg_error *error = NULL; struct pg_brick *vtep; struct pg_bench bench; struct pg_bench_stats stats; struct pg_brick *outside_nop; struct ether_addr mac3 = {{0x52,0x54,0x00,0x12,0x34,0x31}}; struct ether_addr mac4 = {{0x52,0x54,0x00,0x12,0x34,0x41}}; static struct ether_addr mac_vtep = {{0xb0,0xb1,0xb2,0xb3,0xb4,0xb5}}; uint32_t len; vtep = pg_vtep_new("vtep", 1, 1, WEST_SIDE, 0x000000EE, mac_vtep, PG_VTEP_DST_PORT, flags, &error); g_assert(!error); g_assert(!pg_bench_init(&bench, title, argc, argv, &error)); outside_nop = pg_nop_new("nop-outside", &error); bench.input_brick = outside_nop; bench.input_side = WEST_SIDE; bench.output_brick = vtep; bench.output_side = EAST_SIDE; bench.output_poll = false; bench.max_burst_cnt = 1000000; bench.count_brick = pg_nop_new("nop-bench", &error); if (flags & NO_COPY) bench.post_burst_op = add_vtep_hdr; g_assert(!error); pg_brick_link(outside_nop, vtep, &error); g_assert(!error); pg_brick_link(vtep, bench.count_brick, &error); g_assert(!error); pg_vtep_add_vni(vtep, bench.count_brick, 1, inet_addr("224.0.0.1"), &error); g_assert(!pg_error_is_set(&error)); if (pg_vtep_add_mac(vtep, 1, &mac4, &error) < 0) pg_error_print(error); g_assert(!pg_error_is_set(&error)); pg_vtep_add_mac(vtep, 1, &mac3, &error); if (pg_vtep_add_mac(vtep, 1, &mac4, &error) < 0) pg_error_print(error); g_assert(!pg_error_is_set(&error)); bench.pkts_nb = 64; bench.pkts_mask = pg_mask_firsts(64); bench.pkts = pg_packets_create(bench.pkts_mask); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac_vtep, &mac_vtep, ETHER_TYPE_IPv4); bench.brick_full_burst = 1; len = sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr) + 1400; pg_packets_append_ipv4( bench.pkts, bench.pkts_mask, 0x000000EE, 0x000000CC, len, 17); bench.pkts = pg_packets_append_udp( bench.pkts, bench.pkts_mask, 1000, PG_VTEP_DST_PORT, 1400); pg_packets_append_vxlan(bench.pkts, bench.pkts_mask, 1); bench.pkts = pg_packets_append_ether( bench.pkts, bench.pkts_mask, &mac3, &mac4, ETHER_TYPE_IPv4); bench.pkts = pg_packets_append_blank(bench.pkts, bench.pkts_mask, 1400); memcpy(vxlan_hdr, rte_pktmbuf_mtod(bench.pkts[0], void *), len - 1400); vxlan_hdr[sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + sizeof(struct vxlan_hdr) + sizeof(struct ether_hdr)] = '\0'; g_assert(pg_bench_run(&bench, &stats, &error) == 0); pg_bench_print(&stats); pg_packets_free(bench.pkts, bench.pkts_mask); pg_brick_destroy(vtep); pg_brick_destroy(outside_nop); pg_brick_destroy(bench.count_brick); }