Class: OpenFlow::Controller::Controller
- Inherits:
-
Object
- Object
- OpenFlow::Controller::Controller
- Includes:
- Protocol
- Defined in:
- lib/openflow-controller/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
- #broadcast(msg) ⇒ Object
- #datapath_ids ⇒ Object
- #echo_request(datapath_id, msg) ⇒ Object
- #error(_datapath_id, _msg) ⇒ Object
- #eval(input) ⇒ Object
- #flow_removed(_datapath_id, _msg) ⇒ Object
-
#initialize(debug = false) ⇒ Controller
constructor
A new instance of Controller.
- #last_message ⇒ Object
- #last_message_for(datapath_id) ⇒ Object
- #message_received(_datapath_id, _msg) ⇒ Object
- #messages ⇒ Object
- #messages_for(datapath_id) ⇒ Object
- #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 = DEFAULT_IP_ADDRESS, port = DEFAULT_TCP_PORT, *args) ⇒ Object
- #send_message(datapath_id, msg = nil) ⇒ Object
- #start(*_args) ⇒ Object
- #switch_ready(_datapath_id) ⇒ Object
- #switches ⇒ Object
Constructor Details
#initialize(debug = false) ⇒ Controller
Returns a new instance of Controller.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/openflow-controller/controller.rb', line 36 def initialize(debug = false) @switches = {} = {} @logger = Logger.new($stdout).tap do |logger| logger.formatter = proc do |severity, datetime, _progname, msg| "#{datetime} (#{severity}) -- #{msg}\n" end logger.level = debug ? Logger::DEBUG : Logger::INFO end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
34 35 36 |
# File 'lib/openflow-controller/controller.rb', line 34 def logger @logger end |
Class Method Details
.create(*args) ⇒ Object
21 22 23 |
# File 'lib/openflow-controller/controller.rb', line 21 def self.create(*args) (@controller_class || self).new(*args) end |
.inherited(subclass) ⇒ Object
17 18 19 |
# File 'lib/openflow-controller/controller.rb', line 17 def self.inherited(subclass) @controller_class = subclass end |
.timer_event(handler, options) ⇒ Object
25 26 27 28 |
# File 'lib/openflow-controller/controller.rb', line 25 def self.timer_event(handler, ) @timer_handlers ||= {} @timer_handlers[handler] = .fetch(:interval) end |
.timer_handlers ⇒ Object
30 31 32 |
# File 'lib/openflow-controller/controller.rb', line 30 def self.timer_handlers @timer_handlers || {} end |
Instance Method Details
#broadcast(msg) ⇒ Object
76 77 78 |
# File 'lib/openflow-controller/controller.rb', line 76 def broadcast(msg) datapath_ids.each { |did| did, msg } end |
#datapath_ids ⇒ Object
60 61 62 |
# File 'lib/openflow-controller/controller.rb', line 60 def datapath_ids @switches.keys.map(&:to_i) end |
#echo_request(datapath_id, msg) ⇒ Object
100 101 102 |
# File 'lib/openflow-controller/controller.rb', line 100 def echo_request(datapath_id, msg) datapath_id, EchoReply.new(xid: msg.xid) end |
#error(_datapath_id, _msg) ⇒ Object
99 |
# File 'lib/openflow-controller/controller.rb', line 99 def error(_datapath_id, _msg) end |
#eval(input) ⇒ Object
47 48 49 |
# File 'lib/openflow-controller/controller.rb', line 47 def eval(input) binding.eval(input) end |
#flow_removed(_datapath_id, _msg) ⇒ Object
107 |
# File 'lib/openflow-controller/controller.rb', line 107 def flow_removed(_datapath_id, _msg) end |
#last_message ⇒ Object
92 93 94 |
# File 'lib/openflow-controller/controller.rb', line 92 def .last end |
#last_message_for(datapath_id) ⇒ Object
84 85 86 |
# File 'lib/openflow-controller/controller.rb', line 84 def (datapath_id) (datapath_id).last end |
#message_received(_datapath_id, _msg) ⇒ Object
98 |
# File 'lib/openflow-controller/controller.rb', line 98 def (_datapath_id, _msg) end |
#messages ⇒ Object
88 89 90 |
# File 'lib/openflow-controller/controller.rb', line 88 def datapath_ids.first end |
#messages_for(datapath_id) ⇒ Object
80 81 82 |
# File 'lib/openflow-controller/controller.rb', line 80 def (datapath_id) .fetch(datapath_id.to_s) end |
#packet_in(_datapath_id, _msg) ⇒ Object
103 |
# File 'lib/openflow-controller/controller.rb', line 103 def packet_in(_datapath_id, _msg) end |
#port_add(_datapath_id, _msg) ⇒ Object
104 |
# File 'lib/openflow-controller/controller.rb', line 104 def port_add(_datapath_id, _msg) end |
#port_delete(_datapath_id, _msg) ⇒ Object
105 |
# File 'lib/openflow-controller/controller.rb', line 105 def port_delete(_datapath_id, _msg) end |
#port_modify(_datapath_id, _msg) ⇒ Object
106 |
# File 'lib/openflow-controller/controller.rb', line 106 def port_modify(_datapath_id, _msg) end |
#run(ip = DEFAULT_IP_ADDRESS, port = DEFAULT_TCP_PORT, *args) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/openflow-controller/controller.rb', line 51 def run(ip = DEFAULT_IP_ADDRESS, port = DEFAULT_TCP_PORT, *args) maybe_send_handler :start, *args socket = TCPServer.open(ip, port) socket.setsockopt(:SOCKET, :REUSEADDR, true) logger.info "Controller running on #{ip}:#{port}." start_timers loop { start_switch_thread socket.accept } end |
#send_message(datapath_id, msg = nil) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/openflow-controller/controller.rb', line 68 def (datapath_id, msg = nil) if msg.nil? msg = datapath_id datapath_id = datapath_ids.first end @switches.fetch(datapath_id.to_s).send(msg) end |
#start(*_args) ⇒ Object
96 |
# File 'lib/openflow-controller/controller.rb', line 96 def start(*_args) end |
#switch_ready(_datapath_id) ⇒ Object
97 |
# File 'lib/openflow-controller/controller.rb', line 97 def switch_ready(_datapath_id) end |
#switches ⇒ Object
64 65 66 |
# File 'lib/openflow-controller/controller.rb', line 64 def switches @switches.values end |