After applying this patch,
ofctl_v1_0:get_flow_stats outputs only match fields that no wildcard is set.
Execution example is as follows.

before applying this patch:

$curl http://127.0.0.1:8080/stats/flow/1
{
    "1": [
        {
            "actions": [
                "OUTPUT:1"
            ],
            "byte_count": 238,
            "cookie": 0,
            "duration_nsec": 585000000,
            "duration_sec": 154,
            "hard_timeout": 0,
            "idle_timeout": 0,
            "match": {
                "dl_dst": "00:00:00:00:00:01",
                "dl_src": "00:00:00:00:00:00",
                "dl_type": 0,
                "dl_vlan": 0,
                "dl_vlan_pcp": 0,
                "in_port": 2,
                "nw_dst": "0.0.0.0",
                "nw_proto": 0,
                "nw_src": "0.0.0.0",
                "nw_tos": 0,
                "tp_dst": 0,
                "tp_src": 0
            },
            "packet_count": 3,
            "priority": 32768,
            "table_id": 0
        }
    ]
}

after applying this patch:

$curl http://127.0.0.1:8080/stats/flow/1
{
    "1": [
        {
            "actions": [
                "OUTPUT:1"
            ],
            "byte_count": 238,
            "cookie": 0,
            "duration_nsec": 593000000,
            "duration_sec": 12,
            "hard_timeout": 0,
            "idle_timeout": 0,
            "match": {
                "dl_dst": "00:00:00:00:00:01",
                "in_port": 2
            },
            "packet_count": 3,
            "priority": 32768,
            "table_id": 0
        }
    ]
}

Reported-by:Liu, Weijie <[email protected]>
Signed-off-by: Minoru TAKAHASHI <[email protected]>
---
 ryu/lib/ofctl_v1_0.py                 | 52 +++++++++++++++++++++++-------
 ryu/tests/unit/lib/test_ofctl_v1_0.py | 60 +++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 12 deletions(-)
 create mode 100644 ryu/tests/unit/lib/test_ofctl_v1_0.py

diff --git a/ryu/lib/ofctl_v1_0.py b/ryu/lib/ofctl_v1_0.py
index a72d9b7..1a2bf41 100644
--- a/ryu/lib/ofctl_v1_0.py
+++ b/ryu/lib/ofctl_v1_0.py
@@ -206,18 +206,46 @@ def to_match(dp, attrs):
 
 
 def match_to_str(m):
-    return {'dl_dst': haddr_to_str(m.dl_dst),
-            'dl_src': haddr_to_str(m.dl_src),
-            'dl_type': m.dl_type,
-            'dl_vlan': m.dl_vlan,
-            'dl_vlan_pcp': m.dl_vlan_pcp,
-            'in_port': m.in_port,
-            'nw_dst': nw_dst_to_str(m.wildcards, m.nw_dst),
-            'nw_proto': m.nw_proto,
-            'nw_tos': m.nw_tos,
-            'nw_src': nw_src_to_str(m.wildcards, m.nw_src),
-            'tp_src': m.tp_src,
-            'tp_dst': m.tp_dst}
+
+    match = {}
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_IN_PORT:
+        match['in_port'] = m.in_port
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_DL_SRC:
+        match['dl_src'] = haddr_to_str(m.dl_src)
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_DL_DST:
+        match['dl_dst'] = haddr_to_str(m.dl_dst)
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_DL_VLAN:
+        match['dl_vlan'] = m.dl_vlan
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_DL_VLAN_PCP:
+        match['dl_vlan_pcp'] = m.dl_vlan_pcp
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_DL_TYPE:
+        match['dl_type'] = m.dl_type
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_NW_TOS:
+        match['nw_tos'] = m.nw_tos
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_NW_PROTO:
+        match['nw_proto'] = m.nw_proto
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_NW_SRC_ALL:
+        match['nw_src'] = nw_src_to_str(m.wildcards, m.nw_src)
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_NW_DST_ALL:
+        match['nw_dst'] = nw_dst_to_str(m.wildcards, m.nw_dst)
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_TP_SRC:
+        match['tp_src'] = m.tp_src
+
+    if ~m.wildcards & ofproto_v1_0.OFPFW_TP_DST:
+        match['tp_dst'] = m.tp_dst
+
+    return match
 
 
 def nw_src_to_str(wildcards, addr):
diff --git a/ryu/tests/unit/lib/test_ofctl_v1_0.py 
b/ryu/tests/unit/lib/test_ofctl_v1_0.py
new file mode 100644
index 0000000..e8c2762
--- /dev/null
+++ b/ryu/tests/unit/lib/test_ofctl_v1_0.py
@@ -0,0 +1,60 @@
+# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+import unittest
+import logging
+from nose.tools import *
+
+from ryu.lib import ofctl_v1_0
+from ryu.ofproto import ofproto_v1_0, ofproto_v1_0_parser
+from ryu.ofproto import ofproto_protocol
+
+LOG = logging.getLogger('test_ofctl_v1_0')
+
+
+class Test_ofctl_v1_0(unittest.TestCase):
+
+    """ Test case for ofctl_v1_0
+    """
+
+    def setUp(self):
+        self.dp = ofproto_protocol.ProtocolDesc(
+            version=ofproto_v1_0.OFP_VERSION)
+        self.attrs_list = [
+            {"in_port": 3},
+            {"dl_vlan": 3},
+            {"dl_src": "11:11:11:11:11:11"},
+            {"dl_dst": "11:11:11:11:11:12"},
+            {"nw_tos": 16, "dl_type": 2048},
+            {"nw_proto": 5, "dl_type": 2048},
+            {"tp_src": 1, "nw_proto": 6, "dl_type": 2048},
+            {"tp_dst": 2, "nw_proto": 6, "dl_type": 2048},
+            {"nw_src": "192.168.1.5", "dl_type": 2048},
+            {"nw_dst": "192.168.1.5/12", "dl_type": 2048},
+            {"nw_dst": "192.168.1.5/1"},
+            {"nw_dst": "192.168.1.5/12"},
+            {"dl_vlan_pcp": 3}
+        ]
+
+    def tearDown(self):
+        pass
+
+    def test_match_to_str(self):
+        for attrs in self.attrs_list:
+            match = ofctl_v1_0.to_match(self.dp, attrs)
+            str = ofctl_v1_0.match_to_str(match)
+            eq_(attrs, str)
-- 
1.9.1


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to