Skip to content

Commit

Permalink
incoming and outgoing communication barring support in UDA
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkneipp committed Aug 23, 2024
1 parent fa90ae3 commit 1c719f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions default_sh_user_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<Sh-IMS-Data>
<S-CSCFName>{{ Sh_template_vars['scscf'] }}</S-CSCFName>
<IMSUserState>{{ Sh_template_vars['imsUserState'] }}</IMSUserState>
<!-- The following 2 values are not 3gpp-standardised. Remove if your deployment requires 3gpp-compliant XML. -->
<InboundCommunicationBarred>{{ Sh_template_vars['inboundCommunicationBarred'] }}</InboundCommunicationBarred>
<OutboundCommunicationBarred>{{ Sh_template_vars['outboundCommunicationBarred'] }}</OutboundCommunicationBarred>
</Sh-IMS-Data>

</Sh-Data>
38 changes: 37 additions & 1 deletion lib/diameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import re
from baseModels import Peer, OutboundData
import pydantic_core
import xml.etree.ElementTree as ET

class Diameter:

Expand Down Expand Up @@ -338,7 +339,14 @@ def generate_diameter_packet(self, packet_version, packet_flags, packet_command_
except Exception as e:
self.logTool.log(service='HSS', level='error', message=f"[diameter.py] [generate_diameter_packet] Exception: {e}", redisClient=self.redisMessaging)


def get_sh_profile_rules(self, serviceName, xmlRoot, xmlNamespace):
service = xmlRoot.find(f'default:{serviceName}', xmlNamespace)
if service is not None:
active = service.get('active')
allow = service.find('.//default:allow', xmlNamespace)
allowValue = allow.text if allow is not None else None
return active, allowValue
return None, None

def roundUpToMultiple(self, n, multiple):
return ((n + multiple - 1) // multiple) * multiple
Expand Down Expand Up @@ -2772,6 +2780,7 @@ def Answer_16777217_306(self, packet_vars, avps):
msisdn = None
imsi = None
scscf = None
subscriberIsBarred = False
username = None
try:
user_identity_avp = self.get_avp_data(avps, 700)[0]
Expand Down Expand Up @@ -2853,9 +2862,36 @@ def Answer_16777217_306(self, packet_vars, avps):
#These variables are passed to the template for use
subscriber_details['mnc'] = self.MNC.zfill(3)
subscriber_details['mcc'] = self.MCC.zfill(3)
subscriberShProfile = subscriber_details.get('sh_profile', '')
if not subscriberShProfile:
subscriberShProfile = subscriber_details.get('xcap_profile', '')

subscriber_details['inboundCommunicationBarred'] = False
subscriber_details['outboundCommunicationBarred'] = False

try:
subscriberShXml = ET.fromstring(subscriberShProfile)
namespaces = {
'default': 'http://uri.etsi.org/ngn/params/xml/simservs/xcap',
'cp': 'urn:ietf:params:xml:ns:common-policy'
}
incomingCommunicationBarringRuleActive, incomingCommunicationBarringAllowed = self.get_sh_profile_rules('incoming-communication-barring')
outgoingCommunicationBarringRuleActive, outgoingCommunicationBarringAllowed = self.get_sh_profile_rules('outgoing-communication-barring')

if incomingCommunicationBarringRuleActive:
if not incomingCommunicationBarringAllowed:
subscriber_details['inboundCommunicationBarred'] = True

if outgoingCommunicationBarringRuleActive:
if not outgoingCommunicationBarringAllowed:
subscriber_details['outboundCommunicationBarred'] = True

except Exception as e:
self.logTool.log(service='HSS', level='debug', message="Unable to parse Sh Profile XML for subscriber: " + str(subscriber_details), redisClient=self.redisMessaging)

self.logTool.log(service='HSS', level='debug', message="Rendering template with values: " + str(subscriber_details), redisClient=self.redisMessaging)
xmlbody = template.render(Sh_template_vars=subscriber_details)

avp += self.generate_vendor_avp(702, "c0", 10415, str(binascii.hexlify(str.encode(xmlbody)),'ascii'))

avp += self.generate_avp(268, 40, "000007d1") #DIAMETER_SUCCESS
Expand Down

0 comments on commit 1c719f8

Please sign in to comment.