Skip to content

Commit d55d406

Browse files
committed
[acl_loader]: add iptype match to the rules for dataplane acl
dataplane acl has v4 and v6 type. in case the rule does not specify the iptype, the acl_loader will automatically add the match for the iptype based on the table type. for l3 table, it will add ethertype = 0x800 for l3v6 table, it will add iptype = ipv6any Signed-off-by: Guohan Lu <[email protected]>
1 parent 37376dd commit d55d406

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

acl_loader/main.py

+22
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,22 @@ def is_table_mirror(self, tname):
299299
"""
300300
return self.tables_db_info[tname]['type'].upper().startswith(self.ACL_TABLE_TYPE_MIRROR)
301301

302+
def is_table_l3v6(self, tname):
303+
"""
304+
Check if ACL table type is L3V6
305+
:param tname: ACL table name
306+
:return: True if table type is L3V6 else False
307+
"""
308+
return self.tables_db_info[tname]["type"].upper() == "L3V6"
309+
310+
def is_table_l3(self, tname):
311+
"""
312+
Check if ACL table type is L3
313+
:param tname: ACL table name
314+
:return: True if table type is L3 else False
315+
"""
316+
return self.tables_db_info[tname]["type"].upper() == "L3"
317+
302318
def is_table_ipv6(self, tname):
303319
"""
304320
Check if ACL table type is IPv6 (L3V6 or MIRRORV6)
@@ -593,6 +609,12 @@ def convert_rule_to_db_schema(self, table_name, rule):
593609

594610
rule_props["PRIORITY"] = str(self.max_priority - rule_idx)
595611

612+
# setup default ip type match to dataplane acl (could be overriden by rule later)
613+
if self.is_table_l3v6(table_name):
614+
rule_props["IP_TYPE"] = "IPV6ANY" # ETHERTYPE is not supported for DATAACLV6
615+
elif self.is_table_l3(table_name):
616+
rule_props["ETHER_TYPE"] = str(self.ethertype_map["ETHERTYPE_IPV4"])
617+
596618
deep_update(rule_props, self.convert_action(table_name, rule_idx, rule))
597619
deep_update(rule_props, self.convert_l2(table_name, rule_idx, rule))
598620
deep_update(rule_props, self.convert_ip(table_name, rule_idx, rule))

tests/acl_input/acl1.json

+17-1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@
189189
"destination-ip-address": "30.0.0.3/32"
190190
}
191191
}
192+
},
193+
"3": {
194+
"config": {
195+
"sequence-id": 3
196+
},
197+
"actions": {
198+
"config": {
199+
"forwarding-action": "ACCEPT"
200+
}
201+
},
202+
"l2": {
203+
"config": {
204+
"vlan-id": "369",
205+
"ethertype": "ETHERTYPE_LLDP"
206+
}
207+
}
192208
}
193209
}
194210
}
@@ -247,4 +263,4 @@
247263
}
248264
}
249265
}
250-
}
266+
}

tests/acl_loader_test.py

+15
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_vlan_id_translation(self, acl_loader):
6060
assert acl_loader.rules_info[("DATAACL", "RULE_2")]
6161
assert acl_loader.rules_info[("DATAACL", "RULE_2")] == {
6262
"VLAN_ID": 369,
63+
"ETHER_TYPE": "2048",
6364
"IP_PROTOCOL": 6,
6465
"SRC_IP": "20.0.0.2/32",
6566
"DST_IP": "30.0.0.3/32",
@@ -82,6 +83,17 @@ def test_vlan_id_not_a_number(self, acl_loader):
8283
acl_loader.rules_info = {}
8384
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/illegal_vlan_nan.json'))
8485

86+
def test_ethertype_translation(self, acl_loader):
87+
acl_loader.rules_info = {}
88+
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/acl1.json'))
89+
assert acl_loader.rules_info[("DATAACL", "RULE_3")]
90+
assert acl_loader.rules_info[("DATAACL", "RULE_3")] == {
91+
"VLAN_ID": 369,
92+
"ETHER_TYPE": 35020,
93+
"PACKET_ACTION": "FORWARD",
94+
"PRIORITY": "9997"
95+
}
96+
8597
def test_icmp_translation(self, acl_loader):
8698
acl_loader.rules_info = {}
8799
acl_loader.load_rules_from_file(os.path.join(test_path, 'acl_input/acl1.json'))
@@ -92,6 +104,7 @@ def test_icmp_translation(self, acl_loader):
92104
"IP_PROTOCOL": 1,
93105
"SRC_IP": "20.0.0.2/32",
94106
"DST_IP": "30.0.0.3/32",
107+
"ETHER_TYPE": "2048",
95108
"PACKET_ACTION": "FORWARD",
96109
"PRIORITY": "9999"
97110
}
@@ -106,6 +119,7 @@ def test_icmpv6_translation(self, acl_loader):
106119
"IP_PROTOCOL": 58,
107120
"SRC_IPV6": "::1/128",
108121
"DST_IPV6": "::1/128",
122+
"IP_TYPE": "IPV6ANY",
109123
"PACKET_ACTION": "FORWARD",
110124
"PRIORITY": "9999"
111125
}
@@ -114,6 +128,7 @@ def test_icmpv6_translation(self, acl_loader):
114128
"IP_PROTOCOL": 58,
115129
"SRC_IPV6": "::1/128",
116130
"DST_IPV6": "::1/128",
131+
"IP_TYPE": "IPV6ANY",
117132
"PACKET_ACTION": "FORWARD",
118133
"PRIORITY": "9900"
119134
}

0 commit comments

Comments
 (0)