Skip to content

Commit

Permalink
Update according to the OMF6 updates, before the first non --pre release
Browse files Browse the repository at this point in the history
  • Loading branch information
kohoumas committed Mar 9, 2013
1 parent d60cf4a commit 681a70c
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 309 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Or install it yourself as:

In a Linux machine that runs FlowVisor or OpenvSwitch software, execute:

$ omf_rc_openflow_slice_factory
$ omf_rc_openflow_slice_factory -u xmpp://user:password@domain -i topic

Or execute:

$ omf_rc_virtual_openflow_slice_factory
$ omf_rc_virtual_openflow_slice_factory -u xmpp://user:password@domain -i topic

to control the FlowVisor or OpenvSwitch resource in a OMF6 Experiment Controller (EC).

Expand Down
84 changes: 49 additions & 35 deletions bin/omf_rc_openflow_slice_factory
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
#!/usr/bin/env ruby

require "optparse"
require 'optparse'
require 'erb'

require 'omf_rc'
require 'omf_rc/resource_factory'
require 'omf_rc_openflow'

$stdout.sync = true

options = {
uid: `hostname`.chomp
}

options = {}
executable_name = File.basename($PROGRAM_NAME)
oml_enabled = false
gem_version = Gem::Specification.find_by_name('omf_rc_openflow').version.to_s

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
opts.on("-c CONFIGFILE", "Configuration File") do |file|
options[:configfile] = file
end

opts.on("-p PASSWORD", "Password") do |password|
options[:password] = password
opts.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
options[:advanced_configfile] = file
end

opts.on("-s SERVER", "PubSub server") do |server|
options[:server] = server
opts.on("-u URI", "Communication URI (xmpp://user:password@domain)") do |uri|
options[:uri] = uri
end

opts.on("-t TOPIC", "PubSub topic to create, also becomes the uid of the resource, default to hostname") do |topic|
options[:uid] = topic
opts.on("-e ENVIRONMENT", "Environment (development, production ...)") do |environment|
options[:environment] = environment
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
opts.on("-i UID", "UID of the resource, also becomes the pubsub topic of the resource, default to hostname") do |uid|
options[:uid] = uid
end
end
rescue => e
Expand All @@ -56,28 +51,47 @@ rescue => e
end
end

if !options[:configfile].nil?
cfg_options = YAML.load(ERB.new(File.read(options[:configfile])).result)
options = cfg_options.merge(options)
end

options[:uid] ||=`hostname`.chomp

OmfCommon::Measure.enable if oml_enabled

unless options[:server] && options[:user] && options[:password]
options[:environment] ||= :development

if options[:uri]
common_options = { communication: { url: options[:uri] } }
else
common_options = {}
end

if !options[:advanced_configfile].nil?
a_cfg_options = (YAML.load_file(options[:advanced_configfile]))
common_options = a_cfg_options.merge(common_options)
end

unless common_options[:communication] && common_options[:communication][:url]
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
resource_options = {
uid: options[:uid]
}

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
#OmfRc::ResourceFactory.load_default_resource_proxies

EM.run do
openflow_slice_factory = OmfRc::ResourceFactory.new(:openflow_slice_factory, options)
openflow_slice_factory.connect
OmfCommon.init(options[:environment].to_sym, common_options) do |el|
info "Starting OMF Resource Controller for OpenFlow Slice factory (FlowVisor) version '#{gem_version}'"

trap(:INT) { openflow_slice_factory.disconnect }
trap(:TERM) { openflow_slice_factory.disconnect }
OmfCommon.comm.on_connected do |comm|
info "Connected as #{comm.jid}" if comm.jid
res = OmfRc::ResourceFactory.create(:openflow_slice_factory, resource_options)

comm.on_interrupted { res.disconnect }
end
end
info "Stopping OMF Resource Controller for OpenFlow slice factory version '#{gem_version}'"
84 changes: 49 additions & 35 deletions bin/omf_rc_virtual_openflow_switch_factory
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
#!/usr/bin/env ruby

require "optparse"
require 'optparse'
require 'erb'

require 'omf_rc'
require 'omf_rc/resource_factory'
require 'omf_rc_openflow'

$stdout.sync = true

options = {
uid: `hostname`.chomp
}

options = {}
executable_name = File.basename($PROGRAM_NAME)
oml_enabled = false
gem_version = Gem::Specification.find_by_name('omf_rc_openflow').version.to_s

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
opts.on("-c CONFIGFILE", "Configuration File") do |file|
options[:configfile] = file
end

opts.on("-p PASSWORD", "Password") do |password|
options[:password] = password
opts.on("-a ADVANCED_CONFIGFILE", "Advanced Configuration File") do |file|
options[:advanced_configfile] = file
end

opts.on("-s SERVER", "PubSub server") do |server|
options[:server] = server
opts.on("-u URI", "Communication URI (xmpp://user:password@domain)") do |uri|
options[:uri] = uri
end

opts.on("-t TOPIC", "PubSub topic to create, also becomes the uid of the resource, default to hostname") do |topic|
options[:uid] = topic
opts.on("-e ENVIRONMENT", "Environment (development, production ...)") do |environment|
options[:environment] = environment
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
opts.on("-i UID", "UID of the resource, also becomes the pubsub topic of the resource, default to hostname") do |uid|
options[:uid] = uid
end
end
rescue => e
Expand All @@ -56,28 +51,47 @@ rescue => e
end
end

if !options[:configfile].nil?
cfg_options = YAML.load(ERB.new(File.read(options[:configfile])).result)
options = cfg_options.merge(options)
end

options[:uid] ||=`hostname`.chomp

OmfCommon::Measure.enable if oml_enabled

unless options[:server] && options[:user] && options[:password]
options[:environment] ||= :development

if options[:uri]
common_options = { communication: { url: options[:uri] } }
else
common_options = {}
end

if !options[:advanced_configfile].nil?
a_cfg_options = (YAML.load_file(options[:advanced_configfile]))
common_options = a_cfg_options.merge(common_options)
end

unless common_options[:communication] && common_options[:communication][:url]
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
resource_options = {
uid: options[:uid]
}

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
#OmfRc::ResourceFactory.load_default_resource_proxies

EM.run do
virtual_openflow_switch_factory = OmfRc::ResourceFactory.new(:virtual_openflow_switch_factory, options)
virtual_openflow_switch_factory.connect
OmfCommon.init(options[:environment].to_sym, common_options) do |el|
info "Starting OMF Resource Controller for virtual OpenFlow Switch factory (OpenVSwitch) version '#{gem_version}'"

trap(:INT) { virtual_openflow_switch_factory.disconnect }
trap(:TERM) { virtual_openflow_switch_factory.disconnect }
OmfCommon.comm.on_connected do |comm|
info "Connected as #{comm.jid}" if comm.jid
res = OmfRc::ResourceFactory.create(:virtual_openflow_switch_factory, resource_options)

comm.on_interrupted { res.disconnect }
end
end
info "Stopping OMF Resource Controller for virtual OpenFlow Switch factory version '#{gem_version}'"
42 changes: 24 additions & 18 deletions example/openflow_slice_factory_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,38 @@
require 'omf_rc'
require 'omf_rc/resource_factory'
#require 'omf_rc_openflow'

$stdout.sync = true

Blather.logger = logger

op_mode = :development

opts = {
# XMPP server domain
server: 'srv.mytestbed.net',
user: 'flowvisor',
password: 'pw',
uid: 'flowvisor',
# Debug mode of not
debug: false
communication: { url: 'xmpp://flowvisor:[email protected]' },
eventloop: { type: :em },
logging: {
level: 'info'
# level: 'debug',
# appenders: {
# stdout: {
# date_pattern: '%H:%M:%S',
# pattern: '%d %-5l %c{2}: %m\n',
# color_scheme: 'default'
# }
# }
}
}

Logging.logger.root.level = :debug if opts[:debug]

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")

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
OmfCommon.init(op_mode, opts) do |el|
OmfCommon.comm.on_connected do |comm|
info ">>> Starting flowvisor"

flowvisor = OmfRc::ResourceFactory.new(:openflow_slice_factory, opts.merge(uid: 'flowvisor'))

# Disconnect garage from XMPP server, when these two signals received
trap(:INT) { flowvisor.disconnect }
trap(:TERM) { flowvisor.disconnect }
# Disconnect garage from XMPP server, when INT or TERM signals received
comm.on_interrupted { flowvisor.disconnect }
end
end
Loading

0 comments on commit 681a70c

Please sign in to comment.