-/* Creates a new controller in 'ofproto'. Some of the settings are initially
- * drawn from 'c', but update_controller() needs to be called later to finish
- * the new ofconn's configuration. */
-static void
-add_controller(struct ofproto *ofproto, const struct ofproto_controller *c)
-{
- char *name = ofconn_make_name(ofproto, c->target);
- struct ofconn *ofconn;
-
- ofconn = ofconn_create(ofproto, rconn_create(5, 8), OFCONN_PRIMARY);
- ofconn->pktbuf = pktbuf_create();
- ofconn->miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
- rconn_connect(ofconn->rconn, c->target, name);
- hmap_insert(&ofproto->controllers, &ofconn->hmap_node,
- hash_string(c->target, 0));
-
- free(name);
-}
-
-/* Reconfigures 'ofconn' to match 'c'. This function cannot update an ofconn's
- * target (this is done by creating new ofconns and deleting old ones), but it
- * can update the rest of an ofconn's settings. */
-static void
-update_controller(struct ofconn *ofconn, const struct ofproto_controller *c)
-{
- int probe_interval;
-
- ofconn->band = c->band;
-
- rconn_set_max_backoff(ofconn->rconn, c->max_backoff);
-
- probe_interval = c->probe_interval ? MAX(c->probe_interval, 5) : 0;
- rconn_set_probe_interval(ofconn->rconn, probe_interval);
-
- ofconn_set_rate_limit(ofconn, c->rate_limit, c->burst_limit);
-}
-
-static const char *
-ofconn_get_target(const struct ofconn *ofconn)
-{
- return rconn_get_target(ofconn->rconn);
-}
-
-static struct ofconn *
-find_controller_by_target(struct ofproto *ofproto, const char *target)
-{
- struct ofconn *ofconn;
-
- HMAP_FOR_EACH_WITH_HASH (ofconn, hmap_node,
- hash_string(target, 0), &ofproto->controllers) {
- if (!strcmp(ofconn_get_target(ofconn), target)) {
- return ofconn;
- }
- }
- return NULL;
-}
-
-static void
-update_in_band_remotes(struct ofproto *ofproto)
-{
- const struct ofconn *ofconn;
- struct sockaddr_in *addrs;
- size_t max_addrs, n_addrs;
- size_t i;
-
- /* Allocate enough memory for as many remotes as we could possibly have. */
- max_addrs = ofproto->n_extra_remotes + hmap_count(&ofproto->controllers);
- addrs = xmalloc(max_addrs * sizeof *addrs);
- n_addrs = 0;
-
- /* Add all the remotes. */
- HMAP_FOR_EACH (ofconn, hmap_node, &ofproto->controllers) {
- struct sockaddr_in *sin = &addrs[n_addrs];
-
- if (ofconn->band == OFPROTO_OUT_OF_BAND) {
- continue;
- }
-
- sin->sin_addr.s_addr = rconn_get_remote_ip(ofconn->rconn);
- if (sin->sin_addr.s_addr) {
- sin->sin_port = rconn_get_remote_port(ofconn->rconn);
- n_addrs++;
- }
- }
- for (i = 0; i < ofproto->n_extra_remotes; i++) {
- addrs[n_addrs++] = ofproto->extra_in_band_remotes[i];
- }
-
- /* Create or update or destroy in-band. */
- if (n_addrs) {
- if (!ofproto->in_band) {
- in_band_create(ofproto, ofproto->dpif, &ofproto->in_band);
- }
- if (ofproto->in_band) {
- in_band_set_remotes(ofproto->in_band, addrs, n_addrs);
- }
- in_band_set_queue(ofproto->in_band, ofproto->in_band_queue);
- ofproto->next_in_band_update = time_msec() + 1000;
- } else {
- in_band_destroy(ofproto->in_band);
- ofproto->in_band = NULL;
- }
-
- /* Clean up. */
- free(addrs);
-}
-
-static void
-update_fail_open(struct ofproto *p)
-{
- struct ofconn *ofconn;
-
- if (!hmap_is_empty(&p->controllers)
- && p->fail_mode == OFPROTO_FAIL_STANDALONE) {
- struct rconn **rconns;
- size_t n;
-
- if (!p->fail_open) {
- p->fail_open = fail_open_create(p);
- }
-
- n = 0;
- rconns = xmalloc(hmap_count(&p->controllers) * sizeof *rconns);
- HMAP_FOR_EACH (ofconn, hmap_node, &p->controllers) {
- rconns[n++] = ofconn->rconn;
- }
-
- fail_open_set_controllers(p->fail_open, rconns, n);
- /* p->fail_open takes ownership of 'rconns'. */
- } else {
- fail_open_destroy(p->fail_open);
- p->fail_open = NULL;
- }
-}
-