pio 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 399c1ee151a9c001cf2f626ae5cb9f20554664f6
4
- data.tar.gz: 5aa7d55d32839bb91f762b1a601c20a72b4da882
3
+ metadata.gz: adb4a96e523a5a2ee14a1ae1e467820a57d1ecda
4
+ data.tar.gz: 16e5ef5fbd1ca5db6d6842adae25c083df64b6b6
5
5
  SHA512:
6
- metadata.gz: 0f990c0cf9aef24a57f1c04a67f8134e1b6972dca1e0573f6274c9adeebddf5768f38266ad60a7766707ff6560cc031696a6ee1b6187794ec3d56374f3b33c61
7
- data.tar.gz: b82319079f8387ef3c52d457bb4f69aff2cb2a34e2b3dcc04e9546534cc5d1ec0f690d162c99ff2a78dada0de47e19815abd8da40274fa0259274d98bd0cef39
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 = Pio::Features::Reply.new(
237
- xid: request.xid,
238
- dpid: 0x123,
239
- n_buffers: 0x100,
240
- n_tables: 0xfe,
241
- capabilities: [:flow_stats, :table_stats, :port_stats,
242
- :queue_stats, :arp_match_ip],
243
- actions: [:output, :set_vlan_vid, :set_vlan_pcp, :strip_vlan,
244
- :set_dl_src, :set_dl_dst, :set_nw_src, :set_nw_dst,
245
- :set_nw_tos, :set_tp_src, :set_tp_dst, :enqueue],
246
- ports: [{ port_no: 1,
247
- hardware_address: '11:22:33:44:55:66',
248
- name: 'port123',
249
- config: [:port_down],
250
- state: [:link_down],
251
- curr: [:port_10gb_fd, :port_copper] }]
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
- transaction_id: 0,
283
- buffer_id: 0xffffff00,
284
- in_port: 1,
285
- reason: :no_match,
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
- data: data_dump)
323
+ raw_data: data_dump)
323
324
  packet_out.to_binary # => Packet-Out message in binary format.
324
325
 
325
326
  ### Flow Mod
@@ -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 = Pio::Features::Reply.new(
9
- xid: request.xid,
10
- dpid: 0x123,
11
- n_buffers: 0x100,
12
- n_tables: 0xfe,
13
- capabilities: [:flow_stats, :table_stats, :port_stats,
14
- :queue_stats, :arp_match_ip],
15
- actions: [:output, :set_vlan_vid, :set_vlan_pcp, :strip_vlan,
16
- :set_dl_src, :set_dl_dst, :set_nw_src, :set_nw_dst,
17
- :set_nw_tos, :set_tp_src, :set_tp_dst, :enqueue],
18
- ports: [{ port_no: 1,
19
- hardware_address: '11:22:33:44:55:66',
20
- name: 'port123',
21
- config: [:port_down],
22
- state: [:link_down],
23
- curr: [:port_10gb_fd, :port_copper] }]
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.
@@ -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
- transaction_id: 0,
14
- buffer_id: 0xffffff00,
15
- in_port: 1,
16
- reason: :no_match,
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.
@@ -14,5 +14,5 @@ packet_out = Pio::PacketOut.new(transaction_id: 0x16,
14
14
  buffer_id: 0xffffffff,
15
15
  in_port: 0xffff,
16
16
  actions: Pio::SendOutPort.new(2),
17
- data: data_dump)
17
+ raw_data: data_dump)
18
18
  packet_out.to_binary # => Packet-Out message in binary format.
@@ -15,6 +15,6 @@ Feature: Pio::PacketIn.read
15
15
  | total_len | 60 |
16
16
  | in_port | 1 |
17
17
  | reason | no_match |
18
- | data.length | 60 |
18
+ | raw_data.length | 60 |
19
19
  | source_mac | ac:5d:10:31:37:79 |
20
20
  | destination_mac | ff:ff:ff:ff:ff:ff |
@@ -17,5 +17,4 @@ Feature: Pio::PacketOut.read
17
17
  | actions.first.class | Pio::SendOutPort |
18
18
  | actions.first.port_number | 2 |
19
19
  | actions.first.max_len | 65535 |
20
- | data.length | 64 |
21
-
20
+ | raw_data.length | 64 |
@@ -11,7 +11,7 @@ module Pio
11
11
 
12
12
  endian :big
13
13
 
14
- ethernet_header ether_type: 0x0806
14
+ ethernet_header ether_type: EtherType::ARP
15
15
  uint16 :hardware_type, value: 1
16
16
  uint16 :protocol_type, value: 0x0800
17
17
  uint8 :hardware_length, value: 6
@@ -17,8 +17,8 @@ module Pio
17
17
  include UdpHeader
18
18
 
19
19
  endian :big
20
- ethernet_header ether_type: EthernetHeader::ETHER_TYPE_IP
21
- ipv4_header ip_protocol: IPv4Header::IP_PROTOCOL_UDP
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
@@ -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
- ETHER_TYPE_IP = 0x0800
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
- # rubocop:disable AbcSize
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 :ether_type_internal, initial_value: options[:ether_type] || 0
15
- bit3 :vlan_pcp_internal, onlyif: -> { vlan? }
16
- bit1 :vlan_cfi, onlyif: -> { vlan? }
17
- bit12 :vlan_vid_internal, onlyif: -> { vlan? }
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 == 0x8100
36
+ ether_type == EtherType::VLAN
38
37
  end
39
38
  end
40
39
  end
@@ -6,7 +6,7 @@ module Pio
6
6
  # rubocop:disable MethodLength
7
7
  # rubocop:disable AbcSize
8
8
  def initialize(packet_in)
9
- data = packet_in.parsed_data
9
+ data = packet_in.data
10
10
  case data
11
11
  when PacketIn::DataParser::IPv4Packet
12
12
  options = {
data/lib/pio/features.rb CHANGED
@@ -7,6 +7,7 @@ module Pio
7
7
  class Request; end
8
8
  OpenFlow::Message.factory(Request, OpenFlow::FEATURES_REQUEST)
9
9
 
10
+ # OpenFlow 1.0 Features Reply message.
10
11
  class Reply
11
12
  # Message body of features reply.
12
13
  class Body < BinData::Record
@@ -13,8 +13,8 @@ module Pio
13
13
 
14
14
  endian :big
15
15
 
16
- ethernet_header ether_type: EthernetHeader::ETHER_TYPE_IP
17
- ipv4_header ip_protocol: IPv4Header::IP_PROTOCOL_ICMP
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
@@ -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
@@ -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
- include Payload
7
+ # Internet protocol numbers for ipv4_header.ip_protocol
8
+ module ProtocolNumber
9
+ ICMP = 1
10
+ UDP = 17
11
+ end
8
12
 
9
- IP_PROTOCOL_ICMP = 1
10
- IP_PROTOCOL_UDP = 17
13
+ include Payload
11
14
 
12
15
  # rubocop:disable MethodLength
13
16
  # rubocop:disable AbcSize
@@ -14,7 +14,7 @@ module Pio
14
14
 
15
15
  endian :big
16
16
 
17
- ethernet_header ether_type: 0x88cc
17
+ ethernet_header ether_type: EtherType::LLDP
18
18
  chassis_id_tlv :chassis_id
19
19
  port_id_tlv :port_id
20
20
  ttl_tlv :ttl, initial_value: 120
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: -> { data.length }
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 :data, read_length: :total_len
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 + data.length
44
+ 10 + raw_data.length
45
45
  end
46
46
  end
47
47
 
48
- # Pio::PacketIn#data parser
48
+ # Pio::PacketIn#raw_data parser
49
49
  class DataParser
50
50
  # Ethernet header parser
51
- class EthernetHeaderParser < BinData::Record
52
- include EthernetHeader
53
-
51
+ class EtherTypeParser < BinData::Record
54
52
  endian :big
55
53
 
56
- ethernet_header
57
- rest :payload
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 = EthernetHeaderParser.read(raw_data)
76
+ ethernet_header = EtherTypeParser.read(raw_data)
78
77
  case ethernet_header.ether_type
79
- when 0x0800
78
+ when EthernetHeader::EtherType::IPV4
80
79
  IPv4Packet.read raw_data
81
- when 0x0806
80
+ when EthernetHeader::EtherType::ARP
82
81
  Pio::Arp.read raw_data
83
- when 0x88cc
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, :data
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 parsed_data
105
- @parsed_data ||= PacketIn::DataParser.read(data)
103
+ def data
104
+ @data ||= PacketIn::DataParser.read(raw_data)
106
105
  end
107
106
 
108
107
  def lldp?
109
- parsed_data.is_a? Lldp
110
- end
111
-
112
- def source_mac
113
- parsed_data.source_mac
108
+ data.is_a? Lldp
114
109
  end
115
110
 
116
- def destination_mac
117
- parsed_data.destination_mac
111
+ def method_missing(method, *args)
112
+ data.__send__ method, *args
118
113
  end
119
114
  end
120
115
  end
@@ -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 :data
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 + data.length
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, :data
33
+ def_delegators :body, :raw_data
34
34
  end
35
35
  end