Skip to content

Commit

Permalink
SQN resync via geored
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkneipp committed Nov 7, 2023
1 parent 0d9797f commit e2bb2d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Reduced verbosity of failing subscriber lookups to debug
- Added CORS headers: [Zarya/171](https://github.com/nickvsnetworking/pyhss/pull/171)
- Gx RAR now dynamically creates TFT up to 512k based on UE request.
- SQN Resync now propogates via Geored when enabled

### Fixed

Expand Down
20 changes: 15 additions & 5 deletions lib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,9 +1556,19 @@ def Get_APN_by_Name(self, apn):
self.safe_close(session)
return result

def Update_AuC(self, auc_id, sqn=1):
self.logTool.log(service='Database', level='debug', message="Updating AuC record for sub " + str(auc_id), redisClient=self.redisMessaging)
def Update_AuC(self, auc_id, sqn=1, propagate=True):
self.logTool.log(service='Database', level='debug', message=f"Updating AuC record for ID: {auc_id}", redisClient=self.redisMessaging)
self.logTool.log(service='Database', level='debug', message=self.UpdateObj(AUC, {'sqn': sqn}, auc_id, True), redisClient=self.redisMessaging)

if propagate:
if self.config['geored'].get('enabled', False) == True:
aucBody = {
"auc_id": auc_id,
"sqn": sqn,
}
self.handleGeored(aucBody)
self.logTool.log(service='Database', level='debug', message=f"Sent Geored update for AuC: {auc_id} with SQN {sqn}", redisClient=self.redisMessaging)

return

def Update_Serving_MME(self, imsi, serving_mme, serving_mme_realm=None, serving_mme_peer=None, serving_mme_timestamp=None, propagate=True):
Expand Down Expand Up @@ -1626,7 +1636,7 @@ def Update_Serving_MME(self, imsi, serving_mme, serving_mme_realm=None, serving_
result.serving_mme_timestamp = None
result.serving_mme_realm = None
result.serving_mme_peer = None
serving_mme_timestamp_string = result.serving_mme_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if serving_mme_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
serving_mme_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')

session.commit()
objectData = self.GetObj(SUBSCRIBER, result.subscriber_id)
Expand Down Expand Up @@ -1687,7 +1697,7 @@ def Update_Proxy_CSCF(self, imsi, proxy_cscf, pcscf_realm=None, pcscf_peer=None,
result.pcscf_realm = None
result.pcscf_peer = None
result.pcscf_active_session = None
pcscf_timestamp_string = result.pcscf_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if pcscf_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
pcscf_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')

session.commit()
objectData = self.GetObj(IMS_SUBSCRIBER, result.ims_subscriber_id)
Expand Down Expand Up @@ -1741,7 +1751,7 @@ def Update_Serving_CSCF(self, imsi, serving_cscf, scscf_realm=None, scscf_peer=N
result.scscf_timestamp = None
result.scscf_realm = None
result.scscf_peer = None
scscf_timestamp_string = result.scscf_timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') if scscf_timestamp is not None else datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')
scscf_timestamp_string = datetime.datetime.now(tz=timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')

session.commit()
objectData = self.GetObj(IMS_SUBSCRIBER, result.ims_subscriber_id)
Expand Down
17 changes: 15 additions & 2 deletions services/apiService.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@
'serving_pgw_timestamp' : "string",
'scscf' : "string",
'imei' : "string",
'match_response_code' : "string"
'match_response_code' : "string",
'auc_id': "int",
'sqn': "int",
}


Expand Down Expand Up @@ -1615,7 +1617,7 @@ def get(self, subscriber_routing):

@ns_geored.route('/')
class PyHSS_Geored(Resource):
@ns_geored.doc('Create ChargingRule Object')
@ns_geored.doc('Receive GeoRed data')
@ns_geored.expect(GeoRed_model)
@no_auth_required
def patch(self):
Expand Down Expand Up @@ -1708,6 +1710,17 @@ def patch(self):
"geored_host": request.remote_addr,
},
metricExpiry=60)
if 'auc_id' in json_data:
print("Updating AuC")
response_data.append(databaseClient.Update_AuC(json_data['auc_id'], json_data['sqn'], propagate=False))
redisMessaging.sendMetric(serviceName='api', metricName='prom_flask_http_geored_endpoints',
metricType='counter', metricAction='inc',
metricValue=1.0, metricHelp='Number of Geored Pushes Received',
metricLabels={
"endpoint": "SQN",
"geored_host": request.remote_addr,
},
metricExpiry=60)
return response_data, 200
except Exception as E:
print("Exception when updating: " + str(E))
Expand Down

0 comments on commit e2bb2d0

Please sign in to comment.