~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to ofproto/connmgr.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
/* State that should be cleared from one connection to the next. */
61
61
 
62
62
    /* OpenFlow state. */
63
 
    enum nx_role role;           /* Role. */
 
63
    enum ofp12_controller_role role;           /* Role. */
64
64
    enum ofputil_protocol protocol; /* Current protocol variant. */
65
65
    enum nx_packet_in_format packet_in_format; /* OFPT_PACKET_IN format. */
66
66
 
108
108
 
109
109
static void ofconn_run(struct ofconn *,
110
110
                       bool (*handle_openflow)(struct ofconn *,
111
 
                                               struct ofpbuf *ofp_msg));
 
111
                                               const struct ofpbuf *ofp_msg));
112
112
static void ofconn_wait(struct ofconn *, bool handling_openflow);
113
113
 
114
114
static const char *ofconn_get_target(const struct ofconn *);
269
269
 * fail-open processing) are suppressed too. */
270
270
void
271
271
connmgr_run(struct connmgr *mgr,
272
 
            bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
 
272
            bool (*handle_openflow)(struct ofconn *,
 
273
                                    const struct ofpbuf *ofp_msg))
273
274
{
274
275
    struct ofconn *ofconn, *next_ofconn;
275
276
    struct ofservice *ofservice;
314
315
            ofconn_set_rate_limit(ofconn, ofservice->rate_limit,
315
316
                                  ofservice->burst_limit);
316
317
        } else if (retval != EAGAIN) {
317
 
            VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
 
318
            VLOG_WARN_RL(&rl, "accept failed (%s)", ovs_strerror(retval));
318
319
        }
319
320
    }
320
321
 
326
327
        if (!retval) {
327
328
            add_snooper(mgr, vconn);
328
329
        } else if (retval != EAGAIN) {
329
 
            VLOG_WARN_RL(&rl, "accept failed (%s)", strerror(retval));
 
330
            VLOG_WARN_RL(&rl, "accept failed (%s)", ovs_strerror(retval));
330
331
        }
331
332
    }
332
333
}
757
758
        if (!error) {
758
759
            pvconns[n_pvconns++] = pvconn;
759
760
        } else {
760
 
            VLOG_ERR("failed to listen on %s: %s", name, strerror(error));
 
761
            VLOG_ERR("failed to listen on %s: %s", name, ovs_strerror(error));
761
762
            if (!retval) {
762
763
                retval = error;
763
764
            }
777
778
snoop_preference(const struct ofconn *ofconn)
778
779
{
779
780
    switch (ofconn->role) {
780
 
    case NX_ROLE_MASTER:
 
781
    case OFPCR12_ROLE_MASTER:
781
782
        return 3;
782
 
    case NX_ROLE_OTHER:
 
783
    case OFPCR12_ROLE_EQUAL:
783
784
        return 2;
784
 
    case NX_ROLE_SLAVE:
 
785
    case OFPCR12_ROLE_SLAVE:
785
786
        return 1;
 
787
    case OFPCR12_ROLE_NOCHANGE:
786
788
    default:
787
789
        /* Shouldn't happen. */
788
790
        return 0;
822
824
    return ofconn->type;
823
825
}
824
826
 
 
827
/* If a master election id is defined, stores it into '*idp' and returns
 
828
 * true.  Otherwise, stores UINT64_MAX into '*idp' and returns false. */
 
829
bool
 
830
ofconn_get_master_election_id(const struct ofconn *ofconn, uint64_t *idp)
 
831
{
 
832
    *idp = (ofconn->connmgr->master_election_id_defined
 
833
            ? ofconn->connmgr->master_election_id
 
834
            : UINT64_MAX);
 
835
    return ofconn->connmgr->master_election_id_defined;
 
836
}
 
837
 
825
838
/* Sets the master election id.
826
839
 *
827
840
 * Returns true if successful, false if the id is stale
844
857
 
845
858
/* Returns the role configured for 'ofconn'.
846
859
 *
847
 
 * The default role, if no other role has been set, is NX_ROLE_OTHER. */
848
 
enum nx_role
 
860
 * The default role, if no other role has been set, is OFPCR12_ROLE_EQUAL. */
 
861
enum ofp12_controller_role
849
862
ofconn_get_role(const struct ofconn *ofconn)
850
863
{
851
864
    return ofconn->role;
852
865
}
853
866
 
854
 
/* Changes 'ofconn''s role to 'role'.  If 'role' is NX_ROLE_MASTER then any
855
 
 * existing master is demoted to a slave. */
 
867
/* Changes 'ofconn''s role to 'role'.  If 'role' is OFPCR12_ROLE_MASTER then
 
868
 * any existing master is demoted to a slave. */
856
869
void
857
 
ofconn_set_role(struct ofconn *ofconn, enum nx_role role)
 
870
ofconn_set_role(struct ofconn *ofconn, enum ofp12_controller_role role)
858
871
{
859
 
    if (role == NX_ROLE_MASTER) {
 
872
    if (role == OFPCR12_ROLE_MASTER) {
860
873
        struct ofconn *other;
861
874
 
862
875
        HMAP_FOR_EACH (other, hmap_node, &ofconn->connmgr->controllers) {
863
 
            if (other->role == NX_ROLE_MASTER) {
864
 
                other->role = NX_ROLE_SLAVE;
 
876
            if (other->role == OFPCR12_ROLE_MASTER) {
 
877
                other->role = OFPCR12_ROLE_SLAVE;
865
878
            }
866
879
        }
867
880
    }
1026
1039
/* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */
1027
1040
enum ofperr
1028
1041
ofconn_pktbuf_retrieve(struct ofconn *ofconn, uint32_t id,
1029
 
                       struct ofpbuf **bufferp, uint16_t *in_port)
 
1042
                       struct ofpbuf **bufferp, ofp_port_t *in_port)
1030
1043
{
1031
1044
    return pktbuf_retrieve(ofconn->pktbuf, id, bufferp, in_port);
1032
1045
}
1092
1105
    struct ofmonitor *monitor, *next_monitor;
1093
1106
    int i;
1094
1107
 
1095
 
    ofconn->role = NX_ROLE_OTHER;
 
1108
    ofconn->role = OFPCR12_ROLE_EQUAL;
1096
1109
    ofconn_set_protocol(ofconn, OFPUTIL_P_NONE);
1097
1110
    ofconn->packet_in_format = NXPIF_OPENFLOW10;
1098
1111
 
1222
1235
 
1223
1236
static void
1224
1237
ofconn_run(struct ofconn *ofconn,
1225
 
           bool (*handle_openflow)(struct ofconn *, struct ofpbuf *ofp_msg))
 
1238
           bool (*handle_openflow)(struct ofconn *,
 
1239
                                   const struct ofpbuf *ofp_msg))
1226
1240
{
1227
1241
    struct connmgr *mgr = ofconn->connmgr;
1228
1242
    size_t i;
1308
1322
        return false;
1309
1323
    }
1310
1324
 
1311
 
    async_config = (ofconn->role == NX_ROLE_SLAVE
 
1325
    async_config = (ofconn->role == OFPCR12_ROLE_SLAVE
1312
1326
                    ? ofconn->slave_async_config
1313
1327
                    : ofconn->master_async_config);
1314
1328
    if (!(async_config[type] & (1u << reason))) {
1631
1645
/* In-band implementation. */
1632
1646
 
1633
1647
bool
1634
 
connmgr_msg_in_hook(struct connmgr *mgr, const struct flow *flow,
1635
 
                    const struct ofpbuf *packet)
1636
 
{
1637
 
    return mgr->in_band && in_band_msg_in_hook(mgr->in_band, flow, packet);
1638
 
}
1639
 
 
1640
 
bool
1641
 
connmgr_may_set_up_flow(struct connmgr *mgr, const struct flow *flow,
1642
 
                        uint32_t local_odp_port,
1643
 
                        const struct nlattr *odp_actions,
1644
 
                        size_t actions_len)
1645
 
{
1646
 
    return !mgr->in_band || in_band_rule_check(flow, local_odp_port,
1647
 
                                               odp_actions, actions_len);
 
1648
connmgr_has_in_band(struct connmgr *mgr)
 
1649
{
 
1650
    return mgr->in_band != NULL;
1648
1651
}
1649
1652
 
1650
1653
/* Fail-open and in-band implementation. */