X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fofp-parse.c;h=7a888801e7159043743f2baf244ef4a214e49178;hb=8497dd41214ddaac26928f2efa90becd1b336a52;hp=32e790a86b4e23c3df03c67d4c8376a32e150576;hpb=bb98f9b951af0f6438d921522a8f54f5ead0d1d0;p=openvswitch diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index 32e790a8..7a888801 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -21,6 +21,7 @@ #include #include +#include "dynamic-string.h" #include "netdev.h" #include "ofp-util.h" #include "ofpbuf.h" @@ -29,7 +30,7 @@ #include "socket-util.h" #include "vconn.h" #include "vlog.h" - +#include "xtoxll.h" VLOG_DEFINE_THIS_MODULE(ofp_parse) @@ -266,6 +267,17 @@ str_to_action(char *str, struct ofpbuf *b) nah = put_action(b, sizeof *nah, OFPAT_VENDOR); nah->vendor = htonl(NX_VENDOR_ID); nah->subtype = htons(NXAST_DROP_SPOOFED_ARP); + } else if (!strcasecmp(act, "set_queue")) { + struct nx_action_set_queue *nasq; + nasq = put_action(b, sizeof *nasq, OFPAT_VENDOR); + nasq->vendor = htonl(NX_VENDOR_ID); + nasq->subtype = htons(NXAST_SET_QUEUE); + nasq->queue_id = htonl(str_to_u32(arg)); + } else if (!strcasecmp(act, "pop_queue")) { + struct nx_action_header *nah; + nah = put_action(b, sizeof *nah, OFPAT_VENDOR); + nah->vendor = htonl(NX_VENDOR_ID); + nah->subtype = htons(NXAST_POP_QUEUE); } else if (!strcasecmp(act, "output")) { put_output_action(b, str_to_u32(arg)); } else if (!strcasecmp(act, "enqueue")) { @@ -502,3 +514,65 @@ parse_ofp_str(char *string, struct ofp_match *match, struct ofpbuf *actions, free(new); } } + +/* Parses 'string' as a OFPT_FLOW_MOD with subtype OFPFC_ADD and returns an + * ofpbuf that contains it. */ +struct ofpbuf * +parse_ofp_add_flow_str(char *string) +{ + struct ofpbuf *buffer; + struct ofp_flow_mod *ofm; + uint16_t priority, idle_timeout, hard_timeout; + uint64_t cookie; + struct ofp_match match; + + /* parse_ofp_str() will expand and reallocate the data in 'buffer', so we + * can't keep pointers to across the parse_ofp_str() call. */ + make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer); + parse_ofp_str(string, &match, buffer, + NULL, NULL, &priority, &idle_timeout, &hard_timeout, + &cookie); + ofm = buffer->data; + ofm->match = match; + ofm->command = htons(OFPFC_ADD); + ofm->cookie = htonll(cookie); + ofm->idle_timeout = htons(idle_timeout); + ofm->hard_timeout = htons(hard_timeout); + ofm->buffer_id = htonl(UINT32_MAX); + ofm->priority = htons(priority); + update_openflow_length(buffer); + + return buffer; +} + +/* Parses an OFPT_FLOW_MOD with subtype OFPFC_ADD from 'stream' and returns an + * ofpbuf that contains it. Returns a null pointer if end-of-file is reached + * before reading a flow. */ +struct ofpbuf * +parse_ofp_add_flow_file(FILE *stream) +{ + struct ofpbuf *b = NULL; + struct ds s = DS_EMPTY_INITIALIZER; + + while (!ds_get_line(&s, stream)) { + char *line = ds_cstr(&s); + char *comment; + + /* Delete comments. */ + comment = strchr(line, '#'); + if (comment) { + *comment = '\0'; + } + + /* Drop empty lines. */ + if (line[strspn(line, " \t\n")] == '\0') { + continue; + } + + b = parse_ofp_add_flow_str(line); + break; + } + ds_destroy(&s); + + return b; +}