Message ID | f8b2ce76444797ac139d1d8304a5a7f44fd4fd3a.1631107257.git.lorenzo.bianconi@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | [ovs-dev,v2] controller: add datapath meter capability check | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
ovsrobot/github-robot-_ovn-kubernetes | fail | github build: failed |
On 08/09/2021 14:27, Lorenzo Bianconi wrote: > Dump datapath meter capabilities before configuring meters in > ovn-controller > > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> > --- > Changes since v1: > - move rconn in ovn-controller to avoid concurrency issues > --- > controller/lflow.c | 2 +- > controller/ovn-controller.c | 65 +++++++++++++++++++++++++++++++++++++ > controller/ovn-controller.h | 2 ++ > 3 files changed, 68 insertions(+), 1 deletion(-) > > diff --git a/controller/lflow.c b/controller/lflow.c > index 923d8f0a4..d4fda6114 100644 > --- a/controller/lflow.c > +++ b/controller/lflow.c > @@ -648,7 +648,7 @@ add_matches_to_flow_table(const struct sbrec_logical_flow *lflow, > .ct_snat_vip_ptable = OFTABLE_CT_SNAT_HAIRPIN, > .fdb_ptable = OFTABLE_GET_FDB, > .fdb_lookup_ptable = OFTABLE_LOOKUP_FDB, > - .ctrl_meter_id = ctrl_meter_id, > + .ctrl_meter_id = dp_meter_capa > 0 ? ctrl_meter_id : NX_CTLR_NO_METER, > }; I would prefer to not share this as a global variable to reduce the coupling. I think you can pass this down to this function through lflow_ctx_in. > ovnacts_encode(ovnacts->data, ovnacts->size, &ep, &ofpacts); > > diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c > index 0031a1035..5e77f5c2e 100644 > --- a/controller/ovn-controller.c > +++ b/controller/ovn-controller.c > @@ -73,6 +73,9 @@ > #include "stopwatch.h" > #include "lib/inc-proc-eng.h" > #include "hmapx.h" > +#include "openvswitch/rconn.h" > +#include "openvswitch/ofp-msgs.h" > +#include "openvswitch/ofp-meter.h" > > VLOG_DEFINE_THIS_MODULE(main); > > @@ -117,6 +120,9 @@ static const char *ssl_private_key_file; > static const char *ssl_certificate_file; > static const char *ssl_ca_cert_file; > > +/* datapath meter capabilities. */ > +int dp_meter_capa = -1; Is there a reason this is an 'int'. I can't see and I think you are just trying to show if the functionality is available or not? maybe a bool would be better. > + > /* By default don't set an upper bound for the lflow cache and enable auto > * trimming above 10K logical flows when reducing cache size by 50%. > */ > @@ -3065,6 +3071,58 @@ check_northd_version(struct ovsdb_idl *ovs_idl, struct ovsdb_idl *ovnsb_idl, > return true; > } > > +static void > +ovn_controller_connect_vswitch(struct rconn *swconn, > + const struct ovsrec_bridge *br_int) > +{ > + if (!rconn_is_connected(swconn)) { > + char *target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), > + br_int->name); > + if (strcmp(target, rconn_get_target(swconn))) { > + VLOG_INFO("%s: connecting to switch", target); > + rconn_connect(swconn, target, target); > + } > + free(target); > + } > +} > + > +static void > +ovn_controller_get_meter_capa(struct rconn *swconn) > +{ > + if (dp_meter_capa >= 0) { > + return; > + } > + > + rconn_run(swconn); > + if (!rconn_is_connected(swconn)) { > + return; > + } > + > + /* dump datapath meter capabilities. */ > + struct ofpbuf *msg = ofpraw_alloc(OFPRAW_OFPST13_METER_FEATURES_REQUEST, > + rconn_get_version(swconn), 0); > + rconn_send(swconn, msg, NULL); > + for (int i = 0; i < 10; i++) { > + msg = rconn_recv(swconn); > + if (!msg) { > + break; > + } > + > + const struct ofp_header *oh = msg->data; > + enum ofptype type; > + ofptype_decode(&type, oh); > + > + if (type == OFPTYPE_METER_FEATURES_STATS_REPLY) { > + struct ofputil_meter_features mf; > + > + ofputil_decode_meter_features(oh, &mf); > + dp_meter_capa = mf.max_meters > 0; > + engine_set_force_recompute(true); > + } > + ofpbuf_delete(msg); > + } > +} > + > int > main(int argc, char *argv[]) > { > @@ -3445,6 +3503,8 @@ main(int argc, char *argv[]) > char *ovn_version = ovn_get_internal_version(); > VLOG_INFO("OVN internal version is : [%s]", ovn_version); > > + struct rconn *swconn = rconn_create(5, 0, DSCP_DEFAULT, > + 1 << OFP15_VERSION); > /* Main loop. */ > exiting = false; > restart = false; > @@ -3523,6 +3583,10 @@ main(int argc, char *argv[]) > ovsrec_server_has_datapath_table(ovs_idl_loop.idl) > ? &br_int_dp > : NULL); > + if (br_int) { > + ovn_controller_connect_vswitch(swconn, br_int); > + } > + ovn_controller_get_meter_capa(swconn); This reminds me a lot of what ovs_feature_is_supported() in features.c/.h is trying to do. I think you should integrate your change into there somehow rather than creating a once-off interface for dp-meters. Currently, features.c is only checking the capabilities by reading the bridge capabilities table in OVS but I think it would make sense to expand this for capabilities that we can only check by probing over OpenFlow, as you are doing - the first instance of which would be DP_METERS support. What do you think? > > /* Enable ACL matching for double tagged traffic. */ > if (ovs_idl_txn) { > @@ -3898,6 +3962,7 @@ loop_done: > ovsdb_idl_loop_destroy(&ovs_idl_loop); > ovsdb_idl_loop_destroy(&ovnsb_idl_loop); > > + rconn_destroy(swconn); > free(ovs_remote); > service_stop(); > > diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h > index 78a53312f..0eda72724 100644 > --- a/controller/ovn-controller.h > +++ b/controller/ovn-controller.h > @@ -22,6 +22,8 @@ > > struct ovsrec_bridge_table; > > +extern int dp_meter_capa; > + > /* Linux supports a maximum of 64K zones, which seems like a fine default. */ > #define MAX_CT_ZONES 65535 > >
diff --git a/controller/lflow.c b/controller/lflow.c index 923d8f0a4..d4fda6114 100644 --- a/controller/lflow.c +++ b/controller/lflow.c @@ -648,7 +648,7 @@ add_matches_to_flow_table(const struct sbrec_logical_flow *lflow, .ct_snat_vip_ptable = OFTABLE_CT_SNAT_HAIRPIN, .fdb_ptable = OFTABLE_GET_FDB, .fdb_lookup_ptable = OFTABLE_LOOKUP_FDB, - .ctrl_meter_id = ctrl_meter_id, + .ctrl_meter_id = dp_meter_capa > 0 ? ctrl_meter_id : NX_CTLR_NO_METER, }; ovnacts_encode(ovnacts->data, ovnacts->size, &ep, &ofpacts); diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 0031a1035..5e77f5c2e 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -73,6 +73,9 @@ #include "stopwatch.h" #include "lib/inc-proc-eng.h" #include "hmapx.h" +#include "openvswitch/rconn.h" +#include "openvswitch/ofp-msgs.h" +#include "openvswitch/ofp-meter.h" VLOG_DEFINE_THIS_MODULE(main); @@ -117,6 +120,9 @@ static const char *ssl_private_key_file; static const char *ssl_certificate_file; static const char *ssl_ca_cert_file; +/* datapath meter capabilities. */ +int dp_meter_capa = -1; + /* By default don't set an upper bound for the lflow cache and enable auto * trimming above 10K logical flows when reducing cache size by 50%. */ @@ -3065,6 +3071,58 @@ check_northd_version(struct ovsdb_idl *ovs_idl, struct ovsdb_idl *ovnsb_idl, return true; } +static void +ovn_controller_connect_vswitch(struct rconn *swconn, + const struct ovsrec_bridge *br_int) +{ + if (!rconn_is_connected(swconn)) { + char *target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), + br_int->name); + if (strcmp(target, rconn_get_target(swconn))) { + VLOG_INFO("%s: connecting to switch", target); + rconn_connect(swconn, target, target); + } + free(target); + } +} + +static void +ovn_controller_get_meter_capa(struct rconn *swconn) +{ + if (dp_meter_capa >= 0) { + return; + } + + rconn_run(swconn); + if (!rconn_is_connected(swconn)) { + return; + } + + /* dump datapath meter capabilities. */ + struct ofpbuf *msg = ofpraw_alloc(OFPRAW_OFPST13_METER_FEATURES_REQUEST, + rconn_get_version(swconn), 0); + rconn_send(swconn, msg, NULL); + for (int i = 0; i < 10; i++) { + msg = rconn_recv(swconn); + if (!msg) { + break; + } + + const struct ofp_header *oh = msg->data; + enum ofptype type; + ofptype_decode(&type, oh); + + if (type == OFPTYPE_METER_FEATURES_STATS_REPLY) { + struct ofputil_meter_features mf; + + ofputil_decode_meter_features(oh, &mf); + dp_meter_capa = mf.max_meters > 0; + engine_set_force_recompute(true); + } + ofpbuf_delete(msg); + } +} + int main(int argc, char *argv[]) { @@ -3445,6 +3503,8 @@ main(int argc, char *argv[]) char *ovn_version = ovn_get_internal_version(); VLOG_INFO("OVN internal version is : [%s]", ovn_version); + struct rconn *swconn = rconn_create(5, 0, DSCP_DEFAULT, + 1 << OFP15_VERSION); /* Main loop. */ exiting = false; restart = false; @@ -3523,6 +3583,10 @@ main(int argc, char *argv[]) ovsrec_server_has_datapath_table(ovs_idl_loop.idl) ? &br_int_dp : NULL); + if (br_int) { + ovn_controller_connect_vswitch(swconn, br_int); + } + ovn_controller_get_meter_capa(swconn); /* Enable ACL matching for double tagged traffic. */ if (ovs_idl_txn) { @@ -3898,6 +3962,7 @@ loop_done: ovsdb_idl_loop_destroy(&ovs_idl_loop); ovsdb_idl_loop_destroy(&ovnsb_idl_loop); + rconn_destroy(swconn); free(ovs_remote); service_stop(); diff --git a/controller/ovn-controller.h b/controller/ovn-controller.h index 78a53312f..0eda72724 100644 --- a/controller/ovn-controller.h +++ b/controller/ovn-controller.h @@ -22,6 +22,8 @@ struct ovsrec_bridge_table; +extern int dp_meter_capa; + /* Linux supports a maximum of 64K zones, which seems like a fine default. */ #define MAX_CT_ZONES 65535
Dump datapath meter capabilities before configuring meters in ovn-controller Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> --- Changes since v1: - move rconn in ovn-controller to avoid concurrency issues --- controller/lflow.c | 2 +- controller/ovn-controller.c | 65 +++++++++++++++++++++++++++++++++++++ controller/ovn-controller.h | 2 ++ 3 files changed, 68 insertions(+), 1 deletion(-)