Newbie Alert...

Place for developers to chat about the code
SteveSmith-Eon
Posts: 4
Joined: Wed May 11, 2016 10:03 am

Newbie Alert...

Postby SteveSmith-Eon » Wed May 11, 2016 11:14 am

Good afternoon all,
I thought it best to ping out a new topic, mostly to make sure I'm in the right place?
I'm at a large Utility com[pany based in the UK Midlands (hint: look at my username:-) ) where I've been tasked with a project to listen into the INVITE response Messages that are emanating from our Aspect VoIP setup.
Using wireshark we can see the messages we are interested in, namely the 200 'OK' that we see as a result of Invite messages.
Now I need to write some code that will consume all the INVITE and associated 200 'OK' messages we see, and then use the data therein to enrich some other data we have.
In essence I just want to log all the SIP 'ctrl' information.
I hope that's enough of an overview of my task here?

So, I obviously dont intend to reinvent the wheel and write my own 'SIP Decoder', I'd rather find a library I can use to do that for me and just 'read packets' that have been decoded, formed into sensible objects...

I'm intending our little project to be in C# and searches found this community, along with what looks to be a good starting point for code.

Am I in the right place?
And if so is there any place I should look at in order to get started?

any help most gratefully received, I hope to reciprocate going forward.
Regards Steve

User avatar
Aaron
Site Admin
Posts: 4546
Joined: Thu Jul 12, 2007 12:13 am

Re: Newbie Alert...

Postby Aaron » Wed May 11, 2016 11:31 am

If you've already captured the SIP messages and now want to parse them then it should be a very straight forward task.

I'd recommend using nuget to get the latest sipsorcery package (https://www.nuget.org/packages/SIPSorcery/) referenced by your C# project. After that the classes you're most likely interested in are in the SIPSorcery.SIP.Core assembly. A good starting point would be the SIPSorcery.SIP.SIPMessage.ParseSIPMessage. It's got a couple of overloads and their purpose is to take a block of bytes or a string and extract all the SIP information from it.

SteveSmith-Eon
Posts: 4
Joined: Wed May 11, 2016 10:03 am

Re: Newbie Alert...

Postby SteveSmith-Eon » Wed May 11, 2016 12:20 pm

That's really useful Aaron, thanks.

I'm guessing I just use that same Nuget code to connect to my SIP endpoint?

User avatar
Aaron
Site Admin
Posts: 4546
Joined: Thu Jul 12, 2007 12:13 am

Re: Newbie Alert...

Postby Aaron » Wed May 11, 2016 12:45 pm

The nuget package does indeed have everything you need to connect to SIP end points but that's a significantly more complicated task compare to parsing SIP Messages.

The simplest code sample to use the sipsorcery stack to communicate with an external SIP endpoint is here https://github.com/sipsorcery/sipsorcer ... Developers.

SteveSmith-Eon
Posts: 4
Joined: Wed May 11, 2016 10:03 am

Re: Newbie Alert...

Postby SteveSmith-Eon » Thu May 12, 2016 10:38 am

Thanks,
I've looked at that example overnight here and run it up on my desktop.
It looks to me that we're nailling up a 'connection' to the SIP Server in the first part?
// Set up the SIP transport infrastructure.
SIPTransport sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine());
SIPUDPChannel udpChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, 5060));
sipTransport.AddSIPChannel(udpChannel);

Then we're instantiating a client who will use the sipTransport to make a call from anon@10.1.1.15:6060 to anon@10.1.1.2
// Create a SIP user agent client that can be used to initiate calls to external SIP devices and place a call.
SIPClientUserAgent uac = new SIPClientUserAgent(sipTransport, null, null, null, _logDelegate);
SIPCallDescriptor callDescriptor = new SIPCallDescriptor("anonymous", null, "sip:anon@10.1.1.15:6060", "<sip:anon@10.1.1.2>", null, null, null, null, SIPCallDirection.Out, "application/sdp", null, null);
uac.Call(callDescriptor);

When I run the console app, _logDelegate is showing me an INVITE event in my console.

I'm guessing that if I had a SIP Server running somewhere then the INVITE would be going there?
As UDP is a 'broadcast' then any server listening on port 5060 will get the INVITE from my client, see the from and to values and deal accordingly?

If I've managed to grasp all that correctly (fingers crossed eh) then ... if I just wrote a UDP client listening to port 5060 I'd also see all the events that the SIP Server does along with it's own output events?

Then each event that I see flying by I can decode using this library?

Bingo, I'd be home and dry....

Does all this make sense, or should I go get my coat?
Is there a pile of documentation I can read maybe, or is it a case of reading all this code you've put together?

Regards
Steve

User avatar
Aaron
Site Admin
Posts: 4546
Joined: Thu Jul 12, 2007 12:13 am

Re: Newbie Alert...

Postby Aaron » Thu May 12, 2016 11:33 am

You're pretty close but a critical false assumption is:

[quote]As UDP is a 'broadcast'../quote]

That's definitely not the case. The UDP packets are unicast unless you specifically send them to a multicast or broadcast address. In your case this means you'll have to find a way to capture, intercept or forward the SIP packets you want to inspect. You can't just fire up a SIP socket and expect the packets to start arriving.

For your code sample try replacing the corresponding line with:

Code: Select all

SIPCallDescriptor callDescriptor = new SIPCallDescriptor("anonymous", null, "sip:music@iptel.org", "<sip:anon@10.1.1.2>", null, null, null, null, SIPCallDirection.Out, "application/sdp", null, null);


The iptel.org is a live public SIP server so you should see the SIP packets flow back and forth setting the call up and then a short time later tearing it back down.

SteveSmith-Eon
Posts: 4
Joined: Wed May 11, 2016 10:03 am

Re: Newbie Alert...

Postby SteveSmith-Eon » Fri May 13, 2016 9:48 am

Ok, understood.
We're currently getting the UDP (SIP SDP) feed using port mirroring through our switches so I think I can drop my code onto the mirrored endpoint and get the INVITEs etc as they run through to our ACD, we just need to eavesdrop them you'll recall.

Looks like I have a long weekend ahead of me :-)

Thanks for all your help, Steve


Return to “Developer Chat”

Who is online

Users browsing this forum: No registered users and 1 guest