int req_select_attack(t_engine *e, t_trame *trame, int src) { t_game_select_attack game; t_entity *attacked; t_req_select_attack req; int i; if (trame->len != sizeof(game)) { fprintf(stderr, "ERROR: req_select_attack: failed\n"); return (1); } memcpy(&game, trame->msg, sizeof(game)); req.id_req = game.id_req; attacked = find_entity(e, game.id_attacked); if (!attacked || !e->select[0][src]) { fprintf(stderr, "ERROR: req_select_attack: failed\n"); req.id_action = -1; } for (i = 0; i < FW_MAX_SELECT && e->select[i][src]; i++) if (src == e->select[i][src]->app) req.id_action = create_action(e, e->select[i][src], attacked); stock_msg(e->players[src].client, TAG_SELECT_ATTACK_REPLY, sizeof(req), &req); return (0); }
/** * Read the undo_list from the provided config. * Currently, this is only used when the undo_list is empty, but in theory * it could be used to append the config to the current data. */ void undo_list::read(const config & cfg) { // Merge header data. side_ = cfg["side"].to_int(side_); committed_actions_ = committed_actions_ || cfg["committed"].to_bool(); // Build the undo stack. for (const config & child : cfg.child_range("undo")) { try { undo_action_base * action = create_action(child); if ( action ) { undos_.push_back(action); } } catch (bad_lexical_cast &) { ERR_NG << "Error when parsing undo list from config: bad lexical cast." << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this undo action..." << std::endl; } catch (config::error& e) { ERR_NG << "Error when parsing undo list from config: " << e.what() << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this undo action..." << std::endl; } } // Build the redo stack. for (const config & child : cfg.child_range("redo")) { try { undo_action_base * action = create_action(child); if ( undo_action* undoable_action = dynamic_cast<undo_action*>(action)) { redos_.push_back(undoable_action); } else { delete action; ERR_NG << "Error: redo contained action that is not undoable" << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this redo action..." << std::endl; } } catch (bad_lexical_cast &) { ERR_NG << "Error when parsing redo list from config: bad lexical cast." << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this redo action..." << std::endl; } catch (config::error& e) { ERR_NG << "Error when parsing redo list from config: " << e.what() << std::endl; ERR_NG << "config was: " << child.debug() << std::endl; ERR_NG << "Skipping this redo action..." << std::endl; } } }
action * create_action_pop_pbb( void ) { action *action = create_action(); action->type = OFPAT_POP_PBB; return action; }
action * create_action_pop_vlan( void ) { action *action = create_action(); action->type = OFPAT_POP_VLAN; return action; }
action * create_action_copy_ttl_in() { action *action = create_action(); action->type = OFPAT_COPY_TTL_IN; return action; }
action * create_action_copy_ttl_out( void ) { action *action = create_action(); action->type = OFPAT_COPY_TTL_OUT; return action; }
action * create_action_dec_ipv4_ttl() { action *action = create_action(); action->type = OFPAT_DEC_NW_TTL; return action; }
action * create_action_dec_mpls_ttl( void ) { action *action = create_action(); action->type = OFPAT_DEC_MPLS_TTL; return action; }
action * create_action_set_ipv4_ttl( const uint8_t nw_ttl ) { action *action = create_action(); action->type = OFPAT_SET_NW_TTL; action->nw_ttl = nw_ttl; return action; }
action * create_action_push_pbb( const uint16_t ethertype ) { action *action = create_action(); action->type = OFPAT_PUSH_PBB; action->ethertype = ethertype; return action; }
action * create_action_push_vlan( const uint16_t ethertype ) { action *action = create_action(); action->type = OFPAT_PUSH_VLAN; action->ethertype = ethertype; return action; }
action * create_action_pop_mpls( const uint16_t ethertype ) { action *action = create_action(); action->type = OFPAT_POP_MPLS; action->ethertype = ethertype; return action; }
action * create_action_set_field( match *match ) { action *action = create_action(); action->type = OFPAT_SET_FIELD; action->match = match; return action; }
action * create_action_set_mpls_ttl( const uint8_t mpls_ttl ) { action *action = create_action(); action->type = OFPAT_SET_MPLS_TTL; action->mpls_ttl = mpls_ttl; return action; }
action * create_action_group( const uint32_t group_id ) { action *action = create_action(); action->type = OFPAT_GROUP; action->group_id = group_id; return action; }
action * create_action_set_queue( const uint32_t queue_id ) { action *action = create_action(); action->type = OFPAT_SET_QUEUE; action->queue_id = queue_id; return action; }
action * create_action_output( const uint32_t port, const uint16_t max_len ) { action *action = create_action(); action->type = OFPAT_OUTPUT; action->port = port; action->max_len = max_len; return action; }
MainWindow::MainWindow() { init(); create_toolbar(); create_mainWidget(); create_action(); qDebug() << QSqlDatabase::drivers() << endl; db_connect(); setWindowTitle(codec->toUnicode("주소관리")); }
action * duplicate_action( const action *src ) { assert( src != NULL ); action *dst = create_action(); memcpy( dst, src, sizeof( action ) ); if ( src->match != NULL ) { dst->match = duplicate_match( src->match ); } return dst; }
int main(){ uint8_t dummy_mask[MTCH_FLD_LEN]; uint8_t dummy_flow_entry[MTCH_FLD_LEN + 1]; uint8_t dummy_action[ACTN_ST_LEN]; uint8_t dummy_flag[2]; int mask_pos[2]; tcam_unit match_unit; match_unit.mask_tail = 0; match_unit.flow_tail = 0; create_mask(dummy_mask); create_flow_entry(dummy_flow_entry); create_action(dummy_action); dummy_flag[0] = rand() % 256; dummy_flag[1] = rand() % 256; //mask 1 has 1 flow add_new_entry(&match_unit, dummy_mask, dummy_flow_entry, dummy_action, dummy_flag); uint8_t dummy_flow_entry_2[MTCH_FLD_LEN + 1]; create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); dummy_flag[0] = rand() % 256; dummy_flag[1] = rand() % 256; //mask 1 has 2 flows add_new_entry(&match_unit, dummy_mask, dummy_flow_entry_2, dummy_action, dummy_flag); uint8_t dummy_mask_2[MTCH_FLD_LEN]; create_mask(dummy_mask_2); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); dummy_flag[0] = 65; dummy_flag[1] = rand() % 256; //mask 2 has 1 flow add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_2, dummy_action, dummy_flag); uint8_t dummy_flow_entry_3[MTCH_FLD_LEN + 1]; create_flow_entry(dummy_flow_entry_3); create_action(dummy_action); //mask 2 has 2 flows add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_3, dummy_action, dummy_flag); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); //mask 1 has 3 flows add_new_entry(&match_unit, dummy_mask, dummy_flow_entry_2, dummy_action, dummy_flag); create_flow_entry(dummy_flow_entry_2); create_action(dummy_action); //mask 2 has 3 flows add_new_entry(&match_unit, dummy_mask_2, dummy_flow_entry_2, dummy_action, dummy_flag); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit); int pos = delete_flow_entry(&match_unit, dummy_flow_entry); printf("%d\n", pos); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit); uint8_t dummy_action_set[ACTN_ST_LEN]; //search Mask 1 entry 1 //this flow entry has been deleted pos = search_flow(&match_unit, dummy_flow_entry, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); //search mask 2 entry 3 pos = search_flow(&match_unit, dummy_flow_entry_2, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); //search mask 2 entry 2 pos = search_flow(&match_unit, dummy_flow_entry_3, dummy_action_set, mask_pos); printf("%d %d\n", pos, get_mask_pos(&match_unit, pos)); if(pos != -1) write_output(dummy_action_set); /*uint8_t flag_modification[2]; flag_modification[0] = 64; flag_modification[1] = 9; uint8_t new_action_val[8]; uint8_t i; printf("New Action Values:\n"); for(i = 0; i < 8; i++){ new_action_val[i] = rand() % 256; printf("%d\t", new_action_val[i]); } modify_entry(&match_unit, dummy_flow_entry_2, flag_modification, new_action_val); output_all_actions(&match_unit); output_all_flow_entries(&match_unit); output_flags(&match_unit);*/ return 0; }
/*----------------------------------------------------------------------------*/ void handle_open_path(packet_t* p) { int i; uint8_t n_windows = get_payload_at(p,OPEN_PATH_WINDOWS_INDEX); uint8_t start = n_windows*WINDOW_SIZE + 1; uint8_t path_len = (p->header.len - (start + PLD_INDEX))/ADDRESS_LENGTH; uint8_t my_index = 0; uint8_t my_position = 0; uint8_t end = p->header.len - PLD_INDEX; for (i = start; i < end; i += ADDRESS_LENGTH) { address_t tmp = get_address_from_array(&(p->payload[i])); if (is_my_address(&tmp)) { my_index = i; break; } my_position++; } if (my_position > 0) { uint8_t prev = my_index - ADDRESS_LENGTH; uint8_t first = start; entry_t* e = create_entry(); window_t* w = create_window(); w->operation = EQUAL; w->size = SIZE_2; w->lhs = DST_INDEX; w->lhs_location = PACKET; w->rhs = MERGE_BYTES(p->payload[first], p->payload[first+1]); w->rhs_location = CONST; add_window(e,w); for (i = 0; i<n_windows; ++i) { add_window(e, get_window_from_array(&(p->payload[i*WINDOW_SIZE + 1]))); } action_t* a = create_action(FORWARD_U, &(p->payload[prev]), ADDRESS_LENGTH); add_action(e,a); PRINTF("[PHD]: "); print_entry(e); PRINTF("\n"); add_entry(e); } if (my_position < path_len-1) { uint8_t next = my_index + ADDRESS_LENGTH; uint8_t last = end - ADDRESS_LENGTH; entry_t* e = create_entry(); window_t* w = create_window(); w->operation = EQUAL; w->size = SIZE_2; w->lhs = DST_INDEX; w->lhs_location = PACKET; w->rhs = MERGE_BYTES(p->payload[last], p->payload[last+1]); w->rhs_location = CONST; add_window(e,w); for (i = 0; i<n_windows; ++i) { add_window(e, get_window_from_array(&(p->payload[i*WINDOW_SIZE + 1]))); } action_t* a = create_action(FORWARD_U, &(p->payload[next]), ADDRESS_LENGTH); add_action(e,a); PRINTF("[PHD]: "); print_entry(e); PRINTF("\n"); add_entry(e); address_t next_address = get_address_from_array(&(p->payload[next])); p->header.nxh = next_address; p->header.dst = next_address; rf_unicast_send(p); } if (my_position == path_len-1){ packet_deallocate(p); } }
Card *create_rotate_card(enum Direction d, enum Size s) { cards[cards_created] = Card_create(create_action(Action_rotate, d, s), 500); return cards[cards_created++]; }
/*----------------------------------------------------------------------------*/ action_t* get_action_from_array(uint8_t* array, uint8_t action_size){ return create_action(array[0], &(array[1]), action_size-1); }