Class: CiscoAclIntp::AcePortSpec

Inherits:
AceSpecBase show all
Extended by:
Forwardable
Defined in:
lib/cisco_acl_intp/acespec_port.rb

Overview

IP(TCP/UDP) port number and operator container

Constant Summary collapse

OPERATOR_CLASS =

Port set operator table

{
  strict_any: AcePortOpStrictAny,
  any: AcePortOpAny,
  eq: AcePortOpEq,
  neq: AcePortOpNeq,
  lt: AcePortOpLt,
  gt: AcePortOpGt,
  range: AcePortOpRange
}.freeze

Constants inherited from AccessControlContainer

CiscoAclIntp::AccessControlContainer::TERM_COLOR_TABLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AccessControlContainer

#clean_acl_string, disable_color, #generate_tag_footer, #generate_tag_header, #generate_tagged_str, #method_missing, #to_s

Constructor Details

#initialize(opts) ⇒ AcePortSpec

TODO:

in ACL, can “eq/neq” receive port list? IOS15 later?

Note:

‘@begin_port’ and ‘@end_port’ should managed with port number and protocol name. it need the number when operate/compare protocol number, and need the name when stringize the object.

Constructor

Parameters:

  • opts (Hash)

    Options

Options Hash (opts):

  • :operator (String, Symbol)

    Port operator, (any, strict_anyeq, neq, lt, gt, range)

  • :port (AceProtoSpecBase)

    Port (single/lower) (same as :begin_port, alias for unary operator)

  • :begin_port (AceProtoSpecBase)

    Port (single/lower)

  • :end_port (AceProtoSpecBase)

    Port (higher)

Raises:



30
31
32
33
34
35
36
37
# File 'lib/cisco_acl_intp/acespec_port.rb', line 30

def initialize(opts)
  if opts.key?(:operator)
    @options = opts
    define_operator_and_ports
  else
    raise AclArgumentError, 'Not specified port operator'
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CiscoAclIntp::AccessControlContainer

Instance Attribute Details

#operatorAcePortOperatorBase (readonly)

Returns value Port-set operator.

Returns:



12
13
14
# File 'lib/cisco_acl_intp/acespec_port.rb', line 12

def operator
  @operator
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


41
42
43
# File 'lib/cisco_acl_intp/acespec_port.rb', line 41

def ==(other)
  @operator == other.operator
end

#contains?(other) ⇒ Boolean

Check if self contains other port-set?

Parameters:

Returns:

  • (Boolean)

Raises:



49
50
51
# File 'lib/cisco_acl_intp/acespec_port.rb', line 49

def contains?(other)
  @operator.contains?(other.operator)
end

#define_operator_and_portsAcePortOperatorBase (private)

Set instance variables

Returns:

Raises:



69
70
71
72
73
74
75
76
# File 'lib/cisco_acl_intp/acespec_port.rb', line 69

def define_operator_and_ports
  opr = @options.key?(:operator) ? @options[:operator].intern : :any
  raise AclArgumentError, 'Unknown operator' unless OPERATOR_CLASS.key?(opr)
  @operator = OPERATOR_CLASS[opr].new(
    (@options[:port] || @options[:begin_port]),
    @options[:end_port]
  )
end