From 68d1c8c3c3de2f2dc093901d4d83567a37375bc4 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 11 Feb 2010 13:47:30 -0800 Subject: [PATCH] classifier: New function cls_rule_to_string(). This may be useful for debugging. From Jean Tourrilhes . --- lib/classifier.c | 15 ++++++++++++++- lib/classifier.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/classifier.c b/lib/classifier.c index 94c838022..748e0dfdc 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include #include #include +#include "dynamic-string.h" #include "flow.h" #include "hash.h" @@ -75,6 +76,18 @@ cls_rule_from_match(struct cls_rule *rule, const struct ofp_match *match, rule->table_idx = table_idx_from_wildcards(rule->wc.wildcards); } +/* Converts 'rule' to a string and returns the string. The caller must free + * the string (with free()). */ +char * +cls_rule_to_string(const struct cls_rule *rule) +{ + struct ds s = DS_EMPTY_INITIALIZER; + ds_put_format(&s, "wildcards=%x priority=%u ", + rule->wc.wildcards, rule->priority); + flow_format(&s, &rule->flow); + return ds_cstr(&s); +} + /* Prints cls_rule 'rule', for debugging. * * (The output could be improved and expanded, but this was good enough to diff --git a/lib/classifier.h b/lib/classifier.h index 194b04e6b..14fd70792 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -123,6 +123,7 @@ void cls_rule_from_flow(struct cls_rule *, const flow_t *, uint32_t wildcards, unsigned int priority); void cls_rule_from_match(struct cls_rule *, const struct ofp_match *, unsigned int priority); +char *cls_rule_to_string(const struct cls_rule *); void cls_rule_print(const struct cls_rule *); void cls_rule_moved(struct classifier *, struct cls_rule *old, struct cls_rule *new); -- 2.43.0