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? */
55 bool enable_async_msgs; /* Initially enable async messages? */
57 /* State that should be cleared from one connection to the next. */
60 enum nx_role role; /* Role. */
61 enum nx_flow_format flow_format; /* Currently selected flow format. */
62 enum nx_packet_in_format packet_in_format; /* OFPT_PACKET_IN format. */
63 bool flow_mod_table_id; /* NXT_FLOW_MOD_TABLE_ID enabled? */
65 /* Asynchronous flow table operation support. */
66 struct list opgroups; /* Contains pending "ofopgroups", if any. */
67 struct ofpbuf *blocked; /* Postponed OpenFlow message, if any. */
68 bool retry; /* True if 'blocked' is ready to try again. */
70 /* OFPT_PACKET_IN related data. */
71 struct rconn_packet_counter *packet_in_counter; /* # queued on 'rconn'. */
72 #define N_SCHEDULERS 2
73 struct pinsched *schedulers[N_SCHEDULERS];
74 struct pktbuf *pktbuf; /* OpenFlow packet buffers. */
75 int miss_send_len; /* Bytes to send of buffered packets. */
77 /* Number of OpenFlow messages queued on 'rconn' as replies to OpenFlow
78 * requests, and the maximum number before we stop reading OpenFlow
80 #define OFCONN_REPLY_MAX 100
81 struct rconn_packet_counter *reply_counter;
83 /* Asynchronous message configuration in each possible roles.
85 * A 1-bit enables sending an asynchronous message for one possible reason
86 * that the message might be generated, a 0-bit disables it. */
87 uint32_t master_async_config[OAM_N_TYPES]; /* master, other */
88 uint32_t slave_async_config[OAM_N_TYPES]; /* slave */
91 static struct ofconn *ofconn_create(struct connmgr *, struct rconn *,
92 enum ofconn_type, bool enable_async_msgs);
93 static void ofconn_destroy(struct ofconn *);
94 static void ofconn_flush(struct ofconn *);
96 static void ofconn_reconfigure(struct ofconn *,
97 const struct ofproto_controller *);
99 static void ofconn_run(struct ofconn *,
100 bool (*handle_openflow)(struct ofconn *,
101 struct ofpbuf *ofp_msg));
102 static void ofconn_wait(struct ofconn *, bool handling_openflow);
104 static const char *ofconn_get_target(const struct ofconn *);
105 static char *ofconn_make_name(const struct connmgr *, const char *target);
107 static void ofconn_set_rate_limit(struct ofconn *, int rate, int burst);
109 static void ofconn_send(const struct ofconn *, struct ofpbuf *,
110 struct rconn_packet_counter *);
112 static void do_send_packet_in(struct ofpbuf *, void *ofconn_);
114 /* A listener for incoming OpenFlow "service" connections. */
116 struct hmap_node node; /* In struct connmgr's "services" hmap. */
117 struct pvconn *pvconn; /* OpenFlow connection listener. */
119 /* These are not used by ofservice directly. They are settings for
120 * accepted "struct ofconn"s from the pvconn. */
121 int probe_interval; /* Max idle time before probing, in seconds. */
122 int rate_limit; /* Max packet-in rate in packets per second. */
123 int burst_limit; /* Limit on accumulating packet credits. */
124 bool enable_async_msgs; /* Initially enable async messages? */
127 static void ofservice_reconfigure(struct ofservice *,
128 const struct ofproto_controller *);
129 static int ofservice_create(struct connmgr *, const char *target);
130 static void ofservice_destroy(struct connmgr *, struct ofservice *);
131 static struct ofservice *ofservice_lookup(struct connmgr *,
134 /* Connection manager for an OpenFlow switch. */
136 struct ofproto *ofproto;
138 char *local_port_name;
140 /* OpenFlow connections. */
141 struct hmap controllers; /* Controller "struct ofconn"s. */
142 struct list all_conns; /* Contains "struct ofconn"s. */
144 /* OpenFlow listeners. */
145 struct hmap services; /* Contains "struct ofservice"s. */
146 struct pvconn **snoops;
150 struct fail_open *fail_open;
151 enum ofproto_fail_mode fail_mode;
153 /* In-band control. */
154 struct in_band *in_band;
155 struct sockaddr_in *extra_in_band_remotes;
156 size_t n_extra_remotes;
160 static void update_in_band_remotes(struct connmgr *);
161 static void add_snooper(struct connmgr *, struct vconn *);
163 /* Creates and returns a new connection manager owned by 'ofproto'. 'name' is
164 * a name for the ofproto suitable for using in log messages.
165 * 'local_port_name' is the name of the local port (OFPP_LOCAL) within
168 connmgr_create(struct ofproto *ofproto,
169 const char *name, const char *local_port_name)
173 mgr = xmalloc(sizeof *mgr);
174 mgr->ofproto = ofproto;
175 mgr->name = xstrdup(name);
176 mgr->local_port_name = xstrdup(local_port_name);
178 hmap_init(&mgr->controllers);
179 list_init(&mgr->all_conns);
181 hmap_init(&mgr->services);
185 mgr->fail_open = NULL;
186 mgr->fail_mode = OFPROTO_FAIL_SECURE;
189 mgr->extra_in_band_remotes = NULL;
190 mgr->n_extra_remotes = 0;
191 mgr->in_band_queue = -1;
196 /* Frees 'mgr' and all of its resources. */
198 connmgr_destroy(struct connmgr *mgr)
200 struct ofservice *ofservice, *next_ofservice;
201 struct ofconn *ofconn, *next_ofconn;
208 LIST_FOR_EACH_SAFE (ofconn, next_ofconn, node, &mgr->all_conns) {
209 ofconn_destroy(ofconn);
211 hmap_destroy(&mgr->controllers);
213 HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, node, &mgr->services) {
214 ofservice_destroy(mgr, ofservice);
216 hmap_destroy(&mgr->services);
218 for (i = 0; i < mgr->n_snoops; i++) {
219 pvconn_close(mgr->snoops[i]);
223 fail_open_destroy(mgr->fail_open);
224 mgr->fail_open = NULL;
226 in_band_destroy(mgr->in_band);
228 free(mgr->extra_in_band_remotes);
230 free(mgr->local_port_name);
235 /* Does all of the periodic maintenance required by 'mgr'.
237 * If 'handle_openflow' is nonnull, calls 'handle_openflow' for each message
238 * received on an OpenFlow connection, passing along the OpenFlow connection
239 * itself and the message that was sent. If 'handle_openflow' returns true,
240 * the message is considered to be fully processed. If 'handle_openflow'
241 * returns false, the message is considered not to have been processed at all;
242 * it will be stored and re-presented to 'handle_openflow' following the next
243 * call to connmgr_retry(). 'handle_openflow' must not modify or free the
246 * If 'handle_openflow' is NULL, no OpenFlow messages will be processed and
247 * other activities that could affect the flow table (in-band processing,
248 * fail-open processing) are suppressed too. */
250 connmgr_run(struct connmgr *mgr,
251 bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
253 struct ofconn *ofconn, *next_ofconn;
254 struct ofservice *ofservice;
257 if (handle_openflow && mgr->in_band) {
258 if (!in_band_run(mgr->in_band)) {
259 in_band_destroy(mgr->in_band);
264 LIST_FOR_EACH_SAFE (ofconn, next_ofconn, node, &mgr->all_conns) {
265 ofconn_run(ofconn, handle_openflow);
268 /* Fail-open maintenance. Do this after processing the ofconns since
269 * fail-open checks the status of the controller rconn. */
270 if (handle_openflow && mgr->fail_open) {
271 fail_open_run(mgr->fail_open);
274 HMAP_FOR_EACH (ofservice, node, &mgr->services) {
278 retval = pvconn_accept(ofservice->pvconn, OFP_VERSION, &vconn);
283 rconn = rconn_create(ofservice->probe_interval, 0);
284 name = ofconn_make_name(mgr, vconn_get_name(vconn));
285 rconn_connect_unreliably(rconn, vconn, name);
288 ofconn = ofconn_create(mgr, rconn, OFCONN_SERVICE,
289 ofservice->enable_async_msgs);
290 ofconn_set_rate_limit(ofconn, ofservice->rate_limit,
291 ofservice->burst_limit);
292 } else if (retval != EAGAIN) {
293 VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
297 for (i = 0; i < mgr->n_snoops; i++) {
301 retval = pvconn_accept(mgr->snoops[i], OFP_VERSION, &vconn);
303 add_snooper(mgr, vconn);
304 } else if (retval != EAGAIN) {
305 VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
310 /* Causes the poll loop to wake up when connmgr_run() needs to run.
312 * If 'handling_openflow' is true, arriving OpenFlow messages and other
313 * activities that affect the flow table will wake up the poll loop. If
314 * 'handling_openflow' is false, they will not. */
316 connmgr_wait(struct connmgr *mgr, bool handling_openflow)
318 struct ofservice *ofservice;
319 struct ofconn *ofconn;
322 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
323 ofconn_wait(ofconn, handling_openflow);
325 if (handling_openflow && mgr->in_band) {
326 in_band_wait(mgr->in_band);
328 if (handling_openflow && mgr->fail_open) {
329 fail_open_wait(mgr->fail_open);
331 HMAP_FOR_EACH (ofservice, node, &mgr->services) {
332 pvconn_wait(ofservice->pvconn);
334 for (i = 0; i < mgr->n_snoops; i++) {
335 pvconn_wait(mgr->snoops[i]);
339 /* Returns the ofproto that owns 'ofconn''s connmgr. */
341 ofconn_get_ofproto(const struct ofconn *ofconn)
343 return ofconn->connmgr->ofproto;
346 /* If processing of OpenFlow messages was blocked on any 'mgr' ofconns by
347 * returning false to the 'handle_openflow' callback to connmgr_run(), this
348 * re-enables them. */
350 connmgr_retry(struct connmgr *mgr)
352 struct ofconn *ofconn;
354 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
355 ofconn->retry = true;
359 /* OpenFlow configuration. */
361 static void add_controller(struct connmgr *, const char *target);
362 static struct ofconn *find_controller_by_target(struct connmgr *,
364 static void update_fail_open(struct connmgr *);
365 static int set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
366 const struct sset *);
368 /* Returns true if 'mgr' has any configured primary controllers.
370 * Service controllers do not count, but configured primary controllers do
371 * count whether or not they are currently connected. */
373 connmgr_has_controllers(const struct connmgr *mgr)
375 return !hmap_is_empty(&mgr->controllers);
378 /* Initializes 'info' and populates it with information about each configured
379 * primary controller. The keys in 'info' are the controllers' targets; the
380 * data values are corresponding "struct ofproto_controller_info".
382 * The caller owns 'info' and everything in it and should free it when it is no
385 connmgr_get_controller_info(struct connmgr *mgr, struct shash *info)
387 const struct ofconn *ofconn;
389 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
390 const struct rconn *rconn = ofconn->rconn;
391 const char *target = rconn_get_target(rconn);
393 if (!shash_find(info, target)) {
394 struct ofproto_controller_info *cinfo = xmalloc(sizeof *cinfo);
395 time_t now = time_now();
396 time_t last_connection = rconn_get_last_connection(rconn);
397 time_t last_disconnect = rconn_get_last_disconnect(rconn);
398 int last_error = rconn_get_last_error(rconn);
400 shash_add(info, target, cinfo);
402 cinfo->is_connected = rconn_is_connected(rconn);
403 cinfo->role = ofconn->role;
408 cinfo->pairs.keys[cinfo->pairs.n] = "last_error";
409 cinfo->pairs.values[cinfo->pairs.n++]
410 = xstrdup(ovs_retval_to_string(last_error));
413 cinfo->pairs.keys[cinfo->pairs.n] = "state";
414 cinfo->pairs.values[cinfo->pairs.n++]
415 = xstrdup(rconn_get_state(rconn));
417 if (last_connection != TIME_MIN) {
418 cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_connect";
419 cinfo->pairs.values[cinfo->pairs.n++]
420 = xasprintf("%ld", (long int) (now - last_connection));
423 if (last_disconnect != TIME_MIN) {
424 cinfo->pairs.keys[cinfo->pairs.n] = "sec_since_disconnect";
425 cinfo->pairs.values[cinfo->pairs.n++]
426 = xasprintf("%ld", (long int) (now - last_disconnect));
433 connmgr_free_controller_info(struct shash *info)
435 struct shash_node *node;
437 SHASH_FOR_EACH (node, info) {
438 struct ofproto_controller_info *cinfo = node->data;
439 while (cinfo->pairs.n) {
440 free((char *) cinfo->pairs.values[--cinfo->pairs.n]);
447 /* Changes 'mgr''s set of controllers to the 'n_controllers' controllers in
450 connmgr_set_controllers(struct connmgr *mgr,
451 const struct ofproto_controller *controllers,
452 size_t n_controllers)
454 bool had_controllers = connmgr_has_controllers(mgr);
455 struct shash new_controllers;
456 struct ofconn *ofconn, *next_ofconn;
457 struct ofservice *ofservice, *next_ofservice;
460 /* Create newly configured controllers and services.
461 * Create a name to ofproto_controller mapping in 'new_controllers'. */
462 shash_init(&new_controllers);
463 for (i = 0; i < n_controllers; i++) {
464 const struct ofproto_controller *c = &controllers[i];
466 if (!vconn_verify_name(c->target)) {
467 if (!find_controller_by_target(mgr, c->target)) {
468 add_controller(mgr, c->target);
470 } else if (!pvconn_verify_name(c->target)) {
471 if (!ofservice_lookup(mgr, c->target)) {
472 ofservice_create(mgr, c->target);
475 VLOG_WARN_RL(&rl, "%s: unsupported controller \"%s\"",
476 mgr->name, c->target);
480 shash_add_once(&new_controllers, c->target, &controllers[i]);
483 /* Delete controllers that are no longer configured.
484 * Update configuration of all now-existing controllers. */
485 HMAP_FOR_EACH_SAFE (ofconn, next_ofconn, hmap_node, &mgr->controllers) {
486 struct ofproto_controller *c;
488 c = shash_find_data(&new_controllers, ofconn_get_target(ofconn));
490 ofconn_destroy(ofconn);
492 ofconn_reconfigure(ofconn, c);
496 /* Delete services that are no longer configured.
497 * Update configuration of all now-existing services. */
498 HMAP_FOR_EACH_SAFE (ofservice, next_ofservice, node, &mgr->services) {
499 struct ofproto_controller *c;
501 c = shash_find_data(&new_controllers,
502 pvconn_get_name(ofservice->pvconn));
504 ofservice_destroy(mgr, ofservice);
506 ofservice_reconfigure(ofservice, c);
510 shash_destroy(&new_controllers);
512 update_in_band_remotes(mgr);
513 update_fail_open(mgr);
514 if (had_controllers != connmgr_has_controllers(mgr)) {
515 ofproto_flush_flows(mgr->ofproto);
519 /* Drops the connections between 'mgr' and all of its primary and secondary
520 * controllers, forcing them to reconnect. */
522 connmgr_reconnect(const struct connmgr *mgr)
524 struct ofconn *ofconn;
526 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
527 rconn_reconnect(ofconn->rconn);
531 /* Sets the "snoops" for 'mgr' to the pvconn targets listed in 'snoops'.
533 * A "snoop" is a pvconn to which every OpenFlow message to or from the most
534 * important controller on 'mgr' is mirrored. */
536 connmgr_set_snoops(struct connmgr *mgr, const struct sset *snoops)
538 return set_pvconns(&mgr->snoops, &mgr->n_snoops, snoops);
541 /* Adds each of the snoops currently configured on 'mgr' to 'snoops'. */
543 connmgr_get_snoops(const struct connmgr *mgr, struct sset *snoops)
547 for (i = 0; i < mgr->n_snoops; i++) {
548 sset_add(snoops, pvconn_get_name(mgr->snoops[i]));
552 /* Returns true if 'mgr' has at least one snoop, false if it has none. */
554 connmgr_has_snoops(const struct connmgr *mgr)
556 return mgr->n_snoops > 0;
559 /* Creates a new controller for 'target' in 'mgr'. update_controller() needs
560 * to be called later to finish the new ofconn's configuration. */
562 add_controller(struct connmgr *mgr, const char *target)
564 char *name = ofconn_make_name(mgr, target);
565 struct ofconn *ofconn;
567 ofconn = ofconn_create(mgr, rconn_create(5, 8), OFCONN_PRIMARY, true);
568 ofconn->pktbuf = pktbuf_create();
569 rconn_connect(ofconn->rconn, target, name);
570 hmap_insert(&mgr->controllers, &ofconn->hmap_node, hash_string(target, 0));
575 static struct ofconn *
576 find_controller_by_target(struct connmgr *mgr, const char *target)
578 struct ofconn *ofconn;
580 HMAP_FOR_EACH_WITH_HASH (ofconn, hmap_node,
581 hash_string(target, 0), &mgr->controllers) {
582 if (!strcmp(ofconn_get_target(ofconn), target)) {
590 update_in_band_remotes(struct connmgr *mgr)
592 struct sockaddr_in *addrs;
593 size_t max_addrs, n_addrs;
594 struct ofconn *ofconn;
597 /* Allocate enough memory for as many remotes as we could possibly have. */
598 max_addrs = mgr->n_extra_remotes + hmap_count(&mgr->controllers);
599 addrs = xmalloc(max_addrs * sizeof *addrs);
602 /* Add all the remotes. */
603 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
604 struct sockaddr_in *sin = &addrs[n_addrs];
605 const char *target = rconn_get_target(ofconn->rconn);
607 if (ofconn->band == OFPROTO_OUT_OF_BAND) {
611 if (stream_parse_target_with_default_ports(target,
618 for (i = 0; i < mgr->n_extra_remotes; i++) {
619 addrs[n_addrs++] = mgr->extra_in_band_remotes[i];
622 /* Create or update or destroy in-band. */
625 in_band_create(mgr->ofproto, mgr->local_port_name, &mgr->in_band);
627 in_band_set_queue(mgr->in_band, mgr->in_band_queue);
629 /* in_band_run() needs a chance to delete any existing in-band flows.
630 * We will destroy mgr->in_band after it's done with that. */
633 in_band_set_remotes(mgr->in_band, addrs, n_addrs);
641 update_fail_open(struct connmgr *mgr)
643 if (connmgr_has_controllers(mgr)
644 && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
645 if (!mgr->fail_open) {
646 mgr->fail_open = fail_open_create(mgr->ofproto, mgr);
649 fail_open_destroy(mgr->fail_open);
650 mgr->fail_open = NULL;
655 set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp,
656 const struct sset *sset)
658 struct pvconn **pvconns = *pvconnsp;
659 size_t n_pvconns = *n_pvconnsp;
664 for (i = 0; i < n_pvconns; i++) {
665 pvconn_close(pvconns[i]);
669 pvconns = xmalloc(sset_count(sset) * sizeof *pvconns);
671 SSET_FOR_EACH (name, sset) {
672 struct pvconn *pvconn;
675 error = pvconn_open(name, &pvconn);
677 pvconns[n_pvconns++] = pvconn;
679 VLOG_ERR("failed to listen on %s: %s", name, strerror(error));
687 *n_pvconnsp = n_pvconns;
692 /* Returns a "preference level" for snooping 'ofconn'. A higher return value
693 * means that 'ofconn' is more interesting for monitoring than a lower return
696 snoop_preference(const struct ofconn *ofconn)
698 switch (ofconn->role) {
706 /* Shouldn't happen. */
711 /* One of 'mgr''s "snoop" pvconns has accepted a new connection on 'vconn'.
712 * Connects this vconn to a controller. */
714 add_snooper(struct connmgr *mgr, struct vconn *vconn)
716 struct ofconn *ofconn, *best;
718 /* Pick a controller for monitoring. */
720 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
721 if (ofconn->type == OFCONN_PRIMARY
722 && (!best || snoop_preference(ofconn) > snoop_preference(best))) {
728 rconn_add_monitor(best->rconn, vconn);
730 VLOG_INFO_RL(&rl, "no controller connection to snoop");
735 /* Public ofconn functions. */
737 /* Returns the connection type, either OFCONN_PRIMARY or OFCONN_SERVICE. */
739 ofconn_get_type(const struct ofconn *ofconn)
744 /* Returns the role configured for 'ofconn'.
746 * The default role, if no other role has been set, is NX_ROLE_OTHER. */
748 ofconn_get_role(const struct ofconn *ofconn)
753 /* Changes 'ofconn''s role to 'role'. If 'role' is NX_ROLE_MASTER then any
754 * existing master is demoted to a slave. */
756 ofconn_set_role(struct ofconn *ofconn, enum nx_role role)
758 if (role == NX_ROLE_MASTER) {
759 struct ofconn *other;
761 HMAP_FOR_EACH (other, hmap_node, &ofconn->connmgr->controllers) {
762 if (other->role == NX_ROLE_MASTER) {
763 other->role = NX_ROLE_SLAVE;
771 ofconn_set_invalid_ttl_to_controller(struct ofconn *ofconn, bool enable)
773 uint32_t bit = 1u << OFPR_INVALID_TTL;
775 ofconn->master_async_config[OAM_PACKET_IN] |= bit;
777 ofconn->master_async_config[OAM_PACKET_IN] &= ~bit;
782 ofconn_get_invalid_ttl_to_controller(struct ofconn *ofconn)
784 uint32_t bit = 1u << OFPR_INVALID_TTL;
785 return (ofconn->master_async_config[OAM_PACKET_IN] & bit) != 0;
788 /* Returns the currently configured flow format for 'ofconn', one of NXFF_*.
790 * The default, if no other format has been set, is NXFF_OPENFLOW10. */
792 ofconn_get_flow_format(struct ofconn *ofconn)
794 return ofconn->flow_format;
797 /* Sets the flow format for 'ofconn' to 'flow_format' (one of NXFF_*). */
799 ofconn_set_flow_format(struct ofconn *ofconn, enum nx_flow_format flow_format)
801 ofconn->flow_format = flow_format;
804 /* Returns the currently configured packet in format for 'ofconn', one of
807 * The default, if no other format has been set, is NXPIF_OPENFLOW10. */
808 enum nx_packet_in_format
809 ofconn_get_packet_in_format(struct ofconn *ofconn)
811 return ofconn->packet_in_format;
814 /* Sets the packet in format for 'ofconn' to 'packet_in_format' (one of
817 ofconn_set_packet_in_format(struct ofconn *ofconn,
818 enum nx_packet_in_format packet_in_format)
820 ofconn->packet_in_format = packet_in_format;
823 /* Returns true if the NXT_FLOW_MOD_TABLE_ID extension is enabled, false
826 * By default the extension is not enabled. */
828 ofconn_get_flow_mod_table_id(const struct ofconn *ofconn)
830 return ofconn->flow_mod_table_id;
833 /* Enables or disables (according to 'enable') the NXT_FLOW_MOD_TABLE_ID
834 * extension on 'ofconn'. */
836 ofconn_set_flow_mod_table_id(struct ofconn *ofconn, bool enable)
838 ofconn->flow_mod_table_id = enable;
841 /* Returns the default miss send length for 'ofconn'. */
843 ofconn_get_miss_send_len(const struct ofconn *ofconn)
845 return ofconn->miss_send_len;
848 /* Sets the default miss send length for 'ofconn' to 'miss_send_len'. */
850 ofconn_set_miss_send_len(struct ofconn *ofconn, int miss_send_len)
852 ofconn->miss_send_len = miss_send_len;
856 ofconn_set_async_config(struct ofconn *ofconn,
857 const uint32_t master_masks[OAM_N_TYPES],
858 const uint32_t slave_masks[OAM_N_TYPES])
860 size_t size = sizeof ofconn->master_async_config;
861 memcpy(ofconn->master_async_config, master_masks, size);
862 memcpy(ofconn->slave_async_config, slave_masks, size);
865 /* Sends 'msg' on 'ofconn', accounting it as a reply. (If there is a
866 * sufficient number of OpenFlow replies in-flight on a single ofconn, then the
867 * connmgr will stop accepting new OpenFlow requests on that ofconn until the
868 * controller has accepted some of the replies.) */
870 ofconn_send_reply(const struct ofconn *ofconn, struct ofpbuf *msg)
872 ofconn_send(ofconn, msg, ofconn->reply_counter);
875 /* Sends each of the messages in list 'replies' on 'ofconn' in order,
876 * accounting them as replies. */
878 ofconn_send_replies(const struct ofconn *ofconn, struct list *replies)
880 struct ofpbuf *reply, *next;
882 LIST_FOR_EACH_SAFE (reply, next, list_node, replies) {
883 list_remove(&reply->list_node);
884 ofconn_send_reply(ofconn, reply);
888 /* Sends 'error' on 'ofconn', as a reply to 'request'. Only at most the
889 * first 64 bytes of 'request' are used. */
891 ofconn_send_error(const struct ofconn *ofconn,
892 const struct ofp_header *request, enum ofperr error)
894 struct ofpbuf *reply;
896 reply = ofperr_encode_reply(error, request);
898 static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10);
900 if (!VLOG_DROP_INFO(&err_rl)) {
901 const struct ofputil_msg_type *type;
902 const char *type_name;
905 request_len = ntohs(request->length);
906 type_name = (!ofputil_decode_msg_type_partial(request,
907 MIN(64, request_len),
909 ? ofputil_msg_type_name(type)
912 VLOG_INFO("%s: sending %s error reply to %s message",
913 rconn_get_name(ofconn->rconn), ofperr_to_string(error),
916 ofconn_send_reply(ofconn, reply);
920 /* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */
922 ofconn_pktbuf_retrieve(struct ofconn *ofconn, uint32_t id,
923 struct ofpbuf **bufferp, uint16_t *in_port)
925 return pktbuf_retrieve(ofconn->pktbuf, id, bufferp, in_port);
928 /* Returns true if 'ofconn' has any pending opgroups. */
930 ofconn_has_pending_opgroups(const struct ofconn *ofconn)
932 return !list_is_empty(&ofconn->opgroups);
935 /* Adds 'ofconn_node' to 'ofconn''s list of pending opgroups.
937 * If 'ofconn' is destroyed or its connection drops, then 'ofconn' will remove
938 * 'ofconn_node' from the list and re-initialize it with list_init(). The
939 * client may, therefore, use list_is_empty(ofconn_node) to determine whether
940 * 'ofconn_node' is still associated with an active ofconn.
942 * The client may also remove ofconn_node from the list itself, with
945 ofconn_add_opgroup(struct ofconn *ofconn, struct list *ofconn_node)
947 list_push_back(&ofconn->opgroups, ofconn_node);
950 /* Private ofconn functions. */
953 ofconn_get_target(const struct ofconn *ofconn)
955 return rconn_get_target(ofconn->rconn);
958 static struct ofconn *
959 ofconn_create(struct connmgr *mgr, struct rconn *rconn, enum ofconn_type type,
960 bool enable_async_msgs)
962 struct ofconn *ofconn;
964 ofconn = xzalloc(sizeof *ofconn);
965 ofconn->connmgr = mgr;
966 list_push_back(&mgr->all_conns, &ofconn->node);
967 ofconn->rconn = rconn;
969 ofconn->enable_async_msgs = enable_async_msgs;
971 list_init(&ofconn->opgroups);
973 ofconn_flush(ofconn);
978 /* Clears all of the state in 'ofconn' that should not persist from one
979 * connection to the next. */
981 ofconn_flush(struct ofconn *ofconn)
985 ofconn->role = NX_ROLE_OTHER;
986 ofconn->flow_format = NXFF_OPENFLOW10;
987 ofconn->packet_in_format = NXPIF_OPENFLOW10;
988 ofconn->flow_mod_table_id = false;
990 /* Disassociate 'ofconn' from all of the ofopgroups that it initiated that
991 * have not yet completed. (Those ofopgroups will still run to completion
992 * in the usual way, but any errors that they run into will not be reported
993 * on any OpenFlow channel.)
995 * Also discard any blocked operation on 'ofconn'. */
996 while (!list_is_empty(&ofconn->opgroups)) {
997 list_init(list_pop_front(&ofconn->opgroups));
999 ofpbuf_delete(ofconn->blocked);
1000 ofconn->blocked = NULL;
1002 rconn_packet_counter_destroy(ofconn->packet_in_counter);
1003 ofconn->packet_in_counter = rconn_packet_counter_create();
1004 for (i = 0; i < N_SCHEDULERS; i++) {
1005 if (ofconn->schedulers[i]) {
1008 pinsched_get_limits(ofconn->schedulers[i], &rate, &burst);
1009 pinsched_destroy(ofconn->schedulers[i]);
1010 ofconn->schedulers[i] = pinsched_create(rate, burst);
1013 if (ofconn->pktbuf) {
1014 pktbuf_destroy(ofconn->pktbuf);
1015 ofconn->pktbuf = pktbuf_create();
1017 ofconn->miss_send_len = (ofconn->type == OFCONN_PRIMARY
1018 ? OFP_DEFAULT_MISS_SEND_LEN
1021 rconn_packet_counter_destroy(ofconn->reply_counter);
1022 ofconn->reply_counter = rconn_packet_counter_create();
1024 if (ofconn->enable_async_msgs) {
1025 uint32_t *master = ofconn->master_async_config;
1026 uint32_t *slave = ofconn->slave_async_config;
1028 /* "master" and "other" roles get all asynchronous messages by default,
1029 * except that the controller needs to enable nonstandard "packet-in"
1030 * reasons itself. */
1031 master[OAM_PACKET_IN] = (1u << OFPR_NO_MATCH) | (1u << OFPR_ACTION);
1032 master[OAM_PORT_STATUS] = ((1u << OFPPR_ADD)
1033 | (1u << OFPPR_DELETE)
1034 | (1u << OFPPR_MODIFY));
1035 master[OAM_FLOW_REMOVED] = ((1u << OFPRR_IDLE_TIMEOUT)
1036 | (1u << OFPRR_HARD_TIMEOUT)
1037 | (1u << OFPRR_DELETE));
1039 /* "slave" role gets port status updates by default. */
1040 slave[OAM_PACKET_IN] = 0;
1041 slave[OAM_PORT_STATUS] = ((1u << OFPPR_ADD)
1042 | (1u << OFPPR_DELETE)
1043 | (1u << OFPPR_MODIFY));
1044 slave[OAM_FLOW_REMOVED] = 0;
1046 memset(ofconn->master_async_config, 0,
1047 sizeof ofconn->master_async_config);
1048 memset(ofconn->slave_async_config, 0,
1049 sizeof ofconn->slave_async_config);
1054 ofconn_destroy(struct ofconn *ofconn)
1056 ofconn_flush(ofconn);
1058 if (ofconn->type == OFCONN_PRIMARY) {
1059 hmap_remove(&ofconn->connmgr->controllers, &ofconn->hmap_node);
1062 list_remove(&ofconn->node);
1063 rconn_destroy(ofconn->rconn);
1064 rconn_packet_counter_destroy(ofconn->packet_in_counter);
1065 rconn_packet_counter_destroy(ofconn->reply_counter);
1066 pktbuf_destroy(ofconn->pktbuf);
1070 /* Reconfigures 'ofconn' to match 'c'. 'ofconn' and 'c' must have the same
1073 ofconn_reconfigure(struct ofconn *ofconn, const struct ofproto_controller *c)
1077 ofconn->band = c->band;
1078 ofconn->enable_async_msgs = c->enable_async_msgs;
1080 rconn_set_max_backoff(ofconn->rconn, c->max_backoff);
1082 probe_interval = c->probe_interval ? MAX(c->probe_interval, 5) : 0;
1083 rconn_set_probe_interval(ofconn->rconn, probe_interval);
1085 ofconn_set_rate_limit(ofconn, c->rate_limit, c->burst_limit);
1088 /* Returns true if it makes sense for 'ofconn' to receive and process OpenFlow
1091 ofconn_may_recv(const struct ofconn *ofconn)
1093 int count = rconn_packet_counter_read (ofconn->reply_counter);
1094 return (!ofconn->blocked || ofconn->retry) && count < OFCONN_REPLY_MAX;
1098 ofconn_run(struct ofconn *ofconn,
1099 bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
1101 struct connmgr *mgr = ofconn->connmgr;
1104 for (i = 0; i < N_SCHEDULERS; i++) {
1105 pinsched_run(ofconn->schedulers[i], do_send_packet_in, ofconn);
1108 rconn_run(ofconn->rconn);
1110 if (handle_openflow) {
1111 /* Limit the number of iterations to avoid starving other tasks. */
1112 for (i = 0; i < 50 && ofconn_may_recv(ofconn); i++) {
1113 struct ofpbuf *of_msg;
1115 of_msg = (ofconn->blocked
1117 : rconn_recv(ofconn->rconn));
1121 if (mgr->fail_open) {
1122 fail_open_maybe_recover(mgr->fail_open);
1125 if (handle_openflow(ofconn, of_msg)) {
1126 ofpbuf_delete(of_msg);
1127 ofconn->blocked = NULL;
1129 ofconn->blocked = of_msg;
1130 ofconn->retry = false;
1135 if (!rconn_is_alive(ofconn->rconn)) {
1136 ofconn_destroy(ofconn);
1137 } else if (!rconn_is_connected(ofconn->rconn)) {
1138 ofconn_flush(ofconn);
1143 ofconn_wait(struct ofconn *ofconn, bool handling_openflow)
1147 for (i = 0; i < N_SCHEDULERS; i++) {
1148 pinsched_wait(ofconn->schedulers[i]);
1150 rconn_run_wait(ofconn->rconn);
1151 if (handling_openflow && ofconn_may_recv(ofconn)) {
1152 rconn_recv_wait(ofconn->rconn);
1156 /* Returns true if 'ofconn' should receive asynchronous messages of the given
1157 * OAM_* 'type' and 'reason', which should be a OFPR_* value for OAM_PACKET_IN,
1158 * a OFPPR_* value for OAM_PORT_STATUS, or an OFPRR_* value for
1159 * OAM_FLOW_REMOVED. Returns false if the message should not be sent on
1162 ofconn_receives_async_msg(const struct ofconn *ofconn,
1163 enum ofconn_async_msg_type type,
1164 unsigned int reason)
1166 const uint32_t *async_config;
1168 assert(reason < 32);
1169 assert((unsigned int) type < OAM_N_TYPES);
1171 if (!rconn_is_connected(ofconn->rconn)) {
1175 /* Keep the following code in sync with the documentation in the
1176 * "Asynchronous Messages" section in DESIGN. */
1178 if (ofconn->type == OFCONN_SERVICE && !ofconn->miss_send_len) {
1179 /* Service connections don't get asynchronous messages unless they have
1180 * explicitly asked for them by setting a nonzero miss send length. */
1184 async_config = (ofconn->role == NX_ROLE_SLAVE
1185 ? ofconn->slave_async_config
1186 : ofconn->master_async_config);
1187 if (!(async_config[type] & (1u << reason))) {
1194 /* Returns a human-readable name for an OpenFlow connection between 'mgr' and
1195 * 'target', suitable for use in log messages for identifying the connection.
1197 * The name is dynamically allocated. The caller should free it (with free())
1198 * when it is no longer needed. */
1200 ofconn_make_name(const struct connmgr *mgr, const char *target)
1202 return xasprintf("%s<->%s", mgr->name, target);
1206 ofconn_set_rate_limit(struct ofconn *ofconn, int rate, int burst)
1210 for (i = 0; i < N_SCHEDULERS; i++) {
1211 struct pinsched **s = &ofconn->schedulers[i];
1215 *s = pinsched_create(rate, burst);
1217 pinsched_set_limits(*s, rate, burst);
1220 pinsched_destroy(*s);
1227 ofconn_send(const struct ofconn *ofconn, struct ofpbuf *msg,
1228 struct rconn_packet_counter *counter)
1230 update_openflow_length(msg);
1231 if (rconn_send(ofconn->rconn, msg, counter)) {
1236 /* Sending asynchronous messages. */
1238 static void schedule_packet_in(struct ofconn *, struct ofputil_packet_in,
1239 const struct flow *);
1241 /* Sends an OFPT_PORT_STATUS message with 'opp' and 'reason' to appropriate
1242 * controllers managed by 'mgr'. */
1244 connmgr_send_port_status(struct connmgr *mgr, const struct ofp_phy_port *opp,
1247 /* XXX Should limit the number of queued port status change messages. */
1248 struct ofconn *ofconn;
1250 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1251 if (ofconn_receives_async_msg(ofconn, OAM_PORT_STATUS, reason)) {
1252 struct ofp_port_status *ops;
1255 ops = make_openflow_xid(sizeof *ops, OFPT_PORT_STATUS, 0, &b);
1256 ops->reason = reason;
1258 ofconn_send(ofconn, b, NULL);
1263 /* Sends an OFPT_FLOW_REMOVED or NXT_FLOW_REMOVED message based on 'fr' to
1264 * appropriate controllers managed by 'mgr'. */
1266 connmgr_send_flow_removed(struct connmgr *mgr,
1267 const struct ofputil_flow_removed *fr)
1269 struct ofconn *ofconn;
1271 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1272 if (ofconn_receives_async_msg(ofconn, OAM_FLOW_REMOVED, fr->reason)) {
1275 /* Account flow expirations as replies to OpenFlow requests. That
1276 * works because preventing OpenFlow requests from being processed
1277 * also prevents new flows from being added (and expiring). (It
1278 * also prevents processing OpenFlow requests that would not add
1279 * new flows, so it is imperfect.) */
1280 msg = ofputil_encode_flow_removed(fr, ofconn->flow_format);
1281 ofconn_send_reply(ofconn, msg);
1286 /* Given 'pin', sends an OFPT_PACKET_IN message to each OpenFlow controller as
1287 * necessary according to their individual configurations. */
1289 connmgr_send_packet_in(struct connmgr *mgr,
1290 const struct ofputil_packet_in *pin,
1291 const struct flow *flow)
1293 struct ofconn *ofconn;
1295 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1296 if (ofconn_receives_async_msg(ofconn, OAM_PACKET_IN, pin->reason)) {
1297 schedule_packet_in(ofconn, *pin, flow);
1302 /* pinsched callback for sending 'ofp_packet_in' on 'ofconn'. */
1304 do_send_packet_in(struct ofpbuf *ofp_packet_in, void *ofconn_)
1306 struct ofconn *ofconn = ofconn_;
1308 rconn_send_with_limit(ofconn->rconn, ofp_packet_in,
1309 ofconn->packet_in_counter, 100);
1312 /* Takes 'pin', whose packet has the flow specified by 'flow', composes an
1313 * OpenFlow packet-in message from it, and passes it to 'ofconn''s packet
1314 * scheduler for sending. */
1316 schedule_packet_in(struct ofconn *ofconn, struct ofputil_packet_in pin,
1317 const struct flow *flow)
1319 struct connmgr *mgr = ofconn->connmgr;
1321 /* Get OpenFlow buffer_id. */
1322 if (pin.reason == OFPR_ACTION) {
1323 pin.buffer_id = UINT32_MAX;
1324 } else if (mgr->fail_open && fail_open_is_active(mgr->fail_open)) {
1325 pin.buffer_id = pktbuf_get_null();
1326 } else if (!ofconn->pktbuf) {
1327 pin.buffer_id = UINT32_MAX;
1329 pin.buffer_id = pktbuf_save(ofconn->pktbuf, pin.packet, pin.packet_len,
1333 /* Figure out how much of the packet to send. */
1334 if (pin.reason == OFPR_NO_MATCH) {
1335 pin.send_len = pin.packet_len;
1337 /* Caller should have initialized 'send_len' to 'max_len' specified in
1338 * struct ofp_action_output. */
1340 if (pin.buffer_id != UINT32_MAX) {
1341 pin.send_len = MIN(pin.send_len, ofconn->miss_send_len);
1344 /* Make OFPT_PACKET_IN and hand over to packet scheduler. It might
1345 * immediately call into do_send_packet_in() or it might buffer it for a
1346 * while (until a later call to pinsched_run()). */
1347 pinsched_send(ofconn->schedulers[pin.reason == OFPR_NO_MATCH ? 0 : 1],
1349 ofputil_encode_packet_in(&pin, ofconn->packet_in_format),
1350 do_send_packet_in, ofconn);
1353 /* Fail-open settings. */
1355 /* Returns the failure handling mode (OFPROTO_FAIL_SECURE or
1356 * OFPROTO_FAIL_STANDALONE) for 'mgr'. */
1357 enum ofproto_fail_mode
1358 connmgr_get_fail_mode(const struct connmgr *mgr)
1360 return mgr->fail_mode;
1363 /* Sets the failure handling mode for 'mgr' to 'fail_mode' (either
1364 * OFPROTO_FAIL_SECURE or OFPROTO_FAIL_STANDALONE). */
1366 connmgr_set_fail_mode(struct connmgr *mgr, enum ofproto_fail_mode fail_mode)
1368 if (mgr->fail_mode != fail_mode) {
1369 mgr->fail_mode = fail_mode;
1370 update_fail_open(mgr);
1371 if (!connmgr_has_controllers(mgr)) {
1372 ofproto_flush_flows(mgr->ofproto);
1377 /* Fail-open implementation. */
1379 /* Returns the longest probe interval among the primary controllers configured
1380 * on 'mgr'. Returns 0 if there are no primary controllers. */
1382 connmgr_get_max_probe_interval(const struct connmgr *mgr)
1384 const struct ofconn *ofconn;
1385 int max_probe_interval;
1387 max_probe_interval = 0;
1388 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1389 int probe_interval = rconn_get_probe_interval(ofconn->rconn);
1390 max_probe_interval = MAX(max_probe_interval, probe_interval);
1392 return max_probe_interval;
1395 /* Returns the number of seconds for which all of 'mgr's primary controllers
1396 * have been disconnected. Returns 0 if 'mgr' has no primary controllers. */
1398 connmgr_failure_duration(const struct connmgr *mgr)
1400 const struct ofconn *ofconn;
1401 int min_failure_duration;
1403 if (!connmgr_has_controllers(mgr)) {
1407 min_failure_duration = INT_MAX;
1408 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1409 int failure_duration = rconn_failure_duration(ofconn->rconn);
1410 min_failure_duration = MIN(min_failure_duration, failure_duration);
1412 return min_failure_duration;
1415 /* Returns true if at least one primary controller is connected (regardless of
1416 * whether those controllers are believed to have authenticated and accepted
1417 * this switch), false if none of them are connected. */
1419 connmgr_is_any_controller_connected(const struct connmgr *mgr)
1421 const struct ofconn *ofconn;
1423 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1424 if (rconn_is_connected(ofconn->rconn)) {
1431 /* Returns true if at least one primary controller is believed to have
1432 * authenticated and accepted this switch, false otherwise. */
1434 connmgr_is_any_controller_admitted(const struct connmgr *mgr)
1436 const struct ofconn *ofconn;
1438 HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
1439 if (rconn_is_admitted(ofconn->rconn)) {
1446 /* Sends 'packet' to each controller connected to 'mgr'. Takes ownership of
1449 connmgr_broadcast(struct connmgr *mgr, struct ofpbuf *packet)
1451 struct ofconn *ofconn, *prev;
1454 LIST_FOR_EACH (ofconn, node, &mgr->all_conns) {
1456 ofconn_send_reply(ofconn, ofpbuf_clone(packet));
1458 if (rconn_is_connected(ofconn->rconn)) {
1463 ofconn_send_reply(prev, packet);
1465 ofpbuf_delete(packet);
1469 /* In-band configuration. */
1471 static bool any_extras_changed(const struct connmgr *,
1472 const struct sockaddr_in *extras, size_t n);
1474 /* Sets the 'n' TCP port addresses in 'extras' as ones to which 'mgr''s
1475 * in-band control should guarantee access, in the same way that in-band
1476 * control guarantees access to OpenFlow controllers. */
1478 connmgr_set_extra_in_band_remotes(struct connmgr *mgr,
1479 const struct sockaddr_in *extras, size_t n)
1481 if (!any_extras_changed(mgr, extras, n)) {
1485 free(mgr->extra_in_band_remotes);
1486 mgr->n_extra_remotes = n;
1487 mgr->extra_in_band_remotes = xmemdup(extras, n * sizeof *extras);
1489 update_in_band_remotes(mgr);
1492 /* Sets the OpenFlow queue used by flows set up by in-band control on
1493 * 'mgr' to 'queue_id'. If 'queue_id' is negative, then in-band control
1494 * flows will use the default queue. */
1496 connmgr_set_in_band_queue(struct connmgr *mgr, int queue_id)
1498 if (queue_id != mgr->in_band_queue) {
1499 mgr->in_band_queue = queue_id;
1500 update_in_band_remotes(mgr);
1505 any_extras_changed(const struct connmgr *mgr,
1506 const struct sockaddr_in *extras, size_t n)
1510 if (n != mgr->n_extra_remotes) {
1514 for (i = 0; i < n; i++) {
1515 const struct sockaddr_in *old = &mgr->extra_in_band_remotes[i];
1516 const struct sockaddr_in *new = &extras[i];
1518 if (old->sin_addr.s_addr != new->sin_addr.s_addr ||
1519 old->sin_port != new->sin_port) {
1527 /* In-band implementation. */
1530 connmgr_msg_in_hook(struct connmgr *mgr, const struct flow *flow,
1531 const struct ofpbuf *packet)
1533 return mgr->in_band && in_band_msg_in_hook(mgr->in_band, flow, packet);
1537 connmgr_may_set_up_flow(struct connmgr *mgr, const struct flow *flow,
1538 const struct nlattr *odp_actions,
1541 return !mgr->in_band || in_band_rule_check(flow, odp_actions, actions_len);
1544 /* Fail-open and in-band implementation. */
1546 /* Called by 'ofproto' after all flows have been flushed, to allow fail-open
1547 * and standalone mode to re-create their flows.
1549 * In-band control has more sophisticated code that manages flows itself. */
1551 connmgr_flushed(struct connmgr *mgr)
1553 if (mgr->fail_open) {
1554 fail_open_flushed(mgr->fail_open);
1557 /* If there are no controllers and we're in standalone mode, set up a flow
1558 * that matches every packet and directs them to OFPP_NORMAL (which goes to
1559 * us). Otherwise, the switch is in secure mode and we won't pass any
1560 * traffic until a controller has been defined and it tells us to do so. */
1561 if (!connmgr_has_controllers(mgr)
1562 && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
1563 union ofp_action action;
1564 struct cls_rule rule;
1566 memset(&action, 0, sizeof action);
1567 action.type = htons(OFPAT_OUTPUT);
1568 action.output.len = htons(sizeof action);
1569 action.output.port = htons(OFPP_NORMAL);
1570 cls_rule_init_catchall(&rule, 0);
1571 ofproto_add_flow(mgr->ofproto, &rule, &action, 1);
1575 /* Creates a new ofservice for 'target' in 'mgr'. Returns 0 if successful,
1576 * otherwise a positive errno value.
1578 * ofservice_reconfigure() must be called to fully configure the new
1581 ofservice_create(struct connmgr *mgr, const char *target)
1583 struct ofservice *ofservice;
1584 struct pvconn *pvconn;
1587 error = pvconn_open(target, &pvconn);
1592 ofservice = xzalloc(sizeof *ofservice);
1593 hmap_insert(&mgr->services, &ofservice->node, hash_string(target, 0));
1594 ofservice->pvconn = pvconn;
1600 ofservice_destroy(struct connmgr *mgr, struct ofservice *ofservice)
1602 hmap_remove(&mgr->services, &ofservice->node);
1603 pvconn_close(ofservice->pvconn);
1608 ofservice_reconfigure(struct ofservice *ofservice,
1609 const struct ofproto_controller *c)
1611 ofservice->probe_interval = c->probe_interval;
1612 ofservice->rate_limit = c->rate_limit;
1613 ofservice->burst_limit = c->burst_limit;
1614 ofservice->enable_async_msgs = c->enable_async_msgs;
1617 /* Finds and returns the ofservice within 'mgr' that has the given
1618 * 'target', or a null pointer if none exists. */
1619 static struct ofservice *
1620 ofservice_lookup(struct connmgr *mgr, const char *target)
1622 struct ofservice *ofservice;
1624 HMAP_FOR_EACH_WITH_HASH (ofservice, node, hash_string(target, 0),
1626 if (!strcmp(pvconn_get_name(ofservice->pvconn), target)) {