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