Class: Phut::OpenVswitch

Inherits:
Object
  • Object
show all
Includes:
ShellRunner
Defined in:
lib/phut/open_vswitch.rb

Overview

Open vSwitch controller.

Constant Summary collapse

OPENFLOWD =
"#{Phut.root}/vendor/openvswitch-1.2.2.trema1/tests/test-openflowd"
OFCTL =
"#{Phut.root}/vendor/openvswitch-1.2.2.trema1/utilities/ovs-ofctl"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShellRunner

#sh

Constructor Details

#initialize(dpid, name = nil, logger = NullLogger.new) ⇒ OpenVswitch

Returns a new instance of OpenVswitch.



19
20
21
22
23
24
# File 'lib/phut/open_vswitch.rb', line 19

def initialize(dpid, name = nil, logger = NullLogger.new)
  @dpid = dpid
  @name = name
  @interfaces = []
  @logger = logger
end

Instance Attribute Details

#dpidObject (readonly) Also known as: datapath_id

Returns the value of attribute dpid.



15
16
17
# File 'lib/phut/open_vswitch.rb', line 15

def dpid
  @dpid
end

#interfaces=(value) ⇒ Object (writeonly)

Sets the attribute interfaces

Parameters:

  • value

    the value to set the attribute interfaces to.



17
18
19
# File 'lib/phut/open_vswitch.rb', line 17

def interfaces=(value)
  @interfaces = value
end

Instance Method Details

#bring_port_down(port_number) ⇒ Object



57
58
59
# File 'lib/phut/open_vswitch.rb', line 57

def bring_port_down(port_number)
  sh "sudo #{OFCTL} mod-port #{network_device} #{port_number} down"
end

#bring_port_up(port_number) ⇒ Object



53
54
55
# File 'lib/phut/open_vswitch.rb', line 53

def bring_port_up(port_number)
  sh "sudo #{OFCTL} mod-port #{network_device} #{port_number} up"
end

#dump_flowsObject



61
62
63
# File 'lib/phut/open_vswitch.rb', line 61

def dump_flows
  sh "sudo #{OFCTL} dump-flows #{network_device}"
end

#maybe_stopObject



48
49
50
51
# File 'lib/phut/open_vswitch.rb', line 48

def maybe_stop
  return unless running?
  stop
end

#nameObject



26
27
28
# File 'lib/phut/open_vswitch.rb', line 26

def name
  @name || format('%#x', @dpid)
end

#runObject Also known as: start



34
35
36
37
38
# File 'lib/phut/open_vswitch.rb', line 34

def run
  sh "sudo #{OPENFLOWD} #{options.join ' '}"
rescue
  raise "Open vSwitch (dpid = #{@dpid}) is already running!"
end

#running?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/phut/open_vswitch.rb', line 65

def running?
  FileTest.exists?(pid_file)
end

#stopObject Also known as: shutdown



41
42
43
44
45
# File 'lib/phut/open_vswitch.rb', line 41

def stop
  fail "Open vSwitch (dpid = #{@dpid}) is not running!" unless running?
  pid = IO.read(pid_file).chomp
  sh "sudo kill #{pid}"
end

#to_sObject



30
31
32
# File 'lib/phut/open_vswitch.rb', line 30

def to_s
  "vswitch (name = #{name}, dpid = #{format('%#x', @dpid)})"
end