blob: 9741b2a2b4fc1fa369b37bfbd13f869b496824d0 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
Chetan Gaonker52418832017-01-26 23:03:13 +000017#copyright 2016-present Ciena Corporation
18#
19# Licensed under the Apache License, Version 2.0 (the "License");
20# you may not use this file except in compliance with the License.
21# You may obtain a copy of the License at
22#
23# http://www.apache.org/licenses/LICENSE-2.0
24#
25# Unless required by applicable law or agreed to in writing, software
26# distributed under the License is distributed on an "AS IS" BASIS,
27# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28# See the License for the specific language governing permissions and
29# limitations under the License.
30#
A R Karthickd0fdf3b2017-03-21 16:54:22 -070031import time
32import os
A.R Karthick282f0d32017-03-28 16:43:59 -070033import sys
34import json
Chetan Gaonker0bf76312017-05-09 16:48:10 +000035import requests
Chetan Gaonker52418832017-01-26 23:03:13 +000036from nose.tools import *
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +000037from twisted.internet import defer
38from nose.twistedtools import reactor, deferred
A.R Karthick33cfdbe2017-03-17 18:03:48 -070039from CordTestUtils import *
Chetan Gaonker52418832017-01-26 23:03:13 +000040from OltConfig import OltConfig
Chetan Gaonker52418832017-01-26 23:03:13 +000041from onosclidriver import OnosCliDriver
A.R Karthick9ccd0d02017-03-16 17:11:08 -070042from SSHTestAgent import SSHTestAgent
Chetan Gaonker52418832017-01-26 23:03:13 +000043from CordLogger import CordLogger
A R Karthickd0fdf3b2017-03-21 16:54:22 -070044from VSGAccess import VSGAccess
A R Karthick933f5b52017-03-27 15:27:16 -070045from CordTestUtils import log_test as log
A R Karthick9dc6e922017-07-12 14:40:16 -070046from CordTestConfig import setup_module, running_on_ciab, teardown_module
A.R Karthicka9b594d2017-03-29 16:25:22 -070047from OnosCtrl import OnosCtrl
A R Karthickb608d402017-06-02 11:48:41 -070048from CordContainer import Onos
A R Karthicked3a2ca2017-07-06 15:50:03 -070049from CordSubscriberUtils import CordSubscriberUtils, XosUtils
Chetan Gaonker52418832017-01-26 23:03:13 +000050log.setLevel('INFO')
51
52class vsg_exchange(CordLogger):
53 ONOS_INSTANCES = 3
54 V_INF1 = 'veth0'
55 device_id = 'of:' + get_mac()
Chetan Gaonker52418832017-01-26 23:03:13 +000056 TEST_IP = '8.8.8.8'
57 HOST = "10.1.0.1"
58 USER = "vagrant"
59 PASS = "vagrant"
A R Karthick705a5bf2017-10-27 11:17:04 -070060 head_node = os.getenv('HEAD_NODE', 'head1')
A.R Karthick9ccd0d02017-03-16 17:11:08 -070061 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
A R Karthick03f40aa2017-03-20 19:33:55 -070062 test_path = os.path.dirname(os.path.realpath(__file__))
A.R Karthick5968e0d2017-05-16 14:50:46 -070063 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
A.R Karthick282f0d32017-03-28 16:43:59 -070064 restApiXos = None
A R Karthicked3a2ca2017-07-06 15:50:03 -070065 cord_subscriber = None
66 SUBSCRIBER_ACCOUNT_NUM = 200
67 SUBSCRIBER_S_TAG = 304
68 SUBSCRIBER_C_TAG = 304
69 SUBSCRIBERS_PER_S_TAG = 8
A R Karthickb0cec7c2017-04-21 10:42:54 -070070 subscriber_info = []
71 volt_subscriber_info = []
A R Karthick9a16a112017-04-07 15:40:05 -070072 restore_methods = []
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +000073 TIMEOUT=120
A.R Karthickb145da82017-04-20 14:45:43 -070074 FABRIC_PORT_HEAD_NODE = 1
75 FABRIC_PORT_COMPUTE_NODE = 2
76 APP_NAME = 'org.ciena.xconnect'
77 APP_FILE = os.path.join(test_path, '..', 'apps/xconnect-1.0-SNAPSHOT.oar')
A.R Karthick50f4d9a2017-04-20 16:44:19 -070078 NUM_SUBSCRIBERS = 5
A R Karthick0a4ca3a2017-03-30 09:36:53 -070079
80 @classmethod
A R Karthick037cb982017-07-07 17:35:30 -070081 def setUpCordApi(cls, **subscriber_config):
82 num_subscribers = subscriber_config.get('num_subscribers', cls.NUM_SUBSCRIBERS)
83 account_num = subscriber_config.get('account_num', cls.SUBSCRIBER_ACCOUNT_NUM)
84 s_tag = subscriber_config.get('s_tag', cls.SUBSCRIBER_S_TAG)
85 c_tag = subscriber_config.get('c_tag', cls.SUBSCRIBER_C_TAG)
86 subscribers_per_s_tag = subscriber_config.get('subscribers_per_s_tag', cls.SUBSCRIBERS_PER_S_TAG)
A R Karthicked3a2ca2017-07-06 15:50:03 -070087 cls.cord_subscriber = CordSubscriberUtils(num_subscribers,
A R Karthick037cb982017-07-07 17:35:30 -070088 account_num = account_num,
89 s_tag = s_tag,
90 c_tag = c_tag,
91 subscribers_per_s_tag = subscribers_per_s_tag)
A R Karthicked3a2ca2017-07-06 15:50:03 -070092 cls.restApiXos = XosUtils.getRestApi()
A R Karthick97e08852017-04-26 10:06:38 -070093
94 @classmethod
A R Karthickb0cec7c2017-04-21 10:42:54 -070095 def closeVCPEAccess(cls, volt_subscriber_info):
A R Karthick5d30b3c2017-04-27 10:25:40 -070096 OnosCtrl.uninstall_app(cls.APP_NAME, onos_ip = cls.HEAD_NODE)
A.R Karthickb145da82017-04-20 14:45:43 -070097
98 @classmethod
A R Karthickb0cec7c2017-04-21 10:42:54 -070099 def openVCPEAccess(cls, volt_subscriber_info):
A.R Karthickb145da82017-04-20 14:45:43 -0700100 """
A R Karthickb0cec7c2017-04-21 10:42:54 -0700101 This code is used to configure leaf switch for head node access to compute node over fabric.
102 Care is to be taken to avoid overwriting existing/default vcpe flows.
103 The access is opened for generated subscriber info which should not overlap.
104 We target the fabric onos instance on head node.
A.R Karthickb145da82017-04-20 14:45:43 -0700105 """
A R Karthickb608d402017-06-02 11:48:41 -0700106 version = Onos.getVersion(onos_ip = cls.HEAD_NODE)
107 app_version = '1.0-SNAPSHOT'
108 major = int(version.split('.')[0])
109 minor = int(version.split('.')[1])
110 if major > 1:
111 app_version = '2.0-SNAPSHOT'
A R Karthick1a5cefb2017-12-01 09:50:57 -0800112 elif major == 1 and minor >= 10:
A R Karthickb608d402017-06-02 11:48:41 -0700113 app_version = '2.0-SNAPSHOT'
114 cls.APP_FILE = os.path.join(cls.test_path, '..', 'apps/xconnect-{}.oar'.format(app_version))
A.R Karthickb145da82017-04-20 14:45:43 -0700115 OnosCtrl.install_app(cls.APP_FILE, onos_ip = cls.HEAD_NODE)
116 time.sleep(2)
A R Karthickb0cec7c2017-04-21 10:42:54 -0700117 s_tags = map(lambda tenant: int(tenant['voltTenant']['s_tag']), volt_subscriber_info)
118 #only get unique vlan tags
119 s_tags = list(set(s_tags))
A.R Karthickb145da82017-04-20 14:45:43 -0700120 devices = OnosCtrl.get_device_ids(controller = cls.HEAD_NODE)
A R Karthickb0cec7c2017-04-21 10:42:54 -0700121 if devices:
122 device_config = {}
123 for device in devices:
124 device_config[device] = []
125 for s_tag in s_tags:
126 xconnect_config = {'vlan': s_tag, 'ports' : [ cls.FABRIC_PORT_HEAD_NODE, cls.FABRIC_PORT_COMPUTE_NODE ] }
127 device_config[device].append(xconnect_config)
A.R Karthickb145da82017-04-20 14:45:43 -0700128
A R Karthickb0cec7c2017-04-21 10:42:54 -0700129 cfg = { 'apps' : { 'org.ciena.xconnect' : { 'xconnectTestConfig' : device_config } } }
130 OnosCtrl.config(cfg, controller = cls.HEAD_NODE)
A.R Karthickb145da82017-04-20 14:45:43 -0700131
132 @classmethod
A R Karthick037cb982017-07-07 17:35:30 -0700133 def vsgSetup(cls, **subscriber_config):
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700134 cls.controllers = get_controllers()
135 cls.controller = cls.controllers[0]
136 cls.cli = None
A R Karthick19771192017-04-25 14:57:05 -0700137 cls.on_pod = running_on_pod()
138 cls.on_ciab = running_on_ciab()
A R Karthick03f40aa2017-03-20 19:33:55 -0700139 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
140 cls.vcpes = cls.olt.get_vcpes()
141 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
A R Karthick035d2e22017-04-25 13:53:00 -0700142 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
143 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
144 for i in xrange(len(cls.vcpes_reserved)) ]
145 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
A R Karthickb2638632017-10-25 16:01:16 -0700146 cls.container_vcpes_reserved = [ 'vsg-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
A R Karthick035d2e22017-04-25 13:53:00 -0700147 vcpe_dhcp_reserved = None
148 vcpe_container_reserved = None
149 if cls.vcpes_reserved:
150 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
A R Karthick19771192017-04-25 14:57:05 -0700151 if cls.on_pod is False:
A R Karthick035d2e22017-04-25 13:53:00 -0700152 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
153 vcpe_container_reserved = cls.container_vcpes_reserved[0]
154
155 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
156 cls.vcpe_container_reserved = vcpe_container_reserved
157 dhcp_vcpe_offset = len(cls.vcpes_reserved)
A R Karthick927129c2017-04-25 14:08:02 -0700158 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
159 for i in xrange(len(cls.vcpes_dhcp)) ]
160 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
A R Karthickb2638632017-10-25 16:01:16 -0700161 cls.container_vcpes = [ 'vsg-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
A R Karthick03f40aa2017-03-20 19:33:55 -0700162 vcpe_dhcp = None
A R Karthick03f40aa2017-03-20 19:33:55 -0700163 vcpe_container = None
164 #cache the first dhcp vcpe in the class for quick testing
165 if cls.vcpes_dhcp:
A R Karthick035d2e22017-04-25 13:53:00 -0700166 vcpe_container = cls.container_vcpes[0]
167 vcpe_dhcp = cls.dhcp_vcpes[0]
A R Karthick19771192017-04-25 14:57:05 -0700168 if cls.on_pod is False:
A R Karthick035d2e22017-04-25 13:53:00 -0700169 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
170 cls.vcpe_container = vcpe_container_reserved or vcpe_container
171 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700172 VSGAccess.setUp()
A R Karthick037cb982017-07-07 17:35:30 -0700173 cls.setUpCordApi(**subscriber_config)
A R Karthick19771192017-04-25 14:57:05 -0700174 if cls.on_pod is True:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700175 cls.openVCPEAccess(cls.cord_subscriber.volt_subscriber_info)
Chetan Gaonker52418832017-01-26 23:03:13 +0000176
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700177 @classmethod
A R Karthick037cb982017-07-07 17:35:30 -0700178 def setUpClass(cls):
179 num_subscribers = max(cls.NUM_SUBSCRIBERS, 5)
180 cls.vsgSetup(num_subscribers = num_subscribers)
181
182 @classmethod
183 def vsgTeardown(cls):
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700184 VSGAccess.tearDown()
A R Karthick19771192017-04-25 14:57:05 -0700185 if cls.on_pod is True:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700186 cls.closeVCPEAccess(cls.cord_subscriber.volt_subscriber_info)
Chetan Gaonker52418832017-01-26 23:03:13 +0000187
A R Karthick037cb982017-07-07 17:35:30 -0700188 @classmethod
189 def tearDownClass(cls):
A R Karthick03ebafc2017-11-17 14:41:06 -0800190 cls.config_restore()
A R Karthick037cb982017-07-07 17:35:30 -0700191 cls.vsgTeardown()
192
A R Karthick7b6a3242017-11-17 14:33:59 -0800193 def tearDown(self):
194 self.config_restore()
195 super(vsg_exchange, self).tearDown()
196
Chetan Gaonker52418832017-01-26 23:03:13 +0000197 def onos_shutdown(self, controller = None):
198 status = True
A R Karthickb608d402017-06-02 11:48:41 -0700199 cli = Onos.cliEnter(onos_ip = controller)
Chetan Gaonker52418832017-01-26 23:03:13 +0000200 try:
A R Karthickb608d402017-06-02 11:48:41 -0700201 cli.shutdown(timeout = 10)
Chetan Gaonker52418832017-01-26 23:03:13 +0000202 except:
203 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
204 status = False
205
A R Karthickb608d402017-06-02 11:48:41 -0700206 Onos.cliExit(cli)
Chetan Gaonker52418832017-01-26 23:03:13 +0000207 return status
208
A.R Karthick9ccd0d02017-03-16 17:11:08 -0700209 def log_set(self, level = None, app = 'org.onosproject'):
210 CordLogger.logSet(level = level, app = app, controllers = self.controllers, forced = True)
Chetan Gaonker52418832017-01-26 23:03:13 +0000211
A R Karthick9a16a112017-04-07 15:40:05 -0700212 @classmethod
213 def get_dhcp(cls, vcpe, mgmt = 'eth0'):
214 """Get DHCP for vcpe interface saving management settings"""
215
216 def put_dhcp():
217 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
218
219 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
220 if vcpe_ip is not None:
221 cls.restore_methods.append(put_dhcp)
222 return vcpe_ip
223
224 @classmethod
225 def config_restore(cls):
226 """Restore the vsg test configuration on test case failures"""
A R Karthick7b6a3242017-11-17 14:33:59 -0800227 while cls.restore_methods:
228 restore_method = cls.restore_methods.pop()
A R Karthick9a16a112017-04-07 15:40:05 -0700229 restore_method()
230
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000231 def get_vsg_vcpe_pair(self):
232 vcpes = self.vcpes_dhcp
233 vcpe_containers = []
234 vsg_vcpe = {}
235 for vcp in vcpes:
A R Karthickb2638632017-10-25 16:01:16 -0700236 vcpe_container = 'vsg-{}-{}'.format(vcp['s_tag'], vcp['c_tag'])
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000237 vcpe_containers.append(vcpe_container)
238 vsg = VSGAccess.get_vcpe_vsg(vcpe_container)
239 vsg_vcpe[vcpe_container]=str(vsg.get_ip())
240 return vsg_vcpe
241
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000242 def get_vcpe_containers_and_interfaces(self):
243 vcpe_containers = {}
244 vcpe_interfaces = []
245 vcpes = self.vcpes_dhcp
246 count = 0
247 for vcpe in vcpes:
248 vcpe_intf = 'vcpe{}.{}.{}'.format(count,vcpe['s_tag'],vcpe['c_tag'])
249 vcpe_interfaces.append(vcpe_intf)
A R Karthickb2638632017-10-25 16:01:16 -0700250 vcpe_container = 'vsg-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag'])
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000251 vcpe_containers[vcpe_intf] = vcpe_container
252 count += 1
253 log.info('vcpe interfaces are %s'%vcpe_interfaces)
254 log.info('vcpe containers are %s'%vcpe_containers)
255 return vcpe_interfaces,vcpe_containers
256
257 def get_vcpe_interface_dhcp_ip(self,vcpe=None):
258 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000259 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000260 st, _ = getstatusoutput('dhclient {}'.format(vcpe))
261 vcpe_ip = get_ip(vcpe)
262 return vcpe_ip
263
264 def release_vcpe_interface_dhcp_ip(self,vcpe=None):
265 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000266 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000267 st, _ = getstatusoutput('dhclient {} -r'.format(vcpe))
268 vcpe_ip = get_ip(vcpe)
269 assert_equal(vcpe_ip, None)
270
271 def add_static_route_via_vcpe_interface(self, routes, vcpe=None,dhcp_ip=True):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000272 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000273 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000274 if dhcp_ip:
A R Karthick035d2e22017-04-25 13:53:00 -0700275 os.system('dhclient '+vcpe)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000276 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000277 for route in routes:
A R Karthick035d2e22017-04-25 13:53:00 -0700278 log.info('route is %s'%route)
279 cmd = 'ip route add ' + route + ' via 192.168.0.1 '+ 'dev ' + vcpe
A R Karthick035d2e22017-04-25 13:53:00 -0700280 os.system(cmd)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000281 return True
282
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000283 def del_static_route_via_vcpe_interface(self,routes,vcpe=None,dhcp_release=True):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000284 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000285 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000286 cmds = []
287 for route in routes:
A R Karthick035d2e22017-04-25 13:53:00 -0700288 cmd = 'ip route del ' + route + ' via 192.168.0.1 ' + 'dev ' + vcpe
289 os.system(cmd)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000290 if dhcp_release:
A R Karthick035d2e22017-04-25 13:53:00 -0700291 os.system('dhclient '+vcpe+' -r')
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000292 return True
293
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000294 def vsg_for_external_connectivity(self, subscriber_index, reserved = False):
295 if reserved is True:
296 if self.on_pod is True:
297 vcpe = self.dhcp_vcpes_reserved[subscriber_index]
298 else:
299 vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index]
300 else:
301 if self.on_pod is True:
302 vcpe = self.dhcp_vcpes[subscriber_index]
303 else:
304 vcpe = self.untagged_dhcp_vcpes[subscriber_index]
305 mgmt = 'eth0'
306 host = '8.8.8.8'
307 self.success = False
308 assert_not_equal(vcpe, None)
A R Karthick7b6a3242017-11-17 14:33:59 -0800309 vcpe_ip = self.get_dhcp(vcpe, mgmt = mgmt)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000310 assert_not_equal(vcpe_ip, None)
311 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
312 log.info('Sending icmp echo requests to external network 8.8.8.8')
313 st, _ = getstatusoutput('ping -c 3 8.8.8.8')
314 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
A R Karthick7b6a3242017-11-17 14:33:59 -0800315 self.restore_methods.pop()
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000316 assert_equal(st, 0)
317
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000318 def get_vsg_health_check(self, vsg_name=None):
319 if self.on_pod is False:
320 return
321 if vsg_name is None:
322 vcpe = self.container_vcpes_reserved[0]
323 vsg = VSGAccess.get_vcpe_vsg(vcpe)
324 status = vsg.get_health()
325 return status
326 else:
327 vsgs = VSGAccess.get_vsgs()
328 for vsg in vsgs:
329 if vsg.name == vsg_name:
330 status = vsg.get_health()
331 return status
332 return None
333
A R Karthick63751492017-03-22 09:28:01 -0700334 def test_vsg_health(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000335 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000336 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000337 1. Login to compute node VM
338 2. Get all vSGs
339 3. Ping to all vSGs
340 4. Verifying Ping success
341 """
A R Karthick93ba8d02017-04-13 11:59:58 -0700342 status = True
A R Karthick19771192017-04-25 14:57:05 -0700343 if self.on_pod is True:
A R Karthick93ba8d02017-04-13 11:59:58 -0700344 status = VSGAccess.health_check()
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700345 assert_equal(status, True)
Chetan Gaonker52418832017-01-26 23:03:13 +0000346
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000347 def test_vsg_health_check(self, vsg_name=None, verify_status=True):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000348 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000349 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000350 1. If vsg name not specified, Get vsg corresponding to vcpe
351 1. Login to compute mode VM
352 3. Ping to the vSG
353 4. Verifying Ping success
354 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000355 st = self.get_vsg_health_check(vsg_name=vsg_name)
356 assert_equal(st,verify_status)
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000357
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000358 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700359 def test_vsg_for_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000360 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000361 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000362 1. Get list of all compute nodes created using Openstack
363 2. Login to compute mode VM
364 3. Get all vSGs
365 4. Verifying atleast one compute node and one vSG created
366 """
A R Karthick035d2e22017-04-25 13:53:00 -0700367 df = defer.Deferred()
368 def vsg_for_vcpe_df(df):
A R Karthick19771192017-04-25 14:57:05 -0700369 if self.on_pod is True:
A R Karthick93ba8d02017-04-13 11:59:58 -0700370 vsgs = VSGAccess.get_vsgs()
371 compute_nodes = VSGAccess.get_compute_nodes()
372 time.sleep(14)
373 assert_not_equal(len(vsgs), 0)
374 assert_not_equal(len(compute_nodes), 0)
A R Karthick035d2e22017-04-25 13:53:00 -0700375 df.callback(0)
376 reactor.callLater(0,vsg_for_vcpe_df,df)
377 return df
Chetan Gaonker52418832017-01-26 23:03:13 +0000378
A R Karthick63751492017-03-22 09:28:01 -0700379 def test_vsg_for_login(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000380 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000381 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000382 1. Login to compute node VM
383 2. Get all vSGs
384 3. Verifying login to vSG is success
385 """
A R Karthick19771192017-04-25 14:57:05 -0700386 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700387 return
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700388 vsgs = VSGAccess.get_vsgs()
389 vsg_access_status = map(lambda vsg: vsg.check_access(), vsgs)
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700390 status = filter(lambda st: st == False, vsg_access_status)
391 assert_equal(len(status), 0)
392
A R Karthick63751492017-03-22 09:28:01 -0700393 def test_vsg_for_default_route_through_testclient(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000394 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000395 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000396 1. Login to head node
397 2. Verifying for default route in lxc test client
398 """
A R Karthick19771192017-04-25 14:57:05 -0700399 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700400 return
A R Karthick63751492017-03-22 09:28:01 -0700401 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
402 cmd = "sudo lxc exec testclient -- route | grep default"
403 status, output = ssh_agent.run_cmd(cmd)
404 assert_equal(status, True)
405
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000406 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700407 def test_vsg_for_external_connectivity_through_testclient(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000408 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000409 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000410 1. Login to head node
411 2. On head node, executing ping to 8.8.8.8 from lxc test client
412 3. Verifying for the ping success
413 """
A R Karthick19771192017-04-25 14:57:05 -0700414 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700415 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000416 df = defer.Deferred()
417 def test_external_connectivity(df):
418 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
419 cmd = "sudo lxc exec testclient -- ping -c 3 8.8.8.8"
420 status, output = ssh_agent.run_cmd(cmd)
421 assert_equal( status, True)
422 df.callback(0)
423 reactor.callLater(0,test_external_connectivity,df)
424 return df
A R Karthick63751492017-03-22 09:28:01 -0700425
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000426 @deferred(30)
A R Karthick035d2e22017-04-25 13:53:00 -0700427 def test_vsg_for_external_connectivity(self):
428 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000429 Test Method:
A R Karthick035d2e22017-04-25 13:53:00 -0700430 1. Get dhcp IP to vcpe interface in cord-tester
431 2. Verifying vcpe interface gets dhcp IP
432 3. Ping to 8.8.8.8 and Verifying ping should success
433 4. Restoring management interface configuration in cord-tester
434 """
A R Karthick19771192017-04-25 14:57:05 -0700435 reserved = True
436 if self.on_pod:
437 reserved = self.on_ciab
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000438 df = defer.Deferred()
439 def test_external_connectivity(df):
440 self.vsg_for_external_connectivity(0, reserved = reserved)
441 df.callback(0)
442 reactor.callLater(0,test_external_connectivity,df)
443 return df
A R Karthick035d2e22017-04-25 13:53:00 -0700444
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000445 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700446 def test_vsg_for_external_connectivity_to_google(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000447 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000448 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000449 1. Get dhcp IP to vcpe interface in cord-tester
450 2. Verifying vcpe interface gets dhcp IP
451 3. Ping to www.google.com and Verifying ping should success
452 4. Restoring management interface configuration in cord-tester
453 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000454 df = defer.Deferred()
455 def test_external_connectivity(df):
456 host = 'www.google.com'
457 vcpe = self.dhcp_vcpes_reserved[0]
458 mgmt = 'eth0'
459 assert_not_equal(vcpe, None)
460 try:
461 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
462 assert_not_equal(vcpe_ip, None)
463 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
464 log.info('Sending icmp ping requests to %s' %host)
465 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
466 assert_equal(st, 0)
467 except Exception as error:
468 log.info('Got Unexpected error %s'%error)
469 raise
470 finally:
471 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
472 df.callback(0)
473 reactor.callLater(0,test_external_connectivity,df)
474 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000475
A R Karthickb2618052017-05-10 09:23:22 -0700476 def retrieve_content_from_host_to_validate_path_mtu(self, host):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000477 vcpe = self.dhcp_vcpes_reserved[0]
A R Karthickb2618052017-05-10 09:23:22 -0700478 mgmt = 'eth0'
479 assert_not_equal(vcpe, None)
480 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
481 assert_not_equal(vcpe_ip, None)
482 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
483 log.info('Initiating get requests to %s' %host)
484 r = requests.get('http://{}'.format(host))
485 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
486 return r.status_code
487
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000488 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000489 def test_vsg_to_retrieve_content_from_google_to_validate_path_mtu(self):
490 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000491 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000492 1. Get dhcp IP to vcpe interface in cord-tester
493 2. Verifying vcpe interface gets dhcp IP
494 3. Retrieve contents from www.google.com and Verify response status is 200 ok.
495 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
496 (Based on website response, size differs, needs check on MTU)
497 4. Restoring management interface configuration in cord-tester
498 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000499 df = defer.Deferred()
500 def test_external_connectivity(df):
501 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.google.com')
502 assert_equal(status_code, 200)
503 df.callback(0)
504 reactor.callLater(0,test_external_connectivity,df)
505 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000506
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000507 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000508 def test_vsg_to_retrieve_content_from_rediff_to_validate_path_mtu(self):
509 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000510 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000511 1. Get dhcp IP to vcpe interface in cord-tester
512 2. Verifying vcpe interface gets dhcp IP
513 3. Retrieve contents from www.rediff.com and Verify response status is 200 ok.
514 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
515 (Based on website response, size differs, needs check on MTU)
516 4. Restoring management interface configuration in cord-tester
517 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000518 df = defer.Deferred()
519 def test_external_connectivity(df):
520 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.rediff.com')
521 assert_equal(status_code, 200)
522 df.callback(0)
523 reactor.callLater(0,test_external_connectivity,df)
524 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000525
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000526 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000527 def test_vsg_to_retrieve_content_from_yahoo_to_validate_path_mtu(self):
528 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000529 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000530 1. Get dhcp IP to vcpe interface in cord-tester
531 2. Verifying vcpe interface gets dhcp IP
532 3. Retrieve contents from www.yahoo.com and Verify response status is 200 ok.
533 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
534 (Based on website response, size differs, needs check on MTU)
535 4. Restoring management interface configuration in cord-tester
536 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000537 df = defer.Deferred()
538 def test_external_connectivity(df):
539 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.yahoo.com')
540 assert_equal(status_code, 200)
541 df.callback(0)
542 reactor.callLater(0,test_external_connectivity,df)
543 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000544
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000545 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000546 def test_vsg_to_retrieve_content_from_facebook_to_validate_path_mtu(self):
547 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000548 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000549 1. Get dhcp IP to vcpe interface in cord-tester
550 2. Verifying vcpe interface gets dhcp IP
551 3. Retrieve contents from www.facebook.com and Verify response status is 200 ok.
552 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
553 (Based on website response, size differs, needs check on MTU)
554 4. Restoring management interface configuration in cord-tester
555 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000556 df = defer.Deferred()
557 def test_external_connectivity(df):
558 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.facebook.com')
559 assert_equal(status_code, 200)
560 df.callback(0)
561 reactor.callLater(0,test_external_connectivity,df)
562 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000563
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000564
565 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700566 def test_vsg_for_external_connectivity_to_invalid_host(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000567 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000568 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000569 1. Get dhcp IP to vcpe interface in cord-tester
570 2. Verifying vcpe interface gets dhcp IP
571 3. Ping to www.goglee.com and Verifying ping should not success
572 4. Restoring management interface configuration in cord-tester
573 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000574 df = defer.Deferred()
575 def test_external_connectivity(df):
576 host = 'www.goglee.com'
577 vcpe = self.dhcp_vcpes_reserved[0]
578 mgmt = 'eth0'
579 assert_not_equal(vcpe, None)
580 try:
581 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
582 assert_not_equal(vcpe_ip, None)
583 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
584 log.info('Sending icmp ping requests to non existent host %s' %host)
585 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
586 assert_not_equal(st, 0)
587 except Exception as error:
588 log.info('Got Unexpected error %s'%error)
589 raise
590 finally:
591 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
592 df.callback(0)
593 reactor.callLater(0,test_external_connectivity,df)
594 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000595
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000596 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700597 def test_vsg_for_external_connectivity_with_ttl_1(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000598 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000599 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000600 1. Get dhcp IP to vcpe interface in cord-tester
601 2. Verifying vcpe interface gets dhcp IP
602 3. Ping to 8.8.8.8 with ttl set to 1
603 4. Verifying ping should not success
604 5. Restoring management interface configuration in cord-tester
605 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000606 df = defer.Deferred()
607 def test_external_connectivity(df):
608 host = '8.8.8.8'
609 vcpe = self.dhcp_vcpes_reserved[0]
610 mgmt = 'eth0'
611 assert_not_equal(vcpe, None)
612 try:
613 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
614 assert_not_equal(vcpe_ip, None)
615 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
616 log.info('Sending icmp ping requests to host %s with ttl 1' %host)
617 st, _ = getstatusoutput('ping -c 1 -t 1 {}'.format(host))
618 assert_not_equal(st, 0)
619 except Exception as error:
620 log.info('Got Unexpected error %s'%error)
621 raise
622 finally:
623 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
624 df.callback(0)
625 reactor.callLater(0,test_external_connectivity,df)
626 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000627
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000628 @deferred(60)
A R Karthick63751492017-03-22 09:28:01 -0700629 def test_vsg_for_external_connectivity_with_wan_interface_toggle_in_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000630 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000631 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000632 1. Get dhcp IP to vcpe interface in cord-tester
633 2. Verifying vcpe interface gets dhcp IP
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700634 3. Ping to 8.8.8.8 and Verifying ping succeeds
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000635 4. Now down the WAN interface of vcpe
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700636 5. Ping to 8.8.8.8 and Verifying ping fails
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000637 6. Now Up the WAN interface of vcpe
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700638 7. Ping to 8.8.8.8 and Verifying ping succeeds
639 8. Restoring management interface configuration in cord-tester
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000640 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000641 df = defer.Deferred()
642 def test_external_connectivity(df):
643 if self.on_pod is False:
644 return
645 host = '8.8.8.8'
646 mgmt = 'eth0'
647 vcpe = self.dhcp_vcpes_reserved[0]
648 vcpe_name = self.container_vcpes_reserved[0]
649 assert_not_equal(vcpe_name, None)
650 assert_not_equal(vcpe, None)
651 #first get dhcp on the vcpe interface
652 try:
653 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
654 assert_not_equal(vcpe_ip, None)
655 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
656 log.info('Sending ICMP pings to host %s' %(host))
657 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
658 if st != 0:
659 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
660 assert_equal(st, 0)
661 #bring down the wan interface and check again
662 st = VSGAccess.vcpe_wan_down(vcpe_name)
663 if st is False:
664 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
665 assert_equal(st, True)
666 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
667 if st == 0:
668 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
669 assert_not_equal(st, 0)
670 st = VSGAccess.vcpe_wan_up(vcpe_name)
671 if st is False:
672 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
673 assert_equal(st, True)
674 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
675 assert_equal(st, 0)
676 except Exception as error:
677 log.info('Got Unexpected error %s'%error)
678 raise
679 finally:
680 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
681 df.callback(0)
682 reactor.callLater(0,test_external_connectivity,df)
683 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000684
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000685 @deferred(60)
A R Karthick63751492017-03-22 09:28:01 -0700686 def test_vsg_for_external_connectivity_with_lan_interface_toggle_in_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000687 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000688 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000689 1. Get dhcp IP to vcpe interface in cord-tester
690 2. Verifying vcpe interface gets dhcp IP
691 3. Ping to 8.8.8.8 and Verifying ping should success
692 4. Now down the LAN interface of vcpe
693 5. Ping to 8.8.8.8 and Verifying ping should not success
694 6. Now Up the LAN interface of vcpe
695 7. Ping to 8.8.8.8 and Verifying ping should success
696 8. Restoring management interface configuration in cord-tester
697 """
A R Karthick19771192017-04-25 14:57:05 -0700698 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700699 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000700 df = defer.Deferred()
701 def test_external_connectivity(df):
702 host = '8.8.8.8'
703 mgmt = 'eth0'
704 vcpe = self.dhcp_vcpes_reserved[0]
705 vcpe_name = self.container_vcpes_reserved[0]
706 assert_not_equal(vcpe, None)
707 assert_not_equal(vcpe_name, None)
708 #first get dhcp on the vcpe interface
709 try:
710 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
711 assert_not_equal(vcpe_ip, None)
712 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
713 log.info('Sending ICMP pings to host %s' %(host))
714 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
715 if st != 0:
716 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
717 assert_equal(st, 0)
718 #bring down the lan interface and check again
719 st = VSGAccess.vcpe_lan_down(vcpe_name)
720 if st is False:
721 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
722 assert_equal(st, True)
723 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
724 if st == 0:
725 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
726 assert_not_equal(st, 0)
727 st = VSGAccess.vcpe_lan_up(vcpe_name)
728 if st is False:
729 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
730 assert_equal(st, True)
731 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
732 assert_equal(st, 0)
733 except Exception as error:
734 log.info('Got Unexpected error %s'%error)
735 raise
736 finally:
737 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
738 df.callback(0)
739 reactor.callLater(0,test_external_connectivity,df)
740 return df
Chetan Gaonker52418832017-01-26 23:03:13 +0000741
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000742 @deferred(120)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +0000743 def test_vsg_multiple_subscribers_for_same_vcpe_instance(self):
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000744 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000745 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000746 1. Create a vcpe instance
747 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance
748 3. Verify all the interfaces gets dhcp IP in same subnet
749 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000750 df = defer.Deferred()
751 def test_external_connectivity(df):
752 vcpe_intfs,containers = self.get_vcpe_containers_and_interfaces()
753 for vcpe in vcpe_intfs:
754 vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe)
755 assert_not_equal(vcpe_ip,None)
756 for vcpe in vcpe_intfs:
757 self.release_vcpe_interface_dhcp_ip(vcpe=vcpe)
758 df.callback(0)
759 reactor.callLater(0,test_external_connectivity,df)
760 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000761
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000762 @deferred(120)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000763 def test_vsg_for_multiple_subscribers_with_same_vcpe_instance_and_validate_external_connectivity(self):
764 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000765 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000766 1. Create a vcpe instance
767 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance
768 3. Verify all the interfaces gets dhcp IP in same subnet
769 4. From cord-tester ping to external with vcpe interface option
770 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000771 df = defer.Deferred()
772 def test_external_connectivity(df):
773 host = '8.8.8.8'
774 vcpe_intfs, containers = self.get_vcpe_containers_and_interfaces()
775 try:
776 for vcpe in vcpe_intfs:
777 vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe)
778 assert_not_equal(vcpe_ip,None)
779 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_ip=False)
780 st, _ = getstatusoutput('ping -I {} -c 3 {}'.format(vcpe,host))
781 assert_equal(st, 0)
782 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_release=False)
783 except Exception as error:
784 log.info('Got Unexpected error %s'%error)
785 raise
786 finally:
787 for vcpe in vcpe_intfs:
788 self.release_vcpe_interface_dhcp_ip(vcpe=vcpe)
789 df.callback(0)
790 reactor.callLater(0,test_external_connectivity,df)
791 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000792
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000793 @deferred(30)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000794 def test_vsg_vcpe_interface_and_validate_dhcp_ip_after_interface_toggle(self):
795 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000796 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000797 1. Create a vcpe instance
798 2. Create a vcpe interface in cord-tester
799 3. Verify the interface gets dhcp IP
800 4. Toggle the interface
801 5. Verify the interface gets dhcp IP
802 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000803 df = defer.Deferred()
804 def test_external_connectivity(df):
805 vcpe_intf = self.dhcp_vcpes_reserved[0]
806 host = '8.8.8.8'
807 try:
808 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
809 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
810 assert_equal(st, 0)
811 os.system('ifconfig {} down'.format(vcpe_intf))
812 time.sleep(1)
813 os.system('ifconfig {} up'.format(vcpe_intf))
814 time.sleep(1)
815 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
816 assert_equal(st, 0)
817 except Exception as error:
818 log.info('Got Unexpected error %s'%error)
819 raise
820 finally:
821 self.del_static_route_via_vcpe_interface([host], vcpe=vcpe_intf)
822 df.callback(0)
823 reactor.callLater(0,test_external_connectivity,df)
824 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000825
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000826 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000827 def test_vsg_for_external_connectivity_after_restarting_vcpe_instance(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000828 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000829 Test Method:
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000830 1. Get vSG corresponding to vcpe
831 2. Get dhcp ip to vcpe interface
832 3. Add static route to destination route in test container
833 4. From test container ping to destination route and verify ping success
834 5. Login to compute node and execute command to pause vcpe container
835 6. From test container ping to destination route and verify ping success
836 """
837 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000838 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000839 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000840 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000841 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000842 def test_external_connectivity(df):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000843 if self.on_pod is False:
844 df.callback(0)
845 return
846 host = '8.8.8.8'
847 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
848 try:
849 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
850 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
851 assert_equal(st, False)
852 st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000853 clock = 0
854 status = False
855 while(clock <= 20):
856 time.sleep(5)
857 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
858 if st == False:
859 status = True
860 break
861 clock += 5
862 assert_equal(status, True)
863 except Exception as error:
864 log.info('Got Unexpected error %s'%error)
865 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
866 raise
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000867 finally:
868 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
869 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000870 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000871 return df
872
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000873 @nottest #Setup getting distrubed if vSG VM restart
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000874 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000875 def test_vsg_for_external_connectivity_after_restarting_vsg_vm(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000876 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000877 Test Method:
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000878 1. Get vSG corresponding to vcpe
879 2. Get dhcp ip to vcpe interface
880 3. Add static route to destination route in test container
881 4. From test container ping to destination route and verify ping success
882 5. Login to compute node and execute command to pause vcpe container
883 6. From test container ping to destination route and verify ping success
884 """
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000885 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000886 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000887 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000888 def test_external_connectivity(df):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000889 if self.on_pod is False:
890 df.callback(0)
891 return
892 host = '8.8.8.8'
893 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
894 try:
895 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
896 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
897 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000898 vsg.reboot()
899 clock = 0
900 status = False
901 while(clock <= 30):
902 time.sleep(5)
903 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
904 if st == False:
905 status = True
906 break
907 clock += 5
908 assert_equal(status, True)
909 except Exception as error:
910 log.info('Got Unexpected error %s'%error)
911 vsg.reboot()
912 raise
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000913 finally:
914 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
915 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000916 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000917 return df
918
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000919 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000920 def test_vsg_for_external_connectivity_with_vcpe_container_paused(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000921 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000922 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000923 1. Get vSG corresponding to vcpe
924 2. Get dhcp ip to vcpe interface
925 3. Add static route to destination route in test container
926 4. From test container ping to destination route and verify ping success
927 5. Login to compute node and execute command to pause vcpe container
928 6. From test container ping to destination route and verify ping success
929 """
930 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000931 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000932 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000933 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000934 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000935 def test_external_connectivity(df):
A R Karthick19771192017-04-25 14:57:05 -0700936 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700937 df.callback(0)
938 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000939 host = '8.8.8.8'
940 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
941 try:
942 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
943 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
944 assert_equal(st, False)
945 st, _ = vsg.run_cmd('sudo docker pause {}'.format(vcpe_name))
946 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
947 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000948 vsg.run_cmd('sudo docker unpause {}'.format(vcpe_name))
949 except Exception as error:
950 log.info('Got Unexpected error %s'%error)
951 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
952 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000953 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000954 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
955 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000956 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000957 return df
958
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000959 @deferred(30)
960 def test_vsg_firewall_with_deny_destination_ip_set(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000961 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000962 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000963 1. Get vSG corresponding to vcpe
964 2. Login to compute node
965 3. Execute iptable command on vcpe from compute node to deny a destination IP
966 4. From cord-tester ping to the denied IP address
967 5. Verifying that ping should not be successful
968 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000969 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000970 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000971 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000972 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000973 df = defer.Deferred()
974 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -0700975 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700976 df.callback(0)
977 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000978 host = '8.8.8.8'
979 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
980 try:
981 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
982 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
983 assert_equal(st, False)
984 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
985 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
986 assert_equal(st, True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000987 except Exception as error:
988 log.info('Got Unexpected error %s'%error)
989 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000990 finally:
991 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
992 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000993 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000994 df.callback(0)
995 reactor.callLater(0, vcpe_firewall, df)
996 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +0000997
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000998 @deferred(60)
999 def test_vsg_firewall_with_rule_to_add_and_delete_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001000 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001001 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001002 1. Get vSG corresponding to vcpe
1003 2. Login to compute node
1004 3. Execute iptable command on vcpe from compute node to deny a destination IP
1005 4. From cord-tester ping to the denied IP address
1006 5. Verifying that ping should not be successful
1007 6. Delete the iptable rule in vcpe
1008 7. From cord-tester ping to the denied IP address
1009 8. Verifying the ping should success
1010 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001011 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001012 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001013 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001014 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001015 df = defer.Deferred()
1016 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001017 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001018 df.callback(0)
1019 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001020 host = '8.8.8.8'
1021 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1022 try:
1023 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1024 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1025 assert_equal(st, False)
1026 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1027 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1028 assert_equal(st, True)
1029 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1030 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1031 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001032 except Exception as error:
1033 log.info('Got Unexpected error %s'%error)
1034 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1035 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001036 finally:
1037 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1038 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001039 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001040 df.callback(0)
1041 reactor.callLater(0, vcpe_firewall, df)
1042 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001043
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001044 @deferred(40)
1045 def test_vsg_firewall_verifying_reachability_for_non_blocked_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001046 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001047 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001048 1. Get vSG corresponding to vcpe
1049 2. Login to compute node
1050 3. Execute iptable command on vcpe from compute node to deny a destination IP
1051 4. From cord-tester ping to the denied IP address
1052 5. Verifying that ping should not be successful
1053 6. From cord-tester ping to the denied IP address other than the denied one
1054 7. Verifying the ping should success
1055 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001056 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001057 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001058 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001059 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001060 df = defer.Deferred()
1061 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001062 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001063 df.callback(0)
1064 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001065 host1 = '8.8.8.8'
1066 host2 = '204.79.197.203'
1067 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1068 try:
1069 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
1070 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1071 assert_equal(st, False)
1072 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1073 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1074 assert_equal(st, True)
1075 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1076 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001077 except Exception as error:
1078 log.info('Got Unexpected error %s'%error)
1079 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001080 finally:
1081 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1082 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001083 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001084 df.callback(0)
1085 reactor.callLater(0, vcpe_firewall, df)
1086 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001087
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001088 @deferred(60)
1089 def test_vsg_firewall_appending_rules_with_deny_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001090 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001091 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001092 1. Get vSG corresponding to vcpe
1093 2. Login to compute node
1094 3. Execute iptable command on vcpe from compute node to deny a destination IP1
1095 4. From cord-tester ping to the denied IP address IP1
1096 5. Verifying that ping should not be successful
1097 6. Execute iptable command on vcpe from compute node to deny a destination IP2
1098 6. From cord-tester ping to the denied IP address IP2
1099 7. Verifying that ping should not be successful
1100 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001101 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001102 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001103 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001104 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001105 df = defer.Deferred()
1106 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001107 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001108 df.callback(0)
1109 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001110 host1 = '8.8.8.8'
1111 host2 = '204.79.197.203'
1112 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1113 try:
1114 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
1115 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1116 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001117 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1118 assert_equal(st, False)
1119 st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1120 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001121 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1122 assert_equal(st, True)
1123 st, out = getstatusoutput('ping -c 1 {}'.format(host2))
1124 log.info('host2 ping output is %s'%out)
1125 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001126 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,host2))
1127 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001128 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1129 assert_equal(st,True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001130 except Exception as error:
1131 log.info('Got Unexpected error %s'%error)
1132 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001133 finally:
1134 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1135 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1136 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001137 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001138 df.callback(0)
1139 reactor.callLater(0, vcpe_firewall, df)
1140 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001141
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001142 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001143 def test_vsg_firewall_removing_one_rule_denying_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001144 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001145 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001146 1. Get vSG corresponding to vcpe
1147 2. Login to compute node
1148 3. Execute iptable command on vcpe from compute node to deny a destination IP1
1149 4. Execute iptable command on vcpe from compute node to deny a destination IP2
1150 5. From cord-tester ping to the denied IP address IP1
1151 6. Verifying that ping should not be successful
1152 7. From cord-tester ping to the denied IP address IP2
1153 8. Verifying that ping should not be successful
1154 9. Execute iptable command on vcpe from compute node to remove deny a destination IP2 rule
1155 10. From cord-tester ping to the denied IP address IP2
1156 11. Verifying the ping should success
1157 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001158 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001159 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001160 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001161 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001162 df = defer.Deferred()
1163 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001164 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001165 df.callback(0)
1166 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001167 host1 = '8.8.8.8'
1168 host2 = '204.79.197.203'
1169 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1170 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001171 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001172 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1173 assert_equal(st, False)
1174 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1175 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1176 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1177 assert_equal(st, True)
1178 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1179 assert_equal(st,True)
1180 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1181 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1182 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001183 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1184 assert_equal(st, True)
1185 except Exception as error:
1186 log.info('Got Unexpected error %s'%error)
1187 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001188 finally:
1189 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1190 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1191 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001192 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001193 df.callback(0)
1194 reactor.callLater(0, vcpe_firewall, df)
1195 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001196
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001197 @deferred(60)
1198 def test_vsg_firewall_changing_rule_id_deny_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001199 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001200 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001201 1. Get vSG corresponding to vcpe
1202 2. Login to compute node
1203 3. Execute iptable command on vcpe from compute node to deny a destination IP
1204 5. From cord-tester ping to the denied IP address IP1
1205 6. Verifying that ping should not be successful
1206 9. Execute iptable command on vcpe from compute node to change the rule ID to 2 to deny the same destination IP
1207 10. From cord-tester ping to the denied IP address IP
1208 11. Verifying that ping should not be successful
1209 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001210 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001211 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001212 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001213 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001214 df = defer.Deferred()
1215 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001216 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001217 df.callback(0)
1218 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001219 host = '8.8.8.8'
1220 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1221 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001222 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001223 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1224 assert_equal(st, False)
1225 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1226 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1227 assert_equal(st, True)
1228 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP '.format(vcpe_name,host))
1229 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1230 assert_equal(st,True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001231 except Exception as error:
1232 log.info('Got Unexpected error %s'%error)
1233 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001234 finally:
1235 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1236 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001237 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001238 df.callback(0)
1239 reactor.callLater(0, vcpe_firewall, df)
1240 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001241
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001242 @deferred(50)
1243 def test_vsg_firewall_changing_deny_rule_to_accept_dest_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001244 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001245 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001246 1. Get vSG corresponding to vcpe
1247 2. Login to compute node
1248 3. Execute iptable command on vcpe from compute node to deny a destination IP
1249 5. From cord-tester ping to the denied IP address IP1
1250 6. Verifying that ping should not be successful
1251 9. Execute iptable command on vcpe from compute node to accept the same destination IP
1252 10. From cord-tester ping to the accepted IP
1253 11. Verifying the ping should success
1254 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001255 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001256 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001257 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001258 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001259 df = defer.Deferred()
1260 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001261 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001262 df.callback(0)
1263 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001264 host = '8.8.8.8'
1265 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1266 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001267 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001268 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1269 assert_equal(st, False)
1270 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1271 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1272 assert_equal(st, True)
1273 st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -d {} -j ACCEPT'.format(vcpe_name,host))
1274 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1275 assert_equal(st,False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001276 except Exception as error:
1277 log.info('Got Unexpected error %s'%error)
1278 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001279 finally:
1280 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1281 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j ACCEPT'.format(vcpe_name,host))
1282 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001283 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001284 df.callback(0)
1285 reactor.callLater(0, vcpe_firewall, df)
1286 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001287
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001288 @deferred(60)
1289 def test_vsg_firewall_denying_destination_network(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001290 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001291 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001292 1. Get vSG corresponding to vcpe
1293 2. Login to compute node
1294 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet
1295 4. From cord-tester ping to the denied IP address IP1 in the denied subnet
1296 5. Verifying that ping should not be successful
1297 6. From cord-tester ping to the denied IP address IP2 in the denied subnet
1298 7. Verifying that ping should not be successful
1299 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001300 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001301 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001302 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001303 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001304 df = defer.Deferred()
1305 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001306 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001307 df.callback(0)
1308 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001309 network = '204.79.197.192/28'
1310 host1 = '204.79.197.203'
1311 host2 = '204.79.197.210'
1312 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1313 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001314 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001315 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1316 assert_equal(st, False)
1317 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network))
1318 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1319 assert_equal(st, True)
1320 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1321 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001322 except Exception as error:
1323 log.info('Got Unexpected error %s'%error)
1324 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001325 finally:
1326 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network))
1327 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001328 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001329 df.callback(0)
1330 reactor.callLater(0, vcpe_firewall, df)
1331 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001332
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001333 @deferred(60)
1334 def test_vsg_firewall_denying_destination_network_subnet_modification(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001335 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001336 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001337 1. Get vSG corresponding to vcpe
1338 2. Login to compute node
1339 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet
1340 4. From cord-tester ping to the denied IP address IP1 in the denied subnet
1341 5. Verifying that ping should not be successful
1342 6. From cord-tester ping to the denied IP address IP2 in the denied subnet
1343 7. Verifying that ping should not be successful
1344 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001345 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001346 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001347 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001348 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001349 df = defer.Deferred()
1350 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001351 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001352 df.callback(0)
1353 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001354 network1 = '204.79.197.192/28'
1355 network2 = '204.79.197.192/27'
1356 host1 = '204.79.197.203'
1357 host2 = '204.79.197.210'
1358 host3 = '204.79.197.224'
1359 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1360 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001361 self.add_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001362 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1363 assert_equal(st, False)
1364 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network1))
1365 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1366 assert_equal(st, True)
1367 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1368 assert_equal(st,False)
1369 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,network2))
1370 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1371 assert_equal(st, True)
1372 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1373 assert_equal(st, True)
1374 st, _ = getstatusoutput('ping -c 1 {}'.format(host3))
1375 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001376 except Exception as error:
1377 log.info('Got Unexpected error %s'%error)
1378 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001379 finally:
1380 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network1))
1381 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network2))
1382 self.del_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001383 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001384 df.callback(0)
1385 reactor.callLater(0, vcpe_firewall, df)
1386 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001387
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001388 @deferred(40)
1389 def test_vsg_firewall_with_deny_source_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001390 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001391 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001392 1. Get vSG corresponding to vcpe
1393 2. Login to compute node
1394 3. Execute iptable command on vcpe from compute node to deny a source IP
1395 4. From cord-tester ping to 8.8.8.8 from the denied IP
1396 5. Verifying that ping should not be successful
1397 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001398 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001399 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001400 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001401 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001402 df = defer.Deferred()
1403 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001404 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001405 df.callback(0)
1406 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001407 host = '8.8.8.8'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001408 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1409 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001410 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1411 source_ip = get_ip(vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001412 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1413 assert_equal(st, False)
1414 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1415 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1416 assert_equal(st, True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001417 except Exception as error:
1418 log.info('Got Unexpected error %s'%error)
1419 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1420 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001421 finally:
1422 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1423 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001424 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001425 df.callback(0)
1426 reactor.callLater(0, vcpe_firewall, df)
1427 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001428
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001429 @deferred(40)
1430 def test_vsg_firewall_rule_with_add_and_delete_deny_source_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001431 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001432 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001433 1. Get vSG corresponding to vcpe
1434 2. Login to compute node
1435 3. Execute iptable command on vcpe from compute node to deny a source IP
1436 4. From cord-tester ping to 8.8.8.8 from the denied IP
1437 5. Verifying that ping should not be successful
1438 6. Delete the iptable rule in vcpe
1439 7. From cord-tester ping to 8.8.8.8 from the denied IP
1440 8. Verifying the ping should success
1441 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001442 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001443 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001444 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001445 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001446 df = defer.Deferred()
1447 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001448 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001449 df.callback(0)
1450 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001451 host = '8.8.8.8'
1452 source_ip = get_ip(self.vcpe_dhcp)
1453 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1454 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001455 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1456 source_ip = get_ip(vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001457 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1458 assert_equal(st, False)
1459 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1460 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1461 assert_equal(st, True)
1462 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1463 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1464 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001465 except Exception as error:
1466 log.info('Got Unexpected error %s'%error)
1467 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1468 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001469 finally:
1470 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1471 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001472 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001473 df.callback(0)
1474 reactor.callLater(0, vcpe_firewall, df)
1475 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001476
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001477 @deferred(40)
1478 def test_vsg_firewall_rule_with_deny_icmp_protocol_echo_requests_type(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001479 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001480 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001481 1. Get vSG corresponding to vcpe
1482 2. Login to compute node
1483 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets
1484 4. From cord-tester ping to 8.8.8.8
1485 5. Verifying that ping should not be successful
1486 6. Delete the iptable rule
1487 7. From cord-tester ping to 8.8.8.8
1488 8. Verifying the ping should success
1489 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001490 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001491 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001492 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001493 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001494 df = defer.Deferred()
1495 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001496 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001497 df.callback(0)
1498 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001499 host = '8.8.8.8'
1500 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1501 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001502 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001503 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1504 assert_equal(st, False)
1505 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1506 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1507 assert_equal(st, True)
1508 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1509 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1510 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001511 except Exception as error:
1512 log.info('Got Unexpected error %s'%error)
1513 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1514 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001515 finally:
1516 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1517 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001518 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001519 df.callback(0)
1520 reactor.callLater(0, vcpe_firewall, df)
1521 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001522
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001523 @deferred(40)
1524 def test_vsg_firewall_rule_with_deny_icmp_protocol_echo_reply_type(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001525 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001526 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001527 1. Get vSG corresponding to vcpe
1528 2. Login to compute node
1529 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets
1530 4. From cord-tester ping to 8.8.8.8
1531 5. Verifying that ping should not be successful
1532 6. Delete the iptable rule
1533 7. From cord-tester ping to 8.8.8.8
1534 8. Verifying the ping should success
1535 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001536 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001537 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001538 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001539 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001540 df = defer.Deferred()
1541 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001542 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001543 df.callback(0)
1544 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001545 host = '8.8.8.8'
1546 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1547 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001548 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001549 st, _ = getstatusoutput('ping -c 1 {}'.format('8.8.8.8'))
1550 assert_equal(st, False)
1551 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1552 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1553 assert_equal(st, True)
1554 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1555 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1556 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001557 except Exception as error:
1558 log.info('Got Unexpected error %s'%error)
1559 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1560 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001561 finally:
1562 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1563 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001564 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001565 df.callback(0)
1566 reactor.callLater(0, vcpe_firewall, df)
1567 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001568
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001569 @deferred(40)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00001570 def test_vsg_firewall_changing_deny_rule_to_accept_rule_with_icmp_protocol_echo_requests_type(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001571 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001572 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001573 1. Get vSG corresponding to vcpe
1574 2. Login to compute node
1575 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets
1576 4. From cord-tester ping to 8.8.8.8
1577 5. Verifying that ping should not be successful
1578 6. Insert another rule to accept the icmp-echo requests protocol packets
1579 7. From cord-tester ping to 8.8.8.8
1580 8. Verifying the ping should success
1581 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001582 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001583 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001584 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001585 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001586 df = defer.Deferred()
1587 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001588 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001589 df.callback(0)
1590 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001591 host = '8.8.8.8'
1592 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1593 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001594 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001595 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1596 assert_equal(st, False)
1597 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1598 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1599 assert_equal(st, True)
1600 st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name))
1601 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1602 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001603 except Exception as error:
1604 log.info('Got Unexpected error %s'%error)
1605 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001606 finally:
1607 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1608 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name))
1609 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001610 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001611 df.callback(0)
1612 reactor.callLater(0, vcpe_firewall, df)
1613 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001614
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001615 @deferred(40)
1616 def test_vsg_firewall_changing_deny_rule_to_accept_rule_with_icmp_protocol_echo_reply_type(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001617 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001618 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001619 1. Get vSG corresponding to vcpe
1620 2. Login to compute node
1621 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets
1622 4. From cord-tester ping to 8.8.8.8
1623 5. Verifying the ping should not success
1624 6. Insert another rule to accept the icmp-echo requests protocol packets
1625 7. From cord-tester ping to 8.8.8.8
1626 8. Verifying the ping should success
1627 """
1628 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001629 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001630 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001631 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001632 df = defer.Deferred()
1633 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001634 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001635 df.callback(0)
1636 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001637 host = '8.8.8.8'
1638 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1639 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001640 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001641 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1642 assert_equal(st, False)
1643 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1644 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1645 assert_equal(st, True)
1646 st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name))
1647 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1648 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001649 except Exception as error:
1650 log.info('Got Unexpected error %s'%error)
1651 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001652 finally:
1653 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1654 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name))
1655 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001656 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001657 df.callback(0)
1658 reactor.callLater(0, vcpe_firewall, df)
1659 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001660
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001661 @deferred(40)
1662 def test_vsg_firewall_for_deny_icmp_protocol(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001663 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001664 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001665 1. Get vSG corresponding to vcpe
1666 2. Login to compute node
1667 3. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1668 4. From cord-tester ping to 8.8.8.8
1669 5. Verifying that ping should not be successful
1670 6. Delete the iptable rule
1671 7. From cord-tester ping to 8.8.8.8
1672 8. Verifying the ping should success
1673 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001674 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001675 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001676 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001677 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001678 df = defer.Deferred()
1679 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001680 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001681 df.callback(0)
1682 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001683 host = '8.8.8.8'
1684 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1685 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001686 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001687 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1688 assert_equal(st, False)
1689 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1690 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1691 assert_equal(st, True)
1692 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1693 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1694 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001695 except Exception as error:
1696 log.info('Got Unexpected error %s'%error)
1697 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1698 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001699 finally:
1700 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1701 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001702 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001703 df.callback(0)
1704 reactor.callLater(0, vcpe_firewall, df)
1705 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001706
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001707 @deferred(60)
1708 def test_vsg_firewall_rule_deny_icmp_protocol_and_destination_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001709 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001710 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001711 1. Get vSG corresponding to vcpe
1712 2. Login to compute node
1713 3. Execute iptable command on vcpe from compute node to deny a destination IP
1714 4. From cord-tester ping to 8.8.8.8
1715 5. Verifying that ping should not be successful
1716 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1717 7. From cord-tester ping to 8.8.8.8
1718 8. Verifying the ping should success
1719 9. Delete the rule added in step 3
1720 10. From cord-tester ping to 8.8.8.8
1721 11. Verifying that ping should not be successful
1722 12. Delete the rule added in step 6
1723 13. From cord-tester ping to 8.8.8.8
1724 14. Verifying the ping should success
1725 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001726 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001727 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001728 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001729 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001730 df = defer.Deferred()
1731 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001732 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001733 df.callback(0)
1734 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001735 host = '8.8.8.8'
1736 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1737 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001738 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001739 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1740 assert_equal(st, False)
1741 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1742 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1743 assert_equal(st, True)
1744 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1745 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1746 assert_equal(st, True)
1747 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1748 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1749 assert_equal(st, True)
1750 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1751 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1752 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001753 except Exception as error:
1754 log.info('Got Unexpected error %s'%error)
1755 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1756 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1757 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001758 finally:
1759 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1760 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1761 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001762 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001763 df.callback(0)
1764 reactor.callLater(0, vcpe_firewall, df)
1765 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001766
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001767 @deferred(100)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001768 def test_vsg_firewall_flushing_all_configured_rules(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001769 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001770 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001771 1. Get vSG corresponding to vcpe
1772 2. Login to compute node
1773 3. Execute iptable command on vcpe from compute node to deny a destination IP
1774 4. From cord-tester ping to 8.8.8.8
1775 5. Verifying that ping should not be successful
1776 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1777 7. From cord-tester ping to 8.8.8.8
1778 8. Verifying the ping should success
1779 9. Flush all the iptable rules configuraed in vcpe
1780 10. Delete the rule added in step 6
1781 11. From cord-tester ping to 8.8.8.8
1782 12. Verifying the ping should success
1783 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001784 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001785 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001786 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001787 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001788 df = defer.Deferred()
1789 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001790 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001791 df.callback(0)
1792 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001793 host = '8.8.8.8'
1794 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1795 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001796 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001797 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1798 assert_equal(st, False)
1799 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1800 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1801 assert_equal(st, True)
1802 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1803 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1804 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001805 st, _ = vsg.run_cmd('sudo docker exec {} iptables -F FORWARD'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001806 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001807 assert_equal(st, True)
1808 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
1809 status = False
1810 clock = 0
1811 while(clock <= 30):
1812 time.sleep(5)
1813 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1814 if st == False:
1815 status = True
1816 break
1817 clock += 5
1818 assert_equal(status, True)
1819 except Exception as error:
1820 log.info('Got Unexpected error %s'%error)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001821 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001822 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1823 raise
1824 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001825 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001826 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001827 df.callback(0)
1828 reactor.callLater(0, vcpe_firewall, df)
1829 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001830
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001831 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001832 def test_vsg_firewall_deny_all_ipv4_traffic(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001833 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001834 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001835 1. Get vSG corresponding to vcpe
1836 2. Login to compute node
1837 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic
1838 4. From cord-tester ping to 8.8.8.8
1839 5. Verifying that ping should not be successful
1840 6. Delete the iptable rule added
1841 7. From cord-tester ping to 8.8.8.8
1842 8. Verifying the ping should success
1843 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001844 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001845 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001846 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001847 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001848 df = defer.Deferred()
1849 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001850 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001851 df.callback(0)
1852 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001853 host = '8.8.8.8'
1854 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1855 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001856 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001857 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1858 assert_equal(st, False)
1859 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
1860 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1861 assert_equal(st, True)
1862 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1863 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1864 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001865 except Exception as error:
1866 log.info('Got Unexpected error %s'%error)
1867 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1868 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001869 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001870 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001871 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001872 df.callback(0)
1873 reactor.callLater(0, vcpe_firewall, df)
1874 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00001875
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001876 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001877 def test_vsg_firewall_replacing_deny_rule_to_accept_rule_ipv4_traffic(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001878 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001879 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001880 1. Get vSG corresponding to vcpe
1881 2. Login to compute node
1882 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic
1883 4. From cord-tester ping to 8.8.8.8
1884 5. Verifying that ping should not be successful
1885 6. Replace the deny rule added in step 3 with accept rule
1886 7. From cord-tester ping to 8.8.8.8
1887 8. Verifying the ping should success
1888 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001889 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001890 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001891 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001892 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001893 df = defer.Deferred()
1894 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001895 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001896 df.callback(0)
1897 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001898 host = '8.8.8.8'
1899 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1900 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001901 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001902 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1903 assert_equal(st, False)
1904 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
1905 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1906 assert_equal(st, True)
1907 st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -4 -j ACCEPT'.format(vcpe_name))
1908 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1909 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001910 except Exception as error:
1911 log.info('Got Unexpected error %s'%error)
1912 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001913 finally:
1914 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1915 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001916 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001917 df.callback(0)
1918 reactor.callLater(0, vcpe_firewall, df)
1919 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00001920
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001921 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001922 def test_vsg_firewall_deny_all_traffic_coming_on_lan_interface_in_vcpe(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001923 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001924 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001925 1. Get vSG corresponding to vcpe
1926 2. Login to compute node
1927 3. Execute iptable command on vcpe from compute node to deny all the traffic coming on lan interface inside vcpe container
1928 4. From cord-tester ping to 8.8.8.8
1929 5. Verifying the ping should not success
1930 6. Delete the iptable rule added
1931 7. From cord-tester ping to 8.8.8.8
1932 8. Verifying the ping should success
1933 """
1934 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001935 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001936 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001937 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001938 df = defer.Deferred()
1939 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001940 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001941 df.callback(0)
1942 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001943 host = '8.8.8.8'
1944 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1945 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001946 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001947 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1948 assert_equal(st, False)
1949 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -j DROP'.format(vcpe_name))
1950 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1951 assert_equal(st, True)
1952 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name))
1953 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1954 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001955 except Exception as error:
1956 log.info('Got Unexpected error %s'%error)
1957 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name))
1958 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001959 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001960 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001961 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001962 df.callback(0)
1963 reactor.callLater(0, vcpe_firewall, df)
1964 return df
1965
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001966 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001967 def test_vsg_firewall_deny_all_traffic_going_out_of_wan_interface_in_vcpe(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001968 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001969 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001970 1. Get vSG corresponding to vcpe
1971 2. Login to compute node
1972 3. Execute iptable command on vcpe from compute node to deny all the traffic going out of wan interface inside vcpe container
1973 4. From cord-tester ping to 8.8.8.8
1974 5. Verifying the ping should not success
1975 6. Delete the iptable rule added
1976 7. From cord-tester ping to 8.8.8.8
1977 8. Verifying the ping should success
1978 """
1979 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001980 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001981 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001982 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001983 df = defer.Deferred()
1984 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001985 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001986 df.callback(0)
1987 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001988 host = '8.8.8.8'
1989 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1990 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001991 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001992 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1993 assert_equal(st, False)
1994 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -o eth0 -j DROP'.format(vcpe_name))
1995 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1996 assert_equal(st, True)
1997 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name))
1998 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1999 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002000 except Exception as error:
2001 log.info('Got Unexpected error %s'%error)
2002 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name))
2003 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002004 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002005 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002006 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002007 df.callback(0)
2008 reactor.callLater(0, vcpe_firewall, df)
2009 return df
2010
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002011 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002012 def test_vsg_firewall_deny_all_traffic_from_lan_to_wan_in_vcpe(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002013 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002014 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002015 1. Get vSG corresponding to vcpe
2016 2. Login to compute node
2017 3. Execute iptable command on vcpe from compute node to deny all the traffic from lan to wan interface in vcpe
2018 4. From cord-tester ping to 8.8.8.8
2019 5. Verifying that ping should not be successful
2020 6. Delete the iptable rule added
2021 7. From cord-tester ping to 8.8.8.8
2022 8. Verifying the ping should success
2023 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002024 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002025 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002026 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002027 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002028 df = defer.Deferred()
2029 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002030 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002031 df.callback(0)
2032 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002033 host = '8.8.8.8'
2034 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2035 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002036 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002037 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2038 assert_equal(st, False)
2039 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2040 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2041 assert_equal(st, True)
2042 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2043 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2044 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002045 except Exception as error:
2046 log.info('Got Unexpected error %s'%error)
2047 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2048 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002049 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002050 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002051 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002052 df.callback(0)
2053 reactor.callLater(0, vcpe_firewall, df)
2054 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00002055
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002056 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002057 def test_vsg_firewall_deny_all_dns_traffic(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002058 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002059 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002060 1. Get vSG corresponding to vcpe
2061 2. Login to compute node
2062 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2063 4. From cord-tester ping to www.google.com
2064 5. Verifying the ping should not success
2065 6. Delete the iptable rule added
2066 7. From cord-tester ping to www.google.com
2067 8. Verifying the ping should success
2068 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002069 mgmt = 'eth0'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002070 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002071 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002072 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002073 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002074 df = defer.Deferred()
2075 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002076 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002077 df.callback(0)
2078 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002079 host = 'google-public-dns-a.google.com'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002080 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2081 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002082 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2083 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002084 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002085 assert_not_equal(st, False)
2086 VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf)
2087 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2088 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002089 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2090 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002091 VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf)
2092 except Exception as error:
2093 log.info('Got Unexpected error %s'%error)
2094 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2095 VSGAccess.restore_interface_config(mgmt,vcpe=vcpe_intf)
2096 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002097 df.callback(0)
2098 reactor.callLater(0, vcpe_firewall, df)
2099 return df
2100
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002101 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002102 def test_vsg_firewall_deny_all_ipv4_traffic_vcpe_container_restart(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002103 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002104 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002105 1. Get vSG corresponding to vcpe
2106 2. Login to compute node
2107 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2108 4. From cord-tester ping to www.google.com
2109 5. Verifying that ping should not be successful
2110 6. Delete the iptable rule added
2111 7. From cord-tester ping to www.google.com
2112 8. Verifying the ping should success
2113 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002114 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002115 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002116 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002117 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002118 df = defer.Deferred()
2119 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002120 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002121 df.callback(0)
2122 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002123 host = '8.8.8.8'
2124 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2125 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002126 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002127 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2128 assert_equal(st, False)
2129 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
2130 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2131 assert_equal(st, True)
2132 st,output = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002133 clock = 0
2134 status = False
2135 while(clock <= 20 ):
2136 time.sleep(5)
2137 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2138 if st == False:
2139 status = True
2140 break
2141 clock += 5
2142 assert_equal(status, True)
2143 except Exception as error:
2144 log.info('Got Unexpected error %s'%error)
2145 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
2146 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002147 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002148 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002149 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002150 df.callback(0)
2151 reactor.callLater(0, vcpe_firewall, df)
2152 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00002153
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002154 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002155 def test_vsg_nat_dnat_modifying_destination_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002156 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002157 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002158 1. Get vSG corresponding to vcpe
2159 2. Login to compute node
2160 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2161 4. From cord-tester ping to www.google.com
2162 5. Verifying the ping should not success
2163 6. Delete the iptable rule added
2164 7. From cord-tester ping to www.google.com
2165 8. Verifying the ping should success
2166 """
2167 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002168 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002169 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002170 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002171 df = defer.Deferred()
2172 def vcpe_firewall(df):
2173 host = '8.8.8.8'
2174 dst_ip = '123.123.123.123'
2175 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2176 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002177 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002178 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2179 assert_equal(st, False)
2180 st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
2181 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2182 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002183 except Exception as error:
2184 log.info('Got Unexpected error %s'%error)
2185 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002186 finally:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002187
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002188 vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
2189 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002190 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002191 df.callback(0)
2192 reactor.callLater(0,vcpe_firewall,df)
2193 return df
2194
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002195 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002196 def test_vsg_nat_dnat_modifying_destination_ip_and_delete(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002197 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002198 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002199 1. Get vSG corresponding to vcpe
2200 2. Login to compute node
2201 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2202 4. From cord-tester ping to www.google.com
2203 5. Verifying the ping should not success
2204 6. Delete the iptable rule added
2205 7. From cord-tester ping to www.google.com
2206 8. Verifying the ping should success
2207 """
2208 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002209 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002210 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002211 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002212 df = defer.Deferred()
2213 def vcpe_firewall(df):
2214 host = '8.8.8.8'
2215 dst_ip = '123.123.123.123'
2216 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2217 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002218 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002219 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2220 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002221 st, _ = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002222 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2223 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002224 st, _ = vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002225 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2226 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002227 except Exception as error:
2228 log.info('Got Unexpected error %s'%error)
2229 vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
2230 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002231 finally:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002232 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002233 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002234 df.callback(0)
2235 reactor.callLater(0,vcpe_firewall,df)
2236 return df
2237
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002238 @deferred(50)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002239 def test_vsg_dnat_change_modifying_destination_ip_address(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002240 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002241 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002242 1. Get vSG corresponding to vcpe
2243 2. Login to compute node
2244 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2245 4. From cord-tester ping to www.google.com
2246 5. Verifying the ping should not success
2247 6. Delete the iptable rule added
2248 7. From cord-tester ping to www.google.com
2249 8. Verifying the ping should success
2250 """
2251 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002252 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002253 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002254 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002255 df = defer.Deferred()
2256 def vcpe_firewall(df):
2257 host = '8.8.8.8'
2258 dst_ip = '123.123.123.123'
2259 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2260 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002261 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002262 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2263 assert_equal(st, False)
2264 st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
2265 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2266 assert_equal(st, True)
2267 st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -R PREROUTING 1 -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,host))
2268 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2269 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002270 except Exception as error:
2271 log.info('Got Unexpected error %s'%error)
2272 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002273 finally:
2274 vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip))
2275 vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,host))
2276 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002277 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002278 df.callback(0)
2279 reactor.callLater(0,vcpe_firewall,df)
2280 return df
2281
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002282 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
A R Karthick19771192017-04-25 14:57:05 -07002283 if self.on_pod is False:
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002284 return ''
2285 if subscriber_info is None:
A R Karthicked3a2ca2017-07-06 15:50:03 -07002286 subscriber_info = self.cord_subscriber.subscriber_info[index]
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002287 if volt_subscriber_info is None:
A R Karthicked3a2ca2017-07-06 15:50:03 -07002288 volt_subscriber_info = self.cord_subscriber.volt_subscriber_info[index]
A R Karthickd0b06792017-04-25 15:11:23 -07002289 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
2290 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
A R Karthickb2638632017-10-25 16:01:16 -07002291 vcpe = 'vsg-{}-{}'.format(s_tag, c_tag)
A R Karthicked3a2ca2017-07-06 15:50:03 -07002292 subId = self.cord_subscriber.subscriberCreate(index, subscriber_info, volt_subscriber_info)
2293 if subId:
A R Karthick97e08852017-04-26 10:06:38 -07002294 #if the vsg instance was already instantiated, then reduce delay
A R Karthicked3a2ca2017-07-06 15:50:03 -07002295 if c_tag % self.SUBSCRIBERS_PER_S_TAG == 0:
A R Karthick97e08852017-04-26 10:06:38 -07002296 delay = 350
2297 else:
2298 delay = 90
2299 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
2300 time.sleep(delay)
2301 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
2302 self.vsg_for_external_connectivity(index)
A R Karthicked3a2ca2017-07-06 15:50:03 -07002303
2304 return subId
A R Karthick97e08852017-04-26 10:06:38 -07002305
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002306 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
A R Karthick97e08852017-04-26 10:06:38 -07002307 if self.on_pod is False:
2308 return
A R Karthicked3a2ca2017-07-06 15:50:03 -07002309 self.cord_subscriber.subscriberDelete(index, subId = subId, voltId = voltId,
2310 subscriber_info = subscriber_info,
2311 volt_subscriber_info = volt_subscriber_info)
A R Karthick035d2e22017-04-25 13:53:00 -07002312
A R Karthicke29c8d42017-04-27 11:38:52 -07002313 def vsg_xos_subscriber_id(self, index):
A R Karthicked3a2ca2017-07-06 15:50:03 -07002314 if self.on_pod is False:
2315 return ''
2316 return self.cord_subscriber.subscriberId(index)
A R Karthicke29c8d42017-04-27 11:38:52 -07002317
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002318 def test_vsg_xos_subscriber_create_reserved(self):
A.R Karthicka2960912017-05-18 18:52:55 -07002319 if self.on_pod is False:
2320 return
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002321 tags_reserved = [ (int(vcpe['s_tag']), int(vcpe['c_tag'])) for vcpe in self.vcpes_reserved ]
A R Karthick028edaf2017-11-06 16:34:57 -08002322 volt_tenants = self.restApiXos.ApiGet('VOLT_TENANT')
2323 subscribers = self.restApiXos.ApiGet('VOLT_SUBSCRIBER')
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002324 reserved_tenants = filter(lambda tenant: (int(tenant['s_tag']), int(tenant['c_tag'])) in tags_reserved, volt_tenants)
2325 reserved_config = []
2326 for tenant in reserved_tenants:
2327 for subscriber in subscribers:
A R Karthick028edaf2017-11-06 16:34:57 -08002328 volt_id = self.cord_subscriber.getVoltId(subscriber)
2329 provider_id = self.cord_subscriber.getProviderInstance(tenant)
2330 if int(volt_id) == int(provider_id):
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002331 volt_subscriber_info = {}
2332 volt_subscriber_info['voltTenant'] = dict(s_tag = tenant['s_tag'],
A R Karthick028edaf2017-11-06 16:34:57 -08002333 c_tag = tenant['c_tag'])
2334 volt_subscriber_info['volt_id'] = volt_id
2335 volt_subscriber_info['service_specific_id'] = subscriber['service_specific_id']
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002336 reserved_config.append( (subscriber, volt_subscriber_info) )
2337 break
2338 else:
A R Karthick028edaf2017-11-06 16:34:57 -08002339 log.info('Subscriber not found for tenant. s_tag: %s, c_tag: %s' %(\
2340 str(tenant['s_tag']),\
2341 str(tenant['c_tag'])))
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002342
2343 for subscriber_info, volt_subscriber_info in reserved_config:
2344 self.vsg_xos_subscriber_delete(0,
2345 subId = str(subscriber_info['id']),
2346 voltId = str(volt_subscriber_info['volt_id']),
2347 subscriber_info = subscriber_info,
2348 volt_subscriber_info = volt_subscriber_info)
2349 subId = self.vsg_xos_subscriber_create(0,
2350 subscriber_info = subscriber_info,
2351 volt_subscriber_info = volt_subscriber_info)
2352 log.info('Created reserved subscriber %s' %(subId))
2353
A R Karthick037cb982017-07-07 17:35:30 -07002354 def vsg_create(self, num_subscribers):
A R Karthicked3a2ca2017-07-06 15:50:03 -07002355 if self.on_pod is False:
2356 return
A R Karthick037cb982017-07-07 17:35:30 -07002357 num_subscribers = min(num_subscribers, len(self.cord_subscriber.subscriber_info))
2358 for index in xrange(num_subscribers):
A R Karthicke29c8d42017-04-27 11:38:52 -07002359 #check if the index exists
2360 subId = self.vsg_xos_subscriber_id(index)
2361 if subId and subId != '0':
2362 self.vsg_xos_subscriber_delete(index, subId = subId)
2363 subId = self.vsg_xos_subscriber_create(index)
2364 log.info('Created Subscriber %s' %(subId))
2365
A R Karthick037cb982017-07-07 17:35:30 -07002366 def test_vsg_xos_subscriber_create_all(self):
2367 self.vsg_create(len(self.cord_subscriber.subscriber_info))
2368
2369 def vsg_delete(self, num_subscribers):
A R Karthicked3a2ca2017-07-06 15:50:03 -07002370 if self.on_pod is False:
2371 return
A R Karthick037cb982017-07-07 17:35:30 -07002372 num_subscribers = min(num_subscribers, len(self.cord_subscriber.subscriber_info))
2373 for index in xrange(num_subscribers):
A R Karthicke29c8d42017-04-27 11:38:52 -07002374 subId = self.vsg_xos_subscriber_id(index)
2375 if subId and subId != '0':
2376 self.vsg_xos_subscriber_delete(index, subId = subId)
2377
A R Karthick037cb982017-07-07 17:35:30 -07002378 def test_vsg_xos_subscriber_delete_all(self):
2379 self.vsg_delete(len(self.cord_subscriber.subscriber_info))
2380
A R Karthick30c2d682017-11-07 10:39:23 -08002381 def __vsg_xos_subscriber_create(self, index):
2382 subId = self.vsg_xos_subscriber_create(index)
2383 assert_not_equal(subId, '')
2384 assert_not_equal(subId, '0')
2385
2386 def __vsg_xos_subscriber_delete(self, index):
2387 self.vsg_xos_subscriber_delete(index)
2388
2389 def test_vsg_xos_subscriber_create(self):
2390 self.__vsg_xos_subscriber_create(0)
2391
2392 def test_vsg_xos_subscriber_create_2(self):
2393 self.__vsg_xos_subscriber_create(1)
2394
2395 def test_vsg_xos_subscriber_create_3(self):
2396 self.__vsg_xos_subscriber_create(2)
2397
2398 def test_vsg_xos_subscriber_create_4(self):
2399 self.__vsg_xos_subscriber_create(3)
2400
2401 def test_vsg_xos_subscriber_create_5(self):
2402 self.__vsg_xos_subscriber_create(4)
2403
2404 def test_vsg_xos_subscriber_delete(self):
2405 self.__vsg_xos_subscriber_delete(0)
2406
2407 def test_vsg_xos_subscriber_delete_2(self):
2408 self.__vsg_xos_subscriber_delete(1)
2409
2410 def test_vsg_xos_subscriber_delete_3(self):
2411 self.__vsg_xos_subscriber_delete(2)
2412
2413 def test_vsg_xos_subscriber_delete_4(self):
2414 self.__vsg_xos_subscriber_delete(3)
2415
2416 def test_vsg_xos_subscriber_delete_5(self):
2417 self.__vsg_xos_subscriber_delete(4)
2418
A R Karthicke29c8d42017-04-27 11:38:52 -07002419 def test_vsg_xos_subscriber_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002420 subId = self.vsg_xos_subscriber_create(0)
2421 if subId and subId != '0':
2422 self.vsg_xos_subscriber_delete(0, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002423
A R Karthicke29c8d42017-04-27 11:38:52 -07002424 def test_vsg_xos_subscriber_2_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002425 subId = self.vsg_xos_subscriber_create(1)
2426 if subId and subId != '0':
2427 self.vsg_xos_subscriber_delete(1, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002428
A R Karthicke29c8d42017-04-27 11:38:52 -07002429 def test_vsg_xos_subscriber_3_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002430 subId = self.vsg_xos_subscriber_create(2)
2431 if subId and subId != '0':
2432 self.vsg_xos_subscriber_delete(2, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002433
A R Karthicke29c8d42017-04-27 11:38:52 -07002434 def test_vsg_xos_subscriber_4_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002435 subId = self.vsg_xos_subscriber_create(3)
2436 if subId and subId != '0':
2437 self.vsg_xos_subscriber_delete(3, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002438
A R Karthicke29c8d42017-04-27 11:38:52 -07002439 def test_vsg_xos_subscriber_5_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002440 subId = self.vsg_xos_subscriber_create(4)
2441 if subId and subId != '0':
2442 self.vsg_xos_subscriber_delete(4, subId)
A.R Karthick282f0d32017-03-28 16:43:59 -07002443
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002444 @deferred(400)
2445 def test_vsg_xos_subscriber_external_connectivity_through_vcpe_instance(self, index=0):
2446 df = defer.Deferred()
2447 status = False
2448 def test_xos_subscriber(df):
2449 subId = self.vsg_xos_subscriber_id(index)
2450 if subId == '0':
2451 log.info('Creating vcpe instance ')
2452 subId = self.vsg_xos_subscriber_create(index)
2453 assert_not_equal(subId,'0')
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002454 vcpe = self.dhcp_vcpes[index]
2455 host = '8.8.8.8'
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002456 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2457 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2458 assert_equal(st, False)
2459 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2460 df.callback(0)
2461 reactor.callLater(0,test_xos_subscriber,df)
2462 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002463
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002464 #pass
2465 @deferred(50)
2466 def test_vsg_xos_subscriber_external_connectivity_without_creating_vcpe_instance(self, index=0):
2467 df = defer.Deferred()
2468 def test_xos_subscriber(df):
2469 subId = self.vsg_xos_subscriber_id(index)
2470 if subId != '0':
2471 log.info('deleting already existing vcpe instance ')
2472 self.vsg_xos_subscriber_delete(index, subId)
2473 vcpe = self.dhcp_vcpes[index]
2474 host = '8.8.8.8'
2475 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2476 st, out = getstatusoutput('route -n')
2477 log.info('route -n outpu-1-1-1--1-1-1-1-1-1-1 is %s'%out)
2478 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2479 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2480 assert_equal(st, True)
2481 df.callback(0)
2482 reactor.callLater(0,test_xos_subscriber,df)
2483 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002484
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002485 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002486 def test_vsg_xos_subscriber_external_connectivity_after_removing_vcpe_instance_from_xos(self,index=0,host = '8.8.8.8'):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002487 df = defer.Deferred()
2488 def test_xos_subscriber(df):
2489 subId = self.vsg_xos_subscriber_id(index)
2490 if subId == '0':
2491 subId = self.vsg_xos_subscriber_create(index)
2492 assert_not_equal(subId,'0')
2493 vcpe = self.dhcp_vcpes[index]
2494 if subId and subId != '0':
2495 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2496 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2497 assert_equal(st, False)
2498 self.vsg_xos_subscriber_delete(index, subId)
2499 time.sleep(2)
2500 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2501 assert_equal(st, True)
2502 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2503 df.callback(0)
2504 reactor.callLater(0,test_xos_subscriber,df)
2505 return df
2506
2507 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002508 def test_vsg_xos_subscriber_external_connectivity_after_restarting_vcpe_instance(self, index=0, host = '8.8.8.8'):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002509 df = defer.Deferred()
2510 def test_xos_subscriber(df):
2511 subId = self.vsg_xos_subscriber_id(index)
2512 if subId == '0':
2513 subId = self.vsg_xos_subscriber_create(index)
2514 assert_not_equal(subId,'0')
2515 vcpe_intf = self.dhcp_vcpes[index]
2516 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2517 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2518 assert_equal(st, False)
A R Karthickb2638632017-10-25 16:01:16 -07002519 vcpe_name = 'vsg-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002520 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2521 st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
2522 assert_equal(st, True)
2523 time.sleep(5)
2524 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2525 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2526 assert_equal(st, False)
2527 df.callback(0)
2528 reactor.callLater(0,test_xos_subscriber,df)
2529 return df
2530
2531 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002532 def test_vsg_xos_subscriber_external_connectivity_toggling_vcpe_instance(self, index=0, host = '8.8.8.8'):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002533 df = defer.Deferred()
2534 def test_xos_subscriber(df):
2535 subId = self.vsg_xos_subscriber_id(index)
2536 if subId == '0':
2537 subId = self.vsg_xos_subscriber_create(index)
2538 assert_not_equal(subId,'0')
2539 vcpe_intf = self.dhcp_vcpes[index]
2540 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2541 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2542 assert_equal(st, False)
A R Karthickb2638632017-10-25 16:01:16 -07002543 vcpe_name = 'vsg-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002544 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2545 st, _ = vsg.run_cmd('sudo docker stop {}'.format(vcpe_name))
2546 assert_equal(st, True)
2547 time.sleep(3)
2548 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2549 assert_equal(st, True)
2550 st, _ = vsg.run_cmd('sudo docker start {}'.format(vcpe_name))
2551 assert_equal(st, True)
2552 time.sleep(5)
2553 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2554 assert_equal(st, False)
2555 df.callback(0)
2556 reactor.callLater(0,test_xos_subscriber,df)
2557 return df
2558
2559 #getting list out of range error while creating vcpe of index 6
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002560 def test_vsg_create_xos_subscribers_in_different_vsg_vm(self, index1=4, index2=6):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002561 indexes = list(index1,index2)
2562 subids = []
2563 for index in indexes:
2564 subId = self.vsg_xos_subscriber_id(index)
2565 if not subId:
2566 subId = self.vsg_xos_subscriber_create(index)
2567 assert_not_equal(subId,'0')
2568 subids.append(subId)
2569 log.info('succesfully created two vcpe instances in two different vSG VMs')
2570 self.vsg_xos_subscriber_delete(index1, subid[0])
2571 self.vsg_xos_subscriber_delete(index2, subid[1])
2572
2573 #Unable to reach external network via vcpes created by XOS
2574 @deferred(TIMEOUT+400)
2575 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_goes_down(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002576 """
2577 Test Method:
2578 1.Create two vcpe instances in two different vsg vms using XOS
2579 2.Verify external connectivity through vcpe instances from cord-tester
2580 3.Kill first vcpe instance
2581 4.Verify external network cant be reachable form first vcpe interface
2582 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002583 df = defer.Deferred()
2584 def test_xos_subscriber(df):
2585 host1 = '8.8.8.8'
2586 host2 = '4.2.2.2'
2587 vcpe_intf1 = self.dhcp_vcpes[0]
2588 vcpe_intf2 = self.dhcp_vcpes[1]
A R Karthickb2638632017-10-25 16:01:16 -07002589 vcpe_name1 = 'vsg-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2590 vcpe_name2 = 'vsg-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002591 subId1 = self.vsg_xos_subscriber_id(0)
2592 log.info('already existing subid of index 0 is %s'%subId1)
2593 if subId1 == '0':
2594 log.info('creating vcpe instance of index 0')
2595 subId1 = self.vsg_xos_subscriber_create(0)
2596 assert_not_equal(subId1,'0')
2597 subId2 = self.vsg_xos_subscriber_id(1)
2598 log.info('already existing subid of index 1 is %s'%subId2)
2599 if subId2 == '0':
2600 log.info('creating vcpe instance of index 1')
2601 subId2 = self.vsg_xos_subscriber_create(1)
2602 assert_not_equal(subId2,'0')
2603 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2604 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2605 try:
2606 for intf in [vcpe_intf1,vcpe_intf2]:
2607 host = host1 if intf is vcpe_intf1 else host2
2608 self.add_static_route_via_vcpe_interface([host],vcpe=intf)
2609 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2610 assert_equal(st, False)
2611 if intf is vcpe_intf2:
2612 self.vsg_xos_subscriber_delete(1, subId2)
2613 st, _ = vsg2.run_cmd('sudo docker kill {}'.format(vcpe_name2))
2614 time.sleep(2)
2615 self.add_static_route_via_vcpe_interface([host],vcpe=intf)
2616 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2617 assert_equal(st, False)
2618 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2619 assert_equal(st, True)
2620 except Exception as error:
2621 log.info('Got Unexpected error %s'%error)
2622 raise
2623 finally:
2624 self.vsg_xos_subscriber_delete(0, subId1)
2625 self.vsg_xos_subscriber_delete(1, subId2)
2626 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2627 self.del_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2628 df.callback(0)
2629 reactor.callLater(0,test_xos_subscriber,df)
2630 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002631
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002632 @deferred(TIMEOUT+400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002633 def test_vsg_xos_subscriber_external_connectivity_after_vcpe_is_removed_and_added_again(self,index=0):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002634 """
2635 Test Method:
2636 1.Create two vcpe instances in two different vsg vms using XOS
2637 2.Verify external connectivity through vcpe instances from cord-tester
2638 3.Remove first vcpe instance
2639 4.Verify external network cant be reachable form first vcpe interface
2640 5.Add back the removed vcpe instance
2641 6.Verify external connectivity through vcpe instances from cord-tester
2642 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002643 df = defer.Deferred()
2644 def test_xos_subscriber(df,index=index):
2645 host = '8.8.8.8'
2646 subId = self.vsg_xos_subscriber_id(index)
2647 log.info('already existing subid of index 0 is %s'%subId)
2648 if subId == '0':
2649 log.info('creating vcpe instance of index %s'%index)
2650 subId = self.vsg_xos_subscriber_create(index)
2651 assert_not_equal(subId,'0')
2652 vcpe_intf = self.dhcp_vcpes[0]
A R Karthickb2638632017-10-25 16:01:16 -07002653 vcpe_name = 'vsg-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002654 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2655 try:
2656 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2657 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2658 assert_equal(st, False)
2659 log.info('Deleting vcpe Instance of index %s'%index)
2660 self.vsg_xos_subscriber_delete(0, subId)
2661 st, _ = vsg.run_cmd('sudo docker kill {}'.format(vcpe_name))
2662 time.sleep(1)
2663 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2664 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2665 assert_equal(st, True)
2666 subId = self.vsg_xos_subscriber_create(index)
2667 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2668 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2669 assert_equal(st, False)
2670 except Exception as error:
2671 log.info('Got Unexpected error %s'%error)
2672 raise
2673 finally:
2674 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2675 self.vsg_xos_subscriber_delete(0, subId)
2676 df.callback(0)
2677 reactor.callLater(0,test_xos_subscriber,df)
2678 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002679
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002680 @deferred(TIMEOUT+400)
2681 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_restarts(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002682 """
2683 Test Method:
2684 1.Create two vcpe instances in two different vsg vms using XOS
2685 2.Verify external connectivity through vcpe instances from cord-tester
2686 3.Restart first vcpe instance
2687 4.Verify external network cant be reachable form first vcpe interface
2688 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002689 df = defer.Deferred()
2690 def test_xos_subscriber(df):
2691 host1 = '8.8.8.8'
2692 host2 = '4.2.2.2'
2693 subId1 = self.vsg_xos_subscriber_id(0)
2694 log.info('already existing subid of index 0 is %s'%subId1)
2695 if subId1 == '0':
2696 log.info('creating vcpe instance of index 0')
2697 subId1 = self.vsg_xos_subscriber_create(0)
2698 assert_not_equal(subId1,'0')
2699 subId2 = self.vsg_xos_subscriber_id(1)
2700 log.info('already existing subid of index 1 is %s'%subId2)
2701 if subId2 == '0':
2702 log.info('creating vcpe instance of index 1')
2703 subId2 = self.vsg_xos_subscriber_create(1)
2704 vcpe_intf1 = self.dhcp_vcpes[0]
2705 vcpe_intf2 = self.dhcp_vcpes[1]
A R Karthickb2638632017-10-25 16:01:16 -07002706 vcpe_name1 = 'vsg-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2707 vcpe_name2 = 'vsg-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002708 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2709 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2710 try:
2711 #checking external connectivity from vcpe interface 1 before vcpe 2 restart
2712 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2713 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2714 assert_equal(st, False)
2715 #checking external connectivity from vcpe interface 2 before vcpe 2 restart
2716 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2717 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2718 assert_equal(st, False)
2719 st, _ = vsg2.run_cmd('sudo docker restart {}'.format(vcpe_name2))
2720 time.sleep(10)
2721 #checking external connectivity from vcpe interface 1 after vcpe 2 restart
2722 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2723 assert_equal(st, False)
2724 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2725 time = 0
2726 status = False
2727 while(time <= 100):
2728 time.sleep(10)
2729 st,_ = getstatusoutput('ping -c 1 {}'.format(hos2))
2730 if st is False:
2731 status = True
2732 break
2733 time += 10
2734 assert_equal(status, True)
2735 except Exception as error:
2736 log.info('Got Unexpected error %s'%error)
2737 raise
2738 finally:
2739 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2740 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2741 self.vsg_xos_subscriber_delete(0, subId1)
2742 self.vsg_xos_subscriber_delete(1, subId2)
2743 df.callback(0)
2744 reactor.callLater(0,test_xos_subscriber,df)
2745 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002746
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002747 @deferred(500)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002748 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_is_paused(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002749 """
2750 Test Method:
2751 1.Create two vcpe instances in two different vsg vms using XOS
2752 2.Verify external connectivity through vcpe instances from cord-tester
2753 3.Pause running first vcpe instance
2754 4.Verify external network cant be reachable form first vcpe interface
2755 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002756 df = defer.Deferred()
2757 def test_xos_subscriber(df):
2758 host1 = '8.8.8.8'
2759 host2 = '4.2.2.2'
2760 subId1 = self.vsg_xos_subscriber_id(0)
2761 log.info('already existing subid of index 0 is %s'%subId1)
2762 if subId1 == '0':
2763 log.info('creating vcpe instance of index 0')
2764 subId1 = self.vsg_xos_subscriber_create(0)
2765 assert_not_equal(subId1,'0')
2766 subId2 = self.vsg_xos_subscriber_id(1)
2767 log.info('already existing subid of index 1 is %s'%subId2)
2768 if subId2 == '0':
2769 log.info('creating vcpe instance of index 1')
2770 subId2 = self.vsg_xos_subscriber_create(1)
2771 vcpe_intf1 = self.dhcp_vcpes[0]
2772 vcpe_intf2 = self.dhcp_vcpes[1]
A R Karthickb2638632017-10-25 16:01:16 -07002773 vcpe_name1 = 'vsg-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2774 vcpe_name2 = 'vsg-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002775 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2776 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2777 try:
2778 #checking external connectivity from vcpe interface 1 before vcpe 2 pause
2779 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2780 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2781 assert_equal(st, False)
2782 #checking external connectivity from vcpe interface 2 before vcpe 2 pause
2783 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2784 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2785 assert_equal(st, False)
2786 st, _ = vsg2.run_cmd('sudo docker pause {}'.format(vcpe_name2))
2787 time.sleep(1)
2788 #checking external connectivity from vcpe interface 1 after vcpe 2 pause
2789 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2790 assert_equal(st, False)
2791 #checking external connectivity from vcpe interface 2 after vcpe 2 pause
2792 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2793 assert_equal(st, True)
2794 except Exception as error:
2795 log.info('Got Unexpected error %s'%error)
2796 raise
2797 finally:
2798 log.info('In Finally block 3333333333333333')
2799 st, _ = vsg2.run_cmd('sudo docker unpause {}'.format(vcpe_name2))
2800 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2801 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2802 self.vsg_xos_subscriber_delete(0, subId1)
2803 self.vsg_xos_subscriber_delete(1, subId2)
2804 df.callback(0)
2805 reactor.callLater(0,test_xos_subscriber,df)
2806 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002807
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002808 @deferred(500)
2809 def test_vsg_xos_subscriber_external_connectivity_if_one_vcpe_stops(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002810 """
2811 Test Method:
2812 1.Create two vcpe instances in two different vsg vms using XOS
2813 2.Verify external connectivity through vcpe instances from cord-tester
2814 3.Stop running first vcpe instance
2815 4.Verify external network cant be reachable form first vcpe interface
2816 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002817 df = defer.Deferred()
2818 def test_xos_subscriber(df):
2819 host1 = '8.8.8.8'
2820 host2 = '4.2.2.2'
2821 subId1 = self.vsg_xos_subscriber_id(0)
2822 log.info('already existing subid of index 0 is %s'%subId1)
2823 if subId1 == '0':
2824 log.info('creating vcpe instance of index 0')
2825 subId1 = self.vsg_xos_subscriber_create(0)
2826 assert_not_equal(subId1,'0')
2827 subId2 = self.vsg_xos_subscriber_id(1)
2828 log.info('already existing subid of index 1 is %s'%subId2)
2829 if subId2 == '0':
2830 log.info('creating vcpe instance of index 1')
2831 subId2 = self.vsg_xos_subscriber_create(1)
2832 vcpe_intf1 = self.dhcp_vcpes[0]
2833 vcpe_intf2 = self.dhcp_vcpes[1]
A R Karthickb2638632017-10-25 16:01:16 -07002834 vcpe_name1 = 'vsg-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2835 vcpe_name2 = 'vsg-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002836 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2837 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2838 try:
2839 #checking external connectivity from vcpe interface 1 before vcpe 2 stop
2840 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2841 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2842 assert_equal(st, False)
2843 #checking external connectivity from vcpe interface 2 before vcpe 2 stop
2844 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2845 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2846 assert_equal(st, False)
2847 st, _ = vsg2.run_cmd('sudo docker stop {}'.format(vcpe_name2))
2848 time.sleep(5)
2849 #checking external connectivity from vcpe interface 1 after vcpe 2 stop
2850 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2851 assert_equal(st, False)
2852 #checking external connectivity from vcpe interface 1 after vcpe 2 stop
2853 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2854 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2855 assert_equal(st, True)
2856 except Exception as error:
2857 log.info('Got Unexpected error %s'%error)
2858 raise
2859 finally:
2860 st, _ = vsg2.run_cmd('sudo docker start {}'.format(vcpe_name2))
2861 time.sleep(10)
2862 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2863 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2864 self.vsg_xos_subscriber_delete(0, subId1)
2865 self.vsg_xos_subscriber_delete(1, subId2)
2866 df.callback(0)
2867 reactor.callLater(0,test_xos_subscriber,df)
2868 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002869
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002870 @deferred(420)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002871 def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_stopped(self, index=0):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002872 """
2873 Test Method:
2874 1.Create two vcpe instances in two different vsg vms using XOS
2875 2.Verify external connectivity through vcpe instances from cord-tester
2876 3.Bring down first vSG vm
2877 4.Verify external network cant be reachable form first vcpe interface
2878 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002879 df = defer.Deferred()
2880 def test_xos_subscriber(df,index=index):
2881 host = '8.8.8.8'
2882 subId = self.vsg_xos_subscriber_id(index)
2883 if subId == '0':
2884 log.info('creating vcpe instance of index 0')
2885 subId = self.vsg_xos_subscriber_create(index)
2886 assert_not_equal(subId,'0')
2887 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
2888 vcpe_name = self.container_vcpes[index]
2889 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2890 try:
2891 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2892 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2893 assert_equal(st, False)
2894 log.info('Stopping vsg instance')
2895 vsg.stop()
2896 time.sleep(5)
2897 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2898 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2899 assert_equal(st, True)
2900 except Exception as error:
2901 log.info('Got Unexpected error %s'%error)
2902 raise
2903 finally:
2904 vsg.start()
2905 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2906 self.vsg_xos_subscriber_delete(index, subId)
2907 df.callback(0)
2908 reactor.callLater(0,test_xos_subscriber,df)
2909 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002910
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002911 @deferred(420)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002912 def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_restarted(self, index=0):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002913 """
2914 Test Method:
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00002915 1.Create subscriber
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002916 2.Verify external connectivity through vcpe instances from cord-tester
2917 3.Bring down first vSG vm
2918 4.Verify external network cant be reachable form first vcpe interface
2919 """
2920 df = defer.Deferred()
2921 def test_xos_subscriber(df,index=index):
2922 host = '8.8.8.8'
2923 subId = self.vsg_xos_subscriber_id(index)
2924 if subId == '0':
2925 log.info('creating vcpe instance of index 0')
2926 subId = self.vsg_xos_subscriber_create(index)
2927 assert_not_equal(subId,'0')
2928 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
2929 vcpe_name = self.container_vcpes[index]
2930 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2931 try:
2932 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2933 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2934 assert_equal(st, False)
2935 log.info('Restarting vsg instance')
2936 vsg.reboot()
2937 time.sleep(10)
2938 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2939 time = 0
2940 status = False
2941 while(time <= 100):
2942 time.sleep(10)
2943 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2944 if st is False:
2945 status = True
2946 break
2947 time += 10
2948 assert_equal(status, True)
2949 except Exception as error:
2950 log.info('Got Unexpected error %s'%error)
2951 raise
2952 finally:
2953 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2954 self.vsg_xos_subscriber_delete(index, subId)
2955 df.callback(0)
2956 reactor.callLater(0,test_xos_subscriber,df)
2957 return df
2958
2959 @deferred(780)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00002960 def test_vsg_xos_multiple_subscribers_external_connectivity_if_two_vsgs_stop_and_start(self, index1=4, index2=6):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002961 """
2962 Test Method:
2963 1.Create two vcpe instances in two different vsg vms using XOS
2964 2.Verify external connectivity through vcpe instances from cord-tester
2965 3.Bring down first vSG vm
2966 4.Verify external network cant be reachable form first vcpe interface
2967 5.Bring down second vSG vm also
2968 6.Verify external network cant be reachable form first vcpe interface also
2969 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002970 df = defer.Deferred(df,index1=index1,index2=index2)
2971 def test_xos_subscriber(df,index=index):
2972 subId1 = self.vsg_xos_subscriber_create(index1)
2973 subId2 = self.vsg_xos_subscriber_create(index2)
2974 if subId1 == '0':
2975 self.vsg_xos_subscriber_delete(index1, subId1)
2976 assert_not_equal(subId1, '0')
2977 if subId2 == '0':
2978 self.vsg_xos_subscriber_delete(index2, subId2)
2979 assert_not_equal(subId2, '0')
2980 for index in [index1,index2]:
2981 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
2982 vcpe_name = self.container_vcpes[index]
2983 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2984 try:
2985 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2986 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2987 assert_equal(st, False)
2988 log.info('Stopping vsg instance of index %s'%index)
2989 vsg.stop()
2990 time.sleep(5)
2991 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2992 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2993 assert_equal(st, True)
2994 except Exception as error:
2995 log.info('Got Unexpected error %s'%error)
2996 raise
2997 finally:
2998 vsg.start()
2999 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3000 df.callback(0)
3001 reactor.callLater(0,test_xos_subscriber,df)
3002 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00003003
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003004 @deferred(420)
3005 def test_vsg_xos_subscriber_external_connectivity_with_creating_firewall_rule(self,index=0):
3006 """
3007 Alog:
3008 1.Cretae a vcpe instance using XOS
3009 2.Get dhcp IP to vcpe interface in cord-tester
3010 3.Verify external network can be reachable from cord-tester
3011 4.Add an iptable rule to drop packets destined to external network in vcpe
3012 5.Verify now external network cant be reachable
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00003013 6.Delele the iptable in vcpe instance
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003014 7.Verify external network can be reachable from cord-tester
3015 """
3016 df = defer.Deferred()
3017 def test_xos_subscriber(df,index=index):
3018 log.info('cls.dhcp_vcpes is %s'%self.dhcp_vcpes)
3019 host = '8.8.8.8'
3020 subId = self.vsg_xos_subscriber_create(index)
3021 if subId == '0':
3022 subId = self.vsg_xos_subscriber_create(index)
3023 assert_not_equal(subId, '0')
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003024 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003025 vcpe_name = self.container_vcpes[index]
3026 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003027 try:
3028 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3029 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003030 #ssert_equal(st, False)
3031 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003032 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
3033 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003034 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
3035 self.vsg_xos_subscriber_delete(index, subId)
3036 except Exception as error:
3037 log.info('Got Unexpected error %s'%error)
3038 raise
3039 finally:
3040 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003041 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003042 self.vsg_xos_subscriber_delete(index, subId)
3043 df.callback(0)
3044 reactor.callLater(0,test_xos_subscriber,df)
3045 return df
A R Karthick63751492017-03-22 09:28:01 -07003046
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003047 def test_vsg_for_packet_received_with_invalid_ip_fields(self):
3048 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003049 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003050 1.Create a vSG VM in compute node
3051 2.Create a vCPE container in vSG VM
3052 3.Ensure vSG VM and vCPE container created properly
3053 4.From subscriber, send a ping packet with invalid ip fields
3054 5.Verify that vSG drops the packet
3055 6.Verify ping fails
3056 """
A R Karthick63751492017-03-22 09:28:01 -07003057
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003058 def test_vsg_for_packet_received_with_invalid_mac_fields(self):
3059 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003060 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003061 1.Create a vSG VM in compute node
3062 2.Create a vCPE container in vSG VM
3063 3.Ensure vSG VM and vCPE container created properly
3064 4.From subscriber, send a ping packet with invalid mac fields
3065 5.Verify that vSG drops the packet
3066 6.Verify ping fails
3067 """
A R Karthick63751492017-03-22 09:28:01 -07003068
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003069 def test_vsg_for_vlan_id_mismatch_in_stag(self):
3070 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003071 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003072 1.Create a vSG VM in compute Node
3073 2.Create a vCPE container in vSG VM
3074 3.Ensure vSG VM and vCPE container created properly
3075 4.Send a ping request to external valid IP from subscriber, with incorrect vlan id in s-tag and valid c-tag
3076 5.Verify that ping fails as the packet drops at VM entry
3077 6.Repeat step 4 with correct s-tag
3078 7.Verify that ping success
3079 """
A R Karthick63751492017-03-22 09:28:01 -07003080
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003081 def test_vsg_for_vlan_id_mismatch_in_ctag(self):
3082 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003083 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003084 1.Create a vSG VM in compute node
3085 2.Create a vCPE container in vSG VM
3086 3.Ensure vSG VM and vCPE container created properly
3087 4.Send a ping request to external valid IP from subscriber, with valid s-tag and incorrect vlan id in c-tag
3088 5.Verify that ping fails as the packet drops at vCPE container entry
3089 6.Repeat step 4 with valid s-tag and c-tag
3090 7.Verify that ping success
3091 """
A R Karthick63751492017-03-22 09:28:01 -07003092
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003093 def test_vsg_for_matching_and_mismatching_vlan_id_in_stag(self):
3094 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003095 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003096 1.Create two vSG VMs in compute node
3097 2.Create a vCPE container in each vSG VM
3098 3.Ensure vSG VM and vCPE container created properly
3099 4.From subscriber one, send ping request with valid s and c tags
3100 5.From subscriber two, send ping request with vlan id mismatch in s-tag and valid c tags
3101 6.Verify that ping success for only subscriber one and fails for two.
3102 """
A R Karthick63751492017-03-22 09:28:01 -07003103
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003104 def test_vsg_for_matching_and_mismatching_vlan_id_in_ctag(self):
3105 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003106 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003107 1.Create a vSG VM in compute node
3108 2.Create two vCPE containers in vSG VM
3109 3.Ensure vSG VM and vCPE container created properly
3110 4.From subscriber one, send ping request with valid s and c tags
3111 5.From subscriber two, send ping request with valid s-tag and vlan id mismatch in c-tag
3112 6.Verify that ping success for only subscriber one and fails for two
3113 """
A R Karthick63751492017-03-22 09:28:01 -07003114
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003115 def test_vsg_for_out_of_range_vlanid_in_ctag(self):
3116 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003117 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003118 1.Create a vSG VM in compute node
3119 2.Create a vCPE container in vSG VM
3120 3.Ensure vSG VM and vCPE container created properly
3121 4.From subscriber, send ping request with valid stag and vlan id in c-tag is an out of range value ( like 0,4097 )
3122 4.Verify that ping fails as the ping packets drops at vCPE container entry
3123 """
A R Karthick63751492017-03-22 09:28:01 -07003124
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003125 def test_vsg_for_out_of_range_vlanid_in_stag(self):
3126 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003127 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003128 1.Create a vSG VM in compute node
3129 2.Create a vCPE container in vSG VM
3130 3.Ensure vSG VM and vCPE container created properly
3131 2.From subscriber, send ping request with vlan id in s-tag is an out of range value ( like 0,4097 ), with valid c-tag
3132 4.Verify that ping fails as the ping packets drops at vSG VM entry
3133 """
A R Karthick63751492017-03-22 09:28:01 -07003134
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003135 def test_vsg_for_extracting_all_compute_stats_from_all_vcpe_containers(self):
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003136 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003137 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003138 1.Create a vSG VM in compute node
3139 2.Create 10 vCPE containers in VM
3140 3.Ensure vSG VM and vCPE containers created properly
3141 4.Login to all vCPE containers
3142 4.Get all compute stats from all vCPE containers
3143 5.Verify the stats # verification method need to add
3144 """
A R Karthick63751492017-03-22 09:28:01 -07003145
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003146 def test_vsg_for_extracting_dns_stats_from_all_vcpe_containers(self):
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003147 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003148 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003149 1.Create a vSG VM in compute node
3150 2.Create 10 vCPE containers in VM
3151 3.Ensure vSG VM and vCPE containers created properly
3152 4.From 10 subscribers, send ping to valid and invalid dns hosts
3153 5.Verify dns resolves and ping success for valid dns hosts
3154 6.Verify ping fails for invalid dns hosts
3155 7.Verify dns host name resolve flows in OvS
3156 8.Login to all 10 vCPE containers
3157 9.Extract all dns stats
3158 10.Verify dns stats for queries sent, queries received for dns host resolve success and failed scenarios
3159 """
A R Karthick037cb982017-07-07 17:35:30 -07003160 pass