Skip to content

Commit

Permalink
1. Updated to support reporting media addresses, proxy local addresses
Browse files Browse the repository at this point in the history
and provider post dial delay.
2. Updated to support CNAM.
  • Loading branch information
Di-Shi Sun committed Sep 1, 2015
1 parent b9fe3c2 commit 0fc5816
Show file tree
Hide file tree
Showing 17 changed files with 477 additions and 59 deletions.
2 changes: 1 addition & 1 deletion modules/osp/Makefile
Expand Up @@ -30,7 +30,7 @@ LIBS+=-L$(LOCALBASE)/lib -losptk -lpthread -lm

include ../../Makefile.modules

install_module_custom:
install_module_custom:
echo "OSP module overwrites the default configuration file"
sed \
-e "s#/usr/local/lib/opensips#$(modules-prefix)/$(lib-dir)#g" \
Expand Down
133 changes: 99 additions & 34 deletions modules/osp/README
Expand Up @@ -56,18 +56,22 @@ Di-Shi Sun
1.3.25. source_device_avp
1.3.26. source_networkid_avp
1.3.27. custom_info_avp
1.3.28. cnam_avp
1.3.29. source_media_avp, destination_media_avp

1.4. Exported Functions

1.4.1. checkospheader()
1.4.2. validateospheader()
1.4.3. requestosprouting()
1.4.4. checkosproute()
1.4.5. prepareosproute()
1.4.6. prepareredirectosproutes()
1.4.7. prepareallosproutes()
1.4.8. checkcallingtranslation()
1.4.9. reportospusage()
1.4.3. getlocaladdress()
1.4.4. requestosprouting()
1.4.5. checkosproute()
1.4.6. prepareosproute()
1.4.7. prepareredirectosproutes()
1.4.8. prepareallosproutes()
1.4.9. preparecnamresponse()
1.4.10. checkcallingtranslation()
1.4.11. reportospusage()

2. Developer Guide

Expand Down Expand Up @@ -102,15 +106,19 @@ Di-Shi Sun
1.25. Setting the source device IP AVP
1.26. Setting the source network ID AVP
1.27. Setting the custom info AVP
1.28. checkospheader usage
1.29. validateospheader usage
1.30. requestosprouting usage
1.31. checkosproute usage
1.32. prepareosproute usage
1.33. prepareredirectosproutes usage
1.34. prepareallosproutes usage
1.35. checkcallingtranslation usage
1.36. reportospusage usage
1.28. Setting the CNAM AVP
1.29. Setting the media address AVPs
1.30. checkospheader usage
1.31. validateospheader usage
1.32. getlocaladress usage
1.33. requestosprouting usage
1.34. checkosproute usage
1.35. prepareosproute usage
1.36. prepareredirectosproutes usage
1.37. prepareallosproutes usage
1.38. preparecnamresponse usage
1.39. checkcallingtranslation usage
1.40. reportospusage usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -170,8 +178,9 @@ modparam("osp","work_mode",0)
The service_type (integer) parameter instructs the OSP module
what services it should provide. If this value is set to 0, the
OSP module provides normal voice service. If this value is set
to 1, the OSP module provides ported number query service. The
default value is 0.
to 1, the OSP module provides ported number query service. If
this value is set to 2, the OSP module provides CNAM query
service. The default value is 0.

Example 1.2. Instructing the module to provide normal voice
service
Expand Down Expand Up @@ -524,6 +533,29 @@ modparam("osp","source_networkid_avp","$avp(snid)")
Example 1.27. Setting the custom info AVP
modparam("osp","custom_info_avp","$avp(cinfo)")

1.3.28. cnam_avp

The cnam_avp (string) parameter instructs the OSP module to use
the defined AVP to pass the CNAM values. The default value is
"$avp(_osp_cnam_)". Then the CNAM can be used by
"$avp(_osp_cnam_)". All pseudo variables are described in
http://www.opensips.org/Resources/DocsCoreVar.

Example 1.28. Setting the CNAM AVP
modparam("osp","cnam_avp","$avp(cnam)")

1.3.29. source_media_avp, destination_media_avp

These parameters are used to tell the OSP module which AVPs are
used to store media addresses. The default values are
"$avp(_osp_source_media_address_)" and
"$avp(_osp_destination_media_address_)". All pseudo variables
are described in http://www.opensips.org/Resources/DocsCoreVar.

Example 1.29. Setting the media address AVPs
modparam("osp", "source_media_avp", "$avp(srcmedia)")
modparam("osp", "destination_media_avp", "$avp(destmedia)")

1.4. Exported Functions

1.4.1. checkospheader()
Expand All @@ -533,7 +565,7 @@ modparam("osp","custom_info_avp","$avp(cinfo)")

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.28. checkospheader usage
Example 1.30. checkospheader usage
...
if (checkospheader()) {
log(1,"OSP header field found.\n");
Expand All @@ -552,7 +584,7 @@ if (checkospheader()) {

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.29. validateospheader usage
Example 1.31. validateospheader usage
...
if (validateospheader()) {
log(1,"valid OSP header found\n");
Expand All @@ -561,7 +593,23 @@ if (validateospheader()) {
};
...

1.4.3. requestosprouting()
1.4.3. getlocaladdress()

This function gets the receiving IP address of SIP response and
stores it as proxy egress address.

This function can be used from ONREPLY_ROUTE.

Example 1.32. getlocaladress usage
...
if (getlocaladdress()) {
log(1,"Obtain proxy local egress address\n");
} else {
log(1,"Failed to get proxy local egress address\n");
};
...

1.4.4. requestosprouting()

This function launches a query to the peering server requesting
the IP address of one or more destination peers serving the
Expand All @@ -581,7 +629,7 @@ if (validateospheader()) {

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.30. requestosprouting usage
Example 1.33. requestosprouting usage
...
if (requestosprouting()) {
log(1,"successfully queried OSP server, now relaying call\n");
Expand All @@ -590,14 +638,14 @@ if (requestosprouting()) {
};
...

1.4.4. checkosproute()
1.4.5. checkosproute()

This function is used to check if there is any route for the
call.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.31. checkosproute usage
Example 1.34. checkosproute usage
...
if (checkosproute()) {
log(1,"There is at least one route for the call\n");
Expand All @@ -606,7 +654,7 @@ if (checkosproute()) {
};
...

1.4.5. prepareosproute()
1.4.6. prepareosproute()

This function tries to prepare the INVITE to be forwarded using
the destination in the list returned by the peering server. If
Expand All @@ -620,7 +668,7 @@ if (checkosproute()) {

This function can be used from BRANCH_ROUTE.

Example 1.32. prepareosproute usage
Example 1.35. prepareosproute usage
...
if (prepareosproute()) {
log(1,"successfully prepared the route, now relaying call\n");
Expand All @@ -629,7 +677,7 @@ if (prepareosproute()) {
};
...

1.4.6. prepareredirectosproutes()
1.4.7. prepareredirectosproutes()

This function tries to prepare all the routes in the list
returned by the peering server into a SIP 300 Redirect message.
Expand All @@ -639,7 +687,7 @@ if (prepareosproute()) {

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.33. prepareredirectosproutes usage
Example 1.36. prepareredirectosproutes usage
...
if (prepareredirectosproutes()) {
log(1,"Routes are prepared, now redirecting the call\n");
Expand All @@ -648,7 +696,7 @@ if (prepareredirectosproutes()) {
};
...

1.4.7. prepareallosproutes()
1.4.8. prepareallosproutes()

This function tries to prepare all the routes in the list
returned by the peering server. The message is then forked off
Expand All @@ -657,7 +705,7 @@ if (prepareredirectosproutes()) {

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.34. prepareallosproutes usage
Example 1.37. prepareallosproutes usage
...
if (prepareallosproutes()) {
log(1,"Routes are prepared, now forking the call\n");
Expand All @@ -666,7 +714,24 @@ if (prepareallosproutes()) {
};
...

1.4.8. checkcallingtranslation()
1.4.9. preparecnamresponse()

This function tries to prepare the CNAM returned by the peering
server. If unsuccessful in preparing the routes a SIP 500 is
sent back and a trace message is logged.

This function can be used from REQUEST_ROUTE and FAILURE_ROUTE.

Example 1.38. preparecnamresponse usage
...
if (preparecnamresponse()) {
log(1,"CNAM is prepared, new sending the response\n");
} else {
log(1,"Could not prepare CNAM\n");
};
...

1.4.10. checkcallingtranslation()

This function is used to check if the calling number is
translated. Before calling checkcallingtranslation,
Expand All @@ -679,7 +744,7 @@ if (prepareallosproutes()) {

This function can be used from BRANCH_ROUTE.

Example 1.35. checkcallingtranslation usage
Example 1.39. checkcallingtranslation usage
...
if (checkcallingtranslation()) {
# Remove the Remote_Party-ID from the received message
Expand All @@ -691,7 +756,7 @@ if (checkcallingtranslation()) {
}
...

1.4.9. reportospusage()
1.4.11. reportospusage()

This function should be called after receiving a BYE message.
If the message contains an OSP cookie, the function will
Expand All @@ -708,7 +773,7 @@ if (checkcallingtranslation()) {

This function can be used from REQUEST_ROUTE.

Example 1.36. reportospusage usage
Example 1.40. reportospusage usage
...
if (is_direction("downstream")) {
log(1,"This BYE message is from SOURCE\n");
Expand Down
4 changes: 4 additions & 0 deletions modules/osp/RELEASE-NOTES.txt
Expand Up @@ -176,3 +176,7 @@ Support FromDisplayName
Support User-Agent
Support TotalSetupAttempts for completed calls.

2015 September 1
Updated to support media addresses, local address and provider post dial delay.
Updated to support CNAM.

34 changes: 33 additions & 1 deletion modules/osp/destination.c
Expand Up @@ -42,6 +42,8 @@
extern int _osp_origdest_avpid;
extern int _osp_termdest_avpid;
extern int _osp_calling_avpid;
extern int _osp_destmedia_avpid;
extern unsigned short _osp_destmedia_avptype;

/* Name of AVP of OSP */
static str OSP_ORIGDEST_NAME = {"_osp_orig_dests_", 16};
Expand Down Expand Up @@ -317,6 +319,9 @@ static void ospRecordCode(
int code,
osp_dest* dest)
{
struct usr_avp* destmediaavp = NULL;
int_str destmediaval;

LM_DBG("code '%d'\n", code);
dest->lastcode = code;

Expand All @@ -334,6 +339,12 @@ static void ospRecordCode(
case 183:
if (!dest->time180) {
dest->time180 = time(NULL);

if (!dest->endtime) {
dest->endtime = time(NULL);
} else {
LM_DBG("180, 181, 182 or 183 end allready recorded\n");
}
} else {
LM_DBG("180, 181, 182 or 183 allready recorded\n");
}
Expand All @@ -342,12 +353,33 @@ static void ospRecordCode(
case 202:
if (!dest->time200) {
dest->time200 = time(NULL);

if ((_osp_destmedia_avpid >= 0) &&
((destmediaavp = search_first_avp(_osp_destmedia_avptype, _osp_destmedia_avpid, &destmediaval, 0)) != NULL) &&
(destmediaavp->flags & AVP_VAL_STR) && (destmediaval.s.s && destmediaval.s.len))
{
snprintf(dest->destmedia, sizeof(dest->destmedia), "%.*s", destmediaval.s.len, destmediaval.s.s);
dest->destmedia[sizeof(dest->destmedia) - 1] = '\0';
} else {
dest->destmedia[0] = '\0';
}
} else {
LM_DBG("200 or 202 allready recorded\n");
}
break;
case 408:
case 487:
if (!dest->endtime) {
dest->endtime = time(NULL);
} else {
LM_DBG("408 or 487 end allready recorded\n");
}
break;
default:
LM_DBG("will not record time for '%d'\n", code);
/* It may overwrite existing end time, it is the expected behavior */
if ((code >= 400) && (code <= 699)) {
dest->endtime = time(NULL);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions modules/osp/destination.h
Expand Up @@ -60,17 +60,24 @@ typedef struct _osp_dest {
int npdi;
char opname[OSPC_OPNAME_NUMBER][OSP_STRBUF_SIZE];
char display[OSP_STRBUF_SIZE];
char cnam[OSP_STRBUF_SIZE];
char rpid[OSP_STRBUF_SIZE];
char pai[OSP_STRBUF_SIZE];
char divuser[OSP_STRBUF_SIZE];
char divhost[OSP_STRBUF_SIZE];
char pci[OSP_STRBUF_SIZE];
char srcmedia[OSP_STRBUF_SIZE];
char destmedia[OSP_STRBUF_SIZE];
char ingress[OSP_STRBUF_SIZE];
char egress[OSP_STRBUF_SIZE];
unsigned char token[OSP_TOKENBUF_SIZE];
unsigned int tokensize;
unsigned int timelimit;
OSPE_PROTOCOL_NAME protocol;
int lastcode;
time_t authtime;
time_t starttime;
time_t endtime;
time_t time100;
time_t time180;
time_t time200;
Expand Down

0 comments on commit 0fc5816

Please sign in to comment.