コード例 #1
0
ファイル: learning-switch.c プロジェクト: exuuwen/study
static void
lswitch_handshake(struct lswitch *sw)
{
    enum ofputil_protocol protocol;
    enum ofp_version version;

    send_features_request(sw);

	send_controller_id(sw);

    version = rconn_get_version(sw->rconn);
    protocol = ofputil_protocol_from_ofp_version(version);
    
    if (sw->default_flows) {
        struct ofpbuf *msg = NULL;
        int error = 0;
        size_t i;

        if (!(protocol & sw->usable_protocols)) {
            enum ofputil_protocol want = rightmost_1bit(sw->usable_protocols);
            while (!error) {
                msg = ofputil_encode_set_protocol(protocol, want, &protocol);
                if (!msg) {
                    break;
                }
                error = rconn_send(sw->rconn, msg, NULL);
            }
        }
        if (protocol & sw->usable_protocols) {
            for (i = 0; !error && i < sw->n_default_flows; i++) {
                msg = ofputil_encode_flow_mod(&sw->default_flows[i], protocol);
                error = rconn_send(sw->rconn, msg, NULL);
            }

            if (error) {
                VLOG_INFO_RL(&rl, "%s: failed to queue default flows (%s)",
                             rconn_get_name(sw->rconn), ovs_strerror(error));
            }
        } else {
            VLOG_INFO_RL(&rl, "%s: failed to set usable protocol",
                         rconn_get_name(sw->rconn));
        }
    }
    sw->protocol = protocol;
}
コード例 #2
0
ファイル: FlowExecutor.cpp プロジェクト: opendaylight/opflex
OfpBuf
FlowExecutor::EncodeMod<FlowEdit::Entry>(const FlowEdit::Entry& edit,
                                         int ofVersion) {
    ofputil_protocol proto =
        ofputil_protocol_from_ofp_version((ofp_version)ofVersion);
    assert(ofputil_protocol_is_valid(proto));

    FlowEdit::type mod = edit.first;
    ofputil_flow_stats& flow = *(edit.second->entry);

    ofputil_flow_mod flowMod;
    memset(&flowMod, 0, sizeof(flowMod));
    flowMod.table_id = flow.table_id;
    flowMod.priority = flow.priority;
    if (mod != FlowEdit::ADD) {
        flowMod.cookie = flow.cookie;
        flowMod.cookie_mask = ~((uint64_t)0);
    }
    flowMod.new_cookie = mod == FlowEdit::MOD ? OVS_BE64_MAX :
            (mod == FlowEdit::ADD ? flow.cookie : 0);
    memcpy(&flowMod.match, &flow.match, sizeof(flow.match));
    if (mod != FlowEdit::DEL) {
        flowMod.ofpacts_len = flow.ofpacts_len;
        flowMod.ofpacts = (ofpact*)flow.ofpacts;
    }
    flowMod.command = mod == FlowEdit::ADD ? OFPFC_ADD :
            (mod == FlowEdit::MOD ? OFPFC_MODIFY_STRICT : OFPFC_DELETE_STRICT);
    /* fill out defaults */
    flowMod.modify_cookie = false;
    flowMod.idle_timeout = OFP_FLOW_PERMANENT;
    flowMod.hard_timeout = OFP_FLOW_PERMANENT;
    flowMod.buffer_id = UINT32_MAX;
    flowMod.out_port = OFPP_NONE;
    flowMod.out_group = OFPG_ANY;
    flowMod.flags = (ofputil_flow_mod_flags)0;
    if (flow.flags)
        flowMod.flags = flow.flags;

    return OfpBuf(ofputil_encode_flow_mod(&flowMod, proto));
}