<div dir="ltr"><div class="gmail_extra">Hello Chandru,</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thank you for the reply.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Here is what I have done. I'm using the example code given in OTP library available here at <a href="https://github.com/erlang/otp/tree/master/lib/diameter/examples/code">https://github.com/erlang/otp/tree/master/lib/diameter/examples/code</a>. The node.erl being common across client.erl, server.erl and relay.erl. However, I have a seperate version of node.erl for each of these systems. My entire code is here: <a href="https://github.com/arshadansari27/erlang-diameter-eval">https://github.com/arshadansari27/erlang-diameter-eval</a></div><div class="gmail_extra"><br></div><div class="gmail_extra">The code I'm using the run the client.erl and client_cb.erl is as follows:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">-module(runner4).</div><div class="gmail_extra"><br></div><div class="gmail_extra">-export([run/0, one_client/0, stop/0]).</div><div class="gmail_extra"><br></div><div class="gmail_extra">run() -></div><div class="gmail_extra"> diameter:start(),</div><div class="gmail_extra"> client:start(),</div><div class="gmail_extra"> client:connect(tcp).</div><div class="gmail_extra"><br></div><div class="gmail_extra">stop() -></div><div class="gmail_extra"> client:stop(),</div><div class="gmail_extra"> diameter:stop().</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">one_client() -></div><div class="gmail_extra"> <span style="line-height:1.5">client:call().</span></div><div class="gmail_extra"><span style="line-height:1.5"><br></span></div><div class="gmail_extra"><br></div><div class="gmail_extra">I'm calling runner4:run() first then runner4:one_client() and finally runner4:stop() so I can see tcp dumps and all after each and every step. Client connects to Relay and Relay forwards the requests to Server instances and gets a response from there and returns to the client. So that part is working. I was even able to do a little hack in pick_peer as shown below, so I can balance the incoming requests across multiple server instances. In my case, there are only two instances so I'm just selecting in a round robin manner and returning that peer.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">pick_peer(Peers, _, _SvcName, _State, relayed) -></div><div class="gmail_extra"> [{_, Peer_counter}] = ets:lookup(mytable_relay, peers),</div><div class="gmail_extra"> Peer_count = other_counter:inc(Peer_counter),</div><div class="gmail_extra"> Index = (Peer_count rem 2) + 1,</div><div class="gmail_extra"> % List = lists:map(fun(N) -> {Xs, _} = N, Xs end, Peers),</div><div class="gmail_extra"> Peer = lists:nth(Index, Peers),</div><div class="gmail_extra"> {ok, Peer}.</div><div><br></div></div></div><div class="gmail_extra">With this I'm also able to load balance across different server instances from relay at exact 50/50 ration. So I was able to solve much of the original problem I had. The problem that remains is that what I have done is firstly a hack and secondly inexplicable. And what follows is the current problem.</div><div class="gmail_extra"><div>When I start relay and then start both the server instances, relay calls peer up for both the servers and the pick_peer's first argument (local nodes) has both the servers as peers. Whereas when I start the server instances first and then relay, then only one time pick_peer is called and with only one of the server instance. Even the tcp dump on wireshark does not show the CER exchange between relay and servers, whereas the CER exchange is there from client to relay. This is what is confusing me. Why would the order of starting the server/relay allow peers to be added and/or not as well as why no CER exchange between relay and server instances? They do have TCP packets exchanged between them, but not the Diameter protocol CER exchange that is present for Client-relay communication. </div><div><br></div></div><div class="gmail_extra"> Given below is the code that starts the relay and connects it to both the server instances that are running on the same machine. </div><div class="gmail_extra">% runner.erl</div><div class="gmail_extra"><div class="gmail_extra">-module(runner).</div><div class="gmail_extra"><br></div><div class="gmail_extra">-export([run/0]).</div><div class="gmail_extra"><br></div><div class="gmail_extra">run() -></div><div class="gmail_extra"> diameter:start(),</div><div class="gmail_extra"> relay:start(),</div><div class="gmail_extra"> relay:connect(tcp, 1, true),</div><div class="gmail_extra"> relay:connect(tcp, 2, true),</div><div class="gmail_extra"> relay:listen(tcp).</div><div><br></div><div>% relay.erl</div><div><div>-module(relay).</div><div><br></div><div>-include_lib("diameter/include/diameter.hrl").</div><div>-include_lib("diameter/include/diameter_gen_base_rfc3588.hrl").</div><div>-include_lib("diameter/include/diameter_gen_relay.hrl").</div><div><br></div><div>-export([start/1,</div><div> start/2,</div><div> listen/2,</div><div> connect/2,</div><div> connect/3,</div><div> stop/1,</div><div> handle_info/2]).</div><div><br></div><div>-export([start/0,</div><div> listen/1,</div><div> connect/1,</div><div> stop/0]).</div><div><br></div><div>-define(DEF_SVC_NAME, ?MODULE).</div><div><br></div><div>%% The service configuration.</div><div>-define(SERVICE(Name), [{'Origin-Host', "<a href="http://pcrf.relay.com">pcrf.relay.com</a>"},</div><div> {'Origin-Realm', "<a href="http://relay.com">relay.com</a>"},</div><div> {'Vendor-Id', 193},</div><div> {'Product-Name', "RelayAgent"},</div><div> {'Auth-Application-Id', [?DIAMETER_APP_ID_RELAY]}, % 16#FFFFFFFF</div><div> {string_decode, false},</div><div> {use_shared_peers, true},</div><div> {application, [{alias, relay},</div><div> {dictionary, ?DIAMETER_DICT_RELAY}, % diameter_gen_relay</div><div> {module, relay_cb}]},</div><div> {share_peers, true}</div><div> ]).</div></div><div> %% SKIPPING the code that is same as the original one given on that link.. </div><div> </div><div><span class="inbox-inbox-Apple-converted-space"> </span> connect(T, SName, Multi) when Multi == true -></div><div><span class="inbox-inbox-inbox-inbox-Apple-converted-space" style="line-height:1.5"> </span><span style="line-height:1.5"> </span> node:connect(?DEF_SVC_NAME, T, SName).</div><div>% node.erl</div><div><br></div><div>%% SKIPPING the code that is same as the original one given on that link.. <br></div><div><div>-define(RELAY_PORT, 3868).</div><div><span style="line-height:1.5">-define(SERVER_PORT1, 3871).</span><br></div><div>-define(SERVER_PORT2, 3872).</div></div><div><br></div><div><div>%% connect/2</div><div><br></div><div>-spec connect(diameter:service_name(), client_opts())</div><div> -> {ok, diameter:transport_ref()}</div><div> | {error, term()}.</div><div><br></div><div>connect(Name, Opts)</div><div> when is_list(Opts) -></div><div> io:format("Connection Options ~p\n", [{connect, Opts}]),</div><div> diameter:add_transport(Name, {connect, Opts});</div><div><br></div><div>connect(Name, {T, Opts}) -></div><div> connect(Name, Opts ++ client_opts(T));</div><div><br></div><div>connect(Name, T) -></div><div> connect(Name, [{connect_timer, 5000} | client_opts(T)]).</div><div><br></div><div>connect(Name, T, SName) -></div><div> connect(Name, [{connect_timer, 5000} | client_opts({T, SName ,true})]).</div></div><div><br><div>client_opts({T, LA, RA, RP})</div><div> when T == all; %% backwards compatibility</div><div> T == any -></div><div> [[S, {C,Os}], T] = [client_opts({P, LA, RA, RP}) || P <- [sctp,tcp]],</div><div> [S, {C,Os,2000} | T];</div><div><br></div><div>client_opts({T, LA, RA, RP}) -></div><div> [{transport_module, tmod(T)},</div><div> {transport_config, [{raddr, addr(RA)},</div><div> {rport, RP},</div><div> {reuseaddr, true}</div><div> | ip(LA)]}];</div><div><br></div><div>client_opts({T, S_Port, Multi}) when Multi == true -></div><div> Port = case S_Port of </div><div> 1 -> ?SERVER_PORT1;</div><div> 2 -> ?SERVER_PORT2</div><div> end,</div><div> client_opts({T, loopback, remotelocal, Port});</div><div><br></div><div><br></div><div>client_opts({T, RA, RP}) -></div><div> client_opts({T, default, RA, RP});</div><div><br></div></div><div class="gmail_extra">addr(remotelocal) -></div><div class="gmail_extra"> {172,16,101,146};</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">ip(remotelocal) -></div><div class="gmail_extra"> {172,16,101,146};</div></div><div> </div><div><br></div><div>REALM INFO</div><div>------------------</div><div><br></div><div>client: </div><div> Origin-Host: <a href="http://first.client.com">first.client.com</a></div><div> <span style="line-height:1.5">Origin-Realm: <a href="http://client.com">client.com</a></span></div></div><div class="gmail_extra"><div><br class="inbox-inbox-Apple-interchange-newline">Relay: </div><div> Origin-Host: <a href="http://pcrf.realy.com">pcrf.realy.com</a></div><div> <span class="inbox-inbox-Apple-converted-space"> </span><span style="line-height:1.5">Origin-Realm: <a href="http://realy.com">realy.com</a></span></div><div><span style="line-height:1.5"><br></span></div><div><div><br class="inbox-inbox-inbox-inbox-Apple-interchange-newline">Server 1: </div><div> Origin-Host: <a href="http://3671.server.com">3671.server.com</a></div><div> <span class="inbox-inbox-inbox-inbox-Apple-converted-space"> </span><span style="line-height:1.5">Origin-Realm: <a href="http://server.com">server.com</a></span></div></div><div><div><br class="inbox-inbox-inbox-inbox-inbox-inbox-Apple-interchange-newline">Server 2: </div><div> Origin-Host: <a href="http://3672.server.com">3672.server.com</a></div><div> <span class="inbox-inbox-inbox-inbox-inbox-inbox-Apple-converted-space"> </span><span style="line-height:1.5">Origin-Realm: <a href="http://server.com">server.com</a></span></div></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">I hope that covers everything. Any help or direction is very much appreciated.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Regards,</span></div><div><span style="line-height:1.5">Arshad</span></div><div><span style="line-height:1.5"><br></span></div></div><div class="gmail_extra"><div class="gmail_quote">On 28-Jul-2016 2:56 AM, "Chandru" <<a href="mailto:chandrashekhar.mullaparthi@gmail.com" target="_blank">chandrashekhar.mullaparthi@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Arshad,<div><br></div><div>First, some general advice. I've used the Erlang diameter stack quite extensively to build telecom applications and it is pretty rock solid. I wouldn't hesitate to recommend using it. There are several mission critical services built using this stack running in production at EE (largest mobile operator) in the UK.</div><div><br></div><div>Re the specific problem you are facing, how are you generating the requests on the client side? Some packet captures or the client code would be useful to see.</div><div><br></div><div>cheers,</div><div>Chandru</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 27 July 2016 at 09:00, Arshad Ansari <span dir="ltr"><<a href="mailto:arshadansari27@gmail.com" target="_blank">arshadansari27@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello there,<div><br></div><div>Firstly, I've just picked up erlang this week and I'm suppose to evaluate Erlang-Diameter for my company (I'm even new to telecom domain and hence to diameter protocol). So, I'm a complete noob in this area. <span style="line-height:1.5">I'm using the example provided by OTP in lib/diameter/examples/code folder. I'm using the relay (listening on 3868) code given there to connect to the two instance of server that I have seperately started on 3871 and 3872. When I connect to these two servers, the connection is established with both but the Peer Up in relay_cb.erl is called only for the first server I tried to connect to. Hence forth, all the requests from clients are relayed to this single Peer. I'm trying to load balance the requests and therefore sharing client connections across multiple server. I would like and appreciate some help in that direction. I haven't changed much from the example directory. I'm just listing the params I'm using for connection as shown below:</span></div><div><br></div><div>Server uses the following config:</div><div>Server 1:</div><div><div>[{'Origin-Host', "<a href="http://3871.example.com" target="_blank">3871.example.com</a>"},</div><div> {'Origin-Realm', "<a href="http://example.com" target="_blank">example.com</a>"},</div><div> {'Vendor-Id', 193}, </div><div> {'Product-Name', "3871-Server-Erlang"},</div><div> {'Auth-Application-Id', [0]}, </div><div> {restrict_connections, false}, </div><div> {string_decode, false}, </div><div> {application, [{alias, common},</div><div> {dictionary, diameter_gen_base_rfc6733},</div><div> {module, server_cb}]}]). </div></div><div><div><br>Server 2:</div><div><div>[{'Origin-Host', "<a href="http://3872.example.com" target="_blank">3872.example.com</a>"},</div><div> {'Origin-Realm', "<a href="http://example.com" target="_blank">example.com</a>"},</div><div> {'Vendor-Id', 193}, </div><div> {'Product-Name', "3872-Server-Erlang"},</div><div> {'Auth-Application-Id', [0]}, </div><div> {restrict_connections, false}, </div><div> {string_decode, false}, </div><div> {application, [{alias, common},</div><div> {dictionary, diameter_gen_base_rfc6733},</div><div> {module, server_cb}]}]). </div></div></div><div><br></div><div>Relay:</div><div><div>[{'Origin-Host', "<a href="http://arshad.example.com" target="_blank">arshad.example.com</a>"},</div><div> {'Origin-Realm', "<a href="http://example.com" target="_blank">example.com</a>"},</div><div> {'Vendor-Id', 193},</div><div> {'Product-Name', "RelayAgent"},</div><div> {'Auth-Application-Id', [?DIAMETER_APP_ID_RELAY]}, </div><div> {string_decode, false},</div><div> {application, [{alias, relay},</div><div> {dictionary, ?DIAMETER_DICT_RELAY},</div><div> {module, relay_cb}]}]).</div></div><div><br></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div>
</div>