X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fofp-actions.c;h=ae20f8e3b260d8d1fed8d5733aa6193d74fc8f39;hb=9908606290852fc4d29132c843d9f17938cce7d8;hp=8b85f4f7e0862be9120081c6fca857691d566034;hpb=3ddcaf2d7de751346775b3d6183d01a0c0986ce0;p=openvswitch diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 8b85f4f7..ae20f8e3 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -149,14 +149,14 @@ note_from_openflow(const struct nx_action_note *nan, struct ofpbuf *out) } static enum ofperr -dec_ttl_from_openflow(struct ofpbuf *out) +dec_ttl_from_openflow(struct ofpbuf *out, enum ofputil_action_code compat) { uint16_t id = 0; struct ofpact_cnt_ids *ids; enum ofperr error = 0; ids = ofpact_put_DEC_TTL(out); - ids->ofpact.compat = OFPUTIL_NXAST_DEC_TTL; + ids->ofpact.compat = compat; ids->n_controllers = 1; ofpbuf_put(out, &id, sizeof id); ids = out->l2; @@ -362,7 +362,7 @@ ofpact_from_nxast(const union ofp_action *a, enum ofputil_action_code code, break; case OFPUTIL_NXAST_DEC_TTL: - error = dec_ttl_from_openflow(out); + error = dec_ttl_from_openflow(out, code); break; case OFPUTIL_NXAST_DEC_TTL_CNT_IDS: @@ -685,6 +685,10 @@ ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out) ofpact_put_SET_VLAN_PCP(out)->vlan_pcp = a->vlan_pcp.vlan_pcp; break; + case OFPUTIL_OFPAT11_POP_VLAN: + ofpact_put_STRIP_VLAN(out); + break; + case OFPUTIL_OFPAT11_SET_DL_SRC: memcpy(ofpact_put_SET_ETH_SRC(out)->mac, ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN); @@ -695,6 +699,10 @@ ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out) ((const struct ofp_action_dl_addr *) a)->dl_addr, ETH_ADDR_LEN); break; + case OFPUTIL_OFPAT11_DEC_NW_TTL: + dec_ttl_from_openflow(out, code); + break; + case OFPUTIL_OFPAT11_SET_NW_SRC: ofpact_put_SET_IPV4_SRC(out)->ipv4 = a->nw_addr.nw_addr; break; @@ -719,8 +727,8 @@ ofpact_from_openflow11(const union ofp_action *a, struct ofpbuf *out) break; case OFPUTIL_OFPAT12_SET_FIELD: - /* Not yet implemented. */ - break; + return nxm_reg_load_from_openflow12_set_field( + (const struct ofp12_action_set_field *)a, out); #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM: #include "ofp-util.def" @@ -958,11 +966,25 @@ ofpacts_pull_openflow11_instructions(struct ofpbuf *openflow, goto exit; } } + if (insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) { + instruction_get_OFPIT11_CLEAR_ACTIONS( + insts[OVSINST_OFPIT11_CLEAR_ACTIONS]); + ofpact_put_CLEAR_ACTIONS(ofpacts); + } + /* TODO:XXX Write-Actions */ + /* TODO:XXX Write-Metadata */ + if (insts[OVSINST_OFPIT11_GOTO_TABLE]) { + const struct ofp11_instruction_goto_table *oigt; + struct ofpact_goto_table *ogt; + + oigt = instruction_get_OFPIT11_GOTO_TABLE( + insts[OVSINST_OFPIT11_GOTO_TABLE]); + ogt = ofpact_put_GOTO_TABLE(ofpacts); + ogt->table_id = oigt->table_id; + } - if (insts[OVSINST_OFPIT11_GOTO_TABLE] || - insts[OVSINST_OFPIT11_WRITE_METADATA] || - insts[OVSINST_OFPIT11_WRITE_ACTIONS] || - insts[OVSINST_OFPIT11_CLEAR_ACTIONS]) { + if (insts[OVSINST_OFPIT11_WRITE_METADATA] || + insts[OVSINST_OFPIT11_WRITE_ACTIONS]) { error = OFPERR_OFPBIC_UNSUP_INST; goto exit; } @@ -1040,6 +1062,10 @@ ofpact_check__(const struct ofpact *a, const struct flow *flow, int max_ports) case OFPACT_EXIT: return 0; + case OFPACT_CLEAR_ACTIONS: + case OFPACT_GOTO_TABLE: + return 0; + default: NOT_REACHED(); } @@ -1255,6 +1281,8 @@ ofpact_to_nxast(const struct ofpact *a, struct ofpbuf *out) case OFPACT_SET_IPV4_DSCP: case OFPACT_SET_L4_SRC_PORT: case OFPACT_SET_L4_DST_PORT: + case OFPACT_CLEAR_ACTIONS: + case OFPACT_GOTO_TABLE: NOT_REACHED(); } } @@ -1344,6 +1372,11 @@ ofpact_to_openflow10(const struct ofpact *a, struct ofpbuf *out) = htons(ofpact_get_SET_L4_DST_PORT(a)->port); break; + case OFPACT_CLEAR_ACTIONS: + case OFPACT_GOTO_TABLE: + /* TODO:XXX */ + break; + case OFPACT_CONTROLLER: case OFPACT_OUTPUT_REG: case OFPACT_BUNDLE: @@ -1392,6 +1425,19 @@ ofpact_output_to_openflow11(const struct ofpact_output *output, oao->max_len = htons(output->max_len); } +static void +ofpact_dec_ttl_to_openflow11(const struct ofpact_cnt_ids *dec_ttl, + struct ofpbuf *out) +{ + if (dec_ttl->n_controllers == 1 && dec_ttl->cnt_ids[0] == 0 + && (!dec_ttl->ofpact.compat || + dec_ttl->ofpact.compat == OFPUTIL_OFPAT11_DEC_NW_TTL)) { + ofputil_put_OFPAT11_DEC_NW_TTL(out); + } else { + ofpact_dec_ttl_to_nxast(dec_ttl, out); + } +} + static void ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out) { @@ -1414,7 +1460,7 @@ ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out) break; case OFPACT_STRIP_VLAN: - /* XXX */ + ofputil_put_OFPAT11_POP_VLAN(out); break; case OFPACT_SET_ETH_SRC: @@ -1452,12 +1498,19 @@ ofpact_to_openflow11(const struct ofpact *a, struct ofpbuf *out) = htons(ofpact_get_SET_L4_DST_PORT(a)->port); break; + case OFPACT_DEC_TTL: + ofpact_dec_ttl_to_openflow11(ofpact_get_DEC_TTL(a), out); + break; + + case OFPACT_CLEAR_ACTIONS: + case OFPACT_GOTO_TABLE: + NOT_REACHED(); + case OFPACT_CONTROLLER: case OFPACT_OUTPUT_REG: case OFPACT_BUNDLE: case OFPACT_REG_MOVE: case OFPACT_REG_LOAD: - case OFPACT_DEC_TTL: case OFPACT_SET_TUNNEL: case OFPACT_SET_QUEUE: case OFPACT_POP_QUEUE: @@ -1490,18 +1543,10 @@ ofpacts_put_openflow11_actions(const struct ofpact ofpacts[], return openflow->size - start_size; } -void -ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[], - size_t ofpacts_len, - struct ofpbuf *openflow) +static void +ofpacts_update_instruction_actions(struct ofpbuf *openflow, size_t ofs) { struct ofp11_instruction_actions *oia; - size_t ofs; - - /* Put an OFPIT11_APPLY_ACTIONS instruction and fill it in. */ - ofs = openflow->size; - instruction_put_OFPIT11_APPLY_ACTIONS(openflow); - ofpacts_put_openflow11_actions(ofpacts, ofpacts_len, openflow); /* Update the instruction's length (or, if it's empty, delete it). */ oia = ofpbuf_at_assert(openflow, ofs, sizeof *oia); @@ -1511,6 +1556,46 @@ ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[], openflow->size = ofs; } } + +void +ofpacts_put_openflow11_instructions(const struct ofpact ofpacts[], + size_t ofpacts_len, + struct ofpbuf *openflow) +{ + const struct ofpact *a; + + OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) { + /* TODO:XXX Write-Actions */ + /* TODO:XXX Write-Metadata */ + if (a->type == OFPACT_CLEAR_ACTIONS) { + instruction_put_OFPIT11_CLEAR_ACTIONS(openflow); + } else if (a->type == OFPACT_GOTO_TABLE) { + struct ofp11_instruction_goto_table *oigt; + + oigt = instruction_put_OFPIT11_GOTO_TABLE(openflow); + oigt->table_id = ofpact_get_GOTO_TABLE(a)->table_id; + memset(oigt->pad, 0, sizeof oigt->pad); + } else if (!ofpact_is_instruction(a)) { + /* Apply-actions */ + const size_t ofs = openflow->size; + const size_t ofpacts_len_left = + (uint8_t*)ofpact_end(ofpacts, ofpacts_len) - (uint8_t*)a; + const struct ofpact *action; + const struct ofpact *processed = a; + + instruction_put_OFPIT11_APPLY_ACTIONS(openflow); + OFPACT_FOR_EACH(action, a, ofpacts_len_left) { + if (ofpact_is_instruction(action)) { + break; + } + ofpact_to_openflow11(action, openflow); + processed = action; + } + ofpacts_update_instruction_actions(openflow, ofs); + a = processed; + } + } +} /* Returns true if 'action' outputs to 'port', false otherwise. */ static bool @@ -1549,6 +1634,8 @@ ofpact_outputs_to_port(const struct ofpact *ofpact, uint16_t port) case OFPACT_AUTOPATH: case OFPACT_NOTE: case OFPACT_EXIT: + case OFPACT_CLEAR_ACTIONS: + case OFPACT_GOTO_TABLE: default: return false; } @@ -1815,6 +1902,19 @@ ofpact_format(const struct ofpact *a, struct ds *s) case OFPACT_EXIT: ds_put_cstr(s, "exit"); break; + + case OFPACT_CLEAR_ACTIONS: + ds_put_format(s, "%s", + ofpact_instruction_name_from_type( + OVSINST_OFPIT11_CLEAR_ACTIONS)); + break; + + case OFPACT_GOTO_TABLE: + ds_put_format(s, "%s:%"PRIu8, + ofpact_instruction_name_from_type( + OVSINST_OFPIT11_GOTO_TABLE), + ofpact_get_GOTO_TABLE(a)->table_id); + break; } } @@ -1834,6 +1934,9 @@ ofpacts_format(const struct ofpact *ofpacts, size_t ofpacts_len, if (a != ofpacts) { ds_put_cstr(string, ","); } + + /* TODO:XXX write-actions */ + /* TODO:XXX write-metadata */ ofpact_format(a, string); } } @@ -1892,3 +1995,15 @@ ofpact_pad(struct ofpbuf *ofpacts) ofpbuf_put_zeros(ofpacts, OFPACT_ALIGNTO - rem); } } + +void +ofpact_set_field_init(struct ofpact_reg_load *load, const struct mf_field *mf, + const void *src) +{ + load->ofpact.compat = OFPUTIL_OFPAT12_SET_FIELD; + load->dst.field = mf; + load->dst.ofs = 0; + load->dst.n_bits = mf->n_bits; + bitwise_copy(src, mf->n_bytes, load->dst.ofs, + &load->subvalue, sizeof load->subvalue, 0, mf->n_bits); +}