- struct ofconn *ofconn, *next_ofconn;
- struct ofservice *ofservice;
- char *devname;
- int error;
- int i;
-
- if (shash_is_empty(&p->port_by_name)) {
- init_ports(p);
- }
-
- for (i = 0; i < 50; i++) {
- struct ofpbuf *buf;
-
- error = dpif_recv(p->dpif, &buf);
- if (error) {
- if (error == ENODEV) {
- /* Someone destroyed the datapath behind our back. The caller
- * better destroy us and give up, because we're just going to
- * spin from here on out. */
- static struct vlog_rate_limit rl2 = VLOG_RATE_LIMIT_INIT(1, 5);
- VLOG_ERR_RL(&rl2, "%s: datapath was destroyed externally",
- dpif_name(p->dpif));
- return ENODEV;
- }
- break;
- }
-
- handle_odp_msg(p, buf);
- }
-
- while ((error = dpif_port_poll(p->dpif, &devname)) != EAGAIN) {
- process_port_change(p, error, devname);
- }
- while ((error = netdev_monitor_poll(p->netdev_monitor,
- &devname)) != EAGAIN) {
- process_port_change(p, error, devname);
- }
-
- if (p->in_band) {
- if (time_msec() >= p->next_in_band_update) {
- update_in_band_remotes(p);
- }
- in_band_run(p->in_band);
- }
-
- LIST_FOR_EACH_SAFE (ofconn, next_ofconn, node, &p->all_conns) {
- ofconn_run(ofconn, p);
- }
-
- /* Fail-open maintenance. Do this after processing the ofconns since
- * fail-open checks the status of the controller rconn. */
- if (p->fail_open) {
- fail_open_run(p->fail_open);
- }
-
- HMAP_FOR_EACH (ofservice, node, &p->services) {
- struct vconn *vconn;
- int retval;
-
- retval = pvconn_accept(ofservice->pvconn, OFP_VERSION, &vconn);
- if (!retval) {
- struct rconn *rconn;
- char *name;
-
- rconn = rconn_create(ofservice->probe_interval, 0);
- name = ofconn_make_name(p, vconn_get_name(vconn));
- rconn_connect_unreliably(rconn, vconn, name);
- free(name);
-
- ofconn = ofconn_create(p, rconn, OFCONN_SERVICE);
- ofconn_set_rate_limit(ofconn, ofservice->rate_limit,
- ofservice->burst_limit);
- } else if (retval != EAGAIN) {
- VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
- }
- }
-
- for (i = 0; i < p->n_snoops; i++) {
- struct vconn *vconn;
- int retval;
-
- retval = pvconn_accept(p->snoops[i], OFP_VERSION, &vconn);
- if (!retval) {
- add_snooper(p, vconn);
- } else if (retval != EAGAIN) {
- VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
- }
- }
-
- if (time_msec() >= p->next_expiration) {
- int delay = ofproto_expire(p);
- p->next_expiration = time_msec() + delay;
- COVERAGE_INC(ofproto_expiration);
- }
-
- if (p->netflow) {
- netflow_run(p->netflow);
- }
- if (p->sflow) {
- ofproto_sflow_run(p->sflow);
- }
-
- return 0;