Class: CiscoAclIntp::AceSrcDstSpec
- Inherits:
-
AceSpecBase
- Object
- AccessControlContainer
- AceSpecBase
- CiscoAclIntp::AceSrcDstSpec
- Defined in:
- lib/cisco_acl_intp/acespec_srcdst.rb
Overview
Src/Dst takes Network Object Group or IP/wildcard. “object-group” is not implemented yet.
IP Address and TCP/UDP Port Info
Constant Summary
Constants inherited from AccessControlContainer
CiscoAclIntp::AccessControlContainer::TERM_COLOR_TABLE
Instance Attribute Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#contains?(other) ⇒ Boolean
Check address and port number contains this object or not.
-
#contains_address?(ip_spec = nil) ⇒ Boolean
private
Check address match (by NetAddr).
-
#contains_port?(port_spec = nil) ⇒ Boolean
private
Check port match.
-
#define_ipspec ⇒ AceIpSpec
private
Set instance variables.
-
#define_portspec ⇒ AcePortSpec
private
Set instance variables.
-
#initialize(opts) ⇒ AceSrcDstSpec
constructor
Constructor.
-
#to_s ⇒ String
Generate string for Cisco IOS access list.
Methods inherited from AccessControlContainer
#clean_acl_string, disable_color, #generate_tag_footer, #generate_tag_header, #generate_tagged_str, #method_missing
Constructor Details
#initialize(opts) ⇒ AceSrcDstSpec
When it does not specified port in opts, (:port_spec or :operator, :begin_port, :end_port) it assumed with ANY port.
Constructor
39 40 41 42 43 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 39 def initialize(opts) @options = opts @ip_spec = define_ipspec @port_spec = define_portspec end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CiscoAclIntp::AccessControlContainer
Instance Attribute Details
#ip_spec ⇒ AceIpSpec
15 16 17 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 15 def ip_spec @ip_spec end |
#port_spec ⇒ AcePortSpec
19 20 21 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 19 def port_spec @port_spec end |
Instance Method Details
#==(other) ⇒ Boolean
47 48 49 50 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 47 def ==(other) @port_spec == other.port_spec && @ip_spec == other.ip_spec end |
#contains?(other) ⇒ Boolean
Check address and port number contains this object or not.
62 63 64 65 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 62 def contains?(other) contains_address?(other.ip_spec) && contains_port?(other.port_spec) end |
#contains_address?(ip_spec = nil) ⇒ Boolean (private)
Check address match (by NetAddr)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 80 def contains_address?(ip_spec = nil) case ip_spec when nil # 'any', '0.0.0.0/0' true else # IP match/contain checks are delegated to NetAddr if @ip_spec.netmask.nil? # check by wildcard @ip_spec.matches?(ip_spec.ipaddr) else # check by CIDR(netmask) @ip_spec.contains?(ip_spec.ipaddr) end end end |
#contains_port?(port_spec = nil) ⇒ Boolean (private)
Check port match
72 73 74 75 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 72 def contains_port?(port_spec = nil) port_spec = AcePortSpec.new(operator: :any) if port_spec.nil? @port_spec.contains?(port_spec) end |
#define_ipspec ⇒ AceIpSpec (private)
Set instance variables
100 101 102 103 104 105 106 107 108 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 100 def define_ipspec if @options.key?(:ip_spec) # AceIpSpec Obj @options[:ip_spec] elsif @options.key?(:ipaddr) AceIpSpec.new(@options) else raise AclArgumentError, 'Not specified: ip spec' end end |
#define_portspec ⇒ AcePortSpec (private)
Set instance variables
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 113 def define_portspec if @options.key?(:port_spec) && @options[:port_spec].is_a?(AcePortSpec) @options[:port_spec] elsif @options.key?(:operator) AcePortSpec.new( operator: @options[:operator], begin_port: @options[:port] || @options[:begin_port], end_port: @options[:end_port] ) else # in standard acl, not used port_spec # if not specified port spec: default: any port. # port spec should be ignored except tcp/udp protocol. AcePortSpec.new(operator: 'any') end end |
#to_s ⇒ String
Generate string for Cisco IOS access list
54 55 56 |
# File 'lib/cisco_acl_intp/acespec_srcdst.rb', line 54 def to_s format '%s %s', @ip_spec, @port_spec end |