MCPcopy Create free account
hub / github.com/FDio/vpp / test_0001_acl_create

Method test_0001_acl_create

test/test_acl_plugin.py:540–606  ·  view source on GitHub ↗

ACL create/delete test

(self)

Source from the content-addressed store, hash-verified

538 # self.assertEqual(reply.minor, 0)
539
540 def test_0001_acl_create(self):
541 """ACL create/delete test"""
542
543 self.logger.info("ACLP_TEST_START_0001")
544 # Create a permit-1234 ACL
545 r = [AclRule(is_permit=1, proto=17, ports=1234, sport_to=1235)]
546 # Test 1: add a new ACL
547 first_acl = VppAcl(self, rules=r, tag="permit 1234")
548 first_acl.add_vpp_config()
549 self.assertTrue(first_acl.query_vpp_config())
550 # The very first ACL gets #0
551 self.assertEqual(first_acl.acl_index, 0)
552 rr = first_acl.dump()
553 self.logger.info("Dumped ACL: " + str(rr))
554 self.assertEqual(len(rr), 1)
555 # We should have the same number of ACL entries as we had asked
556 self.assertEqual(len(rr[0].r), len(r))
557 # The rules should be the same. But because the submitted and returned
558 # are different types, we need to iterate over rules and keys to get
559 # to basic values.
560 for i_rule in range(0, len(r) - 1):
561 encoded_rule = r[i_rule].encode()
562 for rule_key in encoded_rule:
563 self.assertEqual(rr[0].r[i_rule][rule_key], encoded_rule[rule_key])
564
565 # Create a deny-1234 ACL
566 r_deny = [
567 AclRule(is_permit=0, proto=17, ports=1234, sport_to=1235),
568 AclRule(is_permit=1, proto=17, ports=0),
569 ]
570 second_acl = VppAcl(self, rules=r_deny, tag="deny 1234;permit all")
571 second_acl.add_vpp_config()
572 self.assertTrue(second_acl.query_vpp_config())
573 # The second ACL gets #1
574 self.assertEqual(second_acl.acl_index, 1)
575
576 # Test 2: try to modify a nonexistent ACL
577 invalid_acl = VppAcl(self, acl_index=432, rules=r, tag="FFFF:FFFF")
578 reply = invalid_acl.add_vpp_config(expect_error=True)
579
580 # apply an ACL on an interface inbound, try to delete ACL, must fail
581 acl_if_list = VppAclInterface(
582 self, sw_if_index=self.pg0.sw_if_index, n_input=1, acls=[first_acl]
583 )
584 acl_if_list.add_vpp_config()
585 first_acl.remove_vpp_config(expect_error=True)
586 # Unapply an ACL and then try to delete it - must be ok
587 acl_if_list.remove_vpp_config()
588 first_acl.remove_vpp_config()
589
590 # apply an ACL on an interface inbound, try to delete ACL, must fail
591 acl_if_list = VppAclInterface(
592 self, sw_if_index=self.pg0.sw_if_index, n_input=0, acls=[second_acl]
593 )
594 acl_if_list.add_vpp_config()
595 second_acl.remove_vpp_config(expect_error=True)
596 # Unapply an ACL and then try to delete it - must be ok
597 acl_if_list.remove_vpp_config()

Callers

nothing calls this directly

Calls 10

add_vpp_configMethod · 0.95
query_vpp_configMethod · 0.95
dumpMethod · 0.95
add_vpp_configMethod · 0.95
remove_vpp_configMethod · 0.95
remove_vpp_configMethod · 0.95
AclRuleClass · 0.90
VppAclClass · 0.90
VppAclInterfaceClass · 0.90
encodeMethod · 0.45

Tested by

no test coverage detected