blob: f844a7b1d29d735f503e5e04ae0123526ab6ccfe [file] [log] [blame]
Chetan Gaonker357f4892017-06-19 19:38:27 +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#
15import time
16import os
17import sys
18import json
19import requests
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +000020import random
Chetan Gaonker357f4892017-06-19 19:38:27 +000021from nose.tools import *
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +000022from scapy.all import *
Chetan Gaonker357f4892017-06-19 19:38:27 +000023from twisted.internet import defer
24from nose.twistedtools import reactor, deferred
25from CordTestUtils import *
26from OltConfig import OltConfig
27from onosclidriver import OnosCliDriver
28from SSHTestAgent import SSHTestAgent
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +000029from Channels import IgmpChannel
30from IGMP import *
Chetan Gaonker357f4892017-06-19 19:38:27 +000031from CordLogger import CordLogger
32from VSGAccess import VSGAccess
33from CordTestUtils import log_test as log
34from CordTestConfig import setup_module, running_on_ciab
35from OnosCtrl import OnosCtrl
36from CordContainer import Onos
A R Karthicked3a2ca2017-07-06 15:50:03 -070037from CordSubscriberUtils import CordSubscriberUtils, XosUtils
Chetan Gaonker357f4892017-06-19 19:38:27 +000038log.setLevel('INFO')
39
40class scale_exchange(CordLogger):
41 HOST = "10.1.0.1"
42 USER = "vagrant"
43 PASS = "vagrant"
44 head_node = os.getenv('HEAD_NODE', 'prod')
45 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
46 test_path = os.path.dirname(os.path.realpath(__file__))
47 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
48 restApiXos = None
A R Karthicked3a2ca2017-07-06 15:50:03 -070049 cord_subscriber = None
50 SUBSCRIBER_ACCOUNT_NUM = 100
51 SUBSCRIBER_S_TAG = 500
52 SUBSCRIBER_C_TAG = 500
53 SUBSCRIBERS_PER_S_TAG = 8
Chetan Gaonker357f4892017-06-19 19:38:27 +000054 subscriber_info = []
55 volt_subscriber_info = []
56 restore_methods = []
57 TIMEOUT=120
58 NUM_SUBSCRIBERS = 100
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +000059 wan_intf_ip = '10.6.1.129'
60 V_INF1 = 'veth0'
61 V_INF2 = 'veth1'
62 MGROUP1 = '239.1.2.3'
63 MGROUP2 = '239.2.2.3'
64 MINVALIDGROUP1 = '255.255.255.255'
65 MINVALIDGROUP2 = '239.255.255.255'
66 MMACGROUP1 = "01:00:5e:01:02:03"
67 MMACGROUP2 = "01:00:5e:02:02:03"
68 IGMP_DST_MAC = "01:00:5e:00:00:16"
69 IGMP_SRC_MAC = "5a:e1:ac:ec:4d:a1"
70 IP_SRC = '1.2.3.4'
71 IP_DST = '224.0.0.22'
72 igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP)
73 igmp_ip = IP(dst = IP_DST)
74 PORT_TX_DEFAULT = 2
75 PORT_RX_DEFAULT = 1
76 igmp_app = 'org.opencord.igmp'
Anil Kumar Sanka8942c882017-07-07 17:05:11 +000077 acl_app = 'org.onosproject.acl'
78 aaa_app = 'org.opencord.aaa'
79 app = 'org.onosproject.cli'
80 INTF_TX_DEFAULT = 'veth2'
81 INTF_RX_DEFAULT = 'veth0'
82 default_port_map = {
83 PORT_TX_DEFAULT : INTF_TX_DEFAULT,
84 PORT_RX_DEFAULT : INTF_RX_DEFAULT,
85 INTF_TX_DEFAULT : PORT_TX_DEFAULT,
86 INTF_RX_DEFAULT : PORT_RX_DEFAULT
87 }
88 vrouter_apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
89 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
90MIIEyTCCA7GgAwIBAgIJAN3OagiHm6AXMA0GCSqGSIb3DQEBCwUAMIGLMQswCQYD
91VQQGEwJVUzELMAkGA1UECAwCQ0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UE
92CgwKQ2llbmEgSW5jLjEeMBwGCSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYw
93JAYDVQQDDB1FeGFtcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0xNzAzMTEw
94MDQ3NDNaFw0yMjEwMzEwMDQ3NDNaMIGLMQswCQYDVQQGEwJVUzELMAkGA1UECAwC
95Q0ExEjAQBgNVBAcMCVNvbWV3aGVyZTETMBEGA1UECgwKQ2llbmEgSW5jLjEeMBwG
96CSqGSIb3DQEJARYPYWRtaW5AY2llbmEuY29tMSYwJAYDVQQDDB1FeGFtcGxlIENl
97cnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
98ggEBALYkVvncfeRel/apXy5iODla5H7sUpU7a+pwT7nephmjKDh0GPX/t5GUwgkB
991zQAEj0IPoxZIfSAGSFP/mqTUK2sm7qerArih0E3kBRpnBKJZB/4r1OTZ04CsuRQ
100QJOqcI0mZJWUKEcahN4yZvRyxeiCeFFoc0Nw787MQHhD9lZTqJUoAvautUe1GCjG
10146DS4MzpWNGkqn5/ZC8lQ198AceMwf2pJRuOQg5cPwp65+dKNLUMLiSUV7JpvmAo
102of4MHtGaBxKHESZ2jPiNTT2uKI/7KxH3Pr/ctft3bcSX2d4q49B2tdEIRzC0ankm
103CrxFcq9Cb3MGaNuwWAtk3fOGKusCAwEAAaOCASwwggEoMB0GA1UdDgQWBBRtf8rH
104zJW7rliW1eZnbVbSb3obfDCBwAYDVR0jBIG4MIG1gBRtf8rHzJW7rliW1eZnbVbS
105b3obfKGBkaSBjjCBizELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQH
106DAlTb21ld2hlcmUxEzARBgNVBAoMCkNpZW5hIEluYy4xHjAcBgkqhkiG9w0BCQEW
107D2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAwwdRXhhbXBsZSBDZXJ0aWZpY2F0ZSBB
108dXRob3JpdHmCCQDdzmoIh5ugFzAMBgNVHRMEBTADAQH/MDYGA1UdHwQvMC0wK6Ap
109oCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5jb20vZXhhbXBsZV9jYS5jcmwwDQYJKoZI
110hvcNAQELBQADggEBAKWjORcBc1WK3r8mq88ipUC2UR1qvxdON4K/hd+rdAj0E/xA
111QCJDORKno8f2MktqLfhU0amCVBvwdfmVFmVDtl38b1pu+mNFO+FDp04039Fd5ThM
112iYmiQjnJ2IcAi/CILtrjURvJUPSOX9lviOtcla0HW94dgA9IDRs5frrWO9jkcxXR
113+oz3LNMfVnXqhoHHQ1RtvqOozhEsUZZWY5MuUxRY25peeZ7m1vz+zDa/DbrV1wsP
114dxOocmYdGFIAT9AiRnR4Jc/hqabBVNMZlGAA+2dELajpaHqb4yx5gBLVkT7VgHjI
1157cp7jLRL7T+i4orZiAXpeEpAeOrP8r0DYTJi/8A=
116-----END CERTIFICATE-----'''
117
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000118
Chetan Gaonker357f4892017-06-19 19:38:27 +0000119 @classmethod
120 def setUpCordApi(cls):
Chetan Gaonker357f4892017-06-19 19:38:27 +0000121 num_subscribers = max(cls.NUM_SUBSCRIBERS, 10)
A R Karthicked3a2ca2017-07-06 15:50:03 -0700122 cls.cord_subscriber = CordSubscriberUtils(num_subscribers,
123 account_num = cls.SUBSCRIBER_ACCOUNT_NUM,
124 s_tag = cls.SUBSCRIBER_S_TAG,
125 c_tag = cls.SUBSCRIBER_C_TAG,
126 subscribers_per_s_tag = cls.SUBSCRIBERS_PER_S_TAG)
127 cls.restApiXos = XosUtils.getRestApi()
Chetan Gaonker357f4892017-06-19 19:38:27 +0000128
129 @classmethod
130 def setUpClass(cls):
131 cls.controllers = get_controllers()
132 cls.controller = cls.controllers[0]
133 cls.cli = None
134 cls.on_pod = running_on_pod()
135 cls.on_ciab = running_on_ciab()
136 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
137 cls.vcpes = cls.olt.get_vcpes()
138 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
139 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
140 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
141 for i in xrange(len(cls.vcpes_reserved)) ]
142 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
143 cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
144 vcpe_dhcp_reserved = None
145 vcpe_container_reserved = None
146 if cls.vcpes_reserved:
147 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
148 if cls.on_pod is False:
149 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
150 vcpe_container_reserved = cls.container_vcpes_reserved[0]
151
152 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
153 cls.vcpe_container_reserved = vcpe_container_reserved
154 dhcp_vcpe_offset = len(cls.vcpes_reserved)
155 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
156 for i in xrange(len(cls.vcpes_dhcp)) ]
157 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
158 cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
159 vcpe_dhcp = None
160 vcpe_container = None
161 #cache the first dhcp vcpe in the class for quick testing
162 if cls.vcpes_dhcp:
163 vcpe_container = cls.container_vcpes[0]
164 vcpe_dhcp = cls.dhcp_vcpes[0]
165 if cls.on_pod is False:
166 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
167 cls.vcpe_container = vcpe_container_reserved or vcpe_container
168 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
169 VSGAccess.setUp()
A R Karthicked3a2ca2017-07-06 15:50:03 -0700170 cls.setUpCordApi()
Chetan Gaonker357f4892017-06-19 19:38:27 +0000171 if cls.on_pod is True:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700172 cls.openVCPEAccess(cls.cord_subscriber.volt_subscriber_info)
Anil Kumar Sanka8942c882017-07-07 17:05:11 +0000173 cls.activate_apps()
174
175 @classmethod
176 def activate_apps(cls, deactivate = False):
177 for app in cls.vrouter_apps:
178 onos_ctrl = OnosCtrl(app)
179 if deactivate is False:
180 onos_ctrl.activate()
181 else:
182 onos_ctrl.deactivate()
183 time.sleep(2)
184 OnosCtrl(cls.igmp_app).activate()
185 OnosCtrl(cls.acl_app).activate()
186 OnosCtrl(cls.aaa_app).activate()
Chetan Gaonker357f4892017-06-19 19:38:27 +0000187
188 @classmethod
189 def tearDownClass(cls):
190 VSGAccess.tearDown()
191 if cls.on_pod is True:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700192 cls.closeVCPEAccess(cls.cord_subscriber.volt_subscriber_info)
Chetan Gaonker357f4892017-06-19 19:38:27 +0000193
194 def log_set(self, level = None, app = 'org.onosproject'):
195 CordLogger.logSet(level = level, app = app, controllers = self.controllers, forced = True)
196
197 @classmethod
198 def config_restore(cls):
199 """Restore the vsg test configuration on test case failures"""
200 for restore_method in cls.restore_methods:
201 restore_method()
202
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000203 def get_system_cpu_usage(self):
204 """ Getting compute node CPU usage """
205 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
206 cmd = "top -b -n1 | grep 'Cpu(s)' | awk '{print $2 + $4}'"
207 status, output = ssh_agent.run_cmd(cmd)
208 assert_equal(status, True)
209 return float(output)
210
A R Karthicked3a2ca2017-07-06 15:50:03 -0700211 def vsg_for_external_connectivity(self, subscriber_index, reserved = False):
212 if reserved is True:
213 if self.on_pod is True:
214 vcpe = self.dhcp_vcpes_reserved[subscriber_index]
215 else:
216 vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index]
217 else:
218 if self.on_pod is True:
219 vcpe = self.dhcp_vcpes[subscriber_index]
220 else:
221 vcpe = self.untagged_dhcp_vcpes[subscriber_index]
222 mgmt = 'eth0'
223 host = '8.8.8.8'
224 self.success = False
225 assert_not_equal(vcpe, None)
226 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
227 assert_not_equal(vcpe_ip, None)
228 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
229 log.info('Sending icmp echo requests to external network 8.8.8.8')
230 st, _ = getstatusoutput('ping -c 3 8.8.8.8')
231 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
232 assert_equal(st, 0)
Chetan Gaonker357f4892017-06-19 19:38:27 +0000233
234 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
235 if self.on_pod is False:
236 return ''
237 if subscriber_info is None:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700238 subscriber_info = self.cord_subscriber.subscriber_info[index]
Chetan Gaonker357f4892017-06-19 19:38:27 +0000239 if volt_subscriber_info is None:
A R Karthicked3a2ca2017-07-06 15:50:03 -0700240 volt_subscriber_info = self.cord_subscriber.volt_subscriber_info[index]
Chetan Gaonker357f4892017-06-19 19:38:27 +0000241 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
242 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
243 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
A R Karthicked3a2ca2017-07-06 15:50:03 -0700244 subId = self.cord_subscriber.subscriberCreate(index, subscriber_info, volt_subscriber_info)
245 if subId:
Chetan Gaonker357f4892017-06-19 19:38:27 +0000246 #if the vsg instance was already instantiated, then reduce delay
A R Karthicked3a2ca2017-07-06 15:50:03 -0700247 if c_tag % self.SUBSCRIBERS_PER_S_TAG == 0:
Chetan Gaonker357f4892017-06-19 19:38:27 +0000248 delay = 350
249 else:
250 delay = 90
251 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
252 time.sleep(delay)
253 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
254 self.vsg_for_external_connectivity(index)
A R Karthicked3a2ca2017-07-06 15:50:03 -0700255
256 return subId
Chetan Gaonker357f4892017-06-19 19:38:27 +0000257
258 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
259 if self.on_pod is False:
260 return
A R Karthicked3a2ca2017-07-06 15:50:03 -0700261 self.cord_subscriber.subscriberDelete(index, subId = subId, voltId = voltId,
262 subscriber_info = subscriber_info,
263 volt_subscriber_info = volt_subscriber_info)
264
265 def vsg_xos_subscriber_id(self, index):
266 if self.on_pod is False:
267 return ''
268 return self.cord_subscriber.subscriberId(index)
Chetan Gaonker357f4892017-06-19 19:38:27 +0000269
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000270 def onos_load_config(self, config):
271 #log_test.info('onos load config is %s'%config)
272 status, code = OnosCtrl.config(config)
273 if status is False:
274 log_test.info('JSON request returned status %d' %code)
275 assert_equal(status, True)
276 time.sleep(2)
277
278 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],flag = False):
279 ssm_dict = {'apps' : { 'org.opencord.igmp' : { 'ssmTranslate' : [] } } }
280 ssm_xlate_list = ssm_dict['apps']['org.opencord.igmp']['ssmTranslate']
281 if flag: #to maintain seperate group-source pair.
282 for i in range(len(groups)):
283 d = {}
284 d['source'] = src_list[i] or '0.0.0.0'
285 d['group'] = groups[i]
286 ssm_xlate_list.append(d)
287 else:
288 for g in groups:
289 for s in src_list:
290 d = {}
291 d['source'] = s or '0.0.0.0'
292 d['group'] = g
293 ssm_xlate_list.append(d)
294 self.onos_load_config(ssm_dict)
295 cord_port_map = {}
296 for g in groups:
297 cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT)
298 IgmpChannel().cord_port_table_load(cord_port_map)
299 time.sleep(2)
300
301 def generate_random_multicast_ip_addresses(self,count=500):
302 multicast_ips = []
303 while(count >= 1):
304 ip = '.'.join([str(random.randint(224,239)),str(random.randint(1,254)),str(random.randint(1,254)),str(random.randint(1,254))])
305 if ip in multicast_ips:
306 pass
307 else:
308 multicast_ips.append(ip)
309 count -= 1
310 return multicast_ips
311
312 def generate_random_unicast_ip_addresses(self,count=500):
313 unicast_ips = []
314 while(count >= 1):
315 ip = '.'.join([str(random.randint(11,126)),str(random.randint(1,254)),str(random.randint(1,254)),str(random.randint(1,254))])
316 if ip in unicast_ips:
317 pass
318 else:
319 unicast_ips.append(ip)
320 count -= 1
321 return unicast_ips
322
323 def iptomac(self, mcast_ip):
324 mcast_mac = '01:00:5e:'
325 octets = mcast_ip.split('.')
326 second_oct = int(octets[1]) & 127
327 third_oct = int(octets[2])
328 fourth_oct = int(octets[3])
329 mcast_mac = mcast_mac + format(second_oct,'02x') + ':' + format(third_oct, '02x') + ':' + format(fourth_oct, '02x')
330 return mcast_mac
331
332 def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
333 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1):
334 if ssm_load is True:
335 self.onos_ssm_table_load(groups, src_list)
336 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
337 gaddr=self.IP_DST)
338 for g in groups:
339 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
340 gr.sources = src_list
341 igmp.grps.append(gr)
342 if ip_pkt is None:
343 ip_pkt = self.igmp_eth/self.igmp_ip
344 pkt = ip_pkt/igmp
345 IGMPv3.fixup(pkt)
346 log.info('sending igmp join packet %s'%pkt.show())
347 sendp(pkt, iface=iface)
348 time.sleep(delay)
349
350 def send_multicast_data_traffic(self, group, intf= 'veth2',source = '1.2.3.4'):
351 dst_mac = self.iptomac(group)
352 eth = Ether(dst= dst_mac)
353 ip = IP(dst=group,src=source)
354 data = repr(monotonic.monotonic())
355 sendp(eth/ip/data,count=20, iface = intf)
356
357 def verify_igmp_data_traffic(self, group, intf='veth0', source='1.2.3.4' ):
358 log_test.info('verifying multicast traffic for group %s from source %s'%(group,source))
359 self.success = False
360 def recv_task():
361 def igmp_recv_cb(pkt):
362 #log_test.info('received multicast data packet is %s'%pkt.show())
363 log_test.info('multicast data received for group %s from source %s'%(group,source))
364 self.success = True
365 sniff(prn = igmp_recv_cb,lfilter = lambda p: IP in p and p[IP].dst == group and p[IP].src == source, count=1,timeout = 2, iface='veth0')
366 t = threading.Thread(target = recv_task)
367 t.start()
368 self.send_multicast_data_traffic(group,source=source)
369 t.join()
370 return self.success
371
Anil Kumar Sanka8942c882017-07-07 17:05:11 +0000372 def incmac(self, mac):
373 tmp = str(hex(int('0x'+mac,16)+1).split('x')[1])
374 mac = '0'+ tmp if len(tmp) < 2 else tmp
375 return mac
376
377 def next_mac(self, mac):
378 mac = mac.split(":")
379 mac[5] = self.incmac(mac[5])
380
381 if len(mac[5]) > 2:
382 mac[0] = self.incmac(mac[0])
383 mac[5] = '01'
384
385 if len(mac[0]) > 2:
386 mac[0] = '01'
387 mac[1] = self.incmac(mac[1])
388 mac[5] = '01'
389 return ':'.join(mac)
390
391
392 def to_egress_mac(cls, mac):
393 mac = mac.split(":")
394 mac[4] = '01'
395
396 return ':'.join(mac)
397
398 def inc_ip(self, ip, i):
399
400 ip[i] =str(int(ip[i])+1)
401 return '.'.join(ip)
402
403
404 def next_ip(self, ip):
405
406 lst = ip.split('.')
407 for i in (3,0,-1):
408 if int(lst[i]) < 255:
409 return self.inc_ip(lst, i)
410 elif int(lst[i]) == 255:
411 lst[i] = '0'
412 if int(lst[i-1]) < 255:
413 return self.inc_ip(lst,i-1)
414 elif int(lst[i-2]) < 255:
415 lst[i-1] = '0'
416 return self.inc_ip(lst,i-2)
417 else:
418 break
419
420 def to_egress_ip(self, ip):
421 lst=ip.split('.')
422 lst[0] = '182'
423 return '.'.join(lst)
424
425 @classmethod
426 def start_onos(cls, network_cfg = None):
427 if type(network_cfg) is tuple:
428 res = []
429 for v in network_cfg:
430 res += v.items()
431 config = dict(res)
432 else:
433 config = network_cfg
434 log_test.info('Restarting ONOS with new network configuration')
435 return cord_test_onos_restart(config = config)
436
437 @classmethod
438 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
439 log_test.info('Restarting Quagga container with configuration for %d networks' %(networks))
440 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
441 if networks <= 10000:
442 boot_delay = 25
443 else:
444 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
445 n = min(networks/100000, len(delay_map)-1)
446 boot_delay = delay_map[n]
447 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
448
449 @classmethod
450 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
451 num = 0
452 if peer_address is None:
453 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
454 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
455 else:
456 ip = peer_address[0][0]
457 start_ip = ip.split('.')
458 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
459 end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
460 local_network = end_peer + 1
461 ports_dict = { 'ports' : {} }
462 interface_list = []
463 peer_list = []
464 for n in xrange(start_peer, end_peer, 256):
465 port_map = ports_dict['ports']
466 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
467 device_port_key = '{0}/{1}'.format(cls.device_id, port)
468 try:
469 interfaces = port_map[device_port_key]['interfaces']
470 except:
471 port_map[device_port_key] = { 'interfaces' : [] }
472 interfaces = port_map[device_port_key]['interfaces']
473 ip = n + 2
474 peer_ip = n + 1
475 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
476 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
477 mac = RandMAC()._fix()
478 peer_list.append((peer, mac))
479 if num < cls.MAX_PORTS - 1:
480 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
481 interfaces.append(interface_dict)
482 interface_list.append(interface_dict['name'])
483 else:
484 interfaces[0]['ips'].append(ips)
485 num += 1
486 if num == peers:
487 break
488 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
489 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
490 quagga_router_dict['ospfEnabled'] = True
491 quagga_router_dict['interfaces'] = interface_list
492 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
493
494 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
495 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
496 speaker_dict = {}
497 speaker_dict['name'] = 'bgp{}'.format(peers+1)
498 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
499 speaker_dict['peers'] = peer_list
500 bgp_speakers_list.append(speaker_dict)
501 cls.peer_list = peer_list
502 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
503 @classmethod
504 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
505 num = 0
506 if router_address is None:
507 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
508 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
509 network_mask = 24
510 else:
511 ip = router_address
512 start_ip = ip.split('.')
513 network_mask = int(start_ip[3].split('/')[1])
514 start_ip[3] = (start_ip[3].split('/'))[0]
515 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
516 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
517 net_list = []
518 peer_list = peer_address if peer_address is not None else cls.peer_list
519 network_list = []
520 for n in xrange(start_network, end_network, 256):
521 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
522 network_list.append(net)
523 gateway = peer_list[num % len(peer_list)][0]
524 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
525 net_list.append(net_route)
526 num += 1
527 if num == networks:
528 break
529 cls.network_list = network_list
530 cls.network_mask = network_mask
531 zebra_routes = '\n'.join(net_list)
532 #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
533 return cls.zebra_conf + zebra_routes
534
535 @classmethod
536 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
537 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
538 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
539 peer_address = peer_address, route_update = route_update)
540 cls.start_onos(network_cfg = vrouter_configs)
541 cls.activate_apps()
542 time.sleep(5)
543 cls.vrouter_host_load()
544 ##Start quagga
545 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
546 return vrouter_configs
547
548 def __vrouter_network_verify(self, networks, peers = 1, positive_test = True,
549 start_network = None, start_peer_address = None, route_update = None,
550 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
551 deactivate_activate_vrouter = None, adding_new_routes = None):
552
553 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
554 peer_address = start_peer_address,
555 route_update = route_update,
556 router_address = start_network,
557 time_expire = time_expire,
558 adding_new_routes = adding_new_routes)
559 self.cliEnter()
560 ##Now verify
561 hosts = json.loads(self.cli.hosts(jsonFormat = True))
562 log_test.info('Discovered hosts: %s' %hosts)
563 ##We read from cli if we expect less number of routes to avoid cli timeouts
564 if networks <= 10000:
565 routes = json.loads(self.cli.routes(jsonFormat = True))
566 #log_test.info('Routes: %s' %routes)
567 if start_network is not None:
568 if start_network.split('/')[1] is 24:
569 assert_equal(len(routes['routes4']), networks)
570 if start_network.split('/')[1] is not 24:
571 assert_equal(len(routes['routes4']), 1)
572 if start_network is None and invalid_peers is None:
573 assert_equal(len(routes['routes4']), networks)
574 if invalid_peers is not None:
575 assert_equal(len(routes['routes4']), 0)
576 flows = json.loads(self.cli.flows(jsonFormat = True))
577 flows = filter(lambda f: f['flows'], flows)
578 #log_test.info('Flows: %s' %flows)
579 assert_not_equal(len(flows), 0)
580 if invalid_peers is None:
581 self.vrouter_traffic_verify()
582 if positive_test is False:
583 self.__vrouter_network_verify_negative(networks, peers = peers)
584 if time_expire is True:
585 self.start_quagga(networks = networks, peer_address = start_peer_address, router_address = '12.10.10.1/24')
586 self.vrouter_traffic_verify()
587 if unreachable_route_traffic is True:
588 network_list_backup = self.network_list
589 self.network_list = ['2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5']
590 self.vrouter_traffic_verify(positive_test = False)
591 self.network_list = network_list_backup
592 if deactivate_activate_vrouter is True:
593 log_test.info('Deactivating vrouter app in ONOS controller for negative scenario')
594 self.vrouter_activate(deactivate = True)
595 #routes = json.loads(self.cli.routes(jsonFormat = False, cmd_exist = False))
596 #assert_equal(len(routes['routes4']), 'Command not found')
597 log_test.info('Activating vrouter app again in ONOS controller for negative scenario')
598 self.vrouter_activate(deactivate = False)
599 routes = json.loads(self.cli.routes(jsonFormat = True))
600 assert_equal(len(routes['routes4']), networks)
601 self.vrouter_traffic_verify()
602 self.cliExit()
603 self.vrouter_host_unload()
604 return True
605
606 def onos_aaa_config(self):
607 aaa_dict = {'apps' : { self.app : { 'AAA' : { 'radiusSecret': 'radius_password',
608 'radiusIp': '172.17.0.2' } } } }
609 radius_ip = os.getenv('ONOS_AAA_IP') or '172.17.0.2'
610 aaa_dict['apps'][self.app]['AAA']['radiusIp'] = radius_ip
611 self.onos_ctrl.activate()
612 time.sleep(2)
613 self.onos_load_config(aaa_dict)
614
615 def onos_load_config(self, config):
616 status, code = OnosCtrl.config(config)
617 if status is False:
618 log_test.info('Configure request for AAA returned status %d' %code)
619 assert_equal(status, True)
620 time.sleep(3)
621
Chetan Gaonker357f4892017-06-19 19:38:27 +0000622 def test_scale_for_vsg_vm_creations(self):
A R Karthicked3a2ca2017-07-06 15:50:03 -0700623 for index in xrange(len(self.cord_subscriber.subscriber_info)):
Chetan Gaonker357f4892017-06-19 19:38:27 +0000624 #check if the index exists
625 subId = self.vsg_xos_subscriber_id(index)
626 log.info('test_vsg_xos_subscriber_creation')
627 if subId and subId != '0':
628 self.vsg_xos_subscriber_delete(index, subId = subId)
629 subId = self.vsg_xos_subscriber_create(index)
630 log.info('Created Subscriber %s' %(subId))
631
632 def test_scale_for_vcpe_creations(self):
A R Karthicked3a2ca2017-07-06 15:50:03 -0700633 for index in xrange(len(self.cord_subscriber.subscriber_info)):
Chetan Gaonker357f4892017-06-19 19:38:27 +0000634 #check if the index exists
635 subId = self.vsg_xos_subscriber_id(index)
636 log.info('test_vsg_xos_subscriber_creation')
637 if subId and subId != '0':
638 self.vsg_xos_subscriber_delete(index, subId = subId)
639 subId = self.vsg_xos_subscriber_create(index)
640 log.info('Created Subscriber %s' %(subId))
641
642 def test_scale_of_subcriber_vcpe_creations_in_single_vsg_vm(self):
643 subId = self.vsg_xos_subscriber_create(100)
644 if subId and subId != '0':
645 self.vsg_xos_subscriber_delete(100, subId)
646
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000647 def test_scale_of_subcriber_vcpe_creations_in_multiple_vsg_vm(self):
648 subId = self.vsg_xos_subscriber_create(100)
649 if subId and subId != '0':
650 self.vsg_xos_subscriber_delete(100, subId)
651
652 def test_scale_of_subcriber_vcpe_creations_with_one_vcpe_in_one_vsg_vm(self):
653 subId = self.vsg_xos_subscriber_create(100)
654 if subId and subId != '0':
655 self.vsg_xos_subscriber_delete(100, subId)
656
Chetan Gaonker357f4892017-06-19 19:38:27 +0000657 def test_scale_for_cord_subscriber_creation_and_deletion(self):
658 subId = self.vsg_xos_subscriber_create(100)
659 if subId and subId != '0':
660 self.vsg_xos_subscriber_delete(100, subId)
661
662 def test_cord_for_scale_of_subscriber_containers_per_compute_node(self):
663 pass
664
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000665 def test_latency_of_cord_for_control_packets_using_icmp_packet(self):
666 cmd = "ping -c 4 {0} | tail -1| awk '{{print $4}}'".format(self.wan_intf_ip)
667 st, out = getstatusoutput(cmd)
668 if out != '':
669 out = out.split('/')
670 avg_rtt = out[1]
671 latency = float(avg_rtt)/float(2)
672 else:
673 latency = None
674 log.info('CORD setup latency calculated from icmp packet is = %s ms'%latency)
675 assert_not_equal(latency,None)
676
677 def test_latency_of_cord_for_control_packets_using_increasing_sizes_of_icmp_packet(self):
678 pckt_sizes = [100,500,1000,1500]
679 for size in pckt_sizes:
680 cmd = "ping -c 4 -s {} {} | tail -1| awk '{{print $4}}'".format(size,self.wan_intf_ip)
681 st, out = getstatusoutput(cmd)
682 if out != '':
683 out = out.split('/')
684 avg_rtt = out[1]
685 latency = float(avg_rtt)/float(2)
686 else:
687 latency = None
688 log.info('CORD setup latency calculated from icmp packet with size %s bytes is = %s ms'%(size,latency))
689 assert_not_equal(latency,None)
690
691 def test_latency_of_cord_with_traceroute(self):
692 cmd = "traceroute -q1 {} | tail -1| awk '{{print $4}}'".format(self.wan_intf_ip)
693 avg_rtt = float(0)
694 latency = None
695 for index in [1,2,3]:
696 st, out = getstatusoutput(cmd)
697 if out != '':
698 avg_rtt += float(out)
699 latency = float(avg_rtt)/float(6)
700 log.info('CORD setup latency calculated from traceroute is = %s ms'%latency)
701 assert_not_equal(latency,0.0)
702
703 def test_scale_with_igmp_joins_for_500_multicast_groups_and_check_cpu_usage(self, group_count=500):
704 OnosCtrl(self.igmp_app).activate()
705 groups = self.generate_random_multicast_ip_addresses(count = group_count)
706 sources = self.generate_random_unicast_ip_addresses(count = group_count)
707 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
708 for index in range(group_count):
709 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
710 iface = self.V_INF1)
711 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
712 assert_equal(status, True)
713 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
714 if index % 50 == 0:
715 cpu_usage = self.get_system_cpu_usage()
716 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
717
718 def test_scale_with_igmp_joins_for_1000_multicast_groups_and_check_cpu_usage(self, group_count=1000):
719 OnosCtrl(self.igmp_app).activate()
720 groups = self.generate_random_multicast_ip_addresses(count = group_count)
721 sources = self.generate_random_unicast_ip_addresses(count = group_count)
722 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
723 for index in range(group_count):
724 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
725 iface = self.V_INF1)
726 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
727 assert_equal(status, True)
728 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
729 if index % 50 == 0:
730 cpu_usage = self.get_system_cpu_usage()
731 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
732
733 def test_scale_with_igmp_joins_for_2000_multicast_groups_and_check_cpu_usage(self, group_count=2000):
734 OnosCtrl(self.igmp_app).activate()
735 groups = self.generate_random_multicast_ip_addresses(count = group_count)
736 sources = self.generate_random_unicast_ip_addresses(count = group_count)
737 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
738 for index in range(group_count):
739 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
740 iface = self.V_INF1)
741 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
742 assert_equal(status, True)
743 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
744 if index % 50 == 0:
745 cpu_usage = self.get_system_cpu_usage()
746 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
747
Anil Kumar Sanka8942c882017-07-07 17:05:11 +0000748 def test_scale_of_igmp_joins_for_2000_multicast_groups_and_check_cpu_usage_after_app_deactivation_and_activation(self,group_count=500):
Anil Kumar Sanka12a5ec52017-06-29 18:41:51 +0000749 OnosCtrl(self.igmp_app).activate()
750 groups = self.generate_random_multicast_ip_addresses(count = group_count)
751 sources = self.generate_random_unicast_ip_addresses(count = group_count)
752 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
753 for index in range(group_count):
754 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
755 iface = self.V_INF1)
756 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
757 assert_equal(status, True)
758 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
759 if index % 50 == 0:
760 cpu_usage = self.get_system_cpu_usage()
761 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
762 OnosCtrl(self.igmp_app).deactivate()
763 time.sleep(1)
764 cpu_usage = self.get_system_cpu_usage()
765 log.info('CPU usage is %s for multicast group entries %s after igmp app deactivated'%(cpu_usage,index+1))
Anil Kumar Sanka8942c882017-07-07 17:05:11 +0000766
767 def test_scale_adding_1k_flow_entries_in_onos_with_dynamic_tcp_ports(self,count=1000):
768 cpu_usage1 = self.get_system_cpu_usage()
769 egress = 1
770 ingress = 2
771 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': random.randint(1024,65535) }
772 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': random.randint(1024,65535) }
773 for index in range(0,count):
774 ingress_map['tcp_port'] = random.randint(1024,65535)
775 egress_map['tcp_port'] = random.randint(1024,65535)
776 flow = OnosFlowCtrl(deviceId = self.device_id,
777 egressPort = egress + self.port_offset,
778 ingressPort = ingress + self.port_offset,
779 tcpSrc = ingress_map['tcp_port'],
780 tcpDst = egress_map['tcp_port']
781 )
782 result = flow.addFlow()
783 assert_equal(result, True)
784 log_test.info("flow number = %d is added",index+1)
785 if index % 50 == 0:
786 cpu_usage = self.get_system_cpu_usage()
787 log.info('CPU usage is %s for flow number %d added'%(cpu_usage,index+1))
788 time.sleep(1)
789 cpu_usage2 = self.get_system_cpu_usage()
790 log.info('system cpu usage before flows added = %f and after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
791
792 def test_scale_adding_5k_constant_source_ip_flow_entries_in_onos_and_checking_cpu_usage(self,count=5000):
793 cpu_usage1 = self.get_system_cpu_usage()
794 egress = 1
795 ingress = 2
796 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '182.0.0.0' }
797 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.0.0.0' }
798 for i in range(0,count):
799 ingress_map['ip'] = self.next_ip(ingress_map['ip'])
800 assert_not_equal(ingress_map['ip'], None)
801 egress_map['ip'] = self.to_egress_ip(ingress_map['ip'])
802
803 flow = OnosFlowCtrl(deviceId = self.device_id,
804 egressPort = egress + self.port_offset,
805 ingressPort = ingress + self.port_offset,
806 ethType = '0x0800',
807 ipSrc = ('IPV4_SRC', ingress_map['ip']+'/8'),
808 ipDst = ('IPV4_DST', egress_map['ip']+'/8')
809 )
810 if index % 50 == 0:
811 cpu_usage = self.get_system_cpu_usage()
812 log.info('CPU usage is %s for flow number %d added'%(cpu_usage,index+1))
813 time.sleep(1)
814 cpu_usage2 = self.get_system_cpu_usage()
815 log.info('system cpu usage before flows added = %f and after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
816
817 def test_scale_adding_10k_flow_entries_in_onos_with_dynamic_udp_ports(self,count=10000):
818 cpu_usage1 = self.get_system_cpu_usage()
819 egress = 1
820 ingress = 2
821 egress_map = { 'ether': '00:00:00:00:00:03', 'ip': '192.168.30.1', 'tcp_port': random.randint(1024,65535) }
822 ingress_map = { 'ether': '00:00:00:00:00:04', 'ip': '192.168.40.1', 'tcp_port': random.randint(1024,65535) }
823 for index in range(0,count):
824 ingress_map['tcp_port'] = random.randint(1024,65535)
825 egress_map['tcp_port'] = random.randint(1024,65535)
826 flow = OnosFlowCtrl(deviceId = self.device_id,
827 egressPort = egress + self.port_offset,
828 ingressPort = ingress + self.port_offset,
829 tcpSrc = ingress_map['tcp_port'],
830 tcpDst = egress_map['tcp_port']
831 )
832 result = flow.addFlow()
833 assert_equal(result, True)
834 ##wait for flows to be added to ONOS
835 log_test.info("flow number = %d is added",index+1)
836 if index % 50 == 0:
837 cpu_usage = self.get_system_cpu_usage()
838 log.info('CPU usage is %s for flow number %d added'%(cpu_usage,index+1))
839 time.sleep(1)
840 cpu_usage2 = self.get_system_cpu_usage()
841 log.info('system cpu usage before flows added = %f and after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
842
843 def test_scale_adding_10k_constant_destination_mac_flow_entries_in_onos_and_check_cpu_usage(self,count=10000):
844 cpu_usage1 = self.get_system_cpu_usage()
845 egress = 1
846 ingress = 2
847 egress_mac = '00:00:00:00:01:01'
848 ingress_mac = '02:00:00:00:00:00'
849 for index in range(0,count):
850 ingress_mac = self.next_mac(ingress_mac)
851 flow = OnosFlowCtrl(deviceId = self.device_id,
852 egressPort = egress + self.port_offset,
853 ingressPort = ingress + self.port_offset,
854 ethSrc = ingress_mac,
855 ethDst = egress_mac)
856 result = flow.addFlow()
857 assert_equal(result, True)
858 log.info("flow number = %d is added",index+1)
859 if index % 100 == 0:
860 cpu_usage = self.get_system_cpu_usage()
861 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
862 time.sleep(1)
863 cpu_usage2 = self.get_system_cpu_usage()
864 log.info('system cpu usage before flows added = %f and after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
865
866 def test_scale_adding_10k_acl_rules_to_deny_matching_destination_tcp_port_traffic(self,count=10000):
867 cpu_usage1 = self.get_system_cpu_usage()
868 acl_rule = ACLTest()
869 for index in range(0,count):
870 src_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
871 dst_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
872 dst_port = random.randint(1024,65535)
873 log.info('adding acl rule = %d with src ip = %s, dst ip = %s and dst tcp port = %d'%(index+1, src_ip,dst_ip,dst_port))
874 status,code = acl_rule.adding_acl_rule('v4', srcIp=src_ip, dstIp = dst_ip, ipProto ='TCP', dstTpPort =dst_port, action = 'deny')
875 assert_equal(status, True)
876 if index % 100 == 0:
877 cpu_usage = self.get_system_cpu_usage()
878 log.info('CPU usage is %s for multicast group entries %s'%(cpu_usage,index+1))
879 time.sleep(1)
880 cpu_usage2 = self.get_system_cpu_usage()
881 log.info('system cpu usage before flows added = %f and after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
882
883 def test_scale_adding_and_deleting_10k_acl_rules_to_allow_src_and_dst_ip_matching_traffic_check_cpu_usage(self,count=10000):
884 cpu_usage1 = self.get_system_cpu_usage()
885 acl_rule = ACLTest()
886 for index in range(0,count):
887 src_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
888 dst_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
889 dst_port = random.randint(1024,65535)
890 log.info('adding acl rule = %d with src ip = %s, dst ip = %s '%(index+1, src_ip,dst_ip))
891 status,code = acl_rule.adding_acl_rule('v4', srcIp=src_ip, dstIp = dst_ip,action = 'allow')
892 assert_equal(status, True)
893 if index % 100 == 0:
894 cpu_usage = self.get_system_cpu_usage()
895 log.info('CPU usage is %s for acl rule number %s'%(cpu_usage,index+1))
896 time.sleep(1)
897 cpu_usage2 = self.get_system_cpu_usage()
898 result = acl_rule.get_acl_rules()
899 result = result.json()['aclRules']
900 for acl in result:
901 acl_rule.remove_acl_rule(acl['id'])
902 #log.info('acl is %s'%acl)
903 cpu_usage3 = self.get_system_cpu_usage()
904 log.info('system cpu usage before flows added = %f and after %d flows added = %f, after deleting all acl rules = %f'%(cpu_usage1,count,cpu_usage2,cpu_usage3))
905
906 def test_scale_adding_20k_acl_rules_to_allow_src_and_dst_ip_matching_traffic_and_deactivate_acl_app_checking_cpu_usage(self,count=20000):
907 cpu_usage1 = self.get_system_cpu_usage()
908 acl_rule = ACLTest()
909 for index in range(0,count):
910 src_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
911 dst_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
912 dst_port = random.randint(1024,65535)
913 log.info('adding acl rule = %d with src ip = %s, dst ip = %s '%(index+1, src_ip,dst_ip))
914 status,code = acl_rule.adding_acl_rule('v4', srcIp=src_ip, dstIp = dst_ip,action = 'allow')
915 assert_equal(status, True)
916 if index % 200 == 0:
917 cpu_usage = self.get_system_cpu_usage()
918 log.info('CPU usage is %s for acl rule number %s'%(cpu_usage,index+1))
919 time.sleep(1)
920 cpu_usage2 = self.get_system_cpu_usage()
921 OnosCtrl(cls.acl_app).deactivate()
922 time.sleep(3)
923 cpu_usage3 = self.get_system_cpu_usage()
924 log.info('system cpu usage before flows added = %f, after %d flows added = %f, and after deactivating acl app = %f'%(cpu_usage1,count,cpu_usage2,cpu_usage3))
925
926 def test_scale_adding_igmp_and_acl_with_flow_entries_and_check_cpu_usage(self,igmp_groups=1300, flows_count=10000):
927 cpu_usage1 = self.get_system_cpu_usage()
928 egress = 1
929 ingress = 2
930 egress_mac = '00:00:00:00:01:01'
931 ingress_mac = '02:00:00:00:00:00'
932 acl_rule = ACLTest()
933 OnosCtrl(self.igmp_app).activate()
934 groups = self.generate_random_multicast_ip_addresses(count = igmp_groups)
935 sources = self.generate_random_unicast_ip_addresses(count = igmp_groups)
936 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
937 for index in range(igmp_groups):
938 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
939 iface = self.V_INF1)
940 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
941 assert_equal(status, True)
942 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
943 for index in range(flows_count):
944 src_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
945 dst_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
946 log.info('adding acl rule = %d with src ip = %s, dst ip = %s '%(index+1, src_ip,dst_ip))
947 status,code = acl_rule.adding_acl_rule('v4', srcIp=src_ip, dstIp = dst_ip,action = 'allow')
948 assert_equal(status, True)
949 ingress_mac = self.next_mac(ingress_mac)
950 flow = OnosFlowCtrl(deviceId = self.device_id,
951 egressPort = egress + self.port_offset,
952 ingressPort = ingress + self.port_offset,
953 ethSrc = ingress_mac,
954 ethDst = egress_mac)
955 result = flow.addFlow()
956 assert_equal(result, True)
957 log.info("flow number = %d is added",index+1)
958 if index % 200 == 0:
959 cpu_usage = self.get_system_cpu_usage()
960 log.info('CPU usage is %s for acl rule number %s'%(cpu_usage,index+1))
961 time.sleep(1)
962 cpu_usage2 = self.get_system_cpu_usage()
963 log.info('system cpu usage before flows added = %f, after %d flows added = %f'%(cpu_usage1,count,cpu_usage2))
964
965 def test_scale_adding_igmp_acl_and_flow_entries_and_simultaneously_toggling_app_activation(self,igmp_groups=1300, flows_count=10000):
966 cpu_usage1 = self.get_system_cpu_usage()
967 def adding_igmp_entries():
968 OnosCtrl(self.igmp_app).activate()
969 groups = self.generate_random_multicast_ip_addresses(count = igmp_groups)
970 sources = self.generate_random_unicast_ip_addresses(count = igmp_groups)
971 self.onos_ssm_table_load(groups,src_list=sources,flag=True)
972 for index in range(igmp_groups):
973 self.send_igmp_join(groups = [groups[index]], src_list = [sources[index]],record_type = IGMP_V3_GR_TYPE_INCLUDE,
974 iface = self.V_INF1)
975 status = self.verify_igmp_data_traffic(groups[index],intf=self.V_INF1,source=sources[index])
976 assert_equal(status, True)
977 log_test.info('data received for group %s from source %s - %d'%(groups[index],sources[index],index))
978 def adding_flow_entries():
979 egress = 1
980 ingress = 2
981 egress_mac = '00:00:00:00:01:01'
982 ingress_mac = '02:00:00:00:00:00'
983 for index in range(flows_count):
984 ingress_mac = self.next_mac(ingress_mac)
985 flow = OnosFlowCtrl(deviceId = self.device_id,
986 egressPort = egress + self.port_offset,
987 ingressPort = ingress + self.port_offset,
988 ethSrc = ingress_mac,
989 ethDst = egress_mac)
990 result = flow.addFlow()
991 assert_equal(result, True)
992 log.info("flow number = %d is added",index+1)
993 def adding_acl_entries():
994 OnosCtrl(self.acl_app).activate()
995 for index in range(flows_count):
996 src_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
997 dst_ip = self.generate_random_unicast_ip_addresses(count=1)[0]+'/32'
998 dst_port = random.randint(1024,65535)
999 log.info('adding acl rule = %d with src ip = %s, dst ip = %s and dst tcp port = %d'%(index+1, src_ip,dst_ip,dst_port))
1000 status,code = acl_rule.adding_acl_rule('v4', srcIp=src_ip, dstIp = dst_ip, ipProto ='TCP', dstTpPort =dst_port, action = 'deny')
1001 assert_equal(status, True)
1002 igmp_thread = threading.Thread(target = adding_igmp_entries)
1003 flows_thread = threading.Thread(target = adding_flow_entries)
1004 acl_thread = threading.Thread(target = adding_acl_entries)
1005 igmp_thread.start()
1006 flows_thread.start()
1007 acl_thread.start()
1008 time.sleep(1)
1009 igmp_thread.join()
1010 flows_thread.join()
1011 acl_thread.join()
1012 cpu_usage2 = self.get_system_cpu_usage()
1013 OnosCtrl(self.igmp_app).deactivate()
1014 OnosCtrl(self.acl_app).deactivate()
1015 cpu_usage3 = self.get_system_cpu_usage()
1016 log.info('cpu usage before test start = %f, after igmp,flow and acl entries loaded = %f and after the apps deactivated = %f'%(cpu_usage1,cpu_usage2,cpu_usage3))
1017 OnosCtrl(self.igmp_app).activate()
1018 OnosCtrl(self.acl_app).activate()
1019
1020 def test_scale_for_vrouter_with_10000_routes(self):
1021 res = self.__vrouter_network_verify(10000, peers = 1)
1022 assert_equal(res, True)
1023
1024 def test_scale_for_vrouter_with_20000_routes(self):
1025 res = self.__vrouter_network_verify(20000, peers = 2)
1026 assert_equal(res, True)
1027
1028 def test_scale_for_vrouter_with_20000_routes(self):
1029 res = self.__vrouter_network_verify(20000, peers = 100)
1030 assert_equal(res, True)
1031
1032 #simulating authentication for multiple users, 5K in this test case
1033 @deferred(TEST_TIMEOUT+1800)
1034 def test_scale_of_eap_tls_with_5k_sessions_using_diff_mac(self):
1035 df = defer.Deferred()
1036 def eap_tls_5k_with_diff_mac(df):
1037 for i in xrange(5000):
1038 tls = TLSAuthTest(src_mac = 'random')
1039 tls.runTest()
1040 log_test.info('Authentication successfull for user %d'%i)
1041 df.callback(0)
1042 reactor.callLater(0, eap_tls_5k_with_diff_mac, df)
1043 return df