class OpenFlow::Controller::Switch

Attributes

controller[R]
features_reply[R]

Public Class Methods

new(controller, socket) click to toggle source
# File lib/openflow-controller/switch.rb, line 10
def initialize(controller, socket)
  @controller = controller
  @socket     = socket
  begin
    exchange_hello_messages
    exchange_echo_messages
    exchange_features_messages
  rescue => exception
    controller.logger.debug "Switch error: #{exception}."
    raise exception
  end
end

Public Instance Methods

datapath_id() click to toggle source
# File lib/openflow-controller/switch.rb, line 31
def datapath_id
  @features_reply.datapath_id
end
receive() click to toggle source
# File lib/openflow-controller/switch.rb, line 27
def receive
  Parser.read @socket
end
send(msg) click to toggle source
# File lib/openflow-controller/switch.rb, line 23
def send(msg)
  @socket.write msg.to_binary_s
end

Private Instance Methods

exchange_echo_messages() click to toggle source
# File lib/openflow-controller/switch.rb, line 43
def exchange_echo_messages
  send EchoRequest.new
  controller.logger.debug 'Wait OFPT_ECHO_REPLY.'
  fail unless receive.is_a?(EchoReply)
end
exchange_features_messages() click to toggle source
# File lib/openflow-controller/switch.rb, line 49
def exchange_features_messages
  send FeaturesRequest.new
  controller.logger.debug 'Wait OFPT_FEATURES_REPLY.'
  @features_reply = receive
  controller.logger.debug "OFPT_FEATURES_REPLY.datapath_id: #{datapath_id}."
  fail unless @features_reply.is_a?(FeaturesReply)
end
exchange_hello_messages() click to toggle source
# File lib/openflow-controller/switch.rb, line 37
def exchange_hello_messages
  controller.logger.debug 'Wait OFPT_HELLO.'
  fail unless receive.is_a?(Hello)
  send Hello.new
end