Friday, November 22, 2024

youtube

   
Text Size

Experiment 3 - Wlanconfig Wrapper

Creating a Wrapper around the application binary wlanconfig

We use the Ruby language to create the wrapper application called wlanmonitor-simple.rb

#!/usr/bin/ruby1.8
#
require "/usr/bin/oml4r"

APPNAME = "wlanmonitor"
APPPATH = "/usr/local/bin/wlanconfig"
APPVERSION = "1.2"

class MPStat < OML4R::MPBase
name :wlanstat
param :src_addr
#param :dst_addr
param :aid, :type => :long
param :channel, :type => :long
param :rate
param :rssi, :type => :long
param :dbm, :type => :long
param :idle, :type => :long
param :txseq, :type => :long
param :txfrag, :type => :long
param :rxseq, :type => :long



# wlanconfig returns other metrics which we ignore here
end

class Wrapper

def process_output(output)
# wlanconfig returns a sequence of lines
# The 1st line is a list of labels for the fields of the remaining lines
# Each remaining line is for a detected stations, and follows the format:
# ADDR AID CHAN RATE RSSI DBM IDLE TXSEQ RXSEQ CAPS ACAPS ERP STATE MODE
lines = output.split("\n")
labels = lines.delete_at(0)
lines.each { |row|
column = row.split(" ")
# Inject the measurements into OML
MPStat.inject("#{column[0]}", column[1], column[2],
"#{column[3]}", column[4], column[5],
column[6], column[7], column[8], column[9])

}
end

def initialize(args)

# Initialise some variable specific to this wrapper

@interface = nil
@interval = 1

# Now call the Init of OML4R with the command line arguments (args)
# and a block defining the arguments specific to this wrapper
OML4R::init(args, :appID => APPNAME) { |argParser|
argParser.banner = "\nExecute a wrapper around #{APPNAME}\n" +
"Use -h or --help for a list of options\n\n"
argParser.on("-i", "--interface IFNAME",
"Name of Interface to monitor") { |name| @interface = name }
argParser.on("-s", "--sampling DURATION",
"Interval in second between collected samples") { |time|
@interval = time
}
argParser.on_tail("-v", "--version",
"Show the version\n") { |v|
puts "Version: #{APPVERSION}"; exit
}
}

# Finally do some checking specific to this wrapper
# e.g. here we do not proceed if the user did not give us a
# valid interface to monitor
unless @interface != nil
raise "You did not specify an interface to monitor! (-i option)"
end
end

def start()

while true
# Run the wlanconfig command with the following syntax
#   "wlanconfig list"
cmd = "#{APPPATH} #{@interface} list"
output = `#{cmd}`
# Process its output
process_output(output)
# Wait for a given duration and loop again
sleep @interval.to_i
end
end

end

begin
app = Wrapper.new(ARGV)
app.start()
rescue Exception => ex
puts "Received an Exception when executing the wrapper!"
puts "The Exception is: #{ex}\n"

Create an OMF Application Definition for this wrapper

In order to be able to use an application (such as the above wrapper) in your OMF experiment, you need to write an OMF Application Definition for it. the new file is called wlanmonitor_app.rb

defApplication('wlanmonitor_app', 'wlanmonitor') do |a|

a.path = "/usr/bin/wlanmonitor-simple.rb"
a.version(1, 2, 0)
a.shortDescription = "Wrapper around wlanconfig's list mode"
a.description = <
This is a wrapper around the wlanconfig command used in list mode.
This application is using OML4R part of OML v2.3 or v2.4
TEXT

# Define the properties that can be configured for this application
#
# syntax: defProperty(name, description, mnemonic = nil, options = nil)
#
a.defProperty('interface', 'Interface to listen on', 'i',
{:type => :string, :dynamic => false})
a.defProperty('sampling', 'Sampling interval in sec', 's',
{:type => :integer, :dynamic => false})

# List the Measurement Points and associated metrics that are available
# for this application
#
a.defMeasurement('wlanstat') do |m|
m.defMetric('src_addr',:string)
m.defMetric('dst_addr',:string)
m.defMetric('aid',:long)
m.defMetric('channel',:long)
m.defMetric('rate',:string)
m.defMetric('rssi',:long)
m.defMetric('dbm',:long)
m.defMetric('idle',:long)
m.defMetric('txseq',:long)

Experiment Description

We finally have to write the experiment description for the scenario described above, where the Wrapper application is running on a single resource or node.

defProperty('node', "omf.nitos.node001", "ID of a node")
defProperty('mode1', "adhoc", "wifi mode for 1st node")
defProperty('wifi', "g", "wifi type to use")
defProperty('channel', "3", "wifi channel to use")

defGroup('Observers', property.node) do |node|
node.addApplication("wlanmonitor_app") do |app|
app.setProperty('interface', 'ath0')
app.setProperty('sampling', 3)
app.measure('wlanstat')
end
node.net.w0.mode = property.mode1
node.net.w0.type = property.wifi
node.net.w0.channel = property.channel
node.net.w0.essid = "expmonitor"
node.net.w0.ip = "192.168.0.1"
end       

onEvent(:ALL_UP_AND_INSTALLED) do |event|
wait 1
allGroups.startApplications
wait 30
allGroups.stopApplications
Experiment.done
end

addTab(:defaults)
addTab(:graph2) do |tab|
opts = { :postfix => %{This graph shows the RSSI.}, :updateEvery => 3 }
tab.addGraph("RSSI", opts) do |g|
data = Hash.new
mp = ms('wlanstat')
mp.project(:oml_ts_server, :src_addr, :dst_addr, :rssi).each do |sample|
time, src, dst, rssi = sample.tuple
data[dst] = [] if data[dst] == nil
data[dst] << [time, rssi] if src != dst
end
data.each do |d,v|
g.addLine(v, :label => d)

Run the experiment

In our resource (i.e. node "omf.nicta.node29")

Your 3rd party application ("wlanconfig") is installed at the path: /usr/sbin/wlanconfig

Your Ruby Wrapper with OML support ("wlanmonitor-simple.rb") is installed at: /usr/bin/wlanmonitor-simple

The OML 2.4 library (or newer) is installed The OML4R library is either installed (by default with OML) or installed by you at: /usr/bin/oml4r.rb

We copy wlanmonitor-simple.rb and oml4r.rb on the /usr/bin directory of our node and change the privileges for the two files as following:

chmod +x /usr/bin/wlanmonitor-simple.rb 
chmod +x /usr/bin/oml4r.rb

On your machine or testbed console: Your OMF Application Definition ("wlanmonitor_app.rb") is in the same directory as your experiment ("experiment.rb")

We finally run our experiment using the following command:

 omf exec experiment.rb 

 

Who's Online

We have 92 guests and no members online

VIDEO DEMONSTRATIONS