From f26f1a4c9a52115e04911dea641ce4c3f250533c Mon Sep 17 00:00:00 2001 From: kohoumas Date: Wed, 13 Feb 2013 15:23:43 +0200 Subject: [PATCH] add Virtual Openflow Switch Factory --- bin/omf_rc_virtual_openflow_switch_factory~ | 83 ---------- example/openflow_slice_factory_controller.rb~ | 33 ---- example/openflow_slice_factory_test.rb~ | 64 -------- ...ual_openflow_switch_factory_controller.rb~ | 32 ---- .../virtual_openflow_switch_factory_test.rb~ | 74 --------- lib/omf_rc/resource_proxy/openflow_slice.rb~ | 82 ---------- .../resource_proxy/openflow_slice_factory.rb~ | 72 --------- .../virtual_openflow_switch.rb~ | 143 ------------------ .../virtual_openflow_switch_factory.rb~ | 77 ---------- lib/omf_rc/util/openflow_slice_tools.rb~ | 102 ------------- .../util/virtual_openflow_switch_tools.rb~ | 60 -------- 11 files changed, 822 deletions(-) delete mode 100755 bin/omf_rc_virtual_openflow_switch_factory~ delete mode 100755 example/openflow_slice_factory_controller.rb~ delete mode 100644 example/openflow_slice_factory_test.rb~ delete mode 100755 example/virtual_openflow_switch_factory_controller.rb~ delete mode 100644 example/virtual_openflow_switch_factory_test.rb~ delete mode 100644 lib/omf_rc/resource_proxy/openflow_slice.rb~ delete mode 100644 lib/omf_rc/resource_proxy/openflow_slice_factory.rb~ delete mode 100644 lib/omf_rc/resource_proxy/virtual_openflow_switch.rb~ delete mode 100644 lib/omf_rc/resource_proxy/virtual_openflow_switch_factory.rb~ delete mode 100644 lib/omf_rc/util/openflow_slice_tools.rb~ delete mode 100644 lib/omf_rc/util/virtual_openflow_switch_tools.rb~ diff --git a/bin/omf_rc_virtual_openflow_switch_factory~ b/bin/omf_rc_virtual_openflow_switch_factory~ deleted file mode 100755 index 302c21f..0000000 --- a/bin/omf_rc_virtual_openflow_switch_factory~ +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env ruby - -require "optparse" -require 'omf_rc' -require 'omf_rc/resource_factory' -require 'omf_rc_openflow' - -$stdout.sync = true - -options = { - uid: `hostname`.chomp -} - -executable_name = File.basename($PROGRAM_NAME) -oml_enabled = false - -begin - oml_enabled = OML4R::init(ARGV, :appName => executable_name) do |opts| - opts.banner = "usage: #{executable_name} [options]" - - opts.on("-u USER", "Username") do |user| - options[:user] = user - end - - opts.on("-p PASSWORD", "Password") do |password| - options[:password] = password - end - - opts.on("-s SERVER", "PubSub server") do |server| - options[:server] = server - end - - opts.on("-t TOPIC", "PubSub topic to create, also becomes the uid of the resource, default to hostname") do |topic| - options[:uid] = topic - end - - opts.on("-d", "--debug", "Debug mode") do - options[:debug] = true - end - - opts.on("-l LOG_FILE_DIR", "Write log file to this folder") do |file_dir| - options[:log_file_dir] = file_dir - end - end -rescue => e - # Right now OML4R does not raise proper exceptions :( - # OML4R requires --oml-noop to be set if we want to run without doing any - # measurements... this is too restrictive here, we want to run without OML - # if no OML parameters were set and this even if --oml-noop is not set. - if e.message.include?('OML4R: Missing values for parameters :expID ') - puts "Warning: Missing some OML options to instrument this RC, so it will "+ - "run without instrumentation. (see --oml-help)" - else - puts e.message - exit(1) - end -end - -OmfCommon::Measure.enable if oml_enabled - -unless options[:server] && options[:user] && options[:password] - puts "Error: Missing parameters to connect to a PubSub Server (see --help)" - exit(1) -end - -Logging.logger.root.level = :debug if options[:debug] -Blather.logger = logger - -if options[:log_file_dir] && File.exist?(options[:log_file_dir]) - Logging.logger.root.add_appenders( - Logging.appenders.file( - "#{options[:log_file_dir]}/omf_rc.log", - :layout => Logging.layouts.pattern(:date_pattern => '%F %T %z', - :pattern => '[%d] %-5l %c: %m\n'))) -end - -EM.run do - virtual_openflow_switch_factory = OmfRc::ResourceFactory.new(:virtual_openflow_switch_factory, options) - virtual_openflow_switch_factory - - trap(:INT) { virtual_openflow_switch_factory.disconnect } - trap(:TERM) { virtual_openflow_switch_factory.disconnect } -end diff --git a/example/openflow_slice_factory_controller.rb~ b/example/openflow_slice_factory_controller.rb~ deleted file mode 100755 index eca589f..0000000 --- a/example/openflow_slice_factory_controller.rb~ +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env ruby - -require 'omf_rc' -require 'omf_rc/resource_factory' -#require 'omf_rc_openflow' -$stdout.sync = true - -Blather.logger = logger - -opts = { - # XMPP server domain - server: 'srv.mytestbed.net', - user: 'flowvisor', - password: 'pw', - uid: 'flowvisor', - # Debug mode of not - debug: false -} - -Logging.logger.root.level = :debug if opts[:debug] - -OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy") - -EM.run do - # Use resource factory method to initialise a new instance of garage - info "Starting #{opts[:uid]}" - flowvisor = OmfRc::ResourceFactory.new(:openflow_slice_factory, opts) - flowvisor.connect - - # Disconnect garage from XMPP server, when these two signals received - trap(:INT) { flowvisor.disconnect } - trap(:TERM) { flowvisor.disconnect } -end diff --git a/example/openflow_slice_factory_test.rb~ b/example/openflow_slice_factory_test.rb~ deleted file mode 100644 index 06ffec7..0000000 --- a/example/openflow_slice_factory_test.rb~ +++ /dev/null @@ -1,64 +0,0 @@ -# OMF_VERSIONS = 6.0 - -@comm = OmfEc.comm - -# @comm is default communicator defined in script runner -# -@flowvisor_id = "flowvisor" -@flowvisor_topic = @comm.get_topic(@flowvisor_id) - -@slice_id = nil -@slice_topic = nil - -msgs = { - create_slice: @comm.create_message([type: 'openflow_slice']), - config_slice: @comm.configure_message([name: 'test', contact_email: 'a@a']), - slices: @comm.request_message([:slices]), - config_flows: @comm.configure_message([flows: [{operation: 'add', device: '00:00:00:00:00:00:00:01', eth_dst: '11:22:33:44:55:66'}, - {operation: 'add', device: '00:00:00:00:00:00:00:01', eth_dst: '11:22:33:44:55:77'}]), -} - -@flowvisor_topic.subscribe {msgs[:create_slice].publish @flowvisor_id} - -# If flowvisor is not raised, the following rule will be activated. -@flowvisor_topic.on_message lambda {|m| m.operation == :inform && m.read_content('inform_type') == 'CREATION_FAILED' } do |message| - logger.error message.read_content('reason') - done! -end - -msgs[:create_slice].on_inform_creation_ok do |message| - @slice_id = message.resource_id - @slice_topic = @comm.get_topic(@slice_id) - - msgs[:release_slice] ||= @comm.release_message {|m| m.element('resource_id', @slice_id)} - msgs[:release_slice].on_inform_released do |message| - logger.info "Slice (#{@slice_id}) released" - m = @comm.request_message([:slices]) - m.on_inform_status do |message| - logger.info "Flowvisor (#{message.read_property('uid')}) requested slices: #{message.read_property('slices').join(', ')}" - done! - end - m.publish @flowvisor_id - end - - logger.info "Slice (#{@slice_id}) created" - @slice_topic.subscribe {msgs[:config_slice].publish @slice_id} -end - -msgs[:config_slice].on_inform_status do |message| - logger.info "Slice (#{message.read_property('uid')}) configured name: #{message.read_property('name')} & contact_email: #{message.read_property('contact_email')}" - msgs[:slices].publish @flowvisor_id -end - -msgs[:slices].on_inform_status do |message| - logger.info "Flowvisor (#{message.read_property('uid')}) requested slices: #{message.read_property('slices').join(', ')}" - msgs[:config_flows].publish @slice_id -end - -msgs[:config_flows].on_inform_status do |message| - logger.info "Slice (#{message.read_property('uid')}) configured flows: " - message.read_property('flows').each do |flow| - logger.info " #{flow}" - end - msgs[:release_slice].publish @flowvisor_id -end diff --git a/example/virtual_openflow_switch_factory_controller.rb~ b/example/virtual_openflow_switch_factory_controller.rb~ deleted file mode 100755 index 4e62fbb..0000000 --- a/example/virtual_openflow_switch_factory_controller.rb~ +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env ruby - -require 'omf_rc' -require 'omf_rc/resource_factory' -$stdout.sync = true - -Blather.logger = logger - -opts = { - # XMPP server domain - server: 'srv.mytestbed.net', - user: 'ovs', - password: 'pw', - uid: 'ovs', - # Debug mode of not - debug: false -} - -Logging.logger.root.level = :debug if opts[:debug] - -OmfRc::ResourceFactory.load_addtional_resource_proxies(File.dirname(__FILE__)+"/../lib/omf_rc/resource_proxy") - -EM.run do - # Use resource factory method to initialise a new instance of garage - info "Starting #{opts[:uid]}" - flowvisor = OmfRc::ResourceFactory.new(:virtual_openflow_switch_factory, opts) - flowvisor.connect - - # Disconnect garage from XMPP server, when these two signals received - trap(:INT) { flowvisor.disconnect } - trap(:TERM) { flowvisor.disconnect } -end diff --git a/example/virtual_openflow_switch_factory_test.rb~ b/example/virtual_openflow_switch_factory_test.rb~ deleted file mode 100644 index dcc51ba..0000000 --- a/example/virtual_openflow_switch_factory_test.rb~ +++ /dev/null @@ -1,74 +0,0 @@ -# OMF_VERSIONS = 6.0 - -@comm = OmfEc.comm - -# @comm is default communicator defined in script runner -# -@ovs_id = "ovs" -@ovs_topic = @comm.get_topic(@ovs_id) - -@switch_id = nil -@switch_topic = nil - - -msgs = { - switches: @comm.request_message([:switches]), - create_switch: @comm.create_message([type: 'virtual_openflow_switch']), - config_switch_name: @comm.configure_message([name: 'br0']), - config_add_port: @comm.configure_message([ports: {operation: 'add', name: 'tun0', type: 'tunnel'}]), - request_port: @comm.request_message([port: {information: 'netdev-tunnel/get-port', name: 'tun0'}]), - configure_port: @comm.configure_message([port: {name: 'tun0', remote_ip: '138.48.3.201', remote_port: '39505'}]), -} - -@ovs_topic.subscribe {msgs[:switches].publish @ovs_id} - -# If flowvisor is not raised, the following rule will be activated. -@ovs_topic.on_message lambda {|m| m.operation == :inform && m.read_content('inform_type') == 'CREATION_FAILED' } do |message| - logger.error message.read_content('reason') - done! -end - -msgs[:switches].on_inform_status do |message| - logger.info "OVS (#{message.read_property('uid')}) requested switches: #{message.read_property('switches')}" - msgs[:create_switch].publish @ovs_id -end - -msgs[:create_switch].on_inform_creation_ok do |message| - @switch_id = message.resource_id - @switch_topic = @comm.get_topic(@switch_id) - - msgs[:release_switch] ||= @comm.release_message {|m| m.element('resource_id', @switch_id)} - msgs[:release_switch].on_inform_released do |message| - logger.info "Switch (#{@switch_id}) released" - m = @comm.request_message([:switches]) - m.on_inform_status do |message| - logger.info "OVS (#{message.read_property('uid')}) requested switches: #{message.read_property('switches')}" - done! - end - m.publish @ovs_id - end - - logger.info "Switch (#{@switch_id}) created" - @switch_topic.subscribe {msgs[:config_switch_name].publish @switch_id} -end - -msgs[:config_switch_name].on_inform_status do |message| - logger.info "Switch (#{message.read_property('uid')}) configured name: #{message.read_property('name')}" - msgs[:config_add_port].publish @switch_id -end - -msgs[:config_add_port].on_inform_status do |message| - logger.info "Switch (#{message.read_property('uid')}) configured ports: #{message.read_property('ports')}" - msgs[:request_port].publish @switch_id -end - -msgs[:request_port].on_inform_status do |message| - logger.info "Switch (#{message.read_property('uid')}) requested port: #{message.read_property('port')}" - msgs[:configure_port].publish @switch_id -end - -msgs[:configure_port].on_inform_status do |message| - logger.info "Switch (#{message.read_property('uid')}) configured port: #{message.read_property('port')}" - done! #msgs[:release_switch].publish @ovs_id -end - diff --git a/lib/omf_rc/resource_proxy/openflow_slice.rb~ b/lib/omf_rc/resource_proxy/openflow_slice.rb~ deleted file mode 100644 index ad7f271..0000000 --- a/lib/omf_rc/resource_proxy/openflow_slice.rb~ +++ /dev/null @@ -1,82 +0,0 @@ -# This resource is created from the parent :openflow_slice_factory resource. -# It is related with a slice of a flowvisor instance, and behaves as a proxy between experimenter and the actual flowvisor slice. -# -module OmfRc::ResourceProxy::OpenflowSlice - include OmfRc::ResourceProxyDSL - - # The default parameters of a new slice. The openflow controller is assumed to be in the same working station with flowvisor instance - SLICE_DEFAULTS = { - passwd: "1234", - url: "tcp:127.0.0.1:9933", - email: "nothing@nowhere" - } - - - register_proxy :openflow_slice, :create_by => :openflow_slice_factory - - utility :openflow_tools - - - # Slice's name is initiated with value "nil" - hook :before_ready do |resource| - resource.property.name = nil - end - - # Before release, the related flowvisor instance should also remove the corresponding slice - hook :before_release do |resource| - resource.flowvisor_connection.call("api.deleteSlice", resource.property.name) - end - - - # The name is one-time configured - configure :name do |resource, name| - raise "The name cannot be changed" if resource.property.name - resource.property.name = name.to_s - begin - resource.flowvisor_connection.call("api.createSlice", name.to_s, *SLICE_DEFAULTS.values) - rescue Exception => e - if e.message["Cannot create slice with existing name"] - logger.warn message = "The requested slice already existed in Flowvisor" - else - raise e - end - end - resource.property.name - end - - # Configures the slice password - configure :passwd do |resource, passwd| - resource.flowvisor_connection.call("api.changePasswd", resource.property.name, passwd.to_s) - passwd.to_s - end - - # Configures the slice parameters - [:contact_email, :drop_policy, :controller_hostname, :controller_port].each do |configure_sym| - configure configure_sym do |resource, value| - resource.flowvisor_connection.call("api.changeSlice", resource.property.name, configure_sym.to_s, value.to_s) - value.to_s - end - end - - # Adds/removes a flow to this slice, specified by device, port, etc. - configure :flows do |resource, array_parameters| - array_parameters = [array_parameters] if !array_parameters.kind_of?(Array) - array_parameters.each do |parameters| - resource.flowvisor_connection.call("api.changeFlowSpace", resource.transformed_parameters(parameters)) - end - resource.flows - end - - - # Returns a hash table with the name of this slice, its controller (ip and port) and other related information - request :info do |resource| - result = resource.flowvisor_connection.call("api.getSliceInfo", resource.property.name) - result[:name] = resource.property.name - result - end - - # Returns a string with statistics about the use of this slice - request :stats do |resource| - resource.flowvisor_connection.call("api.getSliceStats", resource.property.name) - end -end diff --git a/lib/omf_rc/resource_proxy/openflow_slice_factory.rb~ b/lib/omf_rc/resource_proxy/openflow_slice_factory.rb~ deleted file mode 100644 index 9205409..0000000 --- a/lib/omf_rc/resource_proxy/openflow_slice_factory.rb~ +++ /dev/null @@ -1,72 +0,0 @@ -# This resourse is related with a flowvisor instance and behaves as a proxy between experimenter and flowvisor. -# -module OmfRc::ResourceProxy::OpenflowSliceFactory - include OmfRc::ResourceProxyDSL - - # The default arguments of the communication between this resource and the flowvisor instance - FLOWVISOR_CONNECTION_DEFAULTS = { - host: "localhost", - path: "/xmlrc", - port: "8080", - proxy_host: nil, - proxy_port: nil, - user: "fvadmin", - password: "openflow", - use_ssl: "true", - timeout: nil - } - - - register_proxy :openflow_slice_factory - - utility :openflow_slice_tools - - - # Checks if the created child is an :openflow_slice resource and passes the connection arguments that are essential for the connection with flowvisor instance - hook :before_create do |resource, type, opts = nil| - if type.to_sym != :openflow_slice - raise "This resource doesn't create resources of type "+type - end - begin - resource.flowvisor_connection - rescue - raise "This resource is not connected with a flowvisor instance, so it cannot create openflow slices" - end - opts.property ||= Hashie::Mash.new - opts.property.provider = ">> #{resource.uid}" - opts.property.flowvisor_connection_args = resource.property.flowvisor_connection_args - end - - - # A new resource uses the default connection arguments (ip adress, port, etc) to connect with a flowvisor instance - hook :before_ready do |resource| - resource.property.flowvisor_connection_args = FLOWVISOR_CONNECTION_DEFAULTS - end - - - # Configures the flowvisor connection arguments (ip adress, port, etc) - configure :flowvisor_connection do |resource, flowvisor_connection_args| - raise "Connection with a new flowvisor instance is not allowed if there exist created slices" if !resource.children.empty? - resource.property.flowvisor_connection_args.update(flowvisor_connection_args) - end - - - # Returns the flowvisor connection arguments (ip adress, port, etc) - request :flowvisor_connection do |resource| - resource.property.flowvisor_connection_args - end - - # Returns a list of the existed slices or the connected devices - {:slices => "listSlices", :devices => "listDevices"}.each do |request_sym, handler_name| - request request_sym do |resource| - resource.flowvisor_connection.call("api.#{handler_name}") - end - end - - # Returns information or statistics for a device specified by the given id - {:device_info => "getDeviceInfo", :device_stats => "getSwitchStats"}.each do |request_sym, handler_name| - request request_sym do |resource, device| - resource.flowvisor_connection.call("api.#{handler_name}", device.to_s) - end - end -end diff --git a/lib/omf_rc/resource_proxy/virtual_openflow_switch.rb~ b/lib/omf_rc/resource_proxy/virtual_openflow_switch.rb~ deleted file mode 100644 index 87f9ead..0000000 --- a/lib/omf_rc/resource_proxy/virtual_openflow_switch.rb~ +++ /dev/null @@ -1,143 +0,0 @@ -# This resource is created from the parent :virtual_openflow_switch_factory resource. -# It is related with a bridge of an ovsdb-server instance, and behaves as a proxy between experimenter and the actual ovsdb-server bridge. -# -module OmfRc::ResourceProxy::VirtualOpenflowSwitch - include OmfRc::ResourceProxyDSL - - register_proxy :virtual_openflow_switch, :create_by => :virtual_openflow_switch_factory - - utility :virtual_openflow_switch_tools - - - # Switch name is initiated with value "nil" - hook :before_ready do |resource| - resource.property.name = nil - end - - # Before release, the related ovsdb-server instance should also remove the corresponding switch - hook :before_release do |resource| - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "mutate", - "table" => "Open_vSwitch", - "where" => [], - "mutations" => [["bridges", "delete", ["set", [["uuid", resource.property.uuid]]]]] - }, - { "op" => "delete", - "table" => "Bridge", - "where" => [["name", "==", resource.property.name]], - }, - { "op" => "delete", - "table" => "Port", - "where" => [["name", "==", resource.property.name]] - }, - { "op" => "delete", - "table" => "Interface", - "where" => [["name", "==", resource.property.name]] - } - ], - "id" => "remove-switch" - } - resource.ovs_connection("ovsdb-server", arguments) - end - - - # Switch name is one-time configured - configure :name do |resource, name| - raise "The name cannot be changed" if resource.property.name - resource.property.name = name.to_s - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "insert", - "table" => "Interface", - "row" => {"name" => resource.property.name, "type" => "internal"}, - "uuid-name" => "new_interface" - }, - { "op" => "insert", - "table" => "Port", - "row" => {"name" => resource.property.name, "interfaces" => ["named-uuid", "new_interface"]}, - "uuid-name" => "new_port" - }, - { "op" => "insert", - "table" => "Bridge", - "row" => {"name" => resource.property.name, "ports" => ["named-uuid", "new_port"], "datapath_type" => "netdev"}, - "uuid-name" => "new_bridge" - }, - { "op" => "mutate", - "table" => "Open_vSwitch", - "where" => [], - "mutations" => [["bridges", "insert", ["set", [["named-uuid", "new_bridge"]]]]] - } - ], - "id" => "add-switch" - } - result = resource.ovs_connection("ovsdb-server", arguments)["result"] - raise "The requested switch already existed in ovsdb-server or there is another problem" if result[4] - resource.property.uuid = result[2]["uuid"][1] - resource.property.name - end - - # Add/remove port - configure :ports do |resource, array_parameters| - array_parameters = [array_parameters] if !array_parameters.kind_of?(Array) - array_parameters.each do |parameters| - arguments = nil - if parameters.operation == "add" - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "insert", - "table" => "Interface", - "row" => {"name" => parameters.name, "type" => parameters.type}, - "uuid-name" => "new_interface" - }, - { "op" => "insert", - "table" => "Port", - "row" => {"name" => parameters.name, "interfaces" => ["named-uuid", "new_interface"]}, - "uuid-name" => "new_port" - }, - { "op" => "mutate", - "table" => "Bridge", - "where" => [["name", "==", resource.property.name]], - "mutations" => [["ports", "insert", ["set", [["named-uuid", "new_port"]]]]] - } - ], - "id" => "add-port" - } - #elsif parameters.operation == "remove" - end - result = resource.ovs_connection("ovsdb-server", arguments)["result"] - raise "The configuration of the switch ports faced a problem" if result[3] - end - resource.ports - end - - # Request port information - request :port do |resource, parameters| - arguments = { - "method" => parameters.information, - "params" => [parameters.name], - "id" => "port-info" - } - resource.ovs_connection("ovs-vswitchd", arguments)["result"] - end - - # Configure port - configure :port do |resource, parameters| - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "mutate", - "table" => "Interface", - "where" => [["name", "==", parameters.name]], - "mutations" => [["options", "insert", ["map", - [["remote_ip", parameters.remote_ip], ["remote_port", parameters.remote_port.to_s]]]]] - } - ], - "id" => "configure-port" - } - resource.ovs_connection("ovsdb-server", arguments)["result"] - end -end diff --git a/lib/omf_rc/resource_proxy/virtual_openflow_switch_factory.rb~ b/lib/omf_rc/resource_proxy/virtual_openflow_switch_factory.rb~ deleted file mode 100644 index ce6f3b0..0000000 --- a/lib/omf_rc/resource_proxy/virtual_openflow_switch_factory.rb~ +++ /dev/null @@ -1,77 +0,0 @@ -# This resourse is related with an ovsdb-server (interface of an OVSDB database) and behaves as a proxy between experimenter and this. -# -module OmfRc::ResourceProxy::VirtualOpenflowSwitchFactory - include OmfRc::ResourceProxyDSL - - # The default arguments of the communication between this resource and the ovsdb-server - OVS_CONNECTION_DEFAULTS = { - ovsdb_server_host: "localhost", - ovsdb_server_port: "6635", - ovsdb_server_socket: "/usr/local/var/run/openvswitch/db.sock", - ovsdb_server_conn: "unix", # default "unix" between "tcp" and "unix" - ovs_vswitchd_pid: "/usr/local/var/run/openvswitch/ovs-vswitchd.pid", - ovs_vswitchd_socket: "/usr/local/var/run/openvswitch/ovs-vswitchd.%s.ctl", - ovs_vswitchd_conn: "unix" #default "unix" - } - - - register_proxy :virtual_openflow_switch_factory - - utility :virtual_openflow_switch_tools - - - # Checks if the created child is an :virtual_openflow_switch resource and passes the connection arguments - hook :before_create do |resource, type, opts = nil| - if type.to_sym != :virtual_openflow_switch - raise "This resource doesn't create resources of type "+type - end - begin - arguments = { - "method" => "list_dbs", - "params" => [], - "id" => "list_dbs" - } - resource.ovs_connection("ovsdb-server", arguments) - rescue - raise "This resource is not connected with an ovsdb-server instance, so it cannot create virtual openflow switches" - end - opts.property ||= Hashie::Mash.new - opts.property.provider = ">> #{resource.uid}" - opts.property.ovs_connection_args = resource.property.ovs_connection_args - end - - # A new resource uses the default connection arguments (ip adress, port) to connect with a ovsdb-server instance - hook :before_ready do |resource| - resource.property.ovs_connection_args = OVS_CONNECTION_DEFAULTS - end - - - # Configures the ovsdb-server connection arguments (ip adress, port) - configure :ovs_connection do |resource, ovs_connection_args| - raise "Connection with a new ovsdb-server instance is not allowed if there exist created switches" if !resource.children.empty? - resource.property.ovs_connection_args.update(ovs_connection_args) - end - - - # Returns the ovsdb-server connection arguments (ip adress, port) - request :ovs_connection do |resource| - resource.property.ovs_connection_args - end - - # Returns a list of virtual openflow switches, that correspond to the ovsdb-server bridges. - request :switches do |resource| - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "select", - "table" => "Bridge", - "where" => [], - "columns" => ["name"] - } - ], - "id" => "switches" - } - result = resource.ovs_connection("ovsdb-server", arguments)["result"] - result[0]["rows"].map {|hash_name| hash_name["name"]} - end -end diff --git a/lib/omf_rc/util/openflow_slice_tools.rb~ b/lib/omf_rc/util/openflow_slice_tools.rb~ deleted file mode 100644 index 0fcbd41..0000000 --- a/lib/omf_rc/util/openflow_slice_tools.rb~ +++ /dev/null @@ -1,102 +0,0 @@ -require 'xmlrpc/client' - -module OmfRc::Util::OpenflowSliceTools - include OmfRc::ResourceProxyDSL - - # The version of the flowvisor that this resource is able to control - FLOWVISOR_VERSION = "FV version=flowvisor-0.8.4" - - # Parts of the regular expression that describes a flow entry for flowvisor - FLOWVISOR_FLOWENTRY_REGEXP_DEVIDED = [ - /dpid=\[(?.+)\]/, - /ruleMatch=\[OFMatch\[(?.+)\]\]/, - /actionsList=\[Slice:(?.+)=(?.+)\]/, - /id=\[(?.+)\]/, - /priority=\[(?.+)\]/ - ] - - # The regular expression that describes a flow entry for flowvisor - FLOWVISOR_FLOWENTRY_REGEXP = /FlowEntry\[#{FLOWVISOR_FLOWENTRY_REGEXP_DEVIDED.join(',')},\]/ - - # The names of the flow (or flow entry) features - FLOW_FEATURES = %w{device match slice actions id priority} - - # The names of the flow (or flow entry) features that are specified by the "match" feature - FLOW_MATCH_FEATURES = %w{in_port eth_src eth_dst ip_src ip_dst} - - # The default features of a new flow (or flow entry) - FLOW_DEFAULTS = { - priority: "10", - actions: "4" - } - - - # Returns the flows (flow entries) that exist for this flowvisor - request :flows do |resource, filter = nil| - resource.flows(filter) - end - - - # Internal function that creates a connection with a flowvisor instance and checks it - work :flowvisor_connection do |resource| - xmlrpc_client = XMLRPC::Client.new_from_hash(resource.property.flowvisor_connection_args) - xmlrpc_client.instance_variable_get("@http").verify_mode = OpenSSL::SSL::VERIFY_NONE - ping_msg = "test" - pong_msg = "PONG(#{resource.property.flowvisor_connection_args[:user]}): #{FLOWVISOR_VERSION}::#{ping_msg}" - raise "Connection with #{FLOWVISOR_VERSION} was not successful" if xmlrpc_client.call("api.ping", ping_msg) != pong_msg - xmlrpc_client - end - - # Internal function that returns the flows (flow entries) that exist in the connected flowvisor instance - work :flows do |resource, filter = nil| - result = resource.flowvisor_connection.call("api.listFlowSpace") - result.map! do |line| - array_values = line.match(FLOWVISOR_FLOWENTRY_REGEXP)[1..-1] - # Example of above array's content: %w{00:00:...:01 in_port=1 test 4 30 10} - array_features_values_zipped = FLOW_FEATURES.zip(array_values) - # Example of above array's content: %w{device 00:00:...:01 match in_port=1 slice test actions 4 id 30 priority 10} - hash = Hashie::Mash.new(Hash[array_features_values_zipped]) - # The following code adds extra features that are specified by the "match" feature - hash["match"].split(",").each do |couple| - array = couple.split("=") - hash[array[0]] = array[1] - end - hash - end - result.delete_if {|hash| hash["slice"] != resource.property.name} if resource.type.to_sym == :openflow_slice - FLOW_FEATURES.each do |feature| - result.delete_if {|hash| hash[feature] != filter[feature].to_s} if filter[feature] - end if filter - result - end - - work :transformed_parameters do |resource, parameters| - match = [] - FLOW_MATCH_FEATURES.each do |feature| - match << "#{feature}=#{parameters[feature]}" if parameters[feature] - end - match = match.join(",") - - result = [] - case parameters.operation - when "add" - h = Hashie::Mash.new - h.operation = parameters.operation.upcase - h.priority = parameters.priority ? parameters.priority.to_s : FLOW_DEFAULTS[:priority] - h.dpid = parameters.device.to_s - h.actions = "Slice:#{resource.property.name}=#{(parameters.actions ? parameters.actions : FLOW_DEFAULTS[:actions])}" - h.match = "OFMatch[#{match}]" - result << h - when "remove" - resource.flows(parameters).each do |f| - if f.match == match - h = Hashie::Mash.new - h.operation = parameters.operation.upcase - h.id = f.id - result << h - end - end - end - result - end -end diff --git a/lib/omf_rc/util/virtual_openflow_switch_tools.rb~ b/lib/omf_rc/util/virtual_openflow_switch_tools.rb~ deleted file mode 100644 index f5826c6..0000000 --- a/lib/omf_rc/util/virtual_openflow_switch_tools.rb~ +++ /dev/null @@ -1,60 +0,0 @@ -module OmfRc::Util::VirtualOpenflowSwitchTools - include OmfRc::ResourceProxyDSL - - work :ovs_connection do |resource, target, arguments| - stream = nil - if target == "ovsdb-server" - if resource.property.ovs_connection_args.ovsdb_server_conn == "tcp" - stream = TCPSocket.new(resource.property.ovs_connection_args.ovsdb_server_host, - resource.property.ovs_connection_args.ovsdb_server_port) - elsif resource.property.ovs_connection_args.ovsdb_server_conn == "unix" - stream = UNIXSocket.new(resource.property.ovs_connection_args.ovsdb_server_socket) - end - elsif target == "ovs-vswitchd" - if resource.property.ovs_connection_args.ovs_vswitchd_conn == "unix" - file = File.new(resource.property.ovs_connection_args.ovs_vswitchd_pid, "r") - pid = file.gets.chomp - file.close - socket = resource.property.ovs_connection_args.ovs_vswitchd_socket % [pid] - stream = UNIXSocket.new(socket) - end - end - stream.puts(arguments.to_json) - string = stream.gets('{') - counter = 1 # number of read '[' - while counter > 0 - char = stream.getc - if char == '{' - counter += 1 - elsif char == '}' - counter -= 1 - end - string += char - end - stream.close - JSON.parse(string) - end - - work :ports do |resource| - arguments = { - "method" => "transact", - "params" => [ "Open_vSwitch", - { "op" => "select", - "table" => "Bridge", - "where" => [["name", "==", resource.property.name]], - "columns" => ["ports"] - }, - { "op" => "select", - "table" => "Port", - "where" => [], - "columns" => ["name", "_uuid"] - } - ], - "id" => "ports" - } - 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]} - end -end