blob: 8bc5f24d3d7e2348a00484c0cb2043cc3fd1247b [file] [log] [blame]
ChetanGaonkerf0dd5bb2016-07-28 16:22:06 -07001#
2# Copyright 2016-present Ciena Corporation
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#
16import unittest
17from nose.tools import *
18from scapy.all import *
19from OnosCtrl import OnosCtrl, get_mac
20from OltConfig import OltConfig
21from OnosFlowCtrl import OnosFlowCtrl
22from onosclidriver import OnosCliDriver
23from CordContainer import Container, Onos
24from portmaps import g_subscriber_port_map
25from CordTestServer import cord_test_onos_restart
26from ACL import ACLTest
27import threading
28import time
29import os
30import json
31import pexpect
32log.setLevel('INFO')
33
34class acl_exchange(unittest.TestCase):
35
36 app = ('org.onosproject.acl')
37 device_id = 'of:' + get_mac('ovsbr0')
38 test_path = os.path.dirname(os.path.realpath(__file__))
39 onos_config_path = os.path.join(test_path, '..', 'setup/onos-config')
40 GATEWAY = '192.168.10.50'
41 INGRESS_PORT = 1
42 EGRESS_PORT = 2
43 ingress_iface = 1
44 egress_iface = 2
45 MAX_PORTS = 100
46 CURRENT_PORT_NUM = egress_iface
47 ACL_SRC_IP = '192.168.20.3/32'
48 ACL_DST_IP = '192.168.30.2/32'
49 ACL_SRC_IP_RULE_2 = '192.168.40.3/32'
50 ACL_DST_IP_RULE_2 = '192.168.50.2/32'
51 ACL_SRC_IP_PREFIX_24 = '192.168.20.3/24'
52 ACL_DST_IP_PREFIX_24 = '192.168.30.2/24'
53 HOST_DST_IP = '192.168.30.0/24'
54 HOST_DST_IP_RULE_2 = '192.168.50.0/24'
55
56 @classmethod
57 def setUpClass(cls):
58 cls.olt = OltConfig()
59 cls.port_map,_ = cls.olt.olt_port_map()
60 if not cls.port_map:
61 cls.port_map = g_subscriber_port_map
62 time.sleep(3)
63 log.info('port_map = %s'%cls.port_map[1] )
64
65 @classmethod
66 def tearDownClass(cls):
67 '''Deactivate the acl app'''
68
69
70 def setUp(self):
71 ''' Activate the acl app'''
72 self.maxDiff = None ##for assert_equal compare outputs on failure
73 self.onos_ctrl = OnosCtrl(self.app)
74 status, _ = self.onos_ctrl.activate()
75 assert_equal(status, True)
76 time.sleep(3)
77 status, _ = ACLTest.remove_acl_rule()
78 log.info('Start setup')
79 assert_equal(status, True)
80
81 def tearDown(self):
82 '''Deactivate the acl app'''
83 log.info('Tear down setup')
84 self.CURRENT_PORT_NUM = 4
85
86 def cliEnter(self):
87 retries = 0
88 while retries < 3:
89 self.cli = OnosCliDriver(connect = True)
90 if self.cli.handle:
91 break
92 else:
93 retries += 1
94 time.sleep(2)
95
96 def cliExit(self):
97 self.cli.disconnect()
98
99 @classmethod
100 def acl_hosts_add(cls, dstHostIpMac, egress_iface_count = 1, egress_iface_num = None):
101 index = 0
102 if egress_iface_num is None:
103 egress_iface_num = cls.egress_iface
104 for ip,_ in dstHostIpMac:
105 egress = cls.port_map[egress_iface_num]
106 log.info('Assigning ip %s to interface %s' %(ip, egress))
107 config_cmds_egress = ( 'ifconfig {} 0'.format(egress),
108 'ifconfig {0} up'.format(egress),
109 'ifconfig {0} {1}'.format(egress, ip),
110 'arping -I {0} {1} -c 2'.format(egress, ip.split('/')[0]),
111 'ifconfig {0}'.format(egress),
112 )
113 for cmd in config_cmds_egress:
114 os.system(cmd)
115 index += 1
116 if index == egress_iface_count:
117 break
118 egress_iface_count += 1
119 egress_iface_num += 1
120
121
122 @classmethod
123 def acl_hosts_remove(cls, egress_iface_count = 1, egress_iface_num = None):
124 if egress_iface_num is None:
125 egress_iface_num = cls.egress_iface
126 n = 0
127 for n in range(egress_iface_count):
128 egress = cls.port_map[egress_iface_num]
129 config_cmds_egress = ('ifconfig {} 0'.format(egress))
130 os.system(config_cmds_egress)
131 egress_iface_num += 1
132
133# @classmethod
134 def acl_rule_traffic_send_recv(self, srcMac, dstMac, srcIp, dstIp, ingress =None, egress=None, ip_proto=None, dstPortNum = None, positive_test = True):
135 if ingress is None:
136 ingress = self.ingress_iface
137 if egress is None:
138 egress = self.egress_iface
139 ingress = self.port_map[ingress]
140 egress = self.port_map[egress]
141 self.success = False if positive_test else True
142 timeout = 10 if positive_test else 1
143 count = 2 if positive_test else 1
144 self.start_sending = True
145 def recv_task():
146 def recv_cb(pkt):
147 log.info('Pkt seen with ingress ip %s, egress ip %s' %(pkt[IP].src, pkt[IP].dst))
148 self.success = True if positive_test else False
149 sniff(count=count, timeout=timeout,
150 lfilter = lambda p: IP in p and p[IP].dst == dstIp.split('/')[0] and p[IP].src == srcIp.split('/')[0],
151 prn = recv_cb, iface = egress)
152 self.start_sending = False
153
154 t = threading.Thread(target = recv_task)
155 t.start()
156 L2 = Ether(src = srcMac, dst = dstMac)
157 L3 = IP(src = srcIp.split('/')[0], dst = dstIp.split('/')[0])
158 pkt = L2/L3
159 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' %
160 (dstIp.split('/')[0], srcIp.split('/')[0], dstMac, srcMac, ingress))
161 while self.start_sending is True:
162 sendp(pkt, count=50, iface = ingress)
163 t.join()
164 assert_equal(self.success, True)
165
166 @classmethod
167 def onos_load_config(cls, config):
168 status, code = OnosCtrl.config(config)
169 if status is False:
170 log.info('JSON request returned status %d' %code)
171 assert_equal(status, True)
172
173 def test_acl_allow_rule(self):
174 acl_rule = ACLTest()
175 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
176 if status is False:
177 log.info('JSON request returned status %d' %code)
178 assert_equal(status, True)
179 result = acl_rule.get_acl_rules()
180 aclRules1 = result.json()['aclRules']
181 log.info('Added ACL rules = %s' %result.json()['aclRules'])
182 acl_Id = map(lambda d: d['id'], aclRules1)
183 assert_equal(len(acl_Id), 1)
184
185 def test_acl_allow_rule_with_24_bit_mask(self):
186 acl_rule = ACLTest()
187 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_PREFIX_24, dstIp =self.ACL_DST_IP_PREFIX_24, action = 'allow')
188 if status is False:
189 log.info('JSON request returned status %d' %code)
190 assert_equal(status, True)
191 result = acl_rule.get_acl_rules()
192 aclRules1 = result.json()['aclRules']
193 log.info('Added ACL rules = %s' %result.json()['aclRules'])
194 acl_Id = map(lambda d: d['id'], aclRules1)
195 assert_equal(len(acl_Id), 1)
196
197 def test_acl_deny_rule(self):
198 acl_rule = ACLTest()
199 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
200 if status is False:
201 log.info('JSON request returned status %d' %code)
202 assert_equal(status, True)
203 result = acl_rule.get_acl_rules()
204 aclRules1 = result.json()['aclRules']
205 log.info('Added ACL rules = %s' %result.json()['aclRules'])
206 acl_Id = map(lambda d: d['id'], aclRules1)
207 assert_equal(len(acl_Id), 1)
208
209 def test_acl_deny_rule_with_24_bit_mask(self):
210 acl_rule = ACLTest()
211 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_PREFIX_24, dstIp =self.ACL_DST_IP_PREFIX_24, action = 'deny')
212 if status is False:
213 log.info('JSON request returned status %d' %code)
214 assert_equal(status, True)
215 result = acl_rule.get_acl_rules()
216 aclRules1 = result.json()['aclRules']
217 log.info('Added ACL rules = %s' %result.json()['aclRules'])
218 acl_Id = map(lambda d: d['id'], aclRules1)
219 assert_equal(len(acl_Id), 1)
220
221 def test_acl_add_remove_rule(self):
222 acl_rule = ACLTest()
223 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
224 if status is False:
225 log.info('JSON request returned status %d' %code)
226 assert_equal(status, True)
227 result = acl_rule.get_acl_rules()
228 aclRules1 = result.json()['aclRules']
229 log.info('Added ACL rules = %s' %result.json()['aclRules'])
230 acl_Id = map(lambda d: d['id'], aclRules1)
231 status, code = acl_rule.remove_acl_rule(acl_Id[0])
232 if status is False:
233 log.info('JSON request returned status %d' %code)
234 assert_equal(status, True)
235
236 def test_acl_add_remove_all_rules(self):
237 acl_rule = ACLTest()
238 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
239 status,code = acl_rule.adding_acl_rule('v4', srcIp='10.10.10.10/24', dstIp ='20.20.20.20/24', action = 'deny')
240 if status is False:
241 log.info('JSON request returned status %d' %code)
242 assert_equal(status, True)
243 result = acl_rule.get_acl_rules()
244 aclRules1 = result.json()['aclRules']
245 log.info('Added ACL rules = %s' %result.json()['aclRules'])
246 acl_Id = map(lambda d: d['id'], aclRules1)
247 status, _ = ACLTest.remove_acl_rule()
248 if status is False:
249 log.info('JSON request returned status %d' %code)
250 assert_equal(status, True)
251
252 def test_acl_remove_all_rules_without_add(self):
253 status, _ = ACLTest.remove_acl_rule()
254 if status is False:
255 log.info('JSON request returned status %d' %code)
256 assert_equal(status, True)
257
258 def test_acl_allow_and_deny_rule_for_same_src_and_dst_ip(self):
259 acl_rule = ACLTest()
260 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
261 if status is False:
262 log.info('JSON request returned status %d' %code)
263 assert_equal(status, True)
264 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
265 if status is False:
266 log.info('JSON request returned status %d' %code)
267 assert_equal(status, False)
268 result = acl_rule.get_acl_rules()
269 aclRules1 = result.json()['aclRules']
270 log.info('Added ACL rules = %s' %result.json()['aclRules'])
271 acl_Id = map(lambda d: d['id'], aclRules1)
272 assert_equal(len(acl_Id), 1)
273 status, _ = ACLTest.remove_acl_rule()
274 if status is False:
275 log.info('JSON request returned status %d' %code)
276 assert_equal(status, True)
277
278 def test_acl_allow_rules_for_matched_dst_ips(self):
279 acl_rule = ACLTest()
280 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp ='192.168.30.2/24', action = 'allow')
281 if status is False:
282 log.info('JSON request returned status %d' %code)
283 assert_equal(status, True)
284 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
285 if status is False:
286 log.info('JSON request returned status %d' %code)
287 assert_equal(status, False)
288 result = acl_rule.get_acl_rules()
289 aclRules1 = result.json()['aclRules']
290 log.info('Added ACL rules = %s' %result.json()['aclRules'])
291 acl_Id = map(lambda d: d['id'], aclRules1)
292 assert_equal(len(acl_Id), 1)
293 status, _ = ACLTest.remove_acl_rule()
294 if status is False:
295 log.info('JSON request returned status %d' %code)
296 assert_equal(status, True)
297
298 def test_acl_with_matching_src_and_dst_ip_traffic(self):
299 ingress = self.ingress_iface
300 egress = self.CURRENT_PORT_NUM
301 acl_rule = ACLTest()
302 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
303 self.CURRENT_PORT_NUM += 1
304 time.sleep(5)
305 if status is False:
306 log.info('JSON request returned status %d' %code)
307 assert_equal(status, True)
308 srcMac = '00:00:00:00:00:11'
309 dstMac = host_ip_mac[0][1]
310 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
311 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
312 time.sleep(10)
313 if status is False:
314 log.info('JSON request returned status %d' %code)
315 assert_equal(status, True)
316 result = acl_rule.get_acl_rules()
317 aclRules1 = result.json()['aclRules']
318 acl_Id = map(lambda d: d['id'], aclRules1)
319 assert_equal(len(acl_Id), 1)
320 log.info('Added ACL rules = %s' %result.json()['aclRules'])
321 self.cliEnter()
322 ##Now verify
323 hosts = json.loads(self.cli.hosts(jsonFormat = True))
324 log.info('Discovered hosts: %s' %hosts)
325 flows = json.loads(self.cli.flows(jsonFormat = True))
326 flows = filter(lambda f: f['flows'], flows)
327 #log.info('Flows: %s' %flows)
328 assert_not_equal(len(flows), 0)
329 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP')
330 self.cliExit()
331 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
332
333 def test_acl_with_matching_24bit_mask_src_and_dst_ip_traffic(self):
334 ingress = self.ingress_iface
335 egress = self.CURRENT_PORT_NUM
336 acl_rule = ACLTest()
337 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
338 self.CURRENT_PORT_NUM += 1
339 time.sleep(5)
340 if status is False:
341 log.info('JSON request returned status %d' %code)
342 assert_equal(status, True)
343 srcMac = '00:00:00:00:00:11'
344 dstMac = host_ip_mac[0][1]
345 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
346 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_PREFIX_24, dstIp =self.ACL_DST_IP_PREFIX_24, action = 'allow')
347 time.sleep(10)
348 if status is False:
349 log.info('JSON request returned status %d' %code)
350 assert_equal(status, True)
351 result = acl_rule.get_acl_rules()
352 aclRules1 = result.json()['aclRules']
353 acl_Id = map(lambda d: d['id'], aclRules1)
354 assert_equal(len(acl_Id), 1)
355 log.info('Added ACL rules = %s' %result.json()['aclRules'])
356 self.cliEnter()
357 ##Now verify
358 hosts = json.loads(self.cli.hosts(jsonFormat = True))
359 log.info('Discovered hosts: %s' %hosts)
360 flows = json.loads(self.cli.flows(jsonFormat = True))
361 flows = filter(lambda f: f['flows'], flows)
362 #log.info('Flows: %s' %flows)
363 assert_not_equal(len(flows), 0)
364 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP, ingress =ingress, egress = egress, ip_proto = 'UDP')
365 self.cliExit()
366 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
367
368 def test_acl_with_non_matching_src_and_dst_ip_traffic(self):
369 ingress = self.ingress_iface
370 egress = self.CURRENT_PORT_NUM
371 acl_rule = ACLTest()
372 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
373 self.CURRENT_PORT_NUM += 1
374 time.sleep(5)
375 if status is False:
376 log.info('JSON request returned status %d' %code)
377 assert_equal(status, True)
378 srcMac = '00:00:00:00:00:11'
379 dstMac = host_ip_mac[0][1]
380 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
381 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
382 time.sleep(10)
383 if status is False:
384 log.info('JSON request returned status %d' %code)
385 assert_equal(status, True)
386 result = acl_rule.get_acl_rules()
387 aclRules1 = result.json()['aclRules']
388 acl_Id = map(lambda d: d['id'], aclRules1)
389 assert_equal(len(acl_Id), 1)
390 log.info('Added ACL rules = %s' %result.json()['aclRules'])
391 self.cliEnter()
392 ##Now verify
393 hosts = json.loads(self.cli.hosts(jsonFormat = True))
394 log.info('Discovered hosts: %s' %hosts)
395 flows = json.loads(self.cli.flows(jsonFormat = True))
396 flows = filter(lambda f: f['flows'], flows)
397 #log.info('Flows: %s' %flows)
398 assert_not_equal(len(flows), 0)
399 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac, srcIp ='192.168.40.1/24', dstIp = self.ACL_DST_IP, ingress=ingress, egress = egress, ip_proto = 'UDP', positive_test = False )
400 self.cliExit()
401 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
402
403 def test_acl_deny_rule_with_matching_src_and_dst_ip_traffic(self):
404 ingress = self.ingress_iface
405 egress = self.CURRENT_PORT_NUM
406 acl_rule = ACLTest()
407 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
408 self.CURRENT_PORT_NUM += 1
409 time.sleep(5)
410 if status is False:
411 log.info('JSON request returned status %d' %code)
412 assert_equal(status, True)
413 srcMac = '00:00:00:00:00:11'
414 dstMac = host_ip_mac[0][1]
415 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
416 status, code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
417 time.sleep(10)
418 if status is False:
419 log.info('JSON request returned status %d' %code)
420 assert_equal(status, True)
421 result = acl_rule.get_acl_rules()
422 aclRules1 = result.json()['aclRules']
423 acl_Id = map(lambda d: d['id'], aclRules1)
424 assert_equal(len(acl_Id), 1)
425 log.info('Added ACL rules = %s' %result.json()['aclRules'])
426 self.cliEnter()
427 ##Now verify
428 hosts = json.loads(self.cli.hosts(jsonFormat = True))
429 log.info('Discovered hosts: %s' %hosts)
430 flows = json.loads(self.cli.flows(jsonFormat = True))
431 flows = filter(lambda f: f['flows'], flows)
432 #log.info('Flows: %s' %flows)
433 assert_not_equal(len(flows), 0)
434 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
435 self.cliExit()
436 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
437
438 def test_acl_deny_rule_with_src_and_dst_ip_applying_24_bit_mask_for_matching_traffic(self):
439 ingress = self.ingress_iface
440 egress = self.CURRENT_PORT_NUM
441 acl_rule = ACLTest()
442 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
443 self.CURRENT_PORT_NUM += 1
444 time.sleep(5)
445 if status is False:
446 log.info('JSON request returned status %d' %code)
447 assert_equal(status, True)
448 srcMac = '00:00:00:00:00:11'
449 dstMac = host_ip_mac[0][1]
450 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
451 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_PREFIX_24, dstIp =self.ACL_DST_IP_PREFIX_24, action = 'deny')
452 time.sleep(10)
453 if status is False:
454 log.info('JSON request returned status %d' %code)
455 assert_equal(status, True)
456 result = acl_rule.get_acl_rules()
457 aclRules1 = result.json()['aclRules']
458 acl_Id = map(lambda d: d['id'], aclRules1)
459 assert_equal(len(acl_Id), 1)
460 log.info('Added ACL rules = %s' %result.json()['aclRules'])
461 self.cliEnter()
462 ##Now verify
463 hosts = json.loads(self.cli.hosts(jsonFormat = True))
464 log.info('Discovered hosts: %s' %hosts)
465 flows = json.loads(self.cli.flows(jsonFormat = True))
466 flows = filter(lambda f: f['flows'], flows)
467 #log.info('Flows: %s' %flows)
468 assert_not_equal(len(flows), 0)
469 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_PREFIX_24, dstIp = self.ACL_DST_IP_PREFIX_24,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
470 self.cliExit()
471 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
472
473 def test_acl_deny_rule_with_non_matching_src_and_dst_ip_traffic(self):
474 ingress = self.ingress_iface
475 egress = self.CURRENT_PORT_NUM
476 acl_rule = ACLTest()
477 status, code, host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
478 self.CURRENT_PORT_NUM += 1
479 time.sleep(5)
480 if status is False:
481 log.info('JSON request returned status %d' %code)
482 assert_equal(status, True)
483 srcMac = '00:00:00:00:00:11'
484 dstMac = host_ip_mac[0][1]
485 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
486 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
487 time.sleep(10)
488 if status is False:
489 log.info('JSON request returned status %d' %code)
490 assert_equal(status, True)
491 result = acl_rule.get_acl_rules()
492 aclRules1 = result.json()['aclRules']
493 acl_Id = map(lambda d: d['id'], aclRules1)
494 assert_equal(len(acl_Id), 1)
495 log.info('Added ACL rules = %s' %result.json()['aclRules'])
496 self.cliEnter()
497 ##Now verify
498 hosts = json.loads(self.cli.hosts(jsonFormat = True))
499 log.info('Discovered hosts: %s' %hosts)
500 flows = json.loads(self.cli.flows(jsonFormat = True))
501 flows = filter(lambda f: f['flows'], flows)
502 #log.info('Flows: %s' %flows)
503 assert_not_equal(len(flows), 0)
504 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp ='192.168.40.1/24', dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
505 self.cliExit()
506 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
507
508 def test_acl_allow_and_deny_rules_with_matching_src_and_dst_ip_traffic(self):
509 ingress = self.ingress_iface
510 egress = self.CURRENT_PORT_NUM
511 acl_rule = ACLTest()
512 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
513 self.CURRENT_PORT_NUM += 1
514 time.sleep(5)
515 if status is False:
516 log.info('JSON request returned status %d' %code)
517 assert_equal(status, True)
518 srcMac = '00:00:00:00:00:11'
519 dstMac = host_ip_mac[0][1]
520 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
521 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
522 time.sleep(10)
523 if status is False:
524 log.info('JSON request returned status %d' %code)
525 assert_equal(status, True)
526 result = acl_rule.get_acl_rules()
527 aclRules1 = result.json()['aclRules']
528 acl_Id = map(lambda d: d['id'], aclRules1)
529 assert_equal(len(acl_Id), 1)
530 log.info('Added ACL rules = %s' %result.json()['aclRules'])
531 self.cliEnter()
532 ##Now verify
533 hosts = json.loads(self.cli.hosts(jsonFormat = True))
534 log.info('Discovered hosts: %s' %hosts)
535 flows = json.loads(self.cli.flows(jsonFormat = True))
536 flows = filter(lambda f: f['flows'], flows)
537 #log.info('Flows: %s' %flows)
538 assert_not_equal(len(flows), 0)
539 egress = self.CURRENT_PORT_NUM
540 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress ,ip_proto = 'UDP')
541 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP_RULE_2)
542 self.CURRENT_PORT_NUM += 1
543 time.sleep(5)
544 if status is False:
545 log.info('JSON request returned status %d' %code)
546 assert_equal(status, True)
547 dstMac = host_ip_mac[0][1]
548 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
549 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_RULE_2, dstIp =self.ACL_DST_IP_RULE_2, action = 'deny')
550 time.sleep(10)
551 if status is False:
552 log.info('JSON request returned status %d' %code)
553 assert_equal(status, True)
554 result = acl_rule.get_acl_rules()
555 aclRules1 = result.json()['aclRules']
556 acl_Id = map(lambda d: d['id'], aclRules1)
557 assert_equal(len(acl_Id), 2)
558 log.info('Added ACL rules = %s' %result.json()['aclRules'])
559 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_RULE_2, dstIp = self.ACL_DST_IP_RULE_2,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
560 ### crossing checking that we should not receive allow acl rule traffic on onther host non matched traffic
561 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, positive_test = False)
562 self.cliExit()
563 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
564
565 def test_acl_for_l4_acl_rule(self):
566 acl_rule = ACLTest()
567 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'allow')
568 if status is False:
569 log.info('JSON request returned status %d' %code)
570 assert_equal(status, True)
571 result = acl_rule.get_acl_rules()
572 aclRules1 = result.json()['aclRules']
573 log.info('Added ACL rules = %s' %result.json()['aclRules'])
574 acl_Id = map(lambda d: d['id'], aclRules1)
575 assert_equal(len(acl_Id), 1)
576
577 def test_acl_for_remove_l4_rule(self):
578 acl_rule = ACLTest()
579 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='245', action = 'allow')
580 if status is False:
581 log.info('JSON request returned status %d' %code)
582 assert_equal(status, True)
583 result = acl_rule.get_acl_rules()
584 aclRules1 = result.json()['aclRules']
585 log.info('Added ACL rules = %s' %result.json()['aclRules'])
586 acl_Id = map(lambda d: d['id'], aclRules1)
587 status, code = acl_rule.remove_acl_rule(acl_Id[0])
588 if status is False:
589 log.info('JSON request returned status %d' %code)
590 assert_equal(status, True)
591
592 def test_acl_for_remove_l4_rules(self):
593 acl_rule = ACLTest()
594 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='567', action = 'allow')
595 if status is False:
596 log.info('JSON request returned status %d' %code)
597 assert_equal(status, True)
598 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='245', action = 'deny')
599 if status is False:
600 log.info('JSON request returned status %d' %code)
601 assert_equal(status, True)
602 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='ICMP', dstTpPort ='1',action = 'allow')
603 if status is False:
604 log.info('JSON request returned status %d' %code)
605 assert_equal(status, True)
606 result = acl_rule.get_acl_rules()
607 aclRules1 = result.json()['aclRules']
608 log.info('Added ACL rules = %s' %result.json()['aclRules'])
609 acl_Id = map(lambda d: d['id'], aclRules1)
610 assert_equal(len(acl_Id), 3)
611 status, _ = ACLTest.remove_acl_rule()
612 if status is False:
613 log.info('JSON request returned status %d' %code)
614 assert_equal(status, True)
615
616 def test_acl_adding_specific_l4_and_all_l4_allow_rule(self):
617 acl_rule = ACLTest()
618 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'allow')
619 if status is False:
620 log.info('JSON request returned status %d' %code)
621 assert_equal(status, True)
622 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
623 if status is False:
624 log.info('JSON request returned status %d' %code)
625 assert_equal(status, True)
626 result = acl_rule.get_acl_rules()
627 aclRules1 = result.json()['aclRules']
628 log.info('Added ACL rules = %s' %result.json()['aclRules'])
629 acl_Id = map(lambda d: d['id'], aclRules1)
630 assert_equal(len(acl_Id), 2)
631
632 def test_acl_adding_all_l4_and_specific_l4_allow_rule(self):
633 acl_rule = ACLTest()
634 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
635 if status is False:
636 log.info('JSON request returned status %d' %code)
637 assert_equal(status, True)
638 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='345', action = 'allow')
639 if status is True:
640 log.info('JSON request returned status %d' %code)
641 assert_equal(status, True)
642 result = acl_rule.get_acl_rules()
643 aclRules1 = result.json()['aclRules']
644 log.info('Added ACL rules = %s' %result.json()['aclRules'])
645 acl_Id = map(lambda d: d['id'], aclRules1)
646 assert_equal(len(acl_Id), 1)
647
648 def test_acl_with_specific_l4_and_all_l4_deny_rule(self):
649 acl_rule = ACLTest()
650 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'deny')
651 if status is False:
652 log.info('JSON request returned status %d' %code)
653 assert_equal(status, True)
654 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
655 if status is False:
656 log.info('JSON request returned status %d' %code)
657 assert_equal(status, True)
658 result = acl_rule.get_acl_rules()
659 aclRules1 = result.json()['aclRules']
660 log.info('Added ACL rules = %s' %result.json()['aclRules'])
661 acl_Id = map(lambda d: d['id'], aclRules1)
662 assert_equal(len(acl_Id), 2)
663
664 def test_acl_with_all_l4_and_specific_l4_deny_rule(self):
665 acl_rule = ACLTest()
666 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
667 if status is False:
668 log.info('JSON request returned status %d' %code)
669 assert_equal(status, True)
670 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='345', action = 'deny')
671 if status is True:
672 log.info('JSON request returned status %d' %code)
673 assert_equal(status, True)
674 result = acl_rule.get_acl_rules()
675 aclRules1 = result.json()['aclRules']
676 log.info('Added ACL rules = %s' %result.json()['aclRules'])
677 acl_Id = map(lambda d: d['id'], aclRules1)
678 assert_equal(len(acl_Id), 1)
679
680 def test_acl_with_specific_l4_deny_and_all_l4_allow_rule(self):
681 acl_rule = ACLTest()
682 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'deny')
683 if status is False:
684 log.info('JSON request returned status %d' %code)
685 assert_equal(status, True)
686 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
687 if status is False:
688 log.info('JSON request returned status %d' %code)
689 assert_equal(status, True)
690 result = acl_rule.get_acl_rules()
691 aclRules1 = result.json()['aclRules']
692 log.info('Added ACL rules = %s' %result.json()['aclRules'])
693 acl_Id = map(lambda d: d['id'], aclRules1)
694 assert_equal(len(acl_Id), 2)
695
696 def test_acl_deny_all_l4_and_allow_specific_l4_rule(self):
697 acl_rule = ACLTest()
698 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
699 if status is False:
700 log.info('JSON request returned status %d' %code)
701 assert_equal(status, True)
702 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='345', action = 'allow')
703 if status is True:
704 log.info('JSON request returned status %d' %code)
705 assert_equal(status, True)
706 result = acl_rule.get_acl_rules()
707 aclRules1 = result.json()['aclRules']
708 log.info('Added ACL rules = %s' %result.json()['aclRules'])
709 acl_Id = map(lambda d: d['id'], aclRules1)
710 assert_equal(len(acl_Id), 1)
711
712 def test_acl_tcp_port_allow_rule_for_matching_and_non_matching_traffic(self):
713 ingress = self.ingress_iface
714 egress = self.CURRENT_PORT_NUM
715 acl_rule = ACLTest()
716 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
717 self.CURRENT_PORT_NUM += 1
718 time.sleep(5)
719 if status is False:
720 log.info('JSON request returned status %d' %code)
721 assert_equal(status, True)
722 srcMac = '00:00:00:00:00:11'
723 dstMac = host_ip_mac[0][1]
724 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
725 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'allow')
726 time.sleep(20)
727 if status is False:
728 log.info('JSON request returned status %d' %code)
729 assert_equal(status, True)
730 result = acl_rule.get_acl_rules()
731 aclRules1 = result.json()['aclRules']
732 acl_Id = map(lambda d: d['id'], aclRules1)
733 assert_equal(len(acl_Id), 1)
734 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
735 self.cliEnter()
736 ##Now verify
737 hosts = json.loads(self.cli.hosts(jsonFormat = True))
738 log.info('Discovered hosts: %s' %hosts)
739 flows = json.loads(self.cli.flows(jsonFormat = True))
740 flows = filter(lambda f: f['flows'], flows)
741 #log.info('Flows: %s' %flows)
742 assert_not_equal(len(flows), 0)
743 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 222)
744 ## Non-matching traffic for TCP portocol testing
745 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 444, positive_test = False)
746 self.cliExit()
747 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
748
749 def test_acl_udp_port_allow_rule_for_matching_and_non_matching_traffic(self):
750 ingress = self.ingress_iface
751 egress = self.CURRENT_PORT_NUM
752 acl_rule = ACLTest()
753 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
754 self.CURRENT_PORT_NUM += 1
755 time.sleep(5)
756 if status is False:
757 log.info('JSON request returned status %d' %code)
758 assert_equal(status, True)
759 srcMac = '00:00:00:00:00:11'
760 dstMac = host_ip_mac[0][1]
761 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
762 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='456', action = 'allow')
763 time.sleep(20)
764 if status is False:
765 log.info('JSON request returned status %d' %code)
766 assert_equal(status, True)
767 result = acl_rule.get_acl_rules()
768 aclRules1 = result.json()['aclRules']
769 acl_Id = map(lambda d: d['id'], aclRules1)
770 assert_equal(len(acl_Id), 1)
771 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
772 self.cliEnter()
773 ##Now verify
774 hosts = json.loads(self.cli.hosts(jsonFormat = True))
775 log.info('Discovered hosts: %s' %hosts)
776 flows = json.loads(self.cli.flows(jsonFormat = True))
777 flows = filter(lambda f: f['flows'], flows)
778 #log.info('Flows: %s' %flows)
779 assert_not_equal(len(flows), 0)
780 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 456)
781 ## Non-matching traffic for TCP portocol testing
782 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 654, positive_test = False)
783 self.cliExit()
784 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
785
786 def test_acl_icmp_port_allow_rule_for_matching_and_non_matching_traffic(self):
787 ingress = self.ingress_iface
788 egress = self.CURRENT_PORT_NUM
789 acl_rule = ACLTest()
790 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
791 self.CURRENT_PORT_NUM += 1
792 time.sleep(5)
793 if status is False:
794 log.info('JSON request returned status %d' %code)
795 assert_equal(status, True)
796 srcMac = '00:00:00:00:00:11'
797 dstMac = host_ip_mac[0][1]
798 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
799 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='ICMP', dstTpPort ='1', action = 'allow')
800 time.sleep(20)
801 if status is False:
802 log.info('JSON request returned status %d' %code)
803 assert_equal(status, True)
804 result = acl_rule.get_acl_rules()
805 aclRules1 = result.json()['aclRules']
806 acl_Id = map(lambda d: d['id'], aclRules1)
807 assert_equal(len(acl_Id), 1)
808 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
809 self.cliEnter()
810 ##Now verify
811 hosts = json.loads(self.cli.hosts(jsonFormat = True))
812 log.info('Discovered hosts: %s' %hosts)
813 flows = json.loads(self.cli.flows(jsonFormat = True))
814 flows = filter(lambda f: f['flows'], flows)
815 #log.info('Flows: %s' %flows)
816 assert_not_equal(len(flows), 0)
817 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'ICMP', dstPortNum = 1)
818 ## Non-matching traffic for TCP portocol testing
819 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'ICMP', dstPortNum = 2, positive_test = False)
820 self.cliExit()
821 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
822
823 def test_acl_tcp_port_deny_rule_for_matching_and_non_matching_traffic(self):
824 ingress = self.ingress_iface
825 egress = self.CURRENT_PORT_NUM
826 acl_rule = ACLTest()
827 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
828 self.CURRENT_PORT_NUM += 1
829 time.sleep(5)
830 if status is False:
831 log.info('JSON request returned status %d' %code)
832 assert_equal(status, True)
833 srcMac = '00:00:00:00:00:11'
834 dstMac = host_ip_mac[0][1]
835 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
836 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'deny')
837 time.sleep(20)
838 if status is False:
839 log.info('JSON request returned status %d' %code)
840 assert_equal(status, True)
841 result = acl_rule.get_acl_rules()
842 aclRules1 = result.json()['aclRules']
843 acl_Id = map(lambda d: d['id'], aclRules1)
844 assert_equal(len(acl_Id), 1)
845 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
846 self.cliEnter()
847 ##Now verify
848 hosts = json.loads(self.cli.hosts(jsonFormat = True))
849 log.info('Discovered hosts: %s' %hosts)
850 flows = json.loads(self.cli.flows(jsonFormat = True))
851 flows = filter(lambda f: f['flows'], flows)
852 #log.info('Flows: %s' %flows)
853 assert_not_equal(len(flows), 0)
854 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 222, positive_test = False)
855 ## Non-matching traffic for TCP portocol testing
856 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 444, positive_test = False)
857 self.cliExit()
858 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
859
860 def test_acl_udp_port_deny_rule_for_matching_and_non_matching_traffic(self):
861 ingress = self.ingress_iface
862 egress = self.CURRENT_PORT_NUM
863 acl_rule = ACLTest()
864 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
865 self.CURRENT_PORT_NUM += 1
866 time.sleep(5)
867 if status is False:
868 log.info('JSON request returned status %d' %code)
869 assert_equal(status, True)
870 srcMac = '00:00:00:00:00:11'
871 dstMac = host_ip_mac[0][1]
872 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
873 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='654', action = 'deny')
874 time.sleep(20)
875 if status is False:
876 log.info('JSON request returned status %d' %code)
877 assert_equal(status, True)
878 result = acl_rule.get_acl_rules()
879 aclRules1 = result.json()['aclRules']
880 acl_Id = map(lambda d: d['id'], aclRules1)
881 assert_equal(len(acl_Id), 1)
882 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
883 self.cliEnter()
884 ##Now verify
885 hosts = json.loads(self.cli.hosts(jsonFormat = True))
886 log.info('Discovered hosts: %s' %hosts)
887 flows = json.loads(self.cli.flows(jsonFormat = True))
888 flows = filter(lambda f: f['flows'], flows)
889 #log.info('Flows: %s' %flows)
890 assert_not_equal(len(flows), 0)
891 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 654, positive_test = False)
892 ## Non-matching traffic for TCP portocol testing
893 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 444, positive_test = False)
894 self.cliExit()
895 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
896
897 def test_acl_icmp_port_deny_rule_for_matching_and_non_matching_traffic(self):
898 ingress = self.ingress_iface
899 egress = self.CURRENT_PORT_NUM
900 acl_rule = ACLTest()
901 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
902 self.CURRENT_PORT_NUM += 1
903 time.sleep(5)
904 if status is False:
905 log.info('JSON request returned status %d' %code)
906 assert_equal(status, True)
907 srcMac = '00:00:00:00:00:11'
908 dstMac = host_ip_mac[0][1]
909 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
910 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='ICMP', dstTpPort ='1', action = 'deny')
911 time.sleep(20)
912 if status is False:
913 log.info('JSON request returned status %d' %code)
914 assert_equal(status, True)
915 result = acl_rule.get_acl_rules()
916 aclRules1 = result.json()['aclRules']
917 acl_Id = map(lambda d: d['id'], aclRules1)
918 assert_equal(len(acl_Id), 1)
919 log.info('Added ACL Rules = %s' %result.json()['aclRules'])
920 self.cliEnter()
921 ##Now verify
922 hosts = json.loads(self.cli.hosts(jsonFormat = True))
923 log.info('Discovered hosts: %s' %hosts)
924 flows = json.loads(self.cli.flows(jsonFormat = True))
925 flows = filter(lambda f: f['flows'], flows)
926 #log.info('Flows: %s' %flows)
927 assert_not_equal(len(flows), 0)
928 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'ICMP', dstPortNum = 1, positive_test = False)
929 ## Non-matching traffic for TCP portocol testing
930 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'ICMP', dstPortNum = 2, positive_test = False)
931 self.cliExit()
932 self.acl_hosts_remove(egress_iface_count = 1, egress_iface_num = egress)
933
934 def test_acl_two_allow_rules_for_tcp_port_matching_traffic(self):
935 ingress = self.ingress_iface
936 egress = self.CURRENT_PORT_NUM
937 acl_rule = ACLTest()
938 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
939 self.CURRENT_PORT_NUM += 1
940 time.sleep(5)
941 if status is False:
942 log.info('JSON request returned status %d' %code)
943 assert_equal(status, True)
944 srcMac = '00:00:00:00:00:11'
945 dstMac = host_ip_mac[0][1]
946 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
947 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='TCP', dstTpPort ='222', action = 'allow')
948 time.sleep(10)
949 if status is False:
950 log.info('JSON request returned status %d' %code)
951 assert_equal(status, True)
952 result = acl_rule.get_acl_rules()
953 aclRules1 = result.json()['aclRules']
954 acl_Id = map(lambda d: d['id'], aclRules1)
955 assert_equal(len(acl_Id), 1)
956 log.info('Added ACL rules = %s' %result.json()['aclRules'])
957 self.cliEnter()
958 ##Now verify
959 hosts = json.loads(self.cli.hosts(jsonFormat = True))
960 log.info('Discovered hosts: %s' %hosts)
961 flows = json.loads(self.cli.flows(jsonFormat = True))
962 flows = filter(lambda f: f['flows'], flows)
963 #log.info('Flows: %s' %flows)
964 assert_not_equal(len(flows), 0)
965 egress = self.CURRENT_PORT_NUM
966 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 222)
967 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP_RULE_2)
968 self.CURRENT_PORT_NUM += 1
969 time.sleep(5)
970 if status is False:
971 log.info('JSON request returned status %d' %code)
972 assert_equal(status, True)
973 dstMac = host_ip_mac[0][1]
974 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
975 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_RULE_2, dstIp =self.ACL_DST_IP_RULE_2, ipProto ='TCP', dstTpPort ='345', action = 'allow')
976 time.sleep(10)
977 if status is False:
978 log.info('JSON request returned status %d' %code)
979 assert_equal(status, True)
980 result = acl_rule.get_acl_rules()
981 aclRules1 = result.json()['aclRules']
982 acl_Id = map(lambda d: d['id'], aclRules1)
983 assert_equal(len(acl_Id), 2)
984 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_RULE_2, dstIp = self.ACL_DST_IP_RULE_2,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 345)
985 ### crossing checking that we should not receive allow acl rule traffic on onther host non matched traffic
986 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 222, positive_test = False)
987 self.cliExit()
988 self.acl_hosts_remove(egress_iface_count = 2, egress_iface_num = egress-1)
989
990 def test_acl_two_allow_rules_for_udp_ports_matching_traffic(self):
991 ingress = self.ingress_iface
992 egress = self.CURRENT_PORT_NUM
993 acl_rule = ACLTest()
994 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
995 self.CURRENT_PORT_NUM += 1
996 time.sleep(5)
997 if status is False:
998 log.info('JSON request returned status %d' %code)
999 assert_equal(status, True)
1000 srcMac = '00:00:00:00:00:11'
1001 dstMac = host_ip_mac[0][1]
1002 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1003 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, ipProto ='UDP', dstTpPort ='987', action = 'allow')
1004 time.sleep(10)
1005 if status is False:
1006 log.info('JSON request returned status %d' %code)
1007 assert_equal(status, True)
1008 result = acl_rule.get_acl_rules()
1009 aclRules1 = result.json()['aclRules']
1010 acl_Id = map(lambda d: d['id'], aclRules1)
1011 assert_equal(len(acl_Id), 1)
1012 log.info('Added ACL rules = %s' %result.json()['aclRules'])
1013 self.cliEnter()
1014 ##Now verify
1015 hosts = json.loads(self.cli.hosts(jsonFormat = True))
1016 log.info('Discovered hosts: %s' %hosts)
1017 flows = json.loads(self.cli.flows(jsonFormat = True))
1018 flows = filter(lambda f: f['flows'], flows)
1019 #log.info('Flows: %s' %flows)
1020 assert_not_equal(len(flows), 0)
1021 egress = self.CURRENT_PORT_NUM
1022 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 987)
1023 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP_RULE_2)
1024 self.CURRENT_PORT_NUM += 1
1025 time.sleep(5)
1026 if status is False:
1027 log.info('JSON request returned status %d' %code)
1028 assert_equal(status, True)
1029 dstMac = host_ip_mac[0][1]
1030 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1031 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_RULE_2, dstIp =self.ACL_DST_IP_RULE_2, ipProto ='TCP', dstTpPort ='345', action = 'allow')
1032 time.sleep(10)
1033 if status is False:
1034 log.info('JSON request returned status %d' %code)
1035 assert_equal(status, True)
1036 result = acl_rule.get_acl_rules()
1037 aclRules1 = result.json()['aclRules']
1038 acl_Id = map(lambda d: d['id'], aclRules1)
1039 assert_equal(len(acl_Id), 2)
1040 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_RULE_2, dstIp = self.ACL_DST_IP_RULE_2,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 345)
1041 ### crossing checking that we should not receive allow acl rule traffic on onther host non matched traffic
1042 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 987, positive_test = False)
1043 self.cliExit()
1044 self.acl_hosts_remove(egress_iface_count = 2, egress_iface_num = egress-1)
1045
1046 def test_acl_two_allow_rules_for_src_ips_dst_ips_and_l4_ports_matching_traffic(self):
1047 ingress = self.ingress_iface
1048 egress = self.CURRENT_PORT_NUM
1049 acl_rule = ACLTest()
1050 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
1051 self.CURRENT_PORT_NUM += 1
1052 time.sleep(5)
1053 if status is False:
1054 log.info('JSON request returned status %d' %code)
1055 assert_equal(status, True)
1056 srcMac = '00:00:00:00:00:11'
1057 dstMac = host_ip_mac[0][1]
1058 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1059 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'allow')
1060 time.sleep(10)
1061 if status is False:
1062 log.info('JSON request returned status %d' %code)
1063 assert_equal(status, True)
1064 result = acl_rule.get_acl_rules()
1065 aclRules1 = result.json()['aclRules']
1066 acl_Id = map(lambda d: d['id'], aclRules1)
1067 assert_equal(len(acl_Id), 1)
1068 log.info('Added ACL rules = %s' %result.json()['aclRules'])
1069 self.cliEnter()
1070 ##Now verify
1071 hosts = json.loads(self.cli.hosts(jsonFormat = True))
1072 log.info('Discovered hosts: %s' %hosts)
1073 flows = json.loads(self.cli.flows(jsonFormat = True))
1074 flows = filter(lambda f: f['flows'], flows)
1075 #log.info('Flows: %s' %flows)
1076 assert_not_equal(len(flows), 0)
1077 egress = self.CURRENT_PORT_NUM
1078 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP')
1079 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP_RULE_2)
1080 self.CURRENT_PORT_NUM += 1
1081 time.sleep(5)
1082 if status is False:
1083 log.info('JSON request returned status %d' %code)
1084 assert_equal(status, True)
1085 dstMac = host_ip_mac[0][1]
1086 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1087 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_RULE_2, dstIp =self.ACL_DST_IP_RULE_2, ipProto ='TCP', dstTpPort ='345', action = 'allow')
1088 time.sleep(10)
1089 if status is False:
1090 log.info('JSON request returned status %d' %code)
1091 assert_equal(status, True)
1092 result = acl_rule.get_acl_rules()
1093 aclRules1 = result.json()['aclRules']
1094 acl_Id = map(lambda d: d['id'], aclRules1)
1095 assert_equal(len(acl_Id), 2)
1096 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_RULE_2, dstIp = self.ACL_DST_IP_RULE_2,ingress =ingress, egress = egress, ip_proto = 'TCP', dstPortNum = 345)
1097 ### crossing checking that we should not receive allow acl rule traffic on onther host non matched traffic
1098 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 987, positive_test = False)
1099 self.cliExit()
1100 self.acl_hosts_remove(egress_iface_count = 2, egress_iface_num = egress-1)
1101
1102 def test_acl_allow_and_deny_rules_for_src_ips_dst_ips_and_l4_ports_matching_traffic(self):
1103 ingress = self.ingress_iface
1104 egress = self.CURRENT_PORT_NUM
1105 acl_rule = ACLTest()
1106 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP)
1107 self.CURRENT_PORT_NUM += 1
1108 time.sleep(5)
1109 if status is False:
1110 log.info('JSON request returned status %d' %code)
1111 assert_equal(status, True)
1112 srcMac = '00:00:00:00:00:11'
1113 dstMac = host_ip_mac[0][1]
1114 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1115 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP, dstIp =self.ACL_DST_IP, action = 'deny')
1116 time.sleep(10)
1117 if status is False:
1118 log.info('JSON request returned status %d' %code)
1119 assert_equal(status, True)
1120 result = acl_rule.get_acl_rules()
1121 aclRules1 = result.json()['aclRules']
1122 acl_Id = map(lambda d: d['id'], aclRules1)
1123 assert_equal(len(acl_Id), 1)
1124 log.info('Added ACL rules = %s' %result.json()['aclRules'])
1125 self.cliEnter()
1126 ##Now verify
1127 hosts = json.loads(self.cli.hosts(jsonFormat = True))
1128 log.info('Discovered hosts: %s' %hosts)
1129 flows = json.loads(self.cli.flows(jsonFormat = True))
1130 flows = filter(lambda f: f['flows'], flows)
1131 #log.info('Flows: %s' %flows)
1132 assert_not_equal(len(flows), 0)
1133 egress = self.CURRENT_PORT_NUM
1134 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', positive_test = False)
1135 status,code,host_ip_mac = acl_rule.generate_onos_interface_config(iface_num= self.CURRENT_PORT_NUM, iface_name = 'b1',iface_count = 1, iface_ip = self.HOST_DST_IP_RULE_2)
1136 self.CURRENT_PORT_NUM += 1
1137 time.sleep(5)
1138 if status is False:
1139 log.info('JSON request returned status %d' %code)
1140 assert_equal(status, True)
1141 dstMac = host_ip_mac[0][1]
1142 self.acl_hosts_add(dstHostIpMac = host_ip_mac, egress_iface_count = 1, egress_iface_num = egress )
1143 status,code = acl_rule.adding_acl_rule('v4', srcIp=self.ACL_SRC_IP_RULE_2, dstIp =self.ACL_DST_IP_RULE_2, ipProto ='UDP', dstTpPort ='345', action = 'allow')
1144 time.sleep(10)
1145 if status is False:
1146 log.info('JSON request returned status %d' %code)
1147 assert_equal(status, True)
1148 result = acl_rule.get_acl_rules()
1149 aclRules1 = result.json()['aclRules']
1150 acl_Id = map(lambda d: d['id'], aclRules1)
1151 assert_equal(len(acl_Id), 2)
1152 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP_RULE_2, dstIp = self.ACL_DST_IP_RULE_2,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 345)
1153 ### crossing checking that we should not receive allow acl rule traffic on onther host non matched traffic
1154 self.acl_rule_traffic_send_recv(srcMac = srcMac, dstMac = dstMac ,srcIp =self.ACL_SRC_IP, dstIp = self.ACL_DST_IP,ingress =ingress, egress = egress, ip_proto = 'UDP', dstPortNum = 987, positive_test = False)
1155 self.cliExit()
1156 self.acl_hosts_remove(egress_iface_count = 2, egress_iface_num = egress-1)
1157
1158
1159