Skip to content

Commit

Permalink
Merge pull request #212 from nickvsnetworking/sos_apn_gbr
Browse files Browse the repository at this point in the history
Sos apn gbr
  • Loading branch information
davidkneipp authored Oct 21, 2024
2 parents 35f4b4a + 289d2e8 commit eeb3967
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,22 @@ def Get_Serving_APNs(self, subscriber_id: int) -> dict:

return apnDict

def Get_Serving_APN_By_IP(self, subscriberIp):
Session = sessionmaker(bind = self.engine)
session = Session()

try:
result = session.query(SERVING_APN).filter_by(subscriber_routing=subscriberIp).first()
except Exception as E:
self.logTool.log(service='Database', level='debug', message=E, redisClient=self.redisMessaging)
self.safe_close(session)
raise ValueError(E)
result = result.__dict__
result.pop('_sa_instance_state')

self.safe_close(session)
return result

def Get_Charging_Rule(self, charging_rule_id):
self.logTool.log(service='Database', level='debug', message="Called Get_Charging_Rule() for charging_rule_id " + str(charging_rule_id), redisClient=self.redisMessaging)
Session = sessionmaker(bind = self.engine)
Expand Down
23 changes: 23 additions & 0 deletions lib/diameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3010,6 +3010,25 @@ def Answer_16777236_265(self, packet_vars, avps):
emergencySubscriber = True
except Exception as e:
emergencySubscriberData = None

"""
If we didn't get a service urn, check if the IP represents a bearer for a local subscriber.
"""
try:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Service URN: {serviceUrn}", redisClient=self.redisMessaging)
if not serviceUrn or serviceUrn == 'None' or serviceUrn == None:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Checking Get_Serving_APN_By_IP", redisClient=self.redisMessaging)
ipServingApn = self.database.Get_Serving_APN_By_IP(subscriberIp=ueIp)
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] IP Serving APN: {ipServingApn}", redisClient=self.redisMessaging)
ipApnName = ''
if ipServingApn:
ipApnName = self.database.Get_APN(apn_id=int(ipServingApn.get('apn', {})))
ipApnName = ipApnName.get('apn', None)
except Exception as e:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Exception: {traceback.format_exc()}", redisClient=self.redisMessaging)
ipApnName = ''

self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] IP APN Name: {ipApnName}", redisClient=self.redisMessaging)

if '@' in subscriptionId:
subscriberIdentifier = subscriptionId.split('@')[0]
Expand Down Expand Up @@ -3109,6 +3128,10 @@ def Answer_16777236_265(self, packet_vars, avps):
if 'sos' in str(serviceUrn).lower():
registeredEmergencySubscriber = True
apnId = (self.database.Get_APN_by_Name(apn="sos")).get('apn_id', None)
elif ipApnName:
if 'sos' in ipApnName.lower():
registeredEmergencySubscriber = True
apnId = (self.database.Get_APN_by_Name(apn="sos")).get('apn_id', None)
else:
apnId = (self.database.Get_APN_by_Name(apn="ims")).get('apn_id', None)
servingApn = self.database.Get_Serving_APN(subscriber_id=subscriberId, apn_id=apnId)
Expand Down

0 comments on commit eeb3967

Please sign in to comment.