void execute_action(unsigned int i, int s, int& c, std::function<void()> f) { if(i == actions.size()) { c++; std::cout << "adaptor: executing block " << c << "/" << s << std::endl; f(); } else { if(actions[i].t == loop) { for(double d=actions[i].begin; d<actions[i].end; d+=actions[i].step) { *(actions[i].link) = picojson::value(d); execute_action(i+1,s, c, f); } } else if(actions[i].t == each) { for(auto v : actions[i].values) { *(actions[i].link) = v; execute_action(i+1, s, c, f); } } else if(actions[i].t == pipe) { execute_action(i+1, s, c, f); } } }
// Switch handling code starts here void handle_switch(const switch_name sw_name, boolean current_state) { const enum switch_result res = _read_switch(&switch_states[sw_name], current_state); if (res == PRESSED_NONE) return; // Handle control to menu system? if (menu_active) { _handle_menu_switch(sw_name, res); return; } // normal switch action switch(res) { case PRESSED_LONG: execute_action(switch_states[sw_name].action_long_press); break; case PRESSED_SHORT: execute_action(switch_states[sw_name].action_short_press); break; case PRESSED_NONE: default: break; } }
void test_push_vlan(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_push *action_push; struct lagopus_packet *pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + sizeof(*action_push) - sizeof(struct ofp_action_header)); action_push = (struct ofp_action_push *)&action->ofpat; action_push->type = OFPAT_PUSH_VLAN; action_push->ethertype = 0x8100; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(m, 64); OS_MTOD(m, uint8_t *)[12] = 0x08; OS_MTOD(m, uint8_t *)[13] = 0x00; OS_MTOD(m, uint8_t *)[14] = 0x45; lagopus_packet_init(pkt, m, &port); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4, "PUSH_VLAN length error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x81, "PUSH_VLAN TPID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0x00, "PUSH_VLAN TPID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x08, "PUSH_VLAN ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0x00, "PUSH_VLAN ethertype[1] error."); OS_MTOD(m, uint8_t *)[14] = 0xef; OS_MTOD(m, uint8_t *)[15] = 0xfe; action_push->ethertype = 0x88a8; execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 8, "PUSH_VLAN(2) length error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x88, "PUSH_VLAN(2) TPID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0xa8, "PUSH_VLAN(2) TPID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0xef, "PUSH_VLAN(2) TCI[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0xfe, "PUSH_VLAN(2) TCI[1] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x81, "PUSH_VLAN(2) ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0x00, "PUSH_VLAN(2) ethertype[1] error."); }
void test_push_vlan(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_push *action_push; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + sizeof(*action_push) - sizeof(struct ofp_action_header)); action_push = (struct ofp_action_push *)&action->ofpat; action_push->type = OFPAT_PUSH_VLAN; action_push->ethertype = 0x8100; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x08; m->data[13] = 0x00; m->data[14] = 0x45; lagopus_packet_init(&pkt, m, &port); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 4, "PUSH_VLAN length error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x81, "PUSH_VLAN TPID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00, "PUSH_VLAN TPID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x08, "PUSH_VLAN ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00, "PUSH_VLAN ethertype[1] error."); m->data[14] = 0xef; m->data[15] = 0xfe; action_push->ethertype = 0x88a8; execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64 + 8, "PUSH_VLAN(2) length error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x88, "PUSH_VLAN(2) TPID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0xa8, "PUSH_VLAN(2) TPID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0xef, "PUSH_VLAN(2) TCI[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0xfe, "PUSH_VLAN(2) TCI[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x81, "PUSH_VLAN(2) ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0x00, "PUSH_VLAN(2) ethertype[1] error."); }
static void state_machine(MSBitrateController *obj){ MSRateControlAction action = {0}; switch(obj->state){ case Stable: obj->stable_count++; case Init: ms_qos_analyzer_suggest_action(obj->analyzer,&action); if (action.type!=MSRateControlActionDoNothing){ execute_action(obj,&action); obj->state=Probing; }else if (obj->stable_count>=probing_up_interval){ action.type=MSRateControlActionIncreaseQuality; action.value=10; execute_action(obj,&action); obj->state=ProbingUp; obj->probing_up_count=0; } break; case Probing: obj->stable_count=0; if (ms_qos_analyzer_has_improved(obj->analyzer)){ obj->state=Stable; }else{ ms_qos_analyzer_suggest_action(obj->analyzer,&action); if (action.type!=MSRateControlActionDoNothing){ execute_action(obj,&action); } } break; case ProbingUp: obj->stable_count=0; obj->probing_up_count++; ms_qos_analyzer_suggest_action(obj->analyzer,&action); if (action.type!=MSRateControlActionDoNothing){ execute_action(obj,&action); obj->state=Probing; }else{ /*continue with slow ramp up*/ if (obj->probing_up_count==2){ action.type=MSRateControlActionIncreaseQuality; action.value=10; if (execute_action(obj,&action)==-1){ /* we reached the maximum*/ obj->state=Init; } obj->probing_up_count=0; } } break; default: break; } ms_message("MSBitrateController: current state is %s",state_name(obj->state)); }
void test_set_field_IPV6_IP_ECN(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x86; m->data[13] = 0xdd; lagopus_packet_init(&pkt, m, &port); set_match(action_set->field, 1, OFPXMT_OFB_IP_ECN << 1, 0x03); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[14], 0x00, "SET_FIELD IPV6_IP_ECN[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0x30, "SET_FIELD IPV6_IP_ECN[1] error."); }
void test_set_field_PBB_ISID(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x88; m->data[13] = 0xe7; lagopus_packet_init(&pkt, m, &port); set_match(action_set->field, 3, OFPXMT_OFB_PBB_ISID << 1, 0xa5, 0x5a, 0xc3); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[15], 0xa5, "SET_FIELD PBB_ISID[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x5a, "SET_FIELD PBB_ISID[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xc3, "SET_FIELD PBB_ISID[2] error."); }
static void end_loop(t_svr_vector *vec, t_select *slt_par, t_game *game, int svr_sock) { execute_action(vec, game); init_svr_par(slt_par, vec, svr_sock); init_timeout(vec, slt_par); }
void test_set_field_METADATA(void) { struct port port; static const uint8_t metadata[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; pkt.oob_data.metadata = 0; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); set_match(action_set->field, 8, OFPXMT_OFB_METADATA << 1, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&pkt.oob_data.metadata, metadata, 8, "SET_FIELD METADATA error."); }
void test_copy_ttl_out_IPV6_to_MPLS(void) { struct port port; struct action_list action_list; struct action *action; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action->ofpat.type = OFPAT_COPY_TTL_OUT; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x88; m->data[13] = 0x47; m->data[16] = 0x01; /* BOS */ m->data[17] = 100; /* MPLS TTL */ m->data[18] = 0x60; m->data[25] = 10; /* IPv6 TTL */ lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[25], 10, "COPY_TTL_OUT_IPv6_to_MPLS(inner) error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 10, "COPY_TTL_OUT_IPv6_to_MPLS(outer) error."); }
bool Game_Manager::handle_input_events() { Event event; bool isEvent = m_app->pollEvent(event); Action action; sf::Mouse::Button click = {}; clicked = false; key_event.get_mouse_position(m_app, mouse_vec); m_selection_vector = m_app->mapPixelToCoords(mouse_vec); bool ret = false; if (isEvent) { if (key_event.manage_key_event(event, action)) { execute_action(action); ret = true; } if (key_event.manage_mouse_click(event, click)) { clicked = true; ret = true; } } return ret; }
void DeletionQueue::execute_actions( const ProgressObserverPtr &observer) throw(Error) { if( ! observer ) { try { execute_actions(); } catch( Error &e ) { e.add_call_info( __FUNCTION__, __FILE__, __LINE__ ); throw; } } observer->set_description( "Executing delete actions" ); observer->set_total( actions_.size() ); for( DeleteActionList::iterator action = actions_.begin(); action != actions_.end(); action++ ) { try { execute_action( *action ); } catch( Error &e ) { e.add_call_info( __FUNCTION__, __FILE__, __LINE__ ); observer->reset(); throw; } observer->progress(); } }
bool Game_Manager::handle_input_events() { Event event; bool isEvent = m_app->pollEvent(event); Action action; sf::Mouse::Button click = {}; Vector2i mouse_vec; key_event.get_mouse_position(m_app, mouse_vec); bool ret = false; if (isEvent) { if (key_event.manage_key_event(event, action)) { execute_action(action); ret = true; } if (key_event.manage_mouse_click(event, click)) { if (!open_window) { handle_mouse_click(click, mouse_vec); } ret = true; } } return ret; }
void client_read(t_info *info, t_client **client) { int r; char buf[BUF_SIZE + 1]; char buff_perso[BUF_SIZE + 1]; char *p; t_client *check_respaw; if ((r = (int)xrecv((*client)->socket, buf, BUF_SIZE, 0)) > 0) { buf[r] = '\0'; strncat((*client)->buf_read, buf, BUF_SIZE - strlen(buf)); while ((p = strstr((*client)->buf_read, "\n"))) { *p = 0; strncpy(buff_perso, (*client)->buf_read, BUF_SIZE - 1); check_respaw = *client; if ((*client)->status < ST_CLIENT) begin_session(info, client); else execute_action(buff_perso, *client, info); if (check_respaw == *client) memmove((*client)->buf_read, p + 1, BUF_SIZE); } } else client_disconnect((*client), info); }
void test_set_nw_ttl_IPV6(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_nw_ttl *action_set; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action_set = (struct ofp_action_nw_ttl *)&action->ofpat; action_set->type = OFPAT_SET_NW_TTL; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x86; m->data[13] = 0xdd; m->data[20] = IPPROTO_TCP; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); action_set->nw_ttl = 240; execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[21], 240, "SET_NW_TTL_IPV6 error."); }
void test_set_field_IPV6_IP_ECN(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet *pkt; OS_MBUF *m; 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); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_APPEND(m, 64); OS_MTOD(m, uint8_t *)[12] = 0x86; OS_MTOD(m, uint8_t *)[13] = 0xdd; lagopus_packet_init(pkt, m, &port); set_match(action_set->field, 1, OFPXMT_OFB_IP_ECN << 1, 0x03); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[14], 0x00, "SET_FIELD IPV6_IP_ECN[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[15], 0x30, "SET_FIELD IPV6_IP_ECN[1] error."); }
void test_set_field_IPV6_SCTP_DST(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; OS_M_PKTLEN(m) = 128; m->data[12] = 0x86; m->data[13] = 0xdd; m->data[20] = IPPROTO_SCTP; lagopus_packet_init(&pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_SCTP_DST << 1, 0x80, 0x21); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[56], 0x80, "SET_FIELD IPV6_SCTP_DST[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[57], 0x21, "SET_FIELD IPV6_SCTP_DST[1] error."); m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_SCTP; m->data[55] = 0; lagopus_packet_init(&pkt, m, &port); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_SCTP, "SET_FIELD IPV6_SCTP_DST proto error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[64], 0x80, "SET_FIELD IPV6_SCTP_DST[0](next hdr) error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[65], 0x21, "SET_FIELD IPV6_SCTP_DST[1](next hdr) error."); }
void test_set_field_IPV6_SCTP_SRC(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet *pkt; OS_MBUF *m; 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); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_PKTLEN(m) = 128; OS_MTOD(m, uint8_t *)[12] = 0x86; OS_MTOD(m, uint8_t *)[13] = 0xdd; OS_MTOD(m, uint8_t *)[20] = IPPROTO_SCTP; lagopus_packet_init(pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_SCTP_SRC << 1, 0x80, 0x21); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], 0x80, "SET_FIELD IPV6_SCTP_SRC[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[55], 0x21, "SET_FIELD IPV6_SCTP_SRC[1] error."); OS_MTOD(m, uint8_t *)[20] = IPPROTO_DSTOPTS; OS_MTOD(m, uint8_t *)[54] = IPPROTO_SCTP; OS_MTOD(m, uint8_t *)[55] = 0; lagopus_packet_init(pkt, m, &port); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], IPPROTO_SCTP, "SET_FIELD IPV6_SCTP_SRC proto error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[62], 0x80, "SET_FIELD IPV6_SCTP_SRC[0](next hdr) error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[63], 0x21, "SET_FIELD IPV6_SCTP_SRC[1](next hdr) error."); }
void DeletionQueue::execute_actions() throw(Error) { for( DeleteActionList::iterator action = actions_.begin(); action != actions_.end(); action++ ) { execute_action( *action ); } }
void test_set_field_ETH_TYPE(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x08; m->data[13] = 0x00; lagopus_packet_init(&pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_ETH_TYPE << 1, 0x20, 0xf1); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x20, "SET_FIELD ETH_TYPE[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0xf1, "SET_FIELD ETH_TYPE[1] error."); m->data[12] = 0x81; m->data[13] = 0x00; lagopus_packet_init(&pkt, m, &port); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[16], 0x20, "SET_FIELD(vlan) ETH_TYPE[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0xf1, "SET_FIELD(vlan) ETH_TYPE[1] error."); }
void test_set_field_ETH_TYPE(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet *pkt; OS_MBUF *m; 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); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_APPEND(m, 64); OS_MTOD(m, uint8_t *)[12] = 0x08; OS_MTOD(m, uint8_t *)[13] = 0x00; lagopus_packet_init(pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_ETH_TYPE << 1, 0x20, 0xf1); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[12], 0x20, "SET_FIELD ETH_TYPE[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[13], 0xf1, "SET_FIELD ETH_TYPE[1] error."); OS_MTOD(m, uint8_t *)[12] = 0x81; OS_MTOD(m, uint8_t *)[13] = 0x00; lagopus_packet_init(pkt, m, &port); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[16], 0x20, "SET_FIELD(vlan) ETH_TYPE[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[17], 0xf1, "SET_FIELD(vlan) ETH_TYPE[1] error."); }
void test_set_field_ICMPV6_TYPE(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet *pkt; OS_MBUF *m; 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); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = PKT2MBUF(pkt); OS_M_APPEND(m, 64); OS_MTOD(m, uint8_t *)[12] = 0x86; OS_MTOD(m, uint8_t *)[13] = 0xdd; OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6; lagopus_packet_init(pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1, ICMP6_ECHO_REQUEST); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], ICMP6_ECHO_REQUEST, "SET_FIELD ICMPV6_TYPE error."); OS_MTOD(m, uint8_t *)[20] = IPPROTO_DSTOPTS; OS_MTOD(m, uint8_t *)[54] = IPPROTO_ICMPV6; OS_MTOD(m, uint8_t *)[55] = 0; lagopus_packet_init(pkt, m, &port); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[54], IPPROTO_ICMPV6, "SET_FIELD ICMPV6_TYPE proto error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[62], ICMP6_ECHO_REQUEST, "SET_FIELD ICMPV6_TYPE(next hdr) error."); }
void test_set_field_ICMPV6_TYPE(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; 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]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x86; m->data[13] = 0xdd; m->data[20] = IPPROTO_ICMPV6; lagopus_packet_init(&pkt, m, &port); set_match(action_set->field, 2, OFPXMT_OFB_ICMPV6_TYPE << 1, ICMP6_ECHO_REQUEST); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[54], ICMP6_ECHO_REQUEST, "SET_FIELD ICMPV6_TYPE error."); m->data[20] = IPPROTO_DSTOPTS; m->data[54] = IPPROTO_ICMPV6; m->data[55] = 0; lagopus_packet_init(&pkt, m, &port); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[54], IPPROTO_ICMPV6, "SET_FIELD ICMPV6_TYPE proto error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[62], ICMP6_ECHO_REQUEST, "SET_FIELD ICMPV6_TYPE(next hdr) error."); }
void test_pop_pbb(void) { static const uint8_t odhost[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }; static const uint8_t oshost[] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54 }; static const uint8_t idhost[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 }; static const uint8_t ishost[] = { 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb }; struct port port; struct action_list action_list; struct action *action; struct ofp_action_pop_mpls *action_pop; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action)); action_pop = (struct ofp_action_pop_mpls *)&action->ofpat; action_pop->type = OFPAT_POP_PBB; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64 + 18; OS_MEMCPY(&m->data[0], odhost, ETH_ALEN); OS_MEMCPY(&m->data[6], oshost, ETH_ALEN); m->data[12] = 0x88; m->data[13] = 0xe7; m->data[14] = 0x00; m->data[15] = 0x11; m->data[16] = 0x22; m->data[17] = 0x33; /* dhost and shost */ OS_MEMCPY(&m->data[18], idhost, ETH_ALEN); OS_MEMCPY(&m->data[24], ishost, ETH_ALEN); m->data[30] = 0x08; m->data[31] = 0x00; m->data[32] = 0x45; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_M_PKTLEN(m), 64, "POP_PBB length error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[0], idhost, ETH_ALEN, "POP_PBB ether_dhost error."); TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(&m->data[6], ishost, ETH_ALEN, "POP_PBB ether_shost error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[12], 0x08, "POP_PBB ethertype[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[13], 0x00, "POP_PBB ethertype[1] error."); }
void test_dec_mpls_ttl(void) { struct port port; struct action_list action_list; struct action *action; struct lagopus_packet pkt; OS_MBUF *m; TAILQ_INIT(&action_list); action = calloc(1, sizeof(*action) + 64); action->ofpat.type = OFPAT_DEC_MPLS_TTL; lagopus_set_action_function(action); TAILQ_INSERT_TAIL(&action_list, action, entry); m = calloc(1, sizeof(*m)); TEST_ASSERT_NOT_EQUAL_MESSAGE(m, NULL, "calloc error."); m->data = &m->dat[128]; OS_M_PKTLEN(m) = 64; m->data[12] = 0x88; m->data[13] = 0x47; m->data[17] = 100; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 99, "DEC_MPLS_TTL error."); m->data[12] = 0x88; m->data[13] = 0x48; m->data[17] = 0; lagopus_packet_init(&pkt, m); pkt.in_port = NULL; execute_action(&pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(m->data[17], 0, "DEC_MPLS_TTL(0) error."); }
void execute(std::function<void()> f) { if(mpi_mode && !master_instance) { // Setup data pipes bool firstJob = true; while(true) { std::string local_config = send_command(RQJ); if(local_config.empty()) break; if(firstJob) { for(action & a : actions) if(a.t == pipe) setup_pipe(a); firstJob = false; } parse_raw_config_str(local_config.c_str()); f(); send_command(DNE); } } else { if(actions.size() == 0) f(); else { int action_size = 1; for(auto& a : actions) action_size *= a.size(); int cur = 0; execute_action(0, action_size, cur, f); } if(!mpi_mode) { measure_time(); store_timing(); } } }
int main(int argc, char * argv[]){ char input[MAX_INPUT_SIZE]; pthread_t thread; if(argc < 2){ printf("usage :\n"); printf("WifoPluginsConsole <userid>\n"); printf("with <userid equal to 1 or 2\n"); return -1; } strncpy(step, "start", sizeof(step)); wx_wengo = atoi(argv[1]); printf("Using wx_wengo_%d\n\n", wx_wengo); // register or quit while(strequals(step, "start")){ display_menu(step); //fgets(input, sizeof(input), stdin); gets(input); // if a quit, then quit if(strequals(input, "quit")){ printf("\nBye.\n"); return 0; } execute_action(input); } // display whole menu display_menu(NULL); // launch a thread to display the menu if(pthread_create(&thread, NULL, interact, NULL) != 0){ // TODO notify GUI return FALSE; } // event loop while(phPoll() == 0){ if(strequals(step, "quit")){ break; } usleep(40); } return 0; }
void test_set_field_IPV6_ND_TLL(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet pkt; OS_MBUF *m; int i; 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]; OS_M_PKTLEN(m) = 128; m->data[12] = 0x86; m->data[13] = 0xdd; m->data[19] = 0x80; /* PLEN */ m->data[20] = IPPROTO_ICMPV6; m->data[54] = ND_NEIGHBOR_ADVERT; m->data[78] = ND_OPT_SOURCE_LINKADDR; m->data[79] = 1; m->data[86] = ND_OPT_TARGET_LINKADDR; m->data[87] = 1; lagopus_set_in_port(&pkt, &port); lagopus_packet_init(&pkt, m); set_match(action_set->field, ETH_ALEN, OFPXMT_OFB_IPV6_ND_TLL << 1, 0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78); execute_action(&pkt, &action_list); i = 88; TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0xe0, "SET_FIELD IPV6_ND_TLL[0] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x4d, "SET_FIELD IPV6_ND_TLL[1] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x01, "SET_FIELD IPV6_ND_TLL[2] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x34, "SET_FIELD IPV6_ND_TLL[3] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x56, "SET_FIELD IPV6_ND_TLL[4] error."); TEST_ASSERT_EQUAL_MESSAGE(m->data[i++], 0x78, "SET_FIELD IPV6_ND_TLL[5] error."); }
void test_set_field_ARP_THA(void) { struct port port; struct action_list action_list; struct action *action; struct ofp_action_set_field *action_set; struct lagopus_packet *pkt; OS_MBUF *m; 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); pkt = alloc_lagopus_packet(); TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error."); m = pkt->mbuf; OS_M_APPEND(m, 64); OS_MTOD(m, uint8_t *)[12] = 0x08; OS_MTOD(m, uint8_t *)[13] = 0x06; OS_MTOD(m, uint8_t *)[20] = 0x00; OS_MTOD(m, uint8_t *)[21] = ARPOP_REQUEST; OS_MTOD(m, uint8_t *)[32] = 0xaa; OS_MTOD(m, uint8_t *)[33] = 0x55; OS_MTOD(m, uint8_t *)[34] = 0xaa; OS_MTOD(m, uint8_t *)[35] = 0x55; OS_MTOD(m, uint8_t *)[36] = 0xaa; OS_MTOD(m, uint8_t *)[37] = 0x55; lagopus_packet_init(pkt, m, &port); set_match(action_set->field, 6, OFPXMT_OFB_ARP_THA << 1, 0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78); execute_action(pkt, &action_list); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[32], 0xe0, "SET_FIELD ARP_THA[0] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[33], 0x4d, "SET_FIELD ARP_THA[1] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[34], 0x01, "SET_FIELD ARP_THA[2] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[35], 0x34, "SET_FIELD ARP_THA[3] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[36], 0x56, "SET_FIELD ARP_THA[4] error."); TEST_ASSERT_EQUAL_MESSAGE(OS_MTOD(m, uint8_t *)[37], 0x78, "SET_FIELD ARP_THA[5] error."); }
/****************************************************************************** * * * Function: send_alerts * * * * Purpose: send warning message to all interested * * * * Parameters: * * * * Return value: * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ static void send_alerts() { int i,now; char error[MAX_STRING_LEN]; now = time(NULL); if(now>lastsent+900) { for(i=0;i<num;i++) { execute_action(&recipients[i].alert,&recipients[i].mediatype, error, sizeof(error)); } lastsent = now; } }