Skip to content

Commit

Permalink
Add FlowMod parser and generator.
Browse files Browse the repository at this point in the history
Also added parsers and generators for the following instructions and actions.

Instructions:
 - Pio::Apply
 - Pio::GotoTable
 - Pio::WriteMetadata
 - Pio::Meter

Actions:
 - Pio::SendOutPort
  • Loading branch information
yasuhito committed Jun 17, 2015
1 parent 56cdc1a commit a25cdce
Show file tree
Hide file tree
Showing 60 changed files with 840 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ supports the following packet formats:
- [Echo Reply](https://relishapp.com/trema/pio/docs/open-flow13/pio-echo-reply)
- [Features Request](https://relishapp.com/trema/pio/docs/open-flow13/pio-features-request)
- [Features Reply](https://relishapp.com/trema/pio/docs/open-flow13/pio-features-reply)
- [Flow Mod](https://relishapp.com/trema/pio/docs/open-flow13/pio-flowmod)

## Features Overview

Expand Down
13 changes: 5 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
require 'bundler/gem_tasks'

RELISH_PROJECT = 'trema/pio'
FLAY_THRESHOLD = 300

# rubocop:disable HashSyntax

task :default => :travis
task :test => [:spec, :cucumber]
task :travis => [:test, :quality, 'coveralls:push']
task default: :travis
task test: [:spec, :cucumber]
task travis: [:test, :quality, 'coveralls:push']

desc 'Check for code quality'
task :quality => [:reek, :flog, :flay, :rubocop]

# rubocop:enable HashSyntax
task quality: [:reek, :flog, :flay, :rubocop]

Dir.glob('tasks/*.rake').each { |each| import each }

Expand Down
10 changes: 5 additions & 5 deletions features/open_flow10/flow_mod.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Feature: Pio::FlowMod
| match.transport_source_port | 8 |
| match.transport_destination_port | 0 |
| cookie | 0 |
| command | add |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority | 65535 |
Expand Down Expand Up @@ -62,7 +62,7 @@ Feature: Pio::FlowMod
| match.transport_source_port | 8 |
| match.transport_destination_port | 0 |
| cookie | 0 |
| command | modify |
| command | :modify |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority | 65535 |
Expand Down Expand Up @@ -99,7 +99,7 @@ Feature: Pio::FlowMod
| match.transport_source_port | 8 |
| match.transport_destination_port | 0 |
| cookie | 0 |
| command | modify_strict |
| command | :modify_strict |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority | 65535 |
Expand Down Expand Up @@ -136,7 +136,7 @@ Feature: Pio::FlowMod
| match.transport_source_port | 8 |
| match.transport_destination_port | 0 |
| cookie | 0 |
| command | delete |
| command | :delete |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority | 65535 |
Expand Down Expand Up @@ -171,7 +171,7 @@ Feature: Pio::FlowMod
| match.transport_source_port | 8 |
| match.transport_destination_port | 0 |
| cookie | 1 |
| command | delete_strict |
| command | :delete_strict |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority | 65535 |
Expand Down
4 changes: 2 additions & 2 deletions features/open_flow10/packet_in.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Pio::PacketIn
| buffer_id | 4294967040 |
| total_len | 60 |
| in_port | 1 |
| reason | no_match |
| reason | :no_match |
| raw_data.length | 60 |
| source_mac | ac:5d:10:31:37:79 |
| source_mac.class | Pio::Mac |
Expand All @@ -50,7 +50,7 @@ Feature: Pio::PacketIn
| buffer_id | 4294967040 |
| total_len | 60 |
| in_port | 1 |
| reason | no_match |
| reason | :no_match |
| raw_data.length | 60 |
| source_mac | ac:5d:10:31:37:79 |
| source_mac.class | Pio::Mac |
Expand Down
2 changes: 1 addition & 1 deletion features/open_flow10/port_status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature: Pio::PortStatus
| message_length | 64 |
| transaction_id | 4 |
| xid | 4 |
| reason | delete |
| reason | :delete |
| desc.port_no | 65533 |
| desc.hardware_address | 01:02:03:04:05:06 |
| desc.name | foo |
Expand Down
Binary file added features/open_flow13/action_copy_ttl_in.raw
Binary file not shown.
Binary file added features/open_flow13/action_copy_ttl_out.raw
Binary file not shown.
Binary file added features/open_flow13/action_dec_mpls_ttl.raw
Binary file not shown.
Binary file added features/open_flow13/action_dec_nw_ttl.raw
Binary file not shown.
Binary file added features/open_flow13/action_group.raw
Binary file not shown.
Binary file added features/open_flow13/action_pop_mpls.raw
Binary file not shown.
Binary file added features/open_flow13/action_pop_pbb.raw
Binary file not shown.
Binary file added features/open_flow13/action_pop_vlan.raw
Binary file not shown.
Binary file added features/open_flow13/action_push_mpls.raw
Binary file not shown.
Binary file added features/open_flow13/action_push_pbb.raw
Binary file not shown.
Binary file added features/open_flow13/action_push_vlan.raw
Binary file not shown.
Binary file added features/open_flow13/action_set_field.raw
Binary file not shown.
Binary file added features/open_flow13/action_set_mpls_ttl.raw
Binary file not shown.
Binary file added features/open_flow13/action_set_nw_ttl.raw
Binary file not shown.
Binary file added features/open_flow13/action_set_queue.raw
Binary file not shown.
43 changes: 43 additions & 0 deletions features/open_flow13/apply_actions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Feature: Apply-Actions instruction.
Background:
Given I use OpenFlow 1.3

Scenario: new()
When I try to create an OpenFlow instruction with:
"""
Pio::Apply.new
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::Apply |
| instruction_type | 4 |
| instruction_length | 8 |
| actions | [] |

Scenario: new(SendOutPort.new(1))
When I try to create an OpenFlow instruction with:
"""
Pio::Apply.new(SendOutPort.new(1))
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::Apply |
| instruction_type | 4 |
| instruction_length | 24 |
| actions.size | 1 |
| actions.at(0).class | Pio::SendOutPort |
| actions.at(0).port | 1 |

Scenario: read
When I try to parse a file named "open_flow13/apply_actions.raw" with "Pio::Apply" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::Apply |
| instruction_type | 4 |
| instruction_length | 24 |
| actions.size | 1 |
| actions.at(0).class | Pio::SendOutPort |
| actions.at(0).port | 1 |
Binary file added features/open_flow13/apply_actions.raw
Binary file not shown.
Binary file added features/open_flow13/flow_add_apply_no_match.raw
Binary file not shown.
146 changes: 146 additions & 0 deletions features/open_flow13/flow_mod.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Feature: Pio::FlowMod
Background:
Given I use OpenFlow 1.3

Scenario: new
When I try to create an OpenFlow message with:
"""
Pio::FlowMod.new
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::FlowMod |
| ofp_version | 4 |
| message_type | 14 |
| message_length | 56 |
| transaction_id | 0 |
| xid | 0 |
| cookie | 0 |
| cookie_mask | 0 |
| table_id | 0 |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority.to_hex | 0xffff |
| buffer_id | :no_buffer |
| out_port | :any |
| out_group | :any |
| flags | [] |
| match.match_fields | [] |
| instructions | [] |

Scenario: new(instructions: Pio::Apply.new(SendOutPort.new(1)))
When I try to create an OpenFlow message with:
"""
Pio::FlowMod.new(instructions: Pio::Apply.new(SendOutPort.new(1)))
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::FlowMod |
| ofp_version | 4 |
| message_type | 14 |
| message_length | 80 |
| transaction_id | 0 |
| xid | 0 |
| cookie | 0 |
| cookie_mask | 0 |
| table_id | 0 |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority.to_hex | 0xffff |
| buffer_id | :no_buffer |
| out_port | :any |
| out_group | :any |
| flags | [] |
| match.match_fields | [] |
| instructions.size | 1 |
| instructions.at(0).class | Pio::Apply |
| instructions.at(0).actions.at(0).class | Pio::SendOutPort |
| instructions.at(0).actions.at(0).port | 1 |

Scenario: new(match: Pio::Match.new(in_port: 1), instructions: Pio::Apply.new(SendOutPort.new(1)))
When I try to create an OpenFlow message with:
"""
Pio::FlowMod.new(match: Pio::Match.new(in_port: 1), instructions: Pio::Apply.new(SendOutPort.new(1)))
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::FlowMod |
| ofp_version | 4 |
| message_type | 14 |
| message_length | 88 |
| transaction_id | 0 |
| xid | 0 |
| cookie | 0 |
| cookie_mask | 0 |
| table_id | 0 |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority.to_hex | 0xffff |
| buffer_id | :no_buffer |
| out_port | :any |
| out_group | :any |
| flags | [] |
| match.in_port | 1 |
| instructions.size | 1 |
| instructions.at(0).class | Pio::Apply |
| instructions.at(0).actions.at(0).class | Pio::SendOutPort |
| instructions.at(0).actions.at(0).port | 1 |

Scenario: read (no match or instructions)
When I try to parse a file named "open_flow13/flow_mod_no_match_or_instructions.raw" with "Pio::FlowMod" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::FlowMod |
| ofp_version | 4 |
| message_type | 14 |
| message_length | 56 |
| transaction_id | 0 |
| xid | 0 |
| cookie | 0 |
| cookie_mask | 0 |
| table_id | 0 |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority.to_hex | 0xffff |
| buffer_id | :no_buffer |
| out_port | :any |
| out_group | :any |
| flags | [] |
| match.match_fields | [] |
| instructions | [] |

Scenario: read (instruction = apply, action = SendOutPort(port: 1))
When I try to parse a file named "open_flow13/flow_mod_add_apply_no_match.raw" with "Pio::FlowMod" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::FlowMod |
| ofp_version | 4 |
| message_type | 14 |
| message_length | 80 |
| transaction_id | 0 |
| xid | 0 |
| cookie | 0 |
| cookie_mask | 0 |
| table_id | 0 |
| command | :add |
| idle_timeout | 0 |
| hard_timeout | 0 |
| priority.to_hex | 0xffff |
| buffer_id | :no_buffer |
| out_port | :any |
| out_group | :any |
| flags | [] |
| match.match_fields | [] |
| instructions.size | 1 |
| instructions.at(0).class | Pio::Apply |
| instructions.at(0).actions.at(0).class | Pio::SendOutPort |
| instructions.at(0).actions.at(0).port | 1 |
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions features/open_flow13/goto_table.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Pio::GotoTable
Background:
Given I use OpenFlow 1.3

Scenario: new(1)
When I try to create an OpenFlow instruction with:
"""
Pio::GotoTable.new(1)
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::GotoTable |
| instruction_type | 1 |
| instruction_length | 8 |
| table_id | 1 |

Scenario: read
When I try to parse a file named "open_flow13/instruction_goto_table.raw" with "Pio::GotoTable" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::GotoTable |
| instruction_type | 1 |
| instruction_length | 8 |
| table_id | 1 |
Binary file not shown.
Binary file added features/open_flow13/instruction_goto_table.raw
Binary file not shown.
Binary file added features/open_flow13/instruction_meter.raw
Binary file not shown.
Binary file added features/open_flow13/instruction_write_actions.raw
Binary file not shown.
Binary file added features/open_flow13/instruction_write_metadata.raw
Binary file not shown.
26 changes: 26 additions & 0 deletions features/open_flow13/meter.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Pio::Meter
Background:
Given I use OpenFlow 1.3

Scenario: new(1)
When I try to create an OpenFlow instruction with:
"""
Pio::Meter.new(1)
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::Meter |
| instruction_type | 6 |
| instruction_length | 8 |
| meter_id | 1 |

Scenario: read
When I try to parse a file named "open_flow13/instruction_meter.raw" with "Pio::Meter" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::Meter |
| instruction_type | 6 |
| instruction_length | 8 |
| meter_id | 1 |
28 changes: 28 additions & 0 deletions features/open_flow13/send_out_port.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Pio::SendOutPort
Background:
Given I use OpenFlow 1.3

Scenario: new(1)
When I try to create an OpenFlow action with:
"""
Pio::SendOutPort.new(1)
"""
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::SendOutPort |
| action_type | 0 |
| action_length | 16 |
| port | 1 |
| max_length | :no_buffer |

Scenario: read
When I try to parse a file named "open_flow13/send_out_port.raw" with "Pio::SendOutPort" class
Then it should finish successfully
And the message have the following fields and values:
| field | value |
| class | Pio::SendOutPort |
| action_type | 0 |
| action_length | 16 |
| port | 1 |
| max_length | :no_buffer |
Binary file added features/open_flow13/send_out_port.raw
Binary file not shown.
Loading

0 comments on commit a25cdce

Please sign in to comment.