Class: CiscoAclIntp::AclBase

Inherits:
AccessControlContainer show all
Extended by:
Forwardable
Includes:
AceSearchUtility, Enumerable
Defined in:
lib/cisco_acl_intp/acl_base.rb

Overview

ACL (access-list) container. ACL is composed of ACL-Header and ACE-List. ACL has list(set) of ACE and functions to operate ACE list.

Direct Known Subclasses

NamedAcl, NumberedAcl

Constant Summary collapse

SEQ_NUM_DIV =

Increment number of ACL sequence number

10

Constants inherited from AccessControlContainer

CiscoAclIntp::AccessControlContainer::TERM_COLOR_TABLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AceSearchUtility

#generate_port_obj, generate_port_obj, #port_spec_by_protocol, port_spec_by_protocol, ptkey, #ptkey, search_conditions, #search_conditions, select_proto_class, #select_proto_class, slice_contains_opts, #slice_contains_opts, #srcdst_condition, srcdst_condition, #target_ace, target_ace

Methods inherited from AccessControlContainer

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

Constructor Details

#initialize(name) ⇒ AclBase

Constructor

Parameters:

  • name (String)

    ACL name



39
40
41
42
43
44
45
46
# File 'lib/cisco_acl_intp/acl_base.rb', line 39

def initialize(name)
  @name = name # ACL name
  @list = [] # List of ACE
  @seq_number = 0 # Sequence Number of ACE

  @acl_type = nil # :standard or :extended
  @name_type = nil # :named or :numbered
end

Dynamic Method Handling

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

Instance Attribute Details

#acl_typeString, Symbol (readonly)

Returns acl_type ACL type.

Returns:

  • (String, Symbol)

    acl_type ACL type



25
26
27
# File 'lib/cisco_acl_intp/acl_base.rb', line 25

def acl_type
  @acl_type
end

#listArray<AceBase>

Some Enumerable included methods returns Array of ACE objects (e.g. sort),the returned Array was used as ACE object by overwrite accessor ‘list’.

Returns:

  • (Array<AceBase>)

    list ACE object Array



23
24
25
# File 'lib/cisco_acl_intp/acl_base.rb', line 23

def list
  @list
end

#nameString (readonly)

Returns name ACL name, when numbered acl, /d+/ string.

Returns:

  • (String)

    name ACL name, when numbered acl, /d+/ string



18
19
20
# File 'lib/cisco_acl_intp/acl_base.rb', line 18

def name
  @name
end

#name_typeString, Symbol (readonly)

Returns name_type ACL name type.

Returns:

  • (String, Symbol)

    name_type ACL name type



27
28
29
# File 'lib/cisco_acl_intp/acl_base.rb', line 27

def name_type
  @name_type
end

Instance Method Details

#==(other) ⇒ Boolean

Check equality

Returns:

  • (Boolean)


77
78
79
80
81
82
83
# File 'lib/cisco_acl_intp/acl_base.rb', line 77

def ==(other)
  @acl_type &&
    @name_type &&
    @acl_type == other.acl_type &&
    @name_type == other.name_type &&
    @list == other.list
end

#add_entry(ace) ⇒ Object

Add ACE to ACL (push with sequence number)

Parameters:



59
60
61
62
63
64
# File 'lib/cisco_acl_intp/acl_base.rb', line 59

def add_entry(ace)
  # 'ace' is AceBase Object
  # it will be ExtendedAce/StandardAce/RemarkAce/EvaluateAce
  ace.seq_number = (@list.length + 1) * SEQ_NUM_DIV unless ace.seq_number?
  @list.push ace
end

#clean_acl_string(str) ⇒ String

acl string clean-up (override)

Parameters:

  • str (String)

    ACL string.

Returns:

  • (String)


128
129
130
# File 'lib/cisco_acl_intp/acl_base.rb', line 128

def clean_acl_string(str)
  str =~ /remark/ ? str : super
end

#dup_with_list(list) ⇒ AclBase

duplicate ACE list

Parameters:

  • list (Array<AceBase>)

    List of ACE

Returns:



51
52
53
54
55
# File 'lib/cisco_acl_intp/acl_base.rb', line 51

def dup_with_list(list)
  acl = dup
  acl.list = list.dup
  acl
end

#find_aces_contained(opts) ⇒ Array<AceBase>

Find lists of ACEs that is contained flow by options

Parameters:

  • opts (Hash)

    Options (target packet info) options are same as #find_aces_with

Returns:

  • (Array<AceBase>)

    List of ACEs or nil(not found)

See Also:



99
100
101
# File 'lib/cisco_acl_intp/acl_base.rb', line 99

def find_aces_contained(opts)
  find_aces_with(opts) { |ace, target_ace| target_ace.contains?(ace) }
end

#find_aces_contains(opts) ⇒ Array<AceBase>

Find lists of ACEs that contains flow by options

Parameters:

  • opts (Hash)

    Options (target packet info) options are same as #find_aces_with

Returns:

  • (Array<AceBase>)

    List of ACEs or nil(not found)

See Also:



90
91
92
# File 'lib/cisco_acl_intp/acl_base.rb', line 90

def find_aces_contains(opts)
  find_aces_with(opts) { |ace, target_ace| ace.contains?(target_ace) }
end

#find_aces_with(opts) {|ace, target_ace| ... } ⇒ Array<AceBase>

Note:

In Standard ACL, only src_ip option is used and another conditions are ignored (if specified).

Find lists of ACEs

Parameters:

  • opts (Hash)

    Options (target flow info),

Options Hash (opts):

  • protocol (Integer, String)

    L3 protocol No./Name

  • src_ip (String)

    Source IP Address

  • src_operator (String)

    Source port operator.

  • src_begin_port (Integer, String)

    Source Port No./Name

  • src_end_port (Integer, String)

    Source Port No./Name

  • dst_ip (String)

    Destination IP Address

  • dst_begin_port (Integer, String)

    Destination Port No./Name

  • dst_end_port (Integer, String)

    Destination Port No./Name

Yields:

  • Find lists of ACEs

Yield Parameters:

Yield Returns:

  • (Boolean)

    Condition to find

Returns:

  • (Array<AceBase>)

    List of ACEs or nil(not found)



120
121
122
123
# File 'lib/cisco_acl_intp/acl_base.rb', line 120

def find_aces_with(opts)
  target_ace = target_ace(opts)
  @list.find { |ace| yield(ace, target_ace) }
end

#renumberObject

Renumber ACL by list sequence



67
68
69
70
71
72
73
# File 'lib/cisco_acl_intp/acl_base.rb', line 67

def renumber
  # re-numbering seq_number of each entry
  @list.reduce(SEQ_NUM_DIV) do |number, each|
    each.seq_number = number
    number + SEQ_NUM_DIV
  end
end