omf_tools 6.0.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +7 -0
- data/bin/test_xmpp_peering +326 -0
- data/lib/omf_tools.rb +5 -0
- data/lib/omf_tools/version.rb +3 -0
- data/omf_tools.gemspec +24 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,326 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2012 National ICT Australia (NICTA), Australia
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# = test_xmpp_peering.rb
|
25
|
+
#
|
26
|
+
# == Description
|
27
|
+
#
|
28
|
+
# This is a small test application which verifies that 2 XMPP PubSub servers
|
29
|
+
# are correctly talking to each other via the server-2-server protocol for
|
30
|
+
# the purpose of OMF federation.
|
31
|
+
#
|
32
|
+
#
|
33
|
+
|
34
|
+
require "rubygems"
|
35
|
+
require "optparse"
|
36
|
+
require "xmpp4r"
|
37
|
+
require "xmpp4r/pubsub"
|
38
|
+
require "xmpp4r/pubsub/helper/servicehelper.rb"
|
39
|
+
require "xmpp4r/pubsub/helper/nodebrowser.rb"
|
40
|
+
require "xmpp4r/pubsub/helper/nodehelper.rb"
|
41
|
+
include Jabber
|
42
|
+
|
43
|
+
#Jabber::debug=true
|
44
|
+
|
45
|
+
class MyServiceHelper < Jabber::PubSub::ServiceHelper
|
46
|
+
#
|
47
|
+
# Perform a 'unsubscribe_from' from scratch
|
48
|
+
#
|
49
|
+
def unsubscribe_from_fixed (node,subid)
|
50
|
+
iq = basic_pubsub_query(:set)
|
51
|
+
sub = REXML::Element.new('unsubscribe')
|
52
|
+
sub.attributes['node'] = node
|
53
|
+
sub.attributes['jid'] = @stream.jid.strip.to_s
|
54
|
+
sub.attributes['subid']=subid
|
55
|
+
iq.pubsub.add(sub)
|
56
|
+
ret = false
|
57
|
+
@stream.send_with_id(iq) do |reply|
|
58
|
+
ret = reply.kind_of?(Jabber::Iq) and reply.type == :result
|
59
|
+
end # @stream.send_with_id(iq)
|
60
|
+
ret
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
###############################################################################
|
65
|
+
#
|
66
|
+
# The class that handles our interactions with the server
|
67
|
+
#
|
68
|
+
###############################################################################
|
69
|
+
|
70
|
+
class PubSubTester
|
71
|
+
|
72
|
+
attr_reader :userJID, :userPWD, :serverJID, :serviceJID, :queue
|
73
|
+
|
74
|
+
def initialize(userJID, userPWD, serverJID, serviceJID, listen = true)
|
75
|
+
@format = REXML::Formatters::Pretty.new
|
76
|
+
@userJID = "#{userJID}@#{serverJID}"
|
77
|
+
@userPWD = userPWD
|
78
|
+
@serverJID = serverJID
|
79
|
+
@serviceJID = "pubsub.#{serviceJID}"
|
80
|
+
# Processing Q for incoming events
|
81
|
+
@queue = Queue.new
|
82
|
+
Thread.new do
|
83
|
+
while event = @queue.pop
|
84
|
+
process_event(event)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Connect as a Client (register and new one if required)
|
89
|
+
@clientHelper = Jabber::Client.new(@userJID)
|
90
|
+
@clientHelper.connect(@serverJID)
|
91
|
+
begin
|
92
|
+
@clientHelper.register(@userPWD)
|
93
|
+
rescue Exception => ex
|
94
|
+
if ("#{ex}" != "conflict: ")
|
95
|
+
raise "Failed to register user #{@userJID} - Error: '#{ex}'"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
@clientHelper.auth(@userPWD)
|
99
|
+
@clientHelper.send(Jabber::Presence.new)
|
100
|
+
|
101
|
+
# Create Helpers for Service and Browser
|
102
|
+
@service = MyServiceHelper.new(@clientHelper, @serviceJID)
|
103
|
+
@browser = Jabber::PubSub::NodeBrowser.new(@clientHelper)
|
104
|
+
|
105
|
+
# Start our Event Callback, which will process Events from
|
106
|
+
# the topics we will subscribe to
|
107
|
+
@service.add_event_callback { |event| @queue << event if listen }
|
108
|
+
end
|
109
|
+
|
110
|
+
def process_event (event)
|
111
|
+
begin
|
112
|
+
incomingPubSubNode = event.first_element("items").attributes['node']
|
113
|
+
eventItem = event.first_element("items").first_element("item")
|
114
|
+
eventBody = eventItem.first_element("message").first_element("body")
|
115
|
+
puts "----"
|
116
|
+
puts "LISTENER - Received a message on Topic: '#{incomingPubSubNode}'"
|
117
|
+
puts "LISTENER - Message is: '#{eventBody.to_s}'"
|
118
|
+
#puts "FULL MSG : '#{event.to_s}'"
|
119
|
+
puts "----"
|
120
|
+
rescue Exception => ex
|
121
|
+
puts "----\nRAW XMPP EVENT\n#{event.to_s}\n----"
|
122
|
+
return
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def send (node, message)
|
127
|
+
item = Jabber::PubSub::Item.new
|
128
|
+
payload = message
|
129
|
+
msg = Jabber::Message.new(nil, payload)
|
130
|
+
item.add(msg)
|
131
|
+
begin
|
132
|
+
@service.publish_item_to("#{node}", item)
|
133
|
+
rescue Exception => ex
|
134
|
+
puts "Failed sending to '#{node}'"
|
135
|
+
puts "Error: '#{ex}'"
|
136
|
+
puts "Msg: '#{payload}'"
|
137
|
+
return
|
138
|
+
end
|
139
|
+
puts "Sent msg to '#{node}' - '#{payload}'"
|
140
|
+
end
|
141
|
+
|
142
|
+
def create(node)
|
143
|
+
@service.create_node(node, Jabber::PubSub::NodeConfig.new(nil,{
|
144
|
+
"pubsub#title" => "#{node}",
|
145
|
+
#"pubsub#node_type" => "flat",
|
146
|
+
#"pubsub#node_type" => "leaf",
|
147
|
+
"pubsub#persist_items" => "1",
|
148
|
+
"pubsub#max_items" => "1",
|
149
|
+
"pubsub#notify_retract" => "0",
|
150
|
+
"pubsub#publish_model" => "open"}))
|
151
|
+
end
|
152
|
+
|
153
|
+
def close ; @clientHelper.close ; end
|
154
|
+
def delete(node) ; @service.delete_node(node) ; end
|
155
|
+
def getconfig(node) ; @service.get_config_from(node) ; end
|
156
|
+
def setconfig(node, config) ; @service.set_config_for(node, config) ; end
|
157
|
+
def join(node) ; @service.subscribe_to(node) ; end
|
158
|
+
def leave(node, id) ; @service.unsubscribe_from_fixed(node, id) ; end
|
159
|
+
def listsub() ; return @service.get_subscriptions_from_all_nodes ; end
|
160
|
+
def listall(server = @serviceJID) ; return @browser.nodes(@serviceJID) ; end
|
161
|
+
|
162
|
+
def pp(inxml)
|
163
|
+
out = String.new
|
164
|
+
@format.write(inxml, out)
|
165
|
+
puts out
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
###############################################################################
|
171
|
+
#
|
172
|
+
# Below are the test definitions
|
173
|
+
#
|
174
|
+
###############################################################################
|
175
|
+
|
176
|
+
def test(tester, name, description, test_block)
|
177
|
+
puts "------------------------"
|
178
|
+
puts "#{name} - #{description}"
|
179
|
+
puts "Remote Server: #{tester[:client].serviceJID}"
|
180
|
+
res = :FAILED
|
181
|
+
begin
|
182
|
+
res = test_block.call(tester)
|
183
|
+
rescue Exception => ex
|
184
|
+
puts "#{name} - ERROR: (#{ex.class}) #{ex}"
|
185
|
+
puts "#{name} - TRACE: \n#{ex.backtrace.join("\n\t")}"
|
186
|
+
end
|
187
|
+
puts "------------------------"
|
188
|
+
puts "#{name} - RESULT: #{res}"
|
189
|
+
puts "------------------------\n\n"
|
190
|
+
if res == :FAILED
|
191
|
+
puts "Test '#{name}' has failed, please find and fix the cause, then "+
|
192
|
+
"re-run this program.\n\n"
|
193
|
+
exit(-1)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test1(tester)
|
198
|
+
test_block = lambda do |t|
|
199
|
+
list = t[:client].listall()
|
200
|
+
list[0,3].each { |node| puts " Topic: '#{node}'" }
|
201
|
+
puts " etc..."
|
202
|
+
return :PASSED
|
203
|
+
end
|
204
|
+
test(tester, 'test1', 'List topics of Remote Server', test_block)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test2(tester)
|
208
|
+
test_block = lambda do |t|
|
209
|
+
topic = t[:client].create(t[:topic])
|
210
|
+
list = t[:client].listall()
|
211
|
+
puts " Created Topic: '#{t[:topic]}'"
|
212
|
+
return !list.index(t[:topic]).nil? ? :PASSED : :FAILED
|
213
|
+
end
|
214
|
+
test(tester, 'test2', 'Create a Topic on Remote Server', test_block)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test3(tester)
|
218
|
+
test_block = lambda do |t|
|
219
|
+
puts " Subscribing to Topic: '#{t[:topic]}'"
|
220
|
+
topic = t[:client].join(t[:topic])
|
221
|
+
puts " Getting list of subscribed Topics: '#{t[:topic]}'"
|
222
|
+
list = t[:client].listsub()
|
223
|
+
list.each { |sub| puts " - '#{sub.node}' (subID: '#{sub.subid}')" }
|
224
|
+
tlist = list.collect { |sub| sub.node }
|
225
|
+
return !tlist.index(t[:topic]).nil? ? :PASSED : :FAILED
|
226
|
+
end
|
227
|
+
test(tester, 'test3', 'Subscribing to a Topic on Remote Server', test_block)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test4(tester)
|
231
|
+
test_block = lambda do |t|
|
232
|
+
puts " Publishing to Topic: '#{t[:topic]}'"
|
233
|
+
puts " Text to publish: '#{t[:text]}'"
|
234
|
+
t[:client].send(t[:topic], t[:text])
|
235
|
+
sleep 2 # wait 2s to let the published msg come back to us and be processed
|
236
|
+
return :PASSED
|
237
|
+
end
|
238
|
+
test(tester, 'test4', 'Publishing to a Topic on Remote Server', test_block)
|
239
|
+
end
|
240
|
+
|
241
|
+
def test5(tester)
|
242
|
+
test_block = lambda do |t|
|
243
|
+
puts " Subscribing to Topic: '#{t[:topic]}'"
|
244
|
+
list = t[:client].listsub()
|
245
|
+
puts " Looking for subscription... "
|
246
|
+
list.each do |sub|
|
247
|
+
if sub.node == t[:topic]
|
248
|
+
begin
|
249
|
+
puts " - unsubscribing: '#{sub.node}' (subid '#{sub.subid}')"
|
250
|
+
t[:client].leave(sub.node, sub.subid)
|
251
|
+
rescue Exception => ex
|
252
|
+
# it is ok to have that specific exception with OpenFire here.
|
253
|
+
raise ex unless "#{ex}" == "unexpected-request: "
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
return :PASSED
|
258
|
+
end
|
259
|
+
test(tester, 'test5', 'Unsubscribe to a Topic on Remote Server', test_block)
|
260
|
+
end
|
261
|
+
|
262
|
+
def test6(tester)
|
263
|
+
test_block = lambda do |t|
|
264
|
+
puts " Deleting the Topic: '#{t[:topic]}'"
|
265
|
+
t[:client].delete(t[:topic])
|
266
|
+
list = t[:client].listall()
|
267
|
+
return list.index(t[:topic]).nil? ? :PASSED : :FAILED
|
268
|
+
end
|
269
|
+
test(tester, 'test6', 'Deleting a Topic on Remote Server', test_block)
|
270
|
+
end
|
271
|
+
|
272
|
+
###############################################################################
|
273
|
+
#
|
274
|
+
# Finally the main loop...
|
275
|
+
#
|
276
|
+
###############################################################################
|
277
|
+
|
278
|
+
# Define Banner and Options
|
279
|
+
@username = @password = @server = @remote = @topic = nil
|
280
|
+
@opts = OptionParser.new
|
281
|
+
@opts.banner = "\nTest XMPP Peering\n\n"+
|
282
|
+
"Usage: #{$0} [OPTIONS]\n\n"
|
283
|
+
@opts.on("-u", "--username NAME",
|
284
|
+
"Username to login to home server") {|n| @username = n }
|
285
|
+
@opts.on("-p", "--password PASS",
|
286
|
+
"Password to login to home server") {|n| @password = n }
|
287
|
+
@opts.on("-s", "--server HOST",
|
288
|
+
"Hostname for home server") {|n| @server = n }
|
289
|
+
@opts.on("-r", "--remote HOST",
|
290
|
+
"Hostname for remote server (default= home server") { |n| @remote = n }
|
291
|
+
@opts.on("-t", "--topic TOPIC",
|
292
|
+
"Topic name to use for test (optional)") {|n| @topic = n }
|
293
|
+
|
294
|
+
def show_help() puts @opts ; puts "\n" ; exit; end
|
295
|
+
@opts.parse(ARGV)
|
296
|
+
show_help if !@username || !@password || !@server
|
297
|
+
|
298
|
+
begin
|
299
|
+
@remote = @server if @remote.nil?
|
300
|
+
puts "\nConnecting to home server '#{@server}' as user: '#{@username}' with "+
|
301
|
+
"pwd: '#{@password}'"
|
302
|
+
puts "Remote server set to: '#{@remote}'"
|
303
|
+
c = PubSubTester.new(@username, @password, @server, @remote, true) || nil
|
304
|
+
raise "Could not connect!!!" if c.nil?
|
305
|
+
|
306
|
+
test_time = Time.now
|
307
|
+
tester = {:client => c,
|
308
|
+
:topic => @topic.nil? ? "testing_#{test_time.to_i}" : @topic,
|
309
|
+
:text => "testing text at #{test_time.to_s}"}
|
310
|
+
|
311
|
+
puts "\nRunning Tests...\n"
|
312
|
+
test1(tester)
|
313
|
+
test2(tester)
|
314
|
+
test3(tester)
|
315
|
+
test4(tester)
|
316
|
+
test5(tester)
|
317
|
+
test6(tester)
|
318
|
+
|
319
|
+
rescue SystemExit => ex
|
320
|
+
rescue Exception => ex
|
321
|
+
puts "ERROR: #{ex}"
|
322
|
+
puts "TRACE: \n#{ex.backtrace.join("\n\t")}"
|
323
|
+
ensure
|
324
|
+
c.close if !c.nil?
|
325
|
+
end
|
326
|
+
|
data/lib/omf_tools.rb
ADDED
data/omf_tools.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omf_tools/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omf_tools"
|
7
|
+
s.version = OmfTools::VERSION
|
8
|
+
s.authors = ["NICTA"]
|
9
|
+
s.email = ["omf-user@lists.nicta.com.au"]
|
10
|
+
s.homepage = "https://www.mytestbed.net"
|
11
|
+
s.summary = %q{OMF utility tools}
|
12
|
+
s.description = %q{A set of useful utility tools of OMF, a generic framework for controlling and managing networking testbeds.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omf_tools"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "minitest", "~> 2.11.3"
|
23
|
+
s.add_runtime_dependency "xmpp4r", "~> 0.5"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omf_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 6.0.0.pre.2
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- NICTA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.3
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.11.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: xmpp4r
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.5'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.5'
|
46
|
+
description: A set of useful utility tools of OMF, a generic framework for controlling
|
47
|
+
and managing networking testbeds.
|
48
|
+
email:
|
49
|
+
- omf-user@lists.nicta.com.au
|
50
|
+
executables:
|
51
|
+
- test_xmpp_peering
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- Rakefile
|
58
|
+
- bin/test_xmpp_peering
|
59
|
+
- lib/omf_tools.rb
|
60
|
+
- lib/omf_tools/version.rb
|
61
|
+
- omf_tools.gemspec
|
62
|
+
homepage: https://www.mytestbed.net
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>'
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.1
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project: omf_tools
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: OMF utility tools
|
86
|
+
test_files: []
|
87
|
+
has_rdoc:
|