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

Răzvan Crainea razvan at opensips.org
Fri Dec 20 07:44:42 UTC 2024


Hi, Marek!

You also need to use AKA+IPSec. I know pjsip does have support for aka, 
not sure about the ipsec tunnel though.
Do note that you still need to be part of the 4G/5G network, so you 
probably need to simulate an UE.

Best regards,

Răzvan Crainea
OpenSIPS Core Developer / SIPhub CTO
http://www.opensips-solutions.com / https://www.siphub.com

On 12/19/24 4:32 PM, marek cervenka wrote:
> 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
> 
> 
> hi,
> thanks for new nice project https://ce.opensips.org/opensips-ims 
> <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 <http://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 <http:// 
> 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 <http://acc_cfg.id> = "sip:alice at ims.example.com 
> <mailto:sip%3Aalice at ims.example.com>"
> acc_cfg.reg_uri = "sip:ims.example.com <http://ims.example.com>"
> acc_cfg.proxy = ["sip:pcscf.ims.example.com <http:// 
> 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 
> <mailto:sip%3Aalice 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 
> <mailto:sip%3Aalice 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 
> <mailto:sip%3Abob at ims.example.com>", cb=CallCallback(), msg_data=msg_data)
> 
> # Wait for user input to terminate
> input("Press Enter to quit...")
> lib.destroy()
> ---
> 
> Marek
> 
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users




More information about the Users mailing list