1 /*! \file acl_example.py
6 """acl_example.py: OpEN API Security Access Lists (ACL) configuration example"""
12 from sys
import version_info
42 ACTION_PERMIT =
'permit'
45 MATCH_ASSIGN_QUEUE =
'assign-queue'
49 MATCH_ETHER_TYPE =
'ether-type'
51 MATCH_FLOW_LABEL =
'flow-label'
52 MATCH_FRAGMENTS =
'fragments'
53 MATCH_ICMP_TYPE =
'icmp-type'
54 MATCH_IGMP_TYPE =
'igmp-type'
55 MATCH_IP_DST_MASK =
'ip-dst-mask'
56 MATCH_IP_SRC_MASK =
'ip-src-mask'
57 MATCH_IPV6_DST_PFX =
'ipv6-dst-pfx'
58 MATCH_IPV6_SRC_PFX =
'ipv6-src-pfx'
59 MATCH_L4_DST_PORT =
'l4-dst-port'
60 MATCH_L4_SRC_PORT =
'l4-src-port'
61 MATCH_LOGGING =
'logging'
62 MATCH_MAC_DST_MASK =
'mac-dst-mask'
63 MATCH_MAC_SRC_MASK =
'mac-src-mask'
64 MATCH_PACKET_MIRRORING =
'packet-mirroring'
65 MATCH_PACKET_REDIRECTION =
'packet-redirection'
66 MATCH_PRECEDENCE =
'precedence'
67 MATCH_PROTOCOL =
'protocol'
68 MATCH_RATE_LIMIT =
'rate-limit'
69 MATCH_REDIRECT_AGENT =
'redirect-agent'
70 MATCH_ROUTING_FLAG =
'routing-flag'
71 MATCH_TCP_FLAGS =
'tcp-flags'
72 MATCH_TIME_BASED =
'time-based'
81 {ACL:[
'test_ip',OpEN.OPEN_ACL_TYPE_IP]},
82 {RULE:OpEN.OPEN_ACL_PERMIT},
84 {MATCH_ASSIGN_QUEUE:[]},
85 {MATCH_LOGGING:[
True]},
86 {MATCH_PACKET_MIRRORING:[]},
87 {RULE:OpEN.OPEN_ACL_PERMIT},
88 {MATCH_IP_SRC_MASK:[
'10.10.10.1',
'255.0.0.0']},
89 {MATCH_IP_DST_MASK:[
'20.20.20.1',
'255.0.0.0']},
90 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_PIM]},
91 {MATCH_DSCP:[OpEN.OPENAPI_ACL_IP_DSCP_AF11]},
92 {MATCH_FRAGMENTS:[
True]},
93 {MATCH_PRECEDENCE:[7]},
94 {MATCH_TOS:[
'a0',
'a2']},
95 {MATCH_PACKET_REDIRECTION:[]},
96 {RULE:OpEN.OPEN_ACL_PERMIT},
97 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_TCP]},
98 {MATCH_REDIRECT_AGENT:[100]},
99 {MATCH_RATE_LIMIT:[4294967295,128]},
100 {MATCH_TIME_BASED:[
'ipv4-time-range-name']},
101 {RULE:OpEN.OPEN_ACL_PERMIT},
102 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_ICMP]},
103 {MATCH_ICMP_TYPE:[8,0,
True]},
104 {RULE:OpEN.OPEN_ACL_PERMIT},
105 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_IGMP]},
106 {MATCH_IGMP_TYPE:[30]},
107 {RULE:OpEN.OPEN_ACL_PERMIT},
108 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_TCP]},
109 {MATCH_TCP_FLAGS:[OpEN.OPENAPI_ACL_TCP_FLAG_FIN,OpEN.OPENAPI_ACL_TCP_FLAG_SYN,OpEN.OPENAPI_ACL_TCP_FLAG_ACK]},
110 {MATCH_L4_SRC_PORT:[OpEN.OPEN_ACL_L4_PORT_OPERATOR_EQUAL_TO,80,0]},
111 {RULE:OpEN.OPEN_ACL_PERMIT},
112 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_UDP]},
113 {MATCH_L4_SRC_PORT:[OpEN.OPEN_ACL_L4_PORT_OPERATOR_LESS_THAN,10000,0]},
114 {MATCH_L4_DST_PORT:[OpEN.OPEN_ACL_L4_PORT_OPERATOR_GREATER_THAN,20000,0]},
115 {RULE:OpEN.OPEN_ACL_DENY},
117 {ACL:[
'test_ip6',OpEN.OPEN_ACL_TYPE_IPV6]},
118 {RULE:OpEN.OPEN_ACL_PERMIT},
119 {MATCH_EVERY:[
True]},
120 {MATCH_ASSIGN_QUEUE:[3]},
121 {MATCH_LOGGING:[
True]},
122 {MATCH_PACKET_MIRRORING:[]},
123 {RULE:OpEN.OPEN_ACL_PERMIT},
124 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_PIM]},
125 {MATCH_IPV6_SRC_PFX:[
'1001::',24]},
126 {MATCH_IPV6_DST_PFX:[
'2001::',24]},
127 {MATCH_DSCP:[OpEN.OPENAPI_ACL_IP_DSCP_AF11]},
128 {MATCH_FRAGMENTS:[
True]},
129 {MATCH_PACKET_REDIRECTION:[100]},
130 {RULE:OpEN.OPEN_ACL_PERMIT},
131 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_TCP]},
132 {MATCH_REDIRECT_AGENT:[100]},
133 {MATCH_RATE_LIMIT:[4294967295,128]},
134 {MATCH_TIME_BASED:[
'ipv6-time-range-name']},
135 {MATCH_FLOW_LABEL:[1048575]},
136 {MATCH_ROUTING_FLAG:[
True]},
137 {RULE:OpEN.OPEN_ACL_PERMIT},
138 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_ICMPV6]},
139 {MATCH_ICMP_TYPE:[1,4,
True]},
140 {RULE:OpEN.OPEN_ACL_PERMIT},
141 {MATCH_PROTOCOL:[OpEN.OPENAPI_ACL_PROTOCOL_TCP]},
142 {MATCH_TCP_FLAGS:[OpEN.OPENAPI_ACL_TCP_FLAG_RST,OpEN.OPENAPI_ACL_TCP_FLAG_PSH,OpEN.OPENAPI_ACL_TCP_FLAG_URG]},
143 {MATCH_L4_SRC_PORT:[OpEN.OPEN_ACL_L4_PORT_OPERATOR_RANGE,20000,20010]},
144 {MATCH_L4_DST_PORT:[OpEN.OPEN_ACL_L4_PORT_OPERATOR_GREATER_THAN,60000,0]},
145 {RULE:OpEN.OPEN_ACL_DENY},
147 {ACL:[
'test_mac',OpEN.OPEN_ACL_TYPE_MAC]},
148 {RULE:OpEN.OPEN_ACL_PERMIT},
149 {MATCH_EVERY:[
True]},
150 {MATCH_ASSIGN_QUEUE:[5]},
151 {MATCH_LOGGING:[
True]},
152 {MATCH_PACKET_MIRRORING:[]},
153 {RULE:OpEN.OPEN_ACL_PERMIT},
154 {MATCH_MAC_SRC_MASK:[
'00:11:22:33:44:55',
'ff:ff:ff:00:00:00']},
155 {MATCH_MAC_DST_MASK:[
'55:44:33:22:11:00',
'00:00:00:ff:ff:ff']},
156 {MATCH_PACKET_REDIRECTION:[]},
157 {RULE:OpEN.OPEN_ACL_PERMIT},
158 {MATCH_REDIRECT_AGENT:[100]},
159 {MATCH_RATE_LIMIT:[4294967295,128]},
160 {MATCH_TIME_BASED:[
'mac-time-range-name']},
161 {MATCH_ETHER_TYPE:[0x809B]},
164 {MATCH_VLAN:[OpEN.OPEN_ACL_VLAN_OPERATOR_RANGE,2,100]},
165 {MATCH_VLAN2:[OpEN.OPEN_ACL_VLAN_OPERATOR_EQUAL_TO,200,0]},
166 {RULE:OpEN.OPEN_ACL_DENY},
171 (OpEN.OPEN_ACL_TYPE_IP,
'test_ip',
'test_ip_renamed'),
172 (OpEN.OPEN_ACL_TYPE_IPV6,
'test_ip6',
'test_ip6_renamed'),
173 (OpEN.OPEN_ACL_TYPE_MAC,
'test_mac',
'test_mac_renamed'),
177 INTERFACE_CREATE_LIST = [
178 {INTF:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 1, OpEN.OPEN_ACL_INBOUND_ACL, 100]},
179 {INTF:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 2, OpEN.OPEN_ACL_INBOUND_ACL, 200]},
180 {INTF:[OpEN.OPEN_ACL_TYPE_IPV6,
'test_ip6_renamed',3, OpEN.OPEN_ACL_INBOUND_ACL, 300]},
181 {INTF:[OpEN.OPEN_ACL_TYPE_MAC,
'test_mac_renamed',4, OpEN.OPEN_ACL_INBOUND_ACL, 400]},
182 {VLAN:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 5, OpEN.OPEN_ACL_INBOUND_ACL, 500]},
183 {VLAN:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 6, OpEN.OPEN_ACL_INBOUND_ACL, 600]},
184 {VLAN:[OpEN.OPEN_ACL_TYPE_IPV6,
'test_ip6_renamed',7, OpEN.OPEN_ACL_INBOUND_ACL, 700]},
185 {VLAN:[OpEN.OPEN_ACL_TYPE_MAC,
'test_mac_renamed',8, OpEN.OPEN_ACL_INBOUND_ACL, 800]},
187 {INTF:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 9, OpEN.OPEN_ACL_INBOUND_ACL, 900]},
191 INTERFACE_DELETE_LIST = [
192 {INTF:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 2, OpEN.OPEN_ACL_INBOUND_ACL]},
193 {VLAN:[OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', 5, OpEN.OPEN_ACL_INBOUND_ACL]},
197 """Convert ipv4 string to integer"""
199 return struct.unpack(
"!I", socket.inet_aton(addr))[0]
202 """Convert ipv4 integer to string"""
204 return socket.inet_ntoa(struct.pack(
"!I", addr))
206 def ipv6_to_int(addr):
207 """Convert ipv6 string to integer"""
209 str_ = socket.inet_pton(socket.AF_INET6, addr)
210 a, b = struct.unpack(
'!2Q', str_)
213 def int_to_ipv6(addr):
214 """Convert ipv6 integer to string"""
217 b = addr & ((1 << 64) - 1)
218 return socket.inet_ntop(socket.AF_INET6, struct.pack(
'!2Q', a, b))
220 def print_sanity_results(result, test, msg, feat):
221 """Print overall comparision results"""
223 if result == OpEN.OPEN_E_UNAVAIL:
224 print (
"Sanity test skipped.")
225 elif result == OpEN.OPEN_E_NONE
and test ==
True:
226 print (
"Sanity Success - %s - %s." % (msg, feat))
228 print (
"Sanity Failure - %s - %s." % (msg, feat))
230 def print_bad_result(result, msg):
231 """Print some general error messages if the result is bad"""
233 if result == OpEN.OPEN_E_UNAVAIL:
234 print (
"Feature not supported - %s (err %d)." % (msg, result))
235 elif result != OpEN.OPEN_E_NONE:
236 print (
"Test Failure - %s (err %d)." % (msg, result))
239 """Simple ACL class implementing basic CRUD examples """
241 def __init__(self, client) :
242 self.m_client = client
244 def create_acl(self, acl_name, acl_type, init=None):
245 """Create an ACL whose type is based on acl_type"""
248 name_string = open_.getStringBuffer(len(acl_name) + 1, acl_name)
249 except OpENBufferSizeError:
250 print(
"create_acl: getStringBuffer raised OpENBufferSizeError")
253 print(
"create_acl: getStringBuffer raised TypeError")
255 name_buff = OpEN.open_buffdesc()
256 name_buff.pstart = name_string
257 name_buff.size = len(acl_name)+1
261 OpEN.openapiAclDeleteByName(self.m_client, acl_type, name_buff)
264 acl_p = OpEN.new_uint32_tp()
265 result = OpEN.openapiAclCreate(self.m_client, acl_type, name_buff, acl_p)
266 print_bad_result(result,
'openapiAclCreate')
268 if result == OpEN.OPEN_E_NONE:
270 acl_id = OpEN.uint32_tp_value(acl_p)
271 tmp_acl_p = OpEN.new_uint32_tp()
272 result = OpEN.openapiAclGet(self.m_client, acl_type, name_buff, tmp_acl_p)
273 print_bad_result(result,
'openapiAclGet')
274 print_sanity_results(result, acl_id==OpEN.uint32_tp_value(tmp_acl_p),
'create_acl', acl_name)
275 OpEN.delete_uint32_tp(tmp_acl_p)
277 OpEN.delete_uint32_tp(acl_p)
279 if result == OpEN.OPEN_E_NONE:
284 def create_rule(self, acl_id, rule_id, action):
285 """Create an action rule which is attached to the given acl_id"""
293 rule_p = OpEN.new_uint32_tp()
294 OpEN.uint32_tp_assign(rule_p, rule_id)
295 result = OpEN.openapiAclRuleActionAdd(self.m_client, acl_id, rule_p, action)
296 print_bad_result(result,
'openapiAclRuleActionAdd')
298 if result == OpEN.OPEN_E_NONE:
300 rule_id = OpEN.uint32_tp_value(rule_p)
301 action_p = OpEN.new_OPEN_ACL_ACTION_tp()
302 result = OpEN.openapiAclRuleActionGet(self.m_client, acl_id, rule_id, action_p)
303 print_bad_result(result,
'openapiAclRuleActionGet')
304 print_sanity_results(result, action==OpEN.OPEN_ACL_ACTION_tp_value(action_p),
'create_rule',
"")
305 OpEN.delete_OPEN_ACL_ACTION_tp(action_p)
307 OpEN.delete_uint32_tp(rule_p)
309 if result == OpEN.OPEN_E_NONE:
314 def create_match(self, acl_id, rule_id, match, conditions):
315 """Add a match-condition to the supplied acl and rule"""
317 if acl_id == 0
or rule_id == 0:
320 if match == MATCH_ASSIGN_QUEUE:
321 val_p = OpEN.new_uint32_tp()
323 if len(conditions) == 1:
328 OpEN.openapiAclMaxAssignQueueGet(self.m_client, val_p)
329 val = OpEN.uint32_tp_value(val_p)
331 result = OpEN.openapiAclRuleMatchAssignQueueAdd(self.m_client, acl_id, rule_id, val)
332 print_bad_result(result,
'openapiAclRuleMatchAssignQueueAdd')
334 if result == OpEN.OPEN_E_NONE:
336 val_p = OpEN.new_uint32_tp()
337 result = OpEN.openapiAclRuleMatchAssignQueueGet(self.m_client, acl_id, rule_id, val_p)
338 print_bad_result(result,
'openapiAclRuleMatchAssignQueueGet')
339 print_sanity_results(result, val==OpEN.uint32_tp_value(val_p),
'create_match', match)
341 OpEN.delete_uint32_tp(val_p)
343 elif match == MATCH_COS:
347 result = OpEN.openapiAclRuleMatchMacCosAdd(self.m_client, acl_id, rule_id, val)
348 print_bad_result(result,
'openapiAclRuleMatchMacCosAdd')
350 if result == OpEN.OPEN_E_NONE:
352 val_p = OpEN.new_uint32_tp()
353 result = OpEN.openapiAclRuleMatchMacCosGet(self.m_client, acl_id, rule_id, val_p)
354 print_bad_result(result,
'openapiAclRuleMatchMacCosGet')
355 print_sanity_results(result, val==OpEN.uint32_tp_value(val_p),
'create_match', match)
356 OpEN.delete_uint32_tp(val_p)
358 elif match == MATCH_COS2:
362 result = OpEN.openapiAclRuleMatchMacCos2Add(self.m_client, acl_id, rule_id, val)
363 print_bad_result(result,
'openapiAclRuleMatchMacCos2Add')
365 if result == OpEN.OPEN_E_NONE:
367 val_p = OpEN.new_uint32_tp()
368 result = OpEN.openapiAclRuleMatchMacCos2Get(self.m_client, acl_id, rule_id, val_p)
369 print_bad_result(result,
'openapiAclRuleMatchMacCos2Get')
370 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
371 OpEN.delete_uint32_tp(val_p)
373 elif match == MATCH_DSCP:
376 result = OpEN.openapiAclRuleMatchDscpAdd(self.m_client, acl_id, rule_id, val)
377 print_bad_result(result,
'openapiAclRuleMatchDscpAdd')
379 if result == OpEN.OPEN_E_NONE:
381 val_p = OpEN.new_uint32_tp()
382 result = OpEN.openapiAclRuleMatchDscpGet(self.m_client, acl_id, rule_id, val_p)
383 print_bad_result(result,
'openapiAclRuleMatchDscpGet')
384 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
385 OpEN.delete_uint32_tp(val_p)
387 elif match == MATCH_ETHER_TYPE:
390 result = OpEN.openapiAclRuleMatchMacEtherTypeAdd(self.m_client, acl_id, rule_id, val)
391 print_bad_result(result,
'openapiAclRuleMatchMacEtherTypeAdd')
393 if result == OpEN.OPEN_E_NONE:
395 val_p = OpEN.new_uint32_tp()
396 result = OpEN.openapiAclRuleMatchMacEtherTypeGet(self.m_client, acl_id, rule_id, val_p)
397 print_bad_result(result,
'openapiAclRuleMatchMacEtherTypeGet')
398 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
399 OpEN.delete_uint32_tp(val_p)
401 elif match == MATCH_FLOW_LABEL:
405 result = OpEN.openapiAclRuleMatchFlowLabelAdd(self.m_client, acl_id, rule_id, val)
406 print_bad_result(result,
'openapiAclRuleMatchFlowLabelAdd')
408 if result == OpEN.OPEN_E_NONE:
410 val_p = OpEN.new_uint32_tp()
411 result = OpEN.openapiAclRuleMatchFlowLabelGet(self.m_client, acl_id, rule_id, val_p)
412 print_bad_result(result,
'openapiAclRuleMatchFlowLabelGet')
413 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
414 OpEN.delete_uint32_tp(val_p)
416 elif match == MATCH_FRAGMENTS:
419 result = OpEN.openapiAclRuleMatchFragmentsAdd(self.m_client, acl_id, rule_id, val)
420 print_bad_result(result,
'openapiAclRuleMatchFragmentsAdd')
422 if result == OpEN.OPEN_E_NONE:
424 val_p = OpEN.new_bool_tp()
425 result = OpEN.openapiAclRuleMatchFragmentsGet(self.m_client, acl_id, rule_id, val_p)
426 print_bad_result(result,
'openapiAclRuleMatchFragmentsGet')
427 print_sanity_results(result, val == OpEN.bool_tp_value(val_p),
'create_match', match)
428 OpEN.delete_bool_tp(val_p)
430 elif match == MATCH_EVERY:
433 result = OpEN.openapiAclRuleMatchEveryAdd(self.m_client, acl_id, rule_id, val)
434 print_bad_result(result,
'openapiAclRuleMatchEveryAdd')
436 if result == OpEN.OPEN_E_NONE:
438 val_p = OpEN.new_bool_tp()
439 result = OpEN.openapiAclRuleMatchEveryGet(self.m_client, acl_id, rule_id, val_p)
440 print_bad_result(result,
'openapiAclRuleMatchEveryGet')
441 print_sanity_results(result, val == OpEN.bool_tp_value(val_p),
'create_match', match)
442 OpEN.delete_bool_tp(val_p)
444 elif match == MATCH_ICMP_TYPE:
445 type_ = conditions[0]
447 bool_ = conditions[2]
449 result = OpEN.openapiAclRuleMatchIcmpTypeCodeAdd(self.m_client, acl_id, rule_id, bool_, type_, code)
450 print_bad_result(result,
'openapiAclRuleMatchIcmpTypeCodeAdd')
452 if result == OpEN.OPEN_E_NONE:
454 type_p = OpEN.new_uint32_tp()
455 code_p = OpEN.new_uint32_tp()
456 result = OpEN.openapiAclRuleMatchIcmpTypeCodeGet(self.m_client, acl_id, rule_id, bool_, type_p, code_p)
457 print_bad_result(result,
'openapiAclRuleMatchIcmpTypeCodeGet')
458 tmp_type = OpEN.uint32_tp_value(type_p)
459 tmp_code = OpEN.uint32_tp_value(code_p)
460 print_sanity_results(result, type_ == tmp_type
and code == tmp_code,
'create_match', match)
461 OpEN.delete_uint32_tp(type_p)
462 OpEN.delete_uint32_tp(code_p)
464 elif match == MATCH_IGMP_TYPE:
465 type_ = conditions[0]
467 result = OpEN.openapiAclRuleMatchIgmpTypeAdd(self.m_client, acl_id, rule_id, type_)
468 print_bad_result(result,
'openapiAclRuleMatchIgmpTypeAdd')
470 if result == OpEN.OPEN_E_NONE:
472 type_p = OpEN.new_uint32_tp()
473 result = OpEN.openapiAclRuleMatchIgmpTypeGet(self.m_client, acl_id, rule_id, type_p)
474 print_bad_result(result,
'openapiAclRuleMatchIgmpTypeGet')
475 tmp_type = OpEN.uint32_tp_value(type_p)
476 print_sanity_results(result, type_ == tmp_type,
'create_match', match)
477 OpEN.delete_uint32_tp(type_p)
479 elif match == MATCH_IP_DST_MASK:
480 dst_addr = OpEN.open_inet_addr_t()
481 dst_addr.addr.ipv4 = socket.ntohl(ip_to_int(conditions[0]))
482 dst_addr.family = socket.AF_INET
484 mask_addr = OpEN.open_inet_addr_t()
485 mask_addr.addr.ipv4 = socket.ntohl(ip_to_int(conditions[1]))
486 mask_addr.family = socket.AF_INET
488 result = OpEN.openapiAclRuleMatchIpDstMaskAdd(self.m_client, acl_id, rule_id, dst_addr, mask_addr)
489 print_bad_result(result,
'openapiAclRuleMatchIpDstMaskAdd')
491 if result == OpEN.OPEN_E_NONE:
493 tmp_dst_addr = OpEN.open_inet_addr_t()
494 tmp_dst_mask = OpEN.open_inet_addr_t()
496 result = OpEN.openapiAclRuleMatchIpDstMaskGet(self.m_client, acl_id, rule_id, tmp_dst_addr, tmp_dst_mask)
497 print_bad_result(result,
'openapiAclRuleMatchIpDstMaskGet')
498 print_sanity_results(result, dst_addr.addr.ipv4 == tmp_dst_addr.addr.ipv4,
'create_match', match)
500 elif match == MATCH_IP_SRC_MASK:
501 src_addr = OpEN.open_inet_addr_t()
502 src_addr.addr.ipv4 = socket.ntohl(ip_to_int(conditions[0]))
503 src_addr.family = socket.AF_INET
505 mask_addr = OpEN.open_inet_addr_t()
506 mask_addr.addr.ipv4 = socket.ntohl(ip_to_int(conditions[1]))
507 mask_addr.family = socket.AF_INET
509 result = OpEN.openapiAclRuleMatchIpSrcMaskAdd(self.m_client, acl_id, rule_id, src_addr, mask_addr)
510 print_bad_result(result,
'openapiAclRuleMatchIpSrcMaskAdd')
512 if result == OpEN.OPEN_E_NONE:
514 tmp_src_addr = OpEN.open_inet_addr_t()
515 tmp_src_mask = OpEN.open_inet_addr_t()
517 result = OpEN.openapiAclRuleMatchIpSrcMaskGet(self.m_client, acl_id, rule_id, tmp_src_addr, tmp_src_mask)
518 print_bad_result(result,
'openapiAclRuleMatchIpSrcMaskGet')
519 print_sanity_results(result, src_addr.addr.ipv4 == tmp_src_addr.addr.ipv4,
'create_match', match)
521 elif match == MATCH_IPV6_DST_PFX:
523 addr = OpEN.open_inet_addr_t()
524 addr.addr.ipv6 = ipv6_to_int(conditions[0])
525 addr.family = socket.AF_INET6
529 result = OpEN.openapiAclRuleMatchIpv6DstPfxAdd(self.m_client, acl_id, rule_id, addr, pfx)
530 print_bad_result(result,
'openapiAclRuleMatchIpv6DstPfxAdd')
532 if result == OpEN.OPEN_E_NONE:
534 tmp_addr = OpEN.open_inet_addr_t()
535 tmp_pfx_p = OpEN.new_uint32_tp()
537 result = OpEN.openapiAclRuleMatchIpv6DstPfxGet(self.m_client, acl_id, rule_id, tmp_addr, tmp_pfx_p)
538 print_bad_result(result,
'openapiAclRuleMatchIpv6DstPfxGet')
539 print_sanity_results(result, addr.addr.ipv6 == tmp_addr.addr.ipv6,
'create_match', match)
540 OpEN.delete_uint32_tp(tmp_pfx_p)
542 elif match == MATCH_IPV6_SRC_PFX:
544 addr = OpEN.open_inet_addr_t()
545 addr.addr.ipv6 = ipv6_to_int(conditions[0])
546 addr.family = socket.AF_INET6
550 result = OpEN.openapiAclRuleMatchIpv6SrcPfxAdd(self.m_client, acl_id, rule_id, dst_addr, pfx)
551 print_bad_result(result,
'openapiAclRuleMatchIpv6SrcPfxAdd')
553 if result == OpEN.OPEN_E_NONE:
555 tmp_addr = OpEN.open_inet_addr_t()
556 tmp_pfx_p = OpEN.new_uint32_tp()
558 result = OpEN.openapiAclRuleMatchIpv6SrcPfxGet(self.m_client, acl_id, rule_id, tmp_addr, tmp_pfx_p)
559 print_bad_result(result,
'openapiAclRuleMatchIpv6SrcPfxGet')
560 print_sanity_results(result, addr.addr.ipv6 == tmp_addr.addr.ipv6,
'create_match', match)
561 OpEN.delete_uint32_tp(tmp_pfx_p)
563 elif match == MATCH_L4_DST_PORT:
565 start = conditions[1]
568 result = OpEN.openapiAclRuleMatchL4DstPortAdd(self.m_client, acl_id, rule_id, oper, start, end)
569 print_bad_result(result,
'openapiAclRuleMatchL4DstPortAdd')
571 if result == OpEN.OPEN_E_NONE:
573 oper_p = OpEN.new_OPEN_ACL_L4_PORT_OPERATOR_tp()
574 start_p = OpEN.new_uint32_tp()
575 end_p = OpEN.new_uint32_tp()
576 result = OpEN.openapiAclRuleMatchL4DstPortGet(self.m_client, acl_id, rule_id, oper_p, start_p, end_p)
577 print_bad_result(result,
'openapiAclRuleMatchL4DstPortGet')
578 print_sanity_results(result, oper == OpEN.OPEN_ACL_L4_PORT_OPERATOR_tp_value(oper_p)
and start == OpEN.uint32_tp_value(start_p),
'create_match', match)
579 OpEN.delete_OPEN_ACL_L4_PORT_OPERATOR_tp(oper_p)
580 OpEN.delete_uint32_tp(start_p)
581 OpEN.delete_uint32_tp(end_p)
583 elif match == MATCH_L4_SRC_PORT:
585 start = conditions[1]
588 result = OpEN.openapiAclRuleMatchL4SrcPortAdd(self.m_client, acl_id, rule_id, oper, start, end)
589 print_bad_result(result,
'openapiAclRuleMatchL4SrcPortAdd')
591 if result == OpEN.OPEN_E_NONE:
593 oper_p = OpEN.new_OPEN_ACL_L4_PORT_OPERATOR_tp()
594 start_p = OpEN.new_uint32_tp()
595 end_p = OpEN.new_uint32_tp()
596 result = OpEN.openapiAclRuleMatchL4SrcPortGet(self.m_client, acl_id, rule_id, oper_p, start_p, end_p)
597 print_bad_result(result,
'openapiAclRuleMatchL4SrcPortGet')
598 print_sanity_results(result, oper == OpEN.OPEN_ACL_L4_PORT_OPERATOR_tp_value(oper_p)
and start == OpEN.uint32_tp_value(start_p),
'create_match', match)
599 OpEN.delete_OPEN_ACL_L4_PORT_OPERATOR_tp(oper_p)
600 OpEN.delete_uint32_tp(start_p)
601 OpEN.delete_uint32_tp(end_p)
603 elif match == MATCH_LOGGING:
606 result = OpEN.openapiAclRuleMatchLoggingAdd(self.m_client, acl_id, rule_id, val)
607 print_bad_result(result,
'openapiAclRuleMatchLoggingAdd')
609 if result == OpEN.OPEN_E_NONE:
611 val_p = OpEN.new_uint32_tp()
612 result = OpEN.openapiAclRuleMatchLoggingGet(self.m_client, acl_id, rule_id, val_p)
613 print_bad_result(result,
'openapiAclRuleMatchLoggingGet')
614 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
615 OpEN.delete_uint32_tp(val_p)
617 elif match == MATCH_MAC_DST_MASK:
623 mac_array = open_.getStringBuffer(len(mac) + 1, mac)
624 except OpENBufferSizeError:
625 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
628 print(
"create_match: getStringBuffer raised TypeError")
630 mac_buff = OpEN.open_buffdesc()
631 mac_buff.pstart = mac_array
632 mac_buff.size = len(mac)+1
635 mask_array = open_.getStringBuffer(len(mask) + 1, mask)
636 except OpENBufferSizeError:
637 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
640 print(
"create_match: getStringBuffer raised TypeError")
642 mask_buff = OpEN.open_buffdesc()
643 mask_buff.pstart = mask_array
644 mask_buff.size = len(mask)+1
646 result = OpEN.openapiAclRuleMatchMacDstMacAdd(self.m_client, acl_id, rule_id, mac_buff, mask_buff)
647 print_bad_result(result,
'openapiAclRuleMatchMacDstMacAdd')
649 if result == OpEN.OPEN_E_NONE:
651 max_len = OpEN.OPENAPI_L7_MAC_ADDR_STRING_LEN + 1
654 tmp_mac_buff_string = open_.getStringBuffer(max_len)
655 except OpENBufferSizeError:
656 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
659 print(
"create_match: getStringBuffer raised TypeError")
661 tmpmac_buff = OpEN.open_buffdesc()
662 tmpmac_buff.pstart = tmp_mac_buff_string
663 tmpmac_buff.size = max_len
666 tmp_mask_buff_string = open_.getStringBuffer(max_len)
667 except OpENBufferSizeError:
668 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
671 print(
"create_match: getStringBuffer raised TypeError")
673 tmp_mask_buff = OpEN.open_buffdesc()
674 tmp_mask_buff.pstart = tmp_mask_buff_string
675 tmp_mask_buff.size = max_len
677 result = OpEN.openapiAclRuleMatchMacDstMacGet(self.m_client, acl_id, rule_id, tmpmac_buff, tmp_mask_buff)
678 print_bad_result(result,
'openapiAclRuleMatchMacDstMacGet')
679 tmp_mac = tmp_mac_buff_string.cast()
680 tmp_mask = tmp_mask_buff_string.cast()
681 print_sanity_results(result, mac == tmp_mac
and mask == tmp_mask,
'create_match', match)
683 elif match == MATCH_MAC_SRC_MASK:
689 mac_array = open_.getStringBuffer(len(mac) + 1, mac)
690 except OpENBufferSizeError:
691 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
694 print(
"create_match: getStringBuffer raised TypeError")
696 mac_buff = OpEN.open_buffdesc()
697 mac_buff.pstart = mac_array
698 mac_buff.size = len(mac)+1
701 mask_array = open_.getStringBuffer(len(mask) + 1, mask)
702 except OpENBufferSizeError:
703 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
706 print(
"create_match: getStringBuffer raised TypeError")
709 mask_buff = OpEN.open_buffdesc()
710 mask_buff.pstart = mask_array
711 mask_buff.size = len(mask)+1
713 result = OpEN.openapiAclRuleMatchMacSrcMacAdd(self.m_client, acl_id, rule_id, mac_buff, mask_buff)
714 print_bad_result(result,
'openapiAclRuleMatchMacSrcMacAdd')
716 if result == OpEN.OPEN_E_NONE:
718 max_len = OpEN.OPENAPI_L7_MAC_ADDR_STRING_LEN + 1
721 tmp_mac_buff_string = open_.getStringBuffer(max_len)
722 except OpENBufferSizeError:
723 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
726 print(
"create_match: getStringBuffer raised TypeError")
728 tmpmac_buff = OpEN.open_buffdesc()
729 tmpmac_buff.pstart = tmp_mac_buff_string
730 tmpmac_buff.size = max_len
733 tmp_mask_buff_string = open_.getStringBuffer(max_len)
734 except OpENBufferSizeError:
735 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
738 print(
"create_match: getStringBuffer raised TypeError")
740 tmp_mask_buff = OpEN.open_buffdesc()
741 tmp_mask_buff.pstart = tmp_mask_buff_string
742 tmp_mask_buff.size = max_len
744 result = OpEN.openapiAclRuleMatchMacSrcMacGet(self.m_client, acl_id, rule_id, tmpmac_buff, tmp_mask_buff)
745 print_bad_result(result,
'openapiAclRuleMatchMacSrcMacGet')
746 tmp_mac = tmp_mac_buff_string.cast()
747 tmp_mask = tmp_mask_buff_string.cast()
748 print_sanity_results(result, mac == tmp_mac
and mask == tmp_mask,
'create_match', match)
750 elif match == MATCH_PACKET_MIRRORING:
751 if len(conditions) == 1:
756 val_p = OpEN.new_uint32_tp()
757 OpEN.openapiIfFirstGet(self.m_client, OpEN.OPEN_INTF_TYPE_PHY, val_p)
758 val = OpEN.uint32_tp_value(val_p)
759 OpEN.delete_uint32_tp(val_p)
761 result = OpEN.openapiAclRuleMatchMirrorAdd(self.m_client, acl_id, rule_id, val)
762 print_bad_result(result,
'openapiAclRuleMatchMirrorAdd')
764 if result == OpEN.OPEN_E_NONE:
766 val_p = OpEN.new_uint32_tp()
767 result = OpEN.openapiAclRuleMatchMirrorGet(self.m_client, acl_id, rule_id, val_p)
768 print_bad_result(result,
'openapiAclRuleMatchMirrorGet')
769 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
770 OpEN.delete_uint32_tp(val_p)
772 elif match == MATCH_PACKET_REDIRECTION:
774 if len(conditions) == 1:
779 val_p = OpEN.new_uint32_tp()
780 OpEN.openapiIfFirstGet(self.m_client, OpEN.OPEN_INTF_TYPE_PHY, val_p)
781 val = OpEN.uint32_tp_value(val_p)
782 OpEN.delete_uint32_tp(val_p)
784 result = OpEN.openapiAclRuleMatchRedirectAdd(self.m_client, acl_id, rule_id, val)
785 print_bad_result(result,
'openapiAclRuleMatchRedirectAdd')
787 if result == OpEN.OPEN_E_NONE:
789 val_p = OpEN.new_uint32_tp()
790 result = OpEN.openapiAclRuleMatchRedirectGet(self.m_client, acl_id, rule_id, val_p)
791 print_bad_result(result,
'openapiAclRuleMatchRedirectGet')
792 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
793 OpEN.delete_uint32_tp(val_p)
795 elif match == MATCH_PRECEDENCE:
798 result = OpEN.openapiAclRuleMatchPrecedenceAdd(self.m_client, acl_id, rule_id, val)
799 print_bad_result(result,
'openapiAclRuleMatchPrecedenceAdd')
801 if result == OpEN.OPEN_E_NONE:
803 val_p = OpEN.new_uint32_tp()
804 result = OpEN.openapiAclRuleMatchPrecedenceGet(self.m_client, acl_id, rule_id, val_p)
805 print_bad_result(result,
'openapiAclRuleMatchPrecedenceGet')
806 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
807 OpEN.delete_uint32_tp(val_p)
809 elif match == MATCH_PROTOCOL:
812 result = OpEN.openapiAclRuleMatchProtocolAdd(self.m_client, acl_id, rule_id, val)
813 print_bad_result(result,
'openapiAclRuleMatchProtocolAdd')
815 if result == OpEN.OPEN_E_NONE:
817 val_p = OpEN.new_uint32_tp()
818 result = OpEN.openapiAclRuleMatchProtocolGet(self.m_client, acl_id, rule_id, val_p)
819 print_bad_result(result,
'openapiAclRuleMatchProtocolGet')
820 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
821 OpEN.delete_uint32_tp(val_p)
823 elif match == MATCH_RATE_LIMIT:
827 result = OpEN.openapiAclRuleMatchRateLimitAdd(self.m_client, acl_id, rule_id, val1, val2)
828 print_bad_result(result,
'openapiAclRuleMatchRateLimitAdd')
830 if result == OpEN.OPEN_E_NONE:
832 val1_p = OpEN.new_uint32_tp()
833 val2_p = OpEN.new_uint32_tp()
834 result = OpEN.openapiAclRuleMatchRateLimitGet(self.m_client, acl_id, rule_id, val1_p, val2_p)
835 print_bad_result(result,
'openapiAclRuleMatchRateLimitGet')
836 print_sanity_results(result, val1 == OpEN.uint32_tp_value(val1_p)
and val2 == OpEN.uint32_tp_value(val2_p),
'create_match', match)
837 OpEN.delete_uint32_tp(val1_p)
838 OpEN.delete_uint32_tp(val2_p)
840 elif match == MATCH_REDIRECT_AGENT:
843 result = OpEN.openapiAclRuleMatchRedirectAgentAdd(self.m_client, acl_id, rule_id, val)
844 print_bad_result(result,
'openapiAclRuleMatchRedirectAgentAdd')
846 if result == OpEN.OPEN_E_NONE:
848 val_p = OpEN.new_uint32_tp()
849 result = OpEN.openapiAclRuleMatchRedirectAgentGet(self.m_client, acl_id, rule_id, val_p)
850 print_bad_result(result,
'openapiAclRuleMatchRedirectAgentGet')
851 print_sanity_results(result, val == OpEN.uint32_tp_value(val_p),
'create_match', match)
852 OpEN.delete_uint32_tp(val_p)
854 elif match == MATCH_ROUTING_FLAG:
858 result = OpEN.openapiAclRuleMatchRoutingAdd(self.m_client, acl_id, rule_id, val)
859 print_bad_result(result,
'openapiAclRuleMatchRoutingAdd')
861 if result == OpEN.OPEN_E_NONE:
863 val_p = OpEN.new_bool_tp()
864 result = OpEN.openapiAclRuleMatchRoutingGet(self.m_client, acl_id, rule_id, val_p)
865 print_bad_result(result,
'openapiAclRuleMatchRoutingGet')
866 print_sanity_results(result, val == OpEN.bool_tp_value(val_p),
'create_match', match)
867 OpEN.delete_bool_tp(val_p)
869 elif match == MATCH_TCP_FLAGS:
873 if version_info >= (3,0,0):
874 for idx
in range(0, len(conditions)) :
875 flag_val |= (
True << conditions[idx])
876 flag_mask |= (
True << conditions[idx])
878 for idx
in xrange(0, len(conditions)) :
879 flag_val |= (
True << conditions[idx])
880 flag_mask |= (
True << conditions[idx])
882 result = OpEN.openapiAclRuleMatchTcpFlagsAdd(self.m_client, acl_id, rule_id, flag_val, flag_mask)
883 print_bad_result(result,
'openapiAclRuleMatchTcpFlagsAdd')
885 if result == OpEN.OPEN_E_NONE:
887 flag_val_p = OpEN.new_uint32_tp()
888 flag_mask_p = OpEN.new_uint32_tp()
889 result = OpEN.openapiAclRuleMatchTcpFlagsGet(self.m_client, acl_id, rule_id, flag_val_p, flag_mask_p)
890 print_bad_result(result,
'openapiAclRuleMatchTcpFlagsGet')
891 print_sanity_results(result, flag_val == OpEN.uint32_tp_value(flag_val_p),
'create_match', match)
892 OpEN.delete_uint32_tp(flag_val_p)
893 OpEN.delete_uint32_tp(flag_mask_p)
895 elif match == MATCH_TIME_BASED:
896 time_name = conditions[0]
899 name_array = open_.getStringBuffer(len(time_name) + 1, time_name)
900 except OpENBufferSizeError:
901 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
904 print(
"create_match: getStringBuffer raised TypeError")
906 name_buff = OpEN.open_buffdesc()
907 name_buff.pstart = name_array
908 name_buff.size = len(time_name)+1
910 result = OpEN.openapiAclRuleMatchTimeRangeAdd(self.m_client, acl_id, rule_id, name_buff)
911 print_bad_result(result,
'openapiAclRuleMatchTimeRangeAdd')
913 if result == OpEN.OPEN_E_NONE:
915 max_len = OpEN.OPENAPI_TIME_RANGE_NAME_LEN_MAX + 1
918 tmp_name_string = open_.getStringBuffer(max_len)
919 except OpENBufferSizeError:
920 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
923 print(
"create_match: getStringBuffer raised TypeError")
925 tmp_name_buff = OpEN.open_buffdesc()
926 tmp_name_buff.pstart = tmp_name_string
927 tmp_name_buff.size = max_len
929 result = OpEN.openapiAclRuleMatchTimeRangeGet(self.m_client, acl_id, rule_id, tmp_name_buff)
930 print_bad_result(result,
'openapiAclRuleMatchTimeRangeGet')
931 tmp_time_name = tmp_name_string.cast()
932 print_sanity_results(result, time_name == tmp_time_name,
'create_match', match)
934 if result == OpEN.OPEN_E_NONE:
935 status_p = OpEN.new_OPEN_ACL_RULE_STATUS_tp()
936 result = OpEN.openapiAclRuleMatchTimeRangeStatusGet(self.m_client, acl_id, rule_id, status_p)
937 print_bad_result(result,
'openapiAclRuleMatchTimeRangeStatusGet')
938 print_sanity_results(result,
True,
'create_match', match+
' status')
939 OpEN.delete_OPEN_ACL_RULE_STATUS_tp(status_p)
941 elif match == MATCH_TOS:
942 tos_val = conditions[0]
943 tos_mask = conditions[1]
946 tos_val_array = open_.getStringBuffer(len(tos_val) + 1, tos_val)
947 except OpENBufferSizeError:
948 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
951 print(
"create_match: getStringBuffer raised TypeError")
953 tos_val_buff = OpEN.open_buffdesc()
954 tos_val_buff.pstart = tos_val_array
955 tos_val_buff.size = len(tos_val) + 1
958 tos_mask_array = open_.getStringBuffer(len(tos_mask) + 1, tos_mask)
959 except OpENBufferSizeError:
960 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
963 print(
"create_match: getStringBuffer raised TypeError")
965 tos_mask_buff = OpEN.open_buffdesc()
966 tos_mask_buff.pstart = tos_mask_array
967 tos_mask_buff.size = len(tos_mask) + 1
969 result = OpEN.openapiAclRuleMatchTosAdd(self.m_client, acl_id, rule_id, tos_val_buff, tos_mask_buff)
970 print_bad_result(result,
'openapiAclRuleMatchTosAdd')
972 if result == OpEN.OPEN_E_NONE:
977 tmp_tos_buffstring = open_.getStringBuffer(max_len)
978 except OpENBufferSizeError:
979 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
982 print(
"create_match: getStringBuffer raised TypeError")
984 tmp_tos_buff = OpEN.open_buffdesc()
985 tmp_tos_buff.pstart = tmp_tos_buffstring
986 tmp_tos_buff.size = max_len
989 tmp_mask_buff_string = open_.getStringBuffer(max_len)
990 except OpENBufferSizeError:
991 print(
"create_match: getStringBuffer raised OpENBufferSizeError")
994 print(
"create_match: getStringBuffer raised TypeError")
996 tmp_mask_buff = OpEN.open_buffdesc()
997 tmp_mask_buff.pstart = tmp_mask_buff_string
998 tmp_mask_buff.size = max_len
1000 result = OpEN.openapiAclRuleMatchTosGet(self.m_client, acl_id, rule_id, tmp_tos_buff, tmp_mask_buff)
1001 print_bad_result(result,
'openapiAclRuleMatchTosGet')
1002 tmp_tos_val = tmp_tos_buffstring.cast()
1003 tmp_tos_mask = tmp_mask_buff_string.cast()
1004 print_sanity_results(result, tos_val == tmp_tos_val
and tos_mask == tmp_tos_mask,
'create_match', match)
1006 elif match == MATCH_VLAN:
1008 oper = conditions[0]
1009 start = conditions[1]
1012 result = OpEN.openapiAclRuleMatchMacVlanAdd(self.m_client, acl_id, rule_id, oper, start, end)
1013 print_bad_result(result,
'openapiAclRuleMatchMacVlanAdd')
1015 if result == OpEN.OPEN_E_NONE:
1017 oper_p = OpEN.new_OPEN_ACL_VLAN_OPERATOR_tp()
1018 start_p = OpEN.new_uint32_tp()
1019 end_p = OpEN.new_uint32_tp()
1020 result = OpEN.openapiAclRuleMatchMacVlanGet(self.m_client, acl_id, rule_id, oper_p, start_p, end_p)
1021 print_bad_result(result,
'openapiAclRuleMatchMacVlanGet')
1022 print_sanity_results(result, oper == OpEN.OPEN_ACL_L4_PORT_OPERATOR_tp_value(oper_p)
and start == OpEN.uint32_tp_value(start_p),
'create_match', match)
1023 OpEN.delete_OPEN_ACL_VLAN_OPERATOR_tp(oper_p)
1024 OpEN.delete_uint32_tp(start_p)
1025 OpEN.delete_uint32_tp(end_p)
1027 elif match == MATCH_VLAN2:
1029 oper = conditions[0]
1030 start = conditions[1]
1033 result = OpEN.openapiAclRuleMatchMacSecondaryVlanAdd(self.m_client, acl_id, rule_id, oper, start, end)
1034 print_bad_result(result,
'openapiAclRuleMatchMacSecondaryVlanAdd')
1036 if result == OpEN.OPEN_E_NONE:
1038 oper_p = OpEN.new_OPEN_ACL_VLAN_OPERATOR_tp()
1039 start_p = OpEN.new_uint32_tp()
1040 end_p = OpEN.new_uint32_tp()
1041 result = OpEN.openapiAclRuleMatchMacSecondaryVlanGet(self.m_client, acl_id, rule_id, oper_p, start_p, end_p)
1042 print_bad_result(result,
'openapiAclRuleMatchMacSecondaryVlanGet')
1043 print_sanity_results(result, oper == OpEN.OPEN_ACL_L4_PORT_OPERATOR_tp_value(oper_p)
and start == OpEN.uint32_tp_value(start_p),
'create_match', match)
1044 OpEN.delete_OPEN_ACL_VLAN_OPERATOR_tp(oper_p)
1045 OpEN.delete_uint32_tp(start_p)
1046 OpEN.delete_uint32_tp(end_p)
1048 def test_acl_creation(self, acls):
1049 """Parse through the acls list and call acl functions based on keys"""
1054 for key, val
in acl.items():
1056 acl_id = self.create_acl(val[0], val[1],
True)
1058 rule_id = self.create_rule(acl_id, rule_id, val)
1060 self.create_match(acl_id, rule_id, key, val)
1062 def test_acl_retrieval(self):
1063 """Perform some generic ACL retrieval and iteration tests."""
1064 acl_p = OpEN.new_uint32_tp()
1065 acl_type = OpEN.OPEN_ACL_TYPE_IP
1068 result = OpEN.openapiAclGetFirst(self.m_client, acl_type, acl_p)
1069 print_bad_result(result,
"openapiAclGetFirst - IP ACL")
1070 print_sanity_results(result, (OpEN.uint32_tp_value(acl_p)>0),
"openapiAclGetFirst",
"IP ACL")
1073 tmp_acl = self.create_acl(
"another_test_ip", acl_type,
True)
1078 while OpEN.openapiAclGetNext(self.m_client, acl_type, tmp_acl, acl_p) == OpEN.OPEN_E_NONE:
1079 tmp_acl = OpEN.uint32_tp_value(acl_p)
1080 print_sanity_results(OpEN.OPEN_E_NONE, (tmp_acl>0),
"openapiAclGetNext",
"temporary")
1084 result = OpEN.openapiAclDelete(self.m_client, tmp_acl)
1085 print_sanity_results(result,
True,
"openapiAclDelete",
"temporary")
1087 OpEN.delete_uint32_tp(acl_p)
1089 def test_acl_rename(self, acls):
1090 """Rename an ACL and verify."""
1097 acl_p = OpEN.new_uint32_tp()
1100 name_string = open_.getStringBuffer(len(name) + 1, name)
1101 except OpENBufferSizeError:
1102 print(
"test_acl_rename: getStringBuffer raised OpENBufferSizeError")
1105 print(
"test_acl_rename: getStringBuffer raised TypeError")
1107 name_buff = OpEN.open_buffdesc()
1108 name_buff.pstart = name_string
1109 name_buff.size = len(name)+1
1112 name_get_string = open_.getStringBuffer(OpEN.OPENAPI_ACL_NAME_LEN_MAX + 1)
1113 except OpENBufferSizeError:
1114 print(
"test_acl_rename: getStringBuffer raised OpENBufferSizeError")
1117 print(
"test_acl_rename: getStringBuffer raised TypeError")
1119 name_get_buff = OpEN.open_buffdesc()
1120 name_get_buff.pstart = name_get_string
1121 name_get_buff.size = OpEN.OPENAPI_ACL_NAME_LEN_MAX + 1
1124 new_name_string = open_.getStringBuffer(len(new_name) + 1, new_name)
1125 except OpENBufferSizeError:
1126 print(
"test_acl_rename: getStringBuffer raised OpENBufferSizeError")
1129 print(
"test_acl_rename: getStringBuffer raised TypeError")
1131 newname_buff = OpEN.open_buffdesc()
1132 newname_buff.pstart = new_name_string
1133 newname_buff.size = len(new_name)+1
1135 result = OpEN.openapiAclGet(self.m_client, acl_type, name_buff, acl_p)
1136 tmp_acl = OpEN.uint32_tp_value(acl_p)
1137 print_bad_result(result,
"openapiAclGet - IP ACL")
1139 if (result == OpEN.OPEN_E_NONE):
1140 result = OpEN.openapiAclNameGet(self.m_client, tmp_acl, name_get_buff)
1141 print_bad_result(result,
"openapiAclNameGet - IP ACL")
1143 if (result == OpEN.OPEN_E_NONE):
1144 result = OpEN.openapiAclRename(self.m_client, tmp_acl, newname_buff)
1145 print_bad_result(result,
"openapiAclRename - IP ACL")
1146 print_sanity_results(result, (tmp_acl>0),
"openapiAclRename", new_name_string.cast())
1148 OpEN.delete_uint32_tp(acl_p)
1150 def test_acl_traffic_filter_create(self, interfaces):
1151 """Parse through the interfaces list and call traffic filter functions based on keys"""
1153 for interface
in interfaces:
1154 for key, val
in interface.items():
1155 acl_p = OpEN.new_uint32_tp()
1164 name_string = open_.getStringBuffer(len(name) + 1, name)
1165 except OpENBufferSizeError:
1166 print(
"test_acl_traffic_filter_create: getStringBuffer raised OpENBufferSizeError")
1169 print(
"test_acl_traffic_filter_create: getStringBuffer raised TypeError")
1171 name_buff = OpEN.open_buffdesc()
1172 name_buff.pstart = name_string
1173 name_buff.size = len(name)+1
1175 result = OpEN.openapiAclGet(self.m_client, type_, name_buff, acl_p)
1176 print_bad_result(result,
"openapiAclGet - IP ACL")
1178 if result == OpEN.OPEN_E_NONE:
1179 acl = OpEN.uint32_tp_value(acl_p)
1181 result = OpEN.openapiAclIntfDirAdd(self.m_client, intf, dir_, acl, seq)
1182 disp =
"ACL:%s INTF:%d dir:%d seq:%d" % (name_string.cast(), intf, dir_, seq)
1183 print_sanity_results(result,
True,
"openapiAclIntfDirAdd", disp)
1185 result = OpEN.openapiAclVlanDirAdd(self.m_client, intf, dir_, acl, seq)
1186 disp =
"ACL:%s VLAN:%d dir:%d seq:%d" % (name_string.cast(), intf, dir_, seq)
1187 print_sanity_results(result,
True,
"openapiAclVlanDirAdd", disp)
1189 OpEN.delete_uint32_tp(acl_p)
1191 def test_acl_traffic_filter_delete(self, interfaces):
1192 """Parse through the interfaces list and call traffic filter functions based on keys"""
1194 for interface
in interfaces:
1195 for key, val
in interface.items():
1196 acl_p = OpEN.new_uint32_tp()
1204 name_string = open_.getStringBuffer(len(name) + 1, name)
1205 except OpENBufferSizeError:
1206 print(
"test_acl_traffic_filter_create: getStringBuffer raised OpENBufferSizeError")
1209 print(
"test_acl_traffic_filter_create: getStringBuffer raised TypeError")
1211 name_buff = OpEN.open_buffdesc()
1212 name_buff.pstart = name_string
1213 name_buff.size = len(name)+1
1215 result = OpEN.openapiAclGet(self.m_client, type_, name_buff, acl_p)
1216 print_bad_result(result,
"openapiAclGet - IP ACL")
1218 if result == OpEN.OPEN_E_NONE:
1219 acl = OpEN.uint32_tp_value(acl_p)
1221 result = OpEN.openapiAclIntfDirDelete(self.m_client, intf, dir_, acl)
1222 disp =
"ACL:%s INTF:%d dir:%d" % (name_string.cast(), intf, dir_)
1223 print_sanity_results(result,
True,
"openapiAclIntfDirDelete", disp)
1225 result = OpEN.openapiAclVlanDirDelete(self.m_client, intf, dir_, acl)
1226 disp =
"ACL:%s VLAN:%d dir:%d" % (name_string.cast(), intf, dir_)
1227 print_sanity_results(result,
True,
"openapiAclVlanDirDelete", disp)
1229 OpEN.delete_uint32_tp(acl_p)
1231 def test_acl_route_filter(self, acl_type, name):
1232 """Apply an ACL as a route filter."""
1235 name_string = open_.getStringBuffer(len(name) + 1, name)
1236 except OpENBufferSizeError:
1237 print(
"test_acl_route_filter: getStringBuffer raised OpENBufferSizeError")
1240 print(
"test_acl_route_filter: getStringBuffer raised TypeError")
1242 name_buff = OpEN.open_buffdesc()
1243 name_buff.pstart = name_string
1244 name_buff.size = len(name)+1
1246 acl_p = OpEN.new_uint32_tp()
1248 result = OpEN.openapiAclGet(self.m_client, acl_type, name_buff, acl_p)
1249 print_bad_result(result,
"openapiAclGet - IP ACL")
1251 if result == OpEN.OPEN_E_NONE:
1252 acl = OpEN.uint32_tp_value(acl_p)
1253 action_p = OpEN.new_OPEN_ACL_ACTION_tp()
1254 action_p = OpEN.copy_OPEN_ACL_ACTION_tp(OpEN.OPEN_ACL_DENY)
1256 routePrefix = socket.ntohl(ip_to_int(
'10.10.10.1'))
1257 routeMask = socket.ntohl(ip_to_int(
'255.0.0.0'))
1259 result = OpEN.openapiAclRouteFilter(self.m_client, acl, routePrefix, routeMask, action_p);
1260 print_sanity_results(result, OpEN.OPEN_ACL_PERMIT == OpEN.OPEN_ACL_ACTION_tp_value(action_p),
"openapiAclRouteFilter",
"permit")
1262 OpEN.delete_uint32_tp(acl_p)
1263 OpEN.delete_OPEN_ACL_ACTION_tp(action_p)
1265 def show_interface_summary(self, dir_):
1266 """Iterate and display interfaces that are inuse with matching direction"""
1268 print (
"\nACL interface direction assignments")
1269 print (
"Interface Direction")
1270 print (
"--------- ---------")
1273 intf_p = OpEN.new_uint32_tp()
1274 dir_p = OpEN.new_OPEN_ACL_DIRECTION_tp()
1275 inuse_p = OpEN.new_OPEN_CONTROL_tp()
1277 while OpEN.openapiAclIntfDirGetNext(self.m_client, intf, dir_, intf_p, dir_p) == OpEN.OPEN_E_NONE:
1279 if OpEN.openapiAclIsIntfInUse(self.m_client, intf, dir_, inuse_p) == OpEN.OPEN_E_NONE:
1280 if OpEN.OPEN_CONTROL_tp_value(inuse_p) == OpEN.OPEN_ENABLE:
1281 print (
"%9d " % (intf,
'Inbound' if dir_ == OpEN.OPEN_ACL_INBOUND_ACL
else 'Outbound'))
1282 dir_ = OpEN.OPEN_ACL_DIRECTION_tp_value(dir_p)
1283 intf = OpEN.uint32_tp_value(intf_p)
1285 OpEN.delete_uint32_tp(intf_p)
1286 OpEN.delete_OPEN_ACL_DIRECTION_tp(dir_p)
1287 OpEN.delete_OPEN_CONTROL_tp(inuse_p)
1289 def show_interface_details(self, type_, intf, dir_):
1290 """Retrieve a list of ACLs for the given interface and direction and display its contents"""
1293 list_info = OpEN.OPEN_ACL_VLAN_DIR_LIST_t()
1294 result = OpEN.openapiAclVlanDirListGet(self.m_client, intf, dir_, list_info)
1295 print_bad_result(result,
"openapiAclVlanDirListGet")
1296 print (
"\nACL VLAN %d, %s details" % (intf,
'Inbound' if dir_ == OpEN.OPEN_ACL_INBOUND_ACL
else 'Outbound'))
1297 print (
"ACL id Type Seq Num")
1298 print (
"------ ---- -------")
1299 for idx
in range(list_info.count):
1300 info = OpEN.OPEN_ACL_VLAN_LIST_INFO_tArray_getitem(list_info.listEntry, idx)
1301 print (
"%6d %4d %7d" % (info.aclId, info.aclType, info.seqNum))
1303 list_info = OpEN.OPEN_ACL_INTF_DIR_LIST_t()
1304 result = OpEN.openapiAclIntfDirListGet(self.m_client, intf, dir_, list_info)
1305 print_bad_result(result,
"openapiAclIntfDirListGet")
1306 print (
"\nACL Interface %d, %s details" % (intf,
'Inbound' if dir_ == OpEN.OPEN_ACL_INBOUND_ACL
else 'Outbound'))
1307 print (
"ACL id Type Seq Num")
1308 print (
"------ ---- -------")
1309 for idx
in range(list_info.count):
1310 info = OpEN.OPEN_ACL_INTF_LIST_INFO_tArray_getitem(list_info.listEntry, idx)
1311 print (
"%6d %4d %7d" % (info.aclId, info.aclType, info.seqNum))
1313 def show_acl_details(self, interface_type, acl_type, name, dir_):
1314 """Retrieve a list of ACLs for the given acl name and direction and display its contents"""
1317 name_string = open_.getStringBuffer(len(name) + 1, name)
1318 except OpENBufferSizeError:
1319 print(
"show_acl_details: getStringBuffer raised OpENBufferSizeError")
1322 print(
"show_acl_details: getStringBuffer raised TypeError")
1324 name_buff = OpEN.open_buffdesc()
1325 name_buff.pstart = name_string
1326 name_buff.size = len(name)+1
1328 acl_p = OpEN.new_uint32_tp()
1330 result = OpEN.openapiAclGet(self.m_client, acl_type, name_buff, acl_p)
1331 acl = OpEN.uint32_tp_value(acl_p)
1332 print_bad_result(result,
"openapiAclGet - IP ACL")
1334 if interface_type == VLAN:
1335 list_info = OpEN.OPEN_ACL_ASSIGNED_VLAN_LIST_t()
1336 result = OpEN.openapiAclAssignedVlanDirListGet(self.m_client, acl, dir_, list_info)
1337 print_bad_result(result,
"openapiAclAssignedVlanDirListGet")
1338 print (
"\nACL %s, %s VLANs" % (name_string.cast(),
'Inbound' if dir_ == OpEN.OPEN_ACL_INBOUND_ACL
else 'Outbound'))
1339 if result == OpEN.OPEN_E_NONE:
1342 for idx
in range(list_info.count):
1343 print (
"%d" % (OpEN.uint32_tArray_getitem(list_info.vlan, idx)))
1345 list_info = OpEN.OPEN_ACL_ASSIGNED_INTF_LIST_t()
1346 result = OpEN.openapiAclAssignedIntfDirListGet(self.m_client, acl, dir_, list_info)
1347 print_bad_result(result,
"openapiAclAssignedIntfDirListGet")
1348 print '\nACL %s, %s Interfaces' % (name_string.cast(),
'Inbound' if dir_ == OpEN.OPEN_ACL_INBOUND_ACL
else 'Outbound')
1349 if result == OpEN.OPEN_E_NONE:
1352 for idx
in range(list_info.count):
1353 print (
"%d" % (OpEN.uint32_tArray_getitem(list_info.intf, idx)))
1355 OpEN.delete_uint32_tp(acl_p)
1357 def show_summary(self):
1358 """Retrieve and display miscellaneous info"""
1360 val_p = OpEN.new_uint32_tp()
1364 result = OpEN.openapiCpuIntfGet(self.m_client, val_p)
1365 print_bad_result(result,
"openapiCpuIntfGet")
1366 string =
"CPU Control Plane Interface ... %d" % OpEN.uint32_tp_value(val_p)
1367 print_sanity_results(result, (1 == 1),
"openapiCpuIntfGet", string)
1369 result = OpEN.openapiAclMaxAclIntfCountGet(self.m_client, val_p)
1370 print_bad_result(result,
"openapiAclMaxAclIntfCountGet")
1371 string =
"Number of allowed ACL Interfaces ... %d" % OpEN.uint32_tp_value(val_p)
1372 print_sanity_results(result, (1 == 1),
"openapiAclMaxAclIntfCountGet", string)
1374 result = OpEN.openapiAclMaxAclVlanCountGet(self.m_client, val_p)
1375 print_bad_result(result,
"openapiAclMaxAclVlanCountGet")
1376 string =
"Number of allowed ACL VLANs ... %d" % OpEN.uint32_tp_value(val_p)
1377 print_sanity_results(result, (1 == 1),
"openapiAclMaxAclVlanCountGet", string)
1379 result = OpEN.openapiAclCountGet(self.m_client, val_p)
1380 print_bad_result(result,
"openapiAclCountGet")
1381 string =
"Total number of configured ACLs ... %d" % OpEN.uint32_tp_value(val_p)
1382 print_sanity_results(result, (1 == 1),
"openapiAclCountGet", string)
1384 result = OpEN.openapiAclMacCountGet(self.m_client, val_p)
1385 print_bad_result(result,
"openapiAclMacCountGet")
1386 string =
"Number of configured MAC ACLs ... %d" % OpEN.uint32_tp_value(val_p)
1387 print_sanity_results(result, (1 == 1),
"openapiAclMacCountGet", string)
1389 OpEN.delete_uint32_tp(val_p)
1392 """Demonstrate OpEN usage for ACL APIs"""
1394 ret = open_.connect(
"acl_example")
1395 if ret == OpEN.OPEN_E_NONE :
1396 open_.getNetworkOSVersion()
1397 client = open_.get_client()
1398 example = AclExample(client)
1399 example.test_acl_creation(ACL_LIST)
1400 example.test_acl_retrieval()
1401 example.test_acl_rename(ACL_RENAME_LIST)
1402 example.test_acl_traffic_filter_create(INTERFACE_CREATE_LIST)
1403 example.test_acl_traffic_filter_delete(INTERFACE_DELETE_LIST)
1404 example.test_acl_route_filter(OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed')
1405 example.show_interface_summary(OpEN.OPEN_ACL_INBOUND_ACL)
1406 example.show_interface_details(INTF, 1, OpEN.OPEN_ACL_INBOUND_ACL)
1407 example.show_interface_details(VLAN, 6, OpEN.OPEN_ACL_INBOUND_ACL)
1408 example.show_acl_details(INTF, OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', OpEN.OPEN_ACL_INBOUND_ACL)
1409 example.show_acl_details(VLAN, OpEN.OPEN_ACL_TYPE_IP,
'test_ip_renamed', OpEN.OPEN_ACL_INBOUND_ACL)
1410 example.show_summary()
1413 print (
"Unable to connect")
1415 if __name__ ==
'__main__': main()