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