Skip to content

Commit

Permalink
Add Flow Removed message parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuhito committed Oct 25, 2015
1 parent aad04f1 commit 32d1199
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Rakefile
@@ -1,7 +1,7 @@
require 'bundler/gem_tasks'

RELISH_PROJECT = 'trema/pio'
FLAY_THRESHOLD = 1007
FLAY_THRESHOLD = 1069

task default: :travis
task test: [:spec, :cucumber]
Expand Down
34 changes: 34 additions & 0 deletions features/open_flow10/flow_removed.feature
@@ -0,0 +1,34 @@
@open_flow10
Feature: Pio::FlowRemoved

@open_flow10
Scenario: read
When I try to parse a file named "open_flow10/flow_removed.raw" with "FlowRemoved" class
Then it should finish successfully
And the message has the following fields and values:
| field | value |
| ofp_version | 1 |
| message_type | 11 |
| message_length | 88 |
| transaction_id | 0 |
| xid | 0 |
| match.wildcards.keys.size | 11 |
| match.wildcards.fetch(:ether_destination_address) | true |
| match.wildcards.fetch(:ether_source_address) | true |
| match.wildcards.fetch(:ether_type) | true |
| match.wildcards.fetch(:ip_destination_address_all) | true |
| match.wildcards.fetch(:ip_protocol) | true |
| match.wildcards.fetch(:ip_source_address_all) | true |
| match.wildcards.fetch(:ip_tos) | true |
| match.wildcards.fetch(:transport_destination_port) | true |
| match.wildcards.fetch(:transport_source_port) | true |
| match.wildcards.fetch(:vlan_priority) | true |
| match.wildcards.fetch(:vlan_vid) | true |
| cookie | 1 |
| priority | 65535 |
| reason | :delete |
| duration_sec | 0 |
| duration_nsec | 0 |
| idle_timeout | 0 |
| packet_count | 0 |
| byte_count | 0 |
3 changes: 2 additions & 1 deletion lib/pio/open_flow.rb
Expand Up @@ -16,7 +16,7 @@ def self.version

def self.switch_version(version)
[:Barrier, :Echo, :Features, :FlowMod, :Hello, :Match,
:PacketIn, :PacketOut, :SendOutPort, :PortStatus, :Stats,
:PacketIn, :FlowRemoved, :PacketOut, :SendOutPort, :PortStatus, :Stats,
:FlowStats, :DescriptionStats, :AggregateStats, :Error].each do |each|
set_message_class_name each, version
@version = version.to_s
Expand All @@ -33,6 +33,7 @@ def self.read(binary)
5 => Pio::Features::Request,
6 => Pio::Features::Reply,
10 => Pio::PacketIn,
11 => Pio::FlowRemoved,
12 => Pio::PortStatus,
13 => Pio::PacketOut,
14 => Pio::FlowMod,
Expand Down
3 changes: 2 additions & 1 deletion lib/pio/open_flow10.rb
@@ -1,5 +1,4 @@
# Messages
require 'pio/open_flow10/stats_reply'
require 'pio/open_flow10/aggregate_stats/reply'
require 'pio/open_flow10/aggregate_stats/request'
require 'pio/open_flow10/barrier/reply'
Expand All @@ -14,12 +13,14 @@
require 'pio/open_flow10/features/reply'
require 'pio/open_flow10/features/request'
require 'pio/open_flow10/flow_mod'
require 'pio/open_flow10/flow_removed'
require 'pio/open_flow10/flow_stats/reply'
require 'pio/open_flow10/flow_stats/request'
require 'pio/open_flow10/hello'
require 'pio/open_flow10/packet_in'
require 'pio/open_flow10/packet_out'
require 'pio/open_flow10/port_status'
require 'pio/open_flow10/stats_reply'
require 'pio/open_flow10/stats_request'

# Actions
Expand Down
40 changes: 40 additions & 0 deletions lib/pio/open_flow10/flow_removed.rb
@@ -0,0 +1,40 @@
require 'pio/open_flow/message'
require 'pio/open_flow10/match10'

module Pio
module OpenFlow10
# Flow Removed message
class FlowRemoved < OpenFlow::Message
# Why was this flow removed?
# (enum ofp_flow_removed_reason)
class Reason < BinData::Primitive
REASONS = { idle_timeout: 0, hard_timeout: 1, delete: 2 }

uint8 :reason

def get
REASONS.invert.fetch(reason)
end

def set(value)
self.reason = REASONS.fetch(value)
end
end

open_flow_header version: 1, message_type: 11, message_length: 88
match10 :match
uint64 :cookie
uint16 :priority
reason :reason
string :padding1, length: 1
hide :padding1
uint32 :duration_sec
uint32 :duration_nsec
uint16 :idle_timeout
string :padding2, length: 2
hide :padding2
uint64 :packet_count
uint64 :byte_count
end
end
end

0 comments on commit 32d1199

Please sign in to comment.