Skip to content

Commit

Permalink
mos
Browse files Browse the repository at this point in the history
  • Loading branch information
altanai committed Apr 12, 2020
1 parent b709b1e commit 5ef433d
Show file tree
Hide file tree
Showing 37 changed files with 3,142 additions and 215 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions .idea/dictionaries/altanaibisht.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/kamilioexamples.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

653 changes: 653 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Loadbalancer_SIP_proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Dispatcher module can be used as stateless load balancer
Can choose one of many load balancing and traffic dispatching algorithms
requires the TM module if auto-discovery of active/inactive gateways is enabled

load dispatcher module
Load dispatcher module
```
#!define WITH_LOADBALANCE
...
Expand All @@ -23,7 +23,7 @@ modparam("dispatcher", "flags", 2)
```

store all possible destinations in the AVP variable and if the selected destination fails, next one can be selected from the list.
* AVP_DST - varaible holds list with addresses and associated properties, in the seleceted order by dispatcher algorithm
* AVP_DST - variable holds list with addresses and associated properties, in the seleceted order by dispatcher algorithm
* AVP_GRP - storing the group id of the destination set.
* AVP_CNT - storing the number of destination addresses kept in dst_avp AVPs.
* AVP_SOCK - hold the list with the sockets associated to the addresses stored in dst_avp avp.
Expand Down
2 changes: 1 addition & 1 deletion Loadbalancer_SIP_proxy/kamailio.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
...

#!KAMAILIO
#
# sample config file for dispatcher module
Expand Down
9 changes: 8 additions & 1 deletion Lua_Nat_handle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ pkill kamailio
```

To read more about Lua scripts for call routing on kamailip sip server
https://telecom.altanai.com/2018/05/08/lua-scripts-for-kamailio-routing/
[Lua script for kamailio record Routing](https://telecom.altanai.com/2018/05/08/lua-scripts-for-kamailio-routing/)

Adding route params for nating
```
if KSR.rr.check_route_param("nat=yes") > 0 then
KSR.setbflag(FLB_NATB);
end
```

## KSR function used :

Expand Down
43 changes: 43 additions & 0 deletions Lua_load_balancer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Kamailio as Load balancer

Uses dipatch module with dbtext to stateless proxy sip traffic to sip servers
Use dbtext to stpres destinations

Read More on employing kamailio as SIP call Load balancer here :
https://telecom.altanai.com/2014/11/12/telephony-solutions-with-kamailio/

> Among other features it offers load balancing with many distribution algorithms and failover support ,
>flexible least cost routing , routing failover and replication for High Availability (HA).
## security against DOS ( denial of service ) attacks

sample pike module in action
```
INFO: <script>: REGISTER from sip:[email protected] (IP:10.20.20.20:44133)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
WARNING: pike [pike_funcs.c:151]: pike_check_req(): PIKE - BLOCKing ip 10.10.10.10, node=0x7f7e073f7dd0
ALERT: pike blocking REGISTER from sip:[email protected] (IP:10.10.10.10:5060)
REGISTER from sip:[email protected] (IP:10.20.20.20:44133)
REGISTER from sip:[email protected] (IP:10.20.20.20:44133)
```
unlcoking
```
pike [pike_funcs.c:278]: refresh_node(): PIKE - UNBLOCKing node 0x7f7e073f7dd0
REGISTER from sip:[email protected] (IP:10.20.20.20:44133)
```

## checking traffic using ngrep
```
> ngrep -W byline -d any port 5060 -q
```

## Dispatcher


Dispatcher module - https://www.kamailio.org/docs/modules/5.1.x/modules/dispatcher.html#dispatcher.f.ds_select_domain
134 changes: 134 additions & 0 deletions Lua_load_balancer/kamailio.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!KAMAILIO


####### Defined Values #########

#!substdef "!MY_IP_ADDR!127.0.0.1!g"
#!substdef "!MY_EXTERNAL_IP!172.16.19.237!g"
#!substdef "!MY_UDP_PORT!5060!g"
#!substdef "!MY_TCP_PORT!8080!g"
#!substdef "!MY_UDP_ADDR!udp:MY_IP_ADDR:MY_UDP_PORT!g"
#!substdef "!MY_TCP_ADDR!tcp:MY_IP_ADDR:MY_TCP_PORT!g"


# Dispatcher File
#!define DISPATCHER_FILE "/Users/altanaibisht/kamilioexamples/Lua_load_balancer/dispatcher.list"

# Routing File
#!define ROUTE_LUA "/Users/altanaibisht/kamilioexamples/Lua_load_balancer/loadbalancer.lua"

#!define WITH_DBTEXT

####### Global Parameters #########

## LOG Levels: 3=DBG, 2=INFO, 1=NOTICE, 0=WARN, -1=ERR
#!ifdef WITH_DEBUG
debug = 4
log_stderror = yes
#!else
debug = 2
log_stderror = no
#!endif
memdbg = 5
memlog = 5

# log setting
log_facility = LOG_LOCAL0

#!ifdef WITH_DBTEXT
# - database URL - used to connect to database server by dispatcher
#!define DBURL "text:///Users/altanaibisht/kamilioexamples/dbtext"
#!endif


children = 4
async_workers=8

#listen = MY_UDP_ADDR advertise MY_EXTERNAL_IP:MY_UDP_PORT
#listening for the xmlrpc
listen = MY_UDP_ADDR
listen = MY_TCP_ADDR

server_header="Server: SampleServer"
sip_warning=0

####### Modules Section ########
#!ifdef WITH_SRCPATH
mpath = "modules/"
#!else
mpath = "/usr/local/lib64/kamailio/modules/"
#!endif
# ------------------ module loading ----------------------------------
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "maxfwd.so"
loadmodule "nathelper.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "path.so"
loadmodule "xhttp.so"
loadmodule "jsonrpcs.so"
loadmodule "app_lua.so"
loadmodule "dispatcher.so"
loadmodule "json.so"
loadmodule "cfg_rpc.so"
loadmodule "xmlrpc.so"
# loadmodule "ctl.so"
loadmodule "dialog.so"
loadmodule "db_text.so"
loadmodule "textopsx.so"
loadmodule "sdpops.so"
# ----------------- setting module-specific parameters ---------------

# ----- rr params -----
# set next param to 1 to add value to ;lr param (helps with some UAs)
modparam("rr", "enable_full_lr", 0)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 1)

# ----- dispatcher params -----
modparam("dispatcher", "list_file", DISPATCHER_FILE)
modparam("dispatcher", "ds_probing_mode", 1)
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "ds_ping_interval", 10)

# ----- nathelper params ----
modparam("nathelper", "received_avp", "$avp(s:rcv)")

# ----- ctl ------
# modparam("ctl", "binrpc", "tcp:MY_IP_ADDR:2046")

# ----- app_lua params ----
modparam("app_lua", "reload", 1)
modparam("app_lua", "load", ROUTE_LUA)

# ---- dialog params ----
modparam("dialog", "enable_stats", 1)
modparam("dialog", "dlg_flag", 4)
modparam("dialog", "dlg_match_mode", 1)
modparam("dialog", "event_callback", "ksr_dialog_event")

# ----- tm params -----
# auto-discard branches from previous serial forking leg
modparam("tm", "failure_reply_mode", 3)
modparam("tm", "fr_timer", 10000)
modparam("tm", "fr_inv_timer", 120000)
modparam("tm", "restart_fr_on_each_reply", 1)
modparam("tm", "pass_provisional_replies", 1)
modparam("tm", "contacts_avp", "tm_contacts");
modparam("tm", "contact_flows_avp", "tm_contact_flows");

# ----- db_text module params ----
modparam("db_text", "db_mode", 1)

# ----- xhttp module params -----
modparam("xhttp", "url_match", "^/XMLRPC")
modparam("xhttp", "event_callback", "ksr_xhttp_event")


cfgengine "lua"
Loading

0 comments on commit 5ef433d

Please sign in to comment.