ofproto: Break apart into generic and hardware-specific parts.
[sliver-openvswitch.git] / ofproto / connmgr.c
index 83b3159..d04641b 100644 (file)
@@ -31,6 +31,7 @@
 #include "pinsched.h"
 #include "poll-loop.h"
 #include "pktbuf.h"
+#include "private.h"
 #include "rconn.h"
 #include "shash.h"
 #include "timeval.h"
@@ -390,6 +391,7 @@ connmgr_set_controllers(struct connmgr *mgr,
                         const struct ofproto_controller *controllers,
                         size_t n_controllers)
 {
+    bool had_controllers = connmgr_has_controllers(mgr);
     struct shash new_controllers;
     struct ofconn *ofconn, *next_ofconn;
     struct ofservice *ofservice, *next_ofservice;
@@ -451,6 +453,9 @@ connmgr_set_controllers(struct connmgr *mgr,
 
     update_in_band_remotes(mgr);
     update_fail_open(mgr);
+    if (had_controllers != connmgr_has_controllers(mgr)) {
+        ofproto_flush_flows(mgr->ofproto);
+    }
 }
 
 /* Drops the connections between 'mgr' and all of its primary and secondary
@@ -925,9 +930,7 @@ static void schedule_packet_in(struct ofconn *, const struct dpif_upcall *,
                                const struct flow *, struct ofpbuf *rw_packet);
 
 /* Sends an OFPT_PORT_STATUS message with 'opp' and 'reason' to appropriate
- * controllers managed by 'mgr'.
- *
- * 'opp' is in *HOST* byte order. */
+ * controllers managed by 'mgr'. */
 void
 connmgr_send_port_status(struct connmgr *mgr, const struct ofp_phy_port *opp,
                          uint8_t reason)
@@ -949,7 +952,6 @@ connmgr_send_port_status(struct connmgr *mgr, const struct ofp_phy_port *opp,
         ops = make_openflow_xid(sizeof *ops, OFPT_PORT_STATUS, 0, &b);
         ops->reason = reason;
         ops->desc = *opp;
-        hton_ofp_phy_port(&ops->desc);
         ofconn_send(ofconn, b, NULL);
     }
 }
@@ -1034,7 +1036,7 @@ schedule_packet_in(struct ofconn *ofconn, const struct dpif_upcall *upcall,
 
     /* Figure out the easy parts. */
     pin.packet = upcall->packet;
-    pin.in_port = odp_port_to_ofp_port(flow->in_port);
+    pin.in_port = flow->in_port;
     pin.reason = upcall->type == DPIF_UC_MISS ? OFPR_NO_MATCH : OFPR_ACTION;
 
     /* Get OpenFlow buffer_id. */
@@ -1081,8 +1083,13 @@ connmgr_get_fail_mode(const struct connmgr *mgr)
 void
 connmgr_set_fail_mode(struct connmgr *mgr, enum ofproto_fail_mode fail_mode)
 {
-    mgr->fail_mode = fail_mode;
-    update_fail_open(mgr);
+    if (mgr->fail_mode != fail_mode) {
+        mgr->fail_mode = fail_mode;
+        update_fail_open(mgr);
+        if (!connmgr_has_controllers(mgr)) {
+            ofproto_flush_flows(mgr->ofproto);
+        }
+    }
 }
 \f
 /* Fail-open implementation. */
@@ -1265,6 +1272,23 @@ connmgr_flushed(struct connmgr *mgr)
     if (mgr->fail_open) {
         fail_open_flushed(mgr->fail_open);
     }
+
+    /* If there are no controllers and we're in standalone mode, set up a flow
+     * that matches every packet and directs them to OFPP_NORMAL (which goes to
+     * us).  Otherwise, the switch is in secure mode and we won't pass any
+     * traffic until a controller has been defined and it tells us to do so. */
+    if (!connmgr_has_controllers(mgr)
+        && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
+        union ofp_action action;
+        struct cls_rule rule;
+
+        memset(&action, 0, sizeof action);
+        action.type = htons(OFPAT_OUTPUT);
+        action.output.len = htons(sizeof action);
+        action.output.port = htons(OFPP_NORMAL);
+        cls_rule_init_catchall(&rule, 0);
+        ofproto_add_flow(mgr->ofproto, &rule, &action, 1);
+    }
 }
 \f
 /* Creates a new ofservice for 'target' in 'mgr'.  Returns 0 if successful,