pio 0.23.1 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -0
- data/Rakefile +1 -1
- data/features/open_flow10/barrier_reply.feature +58 -0
- data/features/open_flow10/barrier_request.feature +58 -0
- data/features/open_flow10/echo_reply.feature +50 -40
- data/features/open_flow10/echo_request.feature +54 -51
- data/features/open_flow10/features_reply.feature +62 -63
- data/features/open_flow10/features_request.feature +2 -19
- data/features/open_flow10/flow_mod.feature +1 -0
- data/features/open_flow10/hello.feature +38 -44
- data/features/open_flow10/packet_in.feature +1 -2
- data/features/open_flow10/packet_in.raw +0 -0
- data/features/open_flow10/packet_out.feature +14 -14
- data/features/open_flow10/port_status.feature +17 -17
- data/features/open_flow13/apply_actions.feature +15 -17
- data/features/open_flow13/echo_reply.feature +58 -58
- data/features/open_flow13/echo_request.feature +58 -58
- data/features/open_flow13/features_reply.feature +2 -6
- data/features/open_flow13/features_request.feature +3 -23
- data/features/open_flow13/flow_mod.feature +86 -93
- data/features/open_flow13/goto_table.feature +4 -4
- data/features/open_flow13/hello.feature +8 -15
- data/features/open_flow13/match.feature +14 -3
- data/features/open_flow13/meter.feature +3 -3
- data/features/open_flow13/oxm_experimenter_stratos_basic_dot11.raw +0 -0
- data/features/open_flow13/oxm_invalid_field.raw +0 -0
- data/features/open_flow13/packet_in.feature +15 -20
- data/features/open_flow13/packet_out.feature +39 -42
- data/features/open_flow13/send_out_port.feature +1 -5
- data/features/open_flow13/write_metadata.feature +3 -3
- data/features/open_flow_read.feature +43 -0
- data/features/open_flow_version.feature +10 -0
- data/features/step_definitions/open_flow_steps.rb +10 -2
- data/features/step_definitions/packet_data_steps.rb +4 -0
- data/features/support/hooks.rb +7 -0
- data/lib/pio.rb +1 -1
- data/lib/pio/monkey_patch/integer/ranges.rb +4 -0
- data/lib/pio/open_flow.rb +54 -16
- data/lib/pio/open_flow/datapath_id.rb +26 -0
- data/lib/pio/open_flow/echo.rb +44 -0
- data/lib/pio/open_flow/format.rb +45 -0
- data/lib/pio/open_flow/message.rb +88 -0
- data/lib/pio/open_flow/open_flow_header.rb +0 -14
- data/lib/pio/open_flow10.rb +3 -8
- data/lib/pio/open_flow10/actions.rb +1 -1
- data/lib/pio/open_flow10/barrier_reply.rb +21 -0
- data/lib/pio/open_flow10/barrier_request.rb +22 -0
- data/lib/pio/open_flow10/echo.rb +15 -11
- data/lib/pio/open_flow10/features.rb +99 -71
- data/lib/pio/open_flow10/flow_mod.rb +73 -66
- data/lib/pio/open_flow10/hello.rb +19 -4
- data/lib/pio/open_flow10/match.rb +133 -131
- data/lib/pio/open_flow10/packet_in.rb +55 -49
- data/lib/pio/open_flow10/packet_out.rb +31 -24
- data/lib/pio/open_flow10/port_status.rb +54 -27
- data/lib/pio/open_flow10/send_out_port.rb +66 -64
- data/lib/pio/open_flow13.rb +0 -15
- data/lib/pio/open_flow13/echo.rb +11 -68
- data/lib/pio/open_flow13/features_reply.rb +48 -77
- data/lib/pio/open_flow13/features_request.rb +16 -45
- data/lib/pio/open_flow13/flow_mod.rb +125 -148
- data/lib/pio/open_flow13/goto_table.rb +1 -0
- data/lib/pio/open_flow13/hello.rb +54 -84
- data/lib/pio/open_flow13/match.rb +69 -11
- data/lib/pio/open_flow13/meter.rb +1 -0
- data/lib/pio/open_flow13/packet_in.rb +38 -50
- data/lib/pio/open_flow13/packet_out.rb +50 -75
- data/lib/pio/open_flow13/send_out_port.rb +34 -34
- data/lib/pio/open_flow13/write_metadata.rb +1 -0
- data/lib/pio/parser.rb +3 -0
- data/lib/pio/version.rb +1 -1
- data/pio.gemspec +6 -6
- data/spec/pio/open_flow10/echo_reply_spec.rb +7 -0
- data/spec/pio/open_flow10/echo_request_spec.rb +7 -0
- data/spec/pio/open_flow10/features_reply_spec.rb +8 -0
- data/spec/pio/open_flow10/features_request_spec.rb +13 -0
- data/spec/pio/open_flow10/flow_mod_spec.rb +17 -16
- data/spec/pio/open_flow10/hello_spec.rb +7 -0
- data/spec/pio/open_flow10/match_spec.rb +8 -6
- data/spec/pio/open_flow10/packet_in_spec.rb +14 -0
- data/spec/pio/open_flow10/packet_out_spec.rb +21 -14
- data/spec/pio/open_flow10/send_out_port_spec.rb +4 -4
- data/spec/pio/open_flow10/wildcards_spec.rb +2 -2
- data/spec/pio/open_flow13/echo_reply_spec.rb +7 -0
- data/spec/pio/open_flow13/echo_request_spec.rb +7 -0
- data/spec/pio/open_flow13/features_reply_spec.rb +8 -0
- data/spec/pio/open_flow13/features_request_spec.rb +13 -0
- data/spec/pio/open_flow13/hello_spec.rb +14 -59
- data/spec/pio/open_flow13/packet_in_spec.rb +14 -0
- data/spec/pio/open_flow13/packet_out_spec.rb +7 -0
- data/spec/pio/open_flow_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/shared_examples_for_openflow_messages.rb +75 -0
- metadata +215 -170
- data/bin/byebug +0 -16
- data/bin/terminal-notifier +0 -16
- data/lib/pio/open_flow10/message.rb +0 -78
- data/spec/pio/open_flow/type_spec.rb +0 -5
@@ -1,89 +1,96 @@
|
|
1
1
|
require 'pio/open_flow'
|
2
|
+
require 'pio/open_flow10/actions'
|
2
3
|
require 'pio/open_flow10/match'
|
3
4
|
|
4
5
|
# Base module.
|
5
6
|
module Pio
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
endian :big
|
19
|
-
uint16 :command
|
20
|
-
|
21
|
-
def get
|
22
|
-
COMMANDS.invert.fetch(command)
|
23
|
-
end
|
7
|
+
module OpenFlow10
|
8
|
+
# OpenFlow 1.0 Flow Mod message.
|
9
|
+
class FlowMod < OpenFlow::Message
|
10
|
+
# enum ofp_flow_mod_command
|
11
|
+
class Command < BinData::Primitive
|
12
|
+
COMMANDS = {
|
13
|
+
add: 0,
|
14
|
+
modify: 1,
|
15
|
+
modify_strict: 2,
|
16
|
+
delete: 3,
|
17
|
+
delete_strict: 4
|
18
|
+
}
|
24
19
|
|
25
|
-
def set(value)
|
26
|
-
self.command = COMMANDS.fetch(value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Message body of FlowMod.
|
31
|
-
class Body < BinData::Record
|
32
|
-
# Pio::MatchFormat wrapper.
|
33
|
-
class Match < BinData::Primitive
|
34
20
|
endian :big
|
21
|
+
uint16 :command
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
def set(object)
|
39
|
-
self.match = object.to_binary_s
|
23
|
+
def get
|
24
|
+
COMMANDS.invert.fetch(command)
|
40
25
|
end
|
41
26
|
|
42
|
-
def
|
43
|
-
|
27
|
+
def set(value)
|
28
|
+
self.command = COMMANDS.fetch(value)
|
44
29
|
end
|
45
30
|
end
|
46
31
|
|
47
|
-
|
32
|
+
# Message body of FlowMod.
|
33
|
+
class Body < BinData::Record
|
34
|
+
# Pio::MatchFormat wrapper.
|
35
|
+
class Match < BinData::Primitive
|
36
|
+
endian :big
|
37
|
+
|
38
|
+
string :match, read_length: 40
|
39
|
+
|
40
|
+
def set(object)
|
41
|
+
self.match = object.to_binary_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def get
|
45
|
+
Pio::OpenFlow10::Match.read match
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
extend OpenFlow::Flags
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
flags_16bit :flags,
|
52
|
+
[:send_flow_rem,
|
53
|
+
:check_overwrap,
|
54
|
+
:emerg]
|
53
55
|
|
54
|
-
|
56
|
+
endian :big
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
match :match
|
59
|
+
uint64 :cookie
|
60
|
+
command :command
|
61
|
+
uint16 :idle_timeout
|
62
|
+
uint16 :hard_timeout
|
63
|
+
uint16 :priority
|
64
|
+
uint32 :buffer_id
|
65
|
+
uint16 :out_port
|
66
|
+
flags :flags
|
67
|
+
actions :actions, length: -> { header.message_length - 72 }
|
68
|
+
|
69
|
+
def empty?
|
70
|
+
false
|
71
|
+
end
|
66
72
|
|
67
|
-
|
68
|
-
|
73
|
+
def length
|
74
|
+
64 + actions.binary.length
|
75
|
+
end
|
69
76
|
end
|
70
77
|
|
71
|
-
|
72
|
-
|
78
|
+
# OpenFlow 1.0 Flow Mod message format.
|
79
|
+
class Format < BinData::Record
|
80
|
+
extend OpenFlow::Format
|
81
|
+
|
82
|
+
header version: 1, message_type: 14
|
83
|
+
body :body
|
73
84
|
end
|
74
|
-
end
|
75
|
-
end
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
def_delegators :body, :flags
|
87
|
-
def_delegators :body, :actions
|
86
|
+
body_option :actions
|
87
|
+
body_option :buffer_id
|
88
|
+
body_option :command
|
89
|
+
body_option :cookie
|
90
|
+
body_option :flags
|
91
|
+
body_option :match
|
92
|
+
body_option :out_port
|
93
|
+
body_option :priority
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
@@ -1,8 +1,23 @@
|
|
1
|
-
require 'pio/open_flow'
|
1
|
+
require 'pio/open_flow/format'
|
2
|
+
require 'pio/open_flow/message'
|
2
3
|
|
3
4
|
# Base module.
|
4
5
|
module Pio
|
5
|
-
# OpenFlow 1.0
|
6
|
-
|
7
|
-
|
6
|
+
# OpenFlow 1.0 messages
|
7
|
+
module OpenFlow10
|
8
|
+
# OpenFlow 1.0 Hello message
|
9
|
+
class Hello < OpenFlow::Message
|
10
|
+
# OpenFlow 1.0 Hello message format
|
11
|
+
class Format < BinData::Record
|
12
|
+
extend OpenFlow::Format
|
13
|
+
|
14
|
+
header version: 1, message_type: 0
|
15
|
+
string :body
|
16
|
+
|
17
|
+
def user_data
|
18
|
+
body
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
8
23
|
end
|
@@ -5,159 +5,161 @@ require 'pio/type/ip_address'
|
|
5
5
|
require 'pio/type/mac_address'
|
6
6
|
|
7
7
|
module Pio
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
8
|
+
module OpenFlow10
|
9
|
+
# Fields to match against flows
|
10
|
+
class Match
|
11
|
+
# Flow wildcards
|
12
|
+
class Wildcards < BinData::Primitive
|
13
|
+
BITS = {
|
14
|
+
in_port: 1 << 0,
|
15
|
+
vlan_vid: 1 << 1,
|
16
|
+
ether_source_address: 1 << 2,
|
17
|
+
ether_destination_address: 1 << 3,
|
18
|
+
ether_type: 1 << 4,
|
19
|
+
ip_protocol: 1 << 5,
|
20
|
+
transport_source_port: 1 << 6,
|
21
|
+
transport_destination_port: 1 << 7,
|
22
|
+
ip_source_address: 0,
|
23
|
+
ip_source_address0: 1 << 8,
|
24
|
+
ip_source_address1: 1 << 9,
|
25
|
+
ip_source_address2: 1 << 10,
|
26
|
+
ip_source_address3: 1 << 11,
|
27
|
+
ip_source_address4: 1 << 12,
|
28
|
+
ip_source_address_all: 1 << 13,
|
29
|
+
ip_destination_address: 0,
|
30
|
+
ip_destination_address0: 1 << 14,
|
31
|
+
ip_destination_address1: 1 << 15,
|
32
|
+
ip_destination_address2: 1 << 16,
|
33
|
+
ip_destination_address3: 1 << 17,
|
34
|
+
ip_destination_address4: 1 << 18,
|
35
|
+
ip_destination_address_all: 1 << 19,
|
36
|
+
vlan_priority: 1 << 20,
|
37
|
+
ip_tos: 1 << 21
|
38
|
+
}
|
39
|
+
NW_FLAGS = [:ip_source_address, :ip_destination_address]
|
40
|
+
FLAGS = BITS.keys.select { |each| !(/^ip_(source|destination)/=~ each) }
|
41
|
+
|
42
|
+
endian :big
|
43
|
+
|
44
|
+
uint32 :flags
|
45
|
+
|
46
|
+
# This method smells of :reek:FeatureEnvy
|
47
|
+
def get
|
48
|
+
BITS.each_with_object(Hash.new(0)) do |(key, bit), memo|
|
49
|
+
next if flags & bit == 0
|
50
|
+
if /(ip_source_address|ip_destination_address)(\d)/=~ key
|
51
|
+
memo[$LAST_MATCH_INFO[1].intern] |= 1 << $LAST_MATCH_INFO[2].to_i
|
52
|
+
else
|
53
|
+
memo[key] = true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
44
57
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
def set(params)
|
59
|
+
self.flags = params.inject(0) do |memo, (key, val)|
|
60
|
+
memo | case key
|
61
|
+
when :ip_source_address, :ip_destination_address
|
62
|
+
(params.fetch(key) & 31) <<
|
63
|
+
(key == :ip_source_address ? 8 : 14)
|
64
|
+
else
|
65
|
+
val ? BITS.fetch(key) : 0
|
66
|
+
end
|
53
67
|
end
|
54
68
|
end
|
55
|
-
end
|
56
69
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
(params.fetch(key) & 31) <<
|
62
|
-
(key == :ip_source_address ? 8 : 14)
|
63
|
-
else
|
64
|
-
val ? BITS.fetch(key) : 0
|
65
|
-
end
|
70
|
+
def ip_source_address
|
71
|
+
get.fetch(:ip_source_address)
|
72
|
+
rescue KeyError
|
73
|
+
0
|
66
74
|
end
|
67
|
-
end
|
68
75
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
76
|
+
def ip_destination_address
|
77
|
+
get.fetch(:ip_destination_address)
|
78
|
+
rescue KeyError
|
79
|
+
0
|
80
|
+
end
|
73
81
|
end
|
74
82
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
0
|
79
|
-
end
|
80
|
-
end
|
83
|
+
# IP address
|
84
|
+
class MatchIpAddress < BinData::Primitive
|
85
|
+
default_parameter bitcount: 0
|
81
86
|
|
82
|
-
|
83
|
-
class MatchIpAddress < BinData::Primitive
|
84
|
-
default_parameter bitcount: 0
|
87
|
+
array :octets, type: :uint8, initial_length: 4
|
85
88
|
|
86
|
-
|
89
|
+
def set(value)
|
90
|
+
self.octets = IPv4Address.new(value).to_a
|
91
|
+
end
|
87
92
|
|
88
|
-
|
89
|
-
|
90
|
-
|
93
|
+
def get
|
94
|
+
ipaddr = octets.map { |each| format('%d', each) }.join('.')
|
95
|
+
prefixlen = 32 - eval_parameter(:bitcount)
|
96
|
+
IPv4Address.new(ipaddr + "/#{prefixlen}")
|
97
|
+
end
|
91
98
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
IPv4Address.new(ipaddr + "/#{prefixlen}")
|
99
|
+
def ==(other)
|
100
|
+
get == other
|
101
|
+
end
|
96
102
|
end
|
97
103
|
|
98
|
-
|
99
|
-
|
104
|
+
# ofp_match format
|
105
|
+
class MatchFormat < BinData::Record
|
106
|
+
endian :big
|
107
|
+
|
108
|
+
wildcards :wildcards
|
109
|
+
uint16 :in_port
|
110
|
+
mac_address :ether_source_address
|
111
|
+
mac_address :ether_destination_address
|
112
|
+
uint16 :vlan_vid
|
113
|
+
uint8 :vlan_priority
|
114
|
+
uint8 :padding1
|
115
|
+
hide :padding1
|
116
|
+
uint16 :ether_type
|
117
|
+
uint8 :ip_tos
|
118
|
+
uint8 :ip_protocol
|
119
|
+
uint16 :padding2
|
120
|
+
hide :padding2
|
121
|
+
match_ip_address :ip_source_address,
|
122
|
+
bitcount: -> { wildcards.ip_source_address }
|
123
|
+
match_ip_address :ip_destination_address,
|
124
|
+
bitcount: -> { wildcards.ip_destination_address }
|
125
|
+
uint16 :transport_source_port
|
126
|
+
uint16 :transport_destination_port
|
100
127
|
end
|
101
|
-
end
|
102
128
|
|
103
|
-
|
104
|
-
|
105
|
-
endian :big
|
106
|
-
|
107
|
-
wildcards :wildcards
|
108
|
-
uint16 :in_port
|
109
|
-
mac_address :ether_source_address
|
110
|
-
mac_address :ether_destination_address
|
111
|
-
uint16 :vlan_vid
|
112
|
-
uint8 :vlan_priority
|
113
|
-
uint8 :padding1
|
114
|
-
hide :padding1
|
115
|
-
uint16 :ether_type
|
116
|
-
uint8 :ip_tos
|
117
|
-
uint8 :ip_protocol
|
118
|
-
uint16 :padding2
|
119
|
-
hide :padding2
|
120
|
-
match_ip_address :ip_source_address,
|
121
|
-
bitcount: -> { wildcards.ip_source_address }
|
122
|
-
match_ip_address :ip_destination_address,
|
123
|
-
bitcount: -> { wildcards.ip_destination_address }
|
124
|
-
uint16 :transport_source_port
|
125
|
-
uint16 :transport_destination_port
|
126
|
-
end
|
127
|
-
|
128
|
-
def self.read(binary)
|
129
|
-
MatchFormat.read binary
|
130
|
-
end
|
131
|
-
|
132
|
-
# rubocop:disable MethodLength
|
133
|
-
# This method smells of :reek:FeatureEnvy
|
134
|
-
# This method smells of :reek:DuplicateMethodCall
|
135
|
-
def initialize(user_options)
|
136
|
-
flags = Wildcards::FLAGS.each_with_object({}) do |each, memo|
|
137
|
-
memo[each] = true unless user_options.key?(each)
|
129
|
+
def self.read(binary)
|
130
|
+
MatchFormat.read binary
|
138
131
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
132
|
+
|
133
|
+
# rubocop:disable MethodLength
|
134
|
+
# This method smells of :reek:FeatureEnvy
|
135
|
+
# This method smells of :reek:DuplicateMethodCall
|
136
|
+
def initialize(user_options)
|
137
|
+
flags = Wildcards::FLAGS.each_with_object({}) do |each, memo|
|
138
|
+
memo[each] = true unless user_options.key?(each)
|
139
|
+
end
|
140
|
+
Wildcards::NW_FLAGS.each_with_object(flags) do |each, memo|
|
141
|
+
if user_options.key?(each)
|
142
|
+
memo[each] = 32 - IPv4Address.new(user_options[each]).prefixlen
|
143
|
+
else
|
144
|
+
memo["#{each}_all".intern] = true
|
145
|
+
end
|
144
146
|
end
|
147
|
+
@format = MatchFormat.new({ wildcards: flags }.merge user_options)
|
145
148
|
end
|
146
|
-
|
147
|
-
end
|
148
|
-
# rubocop:enable MethodLength
|
149
|
+
# rubocop:enable MethodLength
|
149
150
|
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
def to_binary
|
152
|
+
@format.to_binary_s
|
153
|
+
end
|
153
154
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
def ==(other)
|
156
|
+
return false unless other
|
157
|
+
to_binary == other.to_binary
|
158
|
+
end
|
158
159
|
|
159
|
-
|
160
|
-
|
160
|
+
def method_missing(method, *args, &block)
|
161
|
+
@format.__send__ method, *args, &block
|
162
|
+
end
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|