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.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 67 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
61 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 61 define_field :end_addr, PacketGen::Header::IP::Addr |
#end_port ⇒ Integer
16-bit End port
53 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 53 define_field :end_port, PacketGen::Types::Int16, default: 65_535 |
#length ⇒ Integer
16-bit Selector Length
45 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 45 define_field :length, PacketGen::Types::Int16 |
#protocol ⇒ Integer
8-bit protocol ID
41 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 41 define_field :protocol, PacketGen::Types::Int8, default: 0 |
#start_addr ⇒ IP::Addr, IPv6::Addr
starting address
57 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 57 define_field :start_addr, PacketGen::Header::IP::Addr |
#start_port ⇒ Integer
16-bit Start port
49 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 49 define_field :start_port, PacketGen::Types::Int16, default: 0 |
#type ⇒ Integer
8-bit TS type
37 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 37 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.
138 139 140 141 142 143 144 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 138 def human_protocol if protocol.zero? '' else PacketGen::Proto.getprotobynumber(protocol) || protocol.to_s end end |
#human_type ⇒ String
Get human readable TS type
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 148 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
84 85 86 87 88 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 84 def read(str) super select_addr_from_type type super end |
#to_human ⇒ String
Get a human readable string
126 127 128 129 130 131 132 133 |
# File 'lib/packetgen/plugin/ike/ts.rb', line 126 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 |