pio 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +24 -11
- data/Rakefile +0 -2
- data/examples/features_new.rb +17 -6
- data/features/packet_data/aggregate_stats_reply.raw +0 -0
- data/features/packet_data/aggregate_stats_request.raw +0 -0
- data/features/packet_data/barrier_reply.raw +0 -0
- data/features/packet_data/barrier_request.raw +0 -0
- data/features/packet_data/desc_stats_reply.raw +0 -0
- data/features/packet_data/desc_stats_request.raw +0 -0
- data/features/packet_data/echo_reply.raw +0 -0
- data/features/packet_data/echo_request.raw +0 -0
- data/features/packet_data/error.raw +0 -0
- data/features/packet_data/features_reply.raw +0 -0
- data/features/packet_data/flow_mod_add.raw +0 -0
- data/features/packet_data/flow_mod_delete.raw +0 -0
- data/features/packet_data/flow_removed.raw +0 -0
- data/features/packet_data/flow_stats_reply.raw +0 -0
- data/features/packet_data/flow_stats_request.raw +0 -0
- data/features/packet_data/get_config_reply.raw +0 -0
- data/features/packet_data/get_config_request.raw +0 -0
- data/features/packet_data/hello.raw +0 -0
- data/features/packet_data/packet_in.raw +0 -0
- data/features/packet_data/packet_out.raw +0 -0
- data/features/packet_data/port_mod.raw +0 -0
- data/features/packet_data/port_stats_reply.raw +0 -0
- data/features/packet_data/port_stats_request.raw +0 -0
- data/features/packet_data/port_status.raw +0 -0
- data/features/packet_data/queue_get_config_reply.raw +0 -0
- data/features/packet_data/queue_get_config_request.raw +0 -0
- data/features/packet_data/set_config.raw +0 -0
- data/features/packet_data/table_stats_reply.raw +0 -0
- data/features/packet_data/table_stats_request.raw +0 -0
- data/features/packet_data/vendor.raw +0 -0
- data/features/packet_data/vendor_stats_request.raw +0 -0
- data/features/step_definitions/packet_data_steps.rb +0 -2
- data/features/step_definitions/pending_steps.rb +0 -2
- data/features/support/env.rb +0 -2
- data/lib/pio.rb +0 -2
- data/lib/pio/arp.rb +0 -2
- data/lib/pio/arp/format.rb +0 -2
- data/lib/pio/arp/message.rb +14 -22
- data/lib/pio/arp/reply.rb +0 -2
- data/lib/pio/arp/request.rb +0 -2
- data/lib/pio/dhcp.rb +0 -2
- data/lib/pio/dhcp/ack.rb +0 -2
- data/lib/pio/dhcp/boot_reply.rb +0 -2
- data/lib/pio/dhcp/boot_reply_options.rb +0 -2
- data/lib/pio/dhcp/boot_request.rb +0 -2
- data/lib/pio/dhcp/boot_request_options.rb +0 -2
- data/lib/pio/dhcp/client_id.rb +0 -2
- data/lib/pio/dhcp/common_options.rb +0 -2
- data/lib/pio/dhcp/csum_util.rb +0 -2
- data/lib/pio/dhcp/dhcp_field.rb +0 -2
- data/lib/pio/dhcp/dhcp_tlv_options.rb +0 -2
- data/lib/pio/dhcp/discover.rb +0 -2
- data/lib/pio/dhcp/field_util.rb +0 -2
- data/lib/pio/dhcp/frame.rb +0 -2
- data/lib/pio/dhcp/message.rb +0 -2
- data/lib/pio/dhcp/offer.rb +0 -2
- data/lib/pio/dhcp/optional_tlv.rb +0 -2
- data/lib/pio/dhcp/parameter_list.rb +0 -2
- data/lib/pio/dhcp/request.rb +0 -2
- data/lib/pio/echo.rb +3 -6
- data/lib/pio/echo/format.rb +10 -6
- data/lib/pio/echo/message.rb +16 -41
- data/lib/pio/echo/reply.rb +8 -7
- data/lib/pio/echo/request.rb +6 -6
- data/lib/pio/features.rb +15 -9
- data/lib/pio/features/reply.rb +79 -44
- data/lib/pio/features/request.rb +30 -28
- data/lib/pio/hello.rb +17 -29
- data/lib/pio/hello/format.rb +8 -8
- data/lib/pio/icmp.rb +0 -2
- data/lib/pio/icmp/format.rb +0 -2
- data/lib/pio/icmp/message.rb +23 -31
- data/lib/pio/icmp/options.rb +0 -2
- data/lib/pio/icmp/reply.rb +2 -4
- data/lib/pio/icmp/request.rb +0 -2
- data/lib/pio/ipv4_address.rb +1 -5
- data/lib/pio/lldp.rb +0 -2
- data/lib/pio/lldp/chassis_id_tlv.rb +0 -2
- data/lib/pio/lldp/end_of_lldpdu_value.rb +0 -2
- data/lib/pio/lldp/frame.rb +0 -2
- data/lib/pio/lldp/management_address_value.rb +0 -2
- data/lib/pio/lldp/optional_tlv.rb +0 -2
- data/lib/pio/lldp/options.rb +0 -2
- data/lib/pio/lldp/organizationally_specific_value.rb +0 -2
- data/lib/pio/lldp/port_description_value.rb +0 -2
- data/lib/pio/lldp/port_id_tlv.rb +0 -2
- data/lib/pio/lldp/system_capabilities_value.rb +0 -2
- data/lib/pio/lldp/system_description_value.rb +0 -2
- data/lib/pio/lldp/system_name_value.rb +0 -2
- data/lib/pio/lldp/ttl_tlv.rb +0 -2
- data/lib/pio/mac.rb +2 -6
- data/lib/pio/message_type_selector.rb +5 -4
- data/lib/pio/open_flow.rb +5 -0
- data/lib/pio/open_flow/flags.rb +38 -0
- data/lib/pio/open_flow/message.rb +20 -0
- data/lib/pio/open_flow/open_flow_header.rb +18 -0
- data/lib/pio/open_flow/phy_port.rb +74 -0
- data/lib/pio/open_flow/type.rb +12 -0
- data/lib/pio/options.rb +0 -2
- data/lib/pio/parse_error.rb +0 -2
- data/lib/pio/pcap.rb +0 -2
- data/lib/pio/type/ethernet_header.rb +0 -2
- data/lib/pio/type/ip_address.rb +0 -2
- data/lib/pio/type/ipv4_header.rb +2 -2
- data/lib/pio/type/mac_address.rb +6 -3
- data/lib/pio/type/udp_header.rb +0 -2
- data/lib/pio/version.rb +1 -3
- data/pio.gemspec +18 -20
- data/spec/pio/arp/reply/options_spec.rb +0 -2
- data/spec/pio/arp/reply_spec.rb +0 -2
- data/spec/pio/arp/request/options_spec.rb +0 -2
- data/spec/pio/arp/request_spec.rb +0 -2
- data/spec/pio/arp_spec.rb +0 -2
- data/spec/pio/dhcp/ack_spec.rb +0 -2
- data/spec/pio/dhcp/discover_spec.rb +0 -2
- data/spec/pio/dhcp/offer_spec.rb +0 -2
- data/spec/pio/dhcp/request_spec.rb +0 -2
- data/spec/pio/dhcp_spec.rb +0 -2
- data/spec/pio/echo/reply_spec.rb +13 -15
- data/spec/pio/echo/request_spec.rb +15 -15
- data/spec/pio/echo_spec.rb +5 -7
- data/spec/pio/features/reply_spec.rb +47 -17
- data/spec/pio/features/request_spec.rb +6 -11
- data/spec/pio/features_spec.rb +70 -51
- data/spec/pio/hello_spec.rb +1 -3
- data/spec/pio/icmp/reply_spec.rb +0 -2
- data/spec/pio/icmp/request_spec.rb +0 -2
- data/spec/pio/icmp_spec.rb +0 -2
- data/spec/pio/ipv4_address_spec.rb +0 -2
- data/spec/pio/lldp/options_spec.rb +0 -2
- data/spec/pio/lldp_spec.rb +0 -2
- data/spec/pio/mac_spec.rb +0 -1
- data/spec/pio/open_flow/phy_port_spec.rb +25 -0
- data/spec/pio/open_flow/type_spec.rb +5 -0
- data/spec/spec_helper.rb +9 -24
- metadata +105 -40
- data/lib/pio/features/format.rb +0 -18
- data/lib/pio/features/message.rb +0 -14
- data/lib/pio/type/open_flow.rb +0 -34
data/lib/pio/hello/format.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'bindata'
|
2
|
+
require 'pio/open_flow'
|
4
3
|
|
5
4
|
module Pio
|
6
|
-
class Hello
|
7
|
-
# OpenFlow 1.0 Hello message
|
5
|
+
class Hello < Pio::OpenFlow::Message
|
6
|
+
# OpenFlow 1.0 Hello message parser and generator.
|
8
7
|
class Format < BinData::Record
|
8
|
+
include Pio::OpenFlow::Type
|
9
|
+
|
9
10
|
endian :big
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
uint32 :transaction_id
|
12
|
+
open_flow_header :open_flow_header, message_type_value: HELLO
|
13
|
+
virtual assert: -> { open_flow_header.message_type == HELLO }
|
14
|
+
|
15
15
|
string :body # ignored
|
16
16
|
end
|
17
17
|
end
|
data/lib/pio/icmp.rb
CHANGED
data/lib/pio/icmp/format.rb
CHANGED
data/lib/pio/icmp/message.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'pio/icmp/format'
|
4
2
|
require 'forwardable'
|
5
3
|
|
@@ -9,40 +7,34 @@ module Pio
|
|
9
7
|
class Message
|
10
8
|
extend Forwardable
|
11
9
|
|
12
|
-
def_delegators :@
|
13
|
-
def_delegators :@
|
14
|
-
def_delegators :@
|
15
|
-
def_delegators :@
|
16
|
-
def_delegators :@
|
17
|
-
def_delegators :@
|
18
|
-
def_delegators :@
|
19
|
-
def_delegators :@
|
20
|
-
def_delegators :@
|
21
|
-
def_delegators :@
|
22
|
-
def_delegators :@
|
23
|
-
def_delegators :@
|
24
|
-
def_delegators :@
|
25
|
-
def_delegators :@
|
26
|
-
def_delegators :@
|
27
|
-
def_delegators :@
|
28
|
-
def_delegators :@
|
29
|
-
def_delegators :@
|
30
|
-
def_delegators :@
|
31
|
-
def_delegators :@
|
32
|
-
def_delegators :@
|
33
|
-
def_delegators :@
|
34
|
-
|
35
|
-
def self.create_from(frame)
|
36
|
-
message = allocate
|
37
|
-
message.instance_variable_set :@frame, frame
|
38
|
-
message
|
39
|
-
end
|
10
|
+
def_delegators :@format, :destination_mac
|
11
|
+
def_delegators :@format, :source_mac
|
12
|
+
def_delegators :@format, :ether_type
|
13
|
+
def_delegators :@format, :ip_version
|
14
|
+
def_delegators :@format, :ip_header_length
|
15
|
+
def_delegators :@format, :ip_type_of_service
|
16
|
+
def_delegators :@format, :ip_total_length
|
17
|
+
def_delegators :@format, :ip_identifier
|
18
|
+
def_delegators :@format, :ip_flag
|
19
|
+
def_delegators :@format, :ip_fragment
|
20
|
+
def_delegators :@format, :ip_ttl
|
21
|
+
def_delegators :@format, :ip_protocol
|
22
|
+
def_delegators :@format, :ip_header_checksum
|
23
|
+
def_delegators :@format, :ip_source_address
|
24
|
+
def_delegators :@format, :ip_destination_address
|
25
|
+
def_delegators :@format, :icmp_type
|
26
|
+
def_delegators :@format, :icmp_code
|
27
|
+
def_delegators :@format, :icmp_checksum
|
28
|
+
def_delegators :@format, :icmp_identifier
|
29
|
+
def_delegators :@format, :icmp_sequence_number
|
30
|
+
def_delegators :@format, :echo_data
|
31
|
+
def_delegators :@format, :to_binary
|
40
32
|
|
41
33
|
private_class_method :new
|
42
34
|
|
43
35
|
def initialize(user_options)
|
44
36
|
options = self.class.const_get(:Options).new(user_options)
|
45
|
-
@
|
37
|
+
@format = Icmp::Format.new(options.to_hash)
|
46
38
|
end
|
47
39
|
end
|
48
40
|
end
|
data/lib/pio/icmp/options.rb
CHANGED
data/lib/pio/icmp/reply.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'pio/icmp/message'
|
4
2
|
require 'pio/icmp/options'
|
5
3
|
require 'pio/mac'
|
@@ -22,7 +20,7 @@ module Pio
|
|
22
20
|
option :echo_data
|
23
21
|
|
24
22
|
# rubocop:disable MethodLength
|
25
|
-
|
23
|
+
# rubocop:disable AbcSize
|
26
24
|
def initialize(options)
|
27
25
|
validate options
|
28
26
|
@type = TYPE
|
@@ -36,7 +34,7 @@ module Pio
|
|
36
34
|
@sequence_number = options[:sequence_number]
|
37
35
|
@echo_data = options[:echo_data] || DEFAULT_ECHO_DATA
|
38
36
|
end
|
39
|
-
|
37
|
+
# rubocop:enable AbcSize
|
40
38
|
# rubocop:enable MethodLength
|
41
39
|
end
|
42
40
|
end
|
data/lib/pio/icmp/request.rb
CHANGED
data/lib/pio/ipv4_address.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'forwardable'
|
4
2
|
require 'ipaddr'
|
5
3
|
|
@@ -59,9 +57,7 @@ module Pio
|
|
59
57
|
# @return [Array]
|
60
58
|
# an array of decimal numbers converted from IPv4 address.
|
61
59
|
def to_a
|
62
|
-
to_s.split('.').map
|
63
|
-
each.to_i
|
64
|
-
end
|
60
|
+
to_s.split('.').map(&:to_i)
|
65
61
|
end
|
66
62
|
|
67
63
|
# @return [Array]
|
data/lib/pio/lldp.rb
CHANGED
data/lib/pio/lldp/frame.rb
CHANGED
data/lib/pio/lldp/options.rb
CHANGED
data/lib/pio/lldp/port_id_tlv.rb
CHANGED
data/lib/pio/lldp/ttl_tlv.rb
CHANGED
data/lib/pio/mac.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'forwardable'
|
4
2
|
|
5
3
|
module Pio
|
@@ -90,9 +88,7 @@ module Pio
|
|
90
88
|
# @return [Array]
|
91
89
|
#
|
92
90
|
def to_a
|
93
|
-
to_s.split(':').map
|
94
|
-
each.hex
|
95
|
-
end
|
91
|
+
to_s.split(':').map(&:hex)
|
96
92
|
end
|
97
93
|
|
98
94
|
# @!endgroup
|
@@ -131,7 +127,7 @@ module Pio
|
|
131
127
|
# Mac.new("11:22:33:44:55:66").reserved? #=> false
|
132
128
|
#
|
133
129
|
def reserved?
|
134
|
-
(
|
130
|
+
(to_i >> 8) == 0x0180c20000
|
135
131
|
end
|
136
132
|
|
137
133
|
# @!endgroup
|
@@ -1,6 +1,5 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'English'
|
2
|
+
require 'pio/parse_error'
|
4
3
|
|
5
4
|
module Pio
|
6
5
|
# Macros for defining message types.
|
@@ -10,8 +9,10 @@ module Pio
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def read(raw_data)
|
13
|
-
|
14
|
-
const_get(:MESSAGE_TYPE)[
|
12
|
+
format = const_get(:Format).read(raw_data)
|
13
|
+
message = const_get(:MESSAGE_TYPE)[format.message_type].allocate
|
14
|
+
message.instance_variable_set :@format, format
|
15
|
+
message
|
15
16
|
rescue
|
16
17
|
raise Pio::ParseError, $ERROR_INFO.message
|
17
18
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# bitmap functions.
|
2
|
+
module Flags
|
3
|
+
def flags(name, flags)
|
4
|
+
def_field name
|
5
|
+
def_get name, flags
|
6
|
+
def_set name, flags
|
7
|
+
end
|
8
|
+
|
9
|
+
def def_field(name)
|
10
|
+
module_eval("uint32 :#{name}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def def_get(name, flags)
|
14
|
+
str = %{
|
15
|
+
def get
|
16
|
+
list = #{flags.inspect}
|
17
|
+
list.each_with_object([]) do |(key, value), result|
|
18
|
+
result << key if #{name} & value != 0
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
}
|
23
|
+
module_eval str
|
24
|
+
end
|
25
|
+
|
26
|
+
def def_set(name, flags)
|
27
|
+
str = %{
|
28
|
+
def set(v)
|
29
|
+
list = #{flags.inspect}
|
30
|
+
v.each do |each|
|
31
|
+
fail "Invalid state flag: \#{v}" unless list.keys.include?(each)
|
32
|
+
end
|
33
|
+
self.#{name} = v.empty? ? 0 : v.map { |each| list[each] }.inject(:|)
|
34
|
+
end
|
35
|
+
}
|
36
|
+
module_eval str
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Pio
|
4
|
+
module OpenFlow
|
5
|
+
# Defines shortcuts to OpenFlow header fields.
|
6
|
+
class Message
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@format, :open_flow_header
|
10
|
+
def_delegators :open_flow_header, :ofp_version
|
11
|
+
def_delegators :open_flow_header, :message_type
|
12
|
+
def_delegators :open_flow_header, :message_length
|
13
|
+
def_delegators :open_flow_header, :transaction_id
|
14
|
+
def_delegator :open_flow_header, :transaction_id, :xid
|
15
|
+
def_delegators :@format, :body
|
16
|
+
def_delegator :@format, :body, :user_data
|
17
|
+
def_delegator :@format, :to_binary_s, :to_binary
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
|
3
|
+
module Pio
|
4
|
+
module Type
|
5
|
+
# OpenFlow 1.0 format.
|
6
|
+
module OpenFlow
|
7
|
+
# OpenFlow 1.0 message header format.
|
8
|
+
class OpenFlowHeader < BinData::Record
|
9
|
+
endian :big
|
10
|
+
|
11
|
+
uint8 :ofp_version, value: 1
|
12
|
+
uint8 :message_type, initial_value: :message_type_value
|
13
|
+
uint16 :message_length, initial_value: -> { 8 + body.length }
|
14
|
+
uint32 :transaction_id, initial_value: 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
require 'pio/type/mac_address'
|
3
|
+
|
4
|
+
module Pio
|
5
|
+
module Type
|
6
|
+
module OpenFlow
|
7
|
+
# enum ofp_port_config
|
8
|
+
class PortConfig < BinData::Primitive
|
9
|
+
extend Flags
|
10
|
+
|
11
|
+
endian :big
|
12
|
+
|
13
|
+
flags :config,
|
14
|
+
port_down: 1 << 0,
|
15
|
+
no_stp: 1 << 1,
|
16
|
+
no_recv: 1 << 2,
|
17
|
+
no_recv_stp: 1 << 3,
|
18
|
+
no_flood: 1 << 4,
|
19
|
+
no_fwd: 1 << 5,
|
20
|
+
no_packet_in: 1 << 6
|
21
|
+
end
|
22
|
+
|
23
|
+
# enum ofp_port_state
|
24
|
+
class PortState < BinData::Primitive
|
25
|
+
extend Flags
|
26
|
+
|
27
|
+
endian :big
|
28
|
+
|
29
|
+
flags :state,
|
30
|
+
link_down: 1 << 0,
|
31
|
+
stp_listen: 0 << 8,
|
32
|
+
stp_learn: 1 << 8,
|
33
|
+
stp_forward: 2 << 8,
|
34
|
+
stp_block: 3 << 8
|
35
|
+
end
|
36
|
+
|
37
|
+
# enum ofp_port_features
|
38
|
+
class PortFeature < BinData::Primitive
|
39
|
+
extend Flags
|
40
|
+
|
41
|
+
endian :big
|
42
|
+
|
43
|
+
flags :features,
|
44
|
+
port_10mb_hd: 1 << 0,
|
45
|
+
port_10mb_fd: 1 << 1,
|
46
|
+
port_100mb_hd: 1 << 2,
|
47
|
+
port_100mb_fd: 1 << 3,
|
48
|
+
port_1gb_hd: 1 << 4,
|
49
|
+
port_1gb_fd: 1 << 5,
|
50
|
+
port_10gb_fd: 1 << 6,
|
51
|
+
port_copper: 1 << 7,
|
52
|
+
port_fiber: 1 << 8,
|
53
|
+
port_autoneg: 1 << 9,
|
54
|
+
port_pause: 1 << 10,
|
55
|
+
port_pause_asym: 1 << 11
|
56
|
+
end
|
57
|
+
|
58
|
+
# Description of a physical port
|
59
|
+
class PhyPort < BinData::Record
|
60
|
+
endian :big
|
61
|
+
|
62
|
+
uint16 :port_no
|
63
|
+
mac_address :hardware_address
|
64
|
+
string :name, length: 16, trim_padding: true
|
65
|
+
port_config :config
|
66
|
+
port_state :state
|
67
|
+
port_feature :curr
|
68
|
+
port_feature :advertised
|
69
|
+
port_feature :supported
|
70
|
+
port_feature :peer
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|