25.1 What a proxy may change, and what a B2BUA may change
Module 3 introduced the two kinds of element in the middle of a call. A proxyproxy. An element that forwards requests and responses. It does not start or end calls. routes requests that belong to someone else, so RFC 3261 limits what it may touch. A B2BUAB2BUA. An element that ends one call leg as a UAS and starts a new leg as a UAC. ends the call on one side and starts a new call on the other, so it may change anything:
“The proxy MUST NOT reorder field values with a common field name (See Section 7.3.1). The proxy MUST NOT add to, modify, or remove the message body.”Read the section ↗
“No SIP header field is guaranteed to be copied from the received request on the UAS side to the generated request on the UAC side.”Read the section ↗
| Part of the message | Proxy | B2BUA |
|---|---|---|
| Request-URI | Yes: the next target (location service, Route) | Its own, for the new call |
| Via | Adds its own on top; removes it from responses | A new Via stack: only its own |
| Max-Forwards | Minus one | Usually starts again at 70, or copies it minus one |
| Record-Route, Route | Adds Record-Route; removes its own Route entry | Its own route set on each side |
| From, To, tags | Never | New tags; it may also change the names and URIs |
| Call-ID, CSeq | Never | New on each side |
| Contact | Never | Its own address |
| Body (SDP) | Never | Anything: its own address, other codecs, other media |
| Other headers | May add some (such as P-Asserted-Identity); does not remove others | Copies only what it chooses |
Pick a message in the diagram, and compare what each element does to it. The + and ~ marks show the headers that the element added or changed; − marks the ones it removed:
Proxy vs B2BUA
The same message, before and after the element
Proxy
2 added · 2 changed · 0 removed
Reaches the proxy, from Alice
Leaves, to Bob
The proxy changes only what routing needs: the Request-URI (from the location service), a new Via on top, Max-Forwards minus one, and its Record-Route. Call-ID, tags, CSeq, Contact, and the SDP pass unchanged.
B2BUA
3 added · 7 changed · 3 removed
Reaches the B2BUA, from Alice
Leaves, to Bob
The B2BUA answers Alice's INVITE as a UAS and sends a new one as a UAC. Call-ID, From tag, CSeq, Via, Contact, and the SDP are all its own; only the names in From and To survive.
Two consequences matter in daily work:
- Behind a proxy there is one dialog. Alice and Bob hold the same Call-ID and tags, and every feature that works end to end works through the proxy: REFER, Replaces, SDP encryption keys, an Identity signature (Module 28).
- Behind a B2BUA there are two dialogs. To follow one call in a trace, match the two sides by time, numbers, and any correlation header the B2BUA adds. Every end-to-end feature now works only if the B2BUA supports it, on both sides.
25.2 Common open-source roles
Most SIP networks are built from a few well-known open-source servers, each in its usual role. This course does not teach their configuration, but you will meet them in traces and in job descriptions:
| Server | Role | Typical work |
|---|---|---|
| Kamailio, OpenSIPS | Proxy, registrar, load balancer, edge proxy | Routing, authentication, registration, load balancing, rate limits. Tens of thousands of calls per server, because they handle only signaling. |
| Asterisk, FreeSWITCH | B2BUA | PBX features, IVR, voicemail, conferences, queues, recording, transcoding. They handle the media, so far fewer calls per server. |
| rtpengine | Media relay, controlled by a proxy | Anchors RTP, converts between RTP and SRTP or WebRTC, records. |
A common design puts these together: Kamailio at the edge as registrar and load balancer, rtpengine next to it for the media, and a group of Asterisk or FreeSWITCH servers behind it for the features.
25.3 SBC functions
An SBCSBC. Session Border Controller. A B2BUA at the edge of a network that protects and normalises SIP. is a B2BUA at the border of a network:
“SBCs often modify certain SIP headers and message bodies that proxies are not allowed to modify. Consequently, they are, by definition, B2BUAs (Back-to-Back User Agents).”Read the section ↗
Each of its functions solves a problem at the border, and each has a cost. Turn them on and off below. The PBX on the left sends the same INVITE each time; watch what reaches the carrier, where the media flows, and what happens to attacks:
SBC function explorer
What each function of an SBC changes
From the PBX, inside
To the carrier, outside
Result: The carrier answers 404 Not Found: it cannot route ten digits with no country code.
- ⚠ Number format. The carrier expects E.164 and P-Asserted-Identity. It gets ten digits and Remote-Party-ID, a header from an old draft.
- ⚠ Codec. The PBX offers only G.722. The carrier supports only G.711, so it answers 488 Not Acceptable Here.
- ⚠ Media address. The SDP gives 10.1.1.20, a private address. The carrier's RTP never arrives: a call with no audio.
- ⚠ Internal names. The Call-ID, From, To, User-Agent, and X-Corp-Route show inside addresses, host names, the PBX product, and its version.
- ⚠ Transport. Plain UDP and RTP over the Internet: anyone on the path can read the call and listen to it.
- ✓ Call limit. Nobody counts the calls. Fine at 12 calls; a problem when the trunk is full, or under attack.
- REGISTER scan from 192.0.2.66, guessing extensions: passed to the PBX
- INVITE to an international premium number from 198.51.100.99: passed to the PBX
- 400 INVITEs per second from 203.0.113.250: passed to the PBX
| Function | What it does | What it costs |
|---|---|---|
| topology hidingtopology hiding. An SBC removes or replaces the addresses of the inner network in each message it forwards. | New Call-ID, its own Via, Contact, and route set; inside names and addresses removed | Traces on each side show different calls |
| SIP normalisationSIP normalisation. Changes an SBC makes so that each side gets the SIP it expects, such as E.164 numbers, P-Asserted-Identity in place of an old header, or the removal of unknown headers. | E.164 numbers, P-Asserted-Identity, removes or rewrites headers that the other side does not accept | Rules to write and test for each peer |
| media anchoringmedia anchoring. An SBC or B2BUA puts its own address in the SDP, so the RTP flows through it. Needed for NAT traversal, transcoding, SRTP on one side, and recording. (NAT) | Its own address in the SDP; relays the RTP and latches onto its real source | Bandwidth and a little delay; the SBC is now in the media path |
| transcodingtranscoding. Decoding the media in one codec and encoding it in another, for example G.722 to G.711. It costs CPU or DSP capacity, and some quality. | Converts between codecs that the two sides do not share | CPU or DSP capacity, delay, and some quality, on every packet |
| Security | TLS and SRTP on the Internet side, access lists, rate limits, protocol repair | Certificates to manage; CPU for encryption |
| call admission controlcall admission control. A limit on the number of calls, or the bandwidth, that an SBC accepts on a trunk or from a site. Calls over the limit get an error at once. | Limits calls per trunk or site; rejects the rest at once | A limit that must match the trunk contract |
“The most common form of topology hiding is the application of header privacy (see Section 5.1 of [2]), which involves stripping Via and Record-Route headers, replacing the Contact header, and even changing Call-IDs.”Read the section ↗
“By modifying the session description, the SBC can force the media to be sent through a media relay which may be co-located with the SBC.”Read the section ↗
“For example, an SBC can enable a plain SIP [1] user agent to connect to a 3GPP network, or enable a connection between user agents that support different IP versions, different codecs, or that are in different address realms.”Read the section ↗
“This way, all the SIP traffic entering the inner network needs to be routed though the SBC, which only routes messages from authorized parties or traffic that meets a specific policy that is expressed in the SBC administratively.”Read the section ↗
“This is the case when media encryption (e.g., Secure Real-time Transport Protocol (SRTP)) is used only on the access network (outer network) side and the media is carried unencrypted in the inner network.”Read the section ↗
Everything an SBC does to the SDP breaks end-to-end features. Encryption keys exchanged in the SDP, a signature over the SDP, and any feature that the SBC does not understand stop working:
“Implementing traffic management in this manner requires the SBC to access and modify the session descriptions (i.e., offers and answers) exchanged between the user agents. Consequently, this approach does not work if user agents encrypt or integrity-protect their message bodies end-to-end.”Read the section ↗
25.4 Load balancing and failover with OPTIONS health checks
A Load balancerLoad balancer. A proxy in front of a group of servers. It sends each new call or registration to one of them, and skips servers that do not answer its health checks. is a proxy in front of a group of servers. It chooses a server for each new call, often in turn (“round robin”) or by weight, and it must skip servers that are down. It learns that a server is down in one of two ways:
- After a failure. The server answers 503, or nothing comes back at all. With no answer, the load balancer waits for Timer B: 32 seconds over UDP, while the caller hears nothing.
- Before the call, with a health checkhealth check. A request, often OPTIONS, that a load balancer or SBC sends to a server every few seconds to learn whether it is up.. The load balancer sends OPTIONS to each server every few seconds, and takes a server out of the list when it stops answering.
Flow builder · a load balancer in front of two PBXs
Load balancing, with health checks: PBX A is down
- SIP
PBX A does not answer. After a few probes, the load balancer marks it down and sends it no calls.
All steps as text
- Load balancer → PBX A: OPTIONS. PBX A does not answer. After a few probes, the load balancer marks it down and sends it no calls.
- Load balancer → PBX B: OPTIONS. The load balancer checks PBX B every few seconds, with OPTIONS.
- PBX B → Load balancer: 200 OK. PBX B is up.
- Alice → Load balancer: INVITE. Alice calls Bob. The load balancer in front of the PBXs receives the INVITE.
- Load balancer → Alice: 100 Trying. The load balancer stops Alice's retransmissions.
- Load balancer → PBX B: INVITE. The load balancer knows that PBX A is down, so it sends the INVITE to PBX B at once.
- PBX B → Load balancer: 180 Ringing. PBX B rings Bob's phone.
- Load balancer → Alice: 180 Ringing. The load balancer removes its Via and forwards the 180.
- PBX B → Load balancer: 200 OK. Bob answers. PBX B relays his media.
- Load balancer → Alice: 200 OK. The load balancer forwards the 200 OK. It did not Record-Route, so it leaves the dialog now.
- Alice → PBX B: ACK. Alice sends the ACK straight to PBX B, the Contact in the 200 OK.
“For SIP requests, failure occurs if the transaction layer reports a 503 error response or a transport failure of some sort (generally, due to fatal ICMP errors in UDP or connection failures in TCP). Failure also occurs if the transaction layer times out without ever having received any response, provisional or final (i.e., timer B or timer F in RFC 3261 [1] fires).”Read the section ↗
“If a failure occurs, the client SHOULD create a new request, which is identical to the previous, but has a different value of the Via branch ID than the previous (and therefore constitutes a new SIP transaction). That request is sent to the next element in the list as specified by RFC 2782.”Read the section ↗
Fail over only on a failure of the server: a timeout, a transport error, or a 503. A 4xx or 6xx is an answer about the call, and the next server would give the same answer, or worse, ring the user a second time:
“If a 6xx response is received, it is not immediately forwarded, but the stateful proxy SHOULD cancel all client pending transactions as described in Section 10, and it MUST NOT create any new branches in this context.”Read the section ↗
A 503 with Retry-After tells the load balancer how long to leave that server alone:
“The Retry-After header field can be used with a 500 (Server Internal Error) or 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client”Read the section ↗
Three design choices go with every load balancer:
- What it balances: calls, not requests. In-dialog requests follow the Contact and the route set to the server that has the call. A load balancer that Record-Routes must send them to the same server, not to the next one in turn.
- Where registrations live. If each PBX keeps its own registrations, a call for Bob must go to the PBX where Bob registered. A shared location database lets any PBX take any call.
- How fast it detects a failure. OPTIONS every 5 seconds, with a server marked down after 2 or 3 missed answers, finds a failure in about 15 seconds. Shorter intervals find it faster, at the cost of more traffic. DNS SRV (Module 11) spreads the load from the client side instead, with the same failover rules.
25.5 High availability: shared state and floating IPs
An Active SBCActive SBC. In Module 25, the SBC of a high-availability pair that holds the floating IP address and handles the calls. and a Standby SBCStandby SBC. In Module 25, the SBC of a high-availability pair that waits. It takes over the floating IP address when the active SBC fails. share one floating IP addressfloating IP address. An IP address that moves between the servers of a high-availability pair. Clients always use it, so they need not know which server is active.. Phones, carriers, and DNS know only that address. When the active SBC stops sending keepalives, the standby takes the address and announces it with a gratuitous ARPgratuitous ARP. An ARP message that a server sends without being asked, to tell the switches and routers on its LAN that an IP address now belongs to its MAC address.. Packets for the floating address now reach the new active SBC. For this to work, every address that other elements store must be the floating address: Via, Contact, Record-Route, and the SDP.
What survives a failover depends on the state that the two SBCs share:
| State | If it is not shared | If it is shared |
|---|---|---|
| Registrations | Phones are unreachable until they register again | Incoming calls work at once |
| Dialogs | The next request in a call gets 481; one side of the call never ends | BYE, re-INVITE, and transfer work as before |
| Media relay sessions | The RTP stops; both sides hear silence | The audio continues after a short gap |
| Transactions | A request in progress is lost; retransmissions or the user retry it | Rarely shared; the gain is small |
Call flow · a failover during a call, with shared dialogs
SBC failover, with replicated dialogs
- SIP
- RTP media
- TCP / IP
Alice calls Bob. The SBC pair has one floating IP address, 198.51.100.40; the active SBC holds it.
All steps as text
- Alice → Active SBC: INVITE. Alice calls Bob. The SBC pair has one floating IP address, 198.51.100.40; the active SBC holds it.
- Active SBC → Alice: 100 Trying. The active SBC takes the call.
- Active SBC → Bob: INVITE. The SBC starts its call to Bob, and copies the state of both dialogs to the standby SBC.
- Bob → Active SBC: 200 OK. Bob answers.
- Active SBC → Alice: 200 OK. The SBC answers Alice. Its Contact and SDP give the floating address, not its own.
- Alice → Active SBC: ACK. Alice acknowledges.
- Active SBC → Bob: ACK. The SBC acknowledges Bob's 200 OK.
- Alice → Bob: RTP. The media flows through the floating address of the SBC pair.
- Active SBC → Standby SBC: keepalive. The active SBC crashes. Its keepalives to the standby SBC stop.
- Standby SBC → Bob: gratuitous ARP. The standby SBC takes 198.51.100.40 and announces it on its LAN. Packets for that address now reach the standby SBC.
- Bob → Standby SBC: BYE. Bob hangs up. His BYE goes to the floating address, so the standby SBC receives it.
- Standby SBC → Bob: 200 OK. The standby SBC has a copy of both dialogs, so it accepts the BYE.
- Standby SBC → Alice: BYE. It ends Alice's side of the call too, with the tags from the copy.
- Alice → Standby SBC: 200 OK. Alice confirms. Both sides of the call end, and the call record is complete.
“This state consists of the dialog ID, a local sequence number (used to order requests from the UA to its peer), a remote sequence number (used to order requests from its peer to the UA), a local URI, a remote URI, remote target, a boolean flag called "secure", and a route set, which is an ordered list of URIs.”Read the section ↗
“If the UAS wishes to reject the request because it does not wish to recreate the dialog, it MUST respond to the request with a 481 (Call/Transaction Does Not Exist) status code and pass that to the server transaction.”Read the section ↗
A proxy that does not keep dialog state needs none of this: any copy of it can forward the next request, because the route set in the request says where to go. That is one reason why large networks keep their proxies stateless or transaction-stateful, and put the state that must survive in a shared database.
Common mistakes
Topology hiding that forgets the SDP
An SBC rewrites Via, Contact, and Call-ID on its way to the carrier, and the headers look clean. The SDP still gives the PBX’s private address. Calls connect, but the carrier’s RTP goes to 10.1.1.20 and never arrives: one-way audio on every outbound call.
Broken
An SBC that hides the headers but copies the SDP
- SIP
- RTP media
- ⚠Problem
The PBX sends a call to the SBC on its inside interface. Its SDP gives its private address.
All steps as text
- PBX → SBC: INVITE. The PBX sends a call to the SBC on its inside interface. Its SDP gives its private address.
- SBC → Carrier gateway: INVITE. The SBC hides the inside addresses in the headers: new Call-ID, its own Via and Contact. It copies the SDP unchanged. Problem: The SDP still gives 10.1.1.20. The carrier cannot send media to a private address.
- Carrier gateway → SBC: 200 OK. The carrier answers.
- SBC → PBX: 200 OK. The SBC passes the carrier's SDP to the PBX.
- PBX → SBC: ACK. The PBX acknowledges.
- SBC → Carrier gateway: ACK. The SBC acknowledges the carrier's 200 OK.
- PBX → Carrier gateway: RTP. The PBX's RTP reaches the carrier through the company's NAT.
- Carrier gateway → PBX: RTP. The carrier sends its RTP to 10.1.1.20, a private address. It never arrives. Problem: One-way audio: Bob hears Alice, but Alice hears nothing.
Remember: an address in the SDP is part of the topology. Anchor the media on the SBC, or make sure that the inside address is reachable from the outside. The course’s checker calls this rule sdp-private-address (Module 20).
A load balancer with no health checks
A load balancer sends calls in turn to two PBXs, and does not probe them. PBX A fails at night. Every second call now waits 32 seconds for Timer B before it goes to PBX B, and most callers hang up first.
Broken: no health checks
Load balancing, no health checks: PBX A is down
- SIP
- ⚠Problem
Alice calls Bob. The load balancer in front of the PBXs receives the INVITE.
All steps as text
- Alice → Load balancer: INVITE. Alice calls Bob. The load balancer in front of the PBXs receives the INVITE.
- Load balancer → Alice: 100 Trying. The load balancer stops Alice's retransmissions.
- Load balancer → PBX A: INVITE. PBX A is next in the round robin. The load balancer does not know that PBX A is down.
- Load balancer → PBX A: INVITE (retransmission). No 100 Trying comes back. The load balancer sends the INVITE again, and again, with longer gaps.
- Load balancer → PBX A: INVITE (retransmission). Still no answer. Alice hears nothing at all.
- Load balancer → PBX B: INVITE. Timer B fires after 32 seconds. Only now does the load balancer try PBX B, with a new branch. Problem: Alice waited 32 seconds in silence. Most callers hang up before this.
- PBX B → Load balancer: 180 Ringing. PBX B rings Bob's phone.
- Load balancer → Alice: 180 Ringing. The load balancer removes its Via and forwards the 180.
- PBX B → Load balancer: 200 OK. Bob answers. PBX B relays his media.
- Load balancer → Alice: 200 OK. The load balancer forwards the 200 OK. It did not Record-Route, so it leaves the dialog now.
- Alice → PBX B: ACK. Alice sends the ACK straight to PBX B, the Contact in the 200 OK.
Remember: probe every server with OPTIONS, and take it out of the list after a few missed answers. Also set a failover timer much shorter than 32 seconds for the INVITE to a server.
Failing over after a final answer from the user
A load balancer tries the next server after any error response. Bob presses Decline, and PBX A answers 603. The load balancer sends the call to PBX B, which rings Bob’s phone again.
Broken: fails over on 603
Load balancing, with health checks: PBX A bob declines (603)
- SIP
- ⚠Problem
The load balancer checks PBX A every few seconds, with OPTIONS.
All steps as text
- Load balancer → PBX A: OPTIONS. The load balancer checks PBX A every few seconds, with OPTIONS.
- PBX A → Load balancer: 200 OK. PBX A is up.
- Load balancer → PBX B: OPTIONS. The load balancer checks PBX B every few seconds, with OPTIONS.
- PBX B → Load balancer: 200 OK. PBX B is up.
- Alice → Load balancer: INVITE. Alice calls Bob. The load balancer in front of the PBXs receives the INVITE.
- Load balancer → Alice: 100 Trying. The load balancer stops Alice's retransmissions.
- Load balancer → PBX A: INVITE. PBX A is next in the round robin.
- PBX A → Load balancer: 180 Ringing. PBX A rings Bob's phone.
- Load balancer → Alice: 180 Ringing. The load balancer forwards the 180.
- PBX A → Load balancer: 603 Decline. Bob sees who is calling, and presses Decline.
- Load balancer → PBX A: ACK. The load balancer acknowledges the failure on this hop.
- Load balancer → PBX B: INVITE. This load balancer tries the next PBX after any failure. PBX B rings Bob's phone again. Problem: Bob declined the call, and his phone rings again. A 6xx means: try nowhere else.
- PBX B → Load balancer: 180 Ringing. Bob's phone rings a second time.
- PBX B → Load balancer: 603 Decline. Bob declines again.
- Load balancer → PBX B: ACK. The load balancer acknowledges the failure on this hop.
- Load balancer → Alice: 603 Decline. Only now does Alice learn that Bob declined.
- Alice → Load balancer: ACK. Alice acknowledges it.
Remember: fail over on a timeout, a transport error, or a 503. Pass every other final response to the caller, and never try another server after a 6xx.
An HA pair that does not share dialogs
Two SBCs share a floating IP address, and the failover test passes: new calls work within seconds. Nobody tests a call that is up during the failover. In production, every such call has one side that never ends; billing records run for hours, and trunk channels stay in use.
Problem: 481, one side stays up
SBC failover, without replicated dialogs
- SIP
- RTP media
- TCP / IP
- ⚠Problem
Alice calls Bob. The SBC pair has one floating IP address, 198.51.100.40; the active SBC holds it.
All steps as text
- Alice → Active SBC: INVITE. Alice calls Bob. The SBC pair has one floating IP address, 198.51.100.40; the active SBC holds it.
- Active SBC → Alice: 100 Trying. The active SBC takes the call.
- Active SBC → Bob: INVITE. The SBC starts its call to Bob. It keeps the state of both dialogs in its own memory only.
- Bob → Active SBC: 200 OK. Bob answers.
- Active SBC → Alice: 200 OK. The SBC answers Alice. Its Contact and SDP give the floating address, not its own.
- Alice → Active SBC: ACK. Alice acknowledges.
- Active SBC → Bob: ACK. The SBC acknowledges Bob's 200 OK.
- Alice → Bob: RTP. The media flows through the floating address of the SBC pair.
- Active SBC → Standby SBC: keepalive. The active SBC crashes. Its keepalives to the standby SBC stop.
- Standby SBC → Bob: gratuitous ARP. The standby SBC takes 198.51.100.40 and announces it on its LAN. Packets for that address now reach the standby SBC.
- Bob → Standby SBC: BYE. Bob hangs up. His BYE goes to the floating address, so the standby SBC receives it.
- Standby SBC → Bob: 481 Call/Transaction Does Not Exist. The standby SBC knows nothing about this dialog. Problem: Nobody sends a BYE to Alice. Her call stays up, and billing keeps counting.
- Alice → Standby SBC: RTP. Alice's phone still sends RTP. The standby SBC drops it, and Alice hears silence until she hangs up.
Remember: replicate dialog state and media relay sessions between the pair, and use session timers (Module 22) so that a call whose state was lost ends by itself. Test a failover with calls in progress.
Summary
- A proxy changes only what routing needs: Request-URI, Via, Max-Forwards, Route, and Record-Route. It never changes From, To, Call-ID, CSeq, Contact, or the body. A B2BUA may change everything, and splits the call into two dialogs.
- Kamailio and OpenSIPS are proxies, registrars, and load balancers; Asterisk and FreeSWITCH are B2BUAs with media features; rtpengine is a media relay that a proxy controls.
- An SBC is a B2BUA at the border. Its functions: topology hiding, normalisation, media anchoring for NAT, transcoding, security, and call admission control. Each one has a cost, and every change to the SDP breaks end-to-end features.
- A load balancer probes its servers with OPTIONS and fails over on a timeout, a transport error, or a 503, never on a 4xx or 6xx answer about the call.
- An HA pair shares a floating IP address. Calls survive a failover only if the pair shares registrations, dialogs, and media sessions, and every stored address is the floating one.