-
Notifications
You must be signed in to change notification settings - Fork 1k
Added ACL tests #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added ACL tests #87
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4ba14d6
ACL testing: added files input test.
antonpatenko 17b8ef8
ACL testing: added port bind test.
antonpatenko 4bf5c70
ACL testing: added orchagent logic test:
antonpatenko 46183f4
ACL testing: added traffic test.
antonpatenko 6975aff
ACL testing: added counters test (by running traffic)
antonpatenko 4d57486
ACL testing: added L4 port ranges test:
antonpatenko a44751a
Loganalyzer: fixes to the scripts and common_match:
antonpatenko 04fe629
ACL testing: removed ports speed setting.
antonpatenko 54f2c4c
ACL tests fixes:
antonpatenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
ansible/roles/test/files/acstests/acl_port_range_traffic_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import sys | ||
| import ptf.packet as scapy | ||
| import ptf.dataplane as dataplane | ||
| import acs_base_test | ||
| from ptf.base_tests import BaseTest | ||
| import ptf.testutils as testutils | ||
| from ptf.testutils import * | ||
| import scapy.all as scapy2 | ||
|
|
||
| class SendTCP(acs_base_test.ACSDataplaneTest): | ||
| def runTest(self): | ||
| pkt = scapy2.Ether(src="e4:1d:2d:a5:f3:ac", dst="00:02:03:04:05:00") | ||
| pkt /= scapy2.IP(src="20.0.0.2", dst="20.0.0.1") | ||
|
|
||
| # get L4 port number | ||
| port_number = testutils.test_params_get("port_number") | ||
| port = port_number["port_number"] | ||
| pkt /= scapy2.TCP(sport = int(port)) | ||
| pkt /= ("badabadaboom") | ||
|
|
||
| # get packets number | ||
| count = testutils.test_params_get("count") | ||
| pack_number = count["count"] | ||
|
|
||
| # send packets | ||
| send(self, 0, pkt, int(pack_number)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import ptf.packet as scapy | ||
| import ptf.dataplane as dataplane | ||
| import acs_base_test | ||
| from ptf.base_tests import BaseTest | ||
| from ptf.testutils import * | ||
| from ptf.mask import Mask | ||
| import scapy.all as scapy2 | ||
| from time import sleep | ||
| from threading import Thread | ||
|
|
||
| class FailingTest(BaseTest): | ||
| ''' | ||
| Test designed to fail | ||
| ''' | ||
| def runTest(self): | ||
| a = 5 / 0 | ||
| pass | ||
|
|
||
| class SucceessTest(BaseTest): | ||
| ''' | ||
| Test designed for success | ||
| ''' | ||
| def runTest(self): | ||
| pass | ||
|
|
||
| class SendTCP(acs_base_test.ACSDataplaneTest): | ||
| ''' | ||
| FIN = 0x01 | ||
| SYN = 0x02 | ||
| RST = 0x04 | ||
| PSH = 0x08 | ||
| ACK = 0x10 | ||
| URG = 0x20 | ||
| ECE = 0x40 | ||
| CWR = 0x80 | ||
| ''' | ||
|
|
||
| def pkt_callback(self, pkt): | ||
| if pkt.haslayer(scapy2.TCP) and pkt.getlayer(scapy2.IP).src == "22.0.0.2": | ||
| self.sniffed_cnt += 1 | ||
|
|
||
| def Sniffer(self, interface): | ||
| self.sniffed_cnt = 0 | ||
| scapy2.sniff(iface="eth2", prn=self.pkt_callback, store=0, timeout=3) | ||
|
|
||
| def runTest(self): | ||
|
|
||
| pkt = scapy2.Ether() | ||
| pkt /= scapy2.IP(src="21.0.0.2", dst="22.0.0.2") | ||
| pkt /= scapy2.TCP(dport = 80, flags="S", seq=42) | ||
| pkt /= ("badabadaboom") | ||
|
|
||
| t = Thread(target=self.Sniffer, args=("eth2",)) | ||
| t.start() | ||
| scapy2.sendp(pkt, iface='eth2') | ||
| sleep(4) | ||
| # fail if no reply | ||
| if self.sniffed_cnt == 0: | ||
| self.assertTrue(False) | ||
|
|
||
|
|
||
| #res = scapy2.sniff(iface="eth2", timeout=3) | ||
| #print res | ||
| #if res: | ||
| # raise | ||
|
|
||
| #if reply: | ||
| # raise | ||
| #print "================______====\n" | ||
| #print reply | ||
| #print error | ||
| #print "================______====\n" | ||
| #if reply: | ||
| # reply.show() | ||
| #(rcv_device, rcv_port, rcv_pkt, pkt_time) = dp_poll(self, device_number=0, port_number=0, timeout=5) | ||
| #send_packet(self, 0, pkt) | ||
| #(rcv_device, rcv_port, rcv_pkt, pkt_time) = dp_poll(self, device_number=0, port_number=0, timeout=5) | ||
|
|
||
|
|
||
| # verify_packet(self, masked_exp_pkt, 1) | ||
|
|
||
|
|
||
| #mpkt = Mask(pkt) | ||
| #mpkt.set_do_not_care(0, 14*8) | ||
| #mpkt.set_do_not_care(16*8, 49*8) | ||
| #verify_packet(self, mpkt, 0) | ||
| #(rcv_device, rcv_port, rcv_pkt, pkt_time) = dp_poll(self, device_number=0, port_number=0, timeout=5) | ||
| #print "================______====\n" | ||
| #y = 0 | ||
| #for x in rcv_pkt: | ||
| # print "%d - %X" % (y, ord(x)) | ||
| # y +=1 | ||
| """ | ||
| (rcv_device, rcv_port, rcv_pkt, pkt_time) = dp_poll(self, device_number=0, timeout=3) | ||
| print "================______====\n" | ||
| y = 0 | ||
| for x in rcv_pkt: | ||
| print "%d - %X" % (y, ord(x)) | ||
| y +=1 | ||
|
|
||
| y = 0 | ||
| for x in str(pkt): | ||
| print "%d - %X" % (y, ord(x)) | ||
| y +=1 | ||
| """ | ||
|
|
||
|
|
||
| """ | ||
|
|
||
| pkt = scapy.Ether() | ||
| pkt /= scapy.IP(src="21.0.0.2", dst="22.0.0.2") | ||
| pkt /= scapy.TCP(sport = 8192, dport = 80, flags="S", seq=42) | ||
| m = Mask.Mask(pkt) | ||
| m.set_do_not_care_scapy(Ether, 'src') | ||
| m.set_do_not_care_scapy(Ether, 'dst') | ||
| m.set_do_not_care_scapy(IP, 'ttl') | ||
| m.set_do_not_care_scapy(IP, 'len') | ||
| m.set_do_not_care_scapy(IP, 'flags') | ||
| verify_packet(self, pkt, 0); | ||
| verify_packets(<test>, m) | ||
|
|
||
|
|
||
| Test ACL permition | ||
|
|
||
|
|
||
| import ptf.packet as scapy | ||
|
|
||
| import ptf.dataplane as dataplane | ||
| import acs_base_test | ||
|
|
||
| from ptf.testutils import * | ||
| from ptf.mask import Mask | ||
|
|
||
|
|
||
| class ACLpermit(acs_base_test.ACSDataplaneTest): | ||
| def runTest(self): | ||
| print "The test is passed" | ||
| pass | ||
| # pkt = simple_ip_packet( eth_dst='00:01:02:03:04:05', | ||
| # eth_src='00:06:07:08:09:0a', | ||
| # ip_src='192.168.0.1', | ||
| # ip_dst='192.168.0.2', | ||
| # ip_ttl=64) | ||
| # send_packet(self, port, pkt) | ||
|
|
||
| # pkt = scapy.Ether() | ||
| # pkt /= scapy.IP(src="20.0.0.2", dst="21.0.0.2") | ||
| # pkt /= scapy.TCP() | ||
| # pkt /= ("Yellow Sun") | ||
| # send_packet(self, 1, pkt) | ||
| # verify_packet(self, pkt, 2) | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
|
|
||
| #----------------------------------------- | ||
| # Run all the acl tests. | ||
| #----------------------------------------- | ||
|
|
||
| - set_fact: | ||
| vars_files_location: vars/acl | ||
|
|
||
| - include_vars: "{{ vars_files_location }}/acl_vars.yml" | ||
|
|
||
| - name: Create run_dir | ||
| file: path="{{ run_dir }}" state=directory | ||
|
|
||
| #****************************************# | ||
| # Start tests # | ||
| #****************************************# | ||
|
|
||
| - block: | ||
| - name: Test file input. | ||
| include: "{{ tests_location }}/acl_input_test/acl_input_test.yml" | ||
|
|
||
| - name: Test port bind configuration. | ||
| include: "{{ tests_location }}/acl_port_bind_test/acl_port_bind_test.yml" | ||
|
|
||
| - name: Test orchagent logic. | ||
| include: "{{ tests_location }}/acl_orchagent_logic_test/acl_orchagent_logic_test.yml" | ||
|
|
||
| - name: Test traffic. | ||
| include: "{{ tests_location }}/acl_traffic_test/acl_traffic_test.yml" | ||
|
|
||
| - name: Test counters traffic. | ||
| include: "{{ tests_location }}/acl_counter_traffic_test/acl_counter_traffic_test.yml" | ||
|
|
||
| - name: Test L4 ports. | ||
| include: "{{ tests_location }}/acl_port_range_test/acl_port_range_test.yml" | ||
|
|
||
| always: | ||
| - name: General cleanup. | ||
| file: path="{{ item }}" state=absent | ||
| with_items: | ||
| - "{{ run_dir }}/loganalyzer.py" | ||
36 changes: 36 additions & 0 deletions
36
ansible/roles/test/tasks/acl/acl_counter_traffic_test/acl_check_db.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
|
|
||
| - block: | ||
| - name: Check if Redis DB contains corresponding data. | ||
| shell: docker exec -i database redis-cli -n 1 KEYS \* | grep "ASIC_STATE:SAI_OBJECT_TYPE_ACL_COUNTER" | ||
| register: grep_redis | ||
| failed_when: (expect_data == true and grep_redis.rc != 0) or (expect_data == false and grep_redis.rc == 0) | ||
|
|
||
| - name: Wait for data to be written into Counters DB ... | ||
| pause: | ||
| seconds: 10 | ||
|
|
||
| - name: Read counters value. | ||
| shell: docker exec -i database redis-cli -n 2 HGET "COUNTERS:{{ table_name_check }}:{{ rule_name_check }}" Packets | ||
| register: counters_value | ||
| when: expect_data == true | ||
|
|
||
| - name: Check if corresponding data was removed from Counters DB. | ||
| shell: docker exec -i database redis-cli -n 2 KEYS \* | grep {{ rule_name_check }} | ||
| register: grep_counters | ||
| failed_when: grep_counters.rc == 0 | ||
| when: expect_data == false | ||
|
|
||
| always: | ||
| # check for successful creating. | ||
| - fail: msg="Failed to find corresponding data in Redis DB. Used {{ table_name_check }} / {{ rule_name_check }}" | ||
| when: expect_data == true and grep_redis.rc != 0 | ||
|
|
||
| - fail: msg="Failed to find corresponding data in Counters DB. Used {{ table_name_check }} / {{ rule_name_check }}" | ||
| when: expect_data == true and counters_value.stdout != "{{ expected_counter_value }}" | ||
|
|
||
| # check for successful deleting. | ||
| - fail: msg="Failed to delete corresponding rule-data from Redis DB. Used {{ table_name_check }} / {{ rule_name_check }}" | ||
| when: expect_data == false and grep_redis.rc == 0 | ||
|
|
||
| - fail: msg="Failed to delete corresponding rule-data from Counters DB. Used {{ table_name_check }} / {{ rule_name_check }}" | ||
| when: expect_data == false and grep_counters.rc == 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of {{ tests_location }} ?
Are you going to change the tests location?
For me it is a constant.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using of path to the ACL tests occurs pretty often during the tests execution, so I decided to put it into variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it Thanks