Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14 from xcurry/node_create_attrs

Allow attributes for nodes at creation via configuration file
  • Loading branch information...
commit da9fe86d81ef6632229f68fc40fbabf4a97c210a 2 parents 69c083b + 43a4295
@nniclausse nniclausse authored
Showing with 125 additions and 5 deletions.
  1. +90 −0 examples/jabber_node.xml.in
  2. +35 −5 src/tsung/ts_jabber_common.erl
View
90 examples/jabber_node.xml.in
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
+<tsung loglevel="debug" version="1.0">
+
+ <!-- Client side setup -->
+ <clients>
+ <client host="localhost" use_controller_vm="true"></client>
+ </clients>
+
+ <!-- Server side setup -->
+ <servers>
+ <server host="localhost" port="5222" type="tcp"></server>
+ </servers>
+
+ <!-- Define the traffic pattern of the users coming in -->
+ <load>
+ <user session="create_node" start_time="0" unit="minute"></user>
+ <arrivalphase phase="2" duration="1" unit="minute">
+ <users interarrival="2" unit="second"></users>
+ </arrivalphase>
+ </load>
+
+ <!-- JABBER parameters -->
+ <!-- to synchronise users, use a global acknoledgement -->
+ <options>
+ <option type="ts_jabber" name="pubsub_service" value="pubsub.localhost"/>
+ <option type="ts_jabber" name="global_number" value="100"></option>
+ <option type="ts_jabber" name="userid_max" value="1"></option>
+ <option type="ts_jabber" name="domain" value="localhost"></option>
+ <option type="ts_jabber" name="username" value="user"></option>
+ <option type="ts_jabber" name="passwd" value="pass"></option>
+ </options>
+
+ <sessions>
+ <!-- Create nodes -->
+ <session probability='0' name="create_node" type="ts_jabber">
+ <request> <jabber type="connect" ack="local"/> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl" ack="local"/> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="connect" ack="local"></jabber> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl_bind" ack="local" ></jabber></request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl_session" ack="local" ></jabber></request>
+ <thinktime value="5" random="true"/>
+
+ <!-- Create the node -->
+ <request subst="true">
+ <jabber type='pubsub:create' ack="local" node="/test" node_type="flat"
+ data="[{'pubsub#access_model','open'},
+ {'pubsub#deliver_payloads','1'},
+ {'pubsub#notify_retract', '0'},
+ {'pubsub#persist_items', '0'},
+ {'pubsub#max_items', '0'},
+ {'pubsub#send_last_published_item', 'never'},
+ {'pubsub#publish_model', 'open'}]."/>
+ </request>
+
+ <request> <jabber type="close" ack="local"></jabber> </request>
+ </session>
+
+ <session bidi="true" probability="100" name="sasl" type="ts_jabber">
+ <thinktime value="15"/>
+ <request> <jabber type="connect" ack="local"/> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl" ack="local"/> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="connect" ack="local"></jabber> </request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl_bind" ack="local" ></jabber></request>
+ <thinktime value="2" random="true"/>
+ <request> <jabber type="auth_sasl_session" ack="local" ></jabber></request>
+ <thinktime value="5" random="true"/>
+
+ <request>
+ <jabber type='pubsub:subscribe' ack="local" node="/test"/>
+ </request>
+
+ <for from="1" to="10" var="i">
+ <thinktime value="5" random="true"/>
+ <request>
+ <jabber type='pubsub:publish' size='9' ack="local" node="/test"/>
+ </request>
+ </for>
+
+ <request> <jabber type="close" ack="local"></jabber> </request>
+ </session>
+ </sessions>
+</tsung>
View
40 src/tsung/ts_jabber_common.erl
@@ -163,9 +163,9 @@ get_message(Jabber=#jabber{type = 'raw'}) ->
%% For node creation, data contains the pubsub nodename (relative to user
%% hierarchy or absolute, optional)
get_message(#jabber{type = 'pubsub:create', id=Id, username=User,
- node=Node, node_type=NodeType, pubsub_service = PubSubComponent, domain = Domain}) ->
+ node=Node, node_type=NodeType, data = Data, pubsub_service = PubSubComponent, domain = Domain}) ->
Username = username(User,Id),
- create_pubsub_node(Domain, PubSubComponent, Username, Node, NodeType);
+ create_pubsub_node(Domain, PubSubComponent, Username, Node, NodeType, Data);
%% For node subscription, data contain the pubsub nodename (relative to user
%% hierarchy or absolute)
get_message(#jabber{type = 'pubsub:subscribe', id=Id, username=User, user_server=UserServer,
@@ -557,13 +557,43 @@ raw(#jabber{data=Data}) when is_list(Data) ->
%%% Nodenames are relative to the User pubsub hierarchy (ejabberd); they are
%%% absolute with leading slash.
%%%----------------------------------------------------------------------
-create_pubsub_node(Domain, PubSubComponent,Username, Node, NodeType) ->
+create_pubsub_node(Domain, PubSubComponent,Username, Node, NodeType, Data) ->
list_to_binary(["<iq to='", PubSubComponent, "' type='set' id='",
ts_msg_server:get_id(list),"'>"
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
"<create", pubsub_node_attr(Node, Domain, Username),
- pubsub_node_type(NodeType),
- "/></pubsub></iq>"]).
+ pubsub_node_type(NodeType), "/>",
+ "<configure> <x xmlns='jabber:x:data' type='submit'>",
+ create_pubsub_node_options(Data),
+ "</x></configure></pubsub></iq>"]).
+
+create_pubsub_node_options(undefined) ->
+ "";
+create_pubsub_node_options(Data) when is_list(Data) ->
+ case erl_scan:string(Data) of
+ {ok, Ts, _} ->
+ field_elements(erl_parse:parse_term(Ts));
+
+ _ ->
+ ?LOG("Warn: Invalid erlang term scanned from data in pubsub create node", ?WARN),
+ ""
+ end.
+
+field_value(Value) when is_list(Value) ->
+ F = fun(Item, Acc) ->
+ Acc ++ "<value>" ++ atom_to_list(Item) ++ "</value>"
+ end,
+ lists:foldl(F, "", Value);
+field_value(Value) ->
+ "<value>" ++ atom_to_list(Value) ++ "</value>".
+field_elements({ok, Fields}) ->
+ F = fun({Field, Value}, Acc) ->
+ Acc ++ "<field var='" ++ atom_to_list(Field) ++ "'>" ++ field_value(Value) ++ "</field>"
+ end,
+ lists:foldl(F, "", Fields);
+field_elements(_) ->
+ ?LOG("Warn: Invalid erlang term parsed from data in pubsub create node", ?WARN),
+ "".
%% Generate pubsub node attribute
pubsub_node_attr(undefined, _Domain, _Username) -> " ";
Please sign in to comment.
Something went wrong with that request. Please try again.