Skip to content

Commit 95e38ae

Browse files
authored
Merge branch 'herlesupreeth:master' into master
2 parents fa27994 + c81e4b3 commit 95e38ae

3 files changed

Lines changed: 92 additions & 41 deletions

File tree

pcscf/route/mo.cfg

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,25 @@ route[MO_indialog_aar_reply]
287287

288288
#!ifdef WITH_N5
289289
route[MO_N5_CALL_PCF_POLICY_AUTH] {
290+
# Send N5 PCF policy authorization only on replies.
291+
if (!is_reply()) {
292+
return;
293+
}
290294
$var(contact_uri) = $T_req($(ct{nameaddr.uri}));
291295
$var(ue_ip) = $(var(contact_uri){uri.host});
292-
$var(app_session) = $null;
296+
$var(app_session) = 0;
297+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
293298
if ($sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) != $null) {
294299
$var(app_session) = $sht(ue_ip_to_call_app_session_map=>$var(ue_ip));
295300
# Update again so that Hash table does not remove the entry upon session timer expiry.
296301
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $var(app_session);
302+
sht_lock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
297303
$sht(mo_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $var(app_session) + ";" + $var(ue_ip);
304+
sht_unlock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
298305
}
299-
# Send N5 PCF policy authorization only on replies.
300-
if (!is_reply() || !has_body("application/sdp")) {
306+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
307+
# Send N5 PCF policy authorization if SDP body is present.
308+
if (!has_body("application/sdp")) {
301309
return;
302310
}
303311
$var(req_sdp) = $T_req($sdp(body));
@@ -306,10 +314,10 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
306314
xlog("L_INFO","Rep SDP: $var(rep_sdp)\n");
307315

308316
$var(current_media) = "";
309-
$var(req_audio_rtp_port) = $null;
310-
$var(req_audio_rtcp_port) = $null;
311-
$var(req_video_rtp_port) = $null;
312-
$var(req_video_rtcp_port) = $null;
317+
$var(req_audio_rtp_port) = 0;
318+
$var(req_audio_rtcp_port) = 0;
319+
$var(req_video_rtp_port) = 0;
320+
$var(req_video_rtcp_port) = 0;
313321
$var(req_audio_rtcp_explicit) = 0;
314322
$var(req_video_rtcp_explicit) = 0;
315323
$var(audio_bw_as) = 0;
@@ -352,18 +360,18 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
352360
}
353361

354362
# Fallback: RTCP = RTP + 1 (RFC 3550 default) if no explicit a=rtcp.
355-
if ($var(req_audio_rtcp_explicit) != 1 && $var(req_audio_rtp_port) != $null) {
363+
if ($var(req_audio_rtcp_explicit) != 1 && $var(req_audio_rtp_port) > 0) {
356364
$var(req_audio_rtcp_port) = $(var(req_audio_rtp_port){s.int}) + 1;
357365
}
358-
if ($var(req_video_rtcp_explicit) != 1 && $var(req_video_rtp_port) != $null) {
366+
if ($var(req_video_rtcp_explicit) != 1 && $var(req_video_rtp_port) > 0) {
359367
$var(req_video_rtcp_port) = $(var(req_video_rtp_port){s.int}) + 1;
360368
}
361369

362370
$var(current_media) = "";
363-
$var(rep_audio_rtp_port) = $null;
364-
$var(rep_audio_rtcp_port) = $null;
365-
$var(rep_video_rtp_port) = $null;
366-
$var(rep_video_rtcp_port) = $null;
371+
$var(rep_audio_rtp_port) = 0;
372+
$var(rep_audio_rtcp_port) = 0;
373+
$var(rep_video_rtp_port) = 0;
374+
$var(rep_video_rtcp_port) = 0;
367375
$var(rep_audio_rtcp_explicit) = 0;
368376
$var(rep_video_rtcp_explicit) = 0;
369377
# Split SDP into lines and iterate.
@@ -403,10 +411,10 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
403411
}
404412

405413
# Fallback: RTCP = RTP + 1 (RFC 3550 default) if no explicit a=rtcp.
406-
if ($var(rep_audio_rtcp_explicit) != 1 && $var(rep_audio_rtp_port) != $null) {
414+
if ($var(rep_audio_rtcp_explicit) != 1 && $var(rep_audio_rtp_port) > 0) {
407415
$var(rep_audio_rtcp_port) = $(var(rep_audio_rtp_port){s.int}) + 1;
408416
}
409-
if ($var(rep_video_rtcp_explicit) != 1 && $var(rep_video_rtp_port) != $null) {
417+
if ($var(rep_video_rtcp_explicit) != 1 && $var(rep_video_rtp_port) > 0) {
410418
$var(rep_video_rtcp_port) = $(var(rep_video_rtp_port){s.int}) + 1;
411419
}
412420

@@ -415,12 +423,12 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
415423

416424
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Audio RTP: $var(req_audio_rtp_port), RTCP: $var(req_audio_rtcp_port)\n");
417425
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Audio RTP: $var(rep_audio_rtp_port), RTCP: $var(rep_audio_rtcp_port)\n");
418-
if ($var(req_video_rtp_port) != $null && $var(req_video_rtp_port) > 0) {
426+
if ($var(req_video_rtp_port) > 0) {
419427
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Video RTP: $var(req_video_rtp_port), RTCP: $var(req_video_rtcp_port)\n");
420428
} else {
421429
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Audio only (no video)\n");
422430
}
423-
if ($var(rep_video_rtp_port) != $null && $var(rep_video_rtp_port) > 0) {
431+
if ($var(rep_video_rtp_port) > 0) {
424432
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Video RTP: $var(rep_video_rtp_port), RTCP: $var(rep_video_rtcp_port)\n");
425433
} else {
426434
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Audio only (no video)\n");
@@ -481,7 +489,7 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
481489

482490
$var(video_media_component_body) = "";
483491
# NOTE: Only if both request and reply SDPs have video media, we consider video for policy authorization and include it in the media components. This is to handle the case where one side doesn't support video and hence doesn't include it in the SDP at all.
484-
if ($var(req_video_rtp_port) != $null && $var(req_video_rtp_port) > 0 && $var(rep_video_rtp_port) != $null && $var(rep_video_rtp_port) > 0) {
492+
if ($var(req_video_rtp_port) > 0 && $var(rep_video_rtp_port) > 0) {
485493
$var(video_media_component_body) = '"1": {
486494
"medCompN": 2,
487495
"qosReference": "qosVoNR",
@@ -572,7 +580,7 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
572580
xlog("L_DBG", "Constructed UE policy authorization body: $var(ue_policy_authorization_json_body)\n");
573581

574582
$var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z));
575-
if ($var(app_session) != $null) {
583+
if ($var(app_session) > 0) {
576584
xnotice("MT - N5 QoS Auth session already exists for UE with IP $var(ue_ip) so sending a patch request\n");
577585

578586
# Set HTTP2 request headers.
@@ -640,9 +648,13 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
640648
$var(app_session) = $(var(response_url){s.select,-1,/});
641649

642650
# Store the AppSession Id in the hash table associated with the IP address in the last Via SIP header.
651+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
643652
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $var(app_session);
653+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
644654
# Store the AppSession Id in the hash table associated with the dialog Call-Id.
655+
sht_lock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
645656
$sht(mo_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $var(app_session) + ";" + $var(ue_ip);
657+
sht_unlock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
646658
xlog("L_INFO", "Stored call AppSession Id for IP $var(ue_ip) is $var(app_session)\n");
647659
break;
648660
# Failure case.
@@ -664,11 +676,14 @@ route[MO_N5_CALL_PCF_POLICY_AUTH] {
664676

665677
route[MO_N5_CALL_PCF_POLICY_AUTH_DELETE] {
666678
# Retrieve the AppSession Id from the hash table.
679+
sht_lock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
667680
if ($sht(mo_call_id_to_call_app_session_and_ue_ip_map=>$ci) == $null) {
668681
xlog("L_WARN", "No call AppSession found for Call-Id $ci\n");
682+
sht_unlock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
669683
return;
670684
}
671685
$var(app_session_and_ue_ip) = $sht(mo_call_id_to_call_app_session_and_ue_ip_map=>$ci);
686+
sht_unlock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
672687
$var(app_session) = $(var(app_session_and_ue_ip){s.select,0,;});
673688
$var(ue_ip) = $(var(app_session_and_ue_ip){s.select,1,;});
674689

@@ -692,7 +707,11 @@ route[MO_N5_CALL_PCF_POLICY_AUTH_DELETE] {
692707
xlog("L_INFO", "Location Header: [$httprhdr(location)]\n");
693708

694709
# Clear hashtable content irrespective of the response from PCF/IMS as the call has ended.
710+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
695711
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $null;
712+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
713+
sht_lock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
696714
$sht(mo_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $null;
715+
sht_unlock("mo_call_id_to_call_app_session_and_ue_ip_map=>mo_call_id_to_call_app_session_and_ue_ip_map_lock");
697716
}
698717
#!endif

pcscf/route/mt.cfg

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,25 @@ route[MT_indialog_aar_reply]
202202

203203
#!ifdef WITH_N5
204204
route[MT_N5_CALL_PCF_POLICY_AUTH] {
205+
# Send N5 PCF policy authorization only on replies.
206+
if (!is_reply()) {
207+
return;
208+
}
205209
$var(contact_uri) = $(ct{nameaddr.uri});
206210
$var(ue_ip) = $(var(contact_uri){uri.host});
207-
$var(app_session) = $null;
211+
$var(app_session) = 0;
212+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
208213
if ($sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) != $null) {
209214
$var(app_session) = $sht(ue_ip_to_call_app_session_map=>$var(ue_ip));
210215
# Update again so that Hash table does not remove the entry upon session timer expiry.
211216
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $var(app_session);
217+
sht_lock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
212218
$sht(mt_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $var(app_session) + ";" + $var(ue_ip);
219+
sht_unlock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
213220
}
214-
# Send N5 PCF policy authorization only on replies.
215-
if (!is_reply() || !has_body("application/sdp")) {
221+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
222+
# Send N5 PCF policy authorization if SDP body is present.
223+
if (!has_body("application/sdp")) {
216224
return;
217225
}
218226
$var(req_sdp) = $T_req($sdp(body));
@@ -221,10 +229,10 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
221229
xlog("L_INFO","Rep SDP: $var(rep_sdp)\n");
222230

223231
$var(current_media) = "";
224-
$var(req_audio_rtp_port) = $null;
225-
$var(req_audio_rtcp_port) = $null;
226-
$var(req_video_rtp_port) = $null;
227-
$var(req_video_rtcp_port) = $null;
232+
$var(req_audio_rtp_port) = 0;
233+
$var(req_audio_rtcp_port) = 0;
234+
$var(req_video_rtp_port) = 0;
235+
$var(req_video_rtcp_port) = 0;
228236
$var(req_audio_rtcp_explicit) = 0;
229237
$var(req_video_rtcp_explicit) = 0;
230238
$var(audio_bw_as) = 0;
@@ -267,18 +275,18 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
267275
}
268276

269277
# Fallback: RTCP = RTP + 1 (RFC 3550 default) if no explicit a=rtcp.
270-
if ($var(req_audio_rtcp_explicit) != 1 && $var(req_audio_rtp_port) != $null) {
278+
if ($var(req_audio_rtcp_explicit) != 1 && $var(req_audio_rtp_port) > 0) {
271279
$var(req_audio_rtcp_port) = $(var(req_audio_rtp_port){s.int}) + 1;
272280
}
273-
if ($var(req_video_rtcp_explicit) != 1 && $var(req_video_rtp_port) != $null) {
281+
if ($var(req_video_rtcp_explicit) != 1 && $var(req_video_rtp_port) > 0) {
274282
$var(req_video_rtcp_port) = $(var(req_video_rtp_port){s.int}) + 1;
275283
}
276284

277285
$var(current_media) = "";
278-
$var(rep_audio_rtp_port) = $null;
279-
$var(rep_audio_rtcp_port) = $null;
280-
$var(rep_video_rtp_port) = $null;
281-
$var(rep_video_rtcp_port) = $null;
286+
$var(rep_audio_rtp_port) = 0;
287+
$var(rep_audio_rtcp_port) = 0;
288+
$var(rep_video_rtp_port) = 0;
289+
$var(rep_video_rtcp_port) = 0;
282290
$var(rep_audio_rtcp_explicit) = 0;
283291
$var(rep_video_rtcp_explicit) = 0;
284292
# Split SDP into lines and iterate.
@@ -318,10 +326,10 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
318326
}
319327

320328
# Fallback: RTCP = RTP + 1 (RFC 3550 default) if no explicit a=rtcp.
321-
if ($var(rep_audio_rtcp_explicit) != 1 && $var(rep_audio_rtp_port) != $null) {
329+
if ($var(rep_audio_rtcp_explicit) != 1 && $var(rep_audio_rtp_port) > 0) {
322330
$var(rep_audio_rtcp_port) = $(var(rep_audio_rtp_port){s.int}) + 1;
323331
}
324-
if ($var(rep_video_rtcp_explicit) != 1 && $var(rep_video_rtp_port) != $null) {
332+
if ($var(rep_video_rtcp_explicit) != 1 && $var(rep_video_rtp_port) > 0) {
325333
$var(rep_video_rtcp_port) = $(var(rep_video_rtp_port){s.int}) + 1;
326334
}
327335

@@ -330,12 +338,12 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
330338

331339
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Audio RTP: $var(req_audio_rtp_port), RTCP: $var(req_audio_rtcp_port)\n");
332340
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Audio RTP: $var(rep_audio_rtp_port), RTCP: $var(rep_audio_rtcp_port)\n");
333-
if ($var(req_video_rtp_port) != $null && $var(req_video_rtp_port) > 0) {
341+
if ($var(req_video_rtp_port) > 0) {
334342
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Video RTP: $var(req_video_rtp_port), RTCP: $var(req_video_rtcp_port)\n");
335343
} else {
336344
xlog("L_INFO", "Request SDP Parse Result from $var(req_sdp_ip) - Audio only (no video)\n");
337345
}
338-
if ($var(rep_video_rtp_port) != $null && $var(rep_video_rtp_port) > 0) {
346+
if ($var(rep_video_rtp_port) > 0) {
339347
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Video RTP: $var(rep_video_rtp_port), RTCP: $var(rep_video_rtcp_port)\n");
340348
} else {
341349
xlog("L_INFO", "Reply SDP Parse Result from $var(rep_sdp_ip) - Audio only (no video)\n");
@@ -395,7 +403,7 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
395403

396404
$var(video_media_component_body) = "";
397405
# NOTE: Only if both request and reply SDPs have video media, we consider video for policy authorization and include it in the media components. This is to handle the case where one side doesn't support video and hence doesn't include it in the SDP at all.
398-
if ($var(req_video_rtp_port) != $null && $var(req_video_rtp_port) > 0 && $var(rep_video_rtp_port) != $null && $var(rep_video_rtp_port) > 0) {
406+
if ($var(req_video_rtp_port) > 0 && $var(rep_video_rtp_port) > 0) {
399407
$var(video_media_component_body) = '"1": {
400408
"medCompN": 2,
401409
"qosReference": "qosVoNR",
@@ -485,7 +493,7 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
485493
xlog("L_DBG", "Constructed UE policy authorization body: $var(ue_policy_authorization_json_body)\n");
486494

487495
$var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z));
488-
if ($var(app_session) != $null) {
496+
if ($var(app_session) > 0) {
489497
xnotice("MT - N5 QoS Auth session already exists for UE with IP $var(ue_ip) so sending a patch request\n");
490498

491499
# Set HTTP2 request headers.
@@ -553,9 +561,13 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
553561
$var(app_session) = $(var(response_url){s.select,-1,/});
554562

555563
# Store the AppSession Id in the hash table associated with the IP address in the last Via SIP header.
564+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
556565
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $var(app_session);
566+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
557567
# Store the AppSession Id in the hash table associated with the dialog Call-Id.
568+
sht_lock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
558569
$sht(mt_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $var(app_session) + ";" + $var(ue_ip);
570+
sht_unlock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
559571
xlog("L_INFO", "Stored call AppSession Id for IP $var(ue_ip) is $var(app_session)\n");
560572
break;
561573
# Failure case.
@@ -577,11 +589,14 @@ route[MT_N5_CALL_PCF_POLICY_AUTH] {
577589

578590
route[MT_N5_CALL_PCF_POLICY_AUTH_DELETE] {
579591
# Retrieve the AppSession Id from the hash table.
592+
sht_lock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
580593
if ($sht(mt_call_id_to_call_app_session_and_ue_ip_map=>$ci) == $null) {
581594
xlog("L_WARN", "No call AppSession found for Call-Id $ci\n");
595+
sht_unlock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
582596
return;
583597
}
584598
$var(app_session_and_ue_ip) = $sht(mt_call_id_to_call_app_session_and_ue_ip_map=>$ci);
599+
sht_unlock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
585600
$var(app_session) = $(var(app_session_and_ue_ip){s.select,0,;});
586601
$var(ue_ip) = $(var(app_session_and_ue_ip){s.select,1,;});
587602

@@ -605,7 +620,11 @@ route[MT_N5_CALL_PCF_POLICY_AUTH_DELETE] {
605620
xlog("L_INFO", "Location Header: [$httprhdr(location)]\n");
606621

607622
# Clear hashtable content irrespective of the response from PCF/IMS as the call has ended.
623+
sht_lock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
608624
$sht(ue_ip_to_call_app_session_map=>$var(ue_ip)) = $null;
625+
sht_unlock("ue_ip_to_call_app_session_map=>ue_ip_to_call_app_session_map_lock");
626+
sht_lock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
609627
$sht(mt_call_id_to_call_app_session_and_ue_ip_map=>$ci) = $null;
628+
sht_unlock("mt_call_id_to_call_app_session_and_ue_ip_map=>mt_call_id_to_call_app_session_and_ue_ip_map_lock");
610629
}
611630
#!endif

pcscf/route/register.cfg

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,14 @@ route[N5_REG_PCF_POLICY_AUTH]
379379

380380
$var(time_now)=$_s($timef(%a, %d %b %Y %H:%M:%S %Z));
381381

382+
$var(app_session) = 0;
383+
sht_lock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
382384
if ($sht(ue_ip_to_reg_app_session_map=>$viaZ(host)) != $null) {
383-
xnotice("AppSession Id $sht(ue_ip_to_reg_app_session_map=>$viaZ(host)) for IP $viaZ(host) already exists so send a patch request\n");
385+
$var(app_session) = $sht(ue_ip_to_reg_app_session_map=>$viaZ(host));
386+
}
387+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
388+
if ($var(app_session) > 0) {
389+
xnotice("AppSession Id $var(app_session) for IP $viaZ(host) already exists so send a patch request\n");
384390

385391
# Set HTTP2 request headers.
386392
$var(headers) = "Content-Type: application/merge-patch+json\r\n";
@@ -391,8 +397,6 @@ route[N5_REG_PCF_POLICY_AUTH]
391397
$var(headers) = $var(headers) + "3gpp-sbi-discovery-service-names: npcf-policyauthorization\r\n";
392398
$var(headers) = $var(headers) + "3gpp-sbi-sender-timestamp: " + $var(time_now);
393399

394-
$var(app_session) = $sht(ue_ip_to_reg_app_session_map=>$viaZ(host));
395-
396400
http_client_request_v2pk("PATCH", "http://SCP_BIND_IP:SCP_BIND_PORT/npcf-policyauthorization/v1/app-sessions/$var(app_session)", "$var(ue_policy_authorization_json_body)", "$var(headers)", "$var(result)");
397401
switch ($rc) {
398402
# Success case.
@@ -403,7 +407,9 @@ route[N5_REG_PCF_POLICY_AUTH]
403407
xlog("L_INFO", "cURL Response: $curlerror(error)\n");
404408
xlog("L_INFO", "Location Header header: $httprhdr(location)\n");
405409
# Update again so that Hash table does not remove the entry upon timer expiry.
410+
sht_lock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
406411
$sht(ue_ip_to_reg_app_session_map=>$viaZ(host)) = $var(app_session);
412+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
407413
break;
408414
# Failure case.
409415
default:
@@ -444,7 +450,9 @@ route[N5_REG_PCF_POLICY_AUTH]
444450
$var(app_session) = $(var(response_url){s.select,-1,/});
445451

446452
# Store the AppSession Id in the hash table associated with the IP address in the last Via SIP header.
453+
sht_lock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
447454
$sht(ue_ip_to_reg_app_session_map=>$viaZ(host)) = $var(app_session);
455+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
448456
xlog("L_INFO", "Stored registration AppSession Id for IP $viaZ(host) is $var(app_session)\n");
449457
break;
450458
# Failure case.
@@ -470,11 +478,14 @@ route[N5_REG_PCF_POLICY_AUTH_DELETE]
470478
$var(ue_ip) = $T_req($via0(host));
471479
}
472480
# Retrieve the AppSession Id from the hash table.
481+
sht_lock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
473482
if ($sht(ue_ip_to_reg_app_session_map=>$var(ue_ip)) == $null) {
474483
xlog("L_WARN", "No AppSession found for UE with IP $var(ue_ip)\n");
484+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
475485
return;
476486
}
477487
$var(ue_appsess_dereg) = $sht(ue_ip_to_reg_app_session_map=>$var(ue_ip));
488+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
478489
xlog("L_INFO", "Terminating AppSession with Id $var(ue_appsess_dereg) for user with IP $var(ue_ip)\n");
479490

480491
# Set HTTP2 request headers.
@@ -497,7 +508,9 @@ route[N5_REG_PCF_POLICY_AUTH_DELETE]
497508
xlog("L_INFO", "Location Header: [$httprhdr(location)]\n");
498509

499510
# Clear hashtable content irrespective of the response from PCF/IMS as the UE has de-registered and the session context needs to be cleared locally.
511+
sht_lock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
500512
$sht(ue_ip_to_reg_app_session_map=>$var(ue_ip)) = $null;
513+
sht_unlock("ue_ip_to_reg_app_session_map=>ue_ip_to_reg_app_session_map_lock");
501514
}
502515

503516
#!endif

0 commit comments

Comments
 (0)