2 * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include "fail-open.h"
30 #include "ofproto-provider.h"
32 #include "poll-loop.h"
41 VLOG_DEFINE_THIS_MODULE(connmgr);
42 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
44 /* An OpenFlow connection. */
46 /* Configuration that persists from one connection to the next. */
48 struct list node; /* In struct connmgr's "all_conns" list. */
49 struct hmap_node hmap_node; /* In struct connmgr's "controllers" map. */
51 struct connmgr *connmgr; /* Connection's manager. */
52 struct rconn *rconn; /* OpenFlow connection. */
53 enum ofconn_type type; /* Type. */
54 enum ofproto_band band; /* In-band or out-of-band? */
56 /* State that should be cleared from one connection to the next. */
59 enum nx_role role; /* Role. */
60 enum nx_flow_format flow_format; /* Currently selected flow format. */
61 enum nx_packet_in_format packet_in_format; /* OFPT_PACKET_IN format. */
62 bool flow_mod_table_id; /* NXT_FLOW_MOD_TABLE_ID enabled? */
64 /* Asynchronous flow table operation support. */
65 struct list opgroups; /* Contains pending "ofopgroups", if any. */
66 struct ofpbuf *blocked; /* Postponed OpenFlow message, if any. */
67 bool retry; /* True if 'blocked' is ready to try again. */
69 /* OFPT_PACKET_IN related data. */
70 struct rconn_packet_counter *packet_in_counter; /* # queued on 'rconn'. */
71 #define N_SCHEDULERS 2
72 struct pinsched *schedulers[N_SCHEDULERS];
73 struct pktbuf *pktbuf; /* OpenFlow packet buffers. */
74 int miss_send_len; /* Bytes to send of buffered packets. */
76 /* Number of OpenFlow messages queued on 'rconn' as replies to OpenFlow
77 * requests, and the maximum number before we stop reading OpenFlow
79 #define OFCONN_REPLY_MAX 100
80 struct rconn_packet_counter *reply_counter;
82 /* Asynchronous message configuration in each possible roles.
84 * A 1-bit enables sending an asynchronous message for one possible reason
85 * that the message might be generated, a 0-bit disables it. */
86 uint32_t master_async_config[OAM_N_TYPES]; /* master, other */
87 uint32_t slave_async_config[OAM_N_TYPES]; /* slave */
90 static struct ofconn *ofconn_create(struct connmgr *, struct rconn *,
92 static void ofconn_destroy(struct ofconn *);
93 static void ofconn_flush(struct ofconn *);
95 static void ofconn_reconfigure(struct ofconn *,
96 const struct ofproto_controller *);
98 static void ofconn_run(struct ofconn *,
99 bool (*handle_openflow)(struct ofconn *,
100 struct ofpbuf *ofp_msg));
101 static void ofconn_wait(struct ofconn *, bool handling_openflow);
103 static const char *ofconn_get_target(const struct ofconn *);
104 static char *ofconn_make_name(const struct connmgr *, const char *target);
106 static void ofconn_set_rate_limit(struct ofconn *, int rate, int burst);
108 static void ofconn_send(const struct ofconn *, struct ofpbuf *,
109 struct rconn_packet_counter *);
111 static void do_send_packet_in(struct ofpbuf *, void *ofconn_);
113 /* A listener for incoming OpenFlow "service" connections. */
115 struct hmap_node node; /* In struct connmgr's "services" hmap. */
116 struct pvconn *pvconn; /* OpenFlow connection listener. */
118 /* These are not used by ofservice directly. They are settings for
119 * accepted "struct ofconn"s from the pvconn. */
120 int probe_interval; /* Max idle time before probing, in seconds. */
121 int rate_limit; /* Max packet-in rate in packets per second. */
122 int burst_limit; /* Limit on accumulating packet credits. */
125 static void ofservice_reconfigure(struct ofservice *,
126 const struct ofproto_controller *);
127 static int ofservice_create(struct connmgr *, const char *target);
128 static void ofservice_destroy(struct connmgr *, struct ofservice *);
129 static struct ofservice *ofservice_lookup(struct connmgr *,
132 /* Connection manager for an OpenFlow switch. */
134 struct ofproto *ofproto;
136 char *local_port_name;
138 /* OpenFlow connections. */
139 struct hmap controllers; /* Controller "struct ofconn"s. */
140 struct list all_conns; /* Contains "struct ofconn"s. */
142 /* OpenFlow listeners. */
143 struct hmap services; /* Contains "struct ofservice"s. */
144 struct pvconn **snoops;
148 struct fail_open *fail_open;
149 enum ofproto_fail_mode fail_mode;
151 /* In-band control. */
152 struct in_band *in_band;
153 struct sockaddr_in *extra_in_band_remotes;
154 size_t n_extra_remotes;
158 static void update_in_band_remotes(struct connmgr *);
159 static void add_snooper(struct connmgr *, struct vconn *);
161 /* Creates and returns a new connection manager owned by 'ofproto'. 'name' is
162 * a name for the ofproto suitable for using in log messages.
163 * 'local_port_name' is the name of the local port (OFPP_LOCAL) within
166 connmgr_create(struct ofproto *ofproto,
167 const char *name, const char *local_port_name)
171 mgr = xmalloc(sizeof *mgr);
172 mgr->ofproto = ofproto;
173 mgr->name = xstrdup(name);
174 mgr->local_port_name = xstrdup(local_port_name);
176 hmap_init(&mgr->controllers);
177 list_init(&mgr->all_conns);
179 hmap_init(&mgr->services);
183 mgr->fail_open = NULL;
184 mgr->fail_mode = OFPROTO_FAIL_SECURE;
187 mgr->extra_in_band_remotes = NULL;
188 mgr->n_extra_remotes = 0;
189 mgr->in_band_queue = -1;
194 /* Frees 'mgr' and all of its resources. */
196 connmgr_destroy(struct connmgr *mgr)
198 struct ofservice *ofservice, *next_ofservice;
199 struct ofconn *ofconn, *next_ofconn;
206 LIST_FOR_EACH_SAFE (ofconn, next_ofconn, node, &mgr->all_conns) {
207 ofconn_destroy(ofconn);
209 hmap_destroy(&mgr->controllers);
211 HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, node, &mgr->services) {
212 ofservice_destroy(mgr, ofservice);
214 hmap_destroy(&mgr->services);
216 for (i = 0; i < mgr->n_snoops; i++) {
217 pvconn_close(mgr->snoops[i]);
221 fail_open_destroy(mgr->fail_open);
222 mgr->fail_open = NULL;
224 in_band_destroy(mgr->in_band);
226 free(mgr->extra_in_band_remotes);
228 free(mgr->local_port_name);
233 /* Does all of the periodic maintenance required by 'mgr'.
235 * If 'handle_openflow' is nonnull, calls 'handle_openflow' for each message
236 * received on an OpenFlow connection, passing along the OpenFlow connection
237 * itself and the message that was sent. If 'handle_openflow' returns true,
238 * the message is considered to be fully processed. If 'handle_openflow'
239 * returns false, the message is considered not to have been processed at all;
240 * it will be stored and re-presented to 'handle_openflow' following the next
241 * call to connmgr_retry(). 'handle_openflow' must not modify or free the
244 * If 'handle_openflow' is NULL, no OpenFlow messages will be processed and
245 * other activities that could affect the flow table (in-band processing,
246 * fail-open processing) are suppressed too. */
248 connmgr_run(struct connmgr *mgr,
249 bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
251 struct ofconn *ofconn, *next_ofconn;
252 struct ofservice *ofservice;
255 if (handle_openflow && mgr->in_band) {
256 if (!in_band_run(mgr->in_band)) {
257 in_band_destroy(mgr->in_band);
262 LIST_FOR_EACH_SAFE (ofconn, next_ofconn, node, &mgr->all_conns) {
263 ofconn_run(ofconn, handle_openflow);
266 /* Fail-open maintenance. Do this after processing the ofconns since
267 * fail-open checks the status of the controller rconn. */
268 if (handle_openflow && mgr->fail_open) {
269 fail_open_run(mgr->fail_open);
272 HMAP_FOR_EACH (ofservice, node, &mgr->services) {
276 retval = pvconn_accept(ofservice->pvconn, OFP_VERSION, &vconn);
281 rconn = rconn_create(ofservice->probe_interval, 0);
282 name = ofconn_make_name(mgr, vconn_get_name(vconn));
283 rconn_connect_unreliably(rconn, vconn, name);
286 ofconn = ofconn_create(mgr, rconn, OFCONN_SERVICE);
287 ofconn_set_rate_limit(ofconn, ofservice->rate_limit,
288 ofservice->burst_limit);
289 } else if (retval != EAGAIN) {
290 VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
294 for (i = 0; i < mgr->n_snoops; i++) {
298 retval = pvconn_accept(mgr->snoops[i], OFP_VERSION, &vconn);
300 add_snooper(mgr, vconn);
301 } else if (retval != EAGAIN) {
302 VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
307 /* Causes the poll loop to wake up when connmgr_run() needs to run.
309 * If 'handling_openflow' is true, arriving OpenFlow messages and other
310 * activities that affect the flow table will wake up the poll loop. If
311 * 'handling_openflow' is false, they will not. */
313 connmgr_wait(struct connmgr *mgr, bool handling_openflow)
315 struct ofservice *ofservice;
316 struct ofconn *ofconn;
319 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
320 ofconn_wait(ofconn, handling_openflow);
322 if (handling_openflow && mgr->in_band) {
323 in_band_wait(mgr->in_band);
325 if (handling_openflow && mgr->fail_open) {
326 fail_open_wait(mgr->fail_open);
328 HMAP_FOR_EACH (ofservice, node, &mgr->services) {
329 pvconn_wait(ofservice->pvconn);
331 for (i = 0; i < mgr->n_snoops; i++) {
332 pvconn_wait(mgr->snoops[i]);
336 /* Returns the ofproto that owns 'ofconn''s connmgr. */
338 ofconn_get_ofproto(const struct ofconn *ofconn)
340 return ofconn->connmgr->ofproto;
343 /* If processing of OpenFlow messages was blocked on any 'mgr' ofconns by
344 * returning false to the 'handle_openflow' callback to connmgr_run(), this
345 * re-enables them. */
347 connmgr_retry(struct connmgr *mgr)
349 struct ofconn *ofconn;
351 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
352 ofconn->retry = true;
356 /* OpenFlow configuration. */
358 static void add_controller(struct connmgr *, const char *target);
359 static struct ofconn *find_controller_by_target(struct connmgr *,
361 static void update_fail_open(struct connmgr *);
362 static int set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
363 const struct sset *);
365 /* Returns true if 'mgr' has any configured primary controllers.
367 * Service controllers do not count, but configured primary controllers do
368 * count whether or not they are currently connected. */
370 connmgr_has_controllers(const struct connmgr *mgr)
372 return !hmap_is_empty(&mgr->controllers);
375 /* Initializes 'info' and populates it with information about each configured
376 * primary controller. The keys in 'info' are the controllers' targets; the
377 * data values are corresponding "struct ofproto_controller_info".
379 * The caller owns 'info' and everything in it and should free it when it is no
382 connmgr_get_controller_info(struct connmgr *mgr, struct shash *info)
384 const struct ofconn *ofconn;
386 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
387 const struct rconn *rconn = ofconn->rconn;
388 const char *target = rconn_get_target(rconn);
390 if (!shash_find(info, target)) {
391 struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo);
392 time_t now = time_now();
393 time_t last_connection = rconn_get_last_connection(rconn);
394 time_t last_disconnect = rconn_get_last_disconnect(rconn);
395 int last_error = rconn_get_last_error(rconn);
397 shash_add(info, target, cinfo);
399 cinfo->is_connected = rconn_is_connected(rconn);
400 cinfo->role = ofconn->role;
405 cinfo->pairs.keys[cinfo->pairs.n] = "last_error";
406 cinfo->pairs.values[cinfo->pairs.n++]
407 = xstrdup(ovs_retval_to_string(last_error));
410 cinfo->pairs.keys[cinfo->pairs.n] = "state";
411 cinfo->pairs.values[cinfo->pairs.n++]
412 = xstrdup(rconn_get_state(rconn));
414 if (last_connection != TIME_MIN) {
415 cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_connect";
416 cinfo->pairs.values[cinfo->pairs.n++]
417 = xasprintf("%ld", (long int) (now - last_connection));
420 if (last_disconnect != TIME_MIN) {
421 cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_disconnect";
422 cinfo->pairs.values[cinfo->pairs.n++]
423 = xasprintf("%ld", (long int) (now - last_disconnect));
430 connmgr_free_controller_info(struct shash *info)
432 struct shash_node *node;
434 SHASH_FOR_EACH (node, info) {
435 struct ofproto_controller_info *cinfo = node->data;
436 while (cinfo->pairs.n) {
437 free((char *) cinfo->pairs.values[--cinfo->pairs.n]);
444 /* Changes 'mgr''s set of controllers to the 'n_controllers' controllers in
447 connmgr_set_controllers(struct connmgr *mgr,
448 const struct ofproto_controller *controllers,
449 size_t n_controllers)
451 bool had_controllers = connmgr_has_controllers(mgr);
452 struct shash new_controllers;
453 struct ofconn *ofconn, *next_ofconn;
454 struct ofservice *ofservice, *next_ofservice;
457 /* Create newly configured controllers and services.
458 * Create a name to ofproto_controller mapping in 'new_controllers'. */
459 shash_init(&new_controllers);
460 for (i = 0; i < n_controllers; i++) {
461 const struct ofproto_controller *c = &controllers[i];
463 if (!vconn_verify_name(c->target)) {
464 if (!find_controller_by_target(mgr, c->target)) {
465 add_controller(mgr, c->target);
467 } else if (!pvconn_verify_name(c->target)) {
468 if (!ofservice_lookup(mgr, c->target)) {
469 ofservice_create(mgr, c->target);
472 VLOG_WARN_RL(&rl, "%s: unsupported controller \"%s\"",
473 mgr->name, c->target);
477 shash_add_once(&new_controllers, c->target, &controllers[i]);
480 /* Delete controllers that are no longer configured.
481 * Update configuration of all now-existing controllers. */
482 HMAP_FOR_EACH_SAFE (ofconn, next_ofconn, hmap_node, &mgr->controllers) {
483 struct ofproto_controller *c;
485 c = shash_find_data(&new_controllers, ofconn_get_target(ofconn));
487 ofconn_destroy(ofconn);
489 ofconn_reconfigure(ofconn, c);
493 /* Delete services that are no longer configured.
494 * Update configuration of all now-existing services. */
495 HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, node, &mgr->services) {
496 struct ofproto_controller *c;
498 c = shash_find_data(&new_controllers,
499 pvconn_get_name(ofservice->pvconn));
501 ofservice_destroy(mgr, ofservice);
503 ofservice_reconfigure(ofservice, c);
507 shash_destroy(&new_controllers);
509 update_in_band_remotes(mgr);
510 update_fail_open(mgr);
511 if (had_controllers != connmgr_has_controllers(mgr)) {
512 ofproto_flush_flows(mgr->ofproto);
516 /* Drops the connections between 'mgr' and all of its primary and secondary
517 * controllers, forcing them to reconnect. */
519 connmgr_reconnect(const struct connmgr *mgr)
521 struct ofconn *ofconn;
523 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
524 rconn_reconnect(ofconn->rconn);
528 /* Sets the "snoops" for 'mgr' to the pvconn targets listed in 'snoops'.
530 * A "snoop" is a pvconn to which every OpenFlow message to or from the most
531 * important controller on 'mgr' is mirrored. */
533 connmgr_set_snoops(struct connmgr *mgr, const struct sset *snoops)
535 return set_pvconns(&mgr->snoops, &mgr->n_snoops, snoops);
538 /* Adds each of the snoops currently configured on 'mgr' to 'snoops'. */
540 connmgr_get_snoops(const struct connmgr *mgr, struct sset *snoops)
544 for (i = 0; i < mgr->n_snoops; i++) {
545 sset_add(snoops, pvconn_get_name(mgr->snoops[i]));
549 /* Returns true if 'mgr' has at least one snoop, false if it has none. */
551 connmgr_has_snoops(const struct connmgr *mgr)
553 return mgr->n_snoops > 0;
556 /* Creates a new controller for 'target' in 'mgr'. update_controller() needs
557 * to be called later to finish the new ofconn's configuration. */
559 add_controller(struct connmgr *mgr, const char *target)
561 char *name = ofconn_make_name(mgr, target);
562 struct ofconn *ofconn;
564 ofconn = ofconn_create(mgr, rconn_create(5, 8), OFCONN_PRIMARY);
565 ofconn->pktbuf = pktbuf_create();
566 rconn_connect(ofconn->rconn, target, name);
567 hmap_insert(&mgr->controllers, &ofconn->hmap_node, hash_string(target, 0));
572 static struct ofconn *
573 find_controller_by_target(struct connmgr *mgr, const char *target)
575 struct ofconn *ofconn;
577 HMAP_FOR_EACH_WITH_HASH (ofconn, hmap_node,
578 hash_string(target, 0), &mgr->controllers) {
579 if (!strcmp(ofconn_get_target(ofconn), target)) {
587 update_in_band_remotes(struct connmgr *mgr)
589 struct sockaddr_in *addrs;
590 size_t max_addrs, n_addrs;
591 struct ofconn *ofconn;
594 /* Allocate enough memory for as many remotes as we could possibly have. */
595 max_addrs = mgr->n_extra_remotes + hmap_count(&mgr->controllers);
596 addrs = xmalloc(max_addrs * sizeof *addrs);
599 /* Add all the remotes. */
600 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
601 struct sockaddr_in *sin = &addrs[n_addrs];
602 const char *target = rconn_get_target(ofconn->rconn);
604 if (ofconn->band == OFPROTO_OUT_OF_BAND) {
608 if (stream_parse_target_with_default_ports(target,
615 for (i = 0; i < mgr->n_extra_remotes; i++) {
616 addrs[n_addrs++] = mgr->extra_in_band_remotes[i];
619 /* Create or update or destroy in-band. */
622 in_band_create(mgr->ofproto, mgr->local_port_name, &mgr->in_band);
624 in_band_set_queue(mgr->in_band, mgr->in_band_queue);
626 /* in_band_run() needs a chance to delete any existing in-band flows.
627 * We will destroy mgr->in_band after it's done with that. */
630 in_band_set_remotes(mgr->in_band, addrs, n_addrs);
638 update_fail_open(struct connmgr *mgr)
640 if (connmgr_has_controllers(mgr)
641 && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
642 if (!mgr->fail_open) {
643 mgr->fail_open = fail_open_create(mgr->ofproto, mgr);
646 fail_open_destroy(mgr->fail_open);
647 mgr->fail_open = NULL;
652 set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
653 const struct sset *sset)
655 struct pvconn **pvconns = *pvconnsp;
656 size_t n_pvconns = *n_pvconnsp;
661 for (i = 0; i < n_pvconns; i++) {
662 pvconn_close(pvconns[i]);
666 pvconns = xmalloc(sset_count(sset) * sizeof *pvconns);
668 SSET_FOR_EACH (name, sset) {
669 struct pvconn *pvconn;
672 error = pvconn_open(name, &pvconn);
674 pvconns[n_pvconns++] = pvconn;
676 VLOG_ERR("failed to listen on %s: %s", name, strerror(error));
684 *n_pvconnsp = n_pvconns;
689 /* Returns a "preference level" for snooping 'ofconn'. A higher return value
690 * means that 'ofconn' is more interesting for monitoring than a lower return
693 snoop_preference(const struct ofconn *ofconn)
695 switch (ofconn->role) {
703 /* Shouldn't happen. */
708 /* One of 'mgr''s "snoop" pvconns has accepted a new connection on 'vconn'.
709 * Connects this vconn to a controller. */
711 add_snooper(struct connmgr *mgr, struct vconn *vconn)
713 struct ofconn *ofconn, *best;
715 /* Pick a controller for monitoring. */
717 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
718 if (ofconn->type == OFCONN_PRIMARY
719 && (!best || snoop_preference(ofconn) > snoop_preference(best))) {
725 rconn_add_monitor(best->rconn, vconn);
727 VLOG_INFO_RL(&rl, "no controller connection to snoop");
732 /* Public ofconn functions. */
734 /* Returns the connection type, either OFCONN_PRIMARY or OFCONN_SERVICE. */
736 ofconn_get_type(const struct ofconn *ofconn)
741 /* Returns the role configured for 'ofconn'.
743 * The default role, if no other role has been set, is NX_ROLE_OTHER. */
745 ofconn_get_role(const struct ofconn *ofconn)
750 /* Changes 'ofconn''s role to 'role'. If 'role' is NX_ROLE_MASTER then any
751 * existing master is demoted to a slave. */
753 ofconn_set_role(struct ofconn *ofconn, enum nx_role role)
755 if (role == NX_ROLE_MASTER) {
756 struct ofconn *other;
758 HMAP_FOR_EACH (other, hmap_node, &ofconn->connmgr->controllers) {
759 if (other->role == NX_ROLE_MASTER) {
760 other->role = NX_ROLE_SLAVE;
768 ofconn_set_invalid_ttl_to_controller(struct ofconn *ofconn, bool enable)
770 uint32_t bit = 1u << OFPR_INVALID_TTL;
772 ofconn->master_async_config[OAM_PACKET_IN] |= bit;
774 ofconn->master_async_config[OAM_PACKET_IN] &= ~bit;
779 ofconn_get_invalid_ttl_to_controller(struct ofconn *ofconn)
781 uint32_t bit = 1u << OFPR_INVALID_TTL;
782 return (ofconn->master_async_config[OAM_PACKET_IN] & bit) != 0;
785 /* Returns the currently configured flow format for 'ofconn', one of NXFF_*.
787 * The default, if no other format has been set, is NXFF_OPENFLOW10. */
789 ofconn_get_flow_format(struct ofconn *ofconn)
791 return ofconn->flow_format;
794 /* Sets the flow format for 'ofconn' to 'flow_format' (one of NXFF_*). */
796 ofconn_set_flow_format(struct ofconn *ofconn, enum nx_flow_format flow_format)
798 ofconn->flow_format = flow_format;
801 /* Returns the currently configured packet in format for 'ofconn', one of
804 * The default, if no other format has been set, is NXPIF_OPENFLOW10. */
805 enum nx_packet_in_format
806 ofconn_get_packet_in_format(struct ofconn *ofconn)
808 return ofconn->packet_in_format;
811 /* Sets the packet in format for 'ofconn' to 'packet_in_format' (one of
814 ofconn_set_packet_in_format(struct ofconn *ofconn,
815 enum nx_packet_in_format packet_in_format)
817 ofconn->packet_in_format = packet_in_format;
820 /* Returns true if the NXT_FLOW_MOD_TABLE_ID extension is enabled, false
823 * By default the extension is not enabled. */
825 ofconn_get_flow_mod_table_id(const struct ofconn *ofconn)
827 return ofconn->flow_mod_table_id;
830 /* Enables or disables (according to 'enable') the NXT_FLOW_MOD_TABLE_ID
831 * extension on 'ofconn'. */
833 ofconn_set_flow_mod_table_id(struct ofconn *ofconn, bool enable)
835 ofconn->flow_mod_table_id = enable;
838 /* Returns the default miss send length for 'ofconn'. */
840 ofconn_get_miss_send_len(const struct ofconn *ofconn)
842 return ofconn->miss_send_len;
845 /* Sets the default miss send length for 'ofconn' to 'miss_send_len'. */
847 ofconn_set_miss_send_len(struct ofconn *ofconn, int miss_send_len)
849 ofconn->miss_send_len = miss_send_len;
853 ofconn_set_async_config(struct ofconn *ofconn,
854 const uint32_t master_masks[OAM_N_TYPES],
855 const uint32_t slave_masks[OAM_N_TYPES])
857 size_t size = sizeof ofconn->master_async_config;
858 memcpy(ofconn->master_async_config, master_masks, size);
859 memcpy(ofconn->slave_async_config, slave_masks, size);
862 /* Sends 'msg' on 'ofconn', accounting it as a reply. (If there is a
863 * sufficient number of OpenFlow replies in-flight on a single ofconn, then the
864 * connmgr will stop accepting new OpenFlow requests on that ofconn until the
865 * controller has accepted some of the replies.) */
867 ofconn_send_reply(const struct ofconn *ofconn, struct ofpbuf *msg)
869 ofconn_send(ofconn, msg, ofconn->reply_counter);
872 /* Sends each of the messages in list 'replies' on 'ofconn' in order,
873 * accounting them as replies. */
875 ofconn_send_replies(const struct ofconn *ofconn, struct list *replies)
877 struct ofpbuf *reply, *next;
879 LIST_FOR_EACH_SAFE (reply, next, list_node, replies) {
880 list_remove(&reply->list_node);
881 ofconn_send_reply(ofconn, reply);
885 /* Sends 'error' on 'ofconn', as a reply to 'request'. Only at most the
886 * first 64 bytes of 'request' are used. */
888 ofconn_send_error(const struct ofconn *ofconn,
889 const struct ofp_header *request, enum ofperr error)
891 struct ofpbuf *reply;
893 reply = ofperr_encode_reply(error, request);
895 static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10);
897 if (!VLOG_DROP_INFO(&err_rl)) {
898 const struct ofputil_msg_type *type;
899 const char *type_name;
902 request_len = ntohs(request->length);
903 type_name = (!ofputil_decode_msg_type_partial(request,
904 MIN(64, request_len),
906 ? ofputil_msg_type_name(type)
909 VLOG_INFO("%s: sending %s error reply to %s message",
910 rconn_get_name(ofconn->rconn), ofperr_to_string(error),
913 ofconn_send_reply(ofconn, reply);
917 /* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */
919 ofconn_pktbuf_retrieve(struct ofconn *ofconn, uint32_t id,
920 struct ofpbuf **bufferp, uint16_t *in_port)
922 return pktbuf_retrieve(ofconn->pktbuf, id, bufferp, in_port);
925 /* Returns true if 'ofconn' has any pending opgroups. */
927 ofconn_has_pending_opgroups(const struct ofconn *ofconn)
929 return !list_is_empty(&ofconn->opgroups);
932 /* Adds 'ofconn_node' to 'ofconn''s list of pending opgroups.
934 * If 'ofconn' is destroyed or its connection drops, then 'ofconn' will remove
935 * 'ofconn_node' from the list and re-initialize it with list_init(). The
936 * client may, therefore, use list_is_empty(ofconn_node) to determine whether
937 * 'ofconn_node' is still associated with an active ofconn.
939 * The client may also remove ofconn_node from the list itself, with
942 ofconn_add_opgroup(struct ofconn *ofconn, struct list *ofconn_node)
944 list_push_back(&ofconn->opgroups, ofconn_node);
947 /* Private ofconn functions. */
950 ofconn_get_target(const struct ofconn *ofconn)
952 return rconn_get_target(ofconn->rconn);
955 static struct ofconn *
956 ofconn_create(struct connmgr *mgr, struct rconn *rconn, enum ofconn_type type)
958 struct ofconn *ofconn;
960 ofconn = xzalloc(sizeof *ofconn);
961 ofconn->connmgr = mgr;
962 list_push_back(&mgr->all_conns, &ofconn->node);
963 ofconn->rconn = rconn;
966 list_init(&ofconn->opgroups);
968 ofconn_flush(ofconn);
973 /* Clears all of the state in 'ofconn' that should not persist from one
974 * connection to the next. */
976 ofconn_flush(struct ofconn *ofconn)
978 uint32_t *master = ofconn->master_async_config;
979 uint32_t *slave = ofconn->slave_async_config;
982 ofconn->role = NX_ROLE_OTHER;
983 ofconn->flow_format = NXFF_OPENFLOW10;
984 ofconn->packet_in_format = NXPIF_OPENFLOW10;
985 ofconn->flow_mod_table_id = false;
987 /* Disassociate 'ofconn' from all of the ofopgroups that it initiated that
988 * have not yet completed. (Those ofopgroups will still run to completion
989 * in the usual way, but any errors that they run into will not be reported
990 * on any OpenFlow channel.)
992 * Also discard any blocked operation on 'ofconn'. */
993 while (!list_is_empty(&ofconn->opgroups)) {
994 list_init(list_pop_front(&ofconn->opgroups));
996 ofpbuf_delete(ofconn->blocked);
997 ofconn->blocked = NULL;
999 rconn_packet_counter_destroy(ofconn->packet_in_counter);
1000 ofconn->packet_in_counter = rconn_packet_counter_create();
1001 for (i = 0; i < N_SCHEDULERS; i++) {
1002 if (ofconn->schedulers[i]) {
1005 pinsched_get_limits(ofconn->schedulers[i], &rate, &burst);
1006 pinsched_destroy(ofconn->schedulers[i]);
1007 ofconn->schedulers[i] = pinsched_create(rate, burst);
1010 if (ofconn->pktbuf) {
1011 pktbuf_destroy(ofconn->pktbuf);
1012 ofconn->pktbuf = pktbuf_create();
1014 ofconn->miss_send_len = (ofconn->type == OFCONN_PRIMARY
1015 ? OFP_DEFAULT_MISS_SEND_LEN
1018 rconn_packet_counter_destroy(ofconn->reply_counter);
1019 ofconn->reply_counter = rconn_packet_counter_create();
1021 /* "master" and "other" roles get all asynchronous messages by default,
1022 * except that the controller needs to enable nonstandard "packet-in"
1023 * reasons itself. */
1024 master[OAM_PACKET_IN] = (1u << OFPR_NO_MATCH) | (1u << OFPR_ACTION);
1025 master[OAM_PORT_STATUS] = ((1u << OFPPR_ADD)
1026 | (1u << OFPPR_DELETE)
1027 | (1u << OFPPR_MODIFY));
1028 master[OAM_FLOW_REMOVED] = ((1u << OFPRR_IDLE_TIMEOUT)
1029 | (1u << OFPRR_HARD_TIMEOUT)
1030 | (1u << OFPRR_DELETE));
1032 /* "slave" role gets port status updates by default. */
1033 slave[OAM_PACKET_IN] = 0;
1034 slave[OAM_PORT_STATUS] = ((1u << OFPPR_ADD)
1035 | (1u << OFPPR_DELETE)
1036 | (1u << OFPPR_MODIFY));
1037 slave[OAM_FLOW_REMOVED] = 0;
1041 ofconn_destroy(struct ofconn *ofconn)
1043 ofconn_flush(ofconn);
1045 if (ofconn->type == OFCONN_PRIMARY) {
1046 hmap_remove(&ofconn->connmgr->controllers, &ofconn->hmap_node);
1049 list_remove(&ofconn->node);
1050 rconn_destroy(ofconn->rconn);
1051 rconn_packet_counter_destroy(ofconn->packet_in_counter);
1052 rconn_packet_counter_destroy(ofconn->reply_counter);
1053 pktbuf_destroy(ofconn->pktbuf);
1057 /* Reconfigures 'ofconn' to match 'c'. 'ofconn' and 'c' must have the same
1060 ofconn_reconfigure(struct ofconn *ofconn, const struct ofproto_controller *c)
1064 ofconn->band = c->band;
1066 rconn_set_max_backoff(ofconn->rconn, c->max_backoff);
1068 probe_interval = c->probe_interval ? MAX(c->probe_interval, 5) : 0;
1069 rconn_set_probe_interval(ofconn->rconn, probe_interval);
1071 ofconn_set_rate_limit(ofconn, c->rate_limit, c->burst_limit);
1074 /* Returns true if it makes sense for 'ofconn' to receive and process OpenFlow
1077 ofconn_may_recv(const struct ofconn *ofconn)
1079 int count = rconn_packet_counter_read (ofconn->reply_counter);
1080 return (!ofconn->blocked || ofconn->retry) && count < OFCONN_REPLY_MAX;
1084 ofconn_run(struct ofconn *ofconn,
1085 bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
1087 struct connmgr *mgr = ofconn->connmgr;
1090 for (i = 0; i < N_SCHEDULERS; i++) {
1091 pinsched_run(ofconn->schedulers[i], do_send_packet_in, ofconn);
1094 rconn_run(ofconn->rconn);
1096 if (handle_openflow) {
1097 /* Limit the number of iterations to avoid starving other tasks. */
1098 for (i = 0; i < 50 && ofconn_may_recv(ofconn); i++) {
1099 struct ofpbuf *of_msg;
1101 of_msg = (ofconn->blocked
1103 : rconn_recv(ofconn->rconn));
1107 if (mgr->fail_open) {
1108 fail_open_maybe_recover(mgr->fail_open);
1111 if (handle_openflow(ofconn, of_msg)) {
1112 ofpbuf_delete(of_msg);
1113 ofconn->blocked = NULL;
1115 ofconn->blocked = of_msg;
1116 ofconn->retry = false;
1121 if (!rconn_is_alive(ofconn->rconn)) {
1122 ofconn_destroy(ofconn);
1123 } else if (!rconn_is_connected(ofconn->rconn)) {
1124 ofconn_flush(ofconn);
1129 ofconn_wait(struct ofconn *ofconn, bool handling_openflow)
1133 for (i = 0; i < N_SCHEDULERS; i++) {
1134 pinsched_wait(ofconn->schedulers[i]);
1136 rconn_run_wait(ofconn->rconn);
1137 if (handling_openflow && ofconn_may_recv(ofconn)) {
1138 rconn_recv_wait(ofconn->rconn);
1142 /* Returns true if 'ofconn' should receive asynchronous messages of the given
1143 * OAM_* 'type' and 'reason', which should be a OFPR_* value for OAM_PACKET_IN,
1144 * a OFPPR_* value for OAM_PORT_STATUS, or an OFPRR_* value for
1145 * OAM_FLOW_REMOVED. Returns false if the message should not be sent on
1148 ofconn_receives_async_msg(const struct ofconn *ofconn,
1149 enum ofconn_async_msg_type type,
1150 unsigned int reason)
1152 const uint32_t *async_config;
1154 assert(reason < 32);
1155 assert((unsigned int) type < OAM_N_TYPES);
1157 if (!rconn_is_connected(ofconn->rconn)) {
1161 /* Keep the following code in sync with the documentation in the
1162 * "Asynchronous Messages" section in DESIGN. */
1164 if (ofconn->type == OFCONN_SERVICE && !ofconn->miss_send_len) {
1165 /* Service connections don't get asynchronous messages unless they have
1166 * explicitly asked for them by setting a nonzero miss send length. */
1170 async_config = (ofconn->role == NX_ROLE_SLAVE
1171 ? ofconn->slave_async_config
1172 : ofconn->master_async_config);
1173 if (!(async_config[type] & (1u << reason))) {
1180 /* Returns a human-readable name for an OpenFlow connection between 'mgr' and
1181 * 'target', suitable for use in log messages for identifying the connection.
1183 * The name is dynamically allocated. The caller should free it (with free())
1184 * when it is no longer needed. */
1186 ofconn_make_name(const struct connmgr *mgr, const char *target)
1188 return xasprintf("%s<->%s", mgr->name, target);
1192 ofconn_set_rate_limit(struct ofconn *ofconn, int rate, int burst)
1196 for (i = 0; i < N_SCHEDULERS; i++) {
1197 struct pinsched **s = &ofconn->schedulers[i];
1201 *s = pinsched_create(rate, burst);
1203 pinsched_set_limits(*s, rate, burst);
1206 pinsched_destroy(*s);
1213 ofconn_send(const struct ofconn *ofconn, struct ofpbuf *msg,
1214 struct rconn_packet_counter *counter)
1216 update_openflow_length(msg);
1217 if (rconn_send(ofconn->rconn, msg, counter)) {
1222 /* Sending asynchronous messages. */
1224 static void schedule_packet_in(struct ofconn *, struct ofputil_packet_in,
1225 const struct flow *);
1227 /* Sends an OFPT_PORT_STATUS message with 'opp' and 'reason' to appropriate
1228 * controllers managed by 'mgr'. */
1230 connmgr_send_port_status(struct connmgr *mgr, const struct ofp_phy_port *opp,
1233 /* XXX Should limit the number of queued port status change messages. */
1234 struct ofconn *ofconn;
1236 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1237 if (ofconn_receives_async_msg(ofconn, OAM_PORT_STATUS, reason)) {
1238 struct ofp_port_status *ops;
1241 ops = make_openflow_xid(sizeof *ops, OFPT_PORT_STATUS, 0, &b);
1242 ops->reason = reason;
1244 ofconn_send(ofconn, b, NULL);
1249 /* Sends an OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED message based on 'fr' to
1250 * appropriate controllers managed by 'mgr'. */
1252 connmgr_send_flow_removed(struct connmgr *mgr,
1253 const struct ofputil_flow_removed *fr)
1255 struct ofconn *ofconn;
1257 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1258 if (ofconn_receives_async_msg(ofconn, OAM_FLOW_REMOVED, fr->reason)) {
1261 /* Account flow expirations as replies to OpenFlow requests. That
1262 * works because preventing OpenFlow requests from being processed
1263 * also prevents new flows from being added (and expiring). (It
1264 * also prevents processing OpenFlow requests that would not add
1265 * new flows, so it is imperfect.) */
1266 msg = ofputil_encode_flow_removed(fr, ofconn->flow_format);
1267 ofconn_send_reply(ofconn, msg);
1272 /* Given 'pin', sends an OFPT_PACKET_IN message to each OpenFlow controller as
1273 * necessary according to their individual configurations. */
1275 connmgr_send_packet_in(struct connmgr *mgr,
1276 const struct ofputil_packet_in *pin,
1277 const struct flow *flow)
1279 struct ofconn *ofconn;
1281 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1282 if (ofconn_receives_async_msg(ofconn, OAM_PACKET_IN, pin->reason)) {
1283 schedule_packet_in(ofconn, *pin, flow);
1288 /* pinsched callback for sending 'ofp_packet_in' on 'ofconn'. */
1290 do_send_packet_in(struct ofpbuf *ofp_packet_in, void *ofconn_)
1292 struct ofconn *ofconn = ofconn_;
1294 rconn_send_with_limit(ofconn->rconn, ofp_packet_in,
1295 ofconn->packet_in_counter, 100);
1298 /* Takes 'pin', whose packet has the flow specified by 'flow', composes an
1299 * OpenFlow packet-in message from it, and passes it to 'ofconn''s packet
1300 * scheduler for sending. */
1302 schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin,
1303 const struct flow *flow)
1305 struct connmgr *mgr = ofconn->connmgr;
1307 /* Get OpenFlow buffer_id. */
1308 if (pin.reason == OFPR_ACTION) {
1309 pin.buffer_id = UINT32_MAX;
1310 } else if (mgr->fail_open && fail_open_is_active(mgr->fail_open)) {
1311 pin.buffer_id = pktbuf_get_null();
1312 } else if (!ofconn->pktbuf) {
1313 pin.buffer_id = UINT32_MAX;
1315 pin.buffer_id = pktbuf_save(ofconn->pktbuf, pin.packet, pin.packet_len,
1319 /* Figure out how much of the packet to send. */
1320 if (pin.reason == OFPR_NO_MATCH) {
1321 pin.send_len = pin.packet_len;
1323 /* Caller should have initialized 'send_len' to 'max_len' specified in
1324 * struct ofp_action_output. */
1326 if (pin.buffer_id != UINT32_MAX) {
1327 pin.send_len = MIN(pin.send_len, ofconn->miss_send_len);
1330 /* Make OFPT_PACKET_IN and hand over to packet scheduler. It might
1331 * immediately call into do_send_packet_in() or it might buffer it for a
1332 * while (until a later call to pinsched_run()). */
1333 pinsched_send(ofconn->schedulers[pin.reason == OFPR_NO_MATCH ? 0 : 1],
1335 ofputil_encode_packet_in(&pin, ofconn->packet_in_format),
1336 do_send_packet_in, ofconn);
1339 /* Fail-open settings. */
1341 /* Returns the failure handling mode (OFPROTO_FAIL_SECURE or
1342 * OFPROTO_FAIL_STANDALONE) for 'mgr'. */
1343 enum ofproto_fail_mode
1344 connmgr_get_fail_mode(const struct connmgr *mgr)
1346 return mgr->fail_mode;
1349 /* Sets the failure handling mode for 'mgr' to 'fail_mode' (either
1350 * OFPROTO_FAIL_SECURE or OFPROTO_FAIL_STANDALONE). */
1352 connmgr_set_fail_mode(struct connmgr *mgr, enum ofproto_fail_mode fail_mode)
1354 if (mgr->fail_mode != fail_mode) {
1355 mgr->fail_mode = fail_mode;
1356 update_fail_open(mgr);
1357 if (!connmgr_has_controllers(mgr)) {
1358 ofproto_flush_flows(mgr->ofproto);
1363 /* Fail-open implementation. */
1365 /* Returns the longest probe interval among the primary controllers configured
1366 * on 'mgr'. Returns 0 if there are no primary controllers. */
1368 connmgr_get_max_probe_interval(const struct connmgr *mgr)
1370 const struct ofconn *ofconn;
1371 int max_probe_interval;
1373 max_probe_interval = 0;
1374 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1375 int probe_interval = rconn_get_probe_interval(ofconn->rconn);
1376 max_probe_interval = MAX(max_probe_interval, probe_interval);
1378 return max_probe_interval;
1381 /* Returns the number of seconds for which all of 'mgr's primary controllers
1382 * have been disconnected. Returns 0 if 'mgr' has no primary controllers. */
1384 connmgr_failure_duration(const struct connmgr *mgr)
1386 const struct ofconn *ofconn;
1387 int min_failure_duration;
1389 if (!connmgr_has_controllers(mgr)) {
1393 min_failure_duration = INT_MAX;
1394 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1395 int failure_duration = rconn_failure_duration(ofconn->rconn);
1396 min_failure_duration = MIN(min_failure_duration, failure_duration);
1398 return min_failure_duration;
1401 /* Returns true if at least one primary controller is connected (regardless of
1402 * whether those controllers are believed to have authenticated and accepted
1403 * this switch), false if none of them are connected. */
1405 connmgr_is_any_controller_connected(const struct connmgr *mgr)
1407 const struct ofconn *ofconn;
1409 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1410 if (rconn_is_connected(ofconn->rconn)) {
1417 /* Returns true if at least one primary controller is believed to have
1418 * authenticated and accepted this switch, false otherwise. */
1420 connmgr_is_any_controller_admitted(const struct connmgr *mgr)
1422 const struct ofconn *ofconn;
1424 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1425 if (rconn_is_admitted(ofconn->rconn)) {
1432 /* Sends 'packet' to each controller connected to 'mgr'. Takes ownership of
1435 connmgr_broadcast(struct connmgr *mgr, struct ofpbuf *packet)
1437 struct ofconn *ofconn, *prev;
1440 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1442 ofconn_send_reply(ofconn, ofpbuf_clone(packet));
1444 if (rconn_is_connected(ofconn->rconn)) {
1449 ofconn_send_reply(prev, packet);
1451 ofpbuf_delete(packet);
1455 /* In-band configuration. */
1457 static bool any_extras_changed(const struct connmgr *,
1458 const struct sockaddr_in *extras, size_t n);
1460 /* Sets the 'n' TCP port addresses in 'extras' as ones to which 'mgr''s
1461 * in-band control should guarantee access, in the same way that in-band
1462 * control guarantees access to OpenFlow controllers. */
1464 connmgr_set_extra_in_band_remotes(struct connmgr *mgr,
1465 const struct sockaddr_in *extras, size_t n)
1467 if (!any_extras_changed(mgr, extras, n)) {
1471 free(mgr->extra_in_band_remotes);
1472 mgr->n_extra_remotes = n;
1473 mgr->extra_in_band_remotes = xmemdup(extras, n * sizeof *extras);
1475 update_in_band_remotes(mgr);
1478 /* Sets the OpenFlow queue used by flows set up by in-band control on
1479 * 'mgr' to 'queue_id'. If 'queue_id' is negative, then in-band control
1480 * flows will use the default queue. */
1482 connmgr_set_in_band_queue(struct connmgr *mgr, int queue_id)
1484 if (queue_id != mgr->in_band_queue) {
1485 mgr->in_band_queue = queue_id;
1486 update_in_band_remotes(mgr);
1491 any_extras_changed(const struct connmgr *mgr,
1492 const struct sockaddr_in *extras, size_t n)
1496 if (n != mgr->n_extra_remotes) {
1500 for (i = 0; i < n; i++) {
1501 const struct sockaddr_in *old = &mgr->extra_in_band_remotes[i];
1502 const struct sockaddr_in *new = &extras[i];
1504 if (old->sin_addr.s_addr != new->sin_addr.s_addr ||
1505 old->sin_port != new->sin_port) {
1513 /* In-band implementation. */
1516 connmgr_msg_in_hook(struct connmgr *mgr, const struct flow *flow,
1517 const struct ofpbuf *packet)
1519 return mgr->in_band && in_band_msg_in_hook(mgr->in_band, flow, packet);
1523 connmgr_may_set_up_flow(struct connmgr *mgr, const struct flow *flow,
1524 const struct nlattr *odp_actions,
1527 return !mgr->in_band || in_band_rule_check(flow, odp_actions, actions_len);
1530 /* Fail-open and in-band implementation. */
1532 /* Called by 'ofproto' after all flows have been flushed, to allow fail-open
1533 * and standalone mode to re-create their flows.
1535 * In-band control has more sophisticated code that manages flows itself. */
1537 connmgr_flushed(struct connmgr *mgr)
1539 if (mgr->fail_open) {
1540 fail_open_flushed(mgr->fail_open);
1543 /* If there are no controllers and we're in standalone mode, set up a flow
1544 * that matches every packet and directs them to OFPP_NORMAL (which goes to
1545 * us). Otherwise, the switch is in secure mode and we won't pass any
1546 * traffic until a controller has been defined and it tells us to do so. */
1547 if (!connmgr_has_controllers(mgr)
1548 && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
1549 union ofp_action action;
1550 struct cls_rule rule;
1552 memset(&action, 0, sizeof action);
1553 action.type = htons(OFPAT_OUTPUT);
1554 action.output.len = htons(sizeof action);
1555 action.output.port = htons(OFPP_NORMAL);
1556 cls_rule_init_catchall(&rule, 0);
1557 ofproto_add_flow(mgr->ofproto, &rule, &action, 1);
1561 /* Creates a new ofservice for 'target' in 'mgr'. Returns 0 if successful,
1562 * otherwise a positive errno value.
1564 * ofservice_reconfigure() must be called to fully configure the new
1567 ofservice_create(struct connmgr *mgr, const char *target)
1569 struct ofservice *ofservice;
1570 struct pvconn *pvconn;
1573 error = pvconn_open(target, &pvconn);
1578 ofservice = xzalloc(sizeof *ofservice);
1579 hmap_insert(&mgr->services, &ofservice->node, hash_string(target, 0));
1580 ofservice->pvconn = pvconn;
1586 ofservice_destroy(struct connmgr *mgr, struct ofservice *ofservice)
1588 hmap_remove(&mgr->services, &ofservice->node);
1589 pvconn_close(ofservice->pvconn);
1594 ofservice_reconfigure(struct ofservice *ofservice,
1595 const struct ofproto_controller *c)
1597 ofservice->probe_interval = c->probe_interval;
1598 ofservice->rate_limit = c->rate_limit;
1599 ofservice->burst_limit = c->burst_limit;
1602 /* Finds and returns the ofservice within 'mgr' that has the given
1603 * 'target', or a null pointer if none exists. */
1604 static struct ofservice *
1605 ofservice_lookup(struct connmgr *mgr, const char *target)
1607 struct ofservice *ofservice;
1609 HMAP_FOR_EACH_WITH_HASH (ofservice, node, hash_string(target, 0),
1611 if (!strcmp(pvconn_get_name(ofservice->pvconn), target)) {