Looking at a full-fledged opensips script for the first time can be a bewildering experience. It takes a lot of reading, testing and learning to get comfortable with it. However, for some instant gratification, you can try this. The script below is allows you to register SIP phones on your LAN and make calls to each other. It does not handle PSTN calls or any other fancy features. It doesn’t even check for your credentials, so you can pass in anything you like. If two phones are set up with the same extension, both will ring.
OpenSIPS_ Basic

#
####### Global Parameters #########</code>

debug=3
log_stderror=no
log_facility=LOG_LOCAL0
fork=yes
children=2
auto_aliases=no
listen=udp:192.168.32.8:5060 # CUSTOMIZE ME

#
####### Modules Section ########

mpath="/usr/lib/opensips/modules/"

loadmodule "signaling.so"
loadmodule "sl.so"
loadmodule "registrar.so"
loadmodule "proto_udp.so"
loadmodule "tm.so"

loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")

loadmodule "usrloc.so"
modparam("usrloc", "db_mode", 0)

#
####### Routing Logic ########

route{
    # register user location without authentication
    if (method == "REGISTER") {

        xlog("registering $tU \n");
        save("nuc");
        exit;
    }

    # lookup requested user, if registered, below will replace 
    # R-URI with registered user's contact
    if (method == "INVITE") {

        xlog("calling $tU \n");
        if (!lookup("nuc")) {
            sl_send_reply("404", "User not found");
            exit;
        }
    }

    # relay request in stateful manner to R-URI
    t_relay();
}

Run the script and watch your syslog for register and calling messages. You can also view registered users with the following command:


root@nuc:/etc/opensips# opensipsctl ul show
Domain:: nuc table=512 records=2
	AOR:: 102
		Contact:: sip:102@192.168.32.118:2048;line=7dga26nf Q=1
			Expires:: 3337
			Callid:: 313434373937393735303238383034-1soqnqfjhn95
			Cseq:: 26
			User-agent:: n/a
			State:: CS_NEW
			Flags:: 0
			Cflags::
			Socket:: udp:192.168.32.8:5060
			Methods:: 7999
			SIP_instance:: 
	AOR:: 101
		Contact:: sip:101@192.168.32.3:52500;rinstance=4d64f6f35eb88aa6 Q=
			Expires:: 1155
			Callid:: 78102MWJiZmRhY2VkMTJkNjZmMjhmZjQyMThhNjZmYjIwMGU
			Cseq:: 12
			User-agent:: X-Lite release 4.9.0 stamp 78102
			State:: CS_NEW
			Flags:: 0
			Cflags::
			Socket:: udp:192.168.32.8:5060
			Methods:: 5919



In the next post, I will show how to add a PSTN gateway to this set up so that you can make outgoing calls. Small Steps. I recommend reading up on how SIP works and the structure of a SIP datagram and the various field before proceeding with more advanced topics.

 

Leave a Reply

Your email address will not be published. Required fields are marked *