Hi Kamailio team, I'm attempting to use Kamailio as a Diameter Routing Agent, but I can't seem to get the diameter_request() function to actually _send_ the diameter request, instead I get a warning about no JSON Response:
WARNING: ims_diameter_server [avp_helper.c:341]: addAVPsfromJSON(): No JSON Response
Even when relaying received data without modifying it.
I posted this issue on the mailing list but have had no responses. Since then I've run a bunch more tests on a few different versions of Kamailio with a few different Diameter peers with the same result.
### Description The IMS Diameter Server Module's[ diameter_request() function](https://www.kamailio.org/docs/modules/devel/modules/ims_diameter_server.html...) fails to send, reporting "No JSON Response" even when fed unmodified received data into it.
### Troubleshooting
Initially I was trying to use CDP & IMS Diameter Server Module to create & send Diameter messages, I thought my formatting in the message (the Diameter Message (as JSON)) was incorrect. as I was getting:
WARNING: ims_diameter_server [avp_helper.c:341]: addAVPsfromJSON(): No JSON Response
When trying to send the request.
To rule out my JSON formatting being the issue I configured two Diameter Peers in Kamailio:
From one Diameter peer, I sent a Diameter request to Kamailio.
Kamailio is configured to receive the Diameter request, and without modifying the message body ($diameter_request), put that message into the message of the the diameter_request() so as to rule out formatting errors in the message, just a relay of the message, but this also fails to send.
I also included a series of checks to confirm the peer to receive the relayed message was online and capable of handling the specified Diameter application, all of which passed.
I've defined the peers in the diametercfg.xml config file, and they're all showing as online when I do a "kamcmd cdp.list_peers": FQDN: ims-hss.localdomain Details: { State: I_Open Disabled: False Last used: 0 Applications: { appid:vendorid: 16777216:10415 appid:vendorid: 16777216:4491 appid:vendorid: 16777216:13019 appid:vendorid: 16777216:0 appid:vendorid: 16777217:10415 appid:vendorid: 16777221:10415 } }
Here's a simplified version of my event_route[diameter:request], showing I simply receive the diameter request and then try to send it straight back out using the diameter_request() function:
``` event_route[diameter:request]{ xlog("Got diameter message"); diameter_request("ims-hss.localdomain", $diameter_application, $diameter_command, $diameter_request); xlog("Forwarded Diameter Request"); } ```
When tailing syslog I see the "Got diameter message" entry but not the "Forwarded Diameter Request", which suggests it's not getting past the diameter_request(), instead I just see the:
WARNING: ims_diameter_server [avp_helper.c:341]: addAVPsfromJSON(): No JSON Response
Packet captures show Kamailio receives the request but never relays it.
The source of avp_helper.c shows the warning is called if the length of the JSON is <= 0, but as I'm feeding back out what I've received it shouldn't be 0, an no recent major changes to the source, so I'm stumped as to why it's catching this.
I've attached a full copy of the config files below.
#### Reproduction
I've tried this with a few different Diameter servers, but I can reproduce it with two FreeDIAMETER peers configured in Diameter CDP Config XML, I've also tried with one Kamailio CDP based peer and using xhttp to call the diameter_request() function with the same results.
#### Log Messages
Copy of relevant SysLog: https://pastebin.com/ZY8z2kd4
### Additional Information
Full Kamailio Config: https://pastebin.com/afgqUfWr Diameter CDP Config XML: https://pastebin.com/bVrBG8mG Relevant Syslog: https://pastebin.com/ZY8z2kd4 Kamcmd cdp.list_peers: https://pastebin.com/cKi4JAHC
Kamailio 5.1.2 on Ubuntu 18.04 installed from Repos.
Hi, I have followed your page and tried diameter server . But I am not getting logs related to diameter request and the diameter_request route is not getting called. I have attached my kamailio_icscf.cfg file. Kindly help. [kamailio_icscf.txt](https://github.com/kamailio/kamailio/files/5291276/kamailio_icscf.txt)
Hi @pavithra-droid - I must admit I never got to the bottom of this,
In terms of your config I was seeing the Diameter messaging hit Kamailio, and Kamailio could see it,
Could you please provide a PCAP to show the Diameter messaging hitting Kamailio? I'd be keen to replicate it,
Nick
Hi, How yu are saying, It is hitting kamailio as i am not seeing any logs in kamailio logs about xlogs which i have provided in diameter_request.
Hi,
I`am trying to use this module and got the same issue.
I made a quick look into code. The problem lied in ims_diameter_server.c in function diameter_request wich start at line 263 In this function in line 311 made call to function addAVPsfromJSON with empty parameter s_message To resolve this, we need fill s_message with data by calling get_str_fparam
I made a quick patch. [kamailio_ims_diameter_server.txt](https://github.com/kamailio/kamailio/files/5895410/kamailio_ims_diameter_ser...)
Hi @Stranger-inton , I took your patch and put it into this branch with some increased debugging / logging, [Kamailio - Diameter_Fix](https://github.com/nickvsnetworking/kamailio/tree/Diameter_Fix)
Unfortunately I when I tried the patch it seems the get_str_fparam call hasn't fixed it,
Turning up the logging I can see that when get_str_fparam is called and the message converted to a string, but addAVPsfromJSON() is able to parse all the AVPs but as it's the root of the JSON key it fails. [addAVPsfromJSON / ims_diameter_server](https://github.com/nickvsnetworking/kamailio/blob/60ec67edf24f465b6454054698...)
Being able to do Diameter routing in Kamailio would make my life easier, so I'm happy to pay you for your time if you think you can fix it, ping me an email at _nick@nickvsnetworking.com_ if you're interested,
Hi @nickvsnetworking
I did not understand the logick, why function addAVPsfromJSON must return 1 while processing root. I was just comment out "return 1" in the end of if statement. This allowed me to send async request to my HSS, I see response in tcpdump. However event_route[diameter:response] did not catch the response. At this point I`am stuck.
If you will be more lucky please contact me, may be I did something wrong. See my simple config into attached file. [kamailio_cfg.txt](https://github.com/kamailio/kamailio/files/5902879/kamailio_cfg.txt)
Hi @nickvsnetworking
I have good news for you. See attached patches, this allowed me send sync/async request to HSS and get the response. Also in the async mode event_route[diameter:response] was called and processed. [avp_helper_patch.txt](https://github.com/kamailio/kamailio/files/5919202/avp_helper_patch.txt) [ims_diameter_server_patch.txt](https://github.com/kamailio/kamailio/files/5919203/ims_diameter_server_patch...)
Thanks @Stranger-inton , I've got it relaying requests, but relaying responses I have not yet got working, Seems CDP creates a session to associate the responses, which I'd assume is used to route back the replies to the originator, but not 100% sure yet,
Thanks for your help so far, when I get the reply routing working I'll share the rest of my config here,
Cheers, Nick
I've tried to send Sh requests to HSS via xhttp -> diameter_request and found that after successful call I've always got empty $diameter_response.
After reading code of ims_diameter_server module I made following patch to finally get responses:
``` --- a/src/modules/ims_diameter_server/avp_helper.c +++ b/src/modules/ims_diameter_server/avp_helper.c int pv_get_response(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - if ((msg->id != current_msg_id_repl) || (responsejson.len < 0)) { + if (responsejson.len < 0) { return pv_get_strval(msg, param, res, &responsejson); ``` but then I thought that there should be workaround for unpatched version, so here's little hack to set empty $diameter_response before calling diameter_request function:
``` # # Processing HTTP request, it should be POST, # with URI: http://host:port/lcs/diameter-peer-name/diameter-app-id/function-code # event_route[xhttp:request] { xlog("Recieved HTTP request with request $hu\n");
# make diameter_request function happy -- initialize $diameter_response ;) # without setting $diameter_response first - there's no way to get back response_data $diameter_response = ''; xlog('trying to call: "diameter_request($(hu{s.select,2,/})", $(hu{s.select,3,/}), $(hu{s.select,4,/}), rb);\n'); diameter_request($(hu{s.select,2,/}), $(hu{s.select,3,/}), $(hu{s.select,4,/}), $rb);
xlog("Received Diameter response:\n"); # xlog("$diameter_response \n");
xhttp_reply("200", "OK", "application/json", "$diameter_response"); } ```
This issue is stale because it has been open 6 weeks with no activity. Remove stale label or comment or this will be closed in 2 weeks.
Closed #2035 as not planned.