Class: Trema::Flow

Inherits:
Object
  • Object
show all
Defined in:
ruby/trema/flow.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(line) ⇒ self

Parses a text line of OpenFlow switch’s dump-flows command into a Flow object’s dynamic created attributes. A line consists of multiple comma separated key=value fields. A key field may have multiple values specified as key=value#1,value#2,..value#n.

Parameters:

  • line (String)

    the text line to parse.

Returns:

  • (self)

    the object that holds the parsed key=value fields as attributes.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'ruby/trema/flow.rb', line 34

def self.parse line
  flow = self.new
  # to simplify parsing
  line.sub!(/actions=.*,.*$/) { | match | match.gsub(/,/,'/') }
  line.strip.split( /[,\s]\s*/ ).each do | each |
    next unless /(.+)=(.+)/=~ each
    name, value = $1, $2
    attr_reader name.to_sym
    if ( /\A\d+\Z/=~ value ) or ( /\A0x.+\Z/=~ value )
      flow.instance_eval "@#{ name }=#{ value }"
    else
      flow.instance_eval "@#{ name }='#{ value }'"
    end
  end
  flow
end

Instance Method Details

#users_flow?Boolean

Returns whether a flow is a user registered flow or not.

Returns:

  • (Boolean)

    whether a flow is a user registered flow or not.



53
54
55
56
# File 'ruby/trema/flow.rb', line 53

def users_flow?
  not ( ( @actions == "drop" and @priority == 0 ) or
        @actions == "CONTROLLER:65535" )
end