int MAIN(int argc, char *argv[]) { struct datapath_arg dparg; struct dpmgr *dpmgr; lagopus_thread_t *datapath; struct bridge *bridge; int portid; void *rv; int ret; dpmgr = dpmgr_alloc(); if (dpmgr == NULL) { rte_exit(EXIT_FAILURE, "failed to initialize datapath manager.\n"); } /* Create default bridge. */ ret = dpmgr_bridge_add(dpmgr, "br0", 0); if (ret < 0) { rte_exit(EXIT_FAILURE, "Adding br0 failed\n"); } /* register flow entries */ bridge = dpmgr_bridge_lookup(dpmgr, "br0"); register_flow(bridge->flowdb, 100000); flowdb_switch_mode_set(bridge->flowdb, SWITCH_MODE_OPENFLOW); /* Start datapath. */ dparg.dpmgr = dpmgr; dparg.argc = argc; dparg.argv = argv; datapath_initialize(&dparg, &datapath); /* register all physical ports */ for (portid = 0; portid < nb_ports; portid++) { if (lagopus_is_portid_enabled(portid) == true) { struct port nport; /* New port API. */ nport.ofp_port.port_no = (uint32_t)portid + 1; nport.ifindex = (uint32_t)portid; printf("port id %u\n", nport.ofp_port.port_no); snprintf(nport.ofp_port.name , sizeof(nport.ofp_port.name), "eth%d", portid); dpmgr_port_add(dpmgr, &nport); } } /* assign all ports to br0 */ for (portid = 0; portid < nb_ports; portid++) { dpmgr_bridge_port_add(dpmgr, "br0", (uint32_t)portid + 1); } datapath_start(); while (lagopus_thread_wait(datapath, 1000000) == LAGOPUS_RESULT_TIMEDOUT) { sleep(1); } return 0; }
void test_lagopus_match_and_action(void) { struct action_list action_list; struct dpmgr *my_dpmgr; struct bridge *bridge; struct table *table; struct action *action; struct ofp_action_output *action_set; struct port nport, *port; struct lagopus_packet pkt; OS_MBUF *m; /* setup bridge and port */ my_dpmgr = dpmgr_alloc(); dpmgr_bridge_add(my_dpmgr, "br0", 0); nport.type = LAGOPUS_PORT_TYPE_NULL; /* for test */ nport.ifindex = 0; nport.ofp_port.hw_addr[0] = 1; dpmgr_port_add(my_dpmgr, &nport); nport.ifindex = 1; dpmgr_port_add(my_dpmgr, &nport); dpmgr_bridge_port_add(my_dpmgr, "br0", 0, 1); dpmgr_bridge_port_add(my_dpmgr, "br0", 1, 2); bridge = dpmgr_bridge_lookup(my_dpmgr, "br0"); TEST_ASSERT_NOT_NULL(bridge); flowdb_switch_mode_set(bridge->flowdb, SWITCH_MODE_OPENFLOW); table = table_get(bridge->flowdb, 0); table->userdata = new_flowinfo_eth_type(); TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action_set = (struct ofp_action_output *)&action->ofpat; action_set->type = OFPAT_OUTPUT; 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]; m->refcnt = 2; port = port_lookup(bridge->ports, 1); TEST_ASSERT_NOT_NULL(port); lagopus_set_in_port(&pkt, port); TEST_ASSERT_EQUAL(pkt.in_port, port); TEST_ASSERT_EQUAL(pkt.in_port->bridge, bridge); pkt.table_id = 0; lagopus_packet_init(&pkt, m); lagopus_match_and_action(&pkt); TEST_ASSERT_EQUAL_MESSAGE(m->refcnt, 1, "match_and_action refcnt error."); free(m); dpmgr_free(my_dpmgr); }
void test_flowdb_switch_mode(void) { size_t i; enum switch_mode mode, origmode; static const enum switch_mode modes[] = { SWITCH_MODE_OPENFLOW, SWITCH_MODE_SECURE, SWITCH_MODE_STANDALONE, }; TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == flowdb_switch_mode_get(flowdb, &origmode)); for (i = 0; i < sizeof(modes) / sizeof(modes[0]); i++) { mode = modes[i]; TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == flowdb_switch_mode_set(flowdb, mode)); mode = 0; TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == flowdb_switch_mode_get(flowdb, &mode)); TEST_ASSERT_TRUE(modes[i] == mode); } TEST_ASSERT_TRUE(LAGOPUS_RESULT_OK == flowdb_switch_mode_set(flowdb, origmode)); }
lagopus_result_t dpmgr_switch_mode_set(uint64_t dpid, enum switch_mode switch_mode) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; struct dpmgr *dpmgr = NULL; struct bridge *bridge = NULL; dpmgr = dpmgr_get_instance(); if (dpmgr != NULL) { bridge = bridge_lookup_by_dpid(&dpmgr->bridge_list, dpid); if (bridge != NULL) { ret = flowdb_switch_mode_set(bridge->flowdb, switch_mode); } else { lagopus_msg_warning("Not found bridge.\n"); ret = LAGOPUS_RESULT_NOT_FOUND; } } else { lagopus_msg_warning("Not found dpmgr.\n"); ret = LAGOPUS_RESULT_NOT_FOUND; } return ret; }