pio 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +26 -25
- data/examples/features_new.rb +20 -17
- data/examples/packet_in_new.rb +5 -7
- data/examples/packet_out_new.rb +1 -1
- data/features/packet_in_read.feature +1 -1
- data/features/packet_out_read.feature +1 -2
- data/lib/pio/arp/format.rb +1 -1
- data/lib/pio/dhcp/frame.rb +2 -2
- data/lib/pio/ethernet_header.rb +15 -16
- data/lib/pio/exact_match.rb +1 -1
- data/lib/pio/features.rb +1 -0
- data/lib/pio/icmp/format.rb +2 -2
- data/lib/pio/ipv4_address.rb +8 -0
- data/lib/pio/ipv4_header.rb +6 -3
- data/lib/pio/lldp/frame.rb +1 -1
- data/lib/pio/packet_in.rb +19 -24
- data/lib/pio/packet_out.rb +3 -3
- data/lib/pio/udp.rb +2 -2
- data/lib/pio/udp_header.rb +1 -1
- data/lib/pio/version.rb +1 -1
- data/pio.gemspec +5 -5
- data/spec/pio/arp_spec.rb +2 -2
- data/spec/pio/ipv4_address_spec.rb +200 -232
- data/spec/pio/packet_in_spec.rb +7 -7
- data/spec/pio/packet_out_spec.rb +17 -17
- metadata +90 -90
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adb4a96e523a5a2ee14a1ae1e467820a57d1ecda
|
4
|
+
data.tar.gz: 16e5ef5fbd1ca5db6d6842adae25c083df64b6b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51b278154025ee26b185c8e986c1d3f22a4be577ee00fcb5020724223fdd7824b4f7b3785259a4de11beeb0ffeb2ca6d50e1f3f770faf88c6e0415901672ffdc
|
7
|
+
data.tar.gz: d751e889d588d75e1d909724711e7e12b47deb16273f56a28eeef72dabbbfdf1319393fce1acb85c06e8dd140134b442b31c112f2948a986b5a936d76ee58a29
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,13 @@
|
|
3
3
|
## develop (unreleased)
|
4
4
|
|
5
5
|
|
6
|
+
## 0.17.0 (3/6/2015)
|
7
|
+
### Changes
|
8
|
+
* Renamed `Pio::PacketIn#data` => `Pio::PacketIn#raw_data`.
|
9
|
+
* Renamed `Pio::PacketOut#data` => `Pio::PacketOut#raw_data`.
|
10
|
+
* Fix behavior of `IPv4Address#eql?` and `IPv4Address#hash`.
|
11
|
+
|
12
|
+
|
6
13
|
## 0.16.0 (3/2/2015)
|
7
14
|
### New features
|
8
15
|
* [#129](https://github.com/trema/pio/pull/129): Add new class `Pio::Udp`.
|
data/README.md
CHANGED
@@ -233,23 +233,26 @@ generate an Features Request/Reply message like below:
|
|
233
233
|
|
234
234
|
# The Features xid (transaction_id)
|
235
235
|
# should be same as that of the request.
|
236
|
-
reply =
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
236
|
+
reply =
|
237
|
+
Pio::Features::Reply.new(xid: request.xid,
|
238
|
+
dpid: 0x123,
|
239
|
+
n_buffers: 0x100,
|
240
|
+
n_tables: 0xfe,
|
241
|
+
capabilities: [:flow_stats, :table_stats,
|
242
|
+
:port_stats, :queue_stats,
|
243
|
+
:arp_match_ip],
|
244
|
+
actions: [:output, :set_vlan_vid,
|
245
|
+
:set_vlan_pcp, :strip_vlan,
|
246
|
+
:set_dl_src, :set_dl_dst,
|
247
|
+
:set_nw_src, :set_nw_dst,
|
248
|
+
:set_nw_tos, :set_tp_src,
|
249
|
+
:set_tp_dst, :enqueue],
|
250
|
+
ports: [{ port_no: 1,
|
251
|
+
hardware_address: '11:22:33:44:55:66',
|
252
|
+
name: 'port123',
|
253
|
+
config: [:port_down],
|
254
|
+
state: [:link_down],
|
255
|
+
curr: [:port_10gb_fd, :port_copper] }])
|
253
256
|
reply.to_binary # => Features Reply message in binary format.
|
254
257
|
|
255
258
|
### Packet-In
|
@@ -278,13 +281,11 @@ like below:
|
|
278
281
|
0x00, 0x00, 0x00, 0x00, 0x00
|
279
282
|
].pack('C*')
|
280
283
|
|
281
|
-
packet_in = Pio::PacketIn.new(
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
data: data_dump
|
287
|
-
)
|
284
|
+
packet_in = Pio::PacketIn.new(transaction_id: 0,
|
285
|
+
buffer_id: 0xffffff00,
|
286
|
+
in_port: 1,
|
287
|
+
reason: :no_match,
|
288
|
+
raw_data: data_dump)
|
288
289
|
packet_in.to_binary # => Packet-In message in binary format.
|
289
290
|
|
290
291
|
### Packet-Out
|
@@ -319,7 +320,7 @@ like below:
|
|
319
320
|
buffer_id: 0xffffffff,
|
320
321
|
in_port: 0xffff,
|
321
322
|
actions: Pio::SendOutPort.new(2),
|
322
|
-
|
323
|
+
raw_data: data_dump)
|
323
324
|
packet_out.to_binary # => Packet-Out message in binary format.
|
324
325
|
|
325
326
|
### Flow Mod
|
data/examples/features_new.rb
CHANGED
@@ -5,21 +5,24 @@ request.to_binary # => Features Request message in binary format.
|
|
5
5
|
|
6
6
|
# The Features xid (transaction_id)
|
7
7
|
# should be same as that of the request.
|
8
|
-
reply =
|
9
|
-
xid: request.xid,
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
8
|
+
reply =
|
9
|
+
Pio::Features::Reply.new(xid: request.xid,
|
10
|
+
dpid: 0x123,
|
11
|
+
n_buffers: 0x100,
|
12
|
+
n_tables: 0xfe,
|
13
|
+
capabilities: [:flow_stats, :table_stats,
|
14
|
+
:port_stats, :queue_stats,
|
15
|
+
:arp_match_ip],
|
16
|
+
actions: [:output, :set_vlan_vid,
|
17
|
+
:set_vlan_pcp, :strip_vlan,
|
18
|
+
:set_dl_src, :set_dl_dst,
|
19
|
+
:set_nw_src, :set_nw_dst,
|
20
|
+
:set_nw_tos, :set_tp_src,
|
21
|
+
:set_tp_dst, :enqueue],
|
22
|
+
ports: [{ port_no: 1,
|
23
|
+
hardware_address: '11:22:33:44:55:66',
|
24
|
+
name: 'port123',
|
25
|
+
config: [:port_down],
|
26
|
+
state: [:link_down],
|
27
|
+
curr: [:port_10gb_fd, :port_copper] }])
|
25
28
|
reply.to_binary # => Features Reply message in binary format.
|
data/examples/packet_in_new.rb
CHANGED
@@ -9,11 +9,9 @@ data_dump = [
|
|
9
9
|
0x00, 0x00, 0x00, 0x00, 0x00
|
10
10
|
].pack('C*')
|
11
11
|
|
12
|
-
packet_in = Pio::PacketIn.new(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
data: data_dump
|
18
|
-
)
|
12
|
+
packet_in = Pio::PacketIn.new(transaction_id: 0,
|
13
|
+
buffer_id: 0xffffff00,
|
14
|
+
in_port: 1,
|
15
|
+
reason: :no_match,
|
16
|
+
raw_data: data_dump)
|
19
17
|
packet_in.to_binary # => Packet-In message in binary format.
|
data/examples/packet_out_new.rb
CHANGED
data/lib/pio/arp/format.rb
CHANGED
data/lib/pio/dhcp/frame.rb
CHANGED
@@ -17,8 +17,8 @@ module Pio
|
|
17
17
|
include UdpHeader
|
18
18
|
|
19
19
|
endian :big
|
20
|
-
ethernet_header ether_type:
|
21
|
-
ipv4_header ip_protocol:
|
20
|
+
ethernet_header ether_type: EtherType::IPV4
|
21
|
+
ipv4_header ip_protocol: ProtocolNumber::UDP
|
22
22
|
udp_header
|
23
23
|
dhcp_field :dhcp
|
24
24
|
string :padding, read_length: 0, initial_value: :ff_and_padding
|
data/lib/pio/ethernet_header.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
require 'pio/type/mac_address'
|
2
2
|
|
3
|
-
# Base module
|
4
3
|
module Pio
|
5
4
|
# Adds ethernet_header macro.
|
6
5
|
module EthernetHeader
|
7
|
-
|
6
|
+
# EtherType constants for ethernet_header.ether_type.
|
7
|
+
module EtherType
|
8
|
+
ARP = 0x0806
|
9
|
+
IPV4 = 0x0800
|
10
|
+
VLAN = 0x8100
|
11
|
+
LLDP = 0x88cc
|
12
|
+
end
|
8
13
|
|
9
|
-
#
|
14
|
+
# This method smells of :reek:TooManyStatements
|
10
15
|
def self.included(klass)
|
11
|
-
def klass.ethernet_header(options
|
16
|
+
def klass.ethernet_header(options)
|
12
17
|
mac_address :destination_mac
|
13
18
|
mac_address :source_mac
|
14
|
-
uint16 :
|
15
|
-
bit3 :vlan_pcp_internal, onlyif:
|
16
|
-
bit1 :vlan_cfi, onlyif:
|
17
|
-
bit12 :vlan_vid_internal, onlyif:
|
18
|
-
uint16 :ether_type_vlan,
|
19
|
-
onlyif: -> { vlan? }, initial_value: options[:ether_type] || 0
|
19
|
+
uint16 :ether_type, value: options.fetch(:ether_type)
|
20
|
+
bit3 :vlan_pcp_internal, onlyif: :vlan?
|
21
|
+
bit1 :vlan_cfi, onlyif: :vlan?
|
22
|
+
bit12 :vlan_vid_internal, onlyif: :vlan?
|
23
|
+
uint16 :ether_type_vlan, value: :ether_type, onlyif: :vlan?
|
20
24
|
end
|
21
25
|
end
|
22
|
-
# rubocop:enable AbcSize
|
23
|
-
|
24
|
-
def ether_type
|
25
|
-
ether_type_internal
|
26
|
-
end
|
27
26
|
|
28
27
|
def vlan_vid
|
29
28
|
vlan? ? vlan_vid_internal : 0xffff
|
@@ -34,7 +33,7 @@ module Pio
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def vlan?
|
37
|
-
ether_type ==
|
36
|
+
ether_type == EtherType::VLAN
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
data/lib/pio/exact_match.rb
CHANGED
data/lib/pio/features.rb
CHANGED
data/lib/pio/icmp/format.rb
CHANGED
@@ -13,8 +13,8 @@ module Pio
|
|
13
13
|
|
14
14
|
endian :big
|
15
15
|
|
16
|
-
ethernet_header ether_type:
|
17
|
-
ipv4_header ip_protocol:
|
16
|
+
ethernet_header ether_type: EtherType::IPV4
|
17
|
+
ipv4_header ip_protocol: ProtocolNumber::ICMP
|
18
18
|
uint8 :icmp_type
|
19
19
|
uint8 :icmp_code, initial_value: 0
|
20
20
|
uint16 :icmp_checksum, value: :calculate_icmp_checksum
|
data/lib/pio/ipv4_address.rb
CHANGED
@@ -42,6 +42,14 @@ module Pio
|
|
42
42
|
|
43
43
|
def_delegator :value, :==
|
44
44
|
|
45
|
+
def eql?(other)
|
46
|
+
@value == other.value
|
47
|
+
end
|
48
|
+
|
49
|
+
def hash
|
50
|
+
to_s.hash
|
51
|
+
end
|
52
|
+
|
45
53
|
# @return [Number] prefix length of IPv4 address.
|
46
54
|
def prefixlen
|
47
55
|
netmask = to_range.first.to_i ^ to_range.last.to_i
|
data/lib/pio/ipv4_header.rb
CHANGED
@@ -4,10 +4,13 @@ require 'pio/type/ip_address'
|
|
4
4
|
module Pio
|
5
5
|
# IP Version 4 Header Format
|
6
6
|
module IPv4Header
|
7
|
-
|
7
|
+
# Internet protocol numbers for ipv4_header.ip_protocol
|
8
|
+
module ProtocolNumber
|
9
|
+
ICMP = 1
|
10
|
+
UDP = 17
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
IP_PROTOCOL_UDP = 17
|
13
|
+
include Payload
|
11
14
|
|
12
15
|
# rubocop:disable MethodLength
|
13
16
|
# rubocop:disable AbcSize
|
data/lib/pio/lldp/frame.rb
CHANGED
data/lib/pio/packet_in.rb
CHANGED
@@ -29,32 +29,31 @@ module Pio
|
|
29
29
|
endian :big
|
30
30
|
|
31
31
|
uint32 :buffer_id
|
32
|
-
uint16 :total_len, value: -> {
|
32
|
+
uint16 :total_len, value: -> { raw_data.length }
|
33
33
|
uint16 :in_port
|
34
34
|
reason :reason
|
35
35
|
uint8 :padding
|
36
36
|
hide :padding
|
37
|
-
string :
|
37
|
+
string :raw_data, read_length: :total_len
|
38
38
|
|
39
39
|
def empty?
|
40
40
|
false
|
41
41
|
end
|
42
42
|
|
43
43
|
def length
|
44
|
-
10 +
|
44
|
+
10 + raw_data.length
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# Pio::PacketIn#
|
48
|
+
# Pio::PacketIn#raw_data parser
|
49
49
|
class DataParser
|
50
50
|
# Ethernet header parser
|
51
|
-
class
|
52
|
-
include EthernetHeader
|
53
|
-
|
51
|
+
class EtherTypeParser < BinData::Record
|
54
52
|
endian :big
|
55
53
|
|
56
|
-
|
57
|
-
|
54
|
+
mac_address :destination_mac
|
55
|
+
mac_address :source_mac
|
56
|
+
uint16 :ether_type
|
58
57
|
end
|
59
58
|
|
60
59
|
# IPv4 packet parser
|
@@ -64,7 +63,7 @@ module Pio
|
|
64
63
|
|
65
64
|
endian :big
|
66
65
|
|
67
|
-
ethernet_header
|
66
|
+
ethernet_header ether_type: EtherType::IPV4
|
68
67
|
ipv4_header
|
69
68
|
|
70
69
|
uint16 :transport_source_port
|
@@ -74,13 +73,13 @@ module Pio
|
|
74
73
|
|
75
74
|
# rubocop:disable MethodLength
|
76
75
|
def self.read(raw_data)
|
77
|
-
ethernet_header =
|
76
|
+
ethernet_header = EtherTypeParser.read(raw_data)
|
78
77
|
case ethernet_header.ether_type
|
79
|
-
when
|
78
|
+
when EthernetHeader::EtherType::IPV4
|
80
79
|
IPv4Packet.read raw_data
|
81
|
-
when
|
80
|
+
when EthernetHeader::EtherType::ARP
|
82
81
|
Pio::Arp.read raw_data
|
83
|
-
when
|
82
|
+
when EthernetHeader::EtherType::LLDP
|
84
83
|
Pio::Lldp.read raw_data
|
85
84
|
else
|
86
85
|
fail 'Failed to parse packet_in data.'
|
@@ -95,26 +94,22 @@ module Pio
|
|
95
94
|
def_delegators :body, :total_len
|
96
95
|
def_delegators :body, :in_port
|
97
96
|
def_delegators :body, :reason
|
98
|
-
def_delegators :body, :
|
97
|
+
def_delegators :body, :raw_data
|
99
98
|
|
100
99
|
attr_accessor :datapath_id
|
101
100
|
alias_method :dpid, :datapath_id
|
102
101
|
alias_method :dpid=, :datapath_id=
|
103
102
|
|
104
|
-
def
|
105
|
-
@
|
103
|
+
def data
|
104
|
+
@data ||= PacketIn::DataParser.read(raw_data)
|
106
105
|
end
|
107
106
|
|
108
107
|
def lldp?
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
def source_mac
|
113
|
-
parsed_data.source_mac
|
108
|
+
data.is_a? Lldp
|
114
109
|
end
|
115
110
|
|
116
|
-
def
|
117
|
-
|
111
|
+
def method_missing(method, *args)
|
112
|
+
data.__send__ method, *args
|
118
113
|
end
|
119
114
|
end
|
120
115
|
end
|
data/lib/pio/packet_out.rb
CHANGED
@@ -13,14 +13,14 @@ module Pio
|
|
13
13
|
uint16 :in_port
|
14
14
|
uint16 :actions_len, initial_value: -> { actions.binary.length }
|
15
15
|
actions :actions, length: -> { actions_len }
|
16
|
-
rest :
|
16
|
+
rest :raw_data
|
17
17
|
|
18
18
|
def empty?
|
19
19
|
false
|
20
20
|
end
|
21
21
|
|
22
22
|
def length
|
23
|
-
8 + actions_len +
|
23
|
+
8 + actions_len + raw_data.length
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -30,6 +30,6 @@ module Pio
|
|
30
30
|
def_delegators :body, :in_port
|
31
31
|
def_delegators :body, :actions_len
|
32
32
|
def_delegators :body, :actions
|
33
|
-
def_delegators :body, :
|
33
|
+
def_delegators :body, :raw_data
|
34
34
|
end
|
35
35
|
end
|