pio 0.27.2 → 0.28.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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/Rakefile +1 -1
  4. data/bin/{code_metrics → terminal-notifier} +2 -2
  5. data/features/dhcp.feature +12 -12
  6. data/features/icmp.feature +12 -12
  7. data/features/open_flow10/aggregate_stats_request.feature +10 -10
  8. data/features/open_flow10/enqueue.feature +7 -7
  9. data/features/open_flow10/exact_match.feature +15 -15
  10. data/features/open_flow10/features_reply.feature +40 -40
  11. data/features/open_flow10/flow_mod.feature +49 -49
  12. data/features/open_flow10/flow_removed.feature +34 -0
  13. data/features/open_flow10/flow_stats_reply.feature +14 -14
  14. data/features/open_flow10/flow_stats_request.feature +15 -15
  15. data/features/open_flow10/nicira_resubmit.feature +30 -0
  16. data/features/open_flow10/nicira_resubmit_table.feature +32 -0
  17. data/features/open_flow10/port_stats_request.feature +48 -0
  18. data/features/open_flow10/port_stats_request.raw +0 -0
  19. data/features/open_flow10/queue_stats_request.feature +51 -0
  20. data/features/open_flow10/queue_stats_request.raw +0 -0
  21. data/features/open_flow10/send_out_port.feature +40 -40
  22. data/features/open_flow10/set_destination_mac_address.feature +16 -0
  23. data/features/open_flow10/set_ip_destination_address.feature +6 -6
  24. data/features/open_flow10/set_source_ip_address.feature +16 -0
  25. data/features/open_flow10/set_source_mac_address.feature +16 -0
  26. data/features/open_flow10/{set_ip_tos.feature → set_tos.feature} +3 -3
  27. data/features/open_flow10/set_transport_destination_port.feature +6 -6
  28. data/features/open_flow10/set_transport_source_port.feature +6 -6
  29. data/features/open_flow10/set_vlan_priority.feature +3 -3
  30. data/features/open_flow10/set_vlan_vid.feature +6 -6
  31. data/features/open_flow10/strip_vlan_header.feature +5 -5
  32. data/features/open_flow10/table_stats_request.feature +31 -0
  33. data/features/open_flow13/match.feature +33 -33
  34. data/features/open_flow13/send_out_port.feature +45 -45
  35. data/features/udp.feature +2 -2
  36. data/lib/pio/arp/format.rb +5 -5
  37. data/lib/pio/dhcp/boot_reply_options.rb +6 -6
  38. data/lib/pio/dhcp/boot_request_options.rb +2 -2
  39. data/lib/pio/dhcp/common_options.rb +5 -5
  40. data/lib/pio/dhcp/message.rb +2 -2
  41. data/lib/pio/icmp/options.rb +2 -2
  42. data/lib/pio/icmp/reply.rb +6 -6
  43. data/lib/pio/icmp/request.rb +6 -6
  44. data/lib/pio/ipv4_header.rb +11 -11
  45. data/lib/pio/open_flow.rb +5 -2
  46. data/lib/pio/open_flow/action.rb +41 -0
  47. data/lib/pio/open_flow/nicira_action.rb +17 -0
  48. data/lib/pio/open_flow10.rb +12 -1
  49. data/lib/pio/open_flow10/actions.rb +17 -15
  50. data/lib/pio/open_flow10/enqueue.rb +27 -46
  51. data/lib/pio/open_flow10/features/reply.rb +5 -5
  52. data/lib/pio/open_flow10/flow_removed.rb +40 -0
  53. data/lib/pio/open_flow10/match.rb +33 -33
  54. data/lib/pio/open_flow10/nicira_resubmit.rb +20 -0
  55. data/lib/pio/open_flow10/nicira_resubmit_table.rb +17 -0
  56. data/lib/pio/open_flow10/port_stats/request.rb +25 -0
  57. data/lib/pio/open_flow10/queue_stats/request.rb +22 -0
  58. data/lib/pio/open_flow10/send_out_port.rb +6 -27
  59. data/lib/pio/open_flow10/set_destination_ip_address.rb +16 -0
  60. data/lib/pio/open_flow10/set_destination_mac_address.rb +18 -0
  61. data/lib/pio/open_flow10/set_source_ip_address.rb +16 -0
  62. data/lib/pio/open_flow10/set_source_mac_address.rb +18 -0
  63. data/lib/pio/open_flow10/set_tos.rb +24 -0
  64. data/lib/pio/open_flow10/set_transport_port.rb +32 -48
  65. data/lib/pio/open_flow10/set_vlan_priority.rb +16 -11
  66. data/lib/pio/open_flow10/set_vlan_vid.rb +16 -11
  67. data/lib/pio/open_flow10/stats_request.rb +5 -1
  68. data/lib/pio/open_flow10/strip_vlan_header.rb +8 -25
  69. data/lib/pio/open_flow10/table_stats/request.rb +19 -0
  70. data/lib/pio/open_flow13/actions.rb +1 -1
  71. data/lib/pio/open_flow13/match.rb +19 -19
  72. data/lib/pio/open_flow13/send_out_port.rb +9 -28
  73. data/lib/pio/udp_header.rb +4 -4
  74. data/lib/pio/version.rb +1 -1
  75. data/pio.gemspec +3 -2
  76. data/spec/pio/dhcp/ack_spec.rb +8 -8
  77. data/spec/pio/dhcp/offer_spec.rb +8 -8
  78. data/spec/pio/dhcp_spec.rb +16 -16
  79. data/spec/pio/icmp/reply_spec.rb +4 -4
  80. data/spec/pio/icmp/request_spec.rb +6 -6
  81. data/spec/pio/icmp_spec.rb +4 -4
  82. data/spec/pio/open_flow10/enqueue_spec.rb +13 -11
  83. data/spec/pio/open_flow10/flow_mod_spec.rb +20 -20
  84. data/spec/pio/open_flow10/flow_stats_request_spec.rb +4 -4
  85. data/spec/pio/open_flow10/match_spec.rb +59 -59
  86. data/spec/pio/open_flow10/packet_out_spec.rb +31 -29
  87. data/spec/pio/open_flow10/set_destination_ip_address_spec.rb +27 -0
  88. data/spec/pio/open_flow10/set_destination_mac_address_spec.rb +28 -0
  89. data/spec/pio/open_flow10/set_source_ip_address_spec.rb +27 -0
  90. data/spec/pio/open_flow10/set_source_mac_address_spec.rb +28 -0
  91. data/spec/pio/open_flow10/set_tos_spec.rb +30 -0
  92. data/spec/pio/open_flow10/set_transport_destination_port_spec.rb +4 -4
  93. data/spec/pio/open_flow10/set_transport_source_port_spec.rb +4 -4
  94. data/spec/pio/open_flow10/set_vlan_priority_spec.rb +4 -4
  95. data/spec/pio/open_flow10/set_vlan_vid_spec.rb +4 -4
  96. data/spec/pio/open_flow10/strip_vlan_header_spec.rb +5 -5
  97. data/spec/pio/open_flow10/wildcards_spec.rb +18 -18
  98. data/spec/pio/open_flow13/match_spec.rb +20 -20
  99. metadata +73 -37
  100. data/bin/code_metrics-profile +0 -16
  101. data/features/open_flow10/set_ether_destination_address.feature +0 -16
  102. data/features/open_flow10/set_ether_source_address.feature +0 -16
  103. data/features/open_flow10/set_ip_source_address.feature +0 -16
  104. data/lib/pio/open_flow10/set_ether_address.rb +0 -53
  105. data/lib/pio/open_flow10/set_ip_address.rb +0 -49
  106. data/lib/pio/open_flow10/set_ip_tos.rb +0 -42
  107. data/lib/pio/open_flow10/set_vlan.rb +0 -37
  108. data/spec/pio/open_flow10/set_ether_destination_address_spec.rb +0 -28
  109. data/spec/pio/open_flow10/set_ether_source_address_spec.rb +0 -28
  110. data/spec/pio/open_flow10/set_ip_destination_address_spec.rb +0 -27
  111. data/spec/pio/open_flow10/set_ip_source_address_spec.rb +0 -25
  112. data/spec/pio/open_flow10/set_ip_tos_spec.rb +0 -30
@@ -27,11 +27,11 @@ module Pio
27
27
  :set_vlan_vid,
28
28
  :set_vlan_pcp,
29
29
  :strip_vlan,
30
- :set_ether_source_address,
31
- :set_ether_destination_address,
32
- :set_ip_source_address,
33
- :set_ip_destination_address,
34
- :set_ip_tos,
30
+ :set_source_mac_address,
31
+ :set_destination_mac_address,
32
+ :set_source_ip_address,
33
+ :set_destination_ip_address,
34
+ :set_tos,
35
35
  :set_transport_source_port,
36
36
  :set_transport_destination_port,
37
37
  :enqueue]
@@ -0,0 +1,40 @@
1
+ require 'pio/open_flow/message'
2
+ require 'pio/open_flow10/match10'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # Flow Removed message
7
+ class FlowRemoved < OpenFlow::Message
8
+ # Why was this flow removed?
9
+ # (enum ofp_flow_removed_reason)
10
+ class Reason < BinData::Primitive
11
+ REASONS = { idle_timeout: 0, hard_timeout: 1, delete: 2 }
12
+
13
+ uint8 :reason
14
+
15
+ def get
16
+ REASONS.invert.fetch(reason)
17
+ end
18
+
19
+ def set(value)
20
+ self.reason = REASONS.fetch(value)
21
+ end
22
+ end
23
+
24
+ open_flow_header version: 1, message_type: 11, message_length: 88
25
+ match10 :match
26
+ uint64 :cookie
27
+ uint16 :priority
28
+ reason :reason
29
+ string :padding1, length: 1
30
+ hide :padding1
31
+ uint32 :duration_sec
32
+ uint32 :duration_nsec
33
+ uint16 :idle_timeout
34
+ string :padding2, length: 2
35
+ hide :padding2
36
+ uint64 :packet_count
37
+ uint64 :byte_count
38
+ end
39
+ end
40
+ end
@@ -12,31 +12,31 @@ module Pio
12
12
  BITS = {
13
13
  in_port: 1 << 0,
14
14
  vlan_vid: 1 << 1,
15
- ether_source_address: 1 << 2,
16
- ether_destination_address: 1 << 3,
15
+ source_mac_address: 1 << 2,
16
+ destination_mac_address: 1 << 3,
17
17
  ether_type: 1 << 4,
18
18
  ip_protocol: 1 << 5,
19
19
  transport_source_port: 1 << 6,
20
20
  transport_destination_port: 1 << 7,
21
- ip_source_address: 0,
22
- ip_source_address0: 1 << 8,
23
- ip_source_address1: 1 << 9,
24
- ip_source_address2: 1 << 10,
25
- ip_source_address3: 1 << 11,
26
- ip_source_address4: 1 << 12,
27
- ip_source_address_all: 1 << 13,
28
- ip_destination_address: 0,
29
- ip_destination_address0: 1 << 14,
30
- ip_destination_address1: 1 << 15,
31
- ip_destination_address2: 1 << 16,
32
- ip_destination_address3: 1 << 17,
33
- ip_destination_address4: 1 << 18,
34
- ip_destination_address_all: 1 << 19,
21
+ source_ip_address: 0,
22
+ source_ip_address0: 1 << 8,
23
+ source_ip_address1: 1 << 9,
24
+ source_ip_address2: 1 << 10,
25
+ source_ip_address3: 1 << 11,
26
+ source_ip_address4: 1 << 12,
27
+ source_ip_address_all: 1 << 13,
28
+ destination_ip_address: 0,
29
+ destination_ip_address0: 1 << 14,
30
+ destination_ip_address1: 1 << 15,
31
+ destination_ip_address2: 1 << 16,
32
+ destination_ip_address3: 1 << 17,
33
+ destination_ip_address4: 1 << 18,
34
+ destination_ip_address_all: 1 << 19,
35
35
  vlan_priority: 1 << 20,
36
- ip_tos: 1 << 21
36
+ tos: 1 << 21
37
37
  }
38
- NW_FLAGS = [:ip_source_address, :ip_destination_address]
39
- FLAGS = BITS.keys.select { |each| !(/^ip_(source|destination)/=~ each) }
38
+ NW_FLAGS = [:source_ip_address, :destination_ip_address]
39
+ FLAGS = BITS.keys.select { |each| !(/^(source|destination)_ip/=~ each) }
40
40
 
41
41
  endian :big
42
42
 
@@ -46,7 +46,7 @@ module Pio
46
46
  def get
47
47
  BITS.each_with_object(Hash.new(0)) do |(key, bit), memo|
48
48
  next if flags & bit == 0
49
- if /(ip_source_address|ip_destination_address)(\d)/=~ key
49
+ if /(source_ip_address|destination_ip_address)(\d)/=~ key
50
50
  memo[$LAST_MATCH_INFO[1].to_sym] |= 1 << $LAST_MATCH_INFO[2].to_i
51
51
  else
52
52
  memo[key] = true
@@ -57,23 +57,23 @@ module Pio
57
57
  def set(params)
58
58
  self.flags = params.inject(0) do |memo, (key, val)|
59
59
  memo | case key
60
- when :ip_source_address, :ip_destination_address
60
+ when :source_ip_address, :destination_ip_address
61
61
  (params.fetch(key) & 31) <<
62
- (key == :ip_source_address ? 8 : 14)
62
+ (key == :source_ip_address ? 8 : 14)
63
63
  else
64
64
  val ? BITS.fetch(key) : 0
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
- def ip_source_address
70
- get.fetch(:ip_source_address)
69
+ def source_ip_address
70
+ get.fetch(:source_ip_address)
71
71
  rescue KeyError
72
72
  0
73
73
  end
74
74
 
75
- def ip_destination_address
76
- get.fetch(:ip_destination_address)
75
+ def destination_ip_address
76
+ get.fetch(:destination_ip_address)
77
77
  rescue KeyError
78
78
  0
79
79
  end
@@ -106,21 +106,21 @@ module Pio
106
106
 
107
107
  wildcards :wildcards
108
108
  uint16 :in_port
109
- mac_address :ether_source_address
110
- mac_address :ether_destination_address
109
+ mac_address :source_mac_address
110
+ mac_address :destination_mac_address
111
111
  uint16 :vlan_vid
112
112
  uint8 :vlan_priority
113
113
  uint8 :padding1
114
114
  hide :padding1
115
115
  uint16 :ether_type
116
- uint8 :ip_tos
116
+ uint8 :tos
117
117
  uint8 :ip_protocol
118
118
  uint16 :padding2
119
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 }
120
+ match_ip_address :source_ip_address,
121
+ bitcount: -> { wildcards.source_ip_address }
122
+ match_ip_address :destination_ip_address,
123
+ bitcount: -> { wildcards.destination_ip_address }
124
124
  uint16 :transport_source_port
125
125
  uint16 :transport_destination_port
126
126
  end
@@ -0,0 +1,20 @@
1
+ require 'pio/open_flow/nicira_action'
2
+ require 'pio/open_flow10/port16'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # NXAST_RESUBMIT action
7
+ class NiciraResubmit < OpenFlow::NiciraAction
8
+ nicira_action_header action_type: 0xffff,
9
+ action_length: 16,
10
+ subtype: 1
11
+ port16 :in_port
12
+ string :padding, length: 4
13
+ hide :padding
14
+
15
+ def initialize(port_number)
16
+ super(in_port: port_number)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'pio/open_flow/nicira_action'
2
+ require 'pio/open_flow10/port16'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # NXAST_RESUBMIT_TABLE action
7
+ class NiciraResubmitTable < OpenFlow::NiciraAction
8
+ nicira_action_header action_type: 0xffff,
9
+ action_length: 16,
10
+ subtype: 14
11
+ port16 :in_port
12
+ uint8 :table, initial_value: 0xff
13
+ string :padding, length: 3
14
+ hide :padding
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'pio/open_flow/message'
2
+
3
+ module Pio
4
+ module OpenFlow10
5
+ # Port Stats messages
6
+ class PortStats
7
+ # Port Stats Request message
8
+ class Request < OpenFlow::Message
9
+ open_flow_header version: 1,
10
+ message_type: 16,
11
+ message_length: 20
12
+
13
+ stats_type :stats_type, value: -> { :port }
14
+ uint16 :flags
15
+ port16 :port
16
+ string :padding, length: 6
17
+ hide :padding
18
+
19
+ def initialize(port, user_options = {})
20
+ super({ port: port }.merge user_options)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'pio/open_flow/message'
2
+
3
+ module Pio
4
+ module OpenFlow10
5
+ # Queue Stats messages
6
+ class QueueStats
7
+ # Queue Stats Request message
8
+ class Request < OpenFlow::Message
9
+ open_flow_header version: 1,
10
+ message_type: 16,
11
+ message_length: 20
12
+
13
+ stats_type :stats_type, value: -> { :queue }
14
+ uint16 :flags
15
+ port16 :port
16
+ string :padding, length: 2
17
+ hide :padding
18
+ uint32 :queue_id
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,35 +1,14 @@
1
- require 'bindata'
2
- require 'forwardable'
3
1
  require 'pio/monkey_patch/integer'
2
+ require 'pio/open_flow/action'
4
3
  require 'pio/open_flow10/port16'
5
4
 
6
5
  module Pio
7
6
  module OpenFlow10
8
7
  # An action to output a packet to a port.
9
- class SendOutPort
10
- # OpenFlow 1.0 OFPAT_OUTPUT action format.
11
- class Format < BinData::Record
12
- endian :big
13
-
14
- uint16 :action_type, value: 0
15
- uint16 :action_length, value: 8
16
- port16 :port
17
- uint16 :max_length, initial_value: 2**16 - 1
18
- end
19
-
20
- def self.read(raw_data)
21
- send_out_port = allocate
22
- send_out_port.instance_variable_set :@format, Format.read(raw_data)
23
- send_out_port
24
- end
25
-
26
- extend Forwardable
27
-
28
- def_delegators :@format, :action_type
29
- def_delegator :@format, :action_length, :length
30
- def_delegators :@format, :port
31
- def_delegators :@format, :max_length
32
- def_delegator :@format, :to_binary_s, :to_binary
8
+ class SendOutPort < OpenFlow::Action
9
+ action_header action_type: 0, action_length: 8
10
+ port16 :port
11
+ uint16 :max_length, initial_value: 2**16 - 1
33
12
 
34
13
  # rubocop:disable MethodLength
35
14
  def initialize(user_options)
@@ -45,7 +24,7 @@ module Pio
45
24
  fail(ArgumentError,
46
25
  'The max_length should be an unsigned 16bit integer.')
47
26
  end
48
- @format = Format.new(options)
27
+ super(options)
49
28
  end
50
29
  # rubocop:enable MethodLength
51
30
 
@@ -0,0 +1,16 @@
1
+ require 'pio/open_flow/action'
2
+ require 'pio/type/ip_address'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # An action to modify the IPv4 source address of a packet.
7
+ class SetDestinationIpAddress < OpenFlow::Action
8
+ action_header action_type: 7, action_length: 8
9
+ ip_address :ip_address
10
+
11
+ def initialize(ip_address)
12
+ super ip_address: ip_address
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'pio/open_flow/action'
2
+ require 'pio/type/mac_address'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # An action to modify the destination Ethernet address of a packet.
7
+ class SetDestinationMacAddress < OpenFlow::Action
8
+ action_header action_type: 5, action_length: 16
9
+ mac_address :mac_address
10
+ string :padding, length: 6
11
+ hide :padding
12
+
13
+ def initialize(mac_address)
14
+ super mac_address: mac_address
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'pio/open_flow/action'
2
+ require 'pio/type/ip_address'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # An action to modify the IPv4 source address of a packet.
7
+ class SetSourceIpAddress < OpenFlow::Action
8
+ action_header action_type: 6, action_length: 8
9
+ ip_address :ip_address
10
+
11
+ def initialize(ip_address)
12
+ super ip_address: ip_address
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'pio/open_flow/action'
2
+ require 'pio/type/mac_address'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # An action to modify the source Ethernet address of a packet.
7
+ class SetSourceMacAddress < OpenFlow::Action
8
+ action_header action_type: 4, action_length: 16
9
+ mac_address :mac_address
10
+ string :padding, length: 6
11
+ hide :padding
12
+
13
+ def initialize(mac_address)
14
+ super mac_address: mac_address
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'pio/monkey_patch/integer'
2
+ require 'pio/open_flow/action'
3
+
4
+ module Pio
5
+ module OpenFlow10
6
+ # An action to modify the IP ToS/DSCP field of a packet.
7
+ class SetTos < OpenFlow::Action
8
+ action_header action_type: 8, action_length: 8
9
+ uint8 :type_of_service
10
+ string :padding, length: 3
11
+ hide :padding
12
+
13
+ def initialize(type_of_service)
14
+ # tos (IP ToS) value consists of 8 bits, of which only the
15
+ # 6 high-order bits belong to DSCP, the 2 low-order bits must
16
+ # be zero.
17
+ unless type_of_service.unsigned_8bit? && type_of_service % 4 == 0
18
+ fail ArgumentError, 'Invalid type_of_service (ToS) value.'
19
+ end
20
+ super(type_of_service: type_of_service)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,58 +1,42 @@
1
- require 'bindata'
2
- require 'forwardable'
3
1
  require 'pio/monkey_patch/integer'
2
+ require 'pio/open_flow/action'
4
3
 
5
4
  module Pio
6
- # An action to modify the source/destination TCP/UDP port of a packet.
7
- class SetTransportPort
8
- # rubocop:disable MethodLength
9
- def self.action_type(action_type)
10
- str = %(
11
- class Format < BinData::Record
12
- endian :big
13
-
14
- uint16 :action_type, value: #{action_type}
15
- uint16 :action_length, value: 8
16
- uint16 :port
17
- uint16 :padding
18
- hide :padding
5
+ module OpenFlow10
6
+ # An action to modify the source TCP/UDP port of a packet.
7
+ class SetTransportSourcePort < OpenFlow::Action
8
+ action_header action_type: 9, action_length: 8
9
+ uint16 :port
10
+ string :padding, length: 2
11
+ hide :padding
12
+
13
+ def initialize(number)
14
+ port = number.to_i
15
+ unless port.unsigned_16bit?
16
+ fail ArgumentError, 'TCP/UDP port must be an unsigned 16-bit integer.'
19
17
  end
20
- )
21
- module_eval str
22
- end
23
- # rubocop:enable MethodLength
24
-
25
- def self.read(raw_data)
26
- action = allocate
27
- action.instance_variable_set(:@format, const_get(:Format).read(raw_data))
28
- action
18
+ super(port: port)
19
+ rescue NoMethodError
20
+ raise TypeError, 'TCP/UDP port must be an unsigned 16-bit integer.'
21
+ end
29
22
  end
30
23
 
31
- extend Forwardable
32
-
33
- def_delegators :@format, :action_type
34
- def_delegator :@format, :action_length, :length
35
- def_delegators :@format, :port
36
- def_delegator :@format, :to_binary_s, :to_binary
37
-
38
- def initialize(number)
39
- port = number.to_i
40
- unless port.unsigned_16bit?
41
- fail ArgumentError, 'TCP/UDP port must be an unsigned 16-bit integer.'
24
+ # An action to modify the source TCP/UDP port of a packet.
25
+ class SetTransportDestinationPort < OpenFlow::Action
26
+ action_header action_type: 10, action_length: 8
27
+ uint16 :port
28
+ string :padding, length: 2
29
+ hide :padding
30
+
31
+ def initialize(number)
32
+ port = number.to_i
33
+ unless port.unsigned_16bit?
34
+ fail ArgumentError, 'TCP/UDP port must be an unsigned 16-bit integer.'
35
+ end
36
+ super(port: port)
37
+ rescue NoMethodError
38
+ raise TypeError, 'TCP/UDP port must be an unsigned 16-bit integer.'
42
39
  end
43
- @format = self.class.const_get(:Format).new(port: port)
44
- rescue NoMethodError
45
- raise TypeError, 'TCP/UDP port must be an unsigned 16-bit integer.'
46
40
  end
47
41
  end
48
-
49
- # An action to modify the source TCP/UDP port of a packet.
50
- class SetTransportSourcePort < SetTransportPort
51
- action_type 9
52
- end
53
-
54
- # An action to modify the source TCP/UDP port of a packet.
55
- class SetTransportDestinationPort < SetTransportPort
56
- action_type 10
57
- end
58
42
  end