aboutsummaryrefslogtreecommitdiff
path: root/lib/odp-util.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-10-26 10:01:32 -0700
committerBen Pfaff <blp@nicira.com>2011-11-17 10:11:54 -0800
commitb2a60db8e407196d0e6634379e8aedbfe2ec774c (patch)
tree6b1675e66a008de45e75dd1364d1d9dccd7b2cf7 /lib/odp-util.c
parent39db78a0fb8bcf91a6b0e31867018572e2b6dbe9 (diff)
odp-util: Add support for named ports to odp_flow_key_from_string().
Really the "trace" command should support this but in fact I need it for an upcoming update to a test.
Diffstat (limited to 'lib/odp-util.c')
-rw-r--r--lib/odp-util.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/odp-util.c b/lib/odp-util.c
index b4ebd792..c13f7a67 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -31,12 +31,16 @@
#include "ofpbuf.h"
#include "openvswitch/tunnel.h"
#include "packets.h"
+#include "shash.h"
#include "timeval.h"
#include "util.h"
#include "vlog.h"
VLOG_DEFINE_THIS_MODULE(odp_util);
+static int parse_odp_key_attr(const char *, const struct shash *port_names,
+ struct ofpbuf *);
+
/* The interface between userspace and kernel uses an "OVS_*" prefix.
* Since this is fairly non-specific for the OVS userspace components,
* "ODP_*" (Open vSwitch Datapath) is used as the prefix for
@@ -564,7 +568,8 @@ ovs_frag_type_from_string(const char *s, enum ovs_frag_type *type)
}
static int
-parse_odp_key_attr(const char *s, struct ofpbuf *key)
+parse_odp_key_attr(const char *s, const struct shash *port_names,
+ struct ofpbuf *key)
{
/* Many of the sscanf calls in this function use oversized destination
* fields because some sscanf() implementations truncate the range of %i
@@ -608,6 +613,20 @@ parse_odp_key_attr(const char *s, struct ofpbuf *key)
}
}
+ if (port_names && !strncmp(s, "in_port(", 8)) {
+ const char *name;
+ const struct shash_node *node;
+ int name_len;
+
+ name = s + 8;
+ name_len = strcspn(s, ")");
+ node = shash_find_len(port_names, name, name_len);
+ if (node) {
+ nl_msg_put_u32(key, OVS_KEY_ATTR_IN_PORT, (uintptr_t) node->data);
+ return 8 + name_len + 1;
+ }
+ }
+
{
struct ovs_key_ethernet eth_key;
int n = -1;
@@ -880,11 +899,16 @@ parse_odp_key_attr(const char *s, struct ofpbuf *key)
* data is appended to 'key'. Either way, 'key''s data might be
* reallocated.
*
+ * If 'port_names' is nonnull, it points to an shash that maps from a port name
+ * to a port number cast to void *. (Port names may be used instead of port
+ * numbers in in_port.)
+ *
* On success, the attributes appended to 'key' are individually syntactically
* valid, but they may not be valid as a sequence. 'key' might, for example,
* have duplicated keys. odp_flow_key_to_flow() will detect those errors. */
int
-odp_flow_key_from_string(const char *s, struct ofpbuf *key)
+odp_flow_key_from_string(const char *s, const struct shash *port_names,
+ struct ofpbuf *key)
{
const size_t old_size = key->size;
for (;;) {
@@ -895,7 +919,7 @@ odp_flow_key_from_string(const char *s, struct ofpbuf *key)
return 0;
}
- retval = parse_odp_key_attr(s, key);
+ retval = parse_odp_key_attr(s, port_names, key);
if (retval < 0) {
key->size = old_size;
return -retval;