[ovs-dev] [PATCH 07/41 v11] ofp-util: Prepare Packet Out encoder for other Open Flow versions
Simon Horman
horms at verge.net.au
Wed Aug 8 03:19:57 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v11
* Manual rebase
v10
* No change
v9
* Resolve breakage caused by reordering patches in v8
v8
* Make use of enum ofp_version
v7
* Manual Rebase
v6
* No change
v5
* No change
v4
* Manual rebase
v3
* Add protocol variable to do_probe().
Previously this was added by a separate patch.
v2
* No change
---
lib/learning-switch.c | 4 ++--
lib/ofp-util.c | 39 ++++++++++++++++++++++++++-------------
lib/ofp-util.h | 3 ++-
utilities/ovs-ofctl.c | 5 +++--
4 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index c1cd909..235e9d4 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -590,13 +590,13 @@ process_packet_in(struct lswitch *sw, const struct ofp_header *oh)
/* If the switch didn't buffer the packet, we need to send a copy. */
if (pi.buffer_id == UINT32_MAX && out_port != OFPP_NONE) {
- queue_tx(sw, ofputil_encode_packet_out(&po));
+ queue_tx(sw, ofputil_encode_packet_out(&po, sw->protocol));
}
} else {
/* We don't know that MAC, or we don't set up flows. Send along the
* packet without setting up a flow. */
if (pi.buffer_id != UINT32_MAX || out_port != OFPP_NONE) {
- queue_tx(sw, ofputil_encode_packet_out(&po));
+ queue_tx(sw, ofputil_encode_packet_out(&po, sw->protocol));
}
}
}
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 58999d1..fbfd17e 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -3044,27 +3044,40 @@ ofputil_append_flow_update(const struct ofputil_flow_update *update,
}
struct ofpbuf *
-ofputil_encode_packet_out(const struct ofputil_packet_out *po)
+ofputil_encode_packet_out(const struct ofputil_packet_out *po,
+ enum ofputil_protocol protocol)
{
- struct ofp_packet_out *opo;
- size_t actions_ofs;
+ enum ofp_version ofp_version = ofputil_protocol_to_ofp_version(protocol);
struct ofpbuf *msg;
- size_t size;
+ size_t size = 0;
size = po->ofpacts_len;
if (po->buffer_id == UINT32_MAX) {
- size += po->packet_len;
+ size = po->packet_len;
}
- msg = ofpraw_alloc(OFPRAW_OFPT10_PACKET_OUT, OFP10_VERSION, size);
- ofpbuf_put_zeros(msg, sizeof *opo);
- actions_ofs = msg->size;
- ofpacts_put_openflow10(po->ofpacts, po->ofpacts_len, msg);
+ switch (ofp_version) {
+ case OFP10_VERSION: {
+ struct ofp_packet_out *opo;
+ size_t actions_ofs;
+
+ msg = ofpraw_alloc(OFPRAW_OFPT10_PACKET_OUT, OFP10_VERSION, size);
+ ofpbuf_put_zeros(msg, sizeof *opo);
+ actions_ofs = msg->size;
+ ofpacts_put_openflow10(po->ofpacts, po->ofpacts_len, msg);
+
+ opo = msg->l3;
+ opo->buffer_id = htonl(po->buffer_id);
+ opo->in_port = htons(po->in_port);
+ opo->actions_len = htons(msg->size - actions_ofs);
+ break;
+ }
- opo = msg->l3;
- opo->buffer_id = htonl(po->buffer_id);
- opo->in_port = htons(po->in_port);
- opo->actions_len = htons(msg->size - actions_ofs);
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ default:
+ NOT_REACHED();
+ }
if (po->buffer_id == UINT32_MAX) {
ofpbuf_put(msg, po->packet, po->packet_len);
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index bc57226..51f0f5a 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -300,7 +300,8 @@ struct ofputil_packet_out {
enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
const struct ofp_header *,
struct ofpbuf *ofpacts);
-struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *);
+struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
+ enum ofputil_protocol protocol);
enum ofputil_port_config {
/* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index cd42b96..dd5f4ba 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -1453,6 +1453,7 @@ ofctl_probe(int argc OVS_UNUSED, char *argv[])
static void
ofctl_packet_out(int argc, char *argv[])
{
+ enum ofputil_protocol protocol;
struct ofputil_packet_out po;
struct ofpbuf ofpacts;
struct vconn *vconn;
@@ -1468,7 +1469,7 @@ ofctl_packet_out(int argc, char *argv[])
po.ofpacts = ofpacts.data;
po.ofpacts_len = ofpacts.size;
- open_vconn(argv[1], &vconn);
+ protocol = open_vconn(argv[1], &vconn);
for (i = 4; i < argc; i++) {
struct ofpbuf *packet, *opo;
const char *error_msg;
@@ -1480,7 +1481,7 @@ ofctl_packet_out(int argc, char *argv[])
po.packet = packet->data;
po.packet_len = packet->size;
- opo = ofputil_encode_packet_out(&po);
+ opo = ofputil_encode_packet_out(&po, protocol);
transact_noreply(vconn, opo);
ofpbuf_delete(packet);
}
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list