[OpenSIPS-Users] opensips ims ce - ims client with pjsip python

marek cervenka cervajs at freevoice.cz
Thu Dec 19 14:32:12 UTC 2024


hi,
thanks for new nice project https://ce.opensips.org/opensips-ims
we well try to use it in student/home lab

do you think it is possible use python bindings of pjsip to emulate 5G
part? (IMS client)

something like

---
import pjsua as pj

# Define Account Callback for IMS
class IMSAccountCallback(pj.AccountCallback):
    def on_credentials_request(self, realm, username, auth_hdr, allow_new):
        if realm == "ims.example.com":
            return pj.AuthCredInfo(
                scheme="Digest",
                realm=realm,
                username="alice",
                data="password123",
                data_type=pj.AUTH_CRED_DATA_PLAIN_PASSWD
            )

# Define Call Callback
class CallCallback(pj.CallCallback):
    def on_state(self):
        print("Call is ", self.call.info().state_text)

# Initialize PJSUA
lib = pj.Lib()
lib.init()
transport = lib.create_transport(pj.TransportType.UDP,
pj.TransportConfig(5060))
lib.start()

# Account Configuration
acc_cfg = pj.AccountConfig()
acc_cfg.id = "sip:alice at ims.example.com"
acc_cfg.reg_uri = "sip:ims.example.com"
acc_cfg.proxy = ["sip:pcscf.ims.example.com;lr"]
acc_cfg.allow_contact_rewrite = False

# Add Headers
msg_data = pj.MsgData()
msg_data.add_header("P-Preferred-Identity", "<sip:alice at ims.example.com>")
msg_data.add_header("Supported", "path, outbound, 100rel")
msg_data.add_header("User-Agent", "PJSIP/2.12 IMS Client")
msg_data.add_header(
    "Contact",
    '<sip:alice at 192.0.2.1
;transport=udp>;+sip.instance="<urn:uuid:abc123>";+g.3gpp.icsi-ref="urn%3Aurn-7%3A3gpp-service.ims.icsi.mmtel"'
)

# Create Account
acc = lib.create_account(acc_cfg, cb=IMSAccountCallback())

# Register and Make Call
acc.set_registration(True, msg_data=msg_data)
call = acc.make_call("sip:bob at ims.example.com", cb=CallCallback(),
msg_data=msg_data)

# Wait for user input to terminate
input("Press Enter to quit...")
lib.destroy()
---

Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20241219/11f70690/attachment.html>


More information about the Users mailing list