void
ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc)
{
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 20);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 21);
/* Initialize most of wc. */
flow_wildcards_init_catchall(wc);
>> OFPFW10_NW_DST_SHIFT);
if (!(ofpfw & OFPFW10_TP_SRC)) {
- wc->masks.tp_src = htons(UINT16_MAX);
+ wc->masks.tp_src = OVS_BE16_MAX;
}
if (!(ofpfw & OFPFW10_TP_DST)) {
- wc->masks.tp_dst = htons(UINT16_MAX);
+ wc->masks.tp_dst = OVS_BE16_MAX;
}
if (!(ofpfw & OFPFW10_DL_SRC)) {
memset(wc->masks.dl_dst, 0xff, ETH_ADDR_LEN);
}
if (!(ofpfw & OFPFW10_DL_TYPE)) {
- wc->masks.dl_type = htons(UINT16_MAX);
+ wc->masks.dl_type = OVS_BE16_MAX;
}
/* VLAN TCI mask. */
}
}
-/* Converts the ofp11_match in 'match' into a struct match in 'match. Returns
- * 0 if successful, otherwise an OFPERR_* value. */
+/* Converts the ofp11_match in 'ofmatch' into a struct match in 'match'.
+ * Returns 0 if successful, otherwise an OFPERR_* value. */
enum ofperr
ofputil_match_from_ofp11_match(const struct ofp11_match *ofmatch,
struct match *match)
if (ofmatch->dl_vlan == htons(OFPVID11_NONE)) {
/* Match only packets without a VLAN tag. */
match->flow.vlan_tci = htons(0);
- match->wc.masks.vlan_tci = htons(UINT16_MAX);
+ match->wc.masks.vlan_tci = OVS_BE16_MAX;
} else {
if (ofmatch->dl_vlan == htons(OFPVID11_ANY)) {
/* Match any packet with a VLAN tag regardless of VID. */
return error;
}
- error = ofpacts_pull_openflow11_instructions(&b, b.size, ofpacts);
+ error = ofpacts_pull_openflow11_instructions(&b, oh->version,
+ b.size, ofpacts);
if (error) {
return error;
}
} else {
fm->cookie = ofm->cookie;
fm->cookie_mask = ofm->cookie_mask;
- fm->new_cookie = htonll(UINT64_MAX);
+ fm->new_cookie = OVS_BE64_MAX;
}
fm->modify_cookie = false;
fm->command = ofm->command;
NOT_REACHED();
}
- fm->modify_cookie = fm->new_cookie != htonll(UINT64_MAX);
+ fm->modify_cookie = fm->new_cookie != OVS_BE64_MAX;
if (protocol & OFPUTIL_P_TID) {
fm->command = command & 0xff;
fm->table_id = command >> 8;
return EINVAL;
}
- if (ofpacts_pull_openflow11_instructions(msg, length - sizeof *ofs -
+ if (ofpacts_pull_openflow11_instructions(msg, oh->version,
+ length - sizeof *ofs -
padded_match_len, ofpacts)) {
VLOG_WARN_RL(&bad_ofmsg_rl, "OFPST_FLOW reply bad instructions");
return EINVAL;
enum ofputil_protocol protocol,
enum nx_packet_in_format packet_in_format)
{
- size_t send_len = MIN(pin->send_len, pin->packet_len);
struct ofpbuf *packet;
/* Add OFPT_PACKET_IN. */
/* The final argument is just an estimate of the space required. */
packet = ofpraw_alloc_xid(packet_in_raw, packet_in_version,
htonl(0), (sizeof(struct flow_metadata) * 2
- + 2 + send_len));
+ + 2 + pin->packet_len));
ofpbuf_put_zeros(packet, packet_in_size);
oxm_put_match(packet, &match);
ofpbuf_put_zeros(packet, 2);
- ofpbuf_put(packet, pin->packet, send_len);
+ ofpbuf_put(packet, pin->packet, pin->packet_len);
opi = packet->l3;
opi->pi.buffer_id = htonl(pin->buffer_id);
struct ofp10_packet_in *opi;
packet = ofpraw_alloc_xid(OFPRAW_OFPT10_PACKET_IN, OFP10_VERSION,
- htonl(0), send_len);
+ htonl(0), pin->packet_len);
opi = ofpbuf_put_zeros(packet, offsetof(struct ofp10_packet_in, data));
opi->total_len = htons(pin->total_len);
opi->in_port = htons(ofp_to_u16(pin->fmd.in_port));
opi->reason = pin->reason;
opi->buffer_id = htonl(pin->buffer_id);
- ofpbuf_put(packet, pin->packet, send_len);
+ ofpbuf_put(packet, pin->packet, pin->packet_len);
} else if (packet_in_format == NXPIF_NXM) {
struct nx_packet_in *npi;
struct match match;
/* The final argument is just an estimate of the space required. */
packet = ofpraw_alloc_xid(OFPRAW_NXT_PACKET_IN, OFP10_VERSION,
htonl(0), (sizeof(struct flow_metadata) * 2
- + 2 + send_len));
+ + 2 + pin->packet_len));
ofpbuf_put_zeros(packet, sizeof *npi);
match_len = nx_put_match(packet, &match, 0, 0);
ofpbuf_put_zeros(packet, 2);
- ofpbuf_put(packet, pin->packet, send_len);
+ ofpbuf_put(packet, pin->packet, pin->packet_len);
npi = packet->l3;
npi->buffer_id = htonl(pin->buffer_id);
return error;
}
- error = ofpacts_pull_openflow11_actions(&b, ntohs(opo->actions_len),
+ error = ofpacts_pull_openflow11_actions(&b, oh->version,
+ ntohs(opo->actions_len),
ofpacts);
if (error) {
return error;
ofpmsg_update_length(b);
return b;
}
-\f
+
/* ofputil_port_mod */
/* Decodes the OpenFlow "port mod" message in '*oh' into an abstract form in
opm->advertise = netdev_port_features_to_ofp11(pm->advertise);
break;
}
+ default:
+ NOT_REACHED();
+ }
+
+ return b;
+}
+
+/* ofputil_table_mod */
+
+/* Decodes the OpenFlow "table mod" message in '*oh' into an abstract form in
+ * '*pm'. Returns 0 if successful, otherwise an OFPERR_* value. */
+enum ofperr
+ofputil_decode_table_mod(const struct ofp_header *oh,
+ struct ofputil_table_mod *pm)
+{
+ enum ofpraw raw;
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ raw = ofpraw_pull_assert(&b);
+
+ if (raw == OFPRAW_OFPT11_TABLE_MOD) {
+ const struct ofp11_table_mod *otm = b.data;
+
+ pm->table_id = otm->table_id;
+ pm->config = ntohl(otm->config);
+ } else {
+ return OFPERR_OFPBRC_BAD_TYPE;
+ }
+
+ return 0;
+}
+
+/* Converts the abstract form of a "table mod" message in '*pm' into an OpenFlow
+ * message suitable for 'protocol', and returns that encoded form in a buffer
+ * owned by the caller. */
+struct ofpbuf *
+ofputil_encode_table_mod(const struct ofputil_table_mod *pm,
+ enum ofputil_protocol protocol)
+{
+ enum ofp_version ofp_version = ofputil_protocol_to_ofp_version(protocol);
+ struct ofpbuf *b;
+
+ switch (ofp_version) {
+ case OFP10_VERSION: {
+ ovs_fatal(0, "table mod needs OpenFlow 1.1 or later "
+ "(\'-O OpenFlow11\')");
+ break;
+ }
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ case OFP13_VERSION: {
+ struct ofp11_table_mod *otm;
+ b = ofpraw_alloc(OFPRAW_OFPT11_TABLE_MOD, ofp_version, 0);
+ otm = ofpbuf_put_zeros(b, sizeof *otm);
+ otm->table_id = pm->table_id;
+ otm->config = htonl(pm->config);
+ break;
+ }
default:
NOT_REACHED();
}
rr->role = ntohl(orr->role);
if (raw == OFPRAW_OFPT12_ROLE_REQUEST
? orr->role == htonl(OFPCR12_ROLE_NOCHANGE)
- : orr->generation_id == htonll(UINT64_MAX)) {
+ : orr->generation_id == OVS_BE64_MAX) {
rr->have_generation_id = false;
rr->generation_id = 0;
} else {
out->matched_count = in->matched_count;
}
+static void
+ofputil_put_ofp12_table_stats(const struct ofp12_table_stats *in,
+ struct ofpbuf *buf)
+{
+ struct ofp12_table_stats *out = ofpbuf_put(buf, in, sizeof *in);
+
+ /* Trim off OF1.3-only capabilities. */
+ out->match &= htonll(OFPXMT12_MASK);
+ out->wildcards &= htonll(OFPXMT12_MASK);
+ out->write_setfields &= htonll(OFPXMT12_MASK);
+ out->apply_setfields &= htonll(OFPXMT12_MASK);
+}
+
static void
ofputil_put_ofp13_table_stats(const struct ofp12_table_stats *in,
struct ofpbuf *buf)
reply = ofpraw_alloc_stats_reply(request, n * sizeof *stats);
- switch ((enum ofp_version) request->version) {
- case OFP10_VERSION:
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; i++) {
+ switch ((enum ofp_version) request->version) {
+ case OFP10_VERSION:
ofputil_put_ofp10_table_stats(&stats[i], reply);
- }
- break;
+ break;
- case OFP11_VERSION:
- for (i = 0; i < n; i++) {
+ case OFP11_VERSION:
ofputil_put_ofp11_table_stats(&stats[i], reply);
- }
- break;
+ break;
- case OFP12_VERSION:
- ofpbuf_put(reply, stats, n * sizeof *stats);
- break;
+ case OFP12_VERSION:
+ ofputil_put_ofp12_table_stats(&stats[i], reply);
+ break;
- case OFP13_VERSION:
- for (i = 0; i < n; i++) {
+ case OFP13_VERSION:
ofputil_put_ofp13_table_stats(&stats[i], reply);
- }
- break;
+ break;
- default:
- NOT_REACHED();
+ default:
+ NOT_REACHED();
+ }
}
return reply;
}
if (!(may_match & MAY_MPLS)) {
wc.masks.mpls_lse = htonl(0);
- wc.masks.mpls_depth = 0;
}
/* Log any changes. */
}
static enum ofperr
-ofputil_pull_buckets(struct ofpbuf *msg, size_t buckets_length,
- struct list *buckets)
+ofputil_pull_buckets(struct ofpbuf *msg, enum ofp_version version,
+ size_t buckets_length, struct list *buckets)
{
struct ofp11_bucket *ob;
buckets_length -= ob_len;
ofpbuf_init(&ofpacts, 0);
- error = ofpacts_pull_openflow11_actions(msg, ob_len - sizeof *ob,
- &ofpacts);
+ error = ofpacts_pull_openflow11_actions(msg, version,
+ ob_len - sizeof *ob, &ofpacts);
if (error) {
ofpbuf_uninit(&ofpacts);
ofputil_bucket_list_destroy(buckets);
* otherwise a positive errno value. */
int
ofputil_decode_group_desc_reply(struct ofputil_group_desc *gd,
- struct ofpbuf *msg)
+ struct ofpbuf *msg, enum ofp_version version)
{
struct ofp11_group_desc_stats *ogds;
size_t length;
return OFPERR_OFPBRC_BAD_LEN;
}
- return ofputil_pull_buckets(msg, length - sizeof *ogds, &gd->buckets);
+ return ofputil_pull_buckets(msg, version, length - sizeof *ogds,
+ &gd->buckets);
}
/* Converts abstract group mod 'gm' into a message for OpenFlow version
gm->type = ogm->type;
gm->group_id = ntohl(ogm->group_id);
- return ofputil_pull_buckets(&msg, msg.size, &gm->buckets);
+ return ofputil_pull_buckets(&msg, oh->version, msg.size, &gm->buckets);
}
/* Parse a queue status request message into 'oqsr'.
qs13->duration_sec = htonl(oqs->duration_sec);
qs13->duration_nsec = htonl(oqs->duration_nsec);
} else {
- qs13->duration_sec = htonl(UINT32_MAX);
- qs13->duration_nsec = htonl(UINT32_MAX);
+ qs13->duration_sec = OVS_BE32_MAX;
+ qs13->duration_nsec = OVS_BE32_MAX;
}
}