Skip to content

Commit

Permalink
Update request in Virtual OF Switch RC
Browse files Browse the repository at this point in the history
  • Loading branch information
kohoumas committed Mar 17, 2013
1 parent 681a70c commit 32519f3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions example/openflow_slice_factory_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
}
}

OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/util")
OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy")
OmfRc::ResourceFactory.load_additional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/util")
OmfRc::ResourceFactory.load_additional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy")

OmfCommon.init(op_mode, opts) do |el|
OmfCommon.comm.on_connected do |comm|
Expand Down
2 changes: 1 addition & 1 deletion example/openflow_slice_factory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def create_slice(flowvisor)
flowvisor.create(:openflow_slice, {name: "test"}) do |reply_msg|
if !reply_msg.itype.start_with? "ERROR" #success?
if reply_msg.success?
slice = reply_msg.resource

slice.on_subscribed do
Expand Down
4 changes: 2 additions & 2 deletions example/virtual_openflow_switch_factory_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
}
}

OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/util")
OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy")
OmfRc::ResourceFactory.load_additional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/util")
OmfRc::ResourceFactory.load_additional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy")

OmfCommon.init(op_mode, opts) do |el|
OmfCommon.comm.on_connected do |comm|
Expand Down
14 changes: 6 additions & 8 deletions example/virtual_openflow_switch_factory_test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# OMF_VERSIONS = 6.0

#msgs = {
# request_port: @comm.request_message([port: {name: 'tun0', information: 'netdev-tunnel/get-port'}]),
# configure_port: @comm.configure_message([port: {name: 'tun0', remote_ip: '138.48.3.201', remote_port: '39505'}]),
#}

def create_switch(ovs)
ovs.create(:virtual_openflow_switch, {name: "test"}) do |reply_msg|
if !reply_msg.itype.start_with? "ERROR" #success?
if reply_msg.success?
switch = reply_msg.resource

switch.on_subscribed do
Expand All @@ -30,8 +25,11 @@ def on_switch_created(switch)

switch.configure(ports: {operation: 'add', name: 'tun0', type: 'tunnel'}) do |reply_msg|
info "> Switch configured ports: #{reply_msg[:ports]}"
switch.configure(port: {name: 'tun0', remote_ip: '138.48.3.201', remote_port: '39505'}) do |reply_msg|
info "> Switch configured port: #{reply_msg[:port]}"
switch.request([:tunnel_port_numbers]) do |reply_msg|
info "> Switch requested tunnel port: #{reply_msg[:tunnel_port_numbers]}"
switch.configure(tunnel_port: {name: 'tun0', remote_ip: '127.0.0.1', remote_port: '1234'}) do |reply_msg|
info "> Switch configured tunnel port: #{reply_msg[:tunnel_port]}"
end
end
end

Expand Down
28 changes: 16 additions & 12 deletions lib/omf_rc/resource_proxy/virtual_openflow_switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module OmfRc::ResourceProxy::VirtualOpenflowSwitch
end


# Add/remove port
# Add/remove ports to this switch
configure :ports do |resource, array_parameters|
array_parameters = [array_parameters] if !array_parameters.kind_of?(Array)
array_parameters.each do |parameters|
Expand Down Expand Up @@ -75,18 +75,22 @@ module OmfRc::ResourceProxy::VirtualOpenflowSwitch
resource.ports
end

# Request port information (XXX: very restrictive, just to support our case)
request :port do |resource, parameters|
arguments = {
"method" => parameters.information,
"params" => [parameters.name],
"id" => "port-info"
}
resource.ovs_connection("ovs-vswitchd", arguments)["result"]
# Request tunnel port numbers of this switch
request :tunnel_port_numbers do |resource|
ports = resource.ports("tunnel")
port_num = ports.map do |port|
arguments = {
"method" => "netdev-tunnel/get-port",
"params" => [port],
"id" => "port-number"
}
[port, resource.ovs_connection("ovs-vswitchd", arguments)["result"]]
end
Hashie::Mash.new(Hash[port_num])
end

# Configure port (XXX: very restrictive, just to support our case)
configure :port do |resource, parameters|
# Configure tunnel ports
configure :tunnel_port do |resource, parameters|
arguments = {
"method" => "transact",
"params" => [ "Open_vSwitch",
Expand All @@ -97,7 +101,7 @@ module OmfRc::ResourceProxy::VirtualOpenflowSwitch
[["remote_ip", parameters.remote_ip], ["remote_port", parameters.remote_port.to_s]]]]]
}
],
"id" => "configure-port"
"id" => "configure-tunnel-port"
}
resource.ovs_connection("ovsdb-server", arguments)["result"]
end
Expand Down
22 changes: 17 additions & 5 deletions lib/omf_rc/util/virtual_openflow_switch_tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module OmfRc::Util::VirtualOpenflowSwitchTools
JSON.parse(string)
end

# Internal function that returns the ports of a specific switch
work :ports do |resource|
# Internal function that returns the switch ports with interfaces of the specified type, if this type is given
work :ports do |resource, type = nil|
arguments = {
"method" => "transact",
"params" => [ "Open_vSwitch",
Expand All @@ -54,9 +54,21 @@ module OmfRc::Util::VirtualOpenflowSwitchTools
],
"id" => "ports"
}
if type
arguments["params"] << { "op" => "select",
"table" => "Interface",
"where" => [["type", "==", type.to_s]],
"columns" => ["name"]
}
end
result = resource.ovs_connection("ovsdb-server", arguments)["result"]
uuid2name = Hash[result[1]["rows"].map {|hash_uuid_name| [hash_uuid_name["_uuid"][1], hash_uuid_name["name"]]}]
uuids = result[0]["rows"][0]["ports"][1].map {|array_uuid| array_uuid[1]}
uuids.map {|v| uuid2name[v]}
uuid2name = Hashie::Mash.new(Hash[result[1]["rows"].map {|h| [h["_uuid"][1], h["name"]]}]) # hash-table port uuid=>name
uuids = result[0]["rows"][0]["ports"][1].map {|a| a[1]} # The uuids of the switch ports
ports = uuids.map {|v| uuid2name[v]} # The names of the switch ports
if type
ports_of_type = result[2]["rows"].map {|h| h["name"]} # The names of the ports with interfaces of the specified type
ports = ports & ports_of_type # The names of the switch ports with interfaces of the specified type
end
ports
end
end
2 changes: 1 addition & 1 deletion lib/omf_rc_openflow/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OmfRcOpenflow
VERSION = "6.0.0.pre.2"
VERSION = "6.0.0.pre.3"
end

0 comments on commit 32519f3

Please sign in to comment.