-
Notifications
You must be signed in to change notification settings - Fork 35
/
config_acl.py
33 lines (26 loc) · 1003 Bytes
/
config_acl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Python code block to configure ACL
import cps_utils
#Define the enum map
e_stg = {'INGRESS': 1, 'EGRESS': 2}
e_ftype = {'SRC_MAC': 3, 'DST_MAC': 4, 'SRC_IP': 5, 'DST_IP': 6,
'IN_PORT': 9, 'DSCP': 21}
e_atype = {'PACKET_ACTION': 3, 'SET_TC': 10}
e_ptype = {'DROP': 1}
#Register the attribute type with the CPS utility for attributes with non-integer values
type_map = {
'base-acl/entry/SRC_MAC_VALUE/addr': 'mac',
'base-acl/entry/SRC_MAC_VALUE/mask': 'mac',
}
for key,val in type_map.items():
cps_utils.cps_attr_types_map.add_type(key, val)
#Create the CPS object and populate the attributes
cps_obj = cps_utils.CPSObject(module='base-acl/table')
#Set the stage and priority
cps_obj.add_attr ('stage', e_stg['INGRESS'])
cps_obj.add_attr ('priority', 99)
#Define an add operation and object pair to the CPS transaction
cps_trans = cps_utils.CPSTransaction([cps_update])
#Verify the return value
r = cps_trans.commit()
if not r:
raise RuntimeError ("Error creating ACL Table")