2.22. test_classifier module

class test_classifier.TestClassifier(methodName='runTest')

Bases: framework.VppTestCase

Classifier Test Case

static build_ip_mask(proto='', src_ip='', dst_ip='', src_port='', dst_port='')

Build IP ACL mask data with hexstring format.

Parameters
  • proto (str) – protocol number <0-ff>

  • src_ip (str) – source ip address <0-ffffffff>

  • dst_ip (str) – destination ip address <0-ffffffff>

  • src_port (str) – source port number <0-ffff>

  • dst_port (str) – destination port number <0-ffff>

static build_ip_match(proto=0, src_ip='', dst_ip='', src_port=0, dst_port=0)

Build IP ACL match data with hexstring format.

Parameters
  • proto (int) – protocol number with valid option “x”

  • src_ip (str) – source ip address with format of “x.x.x.x”

  • dst_ip (str) – destination ip address with format of “x.x.x.x”

  • src_port (int) – source port number “x”

  • dst_port (int) – destination port number “x”

static build_mac_mask(dst_mac='', src_mac='', ether_type='')

Build MAC ACL mask data with hexstring format.

Parameters
  • dst_mac (str) – source MAC address <0-ffffffffffff>

  • src_mac (str) – destination MAC address <0-ffffffffffff>

  • ether_type (str) – ethernet type <0-ffff>

static build_mac_match(dst_mac='', src_mac='', ether_type='')

Build MAC ACL match data with hexstring format.

Parameters
  • dst_mac (str) – source MAC address <x:x:x:x:x:x>

  • src_mac (str) – destination MAC address <x:x:x:x:x:x>

  • ether_type (str) – ethernet type <0-ffff>

create_classify_session(table_index, match, pbr_option=0, vrfid=0, is_add=1)

Create Classify Session

Parameters
  • table_index (int) – table index to identify classify table.

  • match (str) – matched value for interested traffic.

  • pbr_option (int) – enable/disable PBR feature.

  • vrfid (int) – VRF id.

  • is_add (int) – option to configure classify session. - create(1) or delete(0)

create_classify_table(key, mask, data_offset=0)

Create Classify Table

Parameters
  • key (str) – key for classify table (ex, ACL name).

  • mask (str) – mask value for interested traffic.

  • data_offset (int) –

create_stream(src_if, dst_if, packet_sizes, proto_l=scapy.layers.inet.UDP)

Create input packet stream for defined interfaces.

Parameters
  • src_if (VppInterface) – Source Interface for packet stream.

  • dst_if (VppInterface) – Destination Interface for packet stream.

  • packet_sizes (list) – packet size to test.

  • proto_l (Scapy) – Required IP protocol. Default protocol is UDP.

input_acl_set_interface(intf, table_index, is_add=1)

Configure Input ACL interface

Parameters
  • intf (VppInterface) – Interface to apply Input ACL feature.

  • table_index (int) – table index to identify classify table.

  • is_add (int) – option to configure classify session. - enable(1) or disable(0)

output_acl_set_interface(intf, table_index, is_add=1)

Configure Output ACL interface

Parameters
  • intf (VppInterface) – Interface to apply Output ACL feature.

  • table_index (int) – table index to identify classify table.

  • is_add (int) – option to configure classify session. - enable(1) or disable(0)

setUp()

Perform test setup before test case.

Config:
  • create 4 pg interfaces
    • untagged pg0/pg1/pg2 interface
      pg0 ——-> pg1 (IP ACL)
      —> pg2 (MAC ACL))

      -> pg3 (PBR)

  • setup interfaces:
    • put it into UP state

    • set IPv4 addresses

    • resolve neighbor address using ARP

Variables
  • interfaces (list) – pg interfaces.

  • pg_if_packet_sizes (list) – packet sizes in test.

  • acl_tbl_idx (dict) – ACL table index.

  • pbr_vrfid (int) – VRF id for PBR test.

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

show_commands_at_teardown()

Allow subclass specific teardown logging additions.

tearDown()

Run standard test teardown and acl related log.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

verify_capture(dst_if, capture, proto_l=scapy.layers.inet.UDP)

Verify captured input packet stream for defined interface.

Parameters
  • dst_if (VppInterface) – Interface to verify captured packet stream.

  • capture (list) – Captured packet stream.

  • proto_l (Scapy) – Required IP protocol. Default protocol is UDP.

verify_vrf(vrf_id)

Check if the FIB table / VRF ID is configured.

Parameters

vrf_id (int) – The FIB table / VRF ID to be verified.

Returns

1 if the FIB table / VRF ID is configured, otherwise return 0.

class test_classifier.TestClassifierIP(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier IP Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_iacl_dst_ip()

Destination IP iACL test

Test scenario for basic IP ACL with destination IP
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with destination IP address.

  • Send and verify received packets on pg1 interface.

test_iacl_src_dst_ip()

Source and destination IP iACL test

Test scenario for basic IP ACL with source and destination IP
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with source and destination IP addresses.

  • Send and verify received packets on pg1 interface.

test_iacl_src_ip()

Source IP iACL test

Test scenario for basic IP ACL with source IP
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with source IP address.

  • Send and verify received packets on pg1 interface.

class test_classifier.TestClassifierIPOut(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier output IP Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_acl_ip_out()

Output IP ACL test

Test scenario for basic IP ACL with source IP
  • Create IPv4 stream for pg1 -> pg0 interface.

  • Create ACL with source IP address.

  • Send and verify received packets on pg0 interface.

class test_classifier.TestClassifierMAC(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier MAC Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_acl_mac()

MAC ACL test

Test scenario for basic MAC ACL with source MAC
  • Create IPv4 stream for pg0 -> pg2 interface.

  • Create ACL with source MAC address.

  • Send and verify received packets on pg2 interface.

class test_classifier.TestClassifierPBR(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier PBR Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_acl_pbr()

IP PBR test

Test scenario for PBR with source IP
  • Create IPv4 stream for pg0 -> pg3 interface.

  • Configure PBR fib entry for packet forwarding.

  • Send and verify received packets on pg3 interface.

class test_classifier.TestClassifierTCP(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier TCP proto Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_iacl_proto_tcp()

TCP protocol iACL test

Test scenario for basic protocol ACL with TCP protocol
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with TCP IP protocol.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_tcp_dport()

TCP destination port iACL test

Test scenario for basic protocol ACL with TCP and dport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with TCP IP protocol and defined dport.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_tcp_sport()

TCP source port iACL test

Test scenario for basic protocol ACL with TCP and sport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with TCP IP protocol and defined sport.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_tcp_sport_dport()

TCP source and destination ports iACL test

Test scenario for basic protocol ACL with TCP and sport and dport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with TCP IP protocol and defined sport and dport.

  • Send and verify received packets on pg1 interface.

class test_classifier.TestClassifierUDP(methodName='runTest')

Bases: test_classifier.TestClassifier

Classifier UDP proto Test Case

classmethod setUpClass()

Perform standard class setup (defined by class method setUpClass in class VppTestCase) before running the test case, set test case related variables and configure VPP.

classmethod tearDownClass()

Perform final cleanup after running all tests in this test-case

test_iacl_proto_udp()

UDP protocol iACL test

Test scenario for basic protocol ACL with UDP protocol
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with UDP IP protocol.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_udp_dport()

UDP destination port iACL test

Test scenario for basic protocol ACL with UDP and dport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with UDP IP protocol and defined dport.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_udp_sport()

UDP source port iACL test

Test scenario for basic protocol ACL with UDP and sport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with UDP IP protocol and defined sport.

  • Send and verify received packets on pg1 interface.

test_iacl_proto_udp_sport_dport()

UDP source and destination ports iACL test

Test scenario for basic protocol ACL with UDP and sport and dport
  • Create IPv4 stream for pg0 -> pg1 interface.

  • Create iACL with UDP IP protocol and defined sport and dport.

  • Send and verify received packets on pg1 interface.