cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
692
Views
5
Helpful
2
Replies

Modifying an incoming SIP INVITE message truncate number

p-blalock
Level 1
Level 1

Hello,

 

I'm trying to write sip profile that truncates the 10-digit Diversion number dow to the last 4-digits and re-writes that number back into the Diversion header, but I'm not very succesful.  I've written may copy and writes to different headers, but never had a need to first truncate a part of the header and re-write.  For example (IP addresses changed for privacy):

 

I need the original Diversion header of

          Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

To be changed to:

          Diversion: <sip:3333@192.168.0.1:5060;user=phone>

 

Can someone help with the profile rule to make this happen?

 

Best,

 

 

2 Replies 2

Anthony Holloway
Cisco Employee
Cisco Employee

 

This is a perfect use case for the SIP Profile Test Tool

 

SIP Profile 

voice class sip-profiles 1
 request INVITE sip-header Diversion modify "sip:\d*(\d{4})@" "sip:\1@"
!

 

SIP Input Message

INVITE sip:user@domain SIP/2.0
Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

 

SIP Profile Magic

INVITE sip:user@domain SIP/2.0
Diversion: <sip:3333@192.168.0.1:5060;user=phone>

 

The magic is in the regular expression matching pattern: sip:\d*(\d{4})@

 

Let's break that down.

 

First up, we have a prefix on our pattern, which if it doesn't exist, then we'll ignore the input.  This is a pretty standard way of qualifying the input.

sip: matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

 

Then we stipulate that the next character could be missing, but if it's present, it has to be a digit, and there could be more than on of them.

\d* matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

 

If you're wondering why it didn't match the entire number, it's because we then stipulate that there must be at least 4 digits in there, after those optional leading digits.

(\d{4}) matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

 

The parenthesis around it simply means "remember what you matched."  This is because the modify command, requires that we replace whatever we matched with something else, and we want to be able to reference something we matched; in this case, the last 4 digits.

 

Lastly, much like the prefix matching, we match postfix, and stipulate that the number should be followed by an at sign (@).

@ matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>

 

Ok, this is actually the last part, we have to do the replace, on what we matched.  So we specify our prefix and postfix yet again, followed by recalling what we told the profile to remember about our match.

sip:\1@

 

 

(+5) Anthony.
To add to this, Inbound SIP profile manipulation was added starting IOS 15.4(2) T and XE 3.12S. If you are not on the minimum code, you cannot configure inbound SIP profile. If this is a CUBE, you can use outbound profiling without issues and without the need to upgrade code.