Category Archives: OpenSIPS

A2billing with OpenSIPS and DID calls

This post follows on from these posts about using A2Billing and OpenSIPS together –

In those posts we looked at customers outgoing calls from a2billing. This time we’re going to look at one idea for setting up DID numbers. This is only one suggestion, there are others.

Below we are going to get OpenSIPS to look at the called number (which in this case will be incoming from our DID provider) and if it matches a DID number set up in A2Billing then we will send the call to the A2Billing/Asterisk server for processing. We will add a custom SIP header to the call before sending it to the A2Billing/Asterisk server so that Asterisk knows this is a DID call, rather than an outbound call for an A2Billing customer.


If you check in the previous posts you will see that we had this SIP PEER set up in Asterisk –


Continue reading

Integrating OpenSIPS with Asterisk and A2Billing

Below are links to the 3 parts of a post covering integrating OpenSIPS with Asterisk and A2Billing. The setup described uses OpenSIPS handling A2Billing customer SIP requests for calls (for example when providing a wholesale service to other SIP PBXs).

It’s based on OpenSIPS v1.8 / Asterisk v1.8 / A2Billing v2.01

Please take security in to consideration with VOIP whether testing or in a live situation.

Part 1 – Overview of using A2Billing and OpenSIPS together

Part 2 – Setting up the OpenSIPS MySQL database and integrating it with the A2Billing MySQL database

Part 3 – The opensips.cfg config file

A2Billing and OpenSIPS – Part 3

This post has the actual config of OpenSIPS described in part 1 and part 2. Some of this config will not make sense unless you read those parts.

First a warning … many, many people want to use your call credit!! Make sure that your systems are secure. If only the OpenSIPS server needs to talk to your A2Billing/Asterisk servers over SIP then use a fierwall to block other connections.

In the configuration below OpenSIPS does not handle the Audio/RTP traffic, this is passed directly to the Asterisk/A2Billing server.

The code below is the whole opensips.cfg file, just broken up with some description. All indentation has been removed, apologies if this sometimes makes it difficult to read.

First some global settings, including the IP address of the OpenSIPS server –

listen=udp: # CUSTOMIZE ME

next we load the modules that are required –

loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""
loadmodule ""

Continue reading

A2Billing and OpenSIPS – Part 2

In this part of the guide I’m going to look at some of the set up required for the example config to work.

We are going to enable IP and USER/SECRET authentication for our A2Billing SIP customer calls. To do that we are going to create a couple of MySQL VIEWS in the ‘opensips’ database that point to tables in the ‘a2billing’ database. This means we can create our A2Billing SIP users as normal, and they will then become valid users in OpenSIPS.

Part 2 and Part 3 of the guide assume the following –

  • OpenSIPS server IP =
  • A2Billing server IP =
  • MySQL server IP =   (same server as A2Billing)
  • domain name for our calls =

On the A2Billing/Asterisk server

So now we create our VIEWS in the database. We are going to use the ‘address’ table for IP authentications and the ‘subscriber’ table for USER/SECRET authentications.

Here we create the ‘address’ VIEW –

DROP TABLE opensips.address

CREATE VIEW opensips.address AS
SELECT id AS id,
host AS ip,
cast(port as DECIMAL) AS port,
'UDP' AS proto,
'' AS pattern,
accountcode AS context_info
from a2billing.cc_sip_buddies
WHERE host != 'dynamic';

Continue reading

A2Billing and OpenSIPS – Part 1

This is part 1 of a 3 part post discussing A2Billing and OpenSIPS. A2Billing is a billing platform for Asterisk, and OpenSIPS is an Open Source SIP Server. In this first part I’m going to talk about what OpenSIPS is and why you may want to use it. In the second part I’ll talk about some prerequisites for the setup I’m going to show, and in the third part will be the OpenSIPS config.

A2Billing works perfectly well without OpenSIPS, so why would you want to use them together? Well, with OpenSIPS sitting in front of A2Billing/Asterisk and handling all of the SIP connections it can provide the following benefits –

  • load balance across multiple Asterisk/A2Billing servers
  • failover – take an Asterisk server out of the cluster if it should fail
  • limit SIP connections so that only the OpenSIPS server talks to Asterisk/A2Billing over SIP
  • register all of your SIP customers in a single place – the OpenSIPS server (the config I show is not going to cover SIP registrations)
  • OpenSIPS has much better logging of SIP connections (than Asterisk) so we can use fail2ban more efficiently to block attacks

There are probably many more benefits than those listed above. OpenSIPS has lots of modules that provide flexibility to handle the SIP connections exactly as you need.

In the config that follows I am going to show how to do SIP termination. SIP clients authenticate to OpenSIPS using either IP or USER/SECRET authentication and then calls are passed to A2Billing/Asterisk for completion. This example does not cover SIP registrations or incoming DID numbers.

OpenSIPS will sit between the A2Billing SIP customers and the A2Billing/Asterisk server. All customer SIP connections will be to the OpenSIPS server, which will then pass these on to Asterisk/A2Billing once authenticated. A2Billing/Asterisk will talk to the call provider directly (not via OpenSIPS). So the setup looks something like this –

A2Billing SIP Customer  -->  OpenSIPS  -->  A2Billing/Asterisk  --> Call provider
                                       -->  A2Billing/Asterisk  --> Call provider
                                       -->  A2Billing/Asterisk  --> Call provider

This diagram above shows calls going to 3 different A2Billing/Asterisk servers. In the example config there is just one set up, but it will be obvious how to add more.

Also, in OpenSIPS there are 2 different ‘load balancing’ modules. There is one called ‘dispatcher’ which in unintelligent and just send the calls to a group of A2Billing/Asterisk servers. And there is a module called ‘load-balancer’ which knows the state of each A2Billing/Asterisk server and evenly distributes the load across them. For simplicity in this example I will be using the ‘dispatcher’ module.

This guide assumes that you have –

  • a working A2Billing/Asterisk server in place
  • a working OpenSIPS v1.8 server in place
  • created a database called ‘opensips’ (as per the OpenSIPS install instructions) that is on MySQL running on the A2BIlling/Asterisk server

We are going to have both the A2Billing and OpenSIPS databases running on the A2Billing server so that we can integrate the two

In part 2 I’ll discuss some of the prerequisites and the database setup.