Class: Trema::Switch

Inherits:
Object
  • Object
show all
Includes:
Pio
Defined in:
lib/trema/switch.rb

Overview

OpenFlow switch.

Defined Under Namespace

Classes: InitError

Constant Summary collapse

OPENFLOW_HEADER_LENGTH =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Switch

Returns a new instance of Switch.



16
17
18
# File 'lib/trema/switch.rb', line 16

def initialize(socket)
  @socket = socket
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



8
9
10
# File 'lib/trema/switch.rb', line 8

def error_message
  @error_message
end

Instance Method Details

#datapath_idObject Also known as: dpid



29
30
31
32
# File 'lib/trema/switch.rb', line 29

def datapath_id
  raise 'Switch is not initialized.' unless @features_reply
  @features_reply.datapath_id
end

#initObject



20
21
22
23
24
25
26
27
# File 'lib/trema/switch.rb', line 20

def init
  exchange_messages message_to_send: Hello, message_to_receive: Hello
  exchange_messages(message_to_send: Echo::Request,
                    message_to_receive: Echo::Reply)
  @features_reply = exchange_messages(message_to_send: Features::Request,
                                      message_to_receive: Features::Reply)
  self
end

#readObject



44
45
46
# File 'lib/trema/switch.rb', line 44

def read
  OpenFlow.read read_openflow_binary
end

#write(message) ⇒ Object



35
36
37
38
# File 'lib/trema/switch.rb', line 35

def write(message)
  Trema.logger.debug "Sending #{message.inspect}"
  @socket.write message.to_binary
end

#write_binary(binary) ⇒ Object



40
41
42
# File 'lib/trema/switch.rb', line 40

def write_binary(binary)
  @socket.write binary
end