openflow-protocol 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openflow-protocol.rb +2 -1
  3. data/lib/openflow-protocol/actions/action.rb +30 -0
  4. data/lib/openflow-protocol/actions/action_enqueue.rb +16 -0
  5. data/lib/openflow-protocol/actions/action_output.rb +14 -0
  6. data/lib/openflow-protocol/actions/action_set_destination_port.rb +7 -0
  7. data/lib/openflow-protocol/actions/action_set_ip_destination.rb +7 -0
  8. data/lib/openflow-protocol/actions/action_set_ip_source.rb +13 -0
  9. data/lib/openflow-protocol/actions/action_set_ip_tos.rb +15 -0
  10. data/lib/openflow-protocol/actions/action_set_mac_destination.rb +7 -0
  11. data/lib/openflow-protocol/actions/action_set_mac_source.rb +15 -0
  12. data/lib/openflow-protocol/actions/action_set_source_port.rb +15 -0
  13. data/lib/openflow-protocol/actions/action_set_vlan_id.rb +15 -0
  14. data/lib/openflow-protocol/actions/action_set_vlan_pcp.rb +15 -0
  15. data/lib/openflow-protocol/actions/action_strip_vlan.rb +14 -0
  16. data/lib/openflow-protocol/actions/action_vendor.rb +13 -0
  17. data/lib/openflow-protocol/actions/actions.rb +9 -0
  18. data/lib/openflow-protocol/helpers/array_of_subclasses.rb +42 -0
  19. data/lib/openflow-protocol/helpers/superclass_base.rb +26 -0
  20. data/lib/openflow-protocol/messages/barrier_reply.rb +7 -0
  21. data/lib/openflow-protocol/messages/barrier_request.rb +7 -0
  22. data/lib/openflow-protocol/messages/echo_reply.rb +13 -0
  23. data/lib/openflow-protocol/messages/echo_request.rb +13 -0
  24. data/lib/openflow-protocol/messages/error.rb +69 -0
  25. data/lib/openflow-protocol/messages/features_reply.rb +44 -0
  26. data/lib/openflow-protocol/messages/features_request.rb +7 -0
  27. data/lib/openflow-protocol/messages/flow_mod.rb +24 -0
  28. data/lib/openflow-protocol/messages/flow_removed.rb +27 -0
  29. data/lib/openflow-protocol/messages/get_config_reply.rb +16 -0
  30. data/lib/openflow-protocol/messages/get_config_request.rb +7 -0
  31. data/lib/openflow-protocol/messages/hello.rb +7 -0
  32. data/lib/openflow-protocol/messages/message.rb +49 -0
  33. data/lib/openflow-protocol/messages/packet_in.rb +27 -0
  34. data/lib/openflow-protocol/messages/packet_out.rb +17 -0
  35. data/lib/openflow-protocol/messages/parser.rb +26 -0
  36. data/lib/openflow-protocol/messages/port_mod.rb +19 -0
  37. data/lib/openflow-protocol/messages/port_status.rb +18 -0
  38. data/lib/openflow-protocol/messages/queue_get_config_reply.rb +18 -0
  39. data/lib/openflow-protocol/messages/queue_get_config_request.rb +15 -0
  40. data/lib/openflow-protocol/messages/set_config.rb +7 -0
  41. data/lib/openflow-protocol/messages/statistics.rb +28 -0
  42. data/lib/openflow-protocol/messages/statistics/aggregate_statistics_reply.rb +14 -0
  43. data/lib/openflow-protocol/messages/statistics/aggregate_statistics_request.rb +7 -0
  44. data/lib/openflow-protocol/messages/statistics/description_statistics.rb +32 -0
  45. data/lib/openflow-protocol/messages/statistics/flow_statistics_reply.rb +25 -0
  46. data/lib/openflow-protocol/messages/statistics/flow_statistics_request.rb +14 -0
  47. data/lib/openflow-protocol/messages/statistics/port_statistics_reply.rb +24 -0
  48. data/lib/openflow-protocol/messages/statistics/port_statistics_request.rb +12 -0
  49. data/lib/openflow-protocol/messages/statistics/queue_statistics_reply.rb +16 -0
  50. data/lib/openflow-protocol/messages/statistics/queue_statistics_request.rb +13 -0
  51. data/lib/openflow-protocol/messages/statistics/table_statistics.rb +20 -0
  52. data/lib/openflow-protocol/messages/statistics/vendor_statistics.rb +11 -0
  53. data/lib/openflow-protocol/messages/statistics_reply.rb +26 -0
  54. data/lib/openflow-protocol/messages/statistics_request.rb +18 -0
  55. data/lib/openflow-protocol/messages/vendor.rb +14 -0
  56. data/lib/openflow-protocol/structs/match.rb +106 -0
  57. data/lib/openflow-protocol/structs/packet_queue.rb +14 -0
  58. data/lib/openflow-protocol/structs/physical_port.rb +50 -0
  59. data/lib/openflow-protocol/structs/port_number.rb +49 -0
  60. data/lib/openflow-protocol/structs/queue_properties/queue_properties.rb +9 -0
  61. data/lib/openflow-protocol/structs/queue_properties/queue_property.rb +20 -0
  62. data/lib/openflow-protocol/structs/queue_properties/queue_property_min_rate.rb +30 -0
  63. data/lib/openflow-protocol/structs/queue_properties/queue_property_none.rb +7 -0
  64. data/lib/openflow-protocol/version.rb +1 -1
  65. data/spec/actions/action_enqueue_spec.rb +4 -6
  66. data/spec/actions/action_output_spec.rb +4 -6
  67. data/spec/actions/action_set_destination_port_spec.rb +4 -6
  68. data/spec/actions/action_set_ip_destination_spec.rb +4 -6
  69. data/spec/actions/action_set_ip_source_spec.rb +4 -6
  70. data/spec/actions/action_set_ip_tos_spec.rb +4 -6
  71. data/spec/actions/action_set_mac_destination_spec.rb +4 -6
  72. data/spec/actions/action_set_mac_source_spec.rb +4 -6
  73. data/spec/actions/action_set_source_port_spec.rb +4 -6
  74. data/spec/actions/action_set_vlan_id_spec.rb +4 -6
  75. data/spec/actions/action_set_vlan_pcp_spec.rb +4 -6
  76. data/spec/actions/action_strip_vlan_spec.rb +3 -5
  77. data/spec/actions/action_vendor_spec.rb +4 -6
  78. data/spec/actions/actions_spec.rb +6 -8
  79. data/spec/messages/barrier_reply_spec.rb +9 -11
  80. data/spec/messages/barrier_request_spec.rb +9 -11
  81. data/spec/messages/echo_reply_spec.rb +13 -15
  82. data/spec/messages/echo_request_spec.rb +16 -18
  83. data/spec/messages/error_spec.rb +23 -20
  84. data/spec/messages/features_reply_spec.rb +11 -13
  85. data/spec/messages/features_request_spec.rb +9 -11
  86. data/spec/messages/flow_mod_spec.rb +12 -14
  87. data/spec/messages/flow_removed_spec.rb +9 -11
  88. data/spec/messages/get_config_reply_spec.rb +9 -11
  89. data/spec/messages/get_config_request_spec.rb +9 -11
  90. data/spec/messages/hello_spec.rb +9 -11
  91. data/spec/messages/packet_in_spec.rb +9 -11
  92. data/spec/messages/packet_out_spec.rb +10 -12
  93. data/spec/messages/parser_spec.rb +7 -9
  94. data/spec/messages/port_mod_spec.rb +9 -11
  95. data/spec/messages/port_status_spec.rb +10 -12
  96. data/spec/messages/queue_get_config_reply_spec.rb +9 -11
  97. data/spec/messages/queue_get_config_request_spec.rb +9 -11
  98. data/spec/messages/set_config_spec.rb +9 -11
  99. data/spec/messages/statistics/aggregate_statistics_reply_spec.rb +4 -6
  100. data/spec/messages/statistics/aggregate_statistics_request_spec.rb +4 -6
  101. data/spec/messages/statistics/description_statistics_spec.rb +11 -9
  102. data/spec/messages/statistics/flow_statistics_reply_spec.rb +4 -6
  103. data/spec/messages/statistics/flow_statistics_request_spec.rb +4 -6
  104. data/spec/messages/statistics/port_statistics_reply_spec.rb +4 -6
  105. data/spec/messages/statistics/port_statistics_request_spec.rb +4 -6
  106. data/spec/messages/statistics/queue_statistics_reply_spec.rb +4 -6
  107. data/spec/messages/statistics/queue_statistics_request_spec.rb +4 -6
  108. data/spec/messages/statistics/table_statistics_spec.rb +4 -6
  109. data/spec/messages/statistics/vendor_statistics_spec.rb +4 -6
  110. data/spec/messages/statistics_reply_spec.rb +62 -64
  111. data/spec/messages/statistics_request_spec.rb +45 -47
  112. data/spec/messages/vendor_spec.rb +13 -15
  113. data/spec/spec_helper.rb +1 -1
  114. data/spec/structs/match_spec.rb +7 -9
  115. data/spec/structs/packet_queue_spec.rb +5 -7
  116. data/spec/structs/physical_port_spec.rb +16 -18
  117. data/spec/structs/port_number_spec.rb +11 -13
  118. data/spec/structs/queue_properties/queue_properties_spec.rb +5 -7
  119. data/spec/structs/queue_properties/queue_property_min_rate_spec.rb +5 -7
  120. data/spec/structs/queue_properties/queue_property_none_spec.rb +3 -5
  121. metadata +78 -64
  122. data/lib/actions/action.rb +0 -26
  123. data/lib/actions/action_enqueue.rb +0 -12
  124. data/lib/actions/action_output.rb +0 -10
  125. data/lib/actions/action_set_destination_port.rb +0 -3
  126. data/lib/actions/action_set_ip_destination.rb +0 -3
  127. data/lib/actions/action_set_ip_source.rb +0 -9
  128. data/lib/actions/action_set_ip_tos.rb +0 -11
  129. data/lib/actions/action_set_mac_destination.rb +0 -3
  130. data/lib/actions/action_set_mac_source.rb +0 -11
  131. data/lib/actions/action_set_source_port.rb +0 -11
  132. data/lib/actions/action_set_vlan_id.rb +0 -11
  133. data/lib/actions/action_set_vlan_pcp.rb +0 -11
  134. data/lib/actions/action_strip_vlan.rb +0 -10
  135. data/lib/actions/action_vendor.rb +0 -9
  136. data/lib/actions/actions.rb +0 -5
  137. data/lib/helpers/array_of_subclasses.rb +0 -38
  138. data/lib/helpers/superclass_base.rb +0 -24
  139. data/lib/messages/barrier_reply.rb +0 -3
  140. data/lib/messages/barrier_request.rb +0 -3
  141. data/lib/messages/echo_reply.rb +0 -9
  142. data/lib/messages/echo_request.rb +0 -9
  143. data/lib/messages/error.rb +0 -61
  144. data/lib/messages/features_reply.rb +0 -40
  145. data/lib/messages/features_request.rb +0 -3
  146. data/lib/messages/flow_mod.rb +0 -20
  147. data/lib/messages/flow_removed.rb +0 -23
  148. data/lib/messages/get_config_reply.rb +0 -12
  149. data/lib/messages/get_config_request.rb +0 -3
  150. data/lib/messages/hello.rb +0 -3
  151. data/lib/messages/message.rb +0 -45
  152. data/lib/messages/packet_in.rb +0 -23
  153. data/lib/messages/packet_out.rb +0 -13
  154. data/lib/messages/parser.rb +0 -22
  155. data/lib/messages/port_mod.rb +0 -15
  156. data/lib/messages/port_status.rb +0 -14
  157. data/lib/messages/queue_get_config_reply.rb +0 -14
  158. data/lib/messages/queue_get_config_request.rb +0 -11
  159. data/lib/messages/set_config.rb +0 -3
  160. data/lib/messages/statistics.rb +0 -24
  161. data/lib/messages/statistics/aggregate_statistics_reply.rb +0 -10
  162. data/lib/messages/statistics/aggregate_statistics_request.rb +0 -3
  163. data/lib/messages/statistics/description_statistics.rb +0 -28
  164. data/lib/messages/statistics/flow_statistics_reply.rb +0 -21
  165. data/lib/messages/statistics/flow_statistics_request.rb +0 -10
  166. data/lib/messages/statistics/port_statistics_reply.rb +0 -20
  167. data/lib/messages/statistics/port_statistics_request.rb +0 -8
  168. data/lib/messages/statistics/queue_statistics_reply.rb +0 -12
  169. data/lib/messages/statistics/queue_statistics_request.rb +0 -9
  170. data/lib/messages/statistics/table_statistics.rb +0 -16
  171. data/lib/messages/statistics/vendor_statistics.rb +0 -7
  172. data/lib/messages/statistics_reply.rb +0 -22
  173. data/lib/messages/statistics_request.rb +0 -14
  174. data/lib/messages/vendor.rb +0 -10
  175. data/lib/structs/match.rb +0 -102
  176. data/lib/structs/packet_queue.rb +0 -10
  177. data/lib/structs/physical_port.rb +0 -46
  178. data/lib/structs/port_number.rb +0 -45
  179. data/lib/structs/queue_properties/queue_properties.rb +0 -5
  180. data/lib/structs/queue_properties/queue_property.rb +0 -16
  181. data/lib/structs/queue_properties/queue_property_min_rate.rb +0 -26
  182. data/lib/structs/queue_properties/queue_property_none.rb +0 -3
@@ -1,22 +0,0 @@
1
- require 'stringio'
2
-
3
- Dir[File.expand_path '*.rb', __dir__].each do |file|
4
- require_relative file
5
- end
6
-
7
- class OFParser
8
- def self.read(io)
9
- io = StringIO.new(io) if io.is_a?(String)
10
-
11
- header = io.readpartial(OFMessage::HEADER_LENGTH)
12
-
13
- type = OFMessage::TYPES[header[1].unpack('C')[0].to_i]
14
- klass_name = 'OF' + type.to_s.split('_').map(&:capitalize).join
15
- klass = Object.const_get(klass_name)
16
- length = header[2..3].unpack('S>')[0].to_i
17
-
18
- body = io.readpartial(length - OFMessage::HEADER_LENGTH)
19
-
20
- klass.read(header + body)
21
- end
22
- end
@@ -1,15 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFPortMod < OFMessage
4
- of_port_number :port_number
5
- mac_address :hardware_address
6
- flags32 :config, list: OFPhysicalPort::CONFIG
7
- flags32 :mask, list: OFPhysicalPort::CONFIG
8
- flags32 :advertise, list: OFPhysicalPort::FEATURES
9
- uint32 :padding
10
- hide :padding
11
-
12
- def body_length
13
- 24
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFPortStatus < OFMessage
4
- REASONS = [:add, :delete, :modify]
5
-
6
- enum8 :reason, list: REASONS
7
- uint56 :padding
8
- hide :padding
9
- of_physical_port :desc
10
-
11
- def body_length
12
- 56
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFQueueGetConfigReply < OFMessage
4
- of_port_number_strict :port
5
- uint48 :padding
6
- hide :padding
7
- array :queues,
8
- type: :of_packet_queue,
9
- read_until: :eof
10
-
11
- def body_length
12
- 8 + queues.to_binary_s.length
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFQueueGetConfigRequest < OFMessage
4
- of_port_number_strict :port
5
- uint16 :padding
6
- hide :padding
7
-
8
- def body_length
9
- 4
10
- end
11
- end
@@ -1,3 +0,0 @@
1
- require_relative 'get_config_reply'
2
-
3
- class OFSetConfig < OFGetConfigReply; end
@@ -1,24 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFStatistics < OFMessage
4
- STATISTICS_TYPES = [
5
- :description,
6
- :flow,
7
- :aggregate,
8
- :table,
9
- :port,
10
- :queue
11
- ]
12
- STATISTICS_TYPES[0xffff] = :vendor
13
-
14
- def flags_list
15
- self.class.const_get(:FLAGS)
16
- end
17
-
18
- enum16 :statistic_type, list: STATISTICS_TYPES
19
- flags16 :flags, list: -> { flags_list }
20
-
21
- def body_length
22
- 4 + statistics.to_binary_s.length
23
- end
24
- end
@@ -1,10 +0,0 @@
1
- require 'bindata'
2
-
3
- class OFAggregateStatisticsReply < BinData::Record
4
- endian :big
5
- uint64 :packet_count, initial_value: 0
6
- uint64 :byte_count, initial_value: 0
7
- uint32 :flow_count, initial_value: 0
8
- uint32 :padding
9
- hide :padding
10
- end
@@ -1,3 +0,0 @@
1
- require_relative 'flow_statistics_request'
2
-
3
- class OFAggregateStatisticsRequest < OFFlowStatisticsRequest; end
@@ -1,28 +0,0 @@
1
- require 'bindata'
2
-
3
- class OFDescriptionStatistics < BinData::Record
4
- DESCRIPTION_LENGTH = 256
5
- SERIAL_NUMBER_LENGTH = 32
6
-
7
- endian :big
8
- string :manufacturer_description,
9
- length: DESCRIPTION_LENGTH,
10
- trim_padding: true,
11
- initial_value: ''
12
- string :hardware_description,
13
- length: DESCRIPTION_LENGTH,
14
- trim_padding: true,
15
- initial_value: ''
16
- string :software_description,
17
- length: DESCRIPTION_LENGTH,
18
- trim_padding: true,
19
- initial_value: ''
20
- string :serial_number,
21
- length: SERIAL_NUMBER_LENGTH,
22
- trim_padding: true,
23
- initial_value: ''
24
- string :datapath_description,
25
- length: DESCRIPTION_LENGTH,
26
- trim_padding: true,
27
- initial_value: ''
28
- end
@@ -1,21 +0,0 @@
1
- require_relative 'table_statistics'
2
-
3
- class OFFlowStatisticsReply < BinData::Record
4
- endian :big
5
- uint16 :len, initial_value: -> { 88 + actions.to_binary_s.length }
6
- enum8 :table_id, list: OFTableStatistics::TABLE_IDS, initial_value: -> { :all }
7
- uint8 :padding
8
- hide :padding
9
- of_match :match
10
- uint32 :duration_seconds, initial_value: 0
11
- uint32 :duration_nanoseconds, initial_value: 0
12
- uint16 :priority, initial_value: 0
13
- uint16 :idle_timeout, initial_value: 0
14
- uint16 :hard_timeout, initial_value: 0
15
- uint48 :padding2
16
- hide :padding2
17
- uint64 :cookie, initial_value: 0
18
- uint64 :packet_count, initial_value: 0
19
- uint64 :byte_count, initial_value: 0
20
- of_actions :actions, length: -> { len - actions.rel_offset }
21
- end
@@ -1,10 +0,0 @@
1
- require_relative 'table_statistics'
2
-
3
- class OFFlowStatisticsRequest < BinData::Record
4
- endian :big
5
- of_match :match
6
- enum8 :table_id, list: OFTableStatistics::TABLE_IDS, initial_value: -> { :all }
7
- uint8 :padding
8
- hide :padding
9
- of_port_number :out_port, initial_value: -> { :none }
10
- end
@@ -1,20 +0,0 @@
1
- require_relative '../../structs/port_number'
2
-
3
- class OFPortStatisticsReply < BinData::Record
4
- endian :big
5
- of_port_number :port_number, initial_value: 0
6
- uint48 :padding
7
- hide :padding
8
- uint64 :receive_packets, initial_value: 0
9
- uint64 :transmit_packets, initial_value: 0
10
- uint64 :receive_bytes, initial_value: 0
11
- uint64 :transmit_bytes, initial_value: 0
12
- uint64 :receive_dropped, initial_value: 0
13
- uint64 :transmit_dropped, initial_value: 0
14
- uint64 :receive_errors, initial_value: 0
15
- uint64 :transmit_errors, initial_value: 0
16
- uint64 :receive_frame_errors, initial_value: 0
17
- uint64 :receive_overrun_errors, initial_value: 0
18
- uint64 :receive_crc_errors, initial_value: 0
19
- uint64 :collisions, initial_value: 0
20
- end
@@ -1,8 +0,0 @@
1
- require_relative '../../structs/port_number'
2
-
3
- class OFPortStatisticsRequest < BinData::Record
4
- endian :big
5
- of_port_number :port_number, initial_value: -> { :none } # all ports
6
- uint48 :padding
7
- hide :padding
8
- end
@@ -1,12 +0,0 @@
1
- require_relative '../../structs/port_number'
2
-
3
- class OFQueueStatisticsReply < BinData::Record
4
- endian :big
5
- of_port_number :port_number, initial_value: 0
6
- uint16 :padding
7
- hide :padding
8
- uint32 :queue_id, initial_value: 0
9
- uint64 :transmit_bytes, initial_value: 0
10
- uint64 :transmit_packets, initial_value: 0
11
- uint64 :transmit_errors, initial_value: 0
12
- end
@@ -1,9 +0,0 @@
1
- require_relative '../../structs/port_number'
2
-
3
- class OFQueueStatisticsRequest < BinData::Record
4
- endian :big
5
- of_port_number :port_number, initial_value: -> { :all }
6
- uint16 :padding
7
- hide :padding
8
- enum32 :queue_id, list: {all: 0xffffffff}, initial_value: -> { :all }
9
- end
@@ -1,16 +0,0 @@
1
- require_relative '../../structs/match'
2
-
3
- class OFTableStatistics < BinData::Record
4
- TABLE_IDS = {emergency: 0xfe, all: 0xff}
5
-
6
- endian :big
7
- enum8 :table_id, list: TABLE_IDS, initial_value: 0
8
- uint24 :padding
9
- hide :padding
10
- string :name, length: 32, trim_padding: true, initial_value: ''
11
- flags32 :wildcards, list: OFMatch::Wildcards::FLAGS
12
- uint32 :max_entries, initial_value: 0
13
- uint32 :active_count, initial_value: 0
14
- uint64 :lookup_count, initial_value: 0
15
- uint64 :matched_count, initial_value: 0
16
- end
@@ -1,7 +0,0 @@
1
- require 'bindata'
2
-
3
- class OFVendorStatistics < BinData::Record
4
- endian :big
5
- uint32 :vendor, initial_value: 0
6
- rest :body
7
- end
@@ -1,22 +0,0 @@
1
- require_relative 'statistics'
2
-
3
- class OFStatisticsReply < OFStatistics
4
- FLAGS = [:reply_more]
5
-
6
- choice :statistics, selection: -> { statistic_type.to_s } do
7
- of_description_statistics 'description'
8
- of_flow_statistics_reply 'flow'
9
- of_aggregate_statistics_reply 'aggregate'
10
- array 'table',
11
- type: :of_table_statistics,
12
- initial_length: -> { (len - statistics.rel_offset) / 64 }
13
- array 'port',
14
- type: :of_port_statistics_reply,
15
- initial_length: -> { (len - statistics.rel_offset) / 104 }
16
- array 'queue',
17
- type: :of_queue_statistics_reply,
18
- initial_length: -> { (len - statistics.rel_offset) / 32 }
19
- of_vendor_statistics 'vendor'
20
- rest :default
21
- end
22
- end
@@ -1,14 +0,0 @@
1
- require_relative 'statistics'
2
-
3
- class OFStatisticsRequest < OFStatistics
4
- FLAGS = []
5
-
6
- choice :statistics, selection: -> { statistic_type.to_s } do
7
- of_flow_statistics_request 'flow'
8
- of_aggregate_statistics_request 'aggregate'
9
- of_port_statistics_request 'port'
10
- of_queue_statistics_request 'queue'
11
- of_vendor_statistics 'vendor'
12
- rest :default
13
- end
14
- end
@@ -1,10 +0,0 @@
1
- require_relative 'message'
2
-
3
- class OFVendor < OFMessage
4
- uint32 :vendor, initial_value: 0
5
- rest :data
6
-
7
- def body_length
8
- 4 + data.length
9
- end
10
- end
@@ -1,102 +0,0 @@
1
- require 'English'
2
- require 'bindata-contrib'
3
- require_relative 'port_number'
4
-
5
- class OFMatch < BinData::Record
6
- class Wildcards < BinData::Primitive
7
- FLAGS = {
8
- in_port: 1 << 0,
9
- vlan_id: 1 << 1,
10
- mac_source: 1 << 2,
11
- mac_destination: 1 << 3,
12
- mac_protocol: 1 << 4,
13
- ip_protocol: 1 << 5,
14
- source_port: 1 << 6,
15
- destination_port: 1 << 7,
16
- ip_source0: 1 << 8,
17
- ip_source1: 1 << 9,
18
- ip_source2: 1 << 10,
19
- ip_source3: 1 << 11,
20
- ip_source4: 1 << 12,
21
- ip_source_all: 1 << 13,
22
- ip_destination0: 1 << 14,
23
- ip_destination1: 1 << 15,
24
- ip_destination2: 1 << 16,
25
- ip_destination3: 1 << 17,
26
- ip_destination4: 1 << 18,
27
- ip_destination_all: 1 << 19,
28
- vlan_pcp: 1 << 20,
29
- ip_tos: 1 << 21
30
- }
31
- ALL_FLAGS = Hash[
32
- FLAGS.keys.select { |key| /^ip_(source|destination)\d$/ !~ key }
33
- .map { |key| [key, true] }
34
- ]
35
-
36
- endian :big
37
- uint32 :flags, initial_value: 0x003820ff # all
38
-
39
- def get
40
- FLAGS.each_with_object(Hash.new(0)) do |(key, bit), memo|
41
- next if flags & bit == 0
42
- if /^(ip_source|ip_destination)(\d)/ =~ key
43
- memo[$LAST_MATCH_INFO[1].to_sym] |= 1 << $LAST_MATCH_INFO[2].to_i
44
- else
45
- memo[key] = true
46
- end
47
- end
48
- end
49
-
50
- def set(value)
51
- value = Hash[value.map { |v| [v, true] }] if value.is_a?(Array)
52
- self.flags = value.inject(0) do |memo, (key, val)|
53
- memo |
54
- case key
55
- when :ip_source, :ip_destination
56
- (val & 31) << (key == :ip_source ? 8 : 14)
57
- else
58
- val ? FLAGS.fetch(key) : 0
59
- end
60
- end
61
- end
62
- end
63
-
64
- def self.create(options = {})
65
- unless options[:wildcards]
66
- options[:wildcards] = {}
67
- %i(in_port vlan_id mac_source mac_destination mac_protocol ip_protocol source_port destination_port ip_source ip_destination vlan_pcp ip_tos).each do |flag|
68
- wild_flag = flag
69
- wild_flag = "#{flag}_all".to_sym if %i(ip_source ip_destination).include? flag
70
- options[:wildcards][wild_flag] = true unless options[flag]
71
- end
72
- end
73
- self.new options
74
- end
75
-
76
- endian :big
77
- wildcards :wildcards
78
- of_port_number :in_port, initial_value: 0
79
- mac_address :mac_source
80
- mac_address :mac_destination
81
- uint16 :vlan_id, initial_value: 0xffff
82
- uint8 :vlan_pcp, initial_value: 0
83
- uint8 :padding
84
- hide :padding
85
- enum16 :mac_protocol, list: {
86
- ipv4: 0x0800,
87
- arp: 0x0806,
88
- vlan: 0x8100
89
- }, initial_value: 0
90
- uint8 :ip_tos, initial_value: 0
91
- enum8 :ip_protocol, list: {
92
- icmp: 1,
93
- tcp: 6,
94
- udp: 17
95
- }, initial_value: 0
96
- uint16 :padding2
97
- hide :padding2
98
- ipv4_address :ip_source
99
- ipv4_address :ip_destination
100
- uint16 :source_port, initial_value: 0
101
- uint16 :destination_port, initial_value: 0
102
- end
@@ -1,10 +0,0 @@
1
- require_relative 'queue_properties/queue_properties'
2
-
3
- class OFPacketQueue < BinData::Record
4
- endian :big
5
- uint32 :queue_id, initial_value: 0
6
- uint16 :len, value: -> { 8 + properties.to_binary_s.length }
7
- uint16 :padding
8
- hide :padding
9
- of_queue_properties :properties, length: -> { len - 8 }
10
- end
@@ -1,46 +0,0 @@
1
- require 'bindata-contrib'
2
- require_relative 'port_number'
3
-
4
- class OFPhysicalPort < BinData::Record
5
- CONFIG = [
6
- :port_down,
7
- :no_spanning_tree,
8
- :no_receive,
9
- :no_receive_spanning_tree,
10
- :no_flood,
11
- :no_forward,
12
- :no_packet_in
13
- ]
14
- STATE = {
15
- link_down: 1 << 0,
16
- spanning_tree_listen: 0 << 8,
17
- spanning_tree_learn: 1 << 8,
18
- spanning_tree_forward: 2 << 8,
19
- spanning_tree_block: 3 << 8
20
- }
21
- FEATURES = [
22
- :port_10mb_half_duplex,
23
- :port_10mb_full_duplex,
24
- :port_100mb_half_duplex,
25
- :port_100mb_full_duplex,
26
- :port_1gb_half_duplex,
27
- :port_1gb_full_duplex,
28
- :port_10gb_full_duplex,
29
- :port_copper,
30
- :port_fiber,
31
- :port_auto_negotiation,
32
- :port_pause,
33
- :port_pause_asymmetric
34
- ]
35
-
36
- endian :big
37
- of_port_number :port_number, initial_value: 0
38
- mac_address :hardware_address
39
- string :name, length: 16, trim_padding: true, initial_value: ''
40
- flags32 :config, list: CONFIG
41
- flags32 :state, list: STATE
42
- flags32 :current_features, list: FEATURES
43
- flags32 :advertised_features, list: FEATURES
44
- flags32 :supported_features, list: FEATURES
45
- flags32 :peer_features, list: FEATURES
46
- end