diff options
author | YAMADA Hideki <yamada.hideki@po.ntts.co.jp> | 2013-04-25 20:25:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-04-28 08:13:57 +0900 |
commit | 0d4ff7d34d06d37d3117a4a4e2bbf04a031d9f33 (patch) | |
tree | bf906f1399f720b0f0dc6c2cfa0edd9b01164b02 | |
parent | 84ef5c504631f352d00583f2aa81f51f48c6445a (diff) |
tests/integrated: auto testing script using Mininet and OVS
Signed-off-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rwxr-xr-x | ryu/tests/integrated/run_tests_with_ovs12.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/ryu/tests/integrated/run_tests_with_ovs12.py b/ryu/tests/integrated/run_tests_with_ovs12.py new file mode 100755 index 00000000..6926964d --- /dev/null +++ b/ryu/tests/integrated/run_tests_with_ovs12.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# Copyright (C) 2013 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. + +import unittest +from nose.tools import ok_, eq_, timed, nottest + +from subprocess import Popen, PIPE, STDOUT +import time + +from mininet.net import Mininet +from mininet.node import RemoteController, OVSKernelSwitch + +TIMEOUT = 60 +RYU_HOST = '127.0.0.1' +RYU_PORT = 6633 +PYTHON_BIN = '.venv/bin/python' +RYU_MGR = './bin/ryu-manager' + + +class OVS12KernelSwitch(OVSKernelSwitch): + """Set protocols parameter for OVS version 1.10""" + def start(self, controllers): + super(OVS12KernelSwitch, self).start(controllers) + self.cmd('ovs-vsctl set Bridge', self, + "protocols='[OpenFlow10, OpenFlow12]'") + + +class TestWithOVS12(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.mn = Mininet() + c = cls.mn.addController(controller=RemoteController, + ip=RYU_HOST, port=RYU_PORT) + c.start() + + s1 = cls.mn.addSwitch('s1', cls=OVS12KernelSwitch) + s1.start(cls.mn.controllers) + + h1 = cls.mn.addHost('h1', ip='0.0.0.0/0') + + link = cls.mn.addLink(h1, s1) + s1.attach(link.intf2) + + @classmethod + def tearDownClass(cls): + cls.mn.stop() + + @timed(TIMEOUT) + def test_add_flow_v10(self): + app = 'ryu/tests/integrated/test_add_flow_v10.py' + self._run_ryu_manager_and_check_output(app) + + @timed(TIMEOUT) + def test_request_reply_v12(self): + app = 'ryu/tests/integrated/test_request_reply_v12.py' + self._run_ryu_manager_and_check_output(app) + + @timed(TIMEOUT) + def test_add_flow_v12_actions(self): + app = 'ryu/tests/integrated/test_add_flow_v12_actions.py' + self._run_ryu_manager_and_check_output(app) + + @timed(TIMEOUT) + def test_add_flow_v12_matches(self): + app = 'ryu/tests/integrated/test_add_flow_v12_matches.py' + self._run_ryu_manager_and_check_output(app) + + @nottest + def test_of_config(self): + # OVS 1.10 does not support of_config + pass + + def _run_ryu_manager_and_check_output(self, app): + cmd = [PYTHON_BIN, RYU_MGR, app] + p = Popen(cmd, stdout=PIPE, stderr=STDOUT) + + while True: + if p.poll() is not None: + raise Exception('Another ryu-manager already running?') + + line = p.stdout.readline().strip() + if line == '': + time.sleep(1) + continue + + print "ryu-manager: %s" % line + if line.find('TEST_FINISHED') != -1: + ok_(line.find('Completed=[True]') != -1) + p.terminate() + p.communicate() # wait for subprocess is terminated + break + + +if __name__ == '__main__': + unittest.main() |