[ovs-dev] [PATCH v4 05/14] Support userdata in NXT_PACKET_IN2.
Jarno Rajahalme
jarno at ovn.org
Fri Feb 19 22:35:40 UTC 2016
With the comments below:
Acked-by: Jarno Rajahalme <jarno at ovn.org>
(snip)
> +/* Properties for NXAST_CONTROLLER2. */
> +enum nx_action_controller2_prop_type {
> + NXAC2PT_MAX_LEN, /* ovs_be16 max length to send controller. */
> + NXAC2PT_CONTROLLER_ID, /* ovs_be16 controller ID of destination. */
> + NXAC2PT_REASON, /* uint8_t reason (OFPR_*). */
> + NXAC2PT_USERDATA, /* Data to copy into NXPINT_USERDATA. */
> +};
Should document the default values here.
(snip)
>
> static void
> +format_hex_arg(struct ds *s, const uint8_t *data, size_t len)
> +{
> + for (size_t i = 0; i < len; i++) {
> + if (i) {
> + ds_put_char(s, '.');
> + }
> + ds_put_format(s, "%02"PRIx8, data[i]);
> + }
> +}
> +
> +static void
> format_CONTROLLER(const struct ofpact_controller *a, struct ds *s)
> {
> - if (a->reason == OFPR_ACTION && a->controller_id == 0) {
> + if (a->reason == OFPR_ACTION && !a->controller_id && !a->userdata_len) {
> ds_put_format(s, "CONTROLLER:%"PRIu16, a->max_len);
> } else {
> enum ofp_packet_in_reason reason = a->reason;
> @@ -732,6 +872,11 @@ format_CONTROLLER(const struct ofpact_controller *a, struct ds *s)
> if (a->controller_id != 0) {
> ds_put_format(s, "id=%"PRIu16",", a->controller_id);
> }
> + if (a->userdata_len) {
> + ds_put_cstr(s, "userdata=");
> + format_hex_arg(s, a->userdata, a->userdata_len);
> + ds_put_char(s, ',');
> + }
> ds_chomp(s, ',');
> ds_put_char(s, ')');
> }
> @@ -4400,15 +4545,8 @@ parse_NOTE(const char *arg, struct ofpbuf *ofpacts,
> static void
> format_NOTE(const struct ofpact_note *a, struct ds *s)
> {
> - size_t i;
> -
> ds_put_cstr(s, "note:");
> - for (i = 0; i < a->length; i++) {
> - if (i) {
> - ds_put_char(s, '.');
> - }
> - ds_put_format(s, "%02"PRIx8, a->data[i]);
> - }
> + format_hex_arg(s, a->data, a->length);
> }
>
> /* Exit action. */
> diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h
> index 5dec177..d4125e6 100644
> --- a/lib/ofp-actions.h
> +++ b/lib/ofp-actions.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2012, 2013, 2014, 2015 Nicira, Inc.
> + * Copyright (c) 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.
> @@ -56,7 +56,7 @@
> /* Output. */ \
> OFPACT(OUTPUT, ofpact_output, ofpact, "output") \
> OFPACT(GROUP, ofpact_group, ofpact, "group") \
> - OFPACT(CONTROLLER, ofpact_controller, ofpact, "controller") \
> + OFPACT(CONTROLLER, ofpact_controller, userdata, "controller") \
> OFPACT(ENQUEUE, ofpact_enqueue, ofpact, "enqueue") \
> OFPACT(OUTPUT_REG, ofpact_output_reg, ofpact, "output_reg") \
> OFPACT(BUNDLE, ofpact_bundle, slaves, "bundle") \
> @@ -245,6 +245,11 @@ struct ofpact_controller {
> uint16_t max_len; /* Maximum length to send to controller. */
> uint16_t controller_id; /* Controller ID to send packet-in. */
> enum ofp_packet_in_reason reason; /* Reason to put in packet-in. */
> +
> + /* Arbitrary data to include in the packet-in message (currently, only in
> + * NXT_PACKET_IN2). */
> + uint16_t userdata_len;
> + uint8_t userdata[];
> };
>
> /* OFPACT_ENQUEUE.
> diff --git a/lib/ofp-print.c b/lib/ofp-print.c
> index 74f0de6..39e1c8b 100644
> --- a/lib/ofp-print.c
> +++ b/lib/ofp-print.c
> @@ -141,6 +141,17 @@ ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
> }
> ds_put_char(string, '\n');
>
> + if (pin.userdata_len) {
> + ds_put_cstr(string, " userdata=");
> + for (size_t i = 0; i < pin.userdata_len; i++) {
> + if (i) {
> + ds_put_char(string, '.');
> + }
> + ds_put_format(string, "%02x", pin.userdata[i]);
> + }
Could use format_hex_arg() here?
> + ds_put_char(string, '\n');
> + }
> +
> if (verbosity > 0) {
> char *packet = ofp_packet_to_string(pin.packet, pin.packet_len);
> ds_put_cstr(string, packet);
(snip)
More information about the dev
mailing list