blob: 439b94f23564972e1c55e3453a830c78de71b289 [file] [log] [blame]
Chetan Gaonker52418832017-01-26 23:03:13 +00001#copyright 2016-present Ciena Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
A R Karthickd0fdf3b2017-03-21 16:54:22 -070015import time
16import os
A.R Karthick282f0d32017-03-28 16:43:59 -070017import sys
18import json
Chetan Gaonker0bf76312017-05-09 16:48:10 +000019import requests
Chetan Gaonker52418832017-01-26 23:03:13 +000020from nose.tools import *
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +000021from twisted.internet import defer
22from nose.twistedtools import reactor, deferred
A.R Karthick33cfdbe2017-03-17 18:03:48 -070023from CordTestUtils import *
Chetan Gaonker52418832017-01-26 23:03:13 +000024from OltConfig import OltConfig
Chetan Gaonker52418832017-01-26 23:03:13 +000025from onosclidriver import OnosCliDriver
A.R Karthick9ccd0d02017-03-16 17:11:08 -070026from SSHTestAgent import SSHTestAgent
Chetan Gaonker52418832017-01-26 23:03:13 +000027from CordLogger import CordLogger
A R Karthickd0fdf3b2017-03-21 16:54:22 -070028from VSGAccess import VSGAccess
A R Karthick933f5b52017-03-27 15:27:16 -070029from CordTestUtils import log_test as log
A R Karthick19771192017-04-25 14:57:05 -070030from CordTestConfig import setup_module, running_on_ciab
A.R Karthicka9b594d2017-03-29 16:25:22 -070031from OnosCtrl import OnosCtrl
A R Karthickb608d402017-06-02 11:48:41 -070032from CordContainer import Onos
Chetan Gaonker52418832017-01-26 23:03:13 +000033log.setLevel('INFO')
34
35class vsg_exchange(CordLogger):
36 ONOS_INSTANCES = 3
37 V_INF1 = 'veth0'
38 device_id = 'of:' + get_mac()
Chetan Gaonker52418832017-01-26 23:03:13 +000039 TEST_IP = '8.8.8.8'
40 HOST = "10.1.0.1"
41 USER = "vagrant"
42 PASS = "vagrant"
A R Karthick63751492017-03-22 09:28:01 -070043 head_node = os.getenv('HEAD_NODE', 'prod')
A.R Karthick9ccd0d02017-03-16 17:11:08 -070044 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
A R Karthick03f40aa2017-03-20 19:33:55 -070045 test_path = os.path.dirname(os.path.realpath(__file__))
A.R Karthick5968e0d2017-05-16 14:50:46 -070046 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 -070047 restApiXos = None
A R Karthick0a4ca3a2017-03-30 09:36:53 -070048 subscriber_account_num = 200
49 subscriber_s_tag = 304
50 subscriber_c_tag = 304
51 subscribers_per_s_tag = 8
52 subscriber_map = {}
A R Karthickb0cec7c2017-04-21 10:42:54 -070053 subscriber_info = []
54 volt_subscriber_info = []
A R Karthick9a16a112017-04-07 15:40:05 -070055 restore_methods = []
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +000056 TIMEOUT=120
A.R Karthickb145da82017-04-20 14:45:43 -070057 FABRIC_PORT_HEAD_NODE = 1
58 FABRIC_PORT_COMPUTE_NODE = 2
59 APP_NAME = 'org.ciena.xconnect'
60 APP_FILE = os.path.join(test_path, '..', 'apps/xconnect-1.0-SNAPSHOT.oar')
A.R Karthick50f4d9a2017-04-20 16:44:19 -070061 NUM_SUBSCRIBERS = 5
A R Karthick0a4ca3a2017-03-30 09:36:53 -070062
63 @classmethod
64 def getSubscriberCredentials(cls, subId):
65 """Generate our own account num, s_tag and c_tags"""
66 if subId in cls.subscriber_map:
67 return cls.subscriber_map[subId]
68 account_num = cls.subscriber_account_num
69 cls.subscriber_account_num += 1
70 s_tag, c_tag = cls.subscriber_s_tag, cls.subscriber_c_tag
71 cls.subscriber_c_tag += 1
72 if cls.subscriber_c_tag % cls.subscribers_per_s_tag == 0:
73 cls.subscriber_s_tag += 1
74 cls.subscriber_map[subId] = account_num, s_tag, c_tag
75 return cls.subscriber_map[subId]
A.R Karthick282f0d32017-03-28 16:43:59 -070076
77 @classmethod
A.R Karthicka9b594d2017-03-29 16:25:22 -070078 def getXosCredentials(cls):
79 onos_cfg = OnosCtrl.get_config()
80 if onos_cfg is None:
81 return None
82 if 'apps' in onos_cfg and \
83 'org.opencord.vtn' in onos_cfg['apps'] and \
84 'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \
85 'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']:
86 xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos']
87 endpoint = xos_cfg['endpoint']
88 user = xos_cfg['user']
89 password = xos_cfg['password']
90 xos_endpoints = endpoint.split(':')
91 xos_host = xos_endpoints[1][len('//'):]
92 xos_port = xos_endpoints[2][:-1]
93 #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password))
94 return dict(host = xos_host, port = xos_port, user = user, password = password)
95
96 return None
97
98 @classmethod
A.R Karthick50f4d9a2017-04-20 16:44:19 -070099 def getSubscriberConfig(cls, num_subscribers):
100 features = {
101 'cdn': True,
102 'uplink_speed': 1000000000,
103 'downlink_speed': 1000000000,
104 'uverse': True,
105 'status': 'enabled'
106 }
107 subscriber_map = []
108 for i in xrange(num_subscribers):
109 subId = 'sub{}'.format(i)
110 account_num, _, _ = cls.getSubscriberCredentials(subId)
111 identity = { 'account_num' : str(account_num),
112 'name' : 'My House {}'.format(i)
113 }
114 sub_info = { 'features' : features,
115 'identity' : identity
116 }
117 subscriber_map.append(sub_info)
118
119 return subscriber_map
120
121 @classmethod
122 def getVoltSubscriberConfig(cls, num_subscribers):
123 voltSubscriberMap = []
124 for i in xrange(num_subscribers):
125 subId = 'sub{}'.format(i)
126 account_num, s_tag, c_tag = cls.getSubscriberCredentials(subId)
127 voltSubscriberInfo = {}
128 voltSubscriberInfo['voltTenant'] = dict(s_tag = str(s_tag),
129 c_tag = str(c_tag),
130 subscriber = '')
131 voltSubscriberInfo['account_num'] = account_num
132 voltSubscriberMap.append(voltSubscriberInfo)
133
134 return voltSubscriberMap
135
136 @classmethod
A.R Karthick282f0d32017-03-28 16:43:59 -0700137 def setUpCordApi(cls):
138 our_path = os.path.dirname(os.path.realpath(__file__))
139 cord_api_path = os.path.join(our_path, '..', 'cord-api')
140 framework_path = os.path.join(cord_api_path, 'Framework')
141 utils_path = os.path.join(framework_path, 'utils')
142 data_path = os.path.join(cord_api_path, 'Tests', 'data')
143 subscriber_cfg = os.path.join(data_path, 'Subscriber.json')
144 volt_tenant_cfg = os.path.join(data_path, 'VoltTenant.json')
A R Karthick035d2e22017-04-25 13:53:00 -0700145 num_subscribers = max(cls.NUM_SUBSCRIBERS, 5)
146 cls.subscriber_info = cls.getSubscriberConfig(num_subscribers)
147 cls.volt_subscriber_info = cls.getVoltSubscriberConfig(num_subscribers)
A.R Karthick282f0d32017-03-28 16:43:59 -0700148
149 sys.path.append(utils_path)
150 sys.path.append(framework_path)
151 from restApi import restApi
152 restApiXos = restApi()
A.R Karthicka9b594d2017-03-29 16:25:22 -0700153 xos_credentials = cls.getXosCredentials()
154 if xos_credentials is None:
155 restApiXos.controllerIP = cls.HEAD_NODE
156 restApiXos.controllerPort = '9000'
157 else:
158 restApiXos.controllerIP = xos_credentials['host']
159 restApiXos.controllerPort = xos_credentials['port']
160 restApiXos.user = xos_credentials['user']
161 restApiXos.password = xos_credentials['password']
A.R Karthick282f0d32017-03-28 16:43:59 -0700162 cls.restApiXos = restApiXos
Chetan Gaonker52418832017-01-26 23:03:13 +0000163
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700164 @classmethod
A R Karthick97e08852017-04-26 10:06:38 -0700165 def getVoltId(cls, result, subId):
166 if type(result) is not type([]):
167 return None
168 for tenant in result:
169 if str(tenant['subscriber']) == str(subId):
170 return str(tenant['id'])
171 return None
172
173 @classmethod
A R Karthickb0cec7c2017-04-21 10:42:54 -0700174 def closeVCPEAccess(cls, volt_subscriber_info):
A R Karthick5d30b3c2017-04-27 10:25:40 -0700175 OnosCtrl.uninstall_app(cls.APP_NAME, onos_ip = cls.HEAD_NODE)
A.R Karthickb145da82017-04-20 14:45:43 -0700176
177 @classmethod
A R Karthickb0cec7c2017-04-21 10:42:54 -0700178 def openVCPEAccess(cls, volt_subscriber_info):
A.R Karthickb145da82017-04-20 14:45:43 -0700179 """
A R Karthickb0cec7c2017-04-21 10:42:54 -0700180 This code is used to configure leaf switch for head node access to compute node over fabric.
181 Care is to be taken to avoid overwriting existing/default vcpe flows.
182 The access is opened for generated subscriber info which should not overlap.
183 We target the fabric onos instance on head node.
A.R Karthickb145da82017-04-20 14:45:43 -0700184 """
A R Karthickb608d402017-06-02 11:48:41 -0700185 version = Onos.getVersion(onos_ip = cls.HEAD_NODE)
186 app_version = '1.0-SNAPSHOT'
187 major = int(version.split('.')[0])
188 minor = int(version.split('.')[1])
189 if major > 1:
190 app_version = '2.0-SNAPSHOT'
191 elif major == 1 and minor > 10:
192 app_version = '2.0-SNAPSHOT'
193 cls.APP_FILE = os.path.join(cls.test_path, '..', 'apps/xconnect-{}.oar'.format(app_version))
A.R Karthickb145da82017-04-20 14:45:43 -0700194 OnosCtrl.install_app(cls.APP_FILE, onos_ip = cls.HEAD_NODE)
195 time.sleep(2)
A R Karthickb0cec7c2017-04-21 10:42:54 -0700196 s_tags = map(lambda tenant: int(tenant['voltTenant']['s_tag']), volt_subscriber_info)
197 #only get unique vlan tags
198 s_tags = list(set(s_tags))
A.R Karthickb145da82017-04-20 14:45:43 -0700199 devices = OnosCtrl.get_device_ids(controller = cls.HEAD_NODE)
A R Karthickb0cec7c2017-04-21 10:42:54 -0700200 if devices:
201 device_config = {}
202 for device in devices:
203 device_config[device] = []
204 for s_tag in s_tags:
205 xconnect_config = {'vlan': s_tag, 'ports' : [ cls.FABRIC_PORT_HEAD_NODE, cls.FABRIC_PORT_COMPUTE_NODE ] }
206 device_config[device].append(xconnect_config)
A.R Karthickb145da82017-04-20 14:45:43 -0700207
A R Karthickb0cec7c2017-04-21 10:42:54 -0700208 cfg = { 'apps' : { 'org.ciena.xconnect' : { 'xconnectTestConfig' : device_config } } }
209 OnosCtrl.config(cfg, controller = cls.HEAD_NODE)
A.R Karthickb145da82017-04-20 14:45:43 -0700210
211 @classmethod
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700212 def setUpClass(cls):
213 cls.controllers = get_controllers()
214 cls.controller = cls.controllers[0]
215 cls.cli = None
A R Karthick19771192017-04-25 14:57:05 -0700216 cls.on_pod = running_on_pod()
217 cls.on_ciab = running_on_ciab()
A R Karthick03f40aa2017-03-20 19:33:55 -0700218 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
219 cls.vcpes = cls.olt.get_vcpes()
220 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
A R Karthick035d2e22017-04-25 13:53:00 -0700221 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
222 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
223 for i in xrange(len(cls.vcpes_reserved)) ]
224 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
225 cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
226 vcpe_dhcp_reserved = None
227 vcpe_container_reserved = None
228 if cls.vcpes_reserved:
229 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
A R Karthick19771192017-04-25 14:57:05 -0700230 if cls.on_pod is False:
A R Karthick035d2e22017-04-25 13:53:00 -0700231 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
232 vcpe_container_reserved = cls.container_vcpes_reserved[0]
233
234 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
235 cls.vcpe_container_reserved = vcpe_container_reserved
236 dhcp_vcpe_offset = len(cls.vcpes_reserved)
A R Karthick927129c2017-04-25 14:08:02 -0700237 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
238 for i in xrange(len(cls.vcpes_dhcp)) ]
239 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
240 cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
A R Karthick03f40aa2017-03-20 19:33:55 -0700241 vcpe_dhcp = None
A R Karthick03f40aa2017-03-20 19:33:55 -0700242 vcpe_container = None
243 #cache the first dhcp vcpe in the class for quick testing
244 if cls.vcpes_dhcp:
A R Karthick035d2e22017-04-25 13:53:00 -0700245 vcpe_container = cls.container_vcpes[0]
246 vcpe_dhcp = cls.dhcp_vcpes[0]
A R Karthick19771192017-04-25 14:57:05 -0700247 if cls.on_pod is False:
A R Karthick035d2e22017-04-25 13:53:00 -0700248 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
249 cls.vcpe_container = vcpe_container_reserved or vcpe_container
250 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700251 VSGAccess.setUp()
A.R Karthick282f0d32017-03-28 16:43:59 -0700252 cls.setUpCordApi()
A R Karthick19771192017-04-25 14:57:05 -0700253 if cls.on_pod is True:
A R Karthickb0cec7c2017-04-21 10:42:54 -0700254 cls.openVCPEAccess(cls.volt_subscriber_info)
Chetan Gaonker52418832017-01-26 23:03:13 +0000255
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700256 @classmethod
257 def tearDownClass(cls):
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700258 VSGAccess.tearDown()
A R Karthick19771192017-04-25 14:57:05 -0700259 if cls.on_pod is True:
A R Karthickb0cec7c2017-04-21 10:42:54 -0700260 cls.closeVCPEAccess(cls.volt_subscriber_info)
Chetan Gaonker52418832017-01-26 23:03:13 +0000261
Chetan Gaonker52418832017-01-26 23:03:13 +0000262 def onos_shutdown(self, controller = None):
263 status = True
A R Karthickb608d402017-06-02 11:48:41 -0700264 cli = Onos.cliEnter(onos_ip = controller)
Chetan Gaonker52418832017-01-26 23:03:13 +0000265 try:
A R Karthickb608d402017-06-02 11:48:41 -0700266 cli.shutdown(timeout = 10)
Chetan Gaonker52418832017-01-26 23:03:13 +0000267 except:
268 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
269 status = False
270
A R Karthickb608d402017-06-02 11:48:41 -0700271 Onos.cliExit(cli)
Chetan Gaonker52418832017-01-26 23:03:13 +0000272 return status
273
A.R Karthick9ccd0d02017-03-16 17:11:08 -0700274 def log_set(self, level = None, app = 'org.onosproject'):
275 CordLogger.logSet(level = level, app = app, controllers = self.controllers, forced = True)
Chetan Gaonker52418832017-01-26 23:03:13 +0000276
A R Karthick9a16a112017-04-07 15:40:05 -0700277 @classmethod
278 def get_dhcp(cls, vcpe, mgmt = 'eth0'):
279 """Get DHCP for vcpe interface saving management settings"""
280
281 def put_dhcp():
282 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
283
284 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
285 if vcpe_ip is not None:
286 cls.restore_methods.append(put_dhcp)
287 return vcpe_ip
288
289 @classmethod
290 def config_restore(cls):
291 """Restore the vsg test configuration on test case failures"""
292 for restore_method in cls.restore_methods:
293 restore_method()
294
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000295 def get_vsg_vcpe_pair(self):
296 vcpes = self.vcpes_dhcp
297 vcpe_containers = []
298 vsg_vcpe = {}
299 for vcp in vcpes:
300 vcpe_container = 'vcpe-{}-{}'.format(vcp['s_tag'], vcp['c_tag'])
301 vcpe_containers.append(vcpe_container)
302 vsg = VSGAccess.get_vcpe_vsg(vcpe_container)
303 vsg_vcpe[vcpe_container]=str(vsg.get_ip())
304 return vsg_vcpe
305
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000306 def get_vcpe_containers_and_interfaces(self):
307 vcpe_containers = {}
308 vcpe_interfaces = []
309 vcpes = self.vcpes_dhcp
310 count = 0
311 for vcpe in vcpes:
312 vcpe_intf = 'vcpe{}.{}.{}'.format(count,vcpe['s_tag'],vcpe['c_tag'])
313 vcpe_interfaces.append(vcpe_intf)
314 vcpe_container = 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag'])
315 vcpe_containers[vcpe_intf] = vcpe_container
316 count += 1
317 log.info('vcpe interfaces are %s'%vcpe_interfaces)
318 log.info('vcpe containers are %s'%vcpe_containers)
319 return vcpe_interfaces,vcpe_containers
320
321 def get_vcpe_interface_dhcp_ip(self,vcpe=None):
322 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000323 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000324 st, _ = getstatusoutput('dhclient {}'.format(vcpe))
325 vcpe_ip = get_ip(vcpe)
326 return vcpe_ip
327
328 def release_vcpe_interface_dhcp_ip(self,vcpe=None):
329 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000330 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000331 st, _ = getstatusoutput('dhclient {} -r'.format(vcpe))
332 vcpe_ip = get_ip(vcpe)
333 assert_equal(vcpe_ip, None)
334
335 def add_static_route_via_vcpe_interface(self, routes, vcpe=None,dhcp_ip=True):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000336 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000337 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000338 if dhcp_ip:
A R Karthick035d2e22017-04-25 13:53:00 -0700339 os.system('dhclient '+vcpe)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000340 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000341 for route in routes:
A R Karthick035d2e22017-04-25 13:53:00 -0700342 log.info('route is %s'%route)
343 cmd = 'ip route add ' + route + ' via 192.168.0.1 '+ 'dev ' + vcpe
A R Karthick035d2e22017-04-25 13:53:00 -0700344 os.system(cmd)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000345 return True
346
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000347 def del_static_route_via_vcpe_interface(self,routes,vcpe=None,dhcp_release=True):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000348 if not vcpe:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000349 vcpe = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000350 cmds = []
351 for route in routes:
A R Karthick035d2e22017-04-25 13:53:00 -0700352 cmd = 'ip route del ' + route + ' via 192.168.0.1 ' + 'dev ' + vcpe
353 os.system(cmd)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +0000354 if dhcp_release:
A R Karthick035d2e22017-04-25 13:53:00 -0700355 os.system('dhclient '+vcpe+' -r')
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000356 return True
357
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000358 def vsg_for_external_connectivity(self, subscriber_index, reserved = False):
359 if reserved is True:
360 if self.on_pod is True:
361 vcpe = self.dhcp_vcpes_reserved[subscriber_index]
362 else:
363 vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index]
364 else:
365 if self.on_pod is True:
366 vcpe = self.dhcp_vcpes[subscriber_index]
367 else:
368 vcpe = self.untagged_dhcp_vcpes[subscriber_index]
369 mgmt = 'eth0'
370 host = '8.8.8.8'
371 self.success = False
372 assert_not_equal(vcpe, None)
373 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
374 assert_not_equal(vcpe_ip, None)
375 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
376 log.info('Sending icmp echo requests to external network 8.8.8.8')
377 st, _ = getstatusoutput('ping -c 3 8.8.8.8')
378 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
379 assert_equal(st, 0)
380
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000381 def get_vsg_health_check(self, vsg_name=None):
382 if self.on_pod is False:
383 return
384 if vsg_name is None:
385 vcpe = self.container_vcpes_reserved[0]
386 vsg = VSGAccess.get_vcpe_vsg(vcpe)
387 status = vsg.get_health()
388 return status
389 else:
390 vsgs = VSGAccess.get_vsgs()
391 for vsg in vsgs:
392 if vsg.name == vsg_name:
393 status = vsg.get_health()
394 return status
395 return None
396
A R Karthick63751492017-03-22 09:28:01 -0700397 def test_vsg_health(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000398 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000399 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000400 1. Login to compute node VM
401 2. Get all vSGs
402 3. Ping to all vSGs
403 4. Verifying Ping success
404 """
A R Karthick93ba8d02017-04-13 11:59:58 -0700405 status = True
A R Karthick19771192017-04-25 14:57:05 -0700406 if self.on_pod is True:
A R Karthick93ba8d02017-04-13 11:59:58 -0700407 status = VSGAccess.health_check()
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700408 assert_equal(status, True)
Chetan Gaonker52418832017-01-26 23:03:13 +0000409
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000410 def test_vsg_health_check(self, vsg_name=None, verify_status=True):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000411 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000412 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000413 1. If vsg name not specified, Get vsg corresponding to vcpe
414 1. Login to compute mode VM
415 3. Ping to the vSG
416 4. Verifying Ping success
417 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000418 st = self.get_vsg_health_check(vsg_name=vsg_name)
419 assert_equal(st,verify_status)
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000420
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000421 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700422 def test_vsg_for_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000423 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000424 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000425 1. Get list of all compute nodes created using Openstack
426 2. Login to compute mode VM
427 3. Get all vSGs
428 4. Verifying atleast one compute node and one vSG created
429 """
A R Karthick035d2e22017-04-25 13:53:00 -0700430 df = defer.Deferred()
431 def vsg_for_vcpe_df(df):
A R Karthick19771192017-04-25 14:57:05 -0700432 if self.on_pod is True:
A R Karthick93ba8d02017-04-13 11:59:58 -0700433 vsgs = VSGAccess.get_vsgs()
434 compute_nodes = VSGAccess.get_compute_nodes()
435 time.sleep(14)
436 assert_not_equal(len(vsgs), 0)
437 assert_not_equal(len(compute_nodes), 0)
A R Karthick035d2e22017-04-25 13:53:00 -0700438 df.callback(0)
439 reactor.callLater(0,vsg_for_vcpe_df,df)
440 return df
Chetan Gaonker52418832017-01-26 23:03:13 +0000441
A R Karthick63751492017-03-22 09:28:01 -0700442 def test_vsg_for_login(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000443 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000444 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000445 1. Login to compute node VM
446 2. Get all vSGs
447 3. Verifying login to vSG is success
448 """
A R Karthick19771192017-04-25 14:57:05 -0700449 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700450 return
A R Karthickd0fdf3b2017-03-21 16:54:22 -0700451 vsgs = VSGAccess.get_vsgs()
452 vsg_access_status = map(lambda vsg: vsg.check_access(), vsgs)
A.R Karthick33cfdbe2017-03-17 18:03:48 -0700453 status = filter(lambda st: st == False, vsg_access_status)
454 assert_equal(len(status), 0)
455
A R Karthick63751492017-03-22 09:28:01 -0700456 def test_vsg_for_default_route_through_testclient(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000457 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000458 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000459 1. Login to head node
460 2. Verifying for default route in lxc test client
461 """
A R Karthick19771192017-04-25 14:57:05 -0700462 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700463 return
A R Karthick63751492017-03-22 09:28:01 -0700464 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
465 cmd = "sudo lxc exec testclient -- route | grep default"
466 status, output = ssh_agent.run_cmd(cmd)
467 assert_equal(status, True)
468
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000469 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700470 def test_vsg_for_external_connectivity_through_testclient(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000471 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000472 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000473 1. Login to head node
474 2. On head node, executing ping to 8.8.8.8 from lxc test client
475 3. Verifying for the ping success
476 """
A R Karthick19771192017-04-25 14:57:05 -0700477 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700478 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000479 df = defer.Deferred()
480 def test_external_connectivity(df):
481 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
482 cmd = "sudo lxc exec testclient -- ping -c 3 8.8.8.8"
483 status, output = ssh_agent.run_cmd(cmd)
484 assert_equal( status, True)
485 df.callback(0)
486 reactor.callLater(0,test_external_connectivity,df)
487 return df
A R Karthick63751492017-03-22 09:28:01 -0700488
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000489 @deferred(30)
A R Karthick035d2e22017-04-25 13:53:00 -0700490 def test_vsg_for_external_connectivity(self):
491 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000492 Test Method:
A R Karthick035d2e22017-04-25 13:53:00 -0700493 1. Get dhcp IP to vcpe interface in cord-tester
494 2. Verifying vcpe interface gets dhcp IP
495 3. Ping to 8.8.8.8 and Verifying ping should success
496 4. Restoring management interface configuration in cord-tester
497 """
A R Karthick19771192017-04-25 14:57:05 -0700498 reserved = True
499 if self.on_pod:
500 reserved = self.on_ciab
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000501 df = defer.Deferred()
502 def test_external_connectivity(df):
503 self.vsg_for_external_connectivity(0, reserved = reserved)
504 df.callback(0)
505 reactor.callLater(0,test_external_connectivity,df)
506 return df
A R Karthick035d2e22017-04-25 13:53:00 -0700507
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000508 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700509 def test_vsg_for_external_connectivity_to_google(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000510 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000511 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000512 1. Get dhcp IP to vcpe interface in cord-tester
513 2. Verifying vcpe interface gets dhcp IP
514 3. Ping to www.google.com and Verifying ping should success
515 4. Restoring management interface configuration in cord-tester
516 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000517 df = defer.Deferred()
518 def test_external_connectivity(df):
519 host = 'www.google.com'
520 vcpe = self.dhcp_vcpes_reserved[0]
521 mgmt = 'eth0'
522 assert_not_equal(vcpe, None)
523 try:
524 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
525 assert_not_equal(vcpe_ip, None)
526 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
527 log.info('Sending icmp ping requests to %s' %host)
528 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
529 assert_equal(st, 0)
530 except Exception as error:
531 log.info('Got Unexpected error %s'%error)
532 raise
533 finally:
534 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
535 df.callback(0)
536 reactor.callLater(0,test_external_connectivity,df)
537 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000538
A R Karthickb2618052017-05-10 09:23:22 -0700539 def retrieve_content_from_host_to_validate_path_mtu(self, host):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000540 vcpe = self.dhcp_vcpes_reserved[0]
A R Karthickb2618052017-05-10 09:23:22 -0700541 mgmt = 'eth0'
542 assert_not_equal(vcpe, None)
543 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
544 assert_not_equal(vcpe_ip, None)
545 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
546 log.info('Initiating get requests to %s' %host)
547 r = requests.get('http://{}'.format(host))
548 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
549 return r.status_code
550
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000551 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000552 def test_vsg_to_retrieve_content_from_google_to_validate_path_mtu(self):
553 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000554 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000555 1. Get dhcp IP to vcpe interface in cord-tester
556 2. Verifying vcpe interface gets dhcp IP
557 3. Retrieve contents from www.google.com and Verify response status is 200 ok.
558 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
559 (Based on website response, size differs, needs check on MTU)
560 4. Restoring management interface configuration in cord-tester
561 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000562 df = defer.Deferred()
563 def test_external_connectivity(df):
564 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.google.com')
565 assert_equal(status_code, 200)
566 df.callback(0)
567 reactor.callLater(0,test_external_connectivity,df)
568 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000569
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000570 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000571 def test_vsg_to_retrieve_content_from_rediff_to_validate_path_mtu(self):
572 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000573 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000574 1. Get dhcp IP to vcpe interface in cord-tester
575 2. Verifying vcpe interface gets dhcp IP
576 3. Retrieve contents from www.rediff.com and Verify response status is 200 ok.
577 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
578 (Based on website response, size differs, needs check on MTU)
579 4. Restoring management interface configuration in cord-tester
580 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000581 df = defer.Deferred()
582 def test_external_connectivity(df):
583 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.rediff.com')
584 assert_equal(status_code, 200)
585 df.callback(0)
586 reactor.callLater(0,test_external_connectivity,df)
587 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000588
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000589 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000590 def test_vsg_to_retrieve_content_from_yahoo_to_validate_path_mtu(self):
591 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000592 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000593 1. Get dhcp IP to vcpe interface in cord-tester
594 2. Verifying vcpe interface gets dhcp IP
595 3. Retrieve contents from www.yahoo.com and Verify response status is 200 ok.
596 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
597 (Based on website response, size differs, needs check on MTU)
598 4. Restoring management interface configuration in cord-tester
599 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000600 df = defer.Deferred()
601 def test_external_connectivity(df):
602 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.yahoo.com')
603 assert_equal(status_code, 200)
604 df.callback(0)
605 reactor.callLater(0,test_external_connectivity,df)
606 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000607
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000608 @deferred(30)
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000609 def test_vsg_to_retrieve_content_from_facebook_to_validate_path_mtu(self):
610 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000611 Test Method:
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000612 1. Get dhcp IP to vcpe interface in cord-tester
613 2. Verifying vcpe interface gets dhcp IP
614 3. Retrieve contents from www.facebook.com and Verify response status is 200 ok.
615 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework.
616 (Based on website response, size differs, needs check on MTU)
617 4. Restoring management interface configuration in cord-tester
618 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000619 df = defer.Deferred()
620 def test_external_connectivity(df):
621 status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.facebook.com')
622 assert_equal(status_code, 200)
623 df.callback(0)
624 reactor.callLater(0,test_external_connectivity,df)
625 return df
Chetan Gaonker0bf76312017-05-09 16:48:10 +0000626
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000627
628 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700629 def test_vsg_for_external_connectivity_to_invalid_host(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
634 3. Ping to www.goglee.com and Verifying ping should not success
635 4. Restoring management interface configuration in cord-tester
636 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000637 df = defer.Deferred()
638 def test_external_connectivity(df):
639 host = 'www.goglee.com'
640 vcpe = self.dhcp_vcpes_reserved[0]
641 mgmt = 'eth0'
642 assert_not_equal(vcpe, None)
643 try:
644 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
645 assert_not_equal(vcpe_ip, None)
646 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
647 log.info('Sending icmp ping requests to non existent host %s' %host)
648 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
649 assert_not_equal(st, 0)
650 except Exception as error:
651 log.info('Got Unexpected error %s'%error)
652 raise
653 finally:
654 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
655 df.callback(0)
656 reactor.callLater(0,test_external_connectivity,df)
657 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000658
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000659 @deferred(30)
A R Karthick63751492017-03-22 09:28:01 -0700660 def test_vsg_for_external_connectivity_with_ttl_1(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000661 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000662 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000663 1. Get dhcp IP to vcpe interface in cord-tester
664 2. Verifying vcpe interface gets dhcp IP
665 3. Ping to 8.8.8.8 with ttl set to 1
666 4. Verifying ping should not success
667 5. Restoring management interface configuration in cord-tester
668 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000669 df = defer.Deferred()
670 def test_external_connectivity(df):
671 host = '8.8.8.8'
672 vcpe = self.dhcp_vcpes_reserved[0]
673 mgmt = 'eth0'
674 assert_not_equal(vcpe, None)
675 try:
676 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
677 assert_not_equal(vcpe_ip, None)
678 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
679 log.info('Sending icmp ping requests to host %s with ttl 1' %host)
680 st, _ = getstatusoutput('ping -c 1 -t 1 {}'.format(host))
681 assert_not_equal(st, 0)
682 except Exception as error:
683 log.info('Got Unexpected error %s'%error)
684 raise
685 finally:
686 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
687 df.callback(0)
688 reactor.callLater(0,test_external_connectivity,df)
689 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000690
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000691 @deferred(60)
A R Karthick63751492017-03-22 09:28:01 -0700692 def test_vsg_for_external_connectivity_with_wan_interface_toggle_in_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000693 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000694 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000695 1. Get dhcp IP to vcpe interface in cord-tester
696 2. Verifying vcpe interface gets dhcp IP
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700697 3. Ping to 8.8.8.8 and Verifying ping succeeds
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000698 4. Now down the WAN interface of vcpe
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700699 5. Ping to 8.8.8.8 and Verifying ping fails
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000700 6. Now Up the WAN interface of vcpe
A.R Karthick8f7f1b62017-04-06 18:25:07 -0700701 7. Ping to 8.8.8.8 and Verifying ping succeeds
702 8. Restoring management interface configuration in cord-tester
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000703 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000704 df = defer.Deferred()
705 def test_external_connectivity(df):
706 if self.on_pod is False:
707 return
708 host = '8.8.8.8'
709 mgmt = 'eth0'
710 vcpe = self.dhcp_vcpes_reserved[0]
711 vcpe_name = self.container_vcpes_reserved[0]
712 assert_not_equal(vcpe_name, None)
713 assert_not_equal(vcpe, None)
714 #first get dhcp on the vcpe interface
715 try:
716 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
717 assert_not_equal(vcpe_ip, None)
718 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
719 log.info('Sending ICMP pings to host %s' %(host))
720 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
721 if st != 0:
722 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
723 assert_equal(st, 0)
724 #bring down the wan interface and check again
725 st = VSGAccess.vcpe_wan_down(vcpe_name)
726 if st is False:
727 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
728 assert_equal(st, True)
729 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
730 if st == 0:
731 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
732 assert_not_equal(st, 0)
733 st = VSGAccess.vcpe_wan_up(vcpe_name)
734 if st is False:
735 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
736 assert_equal(st, True)
737 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
738 assert_equal(st, 0)
739 except Exception as error:
740 log.info('Got Unexpected error %s'%error)
741 raise
742 finally:
743 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
744 df.callback(0)
745 reactor.callLater(0,test_external_connectivity,df)
746 return df
Anil Kumar Sanka87115b02017-03-14 17:46:47 +0000747
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000748 @deferred(60)
A R Karthick63751492017-03-22 09:28:01 -0700749 def test_vsg_for_external_connectivity_with_lan_interface_toggle_in_vcpe(self):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000750 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000751 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +0000752 1. Get dhcp IP to vcpe interface in cord-tester
753 2. Verifying vcpe interface gets dhcp IP
754 3. Ping to 8.8.8.8 and Verifying ping should success
755 4. Now down the LAN interface of vcpe
756 5. Ping to 8.8.8.8 and Verifying ping should not success
757 6. Now Up the LAN interface of vcpe
758 7. Ping to 8.8.8.8 and Verifying ping should success
759 8. Restoring management interface configuration in cord-tester
760 """
A R Karthick19771192017-04-25 14:57:05 -0700761 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -0700762 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000763 df = defer.Deferred()
764 def test_external_connectivity(df):
765 host = '8.8.8.8'
766 mgmt = 'eth0'
767 vcpe = self.dhcp_vcpes_reserved[0]
768 vcpe_name = self.container_vcpes_reserved[0]
769 assert_not_equal(vcpe, None)
770 assert_not_equal(vcpe_name, None)
771 #first get dhcp on the vcpe interface
772 try:
773 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
774 assert_not_equal(vcpe_ip, None)
775 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
776 log.info('Sending ICMP pings to host %s' %(host))
777 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
778 if st != 0:
779 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
780 assert_equal(st, 0)
781 #bring down the lan interface and check again
782 st = VSGAccess.vcpe_lan_down(vcpe_name)
783 if st is False:
784 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
785 assert_equal(st, True)
786 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
787 if st == 0:
788 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
789 assert_not_equal(st, 0)
790 st = VSGAccess.vcpe_lan_up(vcpe_name)
791 if st is False:
792 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
793 assert_equal(st, True)
794 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
795 assert_equal(st, 0)
796 except Exception as error:
797 log.info('Got Unexpected error %s'%error)
798 raise
799 finally:
800 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
801 df.callback(0)
802 reactor.callLater(0,test_external_connectivity,df)
803 return df
Chetan Gaonker52418832017-01-26 23:03:13 +0000804
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000805 @deferred(120)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +0000806 def test_vsg_multiple_subscribers_for_same_vcpe_instance(self):
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000807 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000808 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000809 1. Create a vcpe instance
810 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance
811 3. Verify all the interfaces gets dhcp IP in same subnet
812 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000813 df = defer.Deferred()
814 def test_external_connectivity(df):
815 vcpe_intfs,containers = self.get_vcpe_containers_and_interfaces()
816 for vcpe in vcpe_intfs:
817 vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe)
818 assert_not_equal(vcpe_ip,None)
819 for vcpe in vcpe_intfs:
820 self.release_vcpe_interface_dhcp_ip(vcpe=vcpe)
821 df.callback(0)
822 reactor.callLater(0,test_external_connectivity,df)
823 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000824
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000825 @deferred(120)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000826 def test_vsg_for_multiple_subscribers_with_same_vcpe_instance_and_validate_external_connectivity(self):
827 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000828 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000829 1. Create a vcpe instance
830 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance
831 3. Verify all the interfaces gets dhcp IP in same subnet
832 4. From cord-tester ping to external with vcpe interface option
833 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000834 df = defer.Deferred()
835 def test_external_connectivity(df):
836 host = '8.8.8.8'
837 vcpe_intfs, containers = self.get_vcpe_containers_and_interfaces()
838 try:
839 for vcpe in vcpe_intfs:
840 vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe)
841 assert_not_equal(vcpe_ip,None)
842 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_ip=False)
843 st, _ = getstatusoutput('ping -I {} -c 3 {}'.format(vcpe,host))
844 assert_equal(st, 0)
845 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_release=False)
846 except Exception as error:
847 log.info('Got Unexpected error %s'%error)
848 raise
849 finally:
850 for vcpe in vcpe_intfs:
851 self.release_vcpe_interface_dhcp_ip(vcpe=vcpe)
852 df.callback(0)
853 reactor.callLater(0,test_external_connectivity,df)
854 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000855
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000856 @deferred(30)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000857 def test_vsg_vcpe_interface_and_validate_dhcp_ip_after_interface_toggle(self):
858 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000859 Test Method:
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000860 1. Create a vcpe instance
861 2. Create a vcpe interface in cord-tester
862 3. Verify the interface gets dhcp IP
863 4. Toggle the interface
864 5. Verify the interface gets dhcp IP
865 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000866 df = defer.Deferred()
867 def test_external_connectivity(df):
868 vcpe_intf = self.dhcp_vcpes_reserved[0]
869 host = '8.8.8.8'
870 try:
871 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
872 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
873 assert_equal(st, 0)
874 os.system('ifconfig {} down'.format(vcpe_intf))
875 time.sleep(1)
876 os.system('ifconfig {} up'.format(vcpe_intf))
877 time.sleep(1)
878 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
879 assert_equal(st, 0)
880 except Exception as error:
881 log.info('Got Unexpected error %s'%error)
882 raise
883 finally:
884 self.del_static_route_via_vcpe_interface([host], vcpe=vcpe_intf)
885 df.callback(0)
886 reactor.callLater(0,test_external_connectivity,df)
887 return df
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +0000888
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000889 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000890 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 +0000891 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000892 Test Method:
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000893 1. Get vSG corresponding to vcpe
894 2. Get dhcp ip to vcpe interface
895 3. Add static route to destination route in test container
896 4. From test container ping to destination route and verify ping success
897 5. Login to compute node and execute command to pause vcpe container
898 6. From test container ping to destination route and verify ping success
899 """
900 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000901 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000902 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000903 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000904 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000905 def test_external_connectivity(df):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000906 if self.on_pod is False:
907 df.callback(0)
908 return
909 host = '8.8.8.8'
910 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
911 try:
912 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
913 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
914 assert_equal(st, False)
915 st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000916 clock = 0
917 status = False
918 while(clock <= 20):
919 time.sleep(5)
920 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
921 if st == False:
922 status = True
923 break
924 clock += 5
925 assert_equal(status, True)
926 except Exception as error:
927 log.info('Got Unexpected error %s'%error)
928 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
929 raise
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000930 finally:
931 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
932 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000933 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000934 return df
935
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000936 @nottest #Setup getting distrubed if vSG VM restart
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000937 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000938 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 +0000939 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000940 Test Method:
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000941 1. Get vSG corresponding to vcpe
942 2. Get dhcp ip to vcpe interface
943 3. Add static route to destination route in test container
944 4. From test container ping to destination route and verify ping success
945 5. Login to compute node and execute command to pause vcpe container
946 6. From test container ping to destination route and verify ping success
947 """
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000948 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000949 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000950 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000951 def test_external_connectivity(df):
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000952 if self.on_pod is False:
953 df.callback(0)
954 return
955 host = '8.8.8.8'
956 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
957 try:
958 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
959 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
960 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000961 vsg.reboot()
962 clock = 0
963 status = False
964 while(clock <= 30):
965 time.sleep(5)
966 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
967 if st == False:
968 status = True
969 break
970 clock += 5
971 assert_equal(status, True)
972 except Exception as error:
973 log.info('Got Unexpected error %s'%error)
974 vsg.reboot()
975 raise
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000976 finally:
977 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
978 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000979 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +0000980 return df
981
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000982 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +0000983 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 +0000984 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +0000985 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000986 1. Get vSG corresponding to vcpe
987 2. Get dhcp ip to vcpe interface
988 3. Add static route to destination route in test container
989 4. From test container ping to destination route and verify ping success
990 5. Login to compute node and execute command to pause vcpe container
991 6. From test container ping to destination route and verify ping success
992 """
993 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000994 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000995 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000996 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +0000997 df = defer.Deferred()
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +0000998 def test_external_connectivity(df):
A R Karthick19771192017-04-25 14:57:05 -0700999 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001000 df.callback(0)
1001 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001002 host = '8.8.8.8'
1003 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1004 try:
1005 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1006 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1007 assert_equal(st, False)
1008 st, _ = vsg.run_cmd('sudo docker pause {}'.format(vcpe_name))
1009 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1010 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001011 vsg.run_cmd('sudo docker unpause {}'.format(vcpe_name))
1012 except Exception as error:
1013 log.info('Got Unexpected error %s'%error)
1014 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
1015 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001016 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001017 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1018 df.callback(0)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001019 reactor.callLater(0, test_external_connectivity, df)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001020 return df
1021
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001022 @deferred(30)
1023 def test_vsg_firewall_with_deny_destination_ip_set(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001024 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001025 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001026 1. Get vSG corresponding to vcpe
1027 2. Login to compute node
1028 3. Execute iptable command on vcpe from compute node to deny a destination IP
1029 4. From cord-tester ping to the denied IP address
1030 5. Verifying that ping should not be successful
1031 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001032 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001033 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001034 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001035 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001036 df = defer.Deferred()
1037 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001038 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001039 df.callback(0)
1040 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001041 host = '8.8.8.8'
1042 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1043 try:
1044 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1045 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1046 assert_equal(st, False)
1047 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1048 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1049 assert_equal(st, True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001050 except Exception as error:
1051 log.info('Got Unexpected error %s'%error)
1052 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001053 finally:
1054 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1055 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001056 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001057 df.callback(0)
1058 reactor.callLater(0, vcpe_firewall, df)
1059 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001060
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001061 @deferred(60)
1062 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 +00001063 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001064 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001065 1. Get vSG corresponding to vcpe
1066 2. Login to compute node
1067 3. Execute iptable command on vcpe from compute node to deny a destination IP
1068 4. From cord-tester ping to the denied IP address
1069 5. Verifying that ping should not be successful
1070 6. Delete the iptable rule in vcpe
1071 7. From cord-tester ping to the denied IP address
1072 8. Verifying the ping should success
1073 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001074 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001075 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001076 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001077 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001078 df = defer.Deferred()
1079 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001080 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001081 df.callback(0)
1082 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001083 host = '8.8.8.8'
1084 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1085 try:
1086 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1087 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1088 assert_equal(st, False)
1089 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1090 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1091 assert_equal(st, True)
1092 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1093 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1094 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001095 except Exception as error:
1096 log.info('Got Unexpected error %s'%error)
1097 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1098 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001099 finally:
1100 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1101 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001102 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001103 df.callback(0)
1104 reactor.callLater(0, vcpe_firewall, df)
1105 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001106
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001107 @deferred(40)
1108 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 +00001109 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001110 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001111 1. Get vSG corresponding to vcpe
1112 2. Login to compute node
1113 3. Execute iptable command on vcpe from compute node to deny a destination IP
1114 4. From cord-tester ping to the denied IP address
1115 5. Verifying that ping should not be successful
1116 6. From cord-tester ping to the denied IP address other than the denied one
1117 7. Verifying the ping should success
1118 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001119 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001120 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001121 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001122 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001123 df = defer.Deferred()
1124 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001125 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001126 df.callback(0)
1127 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001128 host1 = '8.8.8.8'
1129 host2 = '204.79.197.203'
1130 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1131 try:
1132 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
1133 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1134 assert_equal(st, False)
1135 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1136 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1137 assert_equal(st, True)
1138 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1139 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001140 except Exception as error:
1141 log.info('Got Unexpected error %s'%error)
1142 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001143 finally:
1144 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1145 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001146 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001147 df.callback(0)
1148 reactor.callLater(0, vcpe_firewall, df)
1149 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001150
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001151 @deferred(60)
1152 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 +00001153 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001154 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001155 1. Get vSG corresponding to vcpe
1156 2. Login to compute node
1157 3. Execute iptable command on vcpe from compute node to deny a destination IP1
1158 4. From cord-tester ping to the denied IP address IP1
1159 5. Verifying that ping should not be successful
1160 6. Execute iptable command on vcpe from compute node to deny a destination IP2
1161 6. From cord-tester ping to the denied IP address IP2
1162 7. Verifying that ping should not be successful
1163 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001164 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001165 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001166 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001167 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001168 df = defer.Deferred()
1169 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001170 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001171 df.callback(0)
1172 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001173 host1 = '8.8.8.8'
1174 host2 = '204.79.197.203'
1175 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1176 try:
1177 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
1178 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1179 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001180 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1181 assert_equal(st, False)
1182 st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1183 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001184 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1185 assert_equal(st, True)
1186 st, out = getstatusoutput('ping -c 1 {}'.format(host2))
1187 log.info('host2 ping output is %s'%out)
1188 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001189 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,host2))
1190 time.sleep(1)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001191 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1192 assert_equal(st,True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001193 except Exception as error:
1194 log.info('Got Unexpected error %s'%error)
1195 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001196 finally:
1197 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1198 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1199 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001200 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001201 df.callback(0)
1202 reactor.callLater(0, vcpe_firewall, df)
1203 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001204
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001205 @deferred(TIMEOUT)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001206 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 +00001207 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001208 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001209 1. Get vSG corresponding to vcpe
1210 2. Login to compute node
1211 3. Execute iptable command on vcpe from compute node to deny a destination IP1
1212 4. Execute iptable command on vcpe from compute node to deny a destination IP2
1213 5. From cord-tester ping to the denied IP address IP1
1214 6. Verifying that ping should not be successful
1215 7. From cord-tester ping to the denied IP address IP2
1216 8. Verifying that ping should not be successful
1217 9. Execute iptable command on vcpe from compute node to remove deny a destination IP2 rule
1218 10. From cord-tester ping to the denied IP address IP2
1219 11. Verifying the ping should success
1220 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001221 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001222 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001223 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001224 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001225 df = defer.Deferred()
1226 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001227 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001228 df.callback(0)
1229 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001230 host1 = '8.8.8.8'
1231 host2 = '204.79.197.203'
1232 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1233 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001234 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001235 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1236 assert_equal(st, False)
1237 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1238 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1239 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1240 assert_equal(st, True)
1241 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1242 assert_equal(st,True)
1243 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1244 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1245 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001246 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1247 assert_equal(st, True)
1248 except Exception as error:
1249 log.info('Got Unexpected error %s'%error)
1250 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001251 finally:
1252 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1))
1253 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2))
1254 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001255 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001256 df.callback(0)
1257 reactor.callLater(0, vcpe_firewall, df)
1258 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001259
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001260 @deferred(60)
1261 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 +00001262 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001263 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001264 1. Get vSG corresponding to vcpe
1265 2. Login to compute node
1266 3. Execute iptable command on vcpe from compute node to deny a destination IP
1267 5. From cord-tester ping to the denied IP address IP1
1268 6. Verifying that ping should not be successful
1269 9. Execute iptable command on vcpe from compute node to change the rule ID to 2 to deny the same destination IP
1270 10. From cord-tester ping to the denied IP address IP
1271 11. Verifying that ping should not be successful
1272 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001273 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001274 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001275 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001276 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001277 df = defer.Deferred()
1278 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001279 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001280 df.callback(0)
1281 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001282 host = '8.8.8.8'
1283 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1284 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001285 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001286 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1287 assert_equal(st, False)
1288 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1289 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1290 assert_equal(st, True)
1291 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP '.format(vcpe_name,host))
1292 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1293 assert_equal(st,True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001294 except Exception as error:
1295 log.info('Got Unexpected error %s'%error)
1296 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001297 finally:
1298 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1299 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001300 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001301 df.callback(0)
1302 reactor.callLater(0, vcpe_firewall, df)
1303 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001304
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001305 @deferred(50)
1306 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 +00001307 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001308 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001309 1. Get vSG corresponding to vcpe
1310 2. Login to compute node
1311 3. Execute iptable command on vcpe from compute node to deny a destination IP
1312 5. From cord-tester ping to the denied IP address IP1
1313 6. Verifying that ping should not be successful
1314 9. Execute iptable command on vcpe from compute node to accept the same destination IP
1315 10. From cord-tester ping to the accepted IP
1316 11. Verifying the ping should success
1317 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001318 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001319 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001320 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001321 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001322 df = defer.Deferred()
1323 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001324 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001325 df.callback(0)
1326 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001327 host = '8.8.8.8'
1328 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1329 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001330 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001331 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1332 assert_equal(st, False)
1333 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1334 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1335 assert_equal(st, True)
1336 st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -d {} -j ACCEPT'.format(vcpe_name,host))
1337 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1338 assert_equal(st,False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001339 except Exception as error:
1340 log.info('Got Unexpected error %s'%error)
1341 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001342 finally:
1343 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1344 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j ACCEPT'.format(vcpe_name,host))
1345 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001346 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001347 df.callback(0)
1348 reactor.callLater(0, vcpe_firewall, df)
1349 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001350
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001351 @deferred(60)
1352 def test_vsg_firewall_denying_destination_network(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001353 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001354 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001355 1. Get vSG corresponding to vcpe
1356 2. Login to compute node
1357 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet
1358 4. From cord-tester ping to the denied IP address IP1 in the denied subnet
1359 5. Verifying that ping should not be successful
1360 6. From cord-tester ping to the denied IP address IP2 in the denied subnet
1361 7. Verifying that ping should not be successful
1362 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001363 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001364 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001365 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001366 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001367 df = defer.Deferred()
1368 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001369 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001370 df.callback(0)
1371 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001372 network = '204.79.197.192/28'
1373 host1 = '204.79.197.203'
1374 host2 = '204.79.197.210'
1375 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1376 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001377 self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001378 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1379 assert_equal(st, False)
1380 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network))
1381 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1382 assert_equal(st, True)
1383 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1384 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001385 except Exception as error:
1386 log.info('Got Unexpected error %s'%error)
1387 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001388 finally:
1389 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network))
1390 self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001391 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001392 df.callback(0)
1393 reactor.callLater(0, vcpe_firewall, df)
1394 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001395
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001396 @deferred(60)
1397 def test_vsg_firewall_denying_destination_network_subnet_modification(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001398 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001399 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001400 1. Get vSG corresponding to vcpe
1401 2. Login to compute node
1402 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet
1403 4. From cord-tester ping to the denied IP address IP1 in the denied subnet
1404 5. Verifying that ping should not be successful
1405 6. From cord-tester ping to the denied IP address IP2 in the denied subnet
1406 7. Verifying that ping should not be successful
1407 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001408 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001409 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001410 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001411 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001412 df = defer.Deferred()
1413 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001414 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001415 df.callback(0)
1416 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001417 network1 = '204.79.197.192/28'
1418 network2 = '204.79.197.192/27'
1419 host1 = '204.79.197.203'
1420 host2 = '204.79.197.210'
1421 host3 = '204.79.197.224'
1422 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1423 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001424 self.add_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001425 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1426 assert_equal(st, False)
1427 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network1))
1428 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1429 assert_equal(st, True)
1430 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1431 assert_equal(st,False)
1432 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,network2))
1433 st, _ = getstatusoutput('ping -c 1 {}'.format(host1))
1434 assert_equal(st, True)
1435 st, _ = getstatusoutput('ping -c 1 {}'.format(host2))
1436 assert_equal(st, True)
1437 st, _ = getstatusoutput('ping -c 1 {}'.format(host3))
1438 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001439 except Exception as error:
1440 log.info('Got Unexpected error %s'%error)
1441 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001442 finally:
1443 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network1))
1444 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network2))
1445 self.del_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001446 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001447 df.callback(0)
1448 reactor.callLater(0, vcpe_firewall, df)
1449 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001450
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001451 @deferred(40)
1452 def test_vsg_firewall_with_deny_source_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001453 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001454 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001455 1. Get vSG corresponding to vcpe
1456 2. Login to compute node
1457 3. Execute iptable command on vcpe from compute node to deny a source IP
1458 4. From cord-tester ping to 8.8.8.8 from the denied IP
1459 5. Verifying that ping should not be successful
1460 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001461 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001462 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001463 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001464 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001465 df = defer.Deferred()
1466 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001467 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001468 df.callback(0)
1469 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001470 host = '8.8.8.8'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001471 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1472 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001473 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1474 source_ip = get_ip(vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001475 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1476 assert_equal(st, False)
1477 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1478 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1479 assert_equal(st, True)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001480 except Exception as error:
1481 log.info('Got Unexpected error %s'%error)
1482 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1483 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001484 finally:
1485 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1486 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001487 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001488 df.callback(0)
1489 reactor.callLater(0, vcpe_firewall, df)
1490 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001491
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001492 @deferred(40)
1493 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 +00001494 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001495 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001496 1. Get vSG corresponding to vcpe
1497 2. Login to compute node
1498 3. Execute iptable command on vcpe from compute node to deny a source IP
1499 4. From cord-tester ping to 8.8.8.8 from the denied IP
1500 5. Verifying that ping should not be successful
1501 6. Delete the iptable rule in vcpe
1502 7. From cord-tester ping to 8.8.8.8 from the denied IP
1503 8. Verifying the ping should success
1504 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001505 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001506 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001507 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001508 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001509 df = defer.Deferred()
1510 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001511 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001512 df.callback(0)
1513 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001514 host = '8.8.8.8'
1515 source_ip = get_ip(self.vcpe_dhcp)
1516 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1517 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001518 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
1519 source_ip = get_ip(vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001520 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1521 assert_equal(st, False)
1522 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1523 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1524 assert_equal(st, True)
1525 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1526 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1527 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001528 except Exception as error:
1529 log.info('Got Unexpected error %s'%error)
1530 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1531 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001532 finally:
1533 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip))
1534 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001535 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001536 df.callback(0)
1537 reactor.callLater(0, vcpe_firewall, df)
1538 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001539
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001540 @deferred(40)
1541 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 +00001542 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001543 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001544 1. Get vSG corresponding to vcpe
1545 2. Login to compute node
1546 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets
1547 4. From cord-tester ping to 8.8.8.8
1548 5. Verifying that ping should not be successful
1549 6. Delete the iptable rule
1550 7. From cord-tester ping to 8.8.8.8
1551 8. Verifying the ping should success
1552 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001553 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001554 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001555 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001556 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001557 df = defer.Deferred()
1558 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001559 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001560 df.callback(0)
1561 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001562 host = '8.8.8.8'
1563 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1564 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001565 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001566 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1567 assert_equal(st, False)
1568 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1569 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1570 assert_equal(st, True)
1571 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1572 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1573 assert_equal(st, False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001574 except Exception as error:
1575 log.info('Got Unexpected error %s'%error)
1576 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1577 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001578 finally:
1579 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1580 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001581 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001582 df.callback(0)
1583 reactor.callLater(0, vcpe_firewall, df)
1584 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001585
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001586 @deferred(40)
1587 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 +00001588 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001589 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001590 1. Get vSG corresponding to vcpe
1591 2. Login to compute node
1592 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets
1593 4. From cord-tester ping to 8.8.8.8
1594 5. Verifying that ping should not be successful
1595 6. Delete the iptable rule
1596 7. From cord-tester ping to 8.8.8.8
1597 8. Verifying the ping should success
1598 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001599 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001600 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001601 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001602 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001603 df = defer.Deferred()
1604 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001605 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001606 df.callback(0)
1607 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001608 host = '8.8.8.8'
1609 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1610 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001611 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001612 st, _ = getstatusoutput('ping -c 1 {}'.format('8.8.8.8'))
1613 assert_equal(st, False)
1614 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1615 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1616 assert_equal(st, True)
1617 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1618 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1619 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001620 except Exception as error:
1621 log.info('Got Unexpected error %s'%error)
1622 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1623 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001624 finally:
1625 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1626 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001627 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001628 df.callback(0)
1629 reactor.callLater(0, vcpe_firewall, df)
1630 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001631
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001632 @deferred(40)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00001633 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 +00001634 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001635 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001636 1. Get vSG corresponding to vcpe
1637 2. Login to compute node
1638 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets
1639 4. From cord-tester ping to 8.8.8.8
1640 5. Verifying that ping should not be successful
1641 6. Insert another rule to accept the icmp-echo requests protocol packets
1642 7. From cord-tester ping to 8.8.8.8
1643 8. Verifying the ping should success
1644 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001645 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001646 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001647 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001648 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001649 df = defer.Deferred()
1650 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001651 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001652 df.callback(0)
1653 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001654 host = '8.8.8.8'
1655 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1656 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001657 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001658 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1659 assert_equal(st, False)
1660 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1661 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1662 assert_equal(st, True)
1663 st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name))
1664 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1665 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001666 except Exception as error:
1667 log.info('Got Unexpected error %s'%error)
1668 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001669 finally:
1670 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name))
1671 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name))
1672 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001673 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001674 df.callback(0)
1675 reactor.callLater(0, vcpe_firewall, df)
1676 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001677
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001678 @deferred(40)
1679 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 +00001680 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001681 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001682 1. Get vSG corresponding to vcpe
1683 2. Login to compute node
1684 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets
1685 4. From cord-tester ping to 8.8.8.8
1686 5. Verifying the ping should not success
1687 6. Insert another rule to accept the icmp-echo requests protocol packets
1688 7. From cord-tester ping to 8.8.8.8
1689 8. Verifying the ping should success
1690 """
1691 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001692 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001693 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001694 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001695 df = defer.Deferred()
1696 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001697 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001698 df.callback(0)
1699 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001700 host = '8.8.8.8'
1701 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1702 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001703 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001704 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1705 assert_equal(st, False)
1706 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1707 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1708 assert_equal(st, True)
1709 st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name))
1710 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1711 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001712 except Exception as error:
1713 log.info('Got Unexpected error %s'%error)
1714 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001715 finally:
1716 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name))
1717 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name))
1718 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001719 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001720 df.callback(0)
1721 reactor.callLater(0, vcpe_firewall, df)
1722 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001723
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001724 @deferred(40)
1725 def test_vsg_firewall_for_deny_icmp_protocol(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001726 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001727 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001728 1. Get vSG corresponding to vcpe
1729 2. Login to compute node
1730 3. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1731 4. From cord-tester ping to 8.8.8.8
1732 5. Verifying that ping should not be successful
1733 6. Delete the iptable rule
1734 7. From cord-tester ping to 8.8.8.8
1735 8. Verifying the ping should success
1736 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001737 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001738 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001739 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001740 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001741 df = defer.Deferred()
1742 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001743 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001744 df.callback(0)
1745 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001746 host = '8.8.8.8'
1747 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1748 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001749 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001750 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1751 assert_equal(st, False)
1752 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1753 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1754 assert_equal(st, True)
1755 st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1756 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1757 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001758 except Exception as error:
1759 log.info('Got Unexpected error %s'%error)
1760 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1761 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001762 finally:
1763 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1764 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001765 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001766 df.callback(0)
1767 reactor.callLater(0, vcpe_firewall, df)
1768 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001769
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001770 @deferred(60)
1771 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 +00001772 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001773 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001774 1. Get vSG corresponding to vcpe
1775 2. Login to compute node
1776 3. Execute iptable command on vcpe from compute node to deny a destination IP
1777 4. From cord-tester ping to 8.8.8.8
1778 5. Verifying that ping should not be successful
1779 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1780 7. From cord-tester ping to 8.8.8.8
1781 8. Verifying the ping should success
1782 9. Delete the rule added in step 3
1783 10. From cord-tester ping to 8.8.8.8
1784 11. Verifying that ping should not be successful
1785 12. Delete the rule added in step 6
1786 13. From cord-tester ping to 8.8.8.8
1787 14. Verifying the ping should success
1788 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001789 if not vcpe_name:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001790 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001791 if not vcpe_intf:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001792 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001793 df = defer.Deferred()
1794 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001795 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001796 df.callback(0)
1797 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001798 host = '8.8.8.8'
1799 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1800 try:
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001801 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001802 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1803 assert_equal(st, False)
1804 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1805 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1806 assert_equal(st, True)
1807 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1808 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1809 assert_equal(st, True)
1810 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1811 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1812 assert_equal(st, True)
1813 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1814 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1815 assert_equal(st,False)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001816 except Exception as error:
1817 log.info('Got Unexpected error %s'%error)
1818 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1819 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1820 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001821 finally:
1822 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
1823 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1824 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001825 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001826 df.callback(0)
1827 reactor.callLater(0, vcpe_firewall, df)
1828 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001829
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001830 @deferred(100)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001831 def test_vsg_firewall_flushing_all_configured_rules(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001832 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001833 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001834 1. Get vSG corresponding to vcpe
1835 2. Login to compute node
1836 3. Execute iptable command on vcpe from compute node to deny a destination IP
1837 4. From cord-tester ping to 8.8.8.8
1838 5. Verifying that ping should not be successful
1839 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets
1840 7. From cord-tester ping to 8.8.8.8
1841 8. Verifying the ping should success
1842 9. Flush all the iptable rules configuraed in vcpe
1843 10. Delete the rule added in step 6
1844 11. From cord-tester ping to 8.8.8.8
1845 12. Verifying the ping should success
1846 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001847 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001848 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001849 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001850 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001851 df = defer.Deferred()
1852 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001853 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001854 df.callback(0)
1855 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001856 host = '8.8.8.8'
1857 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1858 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001859 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001860 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1861 assert_equal(st, False)
1862 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host))
1863 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1864 assert_equal(st, True)
1865 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name))
1866 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1867 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001868 st, _ = vsg.run_cmd('sudo docker exec {} iptables -F FORWARD'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001869 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001870 assert_equal(st, True)
1871 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
1872 status = False
1873 clock = 0
1874 while(clock <= 30):
1875 time.sleep(5)
1876 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1877 if st == False:
1878 status = True
1879 break
1880 clock += 5
1881 assert_equal(status, True)
1882 except Exception as error:
1883 log.info('Got Unexpected error %s'%error)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001884 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001885 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name))
1886 raise
1887 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001888 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001889 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001890 df.callback(0)
1891 reactor.callLater(0, vcpe_firewall, df)
1892 return df
Anil Kumar Sankad47023a2017-03-29 21:11:09 +00001893
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001894 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001895 def test_vsg_firewall_deny_all_ipv4_traffic(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001896 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001897 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001898 1. Get vSG corresponding to vcpe
1899 2. Login to compute node
1900 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic
1901 4. From cord-tester ping to 8.8.8.8
1902 5. Verifying that ping should not be successful
1903 6. Delete the iptable rule added
1904 7. From cord-tester ping to 8.8.8.8
1905 8. Verifying the ping should success
1906 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001907 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001908 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001909 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001910 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001911 df = defer.Deferred()
1912 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001913 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001914 df.callback(0)
1915 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001916 host = '8.8.8.8'
1917 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1918 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001919 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001920 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1921 assert_equal(st, False)
1922 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
1923 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1924 assert_equal(st, True)
1925 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1926 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1927 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001928 except Exception as error:
1929 log.info('Got Unexpected error %s'%error)
1930 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1931 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001932 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001933 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001934 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001935 df.callback(0)
1936 reactor.callLater(0, vcpe_firewall, df)
1937 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00001938
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001939 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001940 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 +00001941 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001942 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00001943 1. Get vSG corresponding to vcpe
1944 2. Login to compute node
1945 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic
1946 4. From cord-tester ping to 8.8.8.8
1947 5. Verifying that ping should not be successful
1948 6. Replace the deny rule added in step 3 with accept rule
1949 7. From cord-tester ping to 8.8.8.8
1950 8. Verifying the ping should success
1951 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001952 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001953 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001954 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001955 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001956 df = defer.Deferred()
1957 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07001958 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07001959 df.callback(0)
1960 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001961 host = '8.8.8.8'
1962 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1963 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001964 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001965 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
1966 assert_equal(st, False)
1967 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
1968 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1969 assert_equal(st, True)
1970 st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -4 -j ACCEPT'.format(vcpe_name))
1971 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
1972 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001973 except Exception as error:
1974 log.info('Got Unexpected error %s'%error)
1975 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001976 finally:
1977 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
1978 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001979 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001980 df.callback(0)
1981 reactor.callLater(0, vcpe_firewall, df)
1982 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00001983
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001984 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00001985 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 +00001986 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00001987 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001988 1. Get vSG corresponding to vcpe
1989 2. Login to compute node
1990 3. Execute iptable command on vcpe from compute node to deny all the traffic coming on lan interface inside vcpe container
1991 4. From cord-tester ping to 8.8.8.8
1992 5. Verifying the ping should not success
1993 6. Delete the iptable rule added
1994 7. From cord-tester ping to 8.8.8.8
1995 8. Verifying the ping should success
1996 """
1997 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00001998 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00001999 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002000 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002001 df = defer.Deferred()
2002 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002003 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002004 df.callback(0)
2005 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002006 host = '8.8.8.8'
2007 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2008 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002009 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002010 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2011 assert_equal(st, False)
2012 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -j DROP'.format(vcpe_name))
2013 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2014 assert_equal(st, True)
2015 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name))
2016 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2017 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002018 except Exception as error:
2019 log.info('Got Unexpected error %s'%error)
2020 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name))
2021 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002022 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002023 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002024 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002025 df.callback(0)
2026 reactor.callLater(0, vcpe_firewall, df)
2027 return df
2028
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002029 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002030 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 +00002031 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002032 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002033 1. Get vSG corresponding to vcpe
2034 2. Login to compute node
2035 3. Execute iptable command on vcpe from compute node to deny all the traffic going out of wan interface inside vcpe container
2036 4. From cord-tester ping to 8.8.8.8
2037 5. Verifying the ping should not success
2038 6. Delete the iptable rule added
2039 7. From cord-tester ping to 8.8.8.8
2040 8. Verifying the ping should success
2041 """
2042 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002043 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002044 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002045 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002046 df = defer.Deferred()
2047 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002048 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002049 df.callback(0)
2050 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002051 host = '8.8.8.8'
2052 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2053 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002054 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002055 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2056 assert_equal(st, False)
2057 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -o eth0 -j DROP'.format(vcpe_name))
2058 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2059 assert_equal(st, True)
2060 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name))
2061 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2062 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002063 except Exception as error:
2064 log.info('Got Unexpected error %s'%error)
2065 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name))
2066 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002067 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002068 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002069 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002070 df.callback(0)
2071 reactor.callLater(0, vcpe_firewall, df)
2072 return df
2073
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002074 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002075 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 +00002076 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002077 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002078 1. Get vSG corresponding to vcpe
2079 2. Login to compute node
2080 3. Execute iptable command on vcpe from compute node to deny all the traffic from lan to wan interface in vcpe
2081 4. From cord-tester ping to 8.8.8.8
2082 5. Verifying that ping should not be successful
2083 6. Delete the iptable rule added
2084 7. From cord-tester ping to 8.8.8.8
2085 8. Verifying the ping should success
2086 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002087 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002088 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002089 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002090 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002091 df = defer.Deferred()
2092 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002093 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002094 df.callback(0)
2095 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002096 host = '8.8.8.8'
2097 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2098 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002099 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002100 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2101 assert_equal(st, False)
2102 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2103 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2104 assert_equal(st, True)
2105 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2106 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2107 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002108 except Exception as error:
2109 log.info('Got Unexpected error %s'%error)
2110 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name))
2111 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002112 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002113 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002114 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002115 df.callback(0)
2116 reactor.callLater(0, vcpe_firewall, df)
2117 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00002118
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002119 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002120 def test_vsg_firewall_deny_all_dns_traffic(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002121 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002122 Test Method:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002123 1. Get vSG corresponding to vcpe
2124 2. Login to compute node
2125 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2126 4. From cord-tester ping to www.google.com
2127 5. Verifying the ping should not success
2128 6. Delete the iptable rule added
2129 7. From cord-tester ping to www.google.com
2130 8. Verifying the ping should success
2131 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002132 mgmt = 'eth0'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002133 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002134 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002135 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002136 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002137 df = defer.Deferred()
2138 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002139 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002140 df.callback(0)
2141 return
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002142 host = 'google-public-dns-a.google.com'
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002143 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2144 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002145 st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2146 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002147 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002148 assert_not_equal(st, False)
2149 VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf)
2150 st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2151 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002152 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2153 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002154 VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf)
2155 except Exception as error:
2156 log.info('Got Unexpected error %s'%error)
2157 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name))
2158 VSGAccess.restore_interface_config(mgmt,vcpe=vcpe_intf)
2159 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002160 df.callback(0)
2161 reactor.callLater(0, vcpe_firewall, df)
2162 return df
2163
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002164 @deferred(60)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002165 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 +00002166 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002167 Test Method:
Anil Kumar Sanka72755c92017-04-06 17:19:02 +00002168 1. Get vSG corresponding to vcpe
2169 2. Login to compute node
2170 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2171 4. From cord-tester ping to www.google.com
2172 5. Verifying that ping should not be successful
2173 6. Delete the iptable rule added
2174 7. From cord-tester ping to www.google.com
2175 8. Verifying the ping should success
2176 """
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002177 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002178 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002179 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002180 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002181 df = defer.Deferred()
2182 def vcpe_firewall(df):
A R Karthick19771192017-04-25 14:57:05 -07002183 if self.on_pod is False:
A R Karthick93ba8d02017-04-13 11:59:58 -07002184 df.callback(0)
2185 return
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002186 host = '8.8.8.8'
2187 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2188 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002189 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002190 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2191 assert_equal(st, False)
2192 st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name))
2193 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2194 assert_equal(st, True)
2195 st,output = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002196 clock = 0
2197 status = False
2198 while(clock <= 20 ):
2199 time.sleep(5)
2200 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2201 if st == False:
2202 status = True
2203 break
2204 clock += 5
2205 assert_equal(status, True)
2206 except Exception as error:
2207 log.info('Got Unexpected error %s'%error)
2208 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name))
2209 raise
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002210 finally:
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002211 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002212 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sankaa357c6a2017-04-12 17:52:24 +00002213 df.callback(0)
2214 reactor.callLater(0, vcpe_firewall, df)
2215 return df
Anil Kumar Sanka966c1932017-03-31 00:48:31 +00002216
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002217 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002218 def test_vsg_nat_dnat_modifying_destination_ip(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002219 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002220 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002221 1. Get vSG corresponding to vcpe
2222 2. Login to compute node
2223 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2224 4. From cord-tester ping to www.google.com
2225 5. Verifying the ping should not success
2226 6. Delete the iptable rule added
2227 7. From cord-tester ping to www.google.com
2228 8. Verifying the ping should success
2229 """
2230 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002231 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002232 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002233 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002234 df = defer.Deferred()
2235 def vcpe_firewall(df):
2236 host = '8.8.8.8'
2237 dst_ip = '123.123.123.123'
2238 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2239 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002240 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002241 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2242 assert_equal(st, False)
2243 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))
2244 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2245 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002246 except Exception as error:
2247 log.info('Got Unexpected error %s'%error)
2248 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002249 finally:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002250
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002251 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))
2252 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002253 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002254 df.callback(0)
2255 reactor.callLater(0,vcpe_firewall,df)
2256 return df
2257
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002258 @deferred(40)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002259 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 +00002260 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002261 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002262 1. Get vSG corresponding to vcpe
2263 2. Login to compute node
2264 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2265 4. From cord-tester ping to www.google.com
2266 5. Verifying the ping should not success
2267 6. Delete the iptable rule added
2268 7. From cord-tester ping to www.google.com
2269 8. Verifying the ping should success
2270 """
2271 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002272 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002273 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002274 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002275 df = defer.Deferred()
2276 def vcpe_firewall(df):
2277 host = '8.8.8.8'
2278 dst_ip = '123.123.123.123'
2279 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2280 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002281 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002282 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2283 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002284 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 +00002285 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2286 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002287 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 +00002288 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2289 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002290 except Exception as error:
2291 log.info('Got Unexpected error %s'%error)
2292 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))
2293 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002294 finally:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002295 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002296 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002297 df.callback(0)
2298 reactor.callLater(0,vcpe_firewall,df)
2299 return df
2300
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002301 @deferred(50)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002302 def test_vsg_dnat_change_modifying_destination_ip_address(self, vcpe_name=None, vcpe_intf=None):
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002303 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00002304 Test Method:
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002305 1. Get vSG corresponding to vcpe
2306 2. Login to compute node
2307 3. Execute iptable command on vcpe from compute node to deny all dns Traffic
2308 4. From cord-tester ping to www.google.com
2309 5. Verifying the ping should not success
2310 6. Delete the iptable rule added
2311 7. From cord-tester ping to www.google.com
2312 8. Verifying the ping should success
2313 """
2314 if not vcpe_name:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002315 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002316 if not vcpe_intf:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002317 vcpe_intf = self.dhcp_vcpes_reserved[0]
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002318 df = defer.Deferred()
2319 def vcpe_firewall(df):
2320 host = '8.8.8.8'
2321 dst_ip = '123.123.123.123'
2322 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2323 try:
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002324 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002325 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2326 assert_equal(st, False)
2327 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))
2328 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2329 assert_equal(st, True)
2330 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))
2331 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2332 assert_equal(st, False)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002333 except Exception as error:
2334 log.info('Got Unexpected error %s'%error)
2335 raise
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002336 finally:
2337 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))
2338 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))
2339 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002340 #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
Anil Kumar Sanka5fa8d8b2017-04-18 22:01:48 +00002341 df.callback(0)
2342 reactor.callLater(0,vcpe_firewall,df)
2343 return df
2344
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002345 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
A R Karthick19771192017-04-25 14:57:05 -07002346 if self.on_pod is False:
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002347 return ''
2348 if subscriber_info is None:
2349 subscriber_info = self.subscriber_info[index]
2350 if volt_subscriber_info is None:
2351 volt_subscriber_info = self.volt_subscriber_info[index]
A R Karthickd0b06792017-04-25 15:11:23 -07002352 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
2353 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
2354 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
2355 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
A R Karthick97e08852017-04-26 10:06:38 -07002356 subId = ''
2357 try:
2358 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
2359 assert_equal(result, True)
2360 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
2361 assert_not_equal(result, None)
2362 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
2363 assert_not_equal(subId, '0')
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002364 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
A R Karthick97e08852017-04-26 10:06:38 -07002365 volt_tenant = volt_subscriber_info['voltTenant']
2366 #update the subscriber id in the tenant info before making the rest
2367 volt_tenant['subscriber'] = subId
2368 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
2369 assert_equal(result, True)
2370 #if the vsg instance was already instantiated, then reduce delay
2371 if c_tag % self.subscribers_per_s_tag == 0:
2372 delay = 350
2373 else:
2374 delay = 90
2375 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
2376 time.sleep(delay)
2377 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
2378 self.vsg_for_external_connectivity(index)
2379 finally:
A R Karthick5d30b3c2017-04-27 10:25:40 -07002380 return subId
A R Karthick97e08852017-04-26 10:06:38 -07002381
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002382 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
A R Karthick97e08852017-04-26 10:06:38 -07002383 if self.on_pod is False:
2384 return
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002385 if subscriber_info is None:
2386 subscriber_info = self.subscriber_info[index]
2387 if volt_subscriber_info is None:
2388 volt_subscriber_info = self.volt_subscriber_info[index]
A R Karthick97e08852017-04-26 10:06:38 -07002389 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
2390 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
2391 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
2392 log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
2393 if not subId:
2394 #get the subscriber id first
2395 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
2396 assert_not_equal(result, None)
2397 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
2398 assert_not_equal(subId, '0')
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002399 if not voltId:
2400 #get the volt id for the subscriber
2401 result = self.restApiXos.ApiGet('TENANT_VOLT')
2402 assert_not_equal(result, None)
2403 voltId = self.getVoltId(result, subId)
2404 assert_not_equal(voltId, None)
2405 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
A R Karthicka385cea2017-04-26 10:12:43 -07002406 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
2407 assert_equal(status, True)
A R Karthick97e08852017-04-26 10:06:38 -07002408 #Delete the tenant
2409 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
A R Karthick76944872017-04-26 10:21:37 -07002410 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
A R Karthick035d2e22017-04-25 13:53:00 -07002411
A R Karthicke29c8d42017-04-27 11:38:52 -07002412 def vsg_xos_subscriber_id(self, index):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002413 log.info('index and its type are %s, %s'%(index, type(index)))
A R Karthicke29c8d42017-04-27 11:38:52 -07002414 volt_subscriber_info = self.volt_subscriber_info[index]
2415 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
2416 assert_not_equal(result, None)
2417 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
2418 return subId
2419
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002420 def test_vsg_xos_subscriber_create_reserved(self):
A.R Karthicka2960912017-05-18 18:52:55 -07002421 if self.on_pod is False:
2422 return
A.R Karthicka3fa2f92017-05-18 18:51:36 -07002423 tags_reserved = [ (int(vcpe['s_tag']), int(vcpe['c_tag'])) for vcpe in self.vcpes_reserved ]
2424 volt_tenants = self.restApiXos.ApiGet('TENANT_VOLT')
2425 subscribers = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
2426 reserved_tenants = filter(lambda tenant: (int(tenant['s_tag']), int(tenant['c_tag'])) in tags_reserved, volt_tenants)
2427 reserved_config = []
2428 for tenant in reserved_tenants:
2429 for subscriber in subscribers:
2430 if int(subscriber['id']) == int(tenant['subscriber']):
2431 volt_subscriber_info = {}
2432 volt_subscriber_info['voltTenant'] = dict(s_tag = tenant['s_tag'],
2433 c_tag = tenant['c_tag'],
2434 subscriber = tenant['subscriber'])
2435 volt_subscriber_info['volt_id'] = tenant['id']
2436 volt_subscriber_info['account_num'] = subscriber['identity']['account_num']
2437 reserved_config.append( (subscriber, volt_subscriber_info) )
2438 break
2439 else:
2440 log.info('Subscriber not found for tenant %s, s_tag: %s, c_tag: %s' %(str(tenant['subscriber']),
2441 str(tenant['s_tag']),
2442 str(tenant['c_tag'])))
2443
2444 for subscriber_info, volt_subscriber_info in reserved_config:
2445 self.vsg_xos_subscriber_delete(0,
2446 subId = str(subscriber_info['id']),
2447 voltId = str(volt_subscriber_info['volt_id']),
2448 subscriber_info = subscriber_info,
2449 volt_subscriber_info = volt_subscriber_info)
2450 subId = self.vsg_xos_subscriber_create(0,
2451 subscriber_info = subscriber_info,
2452 volt_subscriber_info = volt_subscriber_info)
2453 log.info('Created reserved subscriber %s' %(subId))
2454
A R Karthicke29c8d42017-04-27 11:38:52 -07002455 def test_vsg_xos_subscriber_create_all(self):
2456 for index in xrange(len(self.subscriber_info)):
2457 #check if the index exists
2458 subId = self.vsg_xos_subscriber_id(index)
2459 if subId and subId != '0':
2460 self.vsg_xos_subscriber_delete(index, subId = subId)
2461 subId = self.vsg_xos_subscriber_create(index)
2462 log.info('Created Subscriber %s' %(subId))
2463
2464 def test_vsg_xos_subscriber_delete_all(self):
2465 for index in xrange(len(self.subscriber_info)):
2466 subId = self.vsg_xos_subscriber_id(index)
2467 if subId and subId != '0':
2468 self.vsg_xos_subscriber_delete(index, subId = subId)
2469
2470 def test_vsg_xos_subscriber_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002471 subId = self.vsg_xos_subscriber_create(0)
2472 if subId and subId != '0':
2473 self.vsg_xos_subscriber_delete(0, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002474
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002475
A R Karthicke29c8d42017-04-27 11:38:52 -07002476 def test_vsg_xos_subscriber_2_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002477 subId = self.vsg_xos_subscriber_create(1)
2478 if subId and subId != '0':
2479 self.vsg_xos_subscriber_delete(1, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002480
A R Karthicke29c8d42017-04-27 11:38:52 -07002481 def test_vsg_xos_subscriber_3_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002482 subId = self.vsg_xos_subscriber_create(2)
2483 if subId and subId != '0':
2484 self.vsg_xos_subscriber_delete(2, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002485
A R Karthicke29c8d42017-04-27 11:38:52 -07002486 def test_vsg_xos_subscriber_4_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002487 subId = self.vsg_xos_subscriber_create(3)
2488 if subId and subId != '0':
2489 self.vsg_xos_subscriber_delete(3, subId)
A R Karthick035d2e22017-04-25 13:53:00 -07002490
A R Karthicke29c8d42017-04-27 11:38:52 -07002491 def test_vsg_xos_subscriber_5_create_and_delete(self):
A R Karthick5d30b3c2017-04-27 10:25:40 -07002492 subId = self.vsg_xos_subscriber_create(4)
2493 if subId and subId != '0':
2494 self.vsg_xos_subscriber_delete(4, subId)
A.R Karthick282f0d32017-03-28 16:43:59 -07002495
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002496 @deferred(400)
2497 def test_vsg_xos_subscriber_external_connectivity_through_vcpe_instance(self, index=0):
2498 df = defer.Deferred()
2499 status = False
2500 def test_xos_subscriber(df):
2501 subId = self.vsg_xos_subscriber_id(index)
2502 if subId == '0':
2503 log.info('Creating vcpe instance ')
2504 subId = self.vsg_xos_subscriber_create(index)
2505 assert_not_equal(subId,'0')
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002506 vcpe = self.dhcp_vcpes[index]
2507 host = '8.8.8.8'
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002508 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2509 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2510 assert_equal(st, False)
2511 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2512 df.callback(0)
2513 reactor.callLater(0,test_xos_subscriber,df)
2514 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002515
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002516 #pass
2517 @deferred(50)
2518 def test_vsg_xos_subscriber_external_connectivity_without_creating_vcpe_instance(self, index=0):
2519 df = defer.Deferred()
2520 def test_xos_subscriber(df):
2521 subId = self.vsg_xos_subscriber_id(index)
2522 if subId != '0':
2523 log.info('deleting already existing vcpe instance ')
2524 self.vsg_xos_subscriber_delete(index, subId)
2525 vcpe = self.dhcp_vcpes[index]
2526 host = '8.8.8.8'
2527 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2528 st, out = getstatusoutput('route -n')
2529 log.info('route -n outpu-1-1-1--1-1-1-1-1-1-1 is %s'%out)
2530 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2531 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2532 assert_equal(st, True)
2533 df.callback(0)
2534 reactor.callLater(0,test_xos_subscriber,df)
2535 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00002536
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002537 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002538 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 +00002539 df = defer.Deferred()
2540 def test_xos_subscriber(df):
2541 subId = self.vsg_xos_subscriber_id(index)
2542 if subId == '0':
2543 subId = self.vsg_xos_subscriber_create(index)
2544 assert_not_equal(subId,'0')
2545 vcpe = self.dhcp_vcpes[index]
2546 if subId and subId != '0':
2547 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe)
2548 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2549 assert_equal(st, False)
2550 self.vsg_xos_subscriber_delete(index, subId)
2551 time.sleep(2)
2552 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2553 assert_equal(st, True)
2554 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe)
2555 df.callback(0)
2556 reactor.callLater(0,test_xos_subscriber,df)
2557 return df
2558
2559 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002560 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 +00002561 df = defer.Deferred()
2562 def test_xos_subscriber(df):
2563 subId = self.vsg_xos_subscriber_id(index)
2564 if subId == '0':
2565 subId = self.vsg_xos_subscriber_create(index)
2566 assert_not_equal(subId,'0')
2567 vcpe_intf = self.dhcp_vcpes[index]
2568 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2569 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2570 assert_equal(st, False)
2571 vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
2572 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2573 st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name))
2574 assert_equal(st, True)
2575 time.sleep(5)
2576 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2577 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2578 assert_equal(st, False)
2579 df.callback(0)
2580 reactor.callLater(0,test_xos_subscriber,df)
2581 return df
2582
2583 @deferred(400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002584 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 +00002585 df = defer.Deferred()
2586 def test_xos_subscriber(df):
2587 subId = self.vsg_xos_subscriber_id(index)
2588 if subId == '0':
2589 subId = self.vsg_xos_subscriber_create(index)
2590 assert_not_equal(subId,'0')
2591 vcpe_intf = self.dhcp_vcpes[index]
2592 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2593 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2594 assert_equal(st, False)
2595 vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
2596 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2597 st, _ = vsg.run_cmd('sudo docker stop {}'.format(vcpe_name))
2598 assert_equal(st, True)
2599 time.sleep(3)
2600 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2601 assert_equal(st, True)
2602 st, _ = vsg.run_cmd('sudo docker start {}'.format(vcpe_name))
2603 assert_equal(st, True)
2604 time.sleep(5)
2605 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2606 assert_equal(st, False)
2607 df.callback(0)
2608 reactor.callLater(0,test_xos_subscriber,df)
2609 return df
2610
2611 #getting list out of range error while creating vcpe of index 6
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002612 def test_vsg_create_xos_subscribers_in_different_vsg_vm(self, index1=4, index2=6):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002613 indexes = list(index1,index2)
2614 subids = []
2615 for index in indexes:
2616 subId = self.vsg_xos_subscriber_id(index)
2617 if not subId:
2618 subId = self.vsg_xos_subscriber_create(index)
2619 assert_not_equal(subId,'0')
2620 subids.append(subId)
2621 log.info('succesfully created two vcpe instances in two different vSG VMs')
2622 self.vsg_xos_subscriber_delete(index1, subid[0])
2623 self.vsg_xos_subscriber_delete(index2, subid[1])
2624
2625 #Unable to reach external network via vcpes created by XOS
2626 @deferred(TIMEOUT+400)
2627 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_goes_down(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002628 """
2629 Test Method:
2630 1.Create two vcpe instances in two different vsg vms using XOS
2631 2.Verify external connectivity through vcpe instances from cord-tester
2632 3.Kill first vcpe instance
2633 4.Verify external network cant be reachable form first vcpe interface
2634 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002635 df = defer.Deferred()
2636 def test_xos_subscriber(df):
2637 host1 = '8.8.8.8'
2638 host2 = '4.2.2.2'
2639 vcpe_intf1 = self.dhcp_vcpes[0]
2640 vcpe_intf2 = self.dhcp_vcpes[1]
2641 vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2642 vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
2643 subId1 = self.vsg_xos_subscriber_id(0)
2644 log.info('already existing subid of index 0 is %s'%subId1)
2645 if subId1 == '0':
2646 log.info('creating vcpe instance of index 0')
2647 subId1 = self.vsg_xos_subscriber_create(0)
2648 assert_not_equal(subId1,'0')
2649 subId2 = self.vsg_xos_subscriber_id(1)
2650 log.info('already existing subid of index 1 is %s'%subId2)
2651 if subId2 == '0':
2652 log.info('creating vcpe instance of index 1')
2653 subId2 = self.vsg_xos_subscriber_create(1)
2654 assert_not_equal(subId2,'0')
2655 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2656 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2657 try:
2658 for intf in [vcpe_intf1,vcpe_intf2]:
2659 host = host1 if intf is vcpe_intf1 else host2
2660 self.add_static_route_via_vcpe_interface([host],vcpe=intf)
2661 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2662 assert_equal(st, False)
2663 if intf is vcpe_intf2:
2664 self.vsg_xos_subscriber_delete(1, subId2)
2665 st, _ = vsg2.run_cmd('sudo docker kill {}'.format(vcpe_name2))
2666 time.sleep(2)
2667 self.add_static_route_via_vcpe_interface([host],vcpe=intf)
2668 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2669 assert_equal(st, False)
2670 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2671 assert_equal(st, True)
2672 except Exception as error:
2673 log.info('Got Unexpected error %s'%error)
2674 raise
2675 finally:
2676 self.vsg_xos_subscriber_delete(0, subId1)
2677 self.vsg_xos_subscriber_delete(1, subId2)
2678 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2679 self.del_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2680 df.callback(0)
2681 reactor.callLater(0,test_xos_subscriber,df)
2682 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002683
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002684 @deferred(TIMEOUT+400)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002685 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 +00002686 """
2687 Test Method:
2688 1.Create two vcpe instances in two different vsg vms using XOS
2689 2.Verify external connectivity through vcpe instances from cord-tester
2690 3.Remove first vcpe instance
2691 4.Verify external network cant be reachable form first vcpe interface
2692 5.Add back the removed vcpe instance
2693 6.Verify external connectivity through vcpe instances from cord-tester
2694 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002695 df = defer.Deferred()
2696 def test_xos_subscriber(df,index=index):
2697 host = '8.8.8.8'
2698 subId = self.vsg_xos_subscriber_id(index)
2699 log.info('already existing subid of index 0 is %s'%subId)
2700 if subId == '0':
2701 log.info('creating vcpe instance of index %s'%index)
2702 subId = self.vsg_xos_subscriber_create(index)
2703 assert_not_equal(subId,'0')
2704 vcpe_intf = self.dhcp_vcpes[0]
2705 vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2])
2706 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2707 try:
2708 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2709 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2710 assert_equal(st, False)
2711 log.info('Deleting vcpe Instance of index %s'%index)
2712 self.vsg_xos_subscriber_delete(0, subId)
2713 st, _ = vsg.run_cmd('sudo docker kill {}'.format(vcpe_name))
2714 time.sleep(1)
2715 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2716 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2717 assert_equal(st, True)
2718 subId = self.vsg_xos_subscriber_create(index)
2719 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2720 st,_ = getstatusoutput('ping -c 1 {}'.format(host))
2721 assert_equal(st, False)
2722 except Exception as error:
2723 log.info('Got Unexpected error %s'%error)
2724 raise
2725 finally:
2726 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2727 self.vsg_xos_subscriber_delete(0, subId)
2728 df.callback(0)
2729 reactor.callLater(0,test_xos_subscriber,df)
2730 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002731
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002732 @deferred(TIMEOUT+400)
2733 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_restarts(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002734 """
2735 Test Method:
2736 1.Create two vcpe instances in two different vsg vms using XOS
2737 2.Verify external connectivity through vcpe instances from cord-tester
2738 3.Restart first vcpe instance
2739 4.Verify external network cant be reachable form first vcpe interface
2740 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002741 df = defer.Deferred()
2742 def test_xos_subscriber(df):
2743 host1 = '8.8.8.8'
2744 host2 = '4.2.2.2'
2745 subId1 = self.vsg_xos_subscriber_id(0)
2746 log.info('already existing subid of index 0 is %s'%subId1)
2747 if subId1 == '0':
2748 log.info('creating vcpe instance of index 0')
2749 subId1 = self.vsg_xos_subscriber_create(0)
2750 assert_not_equal(subId1,'0')
2751 subId2 = self.vsg_xos_subscriber_id(1)
2752 log.info('already existing subid of index 1 is %s'%subId2)
2753 if subId2 == '0':
2754 log.info('creating vcpe instance of index 1')
2755 subId2 = self.vsg_xos_subscriber_create(1)
2756 vcpe_intf1 = self.dhcp_vcpes[0]
2757 vcpe_intf2 = self.dhcp_vcpes[1]
2758 vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2759 vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
2760 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2761 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2762 try:
2763 #checking external connectivity from vcpe interface 1 before vcpe 2 restart
2764 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2765 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2766 assert_equal(st, False)
2767 #checking external connectivity from vcpe interface 2 before vcpe 2 restart
2768 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2769 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2770 assert_equal(st, False)
2771 st, _ = vsg2.run_cmd('sudo docker restart {}'.format(vcpe_name2))
2772 time.sleep(10)
2773 #checking external connectivity from vcpe interface 1 after vcpe 2 restart
2774 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2775 assert_equal(st, False)
2776 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2777 time = 0
2778 status = False
2779 while(time <= 100):
2780 time.sleep(10)
2781 st,_ = getstatusoutput('ping -c 1 {}'.format(hos2))
2782 if st is False:
2783 status = True
2784 break
2785 time += 10
2786 assert_equal(status, True)
2787 except Exception as error:
2788 log.info('Got Unexpected error %s'%error)
2789 raise
2790 finally:
2791 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2792 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2793 self.vsg_xos_subscriber_delete(0, subId1)
2794 self.vsg_xos_subscriber_delete(1, subId2)
2795 df.callback(0)
2796 reactor.callLater(0,test_xos_subscriber,df)
2797 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002798
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002799 @deferred(500)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002800 def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_is_paused(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002801 """
2802 Test Method:
2803 1.Create two vcpe instances in two different vsg vms using XOS
2804 2.Verify external connectivity through vcpe instances from cord-tester
2805 3.Pause running first vcpe instance
2806 4.Verify external network cant be reachable form first vcpe interface
2807 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002808 df = defer.Deferred()
2809 def test_xos_subscriber(df):
2810 host1 = '8.8.8.8'
2811 host2 = '4.2.2.2'
2812 subId1 = self.vsg_xos_subscriber_id(0)
2813 log.info('already existing subid of index 0 is %s'%subId1)
2814 if subId1 == '0':
2815 log.info('creating vcpe instance of index 0')
2816 subId1 = self.vsg_xos_subscriber_create(0)
2817 assert_not_equal(subId1,'0')
2818 subId2 = self.vsg_xos_subscriber_id(1)
2819 log.info('already existing subid of index 1 is %s'%subId2)
2820 if subId2 == '0':
2821 log.info('creating vcpe instance of index 1')
2822 subId2 = self.vsg_xos_subscriber_create(1)
2823 vcpe_intf1 = self.dhcp_vcpes[0]
2824 vcpe_intf2 = self.dhcp_vcpes[1]
2825 vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2826 vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
2827 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2828 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2829 try:
2830 #checking external connectivity from vcpe interface 1 before vcpe 2 pause
2831 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2832 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2833 assert_equal(st, False)
2834 #checking external connectivity from vcpe interface 2 before vcpe 2 pause
2835 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2836 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2837 assert_equal(st, False)
2838 st, _ = vsg2.run_cmd('sudo docker pause {}'.format(vcpe_name2))
2839 time.sleep(1)
2840 #checking external connectivity from vcpe interface 1 after vcpe 2 pause
2841 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2842 assert_equal(st, False)
2843 #checking external connectivity from vcpe interface 2 after vcpe 2 pause
2844 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2845 assert_equal(st, True)
2846 except Exception as error:
2847 log.info('Got Unexpected error %s'%error)
2848 raise
2849 finally:
2850 log.info('In Finally block 3333333333333333')
2851 st, _ = vsg2.run_cmd('sudo docker unpause {}'.format(vcpe_name2))
2852 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2853 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2854 self.vsg_xos_subscriber_delete(0, subId1)
2855 self.vsg_xos_subscriber_delete(1, subId2)
2856 df.callback(0)
2857 reactor.callLater(0,test_xos_subscriber,df)
2858 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002859
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002860 @deferred(500)
2861 def test_vsg_xos_subscriber_external_connectivity_if_one_vcpe_stops(self):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002862 """
2863 Test Method:
2864 1.Create two vcpe instances in two different vsg vms using XOS
2865 2.Verify external connectivity through vcpe instances from cord-tester
2866 3.Stop running first vcpe instance
2867 4.Verify external network cant be reachable form first vcpe interface
2868 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002869 df = defer.Deferred()
2870 def test_xos_subscriber(df):
2871 host1 = '8.8.8.8'
2872 host2 = '4.2.2.2'
2873 subId1 = self.vsg_xos_subscriber_id(0)
2874 log.info('already existing subid of index 0 is %s'%subId1)
2875 if subId1 == '0':
2876 log.info('creating vcpe instance of index 0')
2877 subId1 = self.vsg_xos_subscriber_create(0)
2878 assert_not_equal(subId1,'0')
2879 subId2 = self.vsg_xos_subscriber_id(1)
2880 log.info('already existing subid of index 1 is %s'%subId2)
2881 if subId2 == '0':
2882 log.info('creating vcpe instance of index 1')
2883 subId2 = self.vsg_xos_subscriber_create(1)
2884 vcpe_intf1 = self.dhcp_vcpes[0]
2885 vcpe_intf2 = self.dhcp_vcpes[1]
2886 vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2])
2887 vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2])
2888 vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1)
2889 vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2)
2890 try:
2891 #checking external connectivity from vcpe interface 1 before vcpe 2 stop
2892 self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2893 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2894 assert_equal(st, False)
2895 #checking external connectivity from vcpe interface 2 before vcpe 2 stop
2896 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2897 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2898 assert_equal(st, False)
2899 st, _ = vsg2.run_cmd('sudo docker stop {}'.format(vcpe_name2))
2900 time.sleep(5)
2901 #checking external connectivity from vcpe interface 1 after vcpe 2 stop
2902 st,_ = getstatusoutput('ping -c 1 {}'.format(host1))
2903 assert_equal(st, False)
2904 #checking external connectivity from vcpe interface 1 after vcpe 2 stop
2905 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2906 st,_ = getstatusoutput('ping -c 1 {}'.format(host2))
2907 assert_equal(st, True)
2908 except Exception as error:
2909 log.info('Got Unexpected error %s'%error)
2910 raise
2911 finally:
2912 st, _ = vsg2.run_cmd('sudo docker start {}'.format(vcpe_name2))
2913 time.sleep(10)
2914 self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1)
2915 self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2)
2916 self.vsg_xos_subscriber_delete(0, subId1)
2917 self.vsg_xos_subscriber_delete(1, subId2)
2918 df.callback(0)
2919 reactor.callLater(0,test_xos_subscriber,df)
2920 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002921
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002922 @deferred(420)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002923 def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_stopped(self, index=0):
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002924 """
2925 Test Method:
2926 1.Create two vcpe instances in two different vsg vms using XOS
2927 2.Verify external connectivity through vcpe instances from cord-tester
2928 3.Bring down first vSG vm
2929 4.Verify external network cant be reachable form first vcpe interface
2930 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002931 df = defer.Deferred()
2932 def test_xos_subscriber(df,index=index):
2933 host = '8.8.8.8'
2934 subId = self.vsg_xos_subscriber_id(index)
2935 if subId == '0':
2936 log.info('creating vcpe instance of index 0')
2937 subId = self.vsg_xos_subscriber_create(index)
2938 assert_not_equal(subId,'0')
2939 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
2940 vcpe_name = self.container_vcpes[index]
2941 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2942 try:
2943 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2944 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2945 assert_equal(st, False)
2946 log.info('Stopping vsg instance')
2947 vsg.stop()
2948 time.sleep(5)
2949 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2950 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2951 assert_equal(st, True)
2952 except Exception as error:
2953 log.info('Got Unexpected error %s'%error)
2954 raise
2955 finally:
2956 vsg.start()
2957 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2958 self.vsg_xos_subscriber_delete(index, subId)
2959 df.callback(0)
2960 reactor.callLater(0,test_xos_subscriber,df)
2961 return df
Anil Kumar Sanka5bb352a2017-05-16 22:24:01 +00002962
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002963 @deferred(420)
Chetan Gaonkere1f66382017-06-02 21:34:07 +00002964 def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_restarted(self, index=0):
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002965 """
2966 Test Method:
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00002967 1.Create subscriber
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00002968 2.Verify external connectivity through vcpe instances from cord-tester
2969 3.Bring down first vSG vm
2970 4.Verify external network cant be reachable form first vcpe interface
2971 """
2972 df = defer.Deferred()
2973 def test_xos_subscriber(df,index=index):
2974 host = '8.8.8.8'
2975 subId = self.vsg_xos_subscriber_id(index)
2976 if subId == '0':
2977 log.info('creating vcpe instance of index 0')
2978 subId = self.vsg_xos_subscriber_create(index)
2979 assert_not_equal(subId,'0')
2980 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
2981 vcpe_name = self.container_vcpes[index]
2982 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
2983 try:
2984 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2985 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2986 assert_equal(st, False)
2987 log.info('Restarting vsg instance')
2988 vsg.reboot()
2989 time.sleep(10)
2990 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
2991 time = 0
2992 status = False
2993 while(time <= 100):
2994 time.sleep(10)
2995 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
2996 if st is False:
2997 status = True
2998 break
2999 time += 10
3000 assert_equal(status, True)
3001 except Exception as error:
3002 log.info('Got Unexpected error %s'%error)
3003 raise
3004 finally:
3005 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3006 self.vsg_xos_subscriber_delete(index, subId)
3007 df.callback(0)
3008 reactor.callLater(0,test_xos_subscriber,df)
3009 return df
3010
3011 @deferred(780)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00003012 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 +00003013 """
3014 Test Method:
3015 1.Create two vcpe instances in two different vsg vms using XOS
3016 2.Verify external connectivity through vcpe instances from cord-tester
3017 3.Bring down first vSG vm
3018 4.Verify external network cant be reachable form first vcpe interface
3019 5.Bring down second vSG vm also
3020 6.Verify external network cant be reachable form first vcpe interface also
3021 """
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003022 df = defer.Deferred(df,index1=index1,index2=index2)
3023 def test_xos_subscriber(df,index=index):
3024 subId1 = self.vsg_xos_subscriber_create(index1)
3025 subId2 = self.vsg_xos_subscriber_create(index2)
3026 if subId1 == '0':
3027 self.vsg_xos_subscriber_delete(index1, subId1)
3028 assert_not_equal(subId1, '0')
3029 if subId2 == '0':
3030 self.vsg_xos_subscriber_delete(index2, subId2)
3031 assert_not_equal(subId2, '0')
3032 for index in [index1,index2]:
3033 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
3034 vcpe_name = self.container_vcpes[index]
3035 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
3036 try:
3037 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3038 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
3039 assert_equal(st, False)
3040 log.info('Stopping vsg instance of index %s'%index)
3041 vsg.stop()
3042 time.sleep(5)
3043 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3044 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
3045 assert_equal(st, True)
3046 except Exception as error:
3047 log.info('Got Unexpected error %s'%error)
3048 raise
3049 finally:
3050 vsg.start()
3051 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3052 df.callback(0)
3053 reactor.callLater(0,test_xos_subscriber,df)
3054 return df
Anil Kumar Sanka52a39f82017-05-10 17:39:31 +00003055
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003056 @deferred(420)
3057 def test_vsg_xos_subscriber_external_connectivity_with_creating_firewall_rule(self,index=0):
3058 """
3059 Alog:
3060 1.Cretae a vcpe instance using XOS
3061 2.Get dhcp IP to vcpe interface in cord-tester
3062 3.Verify external network can be reachable from cord-tester
3063 4.Add an iptable rule to drop packets destined to external network in vcpe
3064 5.Verify now external network cant be reachable
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00003065 6.Delele the iptable in vcpe instance
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003066 7.Verify external network can be reachable from cord-tester
3067 """
3068 df = defer.Deferred()
3069 def test_xos_subscriber(df,index=index):
3070 log.info('cls.dhcp_vcpes is %s'%self.dhcp_vcpes)
3071 host = '8.8.8.8'
3072 subId = self.vsg_xos_subscriber_create(index)
3073 if subId == '0':
3074 subId = self.vsg_xos_subscriber_create(index)
3075 assert_not_equal(subId, '0')
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003076 vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003077 vcpe_name = self.container_vcpes[index]
3078 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003079 try:
3080 self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
3081 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003082 #ssert_equal(st, False)
3083 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 +00003084 st, _ = getstatusoutput('ping -c 1 {}'.format(host))
3085 assert_equal(st, True)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003086 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
3087 self.vsg_xos_subscriber_delete(index, subId)
3088 except Exception as error:
3089 log.info('Got Unexpected error %s'%error)
3090 raise
3091 finally:
3092 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host))
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003093 self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf)
Anil Kumar Sanka5db80d02017-06-02 21:10:19 +00003094 self.vsg_xos_subscriber_delete(index, subId)
3095 df.callback(0)
3096 reactor.callLater(0,test_xos_subscriber,df)
3097 return df
A R Karthick63751492017-03-22 09:28:01 -07003098
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003099 def test_vsg_for_packet_received_with_invalid_ip_fields(self):
3100 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003101 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003102 1.Create a vSG VM in compute node
3103 2.Create a vCPE container in vSG VM
3104 3.Ensure vSG VM and vCPE container created properly
3105 4.From subscriber, send a ping packet with invalid ip fields
3106 5.Verify that vSG drops the packet
3107 6.Verify ping fails
3108 """
A R Karthick63751492017-03-22 09:28:01 -07003109
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003110 def test_vsg_for_packet_received_with_invalid_mac_fields(self):
3111 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003112 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003113 1.Create a vSG VM in compute node
3114 2.Create a vCPE container in vSG VM
3115 3.Ensure vSG VM and vCPE container created properly
3116 4.From subscriber, send a ping packet with invalid mac fields
3117 5.Verify that vSG drops the packet
3118 6.Verify ping fails
3119 """
A R Karthick63751492017-03-22 09:28:01 -07003120
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003121 def test_vsg_for_vlan_id_mismatch_in_stag(self):
3122 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003123 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003124 1.Create a vSG VM in compute Node
3125 2.Create a vCPE container in vSG VM
3126 3.Ensure vSG VM and vCPE container created properly
3127 4.Send a ping request to external valid IP from subscriber, with incorrect vlan id in s-tag and valid c-tag
3128 5.Verify that ping fails as the packet drops at VM entry
3129 6.Repeat step 4 with correct s-tag
3130 7.Verify that ping success
3131 """
A R Karthick63751492017-03-22 09:28:01 -07003132
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003133 def test_vsg_for_vlan_id_mismatch_in_ctag(self):
3134 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003135 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003136 1.Create a vSG VM in compute node
3137 2.Create a vCPE container in vSG VM
3138 3.Ensure vSG VM and vCPE container created properly
3139 4.Send a ping request to external valid IP from subscriber, with valid s-tag and incorrect vlan id in c-tag
3140 5.Verify that ping fails as the packet drops at vCPE container entry
3141 6.Repeat step 4 with valid s-tag and c-tag
3142 7.Verify that ping success
3143 """
A R Karthick63751492017-03-22 09:28:01 -07003144
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003145 def test_vsg_for_matching_and_mismatching_vlan_id_in_stag(self):
3146 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003147 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003148 1.Create two vSG VMs in compute node
3149 2.Create a vCPE container in each vSG VM
3150 3.Ensure vSG VM and vCPE container created properly
3151 4.From subscriber one, send ping request with valid s and c tags
3152 5.From subscriber two, send ping request with vlan id mismatch in s-tag and valid c tags
3153 6.Verify that ping success for only subscriber one and fails for two.
3154 """
A R Karthick63751492017-03-22 09:28:01 -07003155
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003156 def test_vsg_for_matching_and_mismatching_vlan_id_in_ctag(self):
3157 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003158 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003159 1.Create a vSG VM in compute node
3160 2.Create two vCPE containers in vSG VM
3161 3.Ensure vSG VM and vCPE container created properly
3162 4.From subscriber one, send ping request with valid s and c tags
3163 5.From subscriber two, send ping request with valid s-tag and vlan id mismatch in c-tag
3164 6.Verify that ping success for only subscriber one and fails for two
3165 """
A R Karthick63751492017-03-22 09:28:01 -07003166
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003167 def test_vsg_for_out_of_range_vlanid_in_ctag(self):
3168 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003169 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003170 1.Create a vSG VM in compute node
3171 2.Create a vCPE container in vSG VM
3172 3.Ensure vSG VM and vCPE container created properly
3173 4.From subscriber, send ping request with valid stag and vlan id in c-tag is an out of range value ( like 0,4097 )
3174 4.Verify that ping fails as the ping packets drops at vCPE container entry
3175 """
A R Karthick63751492017-03-22 09:28:01 -07003176
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003177 def test_vsg_for_out_of_range_vlanid_in_stag(self):
3178 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003179 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003180 1.Create a vSG VM in compute node
3181 2.Create a vCPE container in vSG VM
3182 3.Ensure vSG VM and vCPE container created properly
3183 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
3184 4.Verify that ping fails as the ping packets drops at vSG VM entry
3185 """
A R Karthick63751492017-03-22 09:28:01 -07003186
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003187 def test_vsg_for_extracting_all_compute_stats_from_all_vcpe_containers(self):
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003188 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003189 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003190 1.Create a vSG VM in compute node
3191 2.Create 10 vCPE containers in VM
3192 3.Ensure vSG VM and vCPE containers created properly
3193 4.Login to all vCPE containers
3194 4.Get all compute stats from all vCPE containers
3195 5.Verify the stats # verification method need to add
3196 """
A R Karthick63751492017-03-22 09:28:01 -07003197
Anil Kumar Sankaf6a9f392017-05-06 00:18:31 +00003198 def test_vsg_for_extracting_dns_stats_from_all_vcpe_containers(self):
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003199 """
Chetan Gaonker72f3c4e2017-05-10 18:16:49 +00003200 Test Method:
Anil Kumar Sanka1213d4c2017-02-23 22:50:48 +00003201 1.Create a vSG VM in compute node
3202 2.Create 10 vCPE containers in VM
3203 3.Ensure vSG VM and vCPE containers created properly
3204 4.From 10 subscribers, send ping to valid and invalid dns hosts
3205 5.Verify dns resolves and ping success for valid dns hosts
3206 6.Verify ping fails for invalid dns hosts
3207 7.Verify dns host name resolve flows in OvS
3208 8.Login to all 10 vCPE containers
3209 9.Extract all dns stats
3210 10.Verify dns stats for queries sent, queries received for dns host resolve success and failed scenarios
3211 """
A R Karthick63751492017-03-22 09:28:01 -07003212
A R Karthick63751492017-03-22 09:28:01 -07003213