Module: CiscoAclIntp::AceSearchUtility
- Included in:
- AclBase
- Defined in:
- lib/cisco_acl_intp/acl_utils.rb
Overview
Extended Ace utilities for ace search
Class Method Summary collapse
-
.generate_port_obj(proto, port = nil) ⇒ AceTcpProtoSpec, AceUdpProtoSpec
TCP/UDP port object.
-
.port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) ⇒ AcePortSpec
Generate port spec by protocol.
-
.ptkey(pt, key) ⇒ Symbol
Generate hash key to slice.
-
.search_conditions(opts) ⇒ Array<AceIpProtoSpec, AceSrcDstSpec, AceSrcDstSpec>
Generate ACE components.
-
.select_proto_class(proto) ⇒ Class
Select protocol spec class for tcp/udp.
-
.slice_contains_opts(proto_cond, pt, opts) ⇒ Object
Generate list of values sliced hash (args of srcdst_condition).
-
.srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) ⇒ Object
Generate Src/Dst search condition.
-
.target_ace(opts) ⇒ ExtendedAce
Generate ACE search(contains?) conditions.
Instance Method Summary collapse
-
#generate_port_obj(proto, port = nil) ⇒ AceTcpProtoSpec, AceUdpProtoSpec
private
TCP/UDP port object.
-
#port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) ⇒ AcePortSpec
private
Generate port spec by protocol.
-
#ptkey(pt, key) ⇒ Symbol
private
Generate hash key to slice.
-
#search_conditions(opts) ⇒ Array<AceIpProtoSpec, AceSrcDstSpec, AceSrcDstSpec>
private
Generate ACE components.
-
#select_proto_class(proto) ⇒ Class
private
Select protocol spec class for tcp/udp.
-
#slice_contains_opts(proto_cond, pt, opts) ⇒ Object
private
Generate list of values sliced hash (args of srcdst_condition).
-
#srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) ⇒ Object
private
Generate Src/Dst search condition.
-
#target_ace(opts) ⇒ ExtendedAce
private
Generate ACE search(contains?) conditions.
Class Method Details
.generate_port_obj(proto, port = nil) ⇒ AceTcpProtoSpec, AceUdpProtoSpec
Returns TCP/UDP port object.
24 25 26 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 24 def generate_port_obj(proto, port = nil) port.nil? ? nil : select_proto_class(proto).new(port) end |
.port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) ⇒ AcePortSpec
Generate port spec by protocol
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 34 def port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) if opr.nil? AcePortSpec.new(operator: :any) # any else AcePortSpec.new( operator: opr, begin_port: generate_port_obj(proto, begin_port), end_port: generate_port_obj(proto, end_port) ) end end |
.ptkey(pt, key) ⇒ Symbol
Generate hash key to slice
71 72 73 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 71 def ptkey(pt, key) [pt.to_s, key.to_s].join('_').intern end |
.search_conditions(opts) ⇒ Array<AceIpProtoSpec, AceSrcDstSpec, AceSrcDstSpec>
Generate ACE components
93 94 95 96 97 98 99 100 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 93 def search_conditions(opts) proto_cond = AceIpProtoSpec.new(opts[:protocol]) [ proto_cond, srcdst_condition(*slice_contains_opts(proto_cond, :src, opts)), srcdst_condition(*slice_contains_opts(proto_cond, :dst, opts)) ] end |
.select_proto_class(proto) ⇒ Class
Select protocol spec class for tcp/udp.
12 13 14 15 16 17 18 19 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 12 def select_proto_class(proto) case proto when 'tcp' AceTcpProtoSpec when 'udp' AceUdpProtoSpec end end |
.slice_contains_opts(proto_cond, pt, opts) ⇒ Object
Generate list of values sliced hash (args of srcdst_condition)
79 80 81 82 83 84 85 86 87 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 79 def slice_contains_opts(proto_cond, pt, opts) [ proto_cond, opts[ptkey(pt, :ip)], opts[ptkey(pt, :operator)], (opts[ptkey(pt, :port)] || opts[ptkey(pt, :begin_port)]), opts[ptkey(pt, :end_port)] ] end |
.srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) ⇒ Object
Generate Src/Dst search condition
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 52 def srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) case proto.name when 'tcp', 'udp' AceSrcDstSpec.new( ipaddr: ip, port_spec: port_spec_by_protocol( proto.name, opr, begin_port, end_port ) ) else # if L3 protocol is not tcp/udp, it did not need port condition AceSrcDstSpec.new(ipaddr: ip) end end |
.target_ace(opts) ⇒ ExtendedAce
Generate ACE search(contains?) conditions
106 107 108 109 110 111 112 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 106 def target_ace(opts) (proto_cond, src_cond, dst_cond) = search_conditions(opts) ExtendedAce.new( action: 'permit', protocol: proto_cond.name, src: src_cond, dst: dst_cond ) end |
Instance Method Details
#generate_port_obj(proto, port = nil) ⇒ AceTcpProtoSpec, AceUdpProtoSpec (private)
Returns TCP/UDP port object.
24 25 26 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 24 def generate_port_obj(proto, port = nil) port.nil? ? nil : select_proto_class(proto).new(port) end |
#port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) ⇒ AcePortSpec (private)
Generate port spec by protocol
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 34 def port_spec_by_protocol(proto, opr, begin_port = nil, end_port = nil) if opr.nil? AcePortSpec.new(operator: :any) # any else AcePortSpec.new( operator: opr, begin_port: generate_port_obj(proto, begin_port), end_port: generate_port_obj(proto, end_port) ) end end |
#ptkey(pt, key) ⇒ Symbol (private)
Generate hash key to slice
71 72 73 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 71 def ptkey(pt, key) [pt.to_s, key.to_s].join('_').intern end |
#search_conditions(opts) ⇒ Array<AceIpProtoSpec, AceSrcDstSpec, AceSrcDstSpec> (private)
Generate ACE components
93 94 95 96 97 98 99 100 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 93 def search_conditions(opts) proto_cond = AceIpProtoSpec.new(opts[:protocol]) [ proto_cond, srcdst_condition(*slice_contains_opts(proto_cond, :src, opts)), srcdst_condition(*slice_contains_opts(proto_cond, :dst, opts)) ] end |
#select_proto_class(proto) ⇒ Class (private)
Select protocol spec class for tcp/udp.
12 13 14 15 16 17 18 19 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 12 def select_proto_class(proto) case proto when 'tcp' AceTcpProtoSpec when 'udp' AceUdpProtoSpec end end |
#slice_contains_opts(proto_cond, pt, opts) ⇒ Object (private)
Generate list of values sliced hash (args of srcdst_condition)
79 80 81 82 83 84 85 86 87 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 79 def slice_contains_opts(proto_cond, pt, opts) [ proto_cond, opts[ptkey(pt, :ip)], opts[ptkey(pt, :operator)], (opts[ptkey(pt, :port)] || opts[ptkey(pt, :begin_port)]), opts[ptkey(pt, :end_port)] ] end |
#srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) ⇒ Object (private)
Generate Src/Dst search condition
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 52 def srcdst_condition(proto, ip, opr, begin_port = nil, end_port = nil) case proto.name when 'tcp', 'udp' AceSrcDstSpec.new( ipaddr: ip, port_spec: port_spec_by_protocol( proto.name, opr, begin_port, end_port ) ) else # if L3 protocol is not tcp/udp, it did not need port condition AceSrcDstSpec.new(ipaddr: ip) end end |
#target_ace(opts) ⇒ ExtendedAce (private)
Generate ACE search(contains?) conditions
106 107 108 109 110 111 112 |
# File 'lib/cisco_acl_intp/acl_utils.rb', line 106 def target_ace(opts) (proto_cond, src_cond, dst_cond) = search_conditions(opts) ExtendedAce.new( action: 'permit', protocol: proto_cond.name, src: src_cond, dst: dst_cond ) end |