void test_port_config(void) { datastore_bridge_info_t info; struct ofp_port_mod port_mod; struct ofp_error error; struct bridge *bridge; lagopus_result_t rv; memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_interface_create("interface1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_interface_set("port1", "interface1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 1), LAGOPUS_RESULT_OK); bridge = dp_bridge_lookup("br0"); TEST_ASSERT_NOT_NULL(bridge); port_mod.port_no = 1; port_mod.hw_addr[0] = 0xe0; port_mod.hw_addr[1] = 0x4d; port_mod.hw_addr[2] = 0xff; port_mod.hw_addr[3] = 0x00; port_mod.hw_addr[4] = 0x10; port_mod.hw_addr[5] = 0x04; port_mod.config = 0; port_mod.mask = 0; rv = port_config(bridge, &port_mod, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "port_config error"); }
void setUp(void) { datastore_bridge_info_t info; TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK); }
void setUp(void) { datastore_bridge_info_t info; memset(&info, 0, sizeof(info)); info.dpid = dpid; info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_NULL(bridge); TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_create(bridge_name, &info), LAGOPUS_RESULT_OK); bridge = dp_bridge_lookup(bridge_name); TEST_ASSERT_NOT_NULL(bridge); }
void test_lagopus_get_port_statistics(void) { datastore_bridge_info_t info; struct bridge *bridge; struct ofp_port_stats_request req; struct port_stats_list list; struct ofp_error error; lagopus_result_t rv; memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; rv = dp_bridge_create("br0", &info); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "bridge add error"); bridge = dp_bridge_lookup("br0"); TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "dp_bridge_lookup error"); req.port_no = 1; TAILQ_INIT(&list); rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OFP_ERROR, "result error"); req.port_no = OFPP_ANY; TAILQ_INIT(&list); rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error"); TEST_ASSERT_NULL_MESSAGE(TAILQ_FIRST(&list), "empty list error"); TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_interface_create("interface1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_interface_set("port1", "interface1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 1), LAGOPUS_RESULT_OK); req.port_no = OFPP_ANY; TAILQ_INIT(&list); rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error"); TEST_ASSERT_NOT_NULL_MESSAGE(TAILQ_FIRST(&list), "list error"); req.port_no = 1; TAILQ_INIT(&list); rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error"); TEST_ASSERT_NOT_NULL_MESSAGE(TAILQ_FIRST(&list), "list error"); req.port_no = 5; TAILQ_INIT(&list); rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error); TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OFP_ERROR, "result error"); }
void test_set_field_IN_PORT(void) { datastore_bridge_info_t info; struct action_list action_list; struct bridge *bridge; struct port *port; struct action *action; struct ofp_action_set_field *action_set; struct port nport; struct lagopus_packet pkt; OS_MBUF *m; /* setup bridge and port */ memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_create("port0"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port0", 1), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 2), LAGOPUS_RESULT_OK); TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action_set = (struct ofp_action_set_field *)&action->ofpat; action_set->type = OFPAT_SET_FIELD; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error."); m->data = &m->dat[128]; bridge = dp_bridge_lookup("br0"); TEST_ASSERT_NOT_NULL(bridge); pkt.in_port = port_lookup(bridge->ports, 1); TEST_ASSERT_NOT_NULL(pkt.in_port); lagopus_packet_init(&pkt, m); set_match(action_set->field, 4, OFPXMT_OFB_IN_PORT << 1, 0x00, 0x00, 0x00, 0x02); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(pkt.in_port->ofp_port.port_no, 2, "SET_FIELD IN_PORT error."); }
void setUp(void) { size_t s; char buf[128]; dpid_base = 0; printf("dpid_base = 0x%llx (%llu)\n", (unsigned long long)dpid_base, (unsigned long long)dpid_base); for (s = 0; s < ARRAY_LEN(bridge); s++) { TEST_ASSERT_NULL(bridge_name[s]); TEST_ASSERT_NULL(bridge[s]); TEST_ASSERT_NULL(flowdb[s]); } for (s = 0; s < ARRAY_LEN(port_name); s++) { TEST_ASSERT_NULL(port_name[s]); } for (s = 0; s < ARRAY_LEN(ifname); s++) { TEST_ASSERT_NULL(ifname[s]); } /* Make the bridge names and port configurations. */ for (s = 0; s < ARRAY_LEN(bridge); s++) { snprintf(buf, sizeof(buf), bridge_name_format, (int)s); bridge_name[s] = strdup(buf); snprintf(buf, sizeof(buf), port_name_format, TEST_PORT_IFINDEX(s)); port_name[s] = strdup(buf); snprintf(buf, sizeof(buf), ifname_format, TEST_PORT_IFINDEX(s)); ifname[s] = strdup(buf); } TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); for (s = 0; s < ARRAY_LEN(bridge); s++) { datastore_bridge_info_t info; memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; info.dpid = TEST_DPID(s); TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == dp_bridge_create(bridge_name[s], &info)); TEST_ASSERT_NOT_NULL(bridge[s] = dp_bridge_lookup(bridge_name[s])); TEST_ASSERT_NOT_NULL(flowdb[s] = bridge[s]->flowdb); } }
void setUp(void) { /* Event manager allocation. */ /* init datapath. */ TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); /* interface. */ interface_info.type = DATASTORE_INTERFACE_TYPE_ETHERNET_RAWSOCK; interface_info.eth_rawsock.port_number = 0; interface_info.eth_dpdk_phy.device = strdup("eth0"); if (interface_info.eth_dpdk_phy.device == NULL) { TEST_FAIL_MESSAGE("device is NULL."); } TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_interface_create(interface_name)); dp_interface_info_set(interface_name, &interface_info); /* port. */ TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_create(port_name)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_interface_set(port_name, interface_name)); /* bridge. */ bridge_info.dpid = dpid; bridge_info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; bridge_info.max_buffered_packets = UINT32_MAX; bridge_info.max_ports = UINT16_MAX; bridge_info.max_tables = UINT8_MAX; bridge_info.max_flows = UINT32_MAX; bridge_info.capabilities = UINT64_MAX; bridge_info.action_types = UINT64_MAX; bridge_info.instruction_types = UINT64_MAX; bridge_info.reserved_port_types = UINT64_MAX; bridge_info.group_types = UINT64_MAX; bridge_info.group_capabilities = UINT64_MAX; TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_create(bridge_name, &bridge_info)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_port_set(bridge_name, port_name, 0)); }
void setUp(void) { datastore_bridge_info_t info; struct ofp_error err; TEST_ASSERT_NULL(bridge); TEST_ASSERT_NULL(flowdb); memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == dp_bridge_create(bridge_name, &info)); TEST_ASSERT_NOT_NULL(bridge = dp_bridge_lookup(bridge_name)); TEST_ASSERT_NOT_NULL(flowdb = bridge->flowdb); TAILQ_INIT(&features_list); memset(&err, 0, sizeof(err)); TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == flowdb_get_table_features(flowdb, &features_list, &err)); }
void setUp(void) { datastore_bridge_info_t info; TEST_ASSERT_NULL(bridge); TEST_ASSERT_NULL(flowdb); TEST_ASSERT_NULL(ports); TEST_ASSERT_NULL(group_table); TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); memset(&info, 0, sizeof(info)); info.dpid = dpid; info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == dp_bridge_create(bridge_name, &info)); TEST_ASSERT_NOT_NULL(bridge = dp_bridge_lookup(bridge_name)); TEST_ASSERT_NOT_NULL(flowdb = bridge->flowdb); TEST_ASSERT_EQUAL(lagopus_hashmap_create(&ports, LAGOPUS_HASHMAP_TYPE_ONE_WORD, NULL), LAGOPUS_RESULT_OK); TEST_ASSERT_NOT_NULL(group_table = group_table_alloc(bridge)); }
void test_lagopus_find_flow(void) { datastore_bridge_info_t info; struct bridge *bridge; struct port *port; struct port nport; struct lagopus_packet *pkt; struct table *table; struct flow *flow; OS_MBUF *m; /* setup bridge and port */ memset(&info, 0, sizeof(info)); info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; TEST_ASSERT_EQUAL(dp_bridge_create("br0", &info), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_create("port0"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port0", 1), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 2), LAGOPUS_RESULT_OK); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(m, 64); m->refcnt = 2; bridge = dp_bridge_lookup("br0"); TEST_ASSERT_NOT_NULL(bridge); lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); table = flowdb_get_table(pkt->in_port->bridge->flowdb, 0); table->userdata = new_flowinfo_eth_type(); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(misc) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(misc) error."); OS_MTOD(m, uint8_t *)[14] = 0x08; OS_MTOD(m, uint8_t *)[15] = 0x06; lagopus_packet_init(pkt, m, &port); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(arp) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(arp) error."); OS_MTOD(m, uint8_t *)[14] = 0x08; OS_MTOD(m, uint8_t *)[15] = 0x00; lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(ipv4) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(ipv4) error."); OS_MTOD(m, uint8_t *)[14] = 0x86; OS_MTOD(m, uint8_t *)[15] = 0xdd; OS_MTOD(m, uint8_t *)[20] = IPPROTO_TCP; lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(ipv6) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(ipv6) error."); OS_MTOD(m, uint8_t *)[14] = 0x88; OS_MTOD(m, uint8_t *)[15] = 0x47; lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(mpls) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(mpls) error."); OS_MTOD(m, uint8_t *)[14] = 0x88; OS_MTOD(m, uint8_t *)[15] = 0x48; lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(mpls-mc) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(mpls-mc) error."); OS_MTOD(m, uint8_t *)[14] = 0x88; OS_MTOD(m, uint8_t *)[15] = 0xe7; lagopus_packet_init(pkt, m, port_lookup(&bridge->ports, 1)); flow = lagopus_find_flow(pkt, table); TEST_ASSERT_EQUAL_MESSAGE(table->lookup_count, 0, "lookup_count(pbb) error."); TEST_ASSERT_NULL_MESSAGE(flow, "flow(pbb) error."); }
struct channel * create_data_channel(void) { static uint8_t cnt; char buf[256]; struct channel *channel; lagopus_session_t session; struct addrunion addr; uint64_t dpid = 0xabc; if (s_is_init == false) { s_is_init = true; /* init dataplane. */ TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_api_init()); /* interface. */ s_interface_info.type = DATASTORE_INTERFACE_TYPE_ETHERNET_RAWSOCK; s_interface_info.eth_rawsock.port_number = 0; s_interface_info.eth_dpdk_phy.device = strdup("eth0"); if (s_interface_info.eth_dpdk_phy.device == NULL) { TEST_FAIL_MESSAGE("device is NULL."); } TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_interface_create(interface_name)); dp_interface_info_set(interface_name, &s_interface_info); /* port. */ TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_create(port_name)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_interface_set(port_name, interface_name)); /* bridge. */ ofp_bridgeq_mgr_initialize(NULL); s_bridge_info.dpid = dpid; s_bridge_info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; s_bridge_info.max_buffered_packets = UINT32_MAX; s_bridge_info.max_ports = UINT16_MAX; s_bridge_info.max_tables = UINT8_MAX; s_bridge_info.max_flows = UINT32_MAX; s_bridge_info.capabilities = UINT64_MAX; s_bridge_info.action_types = UINT64_MAX; s_bridge_info.instruction_types = UINT64_MAX; s_bridge_info.reserved_port_types = UINT64_MAX; s_bridge_info.group_types = UINT64_MAX; s_bridge_info.group_capabilities = UINT64_MAX; TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_create(bridge_name, &s_bridge_info)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_port_set(bridge_name, port_name, 0)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ofp_bridgeq_mgr_bridge_register( dpid, bridge_name, &s_bridge_info, &s_queue_info)); channel_mgr_initialize(); } snprintf(buf, sizeof(buf), "127.0.0.%u", cnt++);//XXX addrunion_ipv4_set(&addr, buf); channel_mgr_channel_add(bridge_name, dpid, &addr); channel_mgr_channel_lookup(bridge_name, &addr, &channel); session = channel_session_get(channel); session_write_set(session, s_write_tcp); session_sockfd_set(session, 3); channel_version_set(channel, 0x04); channel_xid_set(channel, s_xid); return channel; }
void setUp(void) { struct sockaddr_storage so = {0,0,{0}}; struct sockaddr_in *sin = (struct sockaddr_in *)&so; struct sockaddr_in6 *sin6; if (s4 != -1) { return; } sin->sin_family = AF_INET; sin->sin_port = htons(10022); sin->sin_addr.s_addr = INADDR_ANY; s4 = socket(AF_INET, SOCK_STREAM, 0); if (s4 < 0) { perror("socket"); exit(1); } if (bind(s4, (struct sockaddr *) sin, sizeof(*sin)) < 0) { perror("bind"); exit(1); } if (listen(s4, 5) < 0) { perror("listen"); exit(1); } sin6 = (struct sockaddr_in6 *)&so; sin6->sin6_family = AF_INET6; sin6->sin6_port = htons(10023); sin6->sin6_addr = in6addr_any; s6 = socket(AF_INET6, SOCK_STREAM, 0); if (s6 < 0) { perror("socket"); exit(1); } if (bind(s6, (struct sockaddr *) sin6, sizeof(*sin6)) < 0) { perror("bind"); exit(1); } if (listen(s6, 5) < 0) { perror("listen"); exit(1); } /* init datapath. */ TEST_ASSERT_EQUAL(dp_api_init(), LAGOPUS_RESULT_OK); /* interface. */ interface_info.type = DATASTORE_INTERFACE_TYPE_ETHERNET_RAWSOCK; interface_info.eth_rawsock.port_number = 0; interface_info.eth_dpdk_phy.device = strdup("eth0"); if (interface_info.eth_dpdk_phy.device == NULL) { TEST_FAIL_MESSAGE("device is NULL."); } TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_interface_create(interface_name)); dp_interface_info_set(interface_name, &interface_info); /* port. */ TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_create(port_name)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_port_interface_set(port_name, interface_name)); /* bridge. */ bridge_info.dpid = dpid; bridge_info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE; bridge_info.max_buffered_packets = UINT32_MAX; bridge_info.max_ports = UINT16_MAX; bridge_info.max_tables = UINT8_MAX; bridge_info.max_flows = UINT32_MAX; bridge_info.capabilities = UINT64_MAX; bridge_info.action_types = UINT64_MAX; bridge_info.instruction_types = UINT64_MAX; bridge_info.reserved_port_types = UINT64_MAX; bridge_info.group_types = UINT64_MAX; bridge_info.group_capabilities = UINT64_MAX; TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_create(bridge_name, &bridge_info)); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, dp_bridge_port_set(bridge_name, port_name, 0)); printf("setup end\n"); }