Signed-off-by: Shinpei Muraoka <shinpei.mura...@gmail.com> --- ryu/tests/packet_data/pcap/openflow_flowmod.pcap | Bin 0 -> 186 bytes .../packet_data/pcap/openflow_flowstats_req.pcap | Bin 0 -> 162 bytes .../packet_data/pcap/openflow_invalid_version.pcap | Bin 0 -> 186 bytes ryu/tests/unit/packet/test_openflow.py | 64 +++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 ryu/tests/packet_data/pcap/openflow_flowmod.pcap create mode 100644 ryu/tests/packet_data/pcap/openflow_flowstats_req.pcap create mode 100644 ryu/tests/packet_data/pcap/openflow_invalid_version.pcap create mode 100644 ryu/tests/unit/packet/test_openflow.py
diff --git a/ryu/tests/packet_data/pcap/openflow_flowmod.pcap b/ryu/tests/packet_data/pcap/openflow_flowmod.pcap new file mode 100644 index 0000000000000000000000000000000000000000..e72a0425387bf852e09f5b59ab69400871bed52e GIT binary patch literal 186 zcmca|c+)~A1{MYcU}0bca-8#`BMyCFW|#zIgD^7SU~pw%X!+0Rz~I1UTTsuyzzD*U zFP}XrTf0le+LuYUL4qOdUj<N*k%NoD-{mI=v+ywlR9q-pk8Bb$`#%sM^MTHQIE#fr N0xB*5RPq<53IMwMBRc>9 literal 0 HcmV?d00001 diff --git a/ryu/tests/packet_data/pcap/openflow_flowstats_req.pcap b/ryu/tests/packet_data/pcap/openflow_flowstats_req.pcap new file mode 100644 index 0000000000000000000000000000000000000000..7ce270d5088557cd10dbf2e7e9734a600b87de04 GIT binary patch literal 162 zcmca|c+)~A1{MYcU}0bca{6B7MnwE(WvBwOK^PfuFt{=><k((uU~pjjx3!*uff0ly zU+y*uy~VnA_n-Gq8YCDZ{v`kf89BHZ!uMt|gzx#tBE(>!^&wyu*m$6E|3MfEkWGiP I86nOB0Hw<%5dZ)H literal 0 HcmV?d00001 diff --git a/ryu/tests/packet_data/pcap/openflow_invalid_version.pcap b/ryu/tests/packet_data/pcap/openflow_invalid_version.pcap new file mode 100644 index 0000000000000000000000000000000000000000..2c22675b3a3fa61cb82b08dfcbdc6cb86994ace9 GIT binary patch literal 186 zcmca|c+)~A1{MYcU}0bca-8#`BMyCFW|#zIgD^7SU~pw%X!+0Rz~I1UTTsuyzzD*U zFP}XrTf0le+LuYUL4qOdUj<N*k%NoD-{mI=|L0=}sJKwH9@!*h_J1Hi<^!DpaTW`M N1XNrAsN^q96#xl(BsKs5 literal 0 HcmV?d00001 diff --git a/ryu/tests/unit/packet/test_openflow.py b/ryu/tests/unit/packet/test_openflow.py new file mode 100644 index 0000000..b0dca25 --- /dev/null +++ b/ryu/tests/unit/packet/test_openflow.py @@ -0,0 +1,64 @@ +# Copyright (C) 2017 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. + +from __future__ import print_function + +import logging +import os +import sys + +import unittest +from nose.tools import eq_ +from nose.tools import ok_ + +from ryu.lib import pcaplib +from ryu.lib.packet import openflow +from ryu.lib.packet import packet +from ryu.utils import binary_str + + +LOG = logging.getLogger(__name__) + +OPENFLOW_DATA_DIR = os.path.join( + os.path.dirname(sys.modules[__name__].__file__), + '../../packet_data/pcap/') + + +class Test_openflow(unittest.TestCase): + """ + Test case for ryu.lib.packet.openflow. + """ + + def test_pcap(self): + files = [ + 'openflow_flowmod', + 'openflow_flowstats_req', + 'openflow_invalid_version', + ] + + for f in files: + # print('*** testing %s ...' % f) + for _, buf in pcaplib.Reader( + open(OPENFLOW_DATA_DIR + f + '.pcap', 'rb')): + # Checks if message can be parsed as expected. + pkt = packet.Packet(buf) + openflow_pkt = pkt.get_protocol(openflow.openflow) + ok_(isinstance(openflow_pkt, openflow.openflow), + 'Failed to parse OpenFlow message: %s' % pkt) + + # Checks if message can be serialized as expected. + pkt.serialize() + eq_(buf, pkt.data, + "b'%s' != b'%s'" % (binary_str(buf), binary_str(pkt.data))) -- 2.7.4 ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today. http://sdm.link/xeonphi _______________________________________________ Ryu-devel mailing list Ryu-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ryu-devel