IMS Core Testing and Validation: P-CSCF, S-CSCF, and HSS
IP Multimedia Subsystem (IMS) is the architectural framework that enables VoLTE, VoNR, RCS, and carrier-grade messaging on 4G/5G networks. Testing an IMS core requires understanding the interplay between SIP signaling, Diameter protocol interfaces, and the HSS (Home Subscriber Server) — the combination that makes registration, authentication, and session control work. This guide walks through systematic testing of each component and their interactions.
IMS Architecture Overview
UE
│ SIP/TLS (Gm interface)
▼
┌─────────────┐
│ P-CSCF │ Proxy-CSCF: first SIP contact point, IPsec termination
└──────┬──────┘
│ SIP (Mw interface)
▼
┌─────────────┐ Cx/Dx (Diameter) ┌─────────────┐
│ I-CSCF │ ──────────────────── │ HSS │
└──────┬──────┘ └─────────────┘
│ SIP (Mw interface)
▼
┌─────────────┐ Cx/Dx (Diameter) ┌─────────────┐
│ S-CSCF │ ──────────────────── │ HSS │
└──────┬──────┘ └─────────────┘
│ SIP (ISC interface)
▼
┌─────────────┐
│ AS (App │ Application Server: voicemail, RCS, XCAP
│ Server) │
└─────────────┘Key reference points:
- Gm: UE ↔ P-CSCF (SIP, protected by IPsec or TLS)
- Mw: CSCF ↔ CSCF (SIP)
- Cx: I-CSCF/S-CSCF ↔ HSS (Diameter)
- Dx: I-CSCF ↔ SLF (Subscription Locator Function, Diameter)
- Sh: AS ↔ HSS (Diameter, for subscriber data access)
IMS Registration Flow Testing
The IMS registration is a two-challenge authentication process (AKA — Authentication and Key Agreement). Testing must verify both the signaling sequence and the authentication outcome.
Registration Sequence
UE P-CSCF I-CSCF S-CSCF HSS
│ │ │ │ │
│──REGISTER (no auth)──>│ │ │ │
│ │──REGISTER─>│ │ │
│ │ │──UAR──────────────────>│
│ │ │<──UAA (S-CSCF addr)───│
│ │ │──REGISTER─────────────>│ (S-CSCF)
│ │ │ │──MAR─────>│
│ │ │ │<──MAA─────│
│ │ │<──401 (SIP)────────────│
│<──401 (challenge)────-│ │ │ │
│ │ │ │ │
│──REGISTER (with auth)>│ │ │ │
│ │──REGISTER─>│ │ │
│ │ │──REGISTER─────────────>│ (S-CSCF)
│ │ │ │──SAR─────>│
│ │ │ │<──SAA─────│
│<──200 OK──────────────│ │ │ │Automated Registration Test with SIPp
<!-- IMS registration scenario with AKA authentication -->
<?xml version="1.0" encoding="UTF-8"?>
<scenario name="IMS Registration AKA">
<!-- First REGISTER (no credentials) -->
<send retrans="500">
<![CDATA[
REGISTER sip:[domain] SIP/2.0
Via: SIP/2.0/UDP [local_ip]:[local_port];branch=[branch]
From: <sip:[impu]@[domain]>;tag=[pid]
To: <sip:[impu]@[domain]>
Call-ID: [call_id]
CSeq: 1 REGISTER
Contact: <sip:[impu]@[local_ip]:[local_port]>
Expires: 3600
Require: sec-agree
Proxy-Require: sec-agree
Security-Client: ipsec-3gpp; alg=hmac-sha-1-96; spi-c=11111; spi-s=22222; port-c=5100; port-s=5101
Authorization: Digest username="[impu]@[domain]",realm="[domain]",nonce="",uri="sip:[domain]",response=""
Content-Length: 0
]]>
</send>
<!-- Receive 401 Unauthorized with challenge -->
<recv response="401" auth="true">
<action>
<!-- Extract nonce from WWW-Authenticate header -->
<ereg regexp="nonce=\"([^\"]+)\""
search_in="hdr"
header="WWW-Authenticate:"
assign_to="nonce" />
</action>
</recv>
<!-- Second REGISTER with AKA response -->
<send retrans="500">
<![CDATA[
REGISTER sip:[domain] SIP/2.0
Via: SIP/2.0/UDP [local_ip]:[local_port];branch=[branch]
From: <sip:[impu]@[domain]>;tag=[pid]
To: <sip:[impu]@[domain]>
Call-ID: [call_id]
CSeq: 2 REGISTER
Contact: <sip:[impu]@[local_ip]:[local_port]>
Expires: 3600
Authorization: Digest username="[impu]@[domain]",realm="[domain]",nonce="[nonce]",uri="sip:[domain]",response="[authentication]",algorithm=AKAv1-MD5
Content-Length: 0
]]>
</send>
<!-- Receive 200 OK -->
<recv response="200">
<action>
<ereg regexp="Expires: (\d+)"
search_in="hdr"
header="Contact:"
assign_to="granted_expires" />
</action>
</recv>
</scenario>Registration Test Validation Script
import subprocess
import re
import time
def test_ims_registration(p_cscf_ip, impu, impi, domain,
expected_expires=3600, timeout=30):
"""
Run SIPp registration scenario and validate outcome.
"""
result = subprocess.run([
"sipp",
"-sf", "ims_register.xml",
"-s", domain,
f"{p_cscf_ip}:5060",
"-key", "impu", impu,
"-key", "impi", impi,
"-key", "domain", domain,
"-m", "1", # Single registration
"-trace_msg",
"-message_file", f"/tmp/ims-reg-{impu}.log",
"-timeout", str(timeout)
], capture_output=True, text=True, timeout=timeout + 5)
if result.returncode != 0:
print(f"FAIL: SIPp returned {result.returncode}")
print(result.stderr[-500:])
return False
# Parse SIPp output for success/failure stats
stats = parse_sipp_stats(result.stdout)
if stats.get("failed_calls", 0) > 0:
print(f"FAIL: Registration failed for {impu}")
return False
# Verify 200 OK was received (not just no failures)
with open(f"/tmp/ims-reg-{impu}.log") as f:
log = f.read()
if "SIP/2.0 200 OK" not in log:
print(f"FAIL: No 200 OK in message log for {impu}")
return False
# Check granted expires value
expires_match = re.search(r"Expires: (\d+)", log)
if expires_match:
granted = int(expires_match.group(1))
assert granted <= expected_expires, \
f"Granted expires {granted} exceeds requested {expected_expires}"
print(f"PASS: Registration successful for {impu}")
return TrueCx/Dx Interface Testing (Diameter)
The Cx interface between CSCFs and HSS uses Diameter protocol. Testing this interface is critical because errors here manifest as mysterious SIP 403/404 responses.
Diameter Command Testing
from diameter import DiameterSession, CxCommands
# Using freeDiameter Python bindings or pyDiameter
def test_user_authorization_request(hss_ip, hss_port, impu, impi, visited_network):
"""
UAR (User-Authorization-Request) — sent by I-CSCF to HSS
to determine which S-CSCF should handle the user.
"""
session = DiameterSession(
origin_host="icscf.test.ims",
origin_realm="test.ims",
destination_host=f"hss.{visited_network}",
destination_realm=visited_network,
host=hss_ip,
port=hss_port
)
session.connect()
uar = CxCommands.UserAuthorizationRequest(
public_identity=impu,
visited_network_identifier=visited_network,
user_authorization_type=0 # 0 = REGISTRATION
)
response = session.send_and_receive(uar, timeout=5)
assert response.result_code == 2001, \
f"UAR failed: Result-Code={response.result_code}, " \
f"Experimental-Result={response.experimental_result_code}"
scscf_name = response.get_avp("Server-Name")
assert scscf_name, "UAA missing Server-Name AVP (S-CSCF address)"
print(f"PASS: UAR → UAA successful, S-CSCF={scscf_name}")
session.disconnect()
return scscf_name
def test_multimedia_auth_request(hss_ip, hss_port, impu, impi):
"""
MAR (Multimedia-Auth-Request) — sent by S-CSCF to HSS
to retrieve authentication vectors.
"""
session = DiameterSession(
origin_host="scscf.test.ims",
origin_realm="test.ims",
destination_realm="test.ims",
host=hss_ip, port=hss_port
)
session.connect()
mar = CxCommands.MultimediaAuthRequest(
public_identity=impu,
user_name=impi,
sip_auth_data_item={
"scheme": "Digest-AKAv1-MD5",
"number_of_requested_vectors": 1
}
)
response = session.send_and_receive(mar, timeout=5)
assert response.result_code == 2001, f"MAR failed: {response.result_code}"
auth_vectors = response.get_avp("SIP-Auth-Data-Item")
assert auth_vectors, "MAA missing authentication vectors"
# Verify vector contents
vector = auth_vectors[0]
assert vector.get("RAND"), "Missing RAND in auth vector"
assert vector.get("AUTN"), "Missing AUTN in auth vector"
print(f"PASS: MAR → MAA successful, got {len(auth_vectors)} auth vector(s)")
session.disconnect()
def test_server_assignment_request(hss_ip, hss_port, impu, impi, scscf_name):
"""
SAR (Server-Assignment-Request) — registers the S-CSCF assignment in HSS.
"""
session = DiameterSession(
origin_host="scscf.test.ims",
origin_realm="test.ims",
host=hss_ip, port=hss_port
)
session.connect()
sar = CxCommands.ServerAssignmentRequest(
public_identity=impu,
user_name=impi,
server_name=scscf_name,
server_assignment_type=1 # REGISTRATION
)
response = session.send_and_receive(sar, timeout=5)
assert response.result_code == 2001, f"SAR failed: {response.result_code}"
# Verify user profile returned
user_data = response.get_avp("User-Data")
assert user_data, "SAA missing User-Data AVP (service profile)"
print(f"PASS: SAR → SAA successful, user profile size={len(user_data)} bytes")
session.disconnect()VoLTE End-to-End Testing
A VoLTE call requires coordinated testing of:
- LTE bearer establishment (dedicated bearer for voice QoS)
- IMS registration
- SIP INVITE flow through P/S-CSCF
- RTP media establishment
- RTCP quality reporting
#!/bin/bash
# VoLTE end-to-end test using two test UEs
UE_A="192.168.100.10"
UE_B="192.168.100.11"
IMPU_A="sip:+447712345678@ims.test"
IMPU_B="sip:+447798765432@ims.test"
echo "Step 1: Register both UEs"
# Use test UE CLI or SIPp to register
register_ue() {
local ue_ip=$1 impu=$2
curl -s -X POST "http://${ue_ip}:8080/api/register" \
-H "Content-Type: application/json" \
-d "{\"impu\": \"${impu}\"}"
}
register_ue $UE_A $IMPU_A && echo "UE-A registered"
register_ue $UE_B $IMPU_B && echo "UE-B registered"
echo ""
echo "Step 2: Initiate VoLTE call from UE-A to UE-B"
CALL_ID=$(curl -s -X POST "http://${UE_A}:8080/api/call" \
-H "Content-Type: application/json" \
-d "{\"destination\": \"${IMPU_B}\", \"duration\": 10}" | \
python3 -c "import sys,json; print(json.load(sys.stdin)['call_id'])")
echo "Call initiated: $CALL_ID"
echo ""
echo "Step 3: Monitor call quality metrics"
sleep 5 # Allow call to establish
# Retrieve RTCP stats from UE-A
RTCP_STATS=$(curl -s "http://${UE_A}:8080/api/call/${CALL_ID}/rtcp")
echo $RTCP_STATS | python3 << 'EOF'
import sys, json
stats = json.load(sys.stdin)
jitter = stats.get("jitter_ms", 0)
loss = stats.get("packet_loss_pct", 0)
mos = stats.get("mos_score", 0)
print(f" Jitter: {jitter:.1f}ms (max 30ms)")
print(f" Packet loss: {loss:.2f}% (max 1%)")
print(f" MOS score: {mos:.2f} (min 3.5)")
failed = []
if jitter > 30: failed.append(f"jitter {jitter:.1f}ms > 30ms")
if loss > 1.0: failed.append(f"loss {loss:.2f}% > 1%")
if mos < 3.5: failed.append(f"MOS {mos:.2f} < 3.5")
if failed:
print(f"FAIL: Quality issues: {', '.join(failed)}")
else:
print("PASS: VoLTE call quality within bounds")
EOFOpen-Source IMS Testbed with Kamailio
For integration testing without a commercial IMS, Kamailio with the IMS modules provides a complete testbed.
# Kamailio IMS core configuration excerpts
# /etc/kamailio/kamailio-ims.cfg
#!define WITH_IMS
#!define WITH_PCSCF
#!define WITH_SCSCF
# Load IMS modules
loadmodule "ims_usrloc_pcscf.so"
loadmodule "ims_registrar_pcscf.so"
loadmodule "ims_auth.so"
loadmodule "ims_dialog.so"
loadmodule "cdp.so" # Diameter client/server
loadmodule "cdp_avp.so"
# CDP (Diameter) configuration
modparam("cdp", "config_file", "/etc/kamailio/diameter.xml")
# IMS registrar parameters
modparam("ims_registrar_pcscf", "min_expires", 300)
modparam("ims_registrar_pcscf", "max_expires", 7200)
modparam("ims_registrar_pcscf", "force_icscf_uri", "sip:icscf.ims.test:5060")Test the Kamailio IMS registration handling:
# Run registration test suite against local Kamailio IMS
python3 << 'EOF'
import subprocess
import time
TEST_CASES = [
{
"name": "Valid AKA registration",
"impu": "sip:test001@ims.test",
"impi": "test001@ims.test",
"expect_success": True
},
{
"name": "Invalid IMPI (unknown subscriber)",
"impu": "sip:unknown@ims.test",
"impi": "unknown@ims.test",
"expect_success": False,
"expected_code": "403"
},
{
"name": "Re-registration within expiry",
"impu": "sip:test001@ims.test",
"impi": "test001@ims.test",
"expect_success": True,
"pre_register": True # Register first, then re-register
},
]
for tc in TEST_CASES:
result = run_registration_test(
p_cscf="127.0.0.1:5060",
impu=tc["impu"],
impi=tc["impi"],
expect_code="200" if tc["expect_success"] else tc.get("expected_code", "4xx")
)
status = "PASS" if result == tc["expect_success"] else "FAIL"
print(f"{status}: {tc['name']}")
EOFSh Interface Testing
The Sh interface (AS ↔ HSS via Diameter) allows application servers to read and update subscriber data. Testing it prevents AS deployments from corrupting HSS subscriber profiles.
def test_sh_user_data_request(hss_ip, impu, data_reference):
"""
UDR (User-Data-Request) on Sh interface.
Used by AS to read subscriber data (e.g., service profile, PSI data).
"""
session = create_sh_diameter_session(hss_ip)
udr = ShCommands.UserDataRequest(
public_identity=impu,
data_reference=data_reference, # 0=RepositoryData, 10=PSIActivation, etc.
service_indication=b"MyAppService"
)
response = session.send_and_receive(udr, timeout=5)
# 2001 = DIAMETER_SUCCESS, 5001 = USER_UNKNOWN, 5004 = NO_TRANSPARENT_DATA
assert response.result_code in (2001, 5004), \
f"UDR failed with unexpected code: {response.result_code}"
if response.result_code == 2001:
user_data_xml = response.get_avp("User-Data")
# Validate XML structure against IMS XCAP schema
validate_sh_user_data_xml(user_data_xml)
print(f"PASS: UDR returned user data for {impu}")
else:
print(f"PASS: UDR returned no-data for {impu} (code 5004)")3GPP TS 24.229 Conformance Validation
IMS behavior is specified in 3GPP TS 24.229. Key test cases from the specification:
TS_24229_TESTS = {
"5.4.1.1": "Registration — Initial registration procedure",
"5.4.1.7": "Registration — Re-registration",
"5.4.2.1": "Deregistration — UE-initiated",
"5.4.2.2": "Deregistration — HSS-initiated",
"6.1.1": "Mobile originating session setup",
"6.1.2": "Mobile terminating session setup",
"6.3.1": "Call hold and resume",
"6.4.1": "Call transfer",
}
def run_conformance_suite(p_cscf_ip, domain, subscriber_pool):
"""
Execute a subset of 3GPP TS 24.229 test cases.
Each test case maps to a SIPp scenario.
"""
results = {}
for test_id, description in TS_24229_TESTS.items():
scenario_file = f"scenarios/ts24229_{test_id.replace('.', '_')}.xml"
impu, impi = next(subscriber_pool)
success = run_sipp_scenario(
scenario=scenario_file,
p_cscf=p_cscf_ip,
impu=impu,
impi=impi,
domain=domain
)
results[test_id] = {
"description": description,
"passed": success
}
print(f" [{test_id}] {description}: {'PASS' if success else 'FAIL'}")
passed = sum(1 for r in results.values() if r["passed"])
print(f"\nConformance: {passed}/{len(results)} test cases passed")
return resultsKey Takeaways
- The two-challenge IMS registration (first REGISTER with no credentials, second with AKA response) is the most common source of interoperability failures — test it with exact header validation
- Cx interface (Diameter) errors are invisible at the SIP layer — test UAR, MAR, and SAR independently using Diameter test tools, not just end-to-end SIP tests
- VoLTE quality must be measured with RTCP statistics during calls, not just call establishment success
- Kamailio with IMS modules provides a free testbed capable of running full registration and session scenarios
- Sh interface testing is often skipped, creating a risk of AS deployments corrupting subscriber profiles in the HSS