Class: PacketGen::Plugin::IKE::TrafficSelector
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Plugin::IKE::TrafficSelector
- Defined in:
- lib/packetgen/plugin/ike/ts.rb
Overview
TrafficSelector substructure, as defined in RFC 7296, §3.13.1:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TS Type |IP Protocol ID*| Selector Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start Port* | End Port* |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Starting Address* ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Ending Address* ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Constant Summary collapse
- TS_IPV4_ADDR_RANGE =
IPv4 traffic selector type
7
- TS_IPV6_ADDR_RANGE =
IPv6 traffic selector type
8
Instance Attribute Summary collapse
-
#end_addr ⇒ IP::Addr, IPv6::Addr
starting address.
-
#end_port ⇒ Integer
16-bit End port.
-
#length ⇒ Integer
16-bit Selector Length.
-
#protocol ⇒ Integer
8-bit protocol ID.
-
#start_addr ⇒ IP::Addr, IPv6::Addr
starting address.
-
#start_port ⇒ Integer
16-bit Start port.
-
#type ⇒ Integer
8-bit TS type.
Instance Method Summary collapse
-
#human_protocol ⇒ String
Get human readable protocol name.
-
#human_type ⇒ String
Get human readable TS type.
-
#initialize(options = {}) ⇒ TrafficSelector
constructor
A new instance of TrafficSelector.
-
#read(str) ⇒ self
Populate object from a string.
-
#to_human ⇒ String
Get a human readable string.
Constructor Details
#initialize(options = {}) ⇒ TrafficSelector
Returns a new instance of TrafficSelector.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 68 def initialize(={}) super select_addr self[:start_addr].from_human([:start_addr]) if [:start_addr] self[:end_addr].from_human([:end_addr]) if [:end_addr] self.type = [:type] if [:type] self.protocol = [:protocol] if [:protocol] self[:length].value = sz unless [:length] return unless [:ports] self.start_port = [:ports].begin self.end_port = [:ports].end end |
Instance Attribute Details
#end_addr ⇒ IP::Addr, IPv6::Addr
starting address
62 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 62 define_field :end_addr, PacketGen::Header::IP::Addr |
#end_port ⇒ Integer
16-bit End port
54 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 54 define_field :end_port, PacketGen::Types::Int16, default: 65_535 |
#length ⇒ Integer
16-bit Selector Length
46 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 46 define_field :length, PacketGen::Types::Int16 |
#protocol ⇒ Integer
8-bit protocol ID
42 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 42 define_field :protocol, PacketGen::Types::Int8, default: 0 |
#start_addr ⇒ IP::Addr, IPv6::Addr
starting address
58 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 58 define_field :start_addr, PacketGen::Header::IP::Addr |
#start_port ⇒ Integer
16-bit Start port
50 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 50 define_field :start_port, PacketGen::Types::Int16, default: 0 |
#type ⇒ Integer
8-bit TS type
38 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 38 define_field :type, PacketGen::Types::Int8, default: 7 |
Instance Method Details
#human_protocol ⇒ String
Get human readable protocol name. If protocol ID is 0, an empty string is returned.
137 138 139 140 141 142 143 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 137 def human_protocol if protocol.zero? '' else Proto.getprotobynumber(protocol) || protocol.to_s end end |
#human_type ⇒ String
Get human readable TS type
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 147 def human_type case type when TS_IPV4_ADDR_RANGE 'IPv4' when TS_IPV6_ADDR_RANGE 'IPv6' else "type #{type}" end end |
#read(str) ⇒ self
Populate object from a string
85 86 87 88 89 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 85 def read(str) super select_addr_from_type type super end |
#to_human ⇒ String
Get a human readable string
125 126 127 128 129 130 131 132 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 125 def to_human h = start_addr << '-' << end_addr unless human_protocol.empty? h << "/#{human_protocol}" h << "[#{start_port}-#{end_port}]" if (start_port..end_port) != (0..65_535) end h end |