Skip to content

Commit

Permalink
ofp-monitor: Extend Flow Monitoring support for OF 1.0-1.2 with Nicir…
Browse files Browse the repository at this point in the history
…a Extensions.

Currently OVS supports flow-monitoring for OpenFlow 1.0 and Nicira Extenstions.
Any other OpenFlow versioned messages are not accepted. This change will allow
OpenFlow1.0-1.2 Flow Monitoring with Nicira extensions be accepted. Also made
sure that flow-monitoring updates, flow monitoring pause messages, resume
messages are sent in the same OpenFlow version as that of flow-monitor request.

Description of changes:

1. Generate ofp-msgs.inc to be able to support 1.0-1.2 Flow Monitoring messages.
include/openvswitch/ofp-msgs.h

2. Support vconn to accept user specified version and use it for vconn
flow-monitoring session
ofproto/ofproto.c

3. Modify APIs to use protocol as an argument to encode and decode messages
include/openvswitch/ofp-monitor.h
lib/ofp-monitor.c
ofproto/connmgr.c
ofproto/connmgr.h
ofproto/ofproto.c

4. Modified following testcases to be verified across supported OF Versions
    ofproto - flow monitoring
    ofproto - flow monitoring with !own
    ofproto - flow monitoring with out_port
    ofproto - flow monitoring pause and resume
    ofproto - flow monitoring usable protocols
tests/ofproto.at

5. Updated NEWS with the support added with this commit

Signed-off-by: Vasu Dasari <[email protected]>
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2020-December/050820.html
Acked-by: Aaron Conole <[email protected]>
Signed-off-by: Ilya Maximets <[email protected]>
  • Loading branch information
vasu-dasari authored and igsilya committed Apr 28, 2022
1 parent d94cd0d commit d8ab75c
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 106 deletions.
2 changes: 1 addition & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ Tony van der Peet [email protected]
Tonghao Zhang [email protected]
Usman Ansari [email protected]
Valient Gough [email protected]
Vasu Dasari [email protected]
Venkata Anil Kommaddi [email protected]
Vishal Deep Ajmera [email protected]
Vivien Bernet-Rollande [email protected]
Expand Down Expand Up @@ -700,7 +701,6 @@ Tulio Ribeiro [email protected]
Tytus Kurek [email protected]
Valentin Bud [email protected]
Vasiliy Tolstov [email protected]
Vasu Dasari [email protected]
Vinllen Chen [email protected]
Vishal Swarankar [email protected]
Vjekoslav Brajkovic [email protected]
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Post-v2.17.0
* New monitor mode flag, OVSDB_IDL_WRITE_CHANGED_ONLY, allowing
applications to relax atomicity requirements when dealing with
columns whose value has been rewritten (but not changed).
- OpenFlow:
* Added Flow Monitoring support for OpenFlow 1.0-1.2 with Nicira
Extensions.


v2.17.0 - 17 Feb 2022
Expand Down
9 changes: 6 additions & 3 deletions include/openvswitch/ofp-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ struct ofputil_flow_monitor_request {
int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
struct ofpbuf *msg);
void ofputil_append_flow_monitor_request(
const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
const struct ofputil_flow_monitor_request *, struct ofpbuf *msg,
enum ofputil_protocol protocol);
void ofputil_flow_monitor_request_format(
struct ds *, const struct ofputil_flow_monitor_request *,
const struct ofputil_port_map *, const struct ofputil_table_map *);
Expand Down Expand Up @@ -103,7 +104,8 @@ struct ofputil_flow_update {

int ofputil_decode_flow_update(struct ofputil_flow_update *,
struct ofpbuf *msg, struct ofpbuf *ofpacts);
void ofputil_start_flow_update(struct ovs_list *replies);
void ofputil_start_flow_update(struct ovs_list *replies,
enum ofputil_protocol protocol);
void ofputil_append_flow_update(const struct ofputil_flow_update *,
struct ovs_list *replies,
const struct tun_table *);
Expand All @@ -114,7 +116,8 @@ void ofputil_flow_update_format(struct ds *,

/* Abstract nx_flow_monitor_cancel. */
uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
struct ofpbuf *ofputil_encode_flow_monitor_cancel(
uint32_t id, enum ofputil_protocol protocol);

struct ofputil_requestforward {
ovs_be32 xid;
Expand Down
4 changes: 2 additions & 2 deletions include/openvswitch/ofp-msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,12 @@ enum ofpraw {

/* OFPST 1.4+ (16): uint8_t[8][]. */
OFPRAW_OFPST14_FLOW_MONITOR_REQUEST,
/* NXST 1.0 (2): uint8_t[8][]. */
/* NXST 1.0-1.2 (2): uint8_t[8][]. */
OFPRAW_NXST_FLOW_MONITOR_REQUEST,

/* OFPST 1.4+ (16): uint8_t[8][]. */
OFPRAW_OFPST14_FLOW_MONITOR_REPLY,
/* NXST 1.0 (2): uint8_t[8][]. */
/* NXST 1.0-1.2 (2): uint8_t[8][]. */
OFPRAW_NXST_FLOW_MONITOR_REPLY,

/* Nicira extension messages.
Expand Down
20 changes: 11 additions & 9 deletions lib/ofp-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,16 @@ ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *rq,

void
ofputil_append_flow_monitor_request(
const struct ofputil_flow_monitor_request *rq, struct ofpbuf *msg)
const struct ofputil_flow_monitor_request *rq, struct ofpbuf *msg,
enum ofputil_protocol protocol)
{
struct nx_flow_monitor_request *nfmr;
size_t start_ofs;
int match_len;
enum ofp_version version = ofputil_protocol_to_ofp_version(protocol);

if (!msg->size) {
ofpraw_put(OFPRAW_NXST_FLOW_MONITOR_REQUEST, OFP10_VERSION, msg);
ofpraw_put(OFPRAW_NXST_FLOW_MONITOR_REQUEST, version, msg);
}

start_ofs = msg->size;
Expand Down Expand Up @@ -517,9 +519,6 @@ parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
if (error) {
return error;
}
/* Flow Monitor is supported in OpenFlow 1.0 or can be further reduced
* to a few 1.0 flavors by a match field. */
*usable_protocols &= OFPUTIL_P_OF10_ANY;
}
return NULL;
}
Expand Down Expand Up @@ -661,23 +660,26 @@ ofputil_decode_flow_monitor_cancel(const struct ofp_header *oh)
}

struct ofpbuf *
ofputil_encode_flow_monitor_cancel(uint32_t id)
ofputil_encode_flow_monitor_cancel(uint32_t id, enum ofputil_protocol protocol)
{
struct nx_flow_monitor_cancel *nfmc;
enum ofp_version version = ofputil_protocol_to_ofp_version(protocol);
struct ofpbuf *msg;

msg = ofpraw_alloc(OFPRAW_NXT_FLOW_MONITOR_CANCEL, OFP10_VERSION, 0);
msg = ofpraw_alloc(OFPRAW_NXT_FLOW_MONITOR_CANCEL, version, 0);
nfmc = ofpbuf_put_uninit(msg, sizeof *nfmc);
nfmc->id = htonl(id);
return msg;
}

void
ofputil_start_flow_update(struct ovs_list *replies)
ofputil_start_flow_update(struct ovs_list *replies,
enum ofputil_protocol protocol)
{
struct ofpbuf *msg;
enum ofp_version version = ofputil_protocol_to_ofp_version(protocol);

msg = ofpraw_alloc_xid(OFPRAW_NXST_FLOW_MONITOR_REPLY, OFP10_VERSION,
msg = ofpraw_alloc_xid(OFPRAW_NXST_FLOW_MONITOR_REPLY, version,
htonl(0), 1024);

ovs_list_init(replies);
Expand Down
18 changes: 13 additions & 5 deletions ofproto/connmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,8 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule,

if (flags) {
if (ovs_list_is_empty(&ofconn->updates)) {
ofputil_start_flow_update(&ofconn->updates);
ofputil_start_flow_update(&ofconn->updates,
ofconn_get_protocol(ofconn));
ofconn->sent_abbrev_update = false;
}

Expand Down Expand Up @@ -2243,6 +2244,7 @@ ofmonitor_flush(struct connmgr *mgr)
OVS_REQUIRES(ofproto_mutex)
{
struct ofconn *ofconn;
enum ofputil_protocol protocol;

if (!mgr) {
return;
Expand All @@ -2260,8 +2262,10 @@ ofmonitor_flush(struct connmgr *mgr)
&& rconn_packet_counter_n_bytes(counter) > 128 * 1024) {
COVERAGE_INC(ofmonitor_pause);
ofconn->monitor_paused = monitor_seqno++;
protocol = ofconn_get_protocol(ofconn);
struct ofpbuf *pause = ofpraw_alloc_xid(
OFPRAW_NXT_FLOW_MONITOR_PAUSED, OFP10_VERSION, htonl(0), 0);
OFPRAW_NXT_FLOW_MONITOR_PAUSED,
ofputil_protocol_to_ofp_version(protocol), htonl(0), 0);
ofconn_send(ofconn, pause, counter);
}
}
Expand All @@ -2271,6 +2275,7 @@ static void
ofmonitor_resume(struct ofconn *ofconn)
OVS_REQUIRES(ofproto_mutex)
{
enum ofputil_protocol protocol;
struct rule_collection rules;
rule_collection_init(&rules);

Expand All @@ -2280,10 +2285,13 @@ ofmonitor_resume(struct ofconn *ofconn)
}

struct ovs_list msgs = OVS_LIST_INITIALIZER(&msgs);
ofmonitor_compose_refresh_updates(&rules, &msgs);
ofmonitor_compose_refresh_updates(&rules, &msgs,
ofconn_get_protocol(ofconn));

struct ofpbuf *resumed = ofpraw_alloc_xid(OFPRAW_NXT_FLOW_MONITOR_RESUMED,
OFP10_VERSION, htonl(0), 0);
protocol = ofconn_get_protocol(ofconn);
struct ofpbuf *resumed = ofpraw_alloc_xid(
OFPRAW_NXT_FLOW_MONITOR_RESUMED,
ofputil_protocol_to_ofp_version(protocol), htonl(0), 0);
ovs_list_push_back(&msgs, &resumed->list_node);
ofconn_send_replies(ofconn, &msgs);

Expand Down
3 changes: 2 additions & 1 deletion ofproto/connmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ void ofmonitor_collect_resume_rules(struct ofmonitor *, uint64_t seqno,
struct rule_collection *)
OVS_REQUIRES(ofproto_mutex);
void ofmonitor_compose_refresh_updates(struct rule_collection *rules,
struct ovs_list *msgs)
struct ovs_list *msgs,
enum ofputil_protocol protocol)
OVS_REQUIRES(ofproto_mutex);

void connmgr_send_table_status(struct connmgr *,
Expand Down
13 changes: 8 additions & 5 deletions ofproto/ofproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -6421,7 +6421,8 @@ static void
ofproto_compose_flow_refresh_update(const struct rule *rule,
enum nx_flow_monitor_flags flags,
struct ovs_list *msgs,
const struct tun_table *tun_table)
const struct tun_table *tun_table,
enum ofputil_protocol protocol)
OVS_REQUIRES(ofproto_mutex)
{
const struct rule_actions *actions;
Expand All @@ -6444,14 +6445,15 @@ ofproto_compose_flow_refresh_update(const struct rule *rule,
fu.ofpacts_len = actions ? actions->ofpacts_len : 0;

if (ovs_list_is_empty(msgs)) {
ofputil_start_flow_update(msgs);
ofputil_start_flow_update(msgs, protocol);
}
ofputil_append_flow_update(&fu, msgs, tun_table);
}

void
ofmonitor_compose_refresh_updates(struct rule_collection *rules,
struct ovs_list *msgs)
struct ovs_list *msgs,
enum ofputil_protocol protocol)
OVS_REQUIRES(ofproto_mutex)
{
struct rule *rule;
Expand All @@ -6461,7 +6463,7 @@ ofmonitor_compose_refresh_updates(struct rule_collection *rules,
rule->monitor_flags = 0;

ofproto_compose_flow_refresh_update(rule, flags, msgs,
ofproto_get_tun_tab(rule->ofproto));
ofproto_get_tun_tab(rule->ofproto), protocol);
}
}

Expand Down Expand Up @@ -6625,7 +6627,8 @@ handle_flow_monitor_request(struct ofconn *ofconn, const struct ovs_list *msgs)

struct ovs_list replies;
ofpmp_init(&replies, ofpbuf_from_list(ovs_list_back(msgs))->header);
ofmonitor_compose_refresh_updates(&rules, &replies);
ofmonitor_compose_refresh_updates(&rules, &replies,
ofconn_get_protocol(ofconn));
ovs_mutex_unlock(&ofproto_mutex);

rule_collection_destroy(&rules);
Expand Down
Loading

0 comments on commit d8ab75c

Please sign in to comment.