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 test_dp_port_queue_add_delete(void) { datastore_queue_info_t qinfo; lagopus_result_t rv; qinfo.id = 0; TEST_ASSERT_EQUAL(dp_queue_create("queue01", &qinfo), LAGOPUS_RESULT_OK); TEST_ASSERT_EQUAL(dp_port_interface_set("port1", "if1"), LAGOPUS_RESULT_OK); rv = dp_port_queue_add("portX", "queue0X"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_add("portX", "queue01"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_add("port1", "queue0X"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_add("port1", "queue01"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_OK); rv = dp_port_queue_delete("portX", "queue0X"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_delete("portX", "queue01"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_delete("port1", "queue0X"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_NOT_FOUND); rv = dp_port_queue_delete("port1", "queue01"); TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_OK); }
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 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)); }
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"); }