From 049c8dc2128f3d336c4b791bb34ec806ddac6b4b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 11 Nov 2010 11:01:09 -0800 Subject: [PATCH] ofp-parse: Generalize parse_ofp_add_flow_str() as parse_ofp_flow_mod_str(). This generalization allows us to delete several lines of code from ovs-ofctl.c. --- lib/ofp-parse.c | 10 +++--- lib/ofp-parse.h | 2 +- utilities/ovs-ofctl.c | 71 ++++++------------------------------------- 3 files changed, 15 insertions(+), 68 deletions(-) diff --git a/lib/ofp-parse.c b/lib/ofp-parse.c index d563a4e4..dfb257d4 100644 --- a/lib/ofp-parse.c +++ b/lib/ofp-parse.c @@ -519,10 +519,10 @@ parse_ofp_str(char *string, struct ofp_match *match, struct ofpbuf *actions, } } -/* Parses 'string' as a OFPT_FLOW_MOD with subtype OFPFC_ADD and returns an - * ofpbuf that contains it. */ +/* Parses 'string' as an OFPT_FLOW_MOD with command 'command' (one of OFPFC_*) + * and returns an ofpbuf that contains it. */ struct ofpbuf * -parse_ofp_add_flow_str(char *string) +parse_ofp_flow_mod_str(char *string, uint16_t command) { struct ofpbuf *buffer; struct ofp_flow_mod *ofm; @@ -538,10 +538,10 @@ parse_ofp_add_flow_str(char *string) &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->command = htons(command); ofm->buffer_id = htonl(UINT32_MAX); ofm->priority = htons(priority); update_openflow_length(buffer); @@ -573,7 +573,7 @@ parse_ofp_add_flow_file(FILE *stream) continue; } - b = parse_ofp_add_flow_str(line); + b = parse_ofp_flow_mod_str(line, OFPFC_ADD); break; } ds_destroy(&s); diff --git a/lib/ofp-parse.h b/lib/ofp-parse.h index ac8e6d2f..5ad7d20f 100644 --- a/lib/ofp-parse.h +++ b/lib/ofp-parse.h @@ -30,7 +30,7 @@ void parse_ofp_str(char *string, struct ofp_match *match, uint16_t *out_port, uint16_t *priority, uint16_t *idle_timeout, uint16_t *hard_timeout, uint64_t *cookie); -struct ofpbuf *parse_ofp_add_flow_str(char *string); +struct ofpbuf *parse_ofp_flow_mod_str(char *string, uint16_t command); struct ofpbuf *parse_ofp_add_flow_file(FILE *); #endif /* ofp-parse.h */ diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 73a8fca4..b11defaf 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -495,26 +495,8 @@ do_add_flow(int argc OVS_UNUSED, char *argv[]) { struct vconn *vconn; struct ofpbuf *buffer; - struct ofp_flow_mod *ofm; - uint16_t priority, idle_timeout, hard_timeout; - uint64_t cookie; - struct ofp_match match; - - /* Parse and send. 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(argv[2], &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); + + buffer = parse_ofp_flow_mod_str(argv[2], OFPFC_ADD); open_vconn(argv[1], &vconn); send_openflow_buffer(vconn, buffer); @@ -544,33 +526,12 @@ do_add_flows(int argc OVS_UNUSED, char *argv[]) static void do_mod_flows(int argc OVS_UNUSED, char *argv[]) { - uint16_t priority, idle_timeout, hard_timeout; - uint64_t cookie; struct vconn *vconn; struct ofpbuf *buffer; - struct ofp_flow_mod *ofm; - struct ofp_match match; - - /* Parse and send. 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(argv[2], &match, buffer, - NULL, NULL, &priority, &idle_timeout, &hard_timeout, - &cookie); - ofm = buffer->data; - ofm->match = match; - if (strict) { - ofm->command = htons(OFPFC_MODIFY_STRICT); - } else { - ofm->command = htons(OFPFC_MODIFY); - } - ofm->idle_timeout = htons(idle_timeout); - ofm->hard_timeout = htons(hard_timeout); - ofm->cookie = htonll(cookie); - ofm->buffer_id = htonl(UINT32_MAX); - ofm->priority = htons(priority); + uint16_t command; + command = strict ? OFPFC_MODIFY_STRICT : OFPFC_MODIFY; + buffer = parse_ofp_flow_mod_str(argv[2], command); open_vconn(argv[1], &vconn); send_openflow_buffer(vconn, buffer); vconn_close(vconn); @@ -579,25 +540,11 @@ do_mod_flows(int argc OVS_UNUSED, char *argv[]) static void do_del_flows(int argc, char *argv[]) { struct vconn *vconn; - uint16_t priority; - uint16_t out_port; struct ofpbuf *buffer; - struct ofp_flow_mod *ofm; - - /* Parse and send. */ - ofm = make_openflow(sizeof *ofm, OFPT_FLOW_MOD, &buffer); - parse_ofp_str(argc > 2 ? argv[2] : "", &ofm->match, NULL, NULL, - &out_port, &priority, NULL, NULL, NULL); - if (strict) { - ofm->command = htons(OFPFC_DELETE_STRICT); - } else { - ofm->command = htons(OFPFC_DELETE); - } - ofm->idle_timeout = htons(0); - ofm->hard_timeout = htons(0); - ofm->buffer_id = htonl(UINT32_MAX); - ofm->out_port = htons(out_port); - ofm->priority = htons(priority); + uint16_t command; + + command = strict ? OFPFC_DELETE_STRICT : OFPFC_DELETE; + buffer = parse_ofp_flow_mod_str(argc > 2 ? argv[2] : "", command); open_vconn(argv[1], &vconn); send_openflow_buffer(vconn, buffer); -- 2.30.2