Class: OFController
- Inherits:
-
Object
- Object
- OFController
- Defined in:
- lib/controller.rb
Constant Summary collapse
- DEFAULT_IP_ADDRESS =
'0.0.0.0'- DEFAULT_TCP_PORT =
6633
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
- .create(*args) ⇒ Object
- .inherited(subclass) ⇒ Object
- .timer_event(handler, options) ⇒ Object
- .timer_handlers ⇒ Object
Instance Method Summary collapse
- #echo_request(datapath_id, msg) ⇒ Object
- #flow_removed(_datapath_id, _msg) ⇒ Object
-
#initialize(level = Logger::INFO) ⇒ OFController
constructor
A new instance of OFController.
- #packet_in(_datapath_id, _msg) ⇒ Object
- #port_add(_datapath_id, _msg) ⇒ Object
- #port_delete(_datapath_id, _msg) ⇒ Object
- #port_modify(_datapath_id, _msg) ⇒ Object
- #run(ip, port, *args) ⇒ Object
- #send_message(datapath_id, msg) ⇒ Object
- #start(*_args) ⇒ Object
- #switch_ready(_datapath_id) ⇒ Object
Constructor Details
#initialize(level = Logger::INFO) ⇒ OFController
Returns a new instance of OFController.
32 33 34 35 36 37 38 39 40 |
# File 'lib/controller.rb', line 32 def initialize(level = Logger::INFO) @switches = {} @logger = Logger.new($stdout).tap do |logger| logger.formatter = proc do |severity, datetime, _progname, msg| "#{datetime} (#{severity}) -- #{msg}\n" end logger.level = level end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
30 31 32 |
# File 'lib/controller.rb', line 30 def logger @logger end |
Class Method Details
.create(*args) ⇒ Object
17 18 19 |
# File 'lib/controller.rb', line 17 def self.create(*args) @controller_class.new(*args) end |
.inherited(subclass) ⇒ Object
13 14 15 |
# File 'lib/controller.rb', line 13 def self.inherited(subclass) @controller_class = subclass end |
.timer_event(handler, options) ⇒ Object
21 22 23 24 |
# File 'lib/controller.rb', line 21 def self.timer_event(handler, ) @timer_handlers ||= {} @timer_handlers[handler] = .fetch(:interval) end |
.timer_handlers ⇒ Object
26 27 28 |
# File 'lib/controller.rb', line 26 def self.timer_handlers @timer_handlers || {} end |
Instance Method Details
#echo_request(datapath_id, msg) ⇒ Object
56 57 58 |
# File 'lib/controller.rb', line 56 def echo_request(datapath_id, msg) datapath_id, OFEchoReply.new(xid: msg.xid) end |
#flow_removed(_datapath_id, _msg) ⇒ Object
63 |
# File 'lib/controller.rb', line 63 def flow_removed(_datapath_id, _msg) end |
#packet_in(_datapath_id, _msg) ⇒ Object
59 |
# File 'lib/controller.rb', line 59 def packet_in(_datapath_id, _msg) end |
#port_add(_datapath_id, _msg) ⇒ Object
60 |
# File 'lib/controller.rb', line 60 def port_add(_datapath_id, _msg) end |
#port_delete(_datapath_id, _msg) ⇒ Object
61 |
# File 'lib/controller.rb', line 61 def port_delete(_datapath_id, _msg) end |
#port_modify(_datapath_id, _msg) ⇒ Object
62 |
# File 'lib/controller.rb', line 62 def port_modify(_datapath_id, _msg) end |
#run(ip, port, *args) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/controller.rb', line 42 def run(ip, port, *args) maybe_send_handler :start, *args socket = TCPServer.open(ip, port) logger.info "Controller running on #{ip}:#{port}." start_timers loop { start_switch_thread socket.accept } end |
#send_message(datapath_id, msg) ⇒ Object
50 51 52 |
# File 'lib/controller.rb', line 50 def (datapath_id, msg) @switches.fetch(datapath_id).send(msg) end |
#start(*_args) ⇒ Object
54 |
# File 'lib/controller.rb', line 54 def start(*_args) end |
#switch_ready(_datapath_id) ⇒ Object
55 |
# File 'lib/controller.rb', line 55 def switch_ready(_datapath_id) end |