blob: 869b71ab9337b7979c4166a87d0077df6877aa8e [file] [log] [blame]
A R Karthickedab01c2016-09-08 14:05:44 -07001#
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#
16import unittest
17import time
18import os
19from nose.tools import *
20from nose.twistedtools import reactor, deferred
21from twisted.internet import defer
22from OnosCtrl import OnosCtrl
23from scapy.all import *
24log.setLevel('INFO')
25
26class cbench_exchange(unittest.TestCase):
27
28 igmp_app_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../apps',
29 'ciena-cordigmp-cbench-1.0-SNAPSHOT.oar')
30 igmp_app_file_default = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../apps',
31 'ciena-cordigmp-2.0-SNAPSHOT.oar')
32 igmp_app = 'org.ciena.cordigmp'
33 switch_script = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../setup', 'of-bridge.sh')
34 switch = 'br-int'
35 ctlr_ip = os.getenv('ONOS_CONTROLLER_IP', 'localhost')
36 ctlr_port = '6653'
37 cbench = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'cbench')
38 cbench_igmp_options = '-g -D 3000 -w 10 -c {} -p {}'.format(ctlr_ip, ctlr_port)
39 CBENCH_TIMEOUT = 60
40
41 @classmethod
42 def setUpClass(cls):
43 cls.stop_switch()
44 cls.install_app()
45
46 @classmethod
47 def tearDownClass(cls):
48 cls.install_app_default()
49 cls.start_switch()
50
51 @classmethod
52 def install_app(cls):
53 OnosCtrl.uninstall_app(cls.igmp_app)
54 time.sleep(2)
55 OnosCtrl.install_app(cls.igmp_app_file)
56 time.sleep(3)
57
58 @classmethod
59 def install_app_default(cls):
60 OnosCtrl.uninstall_app(cls.igmp_app)
61 time.sleep(2)
62 OnosCtrl.install_app(cls.igmp_app_file_default)
63
64 @classmethod
65 def stop_switch(cls):
66 cmd = 'service openvswitch-switch stop'
67 log.info('Stopping switch before running cbench fakeswitch tests')
68 os.system(cmd)
69 time.sleep(1)
70
71 @classmethod
72 def start_switch(cls):
73 cmd = '{} {}'.format(cls.switch_script, cls.switch)
74 log.info('Starting back switch with command: \"%s\"', cmd)
75 os.system(cmd)
76 time.sleep(3)
77
78 @deferred(CBENCH_TIMEOUT)
79 def test_cbench_igmp(self):
80 df = defer.Deferred()
81 def cbench_igmp_join_leave_loop(df):
82 cmd = '{} {} -l 20 -s 1 -m 1000'.format(self.cbench, self.cbench_igmp_options)
83 os.system(cmd)
84 df.callback(0)
85 reactor.callLater(0, cbench_igmp_join_leave_loop, df)
86 return df