Class: PacketGen::Header::IKE::TrafficSelector
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::IKE::TrafficSelector
- Defined in:
- lib/packetgen/header/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.
Methods inherited from Types::Fields
#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #inspect, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
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/header/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[:length].value = sz unless [:length] self.type = [:type] if [:type] self.protocol = [:protocol] if [:protocol] 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/header/ike/ts.rb', line 62 define_field :end_addr, IP::Addr |
#end_port ⇒ Integer
16-bit End port
54 |
# File 'lib/packetgen/header/ike/ts.rb', line 54 define_field :end_port, Types::Int16, default: 65_535 |
#length ⇒ Integer
16-bit Selector Length
46 |
# File 'lib/packetgen/header/ike/ts.rb', line 46 define_field :length, Types::Int16 |
#protocol ⇒ Integer
8-bit protocol ID
42 |
# File 'lib/packetgen/header/ike/ts.rb', line 42 define_field :protocol, Types::Int8, default: 0 |
#start_addr ⇒ IP::Addr, IPv6::Addr
starting address
58 |
# File 'lib/packetgen/header/ike/ts.rb', line 58 define_field :start_addr, IP::Addr |
Instance Method Details
#human_protocol ⇒ String
Get human readable protocol name. If protocol ID is 0, an empty string is returned.
135 136 137 138 139 140 141 |
# File 'lib/packetgen/header/ike/ts.rb', line 135 def human_protocol if protocol.zero? '' else Proto.getprotobynumber(protocol) || protocol.to_s end end |
#human_type ⇒ String
Get human readable TS type
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/packetgen/header/ike/ts.rb', line 145 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/header/ike/ts.rb', line 85 def read(str) super select_addr_from_type type super end |
#to_human ⇒ String
Get a human readable string
123 124 125 126 127 128 129 130 |
# File 'lib/packetgen/header/ike/ts.rb', line 123 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 |