Class: Phut::OpenVswitch
- Inherits:
-
Object
- Object
- Phut::OpenVswitch
- 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
-
#dpid ⇒ Object
(also: #datapath_id)
readonly
Returns the value of attribute dpid.
-
#interfaces ⇒ Object
writeonly
Sets the attribute interfaces.
Instance Method Summary collapse
- #bring_port_down(port_number) ⇒ Object
- #bring_port_up(port_number) ⇒ Object
- #dump_flows ⇒ Object
-
#initialize(dpid, name = nil, logger = NullLogger.new) ⇒ OpenVswitch
constructor
A new instance of OpenVswitch.
- #maybe_stop ⇒ Object
- #name ⇒ Object
- #run ⇒ Object (also: #start)
- #running? ⇒ Boolean
- #stop ⇒ Object (also: #shutdown)
- #to_s ⇒ Object
Methods included from ShellRunner
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
#dpid ⇒ Object (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
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_flows ⇒ Object
61 62 63 |
# File 'lib/phut/open_vswitch.rb', line 61 def dump_flows sh "sudo #{OFCTL} dump-flows #{network_device}" end |
#maybe_stop ⇒ Object
48 49 50 51 |
# File 'lib/phut/open_vswitch.rb', line 48 def maybe_stop return unless running? stop end |
#name ⇒ Object
26 27 28 |
# File 'lib/phut/open_vswitch.rb', line 26 def name @name || format('%#x', @dpid) end |
#run ⇒ Object Also known as: start
34 35 36 37 38 |
# File 'lib/phut/open_vswitch.rb', line 34 def run sh "sudo #{OPENFLOWD} #{.join ' '}" rescue raise "Open vSwitch (dpid = #{@dpid}) is already running!" end |
#running? ⇒ Boolean
65 66 67 |
# File 'lib/phut/open_vswitch.rb', line 65 def running? FileTest.exists?(pid_file) end |
#stop ⇒ Object 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_s ⇒ Object
30 31 32 |
# File 'lib/phut/open_vswitch.rb', line 30 def to_s "vswitch (name = #{name}, dpid = #{format('%#x', @dpid)})" end |