Class: CiscoAclIntp::AceIpProtoSpec

Inherits:
AceProtoSpecBase show all
Defined in:
lib/cisco_acl_intp/acespec_proto.rb

Overview

IP protocol number/name container

Constant Summary collapse

IP_PROTO_TABLE =
Note:

protol=‘ip’ means ANY ip protocol in Cisco IOS ACL. not defined ‘ip’ in IANA, www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml

Convert table of tcp port/name

{
  'ahp' => 51,
  'eigrp' => 88,
  'esp' => 50,
  'gre' => 47,
  'igmp' => 2,
  'igrp' => 9,
  'ipinip' => 94,
  'nos' => 4,
  'ospf' => 89,
  'pcp' => 108,
  'pim' => 103,
  'icmp' => 1,
  'tcp' => 6,
  'udp' => 17,
  'ip' => -1 # dummy
}.freeze

Constants inherited from AceProtoSpecBase

CiscoAclIntp::AceProtoSpecBase::DUMMY_PROTO_TABLE

Constants inherited from AccessControlContainer

CiscoAclIntp::AccessControlContainer::TERM_COLOR_TABLE

Instance Attribute Summary

Attributes inherited from AceProtoSpecBase

#max_num, #name, #number, #protocol

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AceProtoSpecBase

#<=>, #==, #define_param_by_integer, #define_param_by_string, #max?, #min?, #name_to_number, #number_to_name, #to_i, #to_s, #valid_name?, #valid_range?

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(proto_id = nil) ⇒ AceIpProtoSpec

Constructor

Parameters:

  • proto_id (String, Integer) (defaults to: nil)

    L3 Protocol ID (No. or Name)



32
33
34
35
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 32

def initialize(proto_id = nil)
  super(proto_id, 255)
  @protocol = :ip
end

Dynamic Method Handling

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

Class Method Details

.valid_name?(name) ⇒ Boolean

Check the port name is known or not.

Parameters:

  • name (String)

    IP/TCP/UDP port/protocol name

Returns:

  • (Boolean)


46
47
48
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 46

def self.valid_name?(name)
  IP_PROTO_TABLE.key?(name)
end

Instance Method Details

#contains?(other) ⇒ Boolean

Protocol inclusion relation

Parameters:

Returns:

  • (Boolean)


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

def contains?(other)
  if ip?
    other.ip? || other.tcp? || other.udp?
  else
    self == other
  end
end

#ip?Boolean

check protocol is ‘ip’?

Returns:

  • (Boolean)


52
53
54
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 52

def ip?
  @name == 'ip'
end

#proto_tableHash

Protocol Table

Returns:

  • (Hash)

    Protocol table



39
40
41
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 39

def proto_table
  IP_PROTO_TABLE
end

#tcp?Boolean

check protocol is ‘tcp’?

Returns:

  • (Boolean)


58
59
60
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 58

def tcp?
  @name == 'tcp'
end

#udp?Boolean

check protocol is ‘udp’?

Returns:

  • (Boolean)


64
65
66
# File 'lib/cisco_acl_intp/acespec_proto.rb', line 64

def udp?
  @name == 'udp'
end