Forward SIP request between two Kamailio servers - kamailio

I have a simulation setup of 4 VMs in Virtual Box - two UAs and two Kamailio servers. The first UA will register to KAM1, and the second UA will regsiter to KAM2. See the Figure below.
UA1<--->KAM1<---->KAM2<---->UA2
int1 int1 int3 int3
int2 int2
I would like KAM1 to forward all SIP requests destined to int3 via KAM2 and vice versa. I am aware of the routing logic in 'kamailio.cfg', but i find rather excessive. Pseudo code of what i'm trying to achieve:
if (is_method("INVITE")) {
if(dst_ip == int3)
set_next_kamailio_server(KAM2)
}
Or:
if (is_method("INVITE")) {
if(callee is unkown)
ask_kamailio_server(KAM2)
}
Thanks for your help

Module is named DMQ/USRLOC DMQ that can share information between nodes. maybe it can help you.
in addition you can send it with just edit Request Uri like below.
$ru="sip:"+$rU+"#"+KAM2ip
t_relay()

Related

Sim800L lag/delay before incoming calls are visible to arduino

I use SIM800L GSM module to detect incoming calls and generally it works fine. The only problem is that sometimes it takes up to 8 RINGS before the GSM module tells arduino that someone is calling (before RING appears on the serial connection). It looks like a GSM Network congestion but I do not have such issues with normal calls (I mean calls between people). It happens to often - so it cannot be network/Provider overload. Does anybody else had such a problem?
ISP/Provider: Plus GSM in Poland
I don't put any code, because the problem is in different layer I think
sorry that I didn't answer earlier. I've tested it and it turned out that in bare minimum code it worked OK! I mean, I can see 'RING' on the serial monitor immediately after dialing the number. So it's not a hardware issue!
//bare minimum code:
void loop() {
if(serialSIM800.available()){
Serial.write(serialSIM800.read());
}
if(Serial.available()){
serialSIM800.write(Serial.read());
}
}
In my real code I need to compare calling number with the trusted list. To do that I saved all trusted numbers in the contact list on the sim card (with the common prefix name 'mytrusted'). So, in the main loop there's if statement:
while(mySerial.available()){
incomingByte = mySerial.read();
inputString += incomingByte;
}
if (inputString.indexOf("mytrusted") > 0){
isTrusted = 1;
Serial.println("A TRUSTED NUMBER IS CALLING");
}
After adding this "if condition" Arduino sometimes recognize trusted number after 1'st call, and sometimes after 4'th or 5'th. I'm not suspecting the if statement itself , but the preceding while loop, where incoming bytes are combined into one string.
Any ideas, what can be improved in this simply code?
It seems, I found workaround for my problem. I just send a simple 'AT' command every 20 seconds to SIM800L (it replies with 'OK' ). I use timer to count this 20 seconds interval (instead of simply delay function)
TimerObject *timer2 = new TimerObject(20000); //AT command interval
....
timer2->setOnTimer(&SendATCMD);
....
void SendATCMD () {
mySerial.println("AT");
timer2->Stop();
timer2->Start();
}
With this simple modification Arduino always sees incoming call immediately (after 1 ring)

Optimizing Get Requests - Changing RoundTripper with Transport go

I reach a limit in the number of requests I can get using the default httpClient that my API wrapper provides.
//I was getting something like this at the beginning
Head www.example.com:80/: lookup example.com: no such host
To solve this I want to change the MaxIdleConnsPerHost setting for the httpClient.Transport of my client. It looks much more like this:
However, the Transport my client uses is a RoundTripper and subsequently, it doesn't have a MaxIdleConnsPerHost param.
&oauth2.Transport{Source:(*oauth2.reuseTokenSource)(0xc2082ac0c0),
Base:http.RoundTripper(nil),
mu:sync.Mutex{state:0, sema:0x0},
modReq:map[*http.Request]*http.Request(nil)
}
The one I'm providing is mostly a default one and it lacks the proper configuration I suppose or simple what I want to do is not feasible.
&http.Transport{idleMu:sync.Mutex{state:0, sema:0x0},
idleConn:map[http.connectMethodKey][]*http.persistConn(nil),
idleConnCh:map[http.connectMethodKey]chan *http.persistConn(nil),
reqMu:sync.Mutex{state:0, sema:0x0},
reqCanceler:map[*http.Request]func()(nil),
altMu:sync.RWMutex{w:sync.Mutex{state:0, sema:0x0},
writerSem:0x0,
readerSem:0x0,
readerCount:0,
readerWait:0},
altProto:map[string]http.RoundTripper(nil),
Proxy:(func(*http.Request) (*url.URL, error))(nil),
Dial:(func(string, string) (net.Conn, error))(nil),
TLSClientConfig:(*tls.Config)(nil),
TLSHandshakeTimeout:0,
DisableKeepAlives:false,
DisableCompression:false,
MaxIdleConnsPerHost:200,
ResponseHeaderTimeout:0}
Can someone guide me on the right direction?

Twain always returns TWRC_NOTDSEVENT

I use twain 2.3 (TWAINDSM.DLL) in my application with HP Scanjet 200 TWAIN Protocol 1.9.
My TWAIIN calls are:
OpenDSM: DG_CONTROL, DAT_PARENT, MSG_OPENDSM
OpenDS: DG_CONTROL, DAT_IDENTITY, MSG_OPENDS
EnableDS: DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS
ProcessDeviceEvent: DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT
and as a result of the last call I allways get TWRC_NOTDSEVENT instead of TWRC_DSEVENT.
Could please someone help with this?
Once you use DG_CONTROL / DAT_EVENT / MSG_PROCESSEVENT, all messages from the applications message loop must be sent to the data source for processing. Receiving TWRC_NOTDSEVENT means the forwarded message isn't for the source so the application should process it as normal.
Keep forwarding all messages to the source until you receive MSG_XFERREADY which means there is data to transfer. Once the transfer is finished and you have sent MSG_DISABLEDS that's when you can stop forwarding messages to the source.
Twain is a standard, and when many company implement that standard, not all of them do the same way. Along the way to support Twain, we will learn and adjust the code to support all the different implementations.
I experienced this situation before, and this is my workaround:
Instead of placing (rc == TWRC_DSEVENT) at the beginning of code (will skip the following MSG_XFERREADY processing afterward) you can move the comparison to the end after MSG_XFERREADY processing, so that MSG_XFERREADY is always checked and processed.
(rc == TWRC_DSEVENT) is only to determine if we should forward the window message or not.
I don't know your specific situation. I ran into a similar issue because I called OpenDSM with a HWND/wId which is from another process. You should call OpenDSM with the HWND of
the active window/dialog which is owned by current process.

how do I reassemble TCP packet in LUA dissector?

I have a dissector that runs above the TCP protocol and has data that flows on more than one TCP packet.
I want to assemble the data before I convert everything, so I understood that I need tcp_dissect_pdus() for it, but I can't find documentation or examples for it.
Can anyone direct me to it or help me understand how I use it?
There is no wslua API for tcp_dissect_pdus. But you can implement it yourself.
If you want to assemble pdu that span two or more packets it's rather simple:
function slicer.dissector(tvb, pinfo, tree)
...
local pdu_length = get_pdu_length(...)
if pdu_length > tvb:len() then
pinfo.desegment_len = pdu_length - tvb:len()
else
do_dissection(tvb, pifo, tree)
end
return
end
If you don't know exact length of the pdu you can do:
pinfo.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
You should read README.developer section 2.7.

Have ISC dhcpd cycle through a list of gateways when giving out leases

I'm looking for a way to get the ISC's dhcpd to work with several gateways/routers. The behaviour I am after is the following (imagine we have 3 gateways) :
Client A requests a lease, gets gateway #1
Client B requests a lease, gets gateway #2
Client C requests a lease, gets gateway #3
Client D requests a lease, gets gateway #1
And so on...
I am working through the source, but am having difficulty locating the part I am going to have to modify to get this working... (ie: I am clueless & totally lost in the source tree)
I know several routers can be specified by the option-routers, but this does not give the functionality I want.
Any help or pointers to documentation about the dhcpd source would be much appreciated :)
Cheers,
~Thomas
Have you considered doing this with conditional evaluation in the dhcpd.conf file? For example, this should assign the three gateways as per your question:
if suffix(binary-to-ascii(3, 32, "", leased-address), 1) = "0" {
option routers gateway1;
} elsif suffix(binary-to-ascii(3, 32, "", leased-address), 1) = "1" {
option routers gateway2;
} else {
option routers gateway3;
}
(Note: untested, I don't have a DHCP testbed network handy!)

Resources