blob: 6c14872eb070cb0de93630f7ab11f93d1dbf586d [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +000017import os
18from nose.tools import *
19from scapy.all import *
20import requests
21from twisted.internet import defer
22from nose.twistedtools import reactor, deferred
23from CordTestUtils import *
24from CordTestUtils import log_test as log
25from OltConfig import OltConfig
26from onosclidriver import OnosCliDriver
27from SSHTestAgent import SSHTestAgent
28from Channels import Channels, IgmpChannel
29from IGMP import *
30import time, monotonic
31from CordLogger import CordLogger
32from VSGAccess import VSGAccess
33#imports for cord-subscriber module
34from subscriberDb import SubscriberDB
35from Stats import Stats
36from threadPool import ThreadPool
37import threading
38from EapTLS import TLSAuthTest
39from CordTestUtils import log_test as log
40from CordTestConfig import setup_module, running_on_ciab
41from OnosCtrl import OnosCtrl
42from CordContainer import Onos
43from CordSubscriberUtils import CordSubscriberUtils, XosUtils
44from CordTestServer import cord_test_onos_restart, cord_test_quagga_restart, cord_test_shell, cord_test_radius_restart
45
46
47log.setLevel('INFO')
48
49class Subscriber(Channels):
50 log.info('in Subscriber class 0000000')
51 PORT_TX_DEFAULT = 2
52 PORT_RX_DEFAULT = 1
53 INTF_TX_DEFAULT = 'veth2'
54 INTF_RX_DEFAULT = 'veth0'
55 STATS_RX = 0
56 STATS_TX = 1
57 STATS_JOIN = 2
58 STATS_LEAVE = 3
59 SUBSCRIBER_SERVICES = 'DHCP IGMP TLS'
60
61 def __init__(self, name = 'sub', service = SUBSCRIBER_SERVICES, port_map = None,
62 num = 1, channel_start = 0,
63 tx_port = PORT_TX_DEFAULT, rx_port = PORT_RX_DEFAULT,
64 iface = INTF_RX_DEFAULT, iface_mcast = INTF_TX_DEFAULT,
65 mcast_cb = None, loginType = 'wireless'):
66 self.tx_port = tx_port
67 self.rx_port = rx_port
68 self.port_map = port_map or g_subscriber_port_map
69 try:
70 self.tx_intf = self.port_map[tx_port]
71 self.rx_intf = self.port_map[rx_port]
72 except:
73 self.tx_intf = self.port_map[self.PORT_TX_DEFAULT]
74 self.rx_intf = self.port_map[self.PORT_RX_DEFAULT]
75
76 log_test.info('Subscriber %s, rx interface %s, uplink interface %s' %(name, self.rx_intf, self.tx_intf))
77 Channels.__init__(self, num, channel_start = channel_start,
78 iface = self.rx_intf, iface_mcast = self.tx_intf, mcast_cb = mcast_cb)
79 self.name = name
80 self.service = service
81 self.service_map = {}
82 services = self.service.strip().split(' ')
83 for s in services:
84 self.service_map[s] = True
85 self.loginType = loginType
86 ##start streaming channels
87 self.join_map = {}
88 ##accumulated join recv stats
89 self.join_rx_stats = Stats()
90 self.recv_timeout = False
91 def has_service(self, service):
92 if self.service_map.has_key(service):
93 return self.service_map[service]
94 if self.service_map.has_key(service.upper()):
95 return self.service_map[service.upper()]
96 return False
97
98 def channel_join_update(self, chan, join_time):
99 self.join_map[chan] = ( Stats(), Stats(), Stats(), Stats() )
100 self.channel_update(chan, self.STATS_JOIN, 1, t = join_time)
101 def channel_join(self, chan = 0, delay = 2):
102 '''Join a channel and create a send/recv stats map'''
103 if self.join_map.has_key(chan):
104 del self.join_map[chan]
105 self.delay = delay
106 chan, join_time = self.join(chan)
107 self.channel_join_update(chan, join_time)
108 return chan
109
110 def channel_join_next(self, delay = 2, leave_flag = True):
111 '''Joins the next channel leaving the last channel'''
112 if self.last_chan:
113 if self.join_map.has_key(self.last_chan):
114 del self.join_map[self.last_chan]
115 self.delay = delay
116 chan, join_time = self.join_next(leave_flag = leave_flag)
117 self.channel_join_update(chan, join_time)
118 return chan
119
120 def channel_jump(self, delay = 2):
121 '''Jumps randomly to the next channel leaving the last channel'''
122 if self.last_chan is not None:
123 if self.join_map.has_key(self.last_chan):
124 del self.join_map[self.last_chan]
125 self.delay = delay
126 chan, join_time = self.jump()
127 self.channel_join_update(chan, join_time)
128 return chan
129
130 def channel_leave(self, chan = 0, force = False):
131 if self.join_map.has_key(chan):
132 del self.join_map[chan]
133 self.leave(chan, force = force)
134
135 def channel_update(self, chan, stats_type, packets, t=0):
136 if type(chan) == type(0):
137 chan_list = (chan,)
138 else:
139 chan_list = chan
140 for c in chan_list:
141 if self.join_map.has_key(c):
142 self.join_map[c][stats_type].update(packets = packets, t = t)
143 def channel_receive(self, chan, cb = None, count = 1, timeout = 5):
144 log_test.info('Subscriber %s on port %s receiving from group %s, channel %d' %
145 (self.name, self.rx_intf, self.gaddr(chan), chan))
146 r = self.recv(chan, cb = cb, count = count, timeout = timeout)
147 if len(r) == 0:
148 log_test.info('Subscriber %s on port %s timed out' %(self.name, self.rx_intf))
149 else:
150 log_test.info('Subscriber %s on port %s received %d packets' %(self.name, self.rx_intf, len(r)))
151 if self.recv_timeout:
152 ##Negative test case is disabled for now
153 assert_equal(len(r), 0)
154
155 def recv_channel_cb(self, pkt):
156 ##First verify that we have received the packet for the joined instance
157 log_test.info('Packet received for group %s, subscriber %s, port %s' %
158 (pkt[IP].dst, self.name, self.rx_intf))
159 if self.recv_timeout:
160 return
161 chan = self.caddr(pkt[IP].dst)
162 assert_equal(chan in self.join_map.keys(), True)
163 recv_time = monotonic.monotonic() * 1000000
164 join_time = self.join_map[chan][self.STATS_JOIN].start
165 delta = recv_time - join_time
166 self.join_rx_stats.update(packets=1, t = delta, usecs = True)
167 self.channel_update(chan, self.STATS_RX, 1, t = delta)
168 log_test.debug('Packet received in %.3f usecs for group %s after join' %(delta, pkt[IP].dst))
169
170class subscriber_pool:
171
172 def __init__(self, subscriber, test_cbs):
173 self.subscriber = subscriber
174 self.test_cbs = test_cbs
175
176 def pool_cb(self):
177 for cb in self.test_cbs:
178 if cb:
179 self.test_status = cb(self.subscriber)
180 if self.test_status is not True:
181 ## This is chaning for other sub status has to check again
182 self.test_status = True
183 log_test.info('This service is failed and other services will not run for this subscriber')
184 break
185 log_test.info('This Subscriber is tested for multiple service eligibility ')
186 self.test_status = True
187
188class scale(object):
189
190 USER = "vagrant"
191 PASS = "vagrant"
192 head_node = os.getenv('HEAD_NODE', 'prod')
193 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
194 MAX_PORTS = 100
195 device_id = 'of:' + get_mac()
196 test_path = os.path.dirname(os.path.realpath(__file__))
197 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
198 olt = OltConfig(olt_conf_file = olt_conf_file)
199 APP_NAME = 'org.ciena.xconnect'
200 olt_apps = ()
201 table_app = 'org.ciena.cordigmp'
202 table_app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-multitable-2.0-SNAPSHOT.oar')
203 app_file = os.path.join(test_path, '..', 'apps/ciena-cordigmp-2.0-SNAPSHOT.oar')
204 cpqd_path = os.path.join(test_path, '..', 'setup')
205 ovs_path = cpqd_path
206 test_services = ('IGMP', 'TRAFFIC')
207 num_joins = 0
208 num_subscribers = 0
209 leave_flag = True
210 recv_timeout = False
211 onos_restartable = bool(int(os.getenv('ONOS_RESTART', 0)))
212 PORT_TX_DEFAULT = 2
213 PORT_RX_DEFAULT = 1
214 IP_DST = '224.0.0.22'
215 IGMP_DST_MAC = "01:00:5e:00:00:16"
216 igmp_eth = Ether(dst = IGMP_DST_MAC, type = ETH_P_IP)
217 igmp_ip = IP(dst = IP_DST)
Anil Kumar Sanka35fc4452017-07-27 00:39:10 +0000218 INGRESS_PORT = 1
219 EGRESS_PORT = 2
220 ingress_iface = 1
221 egress_iface = 2
222 MAX_PORTS = 100
223 CURRENT_PORT_NUM = egress_iface
224 ACL_SRC_IP = '192.168.20.3/32'
225 ACL_DST_IP = '192.168.30.2/32'
226 ACL_SRC_IP_RULE_2 = '192.168.40.3/32'
227 ACL_DST_IP_RULE_2 = '192.168.50.2/32'
228 ACL_SRC_IP_PREFIX_24 = '192.168.20.3/24'
229 ACL_DST_IP_PREFIX_24 = '192.168.30.2/24'
230 HOST_DST_IP = '192.168.30.0/24'
231 HOST_DST_IP_RULE_2 = '192.168.50.0/24'
232
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000233
234
235
236 CLIENT_CERT = """-----BEGIN CERTIFICATE-----
237MIICuDCCAiGgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
238CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
239IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
240RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNjA2MjExMjI3WhcN
241MTcwNjAxMjExMjI3WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
242BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
243hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
244gYEAwvXiSzb9LZ6c7uNziUfKvoHO7wu/uiFC5YUpXbmVGuGZizbVrny0xnR85Dfe
245+9R4diansfDhIhzOUl1XjN3YDeSS9OeF5YWNNE8XDhlz2d3rVzaN6hIhdotBkUjg
246rUewjTg5OFR31QEyG3v8xR3CLgiE9xQELjZbSA07pD79zuUCAwEAAaNPME0wEwYD
247VR0lBAwwCgYIKwYBBQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5l
248eGFtcGxlLmNvbS9leGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOBgQDAjkrY
2496tDChmKbvr8w6Du/t8vHjTCoCIocHTN0qzWOeb1YsAGX89+TrWIuO1dFyYd+Z0KC
250PDKB5j/ygml9Na+AklSYAVJIjvlzXKZrOaPmhZqDufi+rXWti/utVqY4VMW2+HKC
251nXp37qWeuFLGyR1519Y1d6F/5XzqmvbwURuEug==
252-----END CERTIFICATE-----"""
253
254 CLIENT_CERT_INVALID = '''-----BEGIN CERTIFICATE-----
255MIIDvTCCAqWgAwIBAgIBAjANBgkqhkiG9w0BAQUFADCBizELMAkGA1UEBhMCVVMx
256CzAJBgNVBAgTAkNBMRIwEAYDVQQHEwlTb21ld2hlcmUxEzARBgNVBAoTCkNpZW5h
257IEluYy4xHjAcBgkqhkiG9w0BCQEWD2FkbWluQGNpZW5hLmNvbTEmMCQGA1UEAxMd
258RXhhbXBsZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwMzExMTg1MzM2WhcN
259MTcwMzA2MTg1MzM2WjBnMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNV
260BAoTCkNpZW5hIEluYy4xFzAVBgNVBAMUDnVzZXJAY2llbmEuY29tMR0wGwYJKoZI
261hvcNAQkBFg51c2VyQGNpZW5hLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
262AQoCggEBAOxemcBsPn9tZsCa5o2JA6sQDC7A6JgCNXXl2VFzKLNNvB9PS6D7ZBsQ
2635An0zEDMNzi51q7lnrYg1XyiE4S8FzMGAFr94RlGMQJUbRD9V/oqszMX4k++iAOK
264tIA1gr3x7Zi+0tkjVSVzXTmgNnhChAamdMsjYUG5+CY9WAicXyy+VEV3zTphZZDR
265OjcjEp4m/TSXVPYPgYDXI40YZKX5BdvqykWtT/tIgZb48RS1NPyN/XkCYzl3bv21
266qx7Mc0fcEbsJBIIRYTUkfxnsilcnmLxSYO+p+DZ9uBLBzcQt+4Rd5pLSfi21WM39
2672Z2oOi3vs/OYAPAqgmi2JWOv3mePa/8CAwEAAaNPME0wEwYDVR0lBAwwCgYIKwYB
268BQUHAwIwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL3d3dy5leGFtcGxlLmNvbS9l
269eGFtcGxlX2NhLmNybDANBgkqhkiG9w0BAQUFAAOCAQEALBzMPDTIB6sLyPl0T6JV
270MjOkyldAVhXWiQsTjaGQGJUUe1cmUJyZbUZEc13MygXMPOM4x7z6VpXGuq1c/Vxn
271VzQ2fNnbJcIAHi/7G8W5/SQfPesIVDsHTEc4ZspPi5jlS/MVX3HOC+BDbOjdbwqP
272RX0JEr+uOyhjO+lRxG8ilMRACoBUbw1eDuVDoEBgErSUC44pq5ioDw2xelc+Y6hQ
273dmtYwfY0DbvwxHtA495frLyPcastDiT/zre7NL51MyUDPjjYjghNQEwvu66IKbQ3
274T1tJBrgI7/WI+dqhKBFolKGKTDWIHsZXQvZ1snGu/FRYzg1l+R/jT8cRB9BDwhUt
275yg==
276-----END CERTIFICATE-----'''
277
278############ IGMP utility functions #######################
279 def onos_ssm_table_load(self, groups, src_list = ['1.2.3.4'],flag = False):
280 ssm_dict = {'apps' : { 'org.opencord.igmp' : { 'ssmTranslate' : [] } } }
281 ssm_xlate_list = ssm_dict['apps']['org.opencord.igmp']['ssmTranslate']
282 if flag: #to maintain seperate group-source pair.
283 for i in range(len(groups)):
284 d = {}
285 d['source'] = src_list[i] or '0.0.0.0'
286 d['group'] = groups[i]
287 ssm_xlate_list.append(d)
288 else:
289 for g in groups:
290 for s in src_list:
291 d = {}
292 d['source'] = s or '0.0.0.0'
293 d['group'] = g
294 ssm_xlate_list.append(d)
295 self.onos_load_config(ssm_dict)
296 cord_port_map = {}
297 for g in groups:
298 cord_port_map[g] = (self.PORT_TX_DEFAULT, self.PORT_RX_DEFAULT)
299 IgmpChannel().cord_port_table_load(cord_port_map)
300 time.sleep(2)
301
302 def generate_random_multicast_ip_addresses(self,count=500):
303 multicast_ips = []
304 while(count >= 1):
305 ip = '.'.join([str(random.randint(224,239)),str(random.randint(1,254)),str(random.randint(1,254)),str(random.randint(1,254))])
306 if ip in multicast_ips:
307 pass
308 else:
309 multicast_ips.append(ip)
310 count -= 1
311 return multicast_ips
312
313 def generate_random_unicast_ip_addresses(self,count=1):
314 unicast_ips = []
315 while(count >= 1):
316 ip = '.'.join([str(random.randint(11,126)),str(random.randint(1,254)),str(random.randint(1,254)),str(random.randint(1,254))])
317 if ip in unicast_ips:
318 pass
319 else:
320 unicast_ips.append(ip)
321 count -= 1
322 return unicast_ips
323
324 def iptomac(self, mcast_ip):
325 mcast_mac = '01:00:5e:'
326 octets = mcast_ip.split('.')
327 second_oct = int(octets[1]) & 127
328 third_oct = int(octets[2])
329 fourth_oct = int(octets[3])
330 mcast_mac = mcast_mac + format(second_oct,'02x') + ':' + format(third_oct, '02x') + ':' + format(fourth_oct, '02x')
331 return mcast_mac
332
333 def send_igmp_join(self, groups, src_list = ['1.2.3.4'], record_type=IGMP_V3_GR_TYPE_INCLUDE,
334 ip_pkt = None, iface = 'veth0', ssm_load = False, delay = 1):
335 if ssm_load is True:
336 self.onos_ssm_table_load(groups, src_list)
337 igmp = IGMPv3(type = IGMP_TYPE_V3_MEMBERSHIP_REPORT, max_resp_code=30,
338 gaddr=self.IP_DST)
339 for g in groups:
340 gr = IGMPv3gr(rtype= record_type, mcaddr=g)
341 gr.sources = src_list
342 igmp.grps.append(gr)
343 if ip_pkt is None:
344 ip_pkt = self.igmp_eth/self.igmp_ip
345 pkt = ip_pkt/igmp
346 IGMPv3.fixup(pkt)
347 log.info('sending igmp join packet %s'%pkt.show())
348 sendp(pkt, iface=iface)
349 time.sleep(delay)
350
351 def send_multicast_data_traffic(self, group, intf= 'veth2',source = '1.2.3.4'):
352 dst_mac = self.iptomac(group)
353 eth = Ether(dst= dst_mac)
354 ip = IP(dst=group,src=source)
355 data = repr(monotonic.monotonic())
356 sendp(eth/ip/data,count=20, iface = intf)
357
358 def verify_igmp_data_traffic(self, group, intf='veth0', source='1.2.3.4' ):
359 log_test.info('verifying multicast traffic for group %s from source %s'%(group,source))
360 self.success = False
361 def recv_task():
362 def igmp_recv_cb(pkt):
363 #log_test.info('received multicast data packet is %s'%pkt.show())
364 log_test.info('multicast data received for group %s from source %s'%(group,source))
365 self.success = True
366 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')
367 t = threading.Thread(target = recv_task)
368 t.start()
369 self.send_multicast_data_traffic(group,source=source)
370 t.join()
371 return self.success
Anil Kumar Sanka35fc4452017-07-27 00:39:10 +0000372##################### acl utility functions ###############################
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000373
374 @classmethod
Anil Kumar Sanka35fc4452017-07-27 00:39:10 +0000375 def acl_hosts_add(cls, dstHostIpMac, egress_iface_count = 1, egress_iface_num = None):
376 index = 0
377 if egress_iface_num is None:
378 egress_iface_num = cls.egress_iface
379 for ip,_ in dstHostIpMac:
380 egress = cls.port_map[egress_iface_num]
381 log.info('Assigning ip %s to interface %s' %(ip, egress))
382 config_cmds_egress = ( 'ifconfig {} 0'.format(egress),
383 'ifconfig {0} up'.format(egress),
384 'ifconfig {0} {1}'.format(egress, ip),
385 'arping -I {0} {1} -c 2'.format(egress, ip.split('/')[0]),
386 'ifconfig {0}'.format(egress),
387 )
388 for cmd in config_cmds_egress:
389 os.system(cmd)
390 index += 1
391 if index == egress_iface_count:
392 break
393 egress_iface_count += 1
394 egress_iface_num += 1
395 @classmethod
396 def acl_hosts_remove(cls, egress_iface_count = 1, egress_iface_num = None):
397 if egress_iface_num is None:
398 egress_iface_num = cls.egress_iface
399 n = 0
400 for n in range(egress_iface_count):
401 egress = cls.port_map[egress_iface_num]
402 config_cmds_egress = ('ifconfig {} 0'.format(egress))
403 os.system(config_cmds_egress)
404 egress_iface_num += 1
405 def acl_rule_traffic_send_recv(self, srcMac, dstMac, srcIp, dstIp, ingress =None, egress=None, ip_proto=None, dstPortNum = None, positive_test = True):
406 if ingress is None:
407 ingress = self.ingress_iface
408 if egress is None:
409 egress = self.egress_iface
410 ingress = self.port_map[ingress]
411 egress = self.port_map[egress]
412 self.success = False if positive_test else True
413 timeout = 10 if positive_test else 1
414 count = 2 if positive_test else 1
415 self.start_sending = True
416 def recv_task():
417 def recv_cb(pkt):
418 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
419 self.success = True if positive_test else False
420 sniff(count=count, timeout=timeout,
421 lfilter = lambda p: IP in p and p[IP].dst == dstIp.split('/')[0] and p[IP].src == srcIp.split('/')[0],
422 prn = recv_cb, iface = egress)
423 self.start_sending = False
424
425 t = threading.Thread(target = recv_task)
426 t.start()
427 L2 = Ether(src = srcMac, dst = dstMac)
428 L3 = IP(src = srcIp.split('/')[0], dst = dstIp.split('/')[0])
429 pkt = L2/L3
430 log.info('Sending a packet with dst ip %s, src ip %s , dst mac %s src mac %s on port %s to verify if flows are correct' %
431 (dstIp.split('/')[0], srcIp.split('/')[0], dstMac, srcMac, ingress))
432 while self.start_sending is True:
433 sendp(pkt, count=50, iface = ingress)
434 t.join()
435 assert_equal(self.success, True)
436
437
438
439############################# vrouter utility functiuons ####################
440 @classmethod
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000441 def vrouter_setup(cls):
442 apps = ('org.onosproject.proxyarp', 'org.onosproject.hostprovider', 'org.onosproject.vrouter', 'org.onosproject.fwd')
443 for app in apps:
444 OnosCtrl(app).activate()
445 cls.port_map, cls.port_list = cls.olt.olt_port_map()
446 cls.vrouter_device_dict = { "devices" : {
447 "{}".format(cls.device_id) : {
448 "basic" : {
449 "driver" : "softrouter"
450 }
451 }
452 },
453 }
454 cls.zebra_conf = '''
455password zebra
456log stdout
457service advanced-vty
458!
459!debug zebra rib
460!debug zebra kernel
461!debug zebra fpm
462!
463!interface eth1
464! ip address 10.10.0.3/16
465line vty
466 exec-timeout 0 0
467'''
468 @classmethod
469 def start_quagga(cls, networks = 4, peer_address = None, router_address = None):
470 log_test.info('Restarting Quagga container with configuration for %d networks' %(networks))
471 config = cls.generate_conf(networks = networks, peer_address = peer_address, router_address = router_address)
472 if networks <= 10000:
473 boot_delay = 25
474 else:
475 delay_map = [60, 100, 150, 200, 300, 450, 600, 800, 1000, 1200]
476 n = min(networks/100000, len(delay_map)-1)
477 boot_delay = delay_map[n]
478 cord_test_quagga_restart(config = config, boot_delay = boot_delay)
479 @classmethod
480 def generate_vrouter_conf(cls, networks = 4, peers = 1, peer_address = None, router_address = None):
481 num = 0
482 if peer_address is None:
483 start_peer = ( 192 << 24) | ( 168 << 16) | (10 << 8) | 0
484 end_peer = ( 200 << 24 ) | (168 << 16) | (10 << 8) | 0
485 else:
486 ip = peer_address[0][0]
487 start_ip = ip.split('.')
488 start_peer = ( int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
489 end_peer = ((int(start_ip[0]) + 8) << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
490 local_network = end_peer + 1
491 ports_dict = { 'ports' : {} }
492 interface_list = []
493 peer_list = []
494 for n in xrange(start_peer, end_peer, 256):
495 port_map = ports_dict['ports']
496 port = num + 1 if num < cls.MAX_PORTS - 1 else cls.MAX_PORTS - 1
497 device_port_key = '{0}/{1}'.format(cls.device_id, port)
498 try:
499 interfaces = port_map[device_port_key]['interfaces']
500 except:
501 port_map[device_port_key] = { 'interfaces' : [] }
502 interfaces = port_map[device_port_key]['interfaces']
503 ip = n + 2
504 peer_ip = n + 1
505 ips = '%d.%d.%d.%d/24'%( (ip >> 24) & 0xff, ( (ip >> 16) & 0xff ), ( (ip >> 8 ) & 0xff ), ip & 0xff)
506 peer = '%d.%d.%d.%d' % ( (peer_ip >> 24) & 0xff, ( ( peer_ip >> 16) & 0xff ), ( (peer_ip >> 8 ) & 0xff ), peer_ip & 0xff )
507 mac = RandMAC()._fix()
508 peer_list.append((peer, mac))
509 if num < cls.MAX_PORTS - 1:
510 interface_dict = { 'name' : 'b1-{}'.format(port), 'ips': [ips], 'mac' : mac }
511 interfaces.append(interface_dict)
512 interface_list.append(interface_dict['name'])
513 else:
514 interfaces[0]['ips'].append(ips)
515 num += 1
516 if num == peers:
517 break
518 quagga_dict = { 'apps': { 'org.onosproject.router' : { 'router' : {}, 'bgp' : { 'bgpSpeakers' : [] } } } }
519 quagga_router_dict = quagga_dict['apps']['org.onosproject.router']['router']
520 quagga_router_dict['ospfEnabled'] = True
521 quagga_router_dict['interfaces'] = interface_list
522 quagga_router_dict['controlPlaneConnectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
523
524 #bgp_speaker_dict = { 'apps': { 'org.onosproject.router' : { 'bgp' : { 'bgpSpeakers' : [] } } } }
525 bgp_speakers_list = quagga_dict['apps']['org.onosproject.router']['bgp']['bgpSpeakers']
526 speaker_dict = {}
527 speaker_dict['name'] = 'bgp{}'.format(peers+1)
528 speaker_dict['connectPoint'] = '{0}/{1}'.format(cls.device_id, peers + 1)
529 speaker_dict['peers'] = peer_list
530 bgp_speakers_list.append(speaker_dict)
531 cls.peer_list = peer_list
532 return (cls.vrouter_device_dict, ports_dict, quagga_dict)
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000533 @classmethod
534 def generate_conf(cls, networks = 4, peer_address = None, router_address = None):
535 num = 0
536 if router_address is None:
537 start_network = ( 11 << 24) | ( 10 << 16) | ( 10 << 8) | 0
538 end_network = ( 172 << 24 ) | ( 0 << 16) | (0 << 8) | 0
539 network_mask = 24
540 else:
541 ip = router_address
542 start_ip = ip.split('.')
543 network_mask = int(start_ip[3].split('/')[1])
544 start_ip[3] = (start_ip[3].split('/'))[0]
545 start_network = (int(start_ip[0]) << 24) | ( int(start_ip[1]) << 16) | ( int(start_ip[2]) << 8) | 0
546 end_network = (172 << 24 ) | (int(start_ip[1]) << 16) | (int(start_ip[2]) << 8) | 0
547 net_list = []
548 peer_list = peer_address if peer_address is not None else cls.peer_list
549 network_list = []
550 for n in xrange(start_network, end_network, 256):
551 net = '%d.%d.%d.0'%( (n >> 24) & 0xff, ( ( n >> 16) & 0xff ), ( (n >> 8 ) & 0xff ) )
552 network_list.append(net)
553 gateway = peer_list[num % len(peer_list)][0]
554 net_route = 'ip route {0}/{1} {2}'.format(net, network_mask, gateway)
555 net_list.append(net_route)
556 num += 1
557 if num == networks:
558 break
559 cls.network_list = network_list
560 cls.network_mask = network_mask
561 zebra_routes = '\n'.join(net_list)
562 #log_test.info('Zebra routes: \n:%s\n' %cls.zebra_conf + zebra_routes)
563 return cls.zebra_conf + zebra_routes
564
565 @classmethod
566 def vrouter_host_load(cls, peer_address = None):
567 index = 1
568 peer_info = peer_address if peer_address is not None else cls.peer_list
569
570 for host,_ in peer_info:
571 iface = cls.port_map[index]
572 index += 1
573 log_test.info('Assigning ip %s to interface %s' %(host, iface))
574 config_cmds = ( 'ifconfig {} 0'.format(iface),
575 'ifconfig {0} {1}'.format(iface, host),
576 'arping -I {0} {1} -c 2'.format(iface, host),
577 )
578 for cmd in config_cmds:
579 os.system(cmd)
580 @classmethod
581 def vrouter_host_unload(cls, peer_address = None):
582 index = 1
583 peer_info = peer_address if peer_address is not None else cls.peer_list
584
585 for host,_ in peer_info:
586 iface = cls.port_map[index]
587 index += 1
588 config_cmds = ('ifconfig {} 0'.format(iface), )
589 for cmd in config_cmds:
590 os.system(cmd)
591
592 @classmethod
593 def vrouter_config_get(cls, networks = 4, peers = 1, peer_address = None,
594 route_update = None, router_address = None):
595 vrouter_configs = cls.generate_vrouter_conf(networks = networks, peers = peers,
596 peer_address = peer_address, router_address = router_address)
597 return vrouter_configs
598
599 @classmethod
600 def vrouter_configure(cls, networks = 4, peers = 1, peer_address = None,
601 route_update = None, router_address = None, time_expire = None, adding_new_routes = None):
602 vrouter_configs = cls.vrouter_config_get(networks = networks, peers = peers,
603 peer_address = peer_address, route_update = route_update)
604 cls.start_onos(network_cfg = vrouter_configs)
605 time.sleep(5)
606 cls.vrouter_host_load()
607 ##Start quagga
608 cls.start_quagga(networks = networks, peer_address = peer_address, router_address = router_address)
609 return vrouter_configs
610 def vrouter_port_send_recv(self, ingress, egress, dst_mac, dst_ip, positive_test = True):
611 src_mac = '00:00:00:00:00:02'
612 src_ip = '1.1.1.1'
613 self.success = False if positive_test else True
614 timeout = 10 if positive_test else 1
615 count = 2 if positive_test else 1
616 self.start_sending = True
617 def recv_task():
618 def recv_cb(pkt):
619 log_test.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
620 self.success = True if positive_test else False
621 sniff(count=count, timeout=timeout,
622 lfilter = lambda p: IP in p and p[IP].dst == dst_ip and p[IP].src == src_ip,
623 prn = recv_cb, iface = self.port_map[ingress])
624 self.start_sending = False
625
626 t = threading.Thread(target = recv_task)
627 t.start()
628 L2 = Ether(src = src_mac, dst = dst_mac)
629 L3 = IP(src = src_ip, dst = dst_ip)
630 pkt = L2/L3
631 log_test.info('Sending a packet with dst ip %s, dst mac %s on port %s to verify if flows are correct' %
632 (dst_ip, dst_mac, self.port_map[egress]))
633 while self.start_sending is True:
634 sendp(pkt, count=50, iface = self.port_map[egress])
635 t.join()
636 assert_equal(self.success, True)
637
638 def vrouter_traffic_verify(self, positive_test = True, peer_address = None):
639 if peer_address is None:
640 peers = len(self.peer_list)
641 peer_list = self.peer_list
642 else:
643 peers = len(peer_address)
644 peer_list = peer_address
645 egress = peers + 1
646 num = 0
647 num_hosts = 5 if positive_test else 1
648 src_mac = '00:00:00:00:00:02'
649 src_ip = '1.1.1.1'
650 if self.network_mask != 24:
651 peers = 1
652 for network in self.network_list:
653 num_ips = num_hosts
654 octets = network.split('.')
655 for i in xrange(num_ips):
656 octets[-1] = str(int(octets[-1]) + 1)
657 dst_ip = '.'.join(octets)
658 dst_mac = peer_list[ num % peers ] [1]
659 port = (num % peers)
660 ingress = port + 1
661 #Since peers are on the same network
662 ##Verify if flows are setup by sending traffic across
663 self.vrouter_port_send_recv(ingress, egress, dst_mac, dst_ip, positive_test = positive_test)
664 num += 1
665 def vrouter_network_verify(self, networks, peers = 1, positive_test = True,
666 start_network = None, start_peer_address = None, route_update = None,
667 invalid_peers = None, time_expire = None, unreachable_route_traffic = None,
668 deactivate_activate_vrouter = None, adding_new_routes = None):
669 print 'no.of networks are.....', networks
670 self.vrouter_setup()
671 _, ports_map, egress_map = self.vrouter_configure(networks = networks, peers = peers,
672 peer_address = start_peer_address,
673 route_update = route_update,
674 router_address = start_network,
675 time_expire = time_expire,
676 adding_new_routes = adding_new_routes)
677 self.vrouter_traffic_verify()
678 self.vrouter_host_unload()
679 return True
680
681############### Cord Subscriber utility functions #########################
682
683 @classmethod
684 def flows_setup(cls):
685 cls.olt = OltConfig()
686 cls.port_map, _ = cls.olt.olt_port_map()
687 if not cls.port_map:
688 cls.port_map = cls.default_port_map
689 cls.device_id = OnosCtrl.get_device_id()
690 num_ports = len(cls.port_map['ports'] + cls.port_map['relay_ports'])
691 cls.port_offset = int(os.getenv('TEST_INSTANCE', 0)) * num_ports
692
693 @classmethod
694 def update_apps_version(cls):
695 version = Onos.getVersion()
696 major = int(version.split('.')[0])
697 minor = int(version.split('.')[1])
698 cordigmp_app_version = '2.0-SNAPSHOT'
699 olt_app_version = '1.2-SNAPSHOT'
700 if major > 1:
701 cordigmp_app_version = '3.0-SNAPSHOT'
702 olt_app_version = '2.0-SNAPSHOT'
703 elif major == 1:
704 if minor > 10:
705 cordigmp_app_version = '3.0-SNAPSHOT'
706 olt_app_version = '2.0-SNAPSHOT'
707 elif minor <= 8:
708 olt_app_version = '1.1-SNAPSHOT'
709 cls.app_file = os.path.join(cls.test_path, '..', 'apps/ciena-cordigmp-{}.oar'.format(cordigmp_app_version))
710 cls.table_app_file = os.path.join(cls.test_path, '..', 'apps/ciena-cordigmp-multitable-{}.oar'.format(cordigmp_app_version))
711 cls.olt_app_file = os.path.join(cls.test_path, '..', 'apps/olt-app-{}.oar'.format(olt_app_version))
712
713 @classmethod
714 def subscriber_setup(cls):
715 log.info('in subscriber_setup function 000000000')
716 cls.subscriber_apps = ('org.opencord.aaa', 'org.onosproject.dhcp')
717 for app in cls.subscriber_apps:
718 OnosCtrl(app).activate()
719 cls.update_apps_version()
720 #dids = OnosCtrl.get_device_ids()
721 #device_map = {}
722 #for did in dids:
Luca Prete9c0cdac2018-07-02 14:40:40 +0200723 # device_map[did] = { 'basic' : { 'driver' : 'voltha' } }
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000724 #network_cfg = {}
725 #network_cfg = { 'devices' : device_map }
726 #Restart ONOS with cpqd driver config for OVS
727 #cls.start_onos(network_cfg = network_cfg)
728 cls.port_map, cls.port_list = cls.olt.olt_port_map()
729 cls.switches = cls.port_map['switches']
730 cls.num_ports = cls.port_map['num_ports']
731 if cls.num_ports > 1:
732 cls.num_ports -= 1 ##account for the tx port
733 #Uninstall the existing app if any
734 #OnosCtrl.uninstall_app(cls.table_app)
735 #log_test.info('Installing the multi table app %s for subscriber test' %(cls.table_app_file))
736 #OnosCtrl.install_app(cls.table_app_file)
737
738 @classmethod
739 def subscriber_teardown(cls):
740 log.info('in subscriber_teardown function 000000000')
741 apps = cls.olt_apps + cls.subscriber_apps #( cls.table_app,)
742 for app in apps:
743 OnosCtrl(app).deactivate()
744 #cls.start_onos(network_cfg = {})
745 #OnosCtrl.uninstall_app(cls.table_app)
746 #log_test.info('Installing back the cord igmp app %s for subscriber test on exit' %(cls.app_file))
747 #OnosCtrl.install_app(cls.app_file)
748
749 @classmethod
750 def start_cpqd(cls, mac = '00:11:22:33:44:55'):
751 dpid = mac.replace(':', '')
752 cpqd_file = os.sep.join( (cls.cpqd_path, 'cpqd.sh') )
753 cpqd_cmd = '{} {}'.format(cpqd_file, dpid)
754 ret = os.system(cpqd_cmd)
755 assert_equal(ret, 0)
756 time.sleep(10)
757 device_id = 'of:{}{}'.format('0'*4, dpid)
758 return device_id
759
760 @classmethod
761 def start_ovs(cls):
762 ovs_file = os.sep.join( (cls.ovs_path, 'of-bridge.sh') )
763 ret = os.system(ovs_file)
764 assert_equal(ret, 0)
765 time.sleep(30)
766 @classmethod
767 def ovs_cleanup(cls):
768 log.info('executing ovs_cleanup function 000000000000000000')
769 ##For every test case, delete all the OVS groups
770 cmd = 'ovs-ofctl del-groups br-int -OOpenFlow11 >/dev/null 2>&1'
771 try:
772 cord_test_shell(cmd)
773 ##Since olt config is used for this test, we just fire a careless local cmd as well
774 os.system(cmd)
775 finally:
776 return
777 def tls_verify(self, subscriber):
778 def tls_fail_cb():
779 log_test.info('TLS verification failed')
780 if subscriber.has_service('TLS'):
781 #OnosCtrl('org.opencord.aaa').deactivate()
782 #time.sleep(2)
783 #OnosCtrl('org.opencord.aaa').activate()
784 #time.sleep(5)
785 tls = TLSAuthTest(fail_cb = tls_fail_cb, intf = subscriber.rx_intf)
786 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
787 tls.runTest()
788 assert_equal(tls.failTest, False)
789 self.test_status = True
790 return self.test_status
791 else:
792 self.test_status = True
793 return self.test_status
794
795 def generate_port_list(self, subscribers, channels):
796 log.info('port list in generate port list is %s'%self.port_list)
797 return self.port_list[:subscribers]
798 def subscriber_load(self, create = True, num = 10, num_channels = 1, channel_start = 0, port_list = [], services = None):
799 '''Load the subscriber from the database'''
800 log.info('executing subscriber_load finction 000000000')
801 test_services = services if services else self.test_services
802 self.subscriber_db = SubscriberDB(create = create, services = test_services)
803 if create is True:
804 self.subscriber_db.generate(num)
805 self.subscriber_info = self.subscriber_db.read(num)
806 self.subscriber_list = []
807 if not port_list:
808 port_list = self.generate_port_list(num, num_channels)
809 log.info('port_list in subscriber load is %s'%port_list)
810 index = 0
811 for info in self.subscriber_info:
812 self.subscriber_list.append(Subscriber(name=info['Name'],
813 service=info['Service'],
814 port_map = self.port_map,
815 num=num_channels,
816 channel_start = channel_start,
817 tx_port = port_list[index][0],
818 rx_port = port_list[index][1]))
819 if num_channels > 1:
820 channel_start += num_channels
821 index += 1
822 #load the ssm list for all subscriber channels
823 igmpChannel = IgmpChannel()
824 ssm_groups = map(lambda sub: sub.channels, self.subscriber_list)
825 ssm_list = reduce(lambda ssm1, ssm2: ssm1+ssm2, ssm_groups)
826 igmpChannel.igmp_load_ssm_config(ssm_list)
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +0000827 def subscriber_join_verify( self, num_subscribers = 10, num_channels = 1,
828 channel_start = 0, cbs = None, port_list = [],
829 services = None, negative_subscriber_auth = None):
830 log.info('in subscriber_join_verify function 000000000')
831 self.test_status = False
832 self.ovs_cleanup()
833 subscribers_count = num_subscribers
834 sub_loop_count = num_subscribers
835 self.subscriber_load(create = True, num = num_subscribers,
836 num_channels = num_channels, channel_start = channel_start, port_list = port_list,
837 services = services)
838 self.onos_aaa_config()
839 self.thread_pool = ThreadPool(min(100, subscribers_count), queue_size=1, wait_timeout=1)
840 chan_leave = False #for single channel, multiple subscribers
841 if cbs is None:
842 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
843 chan_leave = True
844 cbs_negative = cbs
845 for subscriber in self.subscriber_list:
846 if services and 'IGMP' in services:
847 subscriber.start()
848 if negative_subscriber_auth is 'half' and sub_loop_count%2 is not 0:
849 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
850 elif negative_subscriber_auth is 'onethird' and sub_loop_count%3 is not 0:
851 cbs = (self.tls_verify, self.dhcp_verify, self.igmp_verify, self.traffic_verify)
852 else:
853 cbs = cbs_negative
854 sub_loop_count = sub_loop_count - 1
855 pool_object = subscriber_pool(subscriber, cbs)
856 self.thread_pool.addTask(pool_object.pool_cb)
857 self.thread_pool.cleanUpThreads()
858 for subscriber in self.subscriber_list:
859 if services and 'IGMP' in services:
860 subscriber.stop()
861 if chan_leave is True:
862 subscriber.channel_leave(0)
863 subscribers_count = 0
864 return self.test_status
865 def tls_invalid_cert(self, subscriber):
866 log.info('in tls_invalid_cert function 000000000000000')
867 if subscriber.has_service('TLS'):
868 time.sleep(2)
869 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
870 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_INVALID)
871 tls.runTest()
872 if tls.failTest == True:
873 self.test_status = False
874 return self.test_status
875 else:
876 self.test_status = True
877 return self.test_status
878
879 def tls_verify(self, subscriber):
880 def tls_fail_cb():
881 log_test.info('TLS verification failed')
882 if subscriber.has_service('TLS'):
883 tls = TLSAuthTest(fail_cb = tls_fail_cb, intf = subscriber.rx_intf)
884 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
885 tls.runTest()
886 assert_equal(tls.failTest, False)
887 self.test_status = True
888 return self.test_status
889 else:
890 self.test_status = True
891 return self.test_status
892
893 def tls_non_ca_authrized_cert(self, subscriber):
894 if subscriber.has_service('TLS'):
895 time.sleep(2)
896 log_test.info('Running subscriber %s tls auth test' %subscriber.name)
897 tls = TLSAuthTest(client_cert = self.CLIENT_CERT_NON_CA_AUTHORIZED)
898 tls.runTest()
899 if tls.failTest == False:
900 self.test_status = True
901 return self.test_status
902 else:
903 self.test_status = True
904 return self.test_status
905
906 def dhcp_verify(self, subscriber):
907 log.info('in dhcp_verify function 000000000000000')
908 if subscriber.has_service('DHCP'):
909 cip, sip = self.dhcp_request(subscriber, update_seed = True)
910 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
911 subscriber.src_list = [cip]
912 self.test_status = True
913 return self.test_status
914 else:
915 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
916 self.test_status = True
917 return self.test_status
918 def dhcp_jump_verify(self, subscriber):
919 if subscriber.has_service('DHCP'):
920 cip, sip = self.dhcp_request(subscriber, seed_ip = '10.10.200.1')
921 log_test.info('Subscriber %s got client ip %s from server %s' %(subscriber.name, cip, sip))
922 subscriber.src_list = [cip]
923 self.test_status = True
924 return self.test_status
925 else:
926 subscriber.src_list = ['10.10.10.{}'.format(subscriber.rx_port)]
927 self.test_status = True
928 return self.test_status
929
930 def igmp_verify(self, subscriber):
931 log.info('in igmp_verify function 000000000000000')
932 chan = 0
933 if subscriber.has_service('IGMP'):
934 ##We wait for all the subscribers to join before triggering leaves
935 if subscriber.rx_port > 1:
936 time.sleep(5)
937 subscriber.channel_join(chan, delay = 0)
938 self.num_joins += 1
939 while self.num_joins < self.num_subscribers:
940 time.sleep(5)
941 log_test.info('All subscribers have joined the channel')
942 for i in range(10):
943 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
944 log_test.info('Leaving channel %d for subscriber %s' %(chan, subscriber.name))
945 subscriber.channel_leave(chan)
946 time.sleep(5)
947 log_test.info('Interface %s Join RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name,subscriber.join_rx_stats))
948 #Should not receive packets for this subscriber
949 self.recv_timeout = True
950 subscriber.recv_timeout = True
951 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 10)
952 subscriber.recv_timeout = False
953 self.recv_timeout = False
954 log_test.info('Joining channel %d for subscriber %s' %(chan, subscriber.name))
955 subscriber.channel_join(chan, delay = 0)
956 self.test_status = True
957 return self.test_status
958
959 def igmp_jump_verify(self, subscriber):
960 if subscriber.has_service('IGMP'):
961 for i in xrange(subscriber.num):
962 log_test.info('Subscriber %s jumping channel' %subscriber.name)
963 chan = subscriber.channel_jump(delay=0)
964 subscriber.channel_receive(chan, cb = subscriber.recv_channel_cb, count = 1)
965 log_test.info('Verified receive for channel %d, subscriber %s' %(chan, subscriber.name))
966 time.sleep(3)
967 log_test.info('Interface %s Jump RX stats for subscriber %s, %s' %(subscriber.iface, subscriber.name, subscriber.join_rx_stats))
968 self.test_status = True
969 return self.test_status
970 def traffic_verify(self, subscriber):
971 if subscriber.has_service('TRAFFIC'):
972 url = 'http://www.google.com'
973 resp = requests.get(url)
974 self.test_status = resp.ok
975 if resp.ok == False:
976 log_test.info('Subscriber %s failed get from url %s with status code %d'
977 %(subscriber.name, url, resp.status_code))
978 else:
979 log_test.info('GET request from %s succeeded for subscriber %s'
980 %(url, subscriber.name))
981 return self.test_status
982################## common utility functions #######################
983 def get_system_cpu_usage(self):
984 """ Getting compute node CPU usage """
985 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
986 cmd = "top -b -n1 | grep 'Cpu(s)' | awk '{print $2 + $4}'"
987 status, output = ssh_agent.run_cmd(cmd)
988 assert_equal(status, True)
989 return float(output)
990
991 @classmethod
992 def start_onos(cls, network_cfg = None):
993 if type(network_cfg) is tuple:
994 res = []
995 for v in network_cfg:
996 res += v.items()
997 config = dict(res)
998 else:
999 config = network_cfg
1000 log_test.info('Restarting ONOS with new network configuration')
1001 return cord_test_onos_restart(config = config)
1002
1003 @classmethod
1004 def config_restore(cls):
1005 """Restore the vsg test configuration on test case failures"""
1006 for restore_method in cls.restore_methods:
1007 restore_method()
1008
1009 def onos_aaa_config(self):
A R Karthick1555c7c2017-09-07 14:59:41 -07001010 OnosCtrl.aaa_load_config()
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +00001011
1012 def onos_load_config(self, config):
1013 status, code = OnosCtrl.config(config)
1014 if status is False:
1015 log_test.info('Configure request for AAA returned status %d' %code)
1016 assert_equal(status, True)
1017 time.sleep(3)
A R Karthick1555c7c2017-09-07 14:59:41 -07001018
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +00001019 def cliEnter(self):
1020 retries = 0
1021 while retries < 3:
1022 self.cli = OnosCliDriver(connect = True)
1023 if self.cli.handle:
1024 break
1025 else:
1026 retries += 1
1027 time.sleep(2)
1028
1029 def cliExit(self):
1030 self.cli.disconnect()
1031
1032 def incmac(self, mac):
1033 tmp = str(hex(int('0x'+mac,16)+1).split('x')[1])
1034 mac = '0'+ tmp if len(tmp) < 2 else tmp
1035 return mac
1036
1037 def next_mac(self, mac):
1038 mac = mac.split(":")
1039 mac[5] = self.incmac(mac[5])
1040
1041 if len(mac[5]) > 2:
1042 mac[0] = self.incmac(mac[0])
1043 mac[5] = '01'
1044
1045 if len(mac[0]) > 2:
1046 mac[0] = '01'
1047 mac[1] = self.incmac(mac[1])
1048 mac[5] = '01'
1049 return ':'.join(mac)
1050
1051 def to_egress_mac(cls, mac):
1052 mac = mac.split(":")
1053 mac[4] = '01'
1054 return ':'.join(mac)
1055
1056 def inc_ip(self, ip, i):
Anil Kumar Sanka35fc4452017-07-27 00:39:10 +00001057
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +00001058 ip[i] =str(int(ip[i])+1)
1059 return '.'.join(ip)
Anil Kumar Sankafcb9a0f2017-07-22 00:24:35 +00001060 def next_ip(self, ip):
1061
1062 lst = ip.split('.')
1063 for i in (3,0,-1):
1064 if int(lst[i]) < 255:
1065 return self.inc_ip(lst, i)
1066 elif int(lst[i]) == 255:
1067 lst[i] = '0'
1068 if int(lst[i-1]) < 255:
1069 return self.inc_ip(lst,i-1)
1070 elif int(lst[i-2]) < 255:
1071 lst[i-1] = '0'
1072 return self.inc_ip(lst,i-2)
1073 else:
1074 break
1075
1076 def to_egress_ip(self, ip):
1077 lst=ip.split('.')
1078 lst[0] = '182'
1079 return '.'.join(lst)