X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fconnmgr.c;h=3851a8e42c9f60a650ab762c1226d80784db9379;hb=0311d4f48ddfeb5f7d25b45d53168c02603bcf62;hp=391995e7a1a4ee0ca1f1b5b55bfe50dab70dbcd7;hpb=5cb7a798405c6ccc07bf9a932b709643c072b086;p=openvswitch diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 391995e7..3851a8e4 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -137,7 +137,8 @@ struct ofservice { static void ofservice_reconfigure(struct ofservice *, const struct ofproto_controller *); -static int ofservice_create(struct connmgr *, const char *target, uint8_t dscp); +static int ofservice_create(struct connmgr *mgr, const char *target, + uint32_t allowed_versions, uint8_t dscp); static void ofservice_destroy(struct connmgr *, struct ofservice *); static struct ofservice *ofservice_lookup(struct connmgr *, const char *target); @@ -289,13 +290,14 @@ connmgr_run(struct connmgr *mgr, struct vconn *vconn; int retval; - retval = pvconn_accept(ofservice->pvconn, OFP10_VERSION, &vconn); + retval = pvconn_accept(ofservice->pvconn, &vconn); if (!retval) { struct rconn *rconn; char *name; /* Passing default value for creation of the rconn */ - rconn = rconn_create(ofservice->probe_interval, 0, ofservice->dscp); + rconn = rconn_create(ofservice->probe_interval, 0, ofservice->dscp, + vconn_get_allowed_versions(vconn)); name = ofconn_make_name(mgr, vconn_get_name(vconn)); rconn_connect_unreliably(rconn, vconn, name); free(name); @@ -313,7 +315,7 @@ connmgr_run(struct connmgr *mgr, struct vconn *vconn; int retval; - retval = pvconn_accept(mgr->snoops[i], OFP10_VERSION, &vconn); + retval = pvconn_accept(mgr->snoops[i], &vconn); if (!retval) { add_snooper(mgr, vconn); } else if (retval != EAGAIN) { @@ -398,7 +400,8 @@ connmgr_retry(struct connmgr *mgr) /* OpenFlow configuration. */ -static void add_controller(struct connmgr *, const char *target, uint8_t dscp); +static void add_controller(struct connmgr *, const char *target, uint8_t dscp, + uint32_t allowed_versions); static struct ofconn *find_controller_by_target(struct connmgr *, const char *target); static void update_fail_open(struct connmgr *); @@ -489,7 +492,7 @@ connmgr_free_controller_info(struct shash *info) void connmgr_set_controllers(struct connmgr *mgr, const struct ofproto_controller *controllers, - size_t n_controllers) + size_t n_controllers, uint32_t allowed_versions) { bool had_controllers = connmgr_has_controllers(mgr); struct shash new_controllers; @@ -507,13 +510,13 @@ connmgr_set_controllers(struct connmgr *mgr, if (!find_controller_by_target(mgr, c->target)) { VLOG_INFO("%s: added primary controller \"%s\"", mgr->name, c->target); - add_controller(mgr, c->target, c->dscp); + add_controller(mgr, c->target, c->dscp, allowed_versions); } } else if (!pvconn_verify_name(c->target)) { if (!ofservice_lookup(mgr, c->target)) { VLOG_INFO("%s: added service controller \"%s\"", mgr->name, c->target); - ofservice_create(mgr, c->target, c->dscp); + ofservice_create(mgr, c->target, allowed_versions, c->dscp); } } else { VLOG_WARN_RL(&rl, "%s: unsupported controller \"%s\"", @@ -608,12 +611,14 @@ connmgr_has_snoops(const struct connmgr *mgr) /* Creates a new controller for 'target' in 'mgr'. update_controller() needs * to be called later to finish the new ofconn's configuration. */ static void -add_controller(struct connmgr *mgr, const char *target, uint8_t dscp) +add_controller(struct connmgr *mgr, const char *target, uint8_t dscp, + uint32_t allowed_versions) { char *name = ofconn_make_name(mgr, target); struct ofconn *ofconn; - ofconn = ofconn_create(mgr, rconn_create(5, 8, dscp), OFCONN_PRIMARY, true); + ofconn = ofconn_create(mgr, rconn_create(5, 8, dscp, allowed_versions), + OFCONN_PRIMARY, true); ofconn->pktbuf = pktbuf_create(); rconn_connect(ofconn->rconn, target, name); hmap_insert(&mgr->controllers, &ofconn->hmap_node, hash_string(target, 0)); @@ -720,8 +725,7 @@ set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp, SSET_FOR_EACH (name, sset) { struct pvconn *pvconn; int error; - - error = pvconn_open(name, &pvconn, 0); + error = pvconn_open(name, 0, &pvconn, 0); if (!error) { pvconns[n_pvconns++] = pvconn; } else { @@ -836,10 +840,24 @@ ofconn_get_invalid_ttl_to_controller(struct ofconn *ofconn) /* Returns the currently configured protocol for 'ofconn', one of OFPUTIL_P_*. * - * The default, if no other format has been set, is OFPUTIL_P_OPENFLOW10. */ + * Returns OFPUTIL_P_NONE, which is not a valid protocol, if 'ofconn' hasn't + * completed version negotiation. This can't happen if at least one OpenFlow + * message, other than OFPT_HELLO, has been received on the connection (such as + * in ofproto.c's message handling code), since version negotiation is a + * prerequisite for starting to receive messages. This means that + * OFPUTIL_P_NONE is a special case that most callers need not worry about. */ enum ofputil_protocol -ofconn_get_protocol(struct ofconn *ofconn) -{ +ofconn_get_protocol(const struct ofconn *ofconn) +{ + if (ofconn->protocol == OFPUTIL_P_NONE && + rconn_is_connected(ofconn->rconn)) { + int version = rconn_get_version(ofconn->rconn); + if (version > 0) { + ofconn_set_protocol(CONST_CAST(struct ofconn *, ofconn), + ofputil_protocol_from_ofp_version(version)); + } + } + return ofconn->protocol; } @@ -1030,7 +1048,7 @@ ofconn_flush(struct ofconn *ofconn) int i; ofconn->role = NX_ROLE_OTHER; - ofconn->protocol = OFPUTIL_P_OF10; + ofconn_set_protocol(ofconn, OFPUTIL_P_NONE); ofconn->packet_in_format = NXPIF_OPENFLOW10; /* Disassociate 'ofconn' from all of the ofopgroups that it initiated that @@ -1230,7 +1248,8 @@ ofconn_receives_async_msg(const struct ofconn *ofconn, assert(reason < 32); assert((unsigned int) type < OAM_N_TYPES); - if (!rconn_is_connected(ofconn->rconn)) { + if (ofconn_get_protocol(ofconn) == OFPUTIL_P_NONE + || !rconn_is_connected(ofconn->rconn)) { return false; } @@ -1313,7 +1332,7 @@ connmgr_send_port_status(struct connmgr *mgr, if (ofconn_receives_async_msg(ofconn, OAM_PORT_STATUS, reason)) { struct ofpbuf *msg; - msg = ofputil_encode_port_status(&ps, ofconn->protocol); + msg = ofputil_encode_port_status(&ps, ofconn_get_protocol(ofconn)); ofconn_send(ofconn, msg, NULL); } } @@ -1336,7 +1355,7 @@ connmgr_send_flow_removed(struct connmgr *mgr, * also prevents new flows from being added (and expiring). (It * also prevents processing OpenFlow requests that would not add * new flows, so it is imperfect.) */ - msg = ofputil_encode_flow_removed(fr, ofconn->protocol); + msg = ofputil_encode_flow_removed(fr, ofconn_get_protocol(ofconn)); ofconn_send_reply(ofconn, msg); } } @@ -1407,7 +1426,7 @@ schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin) * while (until a later call to pinsched_run()). */ pinsched_send(ofconn->schedulers[pin.reason == OFPR_NO_MATCH ? 0 : 1], pin.fmd.in_port, - ofputil_encode_packet_in(&pin, ofconn->protocol, + ofputil_encode_packet_in(&pin, ofconn_get_protocol(ofconn), ofconn->packet_in_format), do_send_packet_in, ofconn); } @@ -1619,13 +1638,14 @@ connmgr_flushed(struct connmgr *mgr) * ofservice_reconfigure() must be called to fully configure the new * ofservice. */ static int -ofservice_create(struct connmgr *mgr, const char *target, uint8_t dscp) +ofservice_create(struct connmgr *mgr, const char *target, + uint32_t allowed_versions, uint8_t dscp) { struct ofservice *ofservice; struct pvconn *pvconn; int error; - error = pvconn_open(target, &pvconn, dscp); + error = pvconn_open(target, allowed_versions, &pvconn, dscp); if (error) { return error; } @@ -1815,6 +1835,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule, fu.cookie = rule->flow_cookie; minimatch_expand(&rule->cr.match, &match); fu.match = &match; + fu.priority = rule->cr.priority; if (flags & NXFMF_ACTIONS) { fu.ofpacts = rule->ofpacts; fu.ofpacts_len = rule->ofpacts_len;