cfm: Cleanup CFM module interface.
[sliver-openvswitch.git] / vswitchd / bridge.c
index ec4bb7b..aead346 100644 (file)
@@ -164,7 +164,6 @@ static bool bridge_has_bond_fake_iface(const struct bridge *,
                                        const char *name);
 static bool port_is_bond_fake_iface(const struct port *);
 
-static unixctl_cb_func cfm_unixctl_show;
 static unixctl_cb_func qos_unixctl_show;
 
 static struct port *port_create(struct bridge *, const struct ovsrec_port *);
@@ -245,10 +244,6 @@ bridge_init(const char *remote)
     ovsdb_idl_omit_alert(idl, &ovsrec_controller_col_status);
     ovsdb_idl_omit(idl, &ovsrec_controller_col_external_ids);
 
-    ovsdb_idl_omit_alert(idl, &ovsrec_maintenance_point_col_fault);
-
-    ovsdb_idl_omit_alert(idl, &ovsrec_monitor_col_fault);
-
     ovsdb_idl_omit(idl, &ovsrec_qos_col_external_ids);
 
     ovsdb_idl_omit(idl, &ovsrec_queue_col_external_ids);
@@ -268,7 +263,6 @@ bridge_init(const char *remote)
     ovsdb_idl_omit(idl, &ovsrec_ssl_col_external_ids);
 
     /* Register unixctl commands. */
-    unixctl_command_register("cfm/show", cfm_unixctl_show, NULL);
     unixctl_command_register("qos/show", qos_unixctl_show, NULL);
     unixctl_command_register("bridge/dump-flows", bridge_unixctl_dump_flows,
                              NULL);
@@ -276,6 +270,7 @@ bridge_init(const char *remote)
                              NULL);
     lacp_init();
     bond_init();
+    cfm_init();
 }
 
 void
@@ -1220,33 +1215,20 @@ iface_refresh_status(struct iface *iface)
 static bool
 iface_refresh_cfm_stats(struct iface *iface)
 {
-    const struct ovsrec_monitor *mon;
-    const struct cfm *cfm;
+    const struct ovsrec_interface *cfg = iface->cfg;
     bool changed = false;
-    size_t i;
+    int fault;
 
-    mon = iface->cfg->monitor;
-    cfm = ofproto_port_get_cfm(iface->port->bridge->ofproto, iface->ofp_port);
+    fault = ofproto_port_get_cfm_fault(iface->port->bridge->ofproto,
+                                       iface->ofp_port);
 
-    if (!cfm || !mon) {
+    if (fault < 0) {
         return false;
     }
 
-    for (i = 0; i < mon->n_remote_mps; i++) {
-        const struct ovsrec_maintenance_point *mp;
-        const struct remote_mp *rmp;
-
-        mp = mon->remote_mps[i];
-        rmp = cfm_get_remote_mp(cfm, mp->mpid);
-
-        if (mp->n_fault != 1 || mp->fault[0] != rmp->fault) {
-            ovsrec_maintenance_point_set_fault(mp, &rmp->fault, 1);
-            changed = true;
-        }
-    }
-
-    if (mon->n_fault != 1 || mon->fault[0] != cfm->fault) {
-        ovsrec_monitor_set_fault(mon, &cfm->fault, 1);
+    if (cfg->n_cfm_fault != 1 || cfg->cfm_fault[0] != fault) {
+        bool fault_bool = fault;
+        ovsrec_interface_set_cfm_fault(cfg, &fault_bool, 1);
         changed = true;
     }
 
@@ -1501,33 +1483,6 @@ bridge_wait(void)
     }
 }
 \f
-/* CFM unixctl user interface functions. */
-static void
-cfm_unixctl_show(struct unixctl_conn *conn,
-                 const char *args, void *aux OVS_UNUSED)
-{
-    struct ds ds = DS_EMPTY_INITIALIZER;
-    struct iface *iface;
-    const struct cfm *cfm;
-
-    iface = iface_find(args);
-    if (!iface) {
-        unixctl_command_reply(conn, 501, "no such interface");
-        return;
-    }
-
-    cfm = ofproto_port_get_cfm(iface->port->bridge->ofproto, iface->ofp_port);
-
-    if (!cfm) {
-        unixctl_command_reply(conn, 501, "CFM not enabled");
-        return;
-    }
-
-    cfm_dump_ds(cfm, &ds);
-    unixctl_command_reply(conn, 200, ds_cstr(&ds));
-    ds_destroy(&ds);
-}
-\f
 /* QoS unixctl user interface functions. */
 
 struct qos_unixctl_show_cbdata {
@@ -2529,37 +2484,28 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos)
 static void
 iface_configure_cfm(struct iface *iface)
 {
-    size_t i;
-    struct cfm cfm;
-    uint16_t *remote_mps;
-    struct ovsrec_monitor *mon;
-    uint8_t maid[CCM_MAID_LEN];
-
-    mon = iface->cfg->monitor;
+    const struct ovsrec_interface *cfg = iface->cfg;
+    struct cfm_settings s;
+    uint16_t remote_mpid;
 
-    if (!mon) {
+    if (!cfg->n_cfm_mpid || !cfg->n_cfm_remote_mpid) {
         ofproto_port_clear_cfm(iface->port->bridge->ofproto, iface->ofp_port);
         return;
     }
 
-    if (!cfm_generate_maid(mon->md_name, mon->ma_name, maid)) {
-        VLOG_WARN("interface %s: Failed to generate MAID.", iface->name);
-        return;
-    }
-
-    cfm.mpid     = mon->mpid;
-    cfm.interval = mon->interval ? *mon->interval : 1000;
-
-    memcpy(cfm.maid, maid, sizeof cfm.maid);
+    s.name = iface->name;
+    s.mpid = *cfg->cfm_mpid;
+    remote_mpid = *cfg->cfm_remote_mpid;
+    s.remote_mpids = &remote_mpid;
+    s.n_remote_mpids = 1;
 
-    remote_mps = xzalloc(mon->n_remote_mps * sizeof *remote_mps);
-    for(i = 0; i < mon->n_remote_mps; i++) {
-        remote_mps[i] = mon->remote_mps[i]->mpid;
+    s.interval = atoi(get_interface_other_config(iface->cfg, "cfm_interval",
+                                                 "0"));
+    if (s.interval <= 0) {
+        s.interval = 1000;
     }
 
-    ofproto_port_set_cfm(iface->port->bridge->ofproto, iface->ofp_port,
-                         &cfm, remote_mps, mon->n_remote_mps);
-    free(remote_mps);
+    ofproto_port_set_cfm(iface->port->bridge->ofproto, iface->ofp_port, &s);
 }
 
 /* Read carrier or miimon status directly from 'iface''s netdev, according to