/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/* OpenFlow 1.3 and later by default drop packets that miss in the flow
* table. Set up a flow to send packets to the controller by
* default. */
- struct ofputil_flow_mod fm;
struct ofpact_output output;
struct ofpbuf *msg;
int error;
output.port = OFPP_CONTROLLER;
output.max_len = OFP_DEFAULT_MISS_SEND_LEN;
- match_init_catchall(&fm.match);
- fm.priority = 0;
- fm.cookie = 0;
- fm.cookie_mask = 0;
- fm.new_cookie = 0;
- fm.modify_cookie = false;
- fm.table_id = 0;
- fm.command = OFPFC_ADD;
- fm.idle_timeout = 0;
- fm.hard_timeout = 0;
- fm.importance = 0;
- fm.buffer_id = UINT32_MAX;
- fm.out_port = OFPP_NONE;
- fm.out_group = OFPG_ANY;
- fm.flags = 0;
- fm.ofpacts = &output.ofpact;
- fm.ofpacts_len = sizeof output;
- fm.delete_reason = 0;
+ struct ofputil_flow_mod fm = {
+ .match = MATCH_CATCHALL_INITIALIZER,
+ .priority = 0,
+ .table_id = 0,
+ .command = OFPFC_ADD,
+ .buffer_id = UINT32_MAX,
+ .out_port = OFPP_NONE,
+ .out_group = OFPG_ANY,
+ .ofpacts = &output.ofpact,
+ .ofpacts_len = sizeof output,
+ };
msg = ofputil_encode_flow_mod(&fm, protocol);
error = rconn_send(sw->rconn, msg, NULL);
return;
}
- switch (type) {
- case OFPTYPE_ECHO_REQUEST:
+ if (type == OFPTYPE_ECHO_REQUEST) {
process_echo_request(sw, msg->data);
- break;
-
- case OFPTYPE_FEATURES_REPLY:
+ } else if (type == OFPTYPE_FEATURES_REPLY) {
if (sw->state == S_FEATURES_REPLY) {
if (!process_switch_features(sw, msg->data)) {
sw->state = S_SWITCHING;
rconn_disconnect(sw->rconn);
}
}
- break;
-
- case OFPTYPE_PACKET_IN:
+ } else if (type == OFPTYPE_PACKET_IN) {
process_packet_in(sw, msg->data);
- break;
-
- case OFPTYPE_FLOW_REMOVED:
+ } else if (type == OFPTYPE_FLOW_REMOVED) {
/* Nothing to do. */
- break;
-
- case OFPTYPE_HELLO:
- case OFPTYPE_ERROR:
- case OFPTYPE_ECHO_REPLY:
- case OFPTYPE_FEATURES_REQUEST:
- case OFPTYPE_GET_CONFIG_REQUEST:
- case OFPTYPE_GET_CONFIG_REPLY:
- case OFPTYPE_SET_CONFIG:
- case OFPTYPE_PORT_STATUS:
- case OFPTYPE_PACKET_OUT:
- case OFPTYPE_FLOW_MOD:
- case OFPTYPE_GROUP_MOD:
- case OFPTYPE_PORT_MOD:
- case OFPTYPE_TABLE_MOD:
- case OFPTYPE_BARRIER_REQUEST:
- case OFPTYPE_BARRIER_REPLY:
- case OFPTYPE_QUEUE_GET_CONFIG_REQUEST:
- case OFPTYPE_QUEUE_GET_CONFIG_REPLY:
- case OFPTYPE_DESC_STATS_REQUEST:
- case OFPTYPE_DESC_STATS_REPLY:
- case OFPTYPE_FLOW_STATS_REQUEST:
- case OFPTYPE_FLOW_STATS_REPLY:
- case OFPTYPE_AGGREGATE_STATS_REQUEST:
- case OFPTYPE_AGGREGATE_STATS_REPLY:
- case OFPTYPE_TABLE_STATS_REQUEST:
- case OFPTYPE_TABLE_STATS_REPLY:
- case OFPTYPE_PORT_STATS_REQUEST:
- case OFPTYPE_PORT_STATS_REPLY:
- case OFPTYPE_QUEUE_STATS_REQUEST:
- case OFPTYPE_QUEUE_STATS_REPLY:
- case OFPTYPE_PORT_DESC_STATS_REQUEST:
- case OFPTYPE_PORT_DESC_STATS_REPLY:
- case OFPTYPE_ROLE_REQUEST:
- case OFPTYPE_ROLE_REPLY:
- case OFPTYPE_ROLE_STATUS:
- case OFPTYPE_SET_FLOW_FORMAT:
- case OFPTYPE_FLOW_MOD_TABLE_ID:
- case OFPTYPE_SET_PACKET_IN_FORMAT:
- case OFPTYPE_FLOW_AGE:
- case OFPTYPE_SET_CONTROLLER_ID:
- case OFPTYPE_FLOW_MONITOR_STATS_REQUEST:
- case OFPTYPE_FLOW_MONITOR_STATS_REPLY:
- case OFPTYPE_FLOW_MONITOR_CANCEL:
- case OFPTYPE_FLOW_MONITOR_PAUSED:
- case OFPTYPE_FLOW_MONITOR_RESUMED:
- case OFPTYPE_GET_ASYNC_REQUEST:
- case OFPTYPE_GET_ASYNC_REPLY:
- case OFPTYPE_SET_ASYNC_CONFIG:
- case OFPTYPE_METER_MOD:
- case OFPTYPE_GROUP_STATS_REQUEST:
- case OFPTYPE_GROUP_STATS_REPLY:
- case OFPTYPE_GROUP_DESC_STATS_REQUEST:
- case OFPTYPE_GROUP_DESC_STATS_REPLY:
- case OFPTYPE_GROUP_FEATURES_STATS_REQUEST:
- case OFPTYPE_GROUP_FEATURES_STATS_REPLY:
- case OFPTYPE_METER_STATS_REQUEST:
- case OFPTYPE_METER_STATS_REPLY:
- case OFPTYPE_METER_CONFIG_STATS_REQUEST:
- case OFPTYPE_METER_CONFIG_STATS_REPLY:
- case OFPTYPE_METER_FEATURES_STATS_REQUEST:
- case OFPTYPE_METER_FEATURES_STATS_REPLY:
- case OFPTYPE_TABLE_FEATURES_STATS_REQUEST:
- case OFPTYPE_TABLE_FEATURES_STATS_REPLY:
- case OFPTYPE_TABLE_DESC_REQUEST:
- case OFPTYPE_TABLE_DESC_REPLY:
- case OFPTYPE_BUNDLE_CONTROL:
- case OFPTYPE_BUNDLE_ADD_MESSAGE:
- case OFPTYPE_NXT_GENEVE_TABLE_MOD:
- case OFPTYPE_NXT_GENEVE_TABLE_REQUEST:
- case OFPTYPE_NXT_GENEVE_TABLE_REPLY:
- default:
- if (VLOG_IS_DBG_ENABLED()) {
- char *s = ofp_to_string(msg->data, msg->size, 2);
- VLOG_DBG_RL(&rl, "%016llx: OpenFlow packet ignored: %s",
- sw->datapath_id, s);
- free(s);
- }
+ } else if (VLOG_IS_DBG_ENABLED()) {
+ char *s = ofp_to_string(msg->data, msg->size, 2);
+ VLOG_DBG_RL(&rl, "%016llx: OpenFlow packet ignored: %s",
+ sw->datapath_id, s);
+ free(s);
}
}
\f
send_features_request(struct lswitch *sw)
{
struct ofpbuf *b;
- struct ofp_switch_config *osc;
int ofp_version = rconn_get_version(sw->rconn);
ovs_assert(ofp_version > 0 && ofp_version < 0xff);
queue_tx(sw, b);
/* Send OFPT_SET_CONFIG. */
- b = ofpraw_alloc(OFPRAW_OFPT_SET_CONFIG, ofp_version, sizeof *osc);
- osc = ofpbuf_put_zeros(b, sizeof *osc);
- osc->miss_send_len = htons(OFP_DEFAULT_MISS_SEND_LEN);
- queue_tx(sw, b);
+ struct ofputil_switch_config config = {
+ .miss_send_len = OFP_DEFAULT_MISS_SEND_LEN
+ };
+ queue_tx(sw, ofputil_encode_set_config(&config, ofp_version));
}
static void
enqueue->port = out_port;
enqueue->queue = queue_id;
}
- ofpact_pad(&ofpacts);
/* Prepare packet_out in case we need one. */
po.buffer_id = pi.buffer_id;
/* Send the packet, and possibly the whole flow, to the output port. */
if (sw->max_idle >= 0 && (!sw->ml || out_port != OFPP_FLOOD)) {
- struct ofputil_flow_mod fm;
- struct ofpbuf *buffer;
-
/* The output port is known, or we always flood everything, so add a
* new flow. */
- memset(&fm, 0, sizeof fm);
+ struct ofputil_flow_mod fm = {
+ .priority = 1, /* Must be > 0 because of table-miss flow entry. */
+ .table_id = 0xff,
+ .command = OFPFC_ADD,
+ .idle_timeout = sw->max_idle,
+ .buffer_id = pi.buffer_id,
+ .out_port = OFPP_NONE,
+ .ofpacts = ofpacts.data,
+ .ofpacts_len = ofpacts.size,
+ };
match_init(&fm.match, &flow, &sw->wc);
ofputil_normalize_match_quiet(&fm.match);
- fm.priority = 1; /* Must be > 0 because of table-miss flow entry. */
- fm.table_id = 0xff;
- fm.command = OFPFC_ADD;
- fm.idle_timeout = sw->max_idle;
- fm.buffer_id = pi.buffer_id;
- fm.out_port = OFPP_NONE;
- fm.ofpacts = ofpacts.data;
- fm.ofpacts_len = ofpacts.size;
- buffer = ofputil_encode_flow_mod(&fm, sw->protocol);
+
+ struct ofpbuf *buffer = ofputil_encode_flow_mod(&fm, sw->protocol);
queue_tx(sw, buffer);