pio 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/README.md +24 -11
  4. data/Rakefile +0 -2
  5. data/examples/features_new.rb +17 -6
  6. data/features/packet_data/aggregate_stats_reply.raw +0 -0
  7. data/features/packet_data/aggregate_stats_request.raw +0 -0
  8. data/features/packet_data/barrier_reply.raw +0 -0
  9. data/features/packet_data/barrier_request.raw +0 -0
  10. data/features/packet_data/desc_stats_reply.raw +0 -0
  11. data/features/packet_data/desc_stats_request.raw +0 -0
  12. data/features/packet_data/echo_reply.raw +0 -0
  13. data/features/packet_data/echo_request.raw +0 -0
  14. data/features/packet_data/error.raw +0 -0
  15. data/features/packet_data/features_reply.raw +0 -0
  16. data/features/packet_data/flow_mod_add.raw +0 -0
  17. data/features/packet_data/flow_mod_delete.raw +0 -0
  18. data/features/packet_data/flow_removed.raw +0 -0
  19. data/features/packet_data/flow_stats_reply.raw +0 -0
  20. data/features/packet_data/flow_stats_request.raw +0 -0
  21. data/features/packet_data/get_config_reply.raw +0 -0
  22. data/features/packet_data/get_config_request.raw +0 -0
  23. data/features/packet_data/hello.raw +0 -0
  24. data/features/packet_data/packet_in.raw +0 -0
  25. data/features/packet_data/packet_out.raw +0 -0
  26. data/features/packet_data/port_mod.raw +0 -0
  27. data/features/packet_data/port_stats_reply.raw +0 -0
  28. data/features/packet_data/port_stats_request.raw +0 -0
  29. data/features/packet_data/port_status.raw +0 -0
  30. data/features/packet_data/queue_get_config_reply.raw +0 -0
  31. data/features/packet_data/queue_get_config_request.raw +0 -0
  32. data/features/packet_data/set_config.raw +0 -0
  33. data/features/packet_data/table_stats_reply.raw +0 -0
  34. data/features/packet_data/table_stats_request.raw +0 -0
  35. data/features/packet_data/vendor.raw +0 -0
  36. data/features/packet_data/vendor_stats_request.raw +0 -0
  37. data/features/step_definitions/packet_data_steps.rb +0 -2
  38. data/features/step_definitions/pending_steps.rb +0 -2
  39. data/features/support/env.rb +0 -2
  40. data/lib/pio.rb +0 -2
  41. data/lib/pio/arp.rb +0 -2
  42. data/lib/pio/arp/format.rb +0 -2
  43. data/lib/pio/arp/message.rb +14 -22
  44. data/lib/pio/arp/reply.rb +0 -2
  45. data/lib/pio/arp/request.rb +0 -2
  46. data/lib/pio/dhcp.rb +0 -2
  47. data/lib/pio/dhcp/ack.rb +0 -2
  48. data/lib/pio/dhcp/boot_reply.rb +0 -2
  49. data/lib/pio/dhcp/boot_reply_options.rb +0 -2
  50. data/lib/pio/dhcp/boot_request.rb +0 -2
  51. data/lib/pio/dhcp/boot_request_options.rb +0 -2
  52. data/lib/pio/dhcp/client_id.rb +0 -2
  53. data/lib/pio/dhcp/common_options.rb +0 -2
  54. data/lib/pio/dhcp/csum_util.rb +0 -2
  55. data/lib/pio/dhcp/dhcp_field.rb +0 -2
  56. data/lib/pio/dhcp/dhcp_tlv_options.rb +0 -2
  57. data/lib/pio/dhcp/discover.rb +0 -2
  58. data/lib/pio/dhcp/field_util.rb +0 -2
  59. data/lib/pio/dhcp/frame.rb +0 -2
  60. data/lib/pio/dhcp/message.rb +0 -2
  61. data/lib/pio/dhcp/offer.rb +0 -2
  62. data/lib/pio/dhcp/optional_tlv.rb +0 -2
  63. data/lib/pio/dhcp/parameter_list.rb +0 -2
  64. data/lib/pio/dhcp/request.rb +0 -2
  65. data/lib/pio/echo.rb +3 -6
  66. data/lib/pio/echo/format.rb +10 -6
  67. data/lib/pio/echo/message.rb +16 -41
  68. data/lib/pio/echo/reply.rb +8 -7
  69. data/lib/pio/echo/request.rb +6 -6
  70. data/lib/pio/features.rb +15 -9
  71. data/lib/pio/features/reply.rb +79 -44
  72. data/lib/pio/features/request.rb +30 -28
  73. data/lib/pio/hello.rb +17 -29
  74. data/lib/pio/hello/format.rb +8 -8
  75. data/lib/pio/icmp.rb +0 -2
  76. data/lib/pio/icmp/format.rb +0 -2
  77. data/lib/pio/icmp/message.rb +23 -31
  78. data/lib/pio/icmp/options.rb +0 -2
  79. data/lib/pio/icmp/reply.rb +2 -4
  80. data/lib/pio/icmp/request.rb +0 -2
  81. data/lib/pio/ipv4_address.rb +1 -5
  82. data/lib/pio/lldp.rb +0 -2
  83. data/lib/pio/lldp/chassis_id_tlv.rb +0 -2
  84. data/lib/pio/lldp/end_of_lldpdu_value.rb +0 -2
  85. data/lib/pio/lldp/frame.rb +0 -2
  86. data/lib/pio/lldp/management_address_value.rb +0 -2
  87. data/lib/pio/lldp/optional_tlv.rb +0 -2
  88. data/lib/pio/lldp/options.rb +0 -2
  89. data/lib/pio/lldp/organizationally_specific_value.rb +0 -2
  90. data/lib/pio/lldp/port_description_value.rb +0 -2
  91. data/lib/pio/lldp/port_id_tlv.rb +0 -2
  92. data/lib/pio/lldp/system_capabilities_value.rb +0 -2
  93. data/lib/pio/lldp/system_description_value.rb +0 -2
  94. data/lib/pio/lldp/system_name_value.rb +0 -2
  95. data/lib/pio/lldp/ttl_tlv.rb +0 -2
  96. data/lib/pio/mac.rb +2 -6
  97. data/lib/pio/message_type_selector.rb +5 -4
  98. data/lib/pio/open_flow.rb +5 -0
  99. data/lib/pio/open_flow/flags.rb +38 -0
  100. data/lib/pio/open_flow/message.rb +20 -0
  101. data/lib/pio/open_flow/open_flow_header.rb +18 -0
  102. data/lib/pio/open_flow/phy_port.rb +74 -0
  103. data/lib/pio/open_flow/type.rb +12 -0
  104. data/lib/pio/options.rb +0 -2
  105. data/lib/pio/parse_error.rb +0 -2
  106. data/lib/pio/pcap.rb +0 -2
  107. data/lib/pio/type/ethernet_header.rb +0 -2
  108. data/lib/pio/type/ip_address.rb +0 -2
  109. data/lib/pio/type/ipv4_header.rb +2 -2
  110. data/lib/pio/type/mac_address.rb +6 -3
  111. data/lib/pio/type/udp_header.rb +0 -2
  112. data/lib/pio/version.rb +1 -3
  113. data/pio.gemspec +18 -20
  114. data/spec/pio/arp/reply/options_spec.rb +0 -2
  115. data/spec/pio/arp/reply_spec.rb +0 -2
  116. data/spec/pio/arp/request/options_spec.rb +0 -2
  117. data/spec/pio/arp/request_spec.rb +0 -2
  118. data/spec/pio/arp_spec.rb +0 -2
  119. data/spec/pio/dhcp/ack_spec.rb +0 -2
  120. data/spec/pio/dhcp/discover_spec.rb +0 -2
  121. data/spec/pio/dhcp/offer_spec.rb +0 -2
  122. data/spec/pio/dhcp/request_spec.rb +0 -2
  123. data/spec/pio/dhcp_spec.rb +0 -2
  124. data/spec/pio/echo/reply_spec.rb +13 -15
  125. data/spec/pio/echo/request_spec.rb +15 -15
  126. data/spec/pio/echo_spec.rb +5 -7
  127. data/spec/pio/features/reply_spec.rb +47 -17
  128. data/spec/pio/features/request_spec.rb +6 -11
  129. data/spec/pio/features_spec.rb +70 -51
  130. data/spec/pio/hello_spec.rb +1 -3
  131. data/spec/pio/icmp/reply_spec.rb +0 -2
  132. data/spec/pio/icmp/request_spec.rb +0 -2
  133. data/spec/pio/icmp_spec.rb +0 -2
  134. data/spec/pio/ipv4_address_spec.rb +0 -2
  135. data/spec/pio/lldp/options_spec.rb +0 -2
  136. data/spec/pio/lldp_spec.rb +0 -2
  137. data/spec/pio/mac_spec.rb +0 -1
  138. data/spec/pio/open_flow/phy_port_spec.rb +25 -0
  139. data/spec/pio/open_flow/type_spec.rb +5 -0
  140. data/spec/spec_helper.rb +9 -24
  141. metadata +105 -40
  142. data/lib/pio/features/format.rb +0 -18
  143. data/lib/pio/features/message.rb +0 -14
  144. data/lib/pio/type/open_flow.rb +0 -34
@@ -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
- uint8 :ofp_version, value: 1
12
- uint8 :message_type, initial_value: 0, assert: -> { value == 0 }
13
- uint16 :message_length, initial_value: 8
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
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'pio/icmp/format'
4
2
  require 'pio/icmp/reply'
5
3
  require 'pio/icmp/request'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
  require 'pio/type/ethernet_header'
5
3
  require 'pio/type/ipv4_header'
@@ -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 :@frame, :destination_mac
13
- def_delegators :@frame, :source_mac
14
- def_delegators :@frame, :ether_type
15
- def_delegators :@frame, :ip_version
16
- def_delegators :@frame, :ip_header_length
17
- def_delegators :@frame, :ip_type_of_service
18
- def_delegators :@frame, :ip_total_length
19
- def_delegators :@frame, :ip_identifier
20
- def_delegators :@frame, :ip_flag
21
- def_delegators :@frame, :ip_fragment
22
- def_delegators :@frame, :ip_ttl
23
- def_delegators :@frame, :ip_protocol
24
- def_delegators :@frame, :ip_header_checksum
25
- def_delegators :@frame, :ip_source_address
26
- def_delegators :@frame, :ip_destination_address
27
- def_delegators :@frame, :icmp_type
28
- def_delegators :@frame, :icmp_code
29
- def_delegators :@frame, :icmp_checksum
30
- def_delegators :@frame, :icmp_identifier
31
- def_delegators :@frame, :icmp_sequence_number
32
- def_delegators :@frame, :echo_data
33
- def_delegators :@frame, :to_binary
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
- @frame = Icmp::Format.new(options.to_hash)
37
+ @format = Icmp::Format.new(options.to_hash)
46
38
  end
47
39
  end
48
40
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'pio/options'
4
2
 
5
3
  module Pio
@@ -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
@@ -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'
@@ -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 do | each |
63
- each.to_i
64
- end
60
+ to_s.split('.').map(&:to_i)
65
61
  end
66
62
 
67
63
  # @return [Array]
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'English'
4
2
  require 'forwardable'
5
3
  require 'pio/lldp/frame'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  require 'pio/lldp/chassis_id_tlv'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'pio/lldp/port_description_value'
4
2
  require 'pio/lldp/system_name_value'
5
3
  require 'pio/lldp/system_description_value'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'pio/options'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bindata'
4
2
 
5
3
  module Pio
@@ -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 do | each |
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
- ( to_i >> 8) == 0x0180c20000
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
- parsed = const_get(:Format).read(raw_data)
14
- const_get(:MESSAGE_TYPE)[parsed.message_type].create_from parsed
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,5 @@
1
+ require 'pio/open_flow/flags'
2
+ require 'pio/open_flow/message'
3
+ require 'pio/open_flow/open_flow_header'
4
+ require 'pio/open_flow/phy_port'
5
+ require 'pio/open_flow/type'
@@ -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