-static struct ofconn *
-ofconn_create(struct ofproto *p, struct rconn *rconn, enum ofconn_type type)
-{
- struct ofconn *ofconn = xzalloc(sizeof *ofconn);
- ofconn->ofproto = p;
- list_push_back(&p->all_conns, &ofconn->node);
- ofconn->rconn = rconn;
- ofconn->type = type;
- ofconn->flow_format = NXFF_OPENFLOW10;
- ofconn->role = NX_ROLE_OTHER;
- ofconn->packet_in_counter = rconn_packet_counter_create ();
- ofconn->pktbuf = NULL;
- ofconn->miss_send_len = 0;
- ofconn->reply_counter = rconn_packet_counter_create ();
- return ofconn;
-}
-
-static void
-ofconn_destroy(struct ofconn *ofconn)
-{
- struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
-
- if (ofconn->type == OFCONN_PRIMARY) {
- hmap_remove(&ofproto->controllers, &ofconn->hmap_node);
- }
-
- list_remove(&ofconn->node);
- rconn_destroy(ofconn->rconn);
- rconn_packet_counter_destroy(ofconn->packet_in_counter);
- rconn_packet_counter_destroy(ofconn->reply_counter);
- pktbuf_destroy(ofconn->pktbuf);
- free(ofconn);
-}
-
-static void
-ofconn_run(struct ofconn *ofconn)
-{
- struct ofproto *p = ofconn_get_ofproto(ofconn);
- int iteration;
- size_t i;
-
- for (i = 0; i < N_SCHEDULERS; i++) {
- pinsched_run(ofconn->schedulers[i], do_send_packet_in, ofconn);
- }
-
- rconn_run(ofconn->rconn);
-
- if (rconn_packet_counter_read (ofconn->reply_counter) < OFCONN_REPLY_MAX) {
- /* Limit the number of iterations to prevent other tasks from
- * starving. */
- for (iteration = 0; iteration < 50; iteration++) {
- struct ofpbuf *of_msg = rconn_recv(ofconn->rconn);
- if (!of_msg) {
- break;
- }
- if (p->fail_open) {
- fail_open_maybe_recover(p->fail_open);
- }
- handle_openflow(ofconn, of_msg);
- ofpbuf_delete(of_msg);
- }
- }
-
- if (!rconn_is_alive(ofconn->rconn)) {
- ofconn_destroy(ofconn);
- }
-}
-
-static void
-ofconn_wait(struct ofconn *ofconn)
-{
- int i;
-
- for (i = 0; i < N_SCHEDULERS; i++) {
- pinsched_wait(ofconn->schedulers[i]);
- }
- rconn_run_wait(ofconn->rconn);
- if (rconn_packet_counter_read (ofconn->reply_counter) < OFCONN_REPLY_MAX) {
- rconn_recv_wait(ofconn->rconn);
- } else {
- COVERAGE_INC(ofproto_ofconn_stuck);
- }
-}
-
-/* Returns true if 'ofconn' should receive asynchronous messages. */
-static bool
-ofconn_receives_async_msgs(const struct ofconn *ofconn)
-{
- if (ofconn->type == OFCONN_PRIMARY) {
- /* Primary controllers always get asynchronous messages unless they
- * have configured themselves as "slaves". */
- return ofconn->role != NX_ROLE_SLAVE;
- } else {
- /* Service connections don't get asynchronous messages unless they have
- * explicitly asked for them by setting a nonzero miss send length. */
- return ofconn->miss_send_len > 0;
- }
-}
-
-/* Returns a human-readable name for an OpenFlow connection between 'ofproto'
- * and 'target', suitable for use in log messages for identifying the
- * connection.
- *
- * The name is dynamically allocated. The caller should free it (with free())
- * when it is no longer needed. */
-static char *
-ofconn_make_name(const struct ofproto *ofproto, const char *target)
-{
- return xasprintf("%s<->%s", dpif_base_name(ofproto->dpif), target);
-}
-
-static void
-ofconn_set_rate_limit(struct ofconn *ofconn, int rate, int burst)
-{
- int i;
-
- for (i = 0; i < N_SCHEDULERS; i++) {
- struct pinsched **s = &ofconn->schedulers[i];
-
- if (rate > 0) {
- if (!*s) {
- *s = pinsched_create(rate, burst);
- } else {
- pinsched_set_limits(*s, rate, burst);
- }
- } else {
- pinsched_destroy(*s);
- *s = NULL;
- }
- }
-}
-
-static struct ofproto *
-ofconn_get_ofproto(struct ofconn *ofconn)
-{
- return ofconn->ofproto;
-}
-\f
-static void
-ofservice_reconfigure(struct ofservice *ofservice,
- const struct ofproto_controller *c)
-{
- ofservice->probe_interval = c->probe_interval;
- ofservice->rate_limit = c->rate_limit;
- ofservice->burst_limit = c->burst_limit;
-}
-
-/* Creates a new ofservice in 'ofproto'. Returns 0 if successful, otherwise a
- * positive errno value. */
-static int
-ofservice_create(struct ofproto *ofproto, const struct ofproto_controller *c)
-{
- struct ofservice *ofservice;
- struct pvconn *pvconn;
- int error;
-
- error = pvconn_open(c->target, &pvconn);
- if (error) {
- return error;
- }
-
- ofservice = xzalloc(sizeof *ofservice);
- hmap_insert(&ofproto->services, &ofservice->node,
- hash_string(c->target, 0));
- ofservice->pvconn = pvconn;
-
- ofservice_reconfigure(ofservice, c);
-
- return 0;
-}
-
-static void
-ofservice_destroy(struct ofproto *ofproto, struct ofservice *ofservice)
-{
- hmap_remove(&ofproto->services, &ofservice->node);
- pvconn_close(ofservice->pvconn);
- free(ofservice);
-}
-
-/* Finds and returns the ofservice within 'ofproto' that has the given
- * 'target', or a null pointer if none exists. */
-static struct ofservice *
-ofservice_lookup(struct ofproto *ofproto, const char *target)
-{
- struct ofservice *ofservice;
-
- HMAP_FOR_EACH_WITH_HASH (ofservice, node, hash_string(target, 0),
- &ofproto->services) {
- if (!strcmp(pvconn_get_name(ofservice->pvconn), target)) {
- return ofservice;
- }
- }
- return NULL;
-}
-\f