A R Karthick | edab01c | 2016-09-08 14:05:44 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016-present Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | import unittest |
| 17 | import time |
| 18 | import os |
| 19 | from nose.tools import * |
| 20 | from nose.twistedtools import reactor, deferred |
| 21 | from twisted.internet import defer |
| 22 | from OnosCtrl import OnosCtrl |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 23 | from CordTestUtils import log_test as log |
| 24 | |
A R Karthick | edab01c | 2016-09-08 14:05:44 -0700 | [diff] [blame] | 25 | log.setLevel('INFO') |
| 26 | |
| 27 | class cbench_exchange(unittest.TestCase): |
| 28 | |
| 29 | igmp_app_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../apps', |
| 30 | 'ciena-cordigmp-cbench-1.0-SNAPSHOT.oar') |
| 31 | igmp_app_file_default = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../apps', |
| 32 | 'ciena-cordigmp-2.0-SNAPSHOT.oar') |
| 33 | igmp_app = 'org.ciena.cordigmp' |
| 34 | switch_script = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup', 'of-bridge.sh') |
| 35 | switch = 'br-int' |
| 36 | ctlr_ip = os.getenv('ONOS_CONTROLLER_IP', 'localhost') |
| 37 | ctlr_port = '6653' |
| 38 | cbench = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'cbench') |
| 39 | cbench_igmp_options = '-g -D 3000 -w 10 -c {} -p {}'.format(ctlr_ip, ctlr_port) |
| 40 | CBENCH_TIMEOUT = 60 |
| 41 | |
| 42 | @classmethod |
| 43 | def setUpClass(cls): |
| 44 | cls.stop_switch() |
| 45 | cls.install_app() |
| 46 | |
| 47 | @classmethod |
| 48 | def tearDownClass(cls): |
| 49 | cls.install_app_default() |
| 50 | cls.start_switch() |
| 51 | |
| 52 | @classmethod |
| 53 | def install_app(cls): |
| 54 | OnosCtrl.uninstall_app(cls.igmp_app) |
| 55 | time.sleep(2) |
| 56 | OnosCtrl.install_app(cls.igmp_app_file) |
| 57 | time.sleep(3) |
| 58 | |
| 59 | @classmethod |
| 60 | def install_app_default(cls): |
| 61 | OnosCtrl.uninstall_app(cls.igmp_app) |
| 62 | time.sleep(2) |
| 63 | OnosCtrl.install_app(cls.igmp_app_file_default) |
| 64 | |
| 65 | @classmethod |
| 66 | def stop_switch(cls): |
| 67 | cmd = 'service openvswitch-switch stop' |
| 68 | log.info('Stopping switch before running cbench fakeswitch tests') |
| 69 | os.system(cmd) |
| 70 | time.sleep(1) |
| 71 | |
| 72 | @classmethod |
| 73 | def start_switch(cls): |
| 74 | cmd = '{} {}'.format(cls.switch_script, cls.switch) |
| 75 | log.info('Starting back switch with command: \"%s\"', cmd) |
| 76 | os.system(cmd) |
| 77 | time.sleep(3) |
A R Karthick | 76a497a | 2017-04-12 10:59:39 -0700 | [diff] [blame] | 78 | |
A R Karthick | edab01c | 2016-09-08 14:05:44 -0700 | [diff] [blame] | 79 | @deferred(CBENCH_TIMEOUT) |
| 80 | def test_cbench_igmp(self): |
| 81 | df = defer.Deferred() |
| 82 | def cbench_igmp_join_leave_loop(df): |
| 83 | cmd = '{} {} -l 20 -s 1 -m 1000'.format(self.cbench, self.cbench_igmp_options) |
| 84 | os.system(cmd) |
| 85 | df.callback(0) |
| 86 | reactor.callLater(0, cbench_igmp_join_leave_loop, df) |
| 87 | return df |