File size: 88,959 Bytes
258fb37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
/*
 * Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
 *
 * This file is part of Open5GS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "test-common.h"

static void issues_1431_func(abts_case *tc, void *data)
{
    int rv;
    ogs_socknode_t *s1ap;
    ogs_socknode_t *gtpu;
    ogs_pkbuf_t *emmbuf;
    ogs_pkbuf_t *esmbuf;
    ogs_pkbuf_t *sendbuf;
    ogs_pkbuf_t *recvbuf;
    ogs_s1ap_message_t message;

    ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
    test_ue_t *test_ue = NULL;
    test_sess_t *sess = NULL;
    test_bearer_t *bearer = NULL;

    uint32_t old_enb_ue_s1ap_id;
    uint64_t old_mme_ue_s1ap_id;
    uint32_t new_enb_ue_s1ap_id;
    uint64_t new_mme_ue_s1ap_id;

    bson_t *doc = NULL;

    /* Setup Test UE & Session Context */
    memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));

    mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
    mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
    mobile_identity_suci.routing_indicator1 = 0;
    mobile_identity_suci.routing_indicator2 = 0xf;
    mobile_identity_suci.routing_indicator3 = 0xf;
    mobile_identity_suci.routing_indicator4 = 0xf;
    mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
    mobile_identity_suci.home_network_pki_value = 0;

    test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
    ogs_assert(test_ue);

    test_ue->e_cgi.cell_id = 0x00003c01;
    test_ue->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
    test_ue->nas.value = OGS_NAS_ATTACH_TYPE_EPS_ATTACH;

    test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
    test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";

    sess = test_sess_add_by_apn(test_ue, "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);

    /* eNB connects to MME */
    s1ap = tests1ap_client(AF_INET);
    ABTS_PTR_NOTNULL(tc, s1ap);

    /* eNB connects to SGW */
    gtpu = test_gtpu_server(1, AF_INET);
    ABTS_PTR_NOTNULL(tc, gtpu);

    /* Send S1-Setup Reqeust */
    sendbuf = test_s1ap_build_s1_setup_request(
            S1AP_ENB_ID_PR_macroENB_ID, 0x54f64);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive S1-Setup Response */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(NULL, recvbuf);

    /********** Insert Subscriber in Database */
    doc = test_db_new_simple(test_ue);
    ABTS_PTR_NOTNULL(tc, doc);
    ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue->attach_request_param,
            0, sizeof(test_ue->attach_request_param));
    test_ue->attach_request_param.ue_usage_setting = 1;
    test_ue->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue, esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /*** Store eNB-UE-S1AP-ID */
    old_enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id;

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /*** Store MME-UE-S1AP-ID */
    old_mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id;

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send Security mode complete */
    test_ue->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send ESM Information Response */
    sess->esm_information_param.pco = 1;
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send UE Capability Info Indication */
    sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue, 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue, esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Wait for Modify Bearer Request/Response */
    ogs_msleep(100);

    /* Send PDN Connectivity Request */
    sess = test_sess_find_by_apn(test_ue, "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 2;

    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.apn = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, true, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive E-RABSetupRequest +
     * Activate default EPS bearer context request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);
    ABTS_INT_EQUAL(tc,
            S1AP_ProcedureCode_id_downlinkNASTransport,
            test_ue->s1ap_procedure_code);

    /* Just Delay */
    ogs_msleep(100);

    /* Send Attach Request - Integrity */
    sess = test_sess_find_by_apn(test_ue, "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 3;

    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue->attach_request_param,
            0, sizeof(test_ue->attach_request_param));
    test_ue->attach_request_param.guti = 1;
    test_ue->attach_request_param.last_visited_registered_tai = 1;
    test_ue->attach_request_param.ue_usage_setting = 1;
    test_ue->attach_request_param.old_guti_type = 1;
    test_ue->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue, esmbuf, true, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /*** Store eNB-UE-S1AP-ID */
    new_enb_ue_s1ap_id = test_ue->enb_ue_s1ap_id;

    /* Receive OLD UE Context Release Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /*** Store MME-UE-S1AP-ID */
    new_mme_ue_s1ap_id = test_ue->mme_ue_s1ap_id;

    /* Send OLD UE Context Release Complete */
    test_ue->enb_ue_s1ap_id = old_enb_ue_s1ap_id;
    test_ue->mme_ue_s1ap_id = old_mme_ue_s1ap_id;

    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Just Delay */
    ogs_msleep(100);

    /* Send ESM Information Response */
    test_ue->enb_ue_s1ap_id = new_enb_ue_s1ap_id;
    test_ue->mme_ue_s1ap_id = new_mme_ue_s1ap_id;

    sess->esm_information_param.pco = 0;
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue, 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue, esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue, emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send UE Context Release Request */
    sendbuf = test_s1ap_build_ue_context_release_request(test_ue,
            S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive UE Context Release Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send UE Context Release Complete */
    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    ogs_msleep(300);

    /********** Remove Subscriber in Database */
    ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));

    /* eNB disonncect from MME */
    testenb_s1ap_close(s1ap);

    /* eNB disonncect from SGW */
    test_gtpu_close(gtpu);

    test_ue_remove(test_ue);
}

/*
- v2.6.3 Analysis
05/03 13:01:08.318 1101136515 486875/209 12/322  Attach request
05/03 13:01:08.318 1101136515 486875/209 12/322  emm_state_initial_context_setup(): ENTRY
05/03 13:01:08.318 1101136515 486875/209 12/322  mme_bearer_find_or_add_by_message() [PTI:7, EBI:0]
05/03 13:01:08.318 1101136515 486875/209 12/322  esm_state_inactive(): ENTRY
05/03 13:01:08.318 1101136515 486875/209 12/322  PDN Connectivity request
05/03 13:01:08.318 1101136515 486875/209 12/322  ESM information request
05/03 13:01:08.331 1101133226 486874/881 582/1029  mme_bearer_find_or_add_by_message() [PTI:2, EBI:0]
05/03 13:01:08.331 1101133226 486874/881 582/1029  esm_state_inactive(): ENTRY
05/03 13:01:08.331 1101133226 486874/881 582/1029  PDN Connectivity request
05/03 13:01:08.331 1101133226 486874/881 582/1029  PDN connectivity reject(ims)
05/03 13:01:08.331 1101133226 486874/881 582/1029  esm_state_exception(): ENTRY
05/03 13:01:08.331 1101133226 486874/881 582/1029  [Removed] Number of MME-Sessions is now 28
05/03 13:01:08.335 1101136515 486875/209 12/322  mme_bearer_find_or_add_by_message() [PTI:7, EBI:0]
05/03 13:01:08.335 1101136515 486875/209 12/322  ESM information response
05/03 13:01:08.338 1101136515 486875/209 12/322  Attach accept
05/03 13:01:08.338 1101136515 486875/209 12/322  Activate default bearer context request
05/03 13:01:08.338 1101136515 486875/209 12/322  InitialContextSetupRequest
05/03 13:01:08.631 1101136515 486875/209 12/322  InitialContextSetupResponse
05/03 13:01:08.633 1101136515 486875/209 12/322  UECapabilityInfoIndication
05/03 13:01:08.636 1101136515 486875/209 12/322  emm_state_initial_context_setup(): MME_EVENT_EMM_MESSAGE
05/03 13:01:08.636 1101136515 486875/209 12/322  Attach complete
05/03 13:01:08.636 1101136515 486875/209 12/322  EMM information
05/03 13:01:08.636 1101136515 486875/209 12/322  mme_bearer_find_or_add_by_message() [PTI:0, EBI:5]
05/03 13:01:08.636 1101136515 486875/209 12/322  esm_state_inactive(): MME_EVENT_ESM_MESSAGE
05/03 13:01:08.636 1101136515 486875/209 12/322  Activate default EPS bearer context accept
05/03 13:01:08.636 1101136515 486875/209 12/322  esm_state_active(): ENTRY
05/03 13:01:08.671 1101136515 486875/209 12/322  mme_bearer_find_or_add_by_message() [PTI:8, EBI:0]
05/03 13:01:08.671 1101136515 486875/209 12/322  esm_state_inactive(): ENTRY
05/03 13:01:08.671 1101136515 486875/209 12/322  PDN Connectivity request
05/03 13:01:08.671 1101136515 486875/209 12/322  PDN connectivity reject(ims)
05/03 13:01:08.671 1101136515 486875/209 12/322  esm_state_exception(): ENTRY
05/03 13:01:08.671 1101136515 486875/209 12/322  [Removed] Number of MME-Sessions is now 28
05/03 13:02:09.026 1101136515 655305/195 798/839 Attach request
05/03 13:02:09.026 1101136515 655305/195 798/839 emm_state_initial_context_setup() : ENTRY
05/03 13:02:09.026 1101136515 655305/195 798/839 mme_bearer_find_or_add_by_message() [PTI:21, EBI:0]
05/03 13:02:09.026 1101136515 655305/195 798/839 esm_state_inactive(): ENTRY
05/03 13:02:09.026 1101136515 655305/195 798/839 PDN Connectivity request
05/03 13:02:09.026 1101136515 655305/195 798/839 ESM information request
05/03 13:02:09.042 1101136515 655305/195 798/839 ESM information response
05/03 13:02:09.046 1101136515 655305/195 798/839 Attach accept
05/03 13:02:09.046 1101136515 655305/195 798/839 Activate default bearer context request
05/03 13:02:09.046 1101136515 655305/195 798/839 InitialContextSetupRequest
05/03 13:02:09.289 1101136515 655305/195 798/839 Attach complete
05/03 13:02:09.290 1101136515 655305/195 798/839 mme_bearer_find_or_add_by_message() [PTI:0, EBI:5]
05/03 13:02:09.290 1101136515 655305/195 798/839 Activate default EPS bearer context accept
05/03 13:02:09.290 1101136515 655305/195 798/839 esm_state_active(): ENTRY
05/03 13:02:09.290 1101136515 655305/195 798/839 InitialContextSetupResponse
05/03 13:02:09.209 1101136515 655305/195 798/839 UECapabilityInfoIndication
05/03 13:02:17.442 1101136515 655305/195 798/839 Detach request
05/03 13:02:17.445 1101136515 655305/195 798/839 Detach accept
05/03 13:02:17.445 1101136515 655305/195 798/839 UEContextReleaseCommand
05/03 13:02:17.463 1101136515 655305/195 798/839 UEContextReleaseComplete
05/03 13:02:26.537 1101136519 486875/209 12/322  Detach request
05/03 13:02:26.540 1101136519 486875/209 12/322  Detach accept
05/03 13:02:26.540 1101136519 486875/209 12/322  UEContextReleaseCommand
05/03 13:02:26.542 1101136519 486875/209 12/322  UEContextReleaseComplete
05/03 13:02:27.706 1101136515 655308/176 798/17  Attach request
05/03 13:02:27.706 1101136515 655308/176 798/17  emm_state_initial_context_setup(): ENTRY
05/03 13:02:27.706 1101136515 655308/176 798/17  mme_bearer_find_or_add_by_message() [PTI:22, EBI:0]
05/03 13:02:27.706 1101136515 655308/176 798/17  esm_state_inactive(): ENTRY
05/03 13:02:27.706 1101136515 655308/176 798/17  PDN Connectivity request
05/03 13:02:27.706 1101136515 655308/176 798/17  ESM information request
05/03 13:02:27.918 1101136517 486880/200 995/841 UEContextReleaseRequest
05/03 13:02:27.918 1101136517 486880/200 995/841 UEContextReleaseCommand
05/03 13:02:27.921 1101136517 486880/200 995/841 UEContextReleaseComplete
05/03 13:02:27.936 1101122519 655307/192 314/424 UEContextReleaseRequest
05/03 13:02:27.936 1101122519 655307/192 314/424 UEContextReleaseCommand
05/03 13:02:29.249 1101122519 655307/192 314/424 Detach request
05/03 13:02:29.251 1101122519 655307/192 314/424 Detach accept
05/03 13:02:30.130 1101136512 486719/913 881/969 Implicit MME Detach
05/03 13:02:30.134 1101136512 486719/913 881/969 [MME] Purge-UE-Request
05/03 13:02:30.134 1101136512 486719/913 881/969 [MME] Purge-UE-Answer
05/03 13:02:30.740 1101226519 655307/192 314/424 UEContextReleaseComplete


05/03 13:02:30.756 1101136515 655308/176 798/17  mme_bearer_find_or_add_by_message() [PTI:22, EBI:0]
05/03 13:02:30.756 1101136515 655308/176 798/17  esm_state_inactive(): MME_EVENT_ESM_MESSAGE
05/03 13:02:30.756 1101136515 655308/176 798/17  ESM information response
05/03 13:02:30.756 1101136515 655308/176 798/0/0/47960/22915 Create Session Response
05/03 13:02:30.760 1101136515 655308/176 798/17  Attach accept
05/03 13:02:30.760 1101136515 655308/176 798/17  Activate default bearer context request
05/03 13:02:30.760 1101136515 655308/176 798/0/0/47960 InitialContextSetupRequest


05/03 13:02:32.118 1101136519 486882/214 12/656  InitialUEMessage(M_TMSI:0xc0000428)
05/03 13:02:32.118 1101136519 486882/214 12/656  Attach request
05/03 13:02:32.118 1101136519 486882/214 12/656  emm_state_initial_context_setup(): ENTRY
05/03 13:02:32.118 1101136519 486882/214 12/656  mme_bearer_find_or_add_by_message() [PTI:9, EBI:0]
05/03 13:02:32.118 1101136519 486882/214 12/656  esm_state_inactive(): ENTRY
05/03 13:02:32.118 1101136519 486882/214 12/656  PDN Connectivity request
05/03 13:02:32.118 1101136519 486882/214 12/656  ESM information request
05/03 13:02:32.135 1101136519 486882/214 12/656  mme_bearer_find_or_add_by_message() [PTI:9, EBI:0]
05/03 13:02:32.135 1101136519 486882/214 12/656  esm_state_inactive(): MME_EVENT_ESM_MESSAGE
05/03 13:02:32.135 1101136519 486882/214 12/656  ESM information response
05/03 13:02:32.135 1101136519 486882/214 12/0/0/26037/17607 Create Session Response
05/03 13:02:32.138 1101136519 486882/214 12/656  Attch accept
05/03 13:02:32.138 1101136519 486882/214 12/656  Activate default bearer context request
05/03 13:02:32.139 1101136519 486882/214 12/0/0/26037 InitialContextSetupRequest
05/03 13:02:32.433 1101136519 486882/214 12/656  InitialContextSetupResponse
05/03 13:02:32.434 1101136519 486882/214 12/656  UECapabilityInfoIndication
05/03 13:02:32.455 1101136519 486882/214 12/656  Attach complete
05/03 13:02:32.455 1101136519 486882/214 12/656  mme_bearer_find_or_add_by_message() [PTI:0, EBI:5]
05/03 13:02:32.455 1101136519 486882/214 12/656  esm_state_inactive(): MME_EVENT_ESM_MESSAGE
05/03 13:02:32.455 1101136519 486882/214 12/656/4154952/26037 Activate default EPS bearer context accept
05/03 13:02:32.455 1101136519 486882/214 12/656  esm_state_active(): ENTRY
05/03 13:02:32.511 1101136519 486882/214 12/656  mme_bearer_find_or_add_by_message() [PTI:10, EBI:0]
05/03 13:02:32.511 1101136519 486882/214 12/656  esm_state_inactive(): ENTRY
05/03 13:02:32.511 1101136519 486882/214 12/656  PDN Connectivity request
05/03 13:02:32.511 1101136519 486882/214 12/656  PDN Connectivity reject(ims)
05/03 13:02:32.511 1101136519 486882/214 12/656  esm_state_exception(): ENTRY
05/03 13:02:32.511 1101136519 486882/214 12/656  [Removed] Number of MME-Sessions is now 27


05/03 13:02:33.190 1101136515 655308/176 798/17/55919304/26037 InitialContextSetupResponse
05/03 13:02:33.191 1101136515 655308/176 798/17  UECapabilityInfoIndication
05/03 13:02:33.209 1101136515 655308/176 798/17  Attach complete
05/03 13:02:33.209 1101136515 655308/176 798/17  mme_bearer_find_or_add_by_message() [PTI:0, EBI:5]
05/03 13:02:33.209 1101136515 655308/176 798/17  esm_state_active(): MME_EVENT_ESM_MESSAGE
05/03 13:02:33.209 1101136515 655308/176 798/17  ERROR: Unknown message(type:194)


05/03 13:02:33.636 1101136519 486882/214 12/656  UECapabilityInfoIndication
05/03 13:02:33.713 1101136519 486882/214 12/656  E_RABModificationIndication
05/03 13:02:33.713 1101136519 486882/214 12/656  E-RABModificationConfirm
05/03 13:02:36.067 1101136515 655308/176 798/17  UECapabilityInfoIndication
05/03 13:02:36.067 1101136515 655308/176 798/17  Detach request
05/03 13:02:36.069 1101136519 486882/214 12/656  Detach accept
05/03 13:02:36.069 1101136519 486882/214 12/656  UEContextReleaseCommand
05/03 13:02:36.072 1101136519 486882/214 12/656  UEContextReleaseComplete
05/03 13:02:36.178 1101122519 655309/223 314/412 Attach request
05/03 13:02:36.178 1101122519 655309/223 314/412 emm_state_initial_context_setup(): ENTRY
05/03 13:02:36.178 1101122519 655309/223 314/412 mme_bearer_find_or_add_by_message() [PTI:15, EBI:0]
05/03 13:02:36.178 1101122519 655309/223 314/412 esm_state_inactive()
05/03 13:02:36.178 1101122519 655309/223 314/412 PDN Connectivity request
05/03 13:02:36.178 1101122519 655309/223 314/412 ESM information request
05/03 13:02:36.194 1101122519 655309/223 314/412 ESM information response
05/03 13:02:36.197 1101122519 655309/223 314/412 Attach accept
05/03 13:02:36.197 1101122519 655309/223 314/412 Activate default bearer context request
05/03 13:02:36.197 1101122519 655309/223 314/412 InitialContextSetupRequest
05/03 13:02:36.254 1101136515 655308/176 798/17  E_RABModificationIndication
05/03 13:02:36.254 1101136515 655308/176 798/17  ERROR: No Bearer [5]
05/03 13:02:36.408 1101136519 486883/907  Service request
05/03 13:02:36.408 1101136519 486883/907  ERROR: No Session Context
05/03 13:02:36.408 1101136519 486883/907  Service reject
05/03 13:02:36.408 1101136519 486883/907  UEContextReleaseCommand
05/03 13:02:36.410 1101136519 486883/907  UEContextReleaseComplete
05/03 13:02:36.410 1101122519 655309/223 314/412 [MME] Purge-UE-Request
05/03 13:02:36.413 1101122519 655309/223 314/412 [MME] Purge-UE-Answer
05/03 13:02:36.514 1101122519 655309/223 314/412 InitialContextSetupResponse
05/03 13:02:36.515 1101122519 655309/223 314/412 UECapabilityInfoIndication
05/03 13:02:36.545 1101122519 655309/223 314/412 Attach complete
05/03 13:02:36.545 1101122519 655309/223 314/412 mme_bearer_find_or_add_by_message() [PTI:0, EBI:5]
05/03 13:02:36.545 1101122519 655309/223 314/412 Activate default EPS bearer context accept
05/03 13:02:36.545 1101122519 655309/223 314/412 esm_state_active()
05/03 13:02:36.584 1101136519 486884/261 473/992 Attach request
05/03 13:02:36.587 1101136519 486884/261 473/992 Authentication request
05/03 13:02:36.639 1101136519 486884/261 473/992 Authentication response
05/03 13:02:36.639 1101136519 486884/261 473/992 Security mode command
05/03 13:02:36.656 1101136519 486884/261 473/992 Security mode complete
05/03 13:02:36.661 1101136519 486884/261 473/992 mme_bearer_find_or_add_by_message() [PTI:11, EBI:0]
05/03 13:02:36.661 1101136519 486884/261 473/992 esm_state_inactive()
05/03 13:02:36.661 1101136519 486884/261 473/992 PDN connection request
05/03 13:02:36.661 1101136519 486884/261 473/992 ESM information request
05/03 13:02:36.678 1101136519 486884/261 473/992 ESM information response
05/03 13:02:36.680 1101136519 486884/261 473/992 Attach accept
05/03 13:02:36.680 1101136519 486884/261 473/992 InitialContextSetupRequest
05/03 13:02:36.968 1101136519 486884/261 473/992 InitialContextSetupResponse
05/03 13:02:36.969 1101136519 486884/261 473/992 UECapabilityInfoIndication
05/03 13:02:36.991 1101136519 486884/261 473/992 Attach complete
05/03 13:02:36.991 1101136519 486884/261 473/992 Activate default EPS bearer context accept
05/03 13:02:36.991 1101136519 486884/261 473/992 esm_state_inactive()
05/03 13:02:37.253 1101136515 655308/176 798/17  UECapabilityInfoIndication
05/03 13:02:38.162 1101136519 486884/261 473/992 UECapabilityInfoIndication
05/03 13:02:38.232 1101136519 486884/261 473/992 E_RABModificationIndication
05/03 13:02:38.232 1101136519 486884/261 473/992 E-RABModificationConfirm
05/03 13:02:38.260 1101136515 655308/176 798/17  UEContextReleaseRequest
05/03 13:02:38.767 1101136514 486877/270 874/207 UEContextReleaseRequest
05/03 13:02:38.768 1101136514 486877/270 874/207 UEContextReleaseCommand
05/03 13:02:38.769 1101136514 486877/270 874/207 UEContextReleaseComplete
05/03 13:02:45.768 1101136515 655308/176 798/17  LOCAL  No Response. Give up! for step 1 type 170 peer
05/03 13:02:45.768 1101136515 655308/176 798/17  UEContextReleaseCommand
05/03 13:02:45.768 1101136515 655308/176 798/17  GTP Timeout : IMSI[1101136515] Message-Type[170]
05/03 13:02:45.996 1101136515 655310/123         Attach Request
05/03 13:02:45.966 1101136515 655310/123         FATAL
*/

#define NUM_OF_TEST_UE 3

static void issues_2287_v263_func(abts_case *tc, void *data)
{
    int rv, i;
    ogs_socknode_t *s1ap;
    ogs_socknode_t *gtpu;
    ogs_pkbuf_t *emmbuf;
    ogs_pkbuf_t *esmbuf;
    ogs_pkbuf_t *sendbuf;
    ogs_pkbuf_t *recvbuf;
    ogs_s1ap_message_t message;

    ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
    test_ue_t *test_ue[NUM_OF_TEST_UE];
    test_sess_t *sess = NULL;
    test_bearer_t *bearer = NULL;

    uint32_t enb_ue_s1ap_id;
    uint64_t mme_ue_s1ap_id;

    bson_t *doc = NULL;

    /* eNB connects to MME */
    s1ap = tests1ap_client(AF_INET);
    ABTS_PTR_NOTNULL(tc, s1ap);

    /* eNB connects to SGW */
    gtpu = test_gtpu_server(1, AF_INET);
    ABTS_PTR_NOTNULL(tc, gtpu);

    /* Send S1-Setup Reqeust */
    sendbuf = test_s1ap_build_s1_setup_request(
            S1AP_ENB_ID_PR_macroENB_ID, 0x54f64);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive S1-Setup Response */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(NULL, recvbuf);

    for (i = 0; i < NUM_OF_TEST_UE; i++) {
        const char *scheme_output[] = {
            "0000000001",
            "0000000002",
            "0000000003",
            "0000000004",
            "0000000005",
        };

        /* Setup Test UE & Session Context */
        memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));

        mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
        mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
        mobile_identity_suci.routing_indicator1 = 0;
        mobile_identity_suci.routing_indicator2 = 0xf;
        mobile_identity_suci.routing_indicator3 = 0xf;
        mobile_identity_suci.routing_indicator4 = 0xf;
        mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
        mobile_identity_suci.home_network_pki_value = 0;

        test_ue[i] = test_ue_add_by_suci(
                &mobile_identity_suci, scheme_output[i]);
        ogs_assert(test_ue[i]);

        test_ue[i]->e_cgi.cell_id = 0x54f6401;
        test_ue[i]->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
        test_ue[i]->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH;

        test_ue[i]->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
        test_ue[i]->opc_string = "e8ed289deba952e4283b54e88e6183ca";

        /********** Insert Subscriber in Database */
        doc = test_db_new_simple(test_ue[i]);
        ABTS_PTR_NOTNULL(tc, doc);
        ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue[i], doc));
    }

    /**********************************************************
     * First UE - INITIAL
     **********************************************************/
    test_ue[0]->enb_ue_s1ap_id = 100;

    sess = test_sess_add_by_apn(
            test_ue[0], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 21;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[0]->attach_request_param,
            0, sizeof(test_ue[0]->attach_request_param));
    test_ue[0]->attach_request_param.drx_parameter = 1;
    test_ue[0]->attach_request_param.ms_network_capability = 1;
    test_ue[0]->attach_request_param.tmsi_status = 1;
    test_ue[0]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[0]->attach_request_param.supported_codecs = 1;
    test_ue[0]->attach_request_param.ue_usage_setting = 1;
    test_ue[0]->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue[0], esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[0]->initial_ue_param, 0,
            sizeof(test_ue[0]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[0], emmbuf,
            S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Security mode complete */
    test_ue[0]->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send UE Capability Info Indication */
    sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[0]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[0], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Detach Request */
    emmbuf = testemm_build_detach_request(test_ue[0], 1, true, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive UE Context Release Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send UE Context Release Complete */
    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /**********************************************************
     * Second UE - INITIAL
     **********************************************************/
    test_ue[1]->enb_ue_s1ap_id = 200;

    sess = test_sess_add_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 8;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[1]->attach_request_param,
            0, sizeof(test_ue[1]->attach_request_param));
    test_ue[1]->attach_request_param.drx_parameter = 1;
    test_ue[1]->attach_request_param.ms_network_capability = 1;
    test_ue[1]->attach_request_param.tmsi_status = 1;
    test_ue[1]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[1]->attach_request_param.supported_codecs = 1;
    test_ue[1]->attach_request_param.ue_usage_setting = 1;
    test_ue[1]->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue[1], esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[1]->initial_ue_param, 0,
            sizeof(test_ue[1]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[1], emmbuf,
            S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Security mode complete */
    test_ue[1]->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send UE Capability Info Indication */
    sendbuf =
        tests1ap_build_ue_radio_capability_info_indication(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[1]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[1], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Detach Request */
    emmbuf = testemm_build_detach_request(test_ue[1], 1, true, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive UE Context Release Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send UE Context Release Complete */
    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /**********************************************************
     * First UE - GUTI
     **********************************************************/
    sess = test_sess_find_by_apn(
            test_ue[0], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    test_sess_remove(sess);

    sess = test_sess_add_by_apn(
            test_ue[0], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 22;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.epco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[0]->attach_request_param,
            0, sizeof(test_ue[0]->attach_request_param));
    test_ue[0]->attach_request_param.guti = 1;
    test_ue[0]->attach_request_param.last_visited_registered_tai = 1;
    test_ue[0]->attach_request_param.drx_parameter = 1;
    test_ue[0]->attach_request_param.ms_network_capability = 1;
    test_ue[0]->attach_request_param.location_area_identication = 1;
    test_ue[0]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[0]->attach_request_param.mobile_station_classmark_3 = 1;
    test_ue[0]->attach_request_param.supported_codecs = 1;
    test_ue[0]->attach_request_param.ue_usage_setting = 1;
    test_ue[0]->attach_request_param.old_guti_type = 1;
    emmbuf = testemm_build_attach_request(test_ue[0], esmbuf, true, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[0]->initial_ue_param, 0, sizeof(test_ue[0]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[0], emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);


    /**********************************************************
     * Second UE - GUTI
     **********************************************************/
    sess = test_sess_find_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    test_sess_remove(sess);

    sess = test_sess_add_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 9;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.epco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[1]->attach_request_param,
            0, sizeof(test_ue[1]->attach_request_param));
    test_ue[1]->attach_request_param.guti = 1;
    test_ue[1]->attach_request_param.last_visited_registered_tai = 1;
    test_ue[1]->attach_request_param.drx_parameter = 1;
    test_ue[1]->attach_request_param.ms_network_capability = 1;
    test_ue[1]->attach_request_param.location_area_identication = 1;
    test_ue[1]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[1]->attach_request_param.mobile_station_classmark_3 = 1;
    test_ue[1]->attach_request_param.supported_codecs = 1;
    test_ue[1]->attach_request_param.ue_usage_setting = 1;
    test_ue[1]->attach_request_param.old_guti_type = 1;
    emmbuf = testemm_build_attach_request(test_ue[1], esmbuf, true, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[1]->initial_ue_param, 0, sizeof(test_ue[1]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[1], emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send UE Capability Info Indication */
    sendbuf =
        tests1ap_build_ue_radio_capability_info_indication(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[1]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[1], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send PDN Connectivity Request */
    sess = test_sess_add_by_apn(test_ue[1], "ims", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 10;

    sess->pdn_connectivity_param.apn = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, true, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive PDN Connectivity reject */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    test_sess_remove(sess);

    /**********************************************************
     * First UE - GUTI Resume
     **********************************************************/

    sess = test_sess_add_by_apn(
            test_ue[0], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send UE Capability Info Indication */
    sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[0]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[0], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    ogs_msleep(300);

    for (i = 0; i < NUM_OF_TEST_UE; i++) {
        /********** Remove Subscriber in Database */
        ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue[i]));
    }

    /* eNB disonncect from MME */
    testenb_s1ap_close(s1ap);

    /* eNB disonncect from SGW */
    test_gtpu_close(gtpu);

    test_ue_remove_all();
}

/*
- v2.6.4 Analysis
05/29 15:02:25.141 1101122519 490/222 267/300/-974782142/30908 E_RABModificationIndication
05/29 15:02:25.141 1101122519 490/222 267/300/-974782142/30908 E-RABModificationConfirm


05/29 15:02:28.090 1101135526 485/106 44/54/41120/45321 E_RABModificationIndication
05/29 15:02:28.090 1101135526 485/106 44/54/41120/45321 E-RABModificationConfirm
05/29 15:02:28.360 1101136515 488/377 692/574/-1025113818/17073 E_RABModificationIndication
05/29 15:02:28.361 1101136515 488/377 692/574/-1025113818/17073 E-RABModificationConfirm
05/29 15:02:30.444 1101135526 485/106 44/54/41120/45321 UEContextReleaseRequest
05/29 15:02:30.445 1101135526 485/106 44/54/41120/45321 UEContextReleaseCommand
05/29 15:02:30.445 1101135526 485/106 44/54/41120/45321 Downlink Data Notification
05/29 15:02:30.445 1101135526 485/106 44/54/41120/45321 [1101135526] Clear Paging Info
05/29 15:02:30.445 1101135526 485/106 44/54/41120/45321 Downlink Data Notification Ackknowledge
05/29 15:02:30.476 1101135526 485/106 44/54/41120/45321 UEContextReleaseComplete
05/29 15:02:31.791 1101135526 491/826 44/54/-1053359805/45321 InitialUEMessage
05/29 15:02:31.791 1101135526 491/826 44/54/-1053359805/45321 Tracking area update request
05/29 15:02:31.792 1101135526 491/826 44/54/-1053359805/45321 Tracking area update accept
05/29 15:02:31.792 1101135526 491/826 44/54/-1053359805/45321 UEContextReleaseCommand
05/29 15:02:31.793 1101135526 491/826 44/54/-1053359805/45321 UEContextReleaseComplete
05/29 15:02:32.129 1101135526 492/65  44/54/41672/45321 InitialUEMessage
05/29 15:02:32.129 1101135526 492/65  44/54/41672/45321 Service request
05/29 15:02:32.129 1101135526 492/65  44/54/41672/45321 InitialContextSetupRequest
05/29 15:02:32.191 1101135526 492/65  44/54/41672/45321 InitialContextSetupResponse
05/29 15:02:32.656 1101135526 492/65  44/54/-1053359805/45321 E_RABModificationIndication
05/29 15:02:32.657 1101135526 492/65  44/54/-1053359805/45321 E-RABModificationConfirm
05/29 15:02:33.530 1101135526 492/65  44/54/41672/45321 E_RABModificationIndication
05/29 15:02:33.531 1101135526 492/65  44/54/41672/45321 E-RABModificationConfirm
05/29 15:02:35.889 1101135526 492/65  44/54/41672/45321 UEContextReleaseRequest
05/29 15:02:35.890 1101135526 492/65  44/54/41672/45321 UEContextReleaseCommand
05/29 15:02:35.890 1101135526 492/65  44/54/41672/45321 Downlink Data Notification
05/29 15:02:35.890 1101135526 492/65  44/54/41672/45321 [1101135526] Clear Paging Info
05/29 15:02:35.890 1101135526 492/65  44/54/41672/45321 Downlink Data Notification Ackknowledge
05/29 15:02:35.891 1101135526 492/65  44/54/41672/45321 UEContextReleaseComplete
05/29 15:02:40.311 1101135526 493/969 44/54/41984/45321 InitialUEMessage
05/29 15:02:40.311 1101135526 493/969 44/54/41984/45321 Service request
05/29 15:02:40.311 1101135526 493/969 44/54/41984/45321 InitialContextSetupRequest
05/29 15:02:40.375 1101135526 493/969 44/54/41984/45321 InitialContextSetupResponse
05/29 15:02:42.402 1101135526 493/969 44/54/41984/45321 UEContextReleaseRequest
05/29 15:02:42.403 1101135526 493/969 44/54/41984/45321 UEContextReleaseCommand
05/29 15:02:42.403 1101135526 493/969 44/54/41984/45321 Downlink Data Notification
05/29 15:02:42.403 1101135526 493/969 44/54/41984/45321 [1101135526] Clear Paging Info
05/29 15:02:42.403 1101135526 493/969 44/54/41984/45321 Downlink Data Notification Ackknowledge
05/29 15:02:42.511 1101135526 494/123 44/54/41984/45321 InitialUEMessage
05/29 15:02:42.511 1101135526 493/969 44/54/41984/45321 UEContextReleaseCommand
05/29 15:02:42.512 1101135526 494/123 44/54/41984/45321 Tracking area update request
05/29 15:02:42.512 1101135526 494/123 44/54/41984/45321 Tracking area update accept
05/29 15:02:42.512 1101135526 494/123 44/54/41984/45321 UEContextReleaseCommand
05/29 15:02:43.412 1101135526 493/969 44/54/41984/45321 UEContextReleaseComplete
05/29 15:02:43.412 1101135526 494/123 44/54/41984/45321 UEContextReleaseComplete
05/29 15:02:43.586 1101135526 495/85  44/54/42064/45321 InitialUEMessage
05/29 15:02:43.586 1101135526 495/85  44/54/42064/45321 Servie request
05/29 15:02:43.586 1101135526 495/85  44/54/42064/45321 InitialContextSetupRequest
05/29 15:02:43.671 1101135526 495/85  44/54/42064/45321 InitialContextSetupResponse
05/29 15:02:44.644 1101135526 495/85  44/54/-991887070/45321 E_RABModificationIndication
05/29 15:02:44.645 1101135526 495/85  44/54/-991887070/45321 E-RABModificationConfirm
05/29 15:02:45.422 1101136514 613657/812 625/399 UEContextReleaseRequest
05/29 15:02:45.423 1101136514 613657/812 625/399 UEContextReleaseCommand
05/29 15:02:45.424 1101136514 613657/812 625/399 UEContextReleaseComplete
05/29 15:02:46.659 1101135526 495/85  44/54/-991887070/45321 UEContextReleaseRequest
05/29 15:02:46.660 1101135526 495/85  44/54/-991887070/45321 UEContextReleaseCommand
05/29 15:02:46.660 1101135526 495/85  44/54/-991887070/45321 Downlink Data Notification
05/29 15:02:46.660 1101135526 495/85  44/54/-991887070/45321 [1101135526] Clear Paging Info
05/29 15:02:46.660 1101135526 495/85  44/54/-991887070/45321 Downlink Data Notification Ackknowledge
05/29 15:02:46.668 1101135526 495/85  44/54/-991887070/45321 UEContextReleaseComplete
05/29 15:02:46.668 1101135526 496/913 44/54/42104/45321 InitialUEMessage
05/29 15:02:48.146 1101135526 496/913 44/54/42104/45321 Servie request
05/29 15:02:48.146 1101135526 496/913 44/54/42104/45321 InitialContextSetupRequest
05/29 15:02:48.231 1101135526 496/913 44/54/42104/45321 InitialContextSetupResponse
05/29 15:02:48.788 1101135526 496/913 44/54/-991821534/45321 E_RABModificationIndication
05/29 15:02:48.789 1101135526 496/913 44/54/-991821534/45321 E-RABModificationConfirm

05/29 15:02:49.067 1101133203 613658/898 64/808 InitialUEMessage
05/29 15:02:49.067 1101133203 613658/898 64/808 Attach Request
05/29 15:02:49.067 1101133203 613658/898 64/808 Delete Session Request
05/29 15:02:49.071 1101133203 613658/898 64/808 Delete Session Response
05/29 15:02:49.071 1101133203 613658/898 64/808 INFO: Removed Session: UE IMSI:[1101133203] APN:[internet]
05/29 15:02:49.073 1101133203 613658/898 64/0 Authentication request
05/29 15:02:49.127 1101133203 613658/898 64/0 Authentication response
05/29 15:02:49.127 1101133203 613658/898 64/0 Security mode command
05/29 15:02:49.144 1101133203 613658/898 64/0 Security mode complete
05/29 15:02:49.149 1101133203 613658/898 64/0 mme_bearer_find_or_add_by_message() : ESM message type:208, PTI:1, EBI:0
05/29 15:02:49.149 1101133203 613658/898 64/0 esm_state_inactive(): ENTRY
05/29 15:02:49.149 1101133203 613658/898 64/0 [Added] Number of MME-Sessions is now 28
05/29 15:02:49.149 1101133203 613658/898 64/0 PDN Connectivity request
05/29 15:02:49.149 1101133203 613658/898 64/0 ESM information request
05/29 15:02:49.165 1101133203 613658/898 64/0 mme_bearer_find_or_add_by_message() : ESM message type:218, PTI:1, EBI:0
05/29 15:02:49.165 1101133203 613658/898 64/0/0/26394 esm_state_inactive(): ENTRY
05/29 15:02:49.165 1101133203 613658/898 64/0/0/26394 ESM information response
05/29 15:02:49.165 1101133203 613658/898 64/0/0/26394 Create Session Request
05/29 15:02:49.170 1101133203 613658/898 64/845/0/26394/60543 Create Session Response
05/29 15:02:49.170 1101133203 613658/898 64/845/0/26394 Attach accept
05/29 15:02:49.170 1101133203 613658/898 64/845/0/26394 InitialContextSetupRequest
05/29 15:02:49.538 1101133203 613658/898 64/845/0/26394 InitialContextSetupResponse
05/29 15:02:49.539 1101133203 613658/898 64/845/0/26394 UECapabilityInfoIndication
05/29 15:02:49.577 1101133203 613658/898 64/845/0/26394 Attach complete
05/29 15:02:49.577 1101133203 613658/898 64/845/0/26394 EMM information
05/29 15:02:49.577 1101133203 613658/898 64/845/0/26394 mme_bearer_find_or_add_by_message() : ESM message type:194, PTI:0, EBI:5
05/29 15:02:49.577 1101133203 613658/898 64/845/0/26394 esm_state_inactive(): MME_EVENT_ESM_MESSAGE
05/29 15:02:49.577 1101133203 613658/898 64/845/52365352/26394 Activate default EPS bearer context accept
05/29 15:02:49.577 1101133203 613658/898 64/845/52365352/26394 esm_state_active(): ENTRY
05/29 15:02:50.840 1101133203 613658/898 64/845/52365352/26394 UECapabilityInfoIndication

05/29 15:02:50.886 1101135526 496/913 44/54/42104/45321 E_RABModificationIndication
05/29 15:02:50.887 1101135526 496/913 44/54/42104/45321 E-RABModificationConfirm

05/29 15:02:50.904 1101133203 613658/898 64/845/-1069940446/26394 E_RABModificationIndication
05/29 15:02:50.905 1101133203 613658/898 64/845/-1069940446/26394 E-RABModificationConfirm

05/29 15:02:51.402 1101135526 496/913 44/54/-1053294269/45321 E_RABModificationIndication
05/29 15:02:51.403 1101135526 496/913 44/54/-1053294269/45321 E-RABModificationConfirm

05/29 15:02:52.260 1101122519 490/222 267/300/41592/26394 E_RABModificationIndication
05/29 15:02:52.260 1101122519 490/222 267/300/41592/26394 E-RABModificationConfirm


05/29 15:02:59.275 1101133203 613658/898 64/845  UEContextReleaseRequest
05/29 15:02:59.275 1101133203 613658/898 64/845  UEContextReleaseCommand
05/29 15:02:59.277 1101133203 613658/898 64/845  UEContextReleaseComplete
05/29 15:03:26.951 1101122519 501/104    InitialUEMessage
05/29 15:03:26.951 1101122519 490/222    UEContextReleaseCommand
05/29 15:03:26.951 1101122519 501/104        ///26394 Service request
05/29 15:03:26.951 1101122519 501/104        ///26394 InitialContextSetupRequest
05/29 15:03:31.956 1101122519 502/32     267/300 InitialUEMessage
05/29 15:03:31.956 1101122519 501/104    UEContextReleaseCommand
05/29 15:03:31.956 1101122519 502/32     267/300 Service request
05/29 15:03:31.956 1101122519 502/32     267/300//26394 InitialContextSetupRequest
05/29 15:03:34.128 1101136523 613659/44  781/369 InitialContextSetupResponse
05/29 15:03:34.222 1101136523 613659/44  781/369 Attach complete
05/29 15:03:34.223 1101136523 613659/44  781/369 mme_bearer_find_or_add_by_message() : ESM message type:194, PTI:0, EBI:5
05/29 15:03:34.223 1101136523 613659/44  781/369 esm_state_inactive()
05/29 15:03:34.223 1101136523 613659/44  781/369 Activate default EPS bearer context accept
05/29 15:03:34.257 1101136523 613659/44  781/369 PDN Connectivity request
05/29 15:03:34.257 1101136523 613659/44  781/369 PDN Connectivity reject(ims)
05/29 15:03:34.257 1101136523 613659/44  781/369 esm_state_inactive(): EXIT
05/29 15:03:34.257 1101136523 613659/44  781/369 esm_state_exception(): ENTRY
05/29 15:03:34.257 1101136523 613659/44  781/369 Removed Session: UE IMSI:[1101136523] APN:[Unknown]
05/29 15:03:34.257 1101136523 613659/44  781/369 esm_state_exception(): EXIT
05/29 15:03:34.373 1101135526 500/620    44/54   UEContextReleaseComplete
05/29 15:03:34.423 1101122519 502/32     267/300/42616/26394 InitialContextSetupResponse
05/29 15:03:34.896 1101122519 502/32     267/300/-991690462/26394 E_RABModificationIndication
05/29 15:03:34.897 1101122519 502/32     267/300/-991690462/26394 E-RABModificationConfirm
05/29 15:03:35.078 1101135526 503/123    44/54   Service request
05/29 15:03:35.078 1101135526 503/123    44/54   InitialContextSetupRequest
05/29 15:03:35.123 1101135526 503/123    44/54   InitialContextSetupResponse
05/29 15:03:35.222 1101133205 613635/84  164/377 UEContextReleaseRequest
05/29 15:03:35.223 1101133205 613635/84  164/377 UEContextReleaseCommand
05/29 15:03:35.225 1101133205 613635/84  164/377 UEContextReleaseCommplete
05/29 15:03:34.421 1101136523 613659/44  781/369 UECapabilityInfoIndication
05/29 15:03:34.498 1101136523 613659/44  781/369 E_RABModificationIndication
05/29 15:03:34.499 1101136523 613659/44  781/369 E-RABModificationConfirm
05/29 15:03:35.619 1101135526 503/123    44/54   E_RABModificationIndication
05/29 15:03:35.619 1101135526 503/123    44/54   E-RABModificationConfirm
05/29 15:03:36.088 1101122519 501/104    InitialContextSetupFailure
05/29 15:03:36.088 1101122519 501/104    UEContextReleaseCommand
05/29 15:03:36.088 1101122519 501/104    UEContextReleaseComplete
05/29 15:03:36.328 1101133205 613660/844 164/377 Service request
05/29 15:03:36.328 1101133205 613660/844 164/377 InitialContextSetupRequest
05/29 15:03:36.388 1101133205 613660/844 164/377/52365432/22946 InitialContextSetupResponse
05/29 15:03:37.618 1101133205 613660/844 164/377/-942800606/22946 E_RABModificationIndication
05/29 15:03:37.618 1101133205 613660/844 164/377/-942800606/22946 E-RABModificationConfirm
05/29 15:04:26.776 1101122519 502/32     267/300/-991559390/26394 E_RABModificationIndication
05/29 15:04:26.777 1101122519 502/32     267/300/-991559390/26394 E-RABModificationConfirm
05/29 15:03:37.618 1101133205 613660/844 164/377/-942800606/22946 E-RABModificationConfirm
05/29 15:04:31.533 1101133205 613664/975 164/377 Servie request
05/29 15:04:31.533 1101133205 613664/975 164/0/0/22946 InitialContextSetupRequest
05/29 15:04:31.586 1101133205 613664/975 164/377 Downlink Data Notification
05/29 15:04:31.586 1101133205 613664/975 164/377 [1101133205] Clear Paging Info
05/29 15:04:31.586 1101133205 613664/975 164/377 Downlink Data Notification Ackknowledge
05/29 15:04:31.587 1101133205 613664/975 164/377/52365864/22946 InitialContextSetupResponse
05/29 15:04:34.042 1101136514 613665/870 625/870 Servie request
05/29 15:04:34.042 1101136514 613665/870 625/870 InitialContextSetupRequest
05/29 15:04:34.099 1101136514 613665/870 625/870 mme_bearer_find_or_add_by_message() : ESM message type:208, PTI:89, EBI:0
05/29 15:04:34.099 1101136514 613665/870 625/870 esm_state_inactive(): ENTRY
05/29 15:04:34.099 1101136514 613665/870 625/870 [Added] Number of MME-Sessions is now 29 (../src/mme/mme-context.c:4049)
05/29 15:04:34.099 1101136514 613665/870 625/870 PDN Connectivity request
05/29 15:04:34.099 1101136514 613665/870 625/870 PDN Connectivity reject(ims)
05/29 15:04:34.099 1101136514 613665/870 625/870 Removed Session: UE IMSI:[1101136514] APN:[Unknown]
05/29 15:04:34.099 1101136514 613665/870 625/870 InitialContextSetupResponse
05/29 15:04:45.037 1101136515 506/91     692/546 E_RABModificationIndication
05/29 15:04:45.037 1101136515 506/91     692/546 E-RABModificationConfirm
05/29 15:04:48.070 1101122519 502/32     267/300 Detach request
05/29 15:04:48.073 1101133023 613658/898 64/845  ERROR: S1 context has already been removed
05/29 15:04:48.073 1101133023 613658/898 64/845  ERROR: mme_s11_handle_delete_session_response: Expectation `r == OGS_OK' failed.
05/29 15:04:48.073 1101133023 613658/898 64/845  Removed Session: UE IMSI:[1101133203] APN:[internet]
05/29 15:04:48.073 1101133023 613658/898 64/845  esm_stae_active(): EXIT
05/29 15:04:48.474 1101136515 506/91     692/546 E_RABModificationIndication
05/29 15:04:48.475 1101136515 506/91     692/546 E-RABModificationConfirm
05/29 15:04:53.029 1101136515 506/91     692/546 E_RABModificationIndication
05/29 15:04:53.030 1101136515 506/91     692/546 E-RABModificationConfirm
05/29 15:04:53.278 1101135526 505/150    44/54   E_RABModificationIndication
05/29 15:04:53.279 1101135526 505/150    44/54   E-RABModificationConfirm
05/29 15:04:53.933 1101122519 502/32     267/300 E_RABModificationIndication
05/29 15:04:53.933 1101122519 502/32     267/300 ERROR: No Bearer [5]
05/29 15:04:53.933 1101122519 502/32     267/300 ErrorIndication
05/29 15:04:53.990 1101135526 505/150    44/54   E_RABModificationIndication
05/29 15:04:53.991 1101135526 505/150    44/54   E-RABModificationConfirm
05/29 15:04:55.146 1101122519 502/32     267/300 Attach request
05/29 15:04:55.146 1101133023 613658/898 64/845  Removed Session: UE IMSI:[1101133203] APN:[internet]
05/29 15:04:55.146 1101122519 502/32     267/300 emm_state_initial_context_setup(): ENTRY
05/29 15:04:55.146 1101122519 502/32     267/300 mme_bearer_find_or_add_by_message() : ESM message type:208, PTI:16, EBI:0
05/29 15:04:55.147 1101122519 502/32     267/300 ERROR: No Bearer(1) : ESM message type:208, PTI:16, EBI:0
*/

static void issues_2287_v264_func(abts_case *tc, void *data)
{
    int rv, i;
    ogs_socknode_t *s1ap;
    ogs_socknode_t *gtpu;
    ogs_pkbuf_t *emmbuf;
    ogs_pkbuf_t *esmbuf;
    ogs_pkbuf_t *sendbuf;
    ogs_pkbuf_t *recvbuf;
    ogs_s1ap_message_t message;

    ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
    test_ue_t *test_ue[NUM_OF_TEST_UE];
    test_sess_t *sess = NULL;
    test_bearer_t *bearer = NULL;

    uint32_t enb_ue_s1ap_id;
    uint64_t mme_ue_s1ap_id;

    bson_t *doc = NULL;

    /* eNB connects to MME */
    s1ap = tests1ap_client(AF_INET);
    ABTS_PTR_NOTNULL(tc, s1ap);

    /* eNB connects to SGW */
    gtpu = test_gtpu_server(1, AF_INET);
    ABTS_PTR_NOTNULL(tc, gtpu);

    /* Send S1-Setup Reqeust */
    sendbuf = test_s1ap_build_s1_setup_request(
            S1AP_ENB_ID_PR_macroENB_ID, 0x54f64);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive S1-Setup Response */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(NULL, recvbuf);

    for (i = 0; i < NUM_OF_TEST_UE; i++) {
        const char *scheme_output[] = {
            "0000000001",
            "0000000002",
            "0000000003",
            "0000000004",
            "0000000005",
        };

        /* Setup Test UE & Session Context */
        memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));

        mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
        mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
        mobile_identity_suci.routing_indicator1 = 0;
        mobile_identity_suci.routing_indicator2 = 0xf;
        mobile_identity_suci.routing_indicator3 = 0xf;
        mobile_identity_suci.routing_indicator4 = 0xf;
        mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
        mobile_identity_suci.home_network_pki_value = 0;

        test_ue[i] = test_ue_add_by_suci(
                &mobile_identity_suci, scheme_output[i]);
        ogs_assert(test_ue[i]);

        test_ue[i]->e_cgi.cell_id = 0x54f6401;
        test_ue[i]->nas.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE;
        test_ue[i]->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH;

        test_ue[i]->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
        test_ue[i]->opc_string = "e8ed289deba952e4283b54e88e6183ca";

        /********** Insert Subscriber in Database */
        doc = test_db_new_simple(test_ue[i]);
        ABTS_PTR_NOTNULL(tc, doc);
        ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue[i], doc));
    }

    /**********************************************************
     * Second UE - INITIAL
     **********************************************************/
    test_ue[1]->enb_ue_s1ap_id = 200;

    sess = test_sess_add_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 8;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[1]->attach_request_param,
            0, sizeof(test_ue[1]->attach_request_param));
    test_ue[1]->attach_request_param.drx_parameter = 1;
    test_ue[1]->attach_request_param.ms_network_capability = 1;
    test_ue[1]->attach_request_param.tmsi_status = 1;
    test_ue[1]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[1]->attach_request_param.supported_codecs = 1;
    test_ue[1]->attach_request_param.ue_usage_setting = 1;
    test_ue[1]->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue[1], esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[1]->initial_ue_param, 0,
            sizeof(test_ue[1]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[1], emmbuf,
            S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Security mode complete */
    test_ue[1]->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send UE Capability Info Indication */
    sendbuf =
        tests1ap_build_ue_radio_capability_info_indication(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[1]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[1], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send UE Context Release Request */
    sendbuf = test_s1ap_build_ue_context_release_request(test_ue[1],
            S1AP_Cause_PR_radioNetwork, S1AP_CauseRadioNetwork_user_inactivity);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive UE Context Release Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send UE Context Release Complete */
    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /**********************************************************
     * First UE - INITIAL
     **********************************************************/
    test_ue[0]->enb_ue_s1ap_id = 100;

    sess = test_sess_add_by_apn(
            test_ue[0], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 21;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[0]->attach_request_param,
            0, sizeof(test_ue[0]->attach_request_param));
    test_ue[0]->attach_request_param.drx_parameter = 1;
    test_ue[0]->attach_request_param.ms_network_capability = 1;
    test_ue[0]->attach_request_param.tmsi_status = 1;
    test_ue[0]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[0]->attach_request_param.supported_codecs = 1;
    test_ue[0]->attach_request_param.ue_usage_setting = 1;
    test_ue[0]->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue[0], esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[0]->initial_ue_param, 0,
            sizeof(test_ue[0]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[0], emmbuf,
            S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Security mode complete */
    test_ue[0]->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send UE Capability Info Indication */
    sendbuf = tests1ap_build_ue_radio_capability_info_indication(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[0]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[0], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[0], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[0], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /* Send E-RABModificationIndication */
    ogs_list_for_each(&sess->bearer_list, bearer)
        bearer->enb_s1u_teid++;

    sendbuf = test_s1ap_build_e_rab_modification_indication(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive E-RABModificationConfirm */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    /**********************************************************
     * Second UE - AUTH
     **********************************************************/
    sess = test_sess_find_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    test_sess_remove(sess);

    sess = test_sess_add_by_apn(
            test_ue[1], "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);
    sess->pti = 1;

    /* Send Attach Request */
    memset(&sess->pdn_connectivity_param,
            0, sizeof(sess->pdn_connectivity_param));
    sess->pdn_connectivity_param.eit = 1;
    sess->pdn_connectivity_param.pco = 1;
    sess->pdn_connectivity_param.request_type =
        OGS_NAS_EPS_REQUEST_TYPE_INITIAL;
    esmbuf = testesm_build_pdn_connectivity_request(
            sess, false, OGS_NAS_EPS_PDN_TYPE_IPV4V6);
    ABTS_PTR_NOTNULL(tc, esmbuf);

    memset(&test_ue[1]->attach_request_param,
            0, sizeof(test_ue[1]->attach_request_param));
    test_ue[1]->attach_request_param.drx_parameter = 1;
    test_ue[1]->attach_request_param.ms_network_capability = 1;
    test_ue[1]->attach_request_param.tmsi_status = 1;
    test_ue[1]->attach_request_param.mobile_station_classmark_2 = 1;
    test_ue[1]->attach_request_param.supported_codecs = 1;
    test_ue[1]->attach_request_param.ue_usage_setting = 1;
    test_ue[1]->attach_request_param.ms_network_feature_support = 1;
    emmbuf = testemm_build_attach_request(test_ue[1], esmbuf, false, false);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue[1]->initial_ue_param, 0,
            sizeof(test_ue[1]->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue[1], emmbuf,
            S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Authentication Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Authentication response */
    emmbuf = testemm_build_authentication_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Security mode Command */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Security mode complete */
    test_ue[1]->mobile_identity_imeisv_presence = true;
    emmbuf = testemm_build_security_mode_complete(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ESM Information Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send ESM Information Response */
    esmbuf = testesm_build_esm_information_response(sess);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive Initial Context Setup Request +
     * Attach Accept +
     * Activate Default Bearer Context Request */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);

    /* Send Initial Context Setup Response */
    sendbuf = test_s1ap_build_initial_context_setup_response(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send UE Capability Info Indication */
    sendbuf =
        tests1ap_build_ue_radio_capability_info_indication(test_ue[1]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Send Attach Complete + Activate default EPS bearer cotext accept */
    test_ue[1]->nr_cgi.cell_id = 0x1234502;
    bearer = test_bearer_find_by_ue_ebi(test_ue[1], 5);
    ogs_assert(bearer);
    esmbuf = testesm_build_activate_default_eps_bearer_context_accept(
            bearer, false);
    ABTS_PTR_NOTNULL(tc, esmbuf);
    emmbuf = testemm_build_attach_complete(test_ue[1], esmbuf);
    ABTS_PTR_NOTNULL(tc, emmbuf);
    sendbuf = test_s1ap_build_uplink_nas_transport(test_ue[1], emmbuf);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive EMM information */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[1], recvbuf);


    /**********************************************************
     * First UE - AUTH
     **********************************************************/

    /* Send E-RABModificationIndication */
    ogs_list_for_each(&sess->bearer_list, bearer)
        bearer->enb_s1u_teid++;

    sendbuf = test_s1ap_build_e_rab_modification_indication(test_ue[0]);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive E-RABModificationConfirm */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue[0], recvbuf);

    ogs_msleep(300);

    for (i = 0; i < NUM_OF_TEST_UE; i++) {
        /********** Remove Subscriber in Database */
        ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue[i]));
    }

    /* eNB disonncect from MME */
    testenb_s1ap_close(s1ap);

    /* eNB disonncect from SGW */
    test_gtpu_close(gtpu);

    test_ue_remove_all();
}

#if 0 /* Deprecated to resolve issue #3131 */
static void pull_3122_v270_func(abts_case *tc, void *data)
{
    int rv;
    ogs_socknode_t *s1ap;
    ogs_socknode_t *gtpu;
    ogs_pkbuf_t *emmbuf;
    ogs_pkbuf_t *esmbuf;
    ogs_pkbuf_t *sendbuf;
    ogs_pkbuf_t *recvbuf;
    ogs_s1ap_message_t message;

    ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci;
    test_ue_t *test_ue = NULL;
    test_sess_t *sess = NULL;
    test_bearer_t *bearer = NULL;

    uint32_t enb_ue_s1ap_id;
    uint64_t mme_ue_s1ap_id;

    bson_t *doc = NULL;

    /* Setup Test UE & Session Context */
    memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci));

    mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI;
    mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI;
    mobile_identity_suci.routing_indicator1 = 0;
    mobile_identity_suci.routing_indicator2 = 0xf;
    mobile_identity_suci.routing_indicator3 = 0xf;
    mobile_identity_suci.routing_indicator4 = 0xf;
    mobile_identity_suci.protection_scheme_id = OGS_PROTECTION_SCHEME_NULL;
    mobile_identity_suci.home_network_pki_value = 0;

    test_ue = test_ue_add_by_suci(&mobile_identity_suci, "3746000006");
    ogs_assert(test_ue);

    test_ue->e_cgi.cell_id = 0x1079baf0;
    test_ue->nas.ksi = 0;
    test_ue->nas.value = OGS_NAS_ATTACH_TYPE_COMBINED_EPS_IMSI_ATTACH;

    test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc";
    test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca";

    sess = test_sess_add_by_apn(test_ue, "internet", OGS_GTP2_RAT_TYPE_EUTRAN);
    ogs_assert(sess);

    /* eNB connects to MME */
    s1ap = tests1ap_client(AF_INET);
    ABTS_PTR_NOTNULL(tc, s1ap);

    /* eNB connects to SGW */
    gtpu = test_gtpu_server(1, AF_INET);
    ABTS_PTR_NOTNULL(tc, gtpu);

    /* Send S1-Setup Reqeust */
    sendbuf = test_s1ap_build_s1_setup_request(
            S1AP_ENB_ID_PR_macroENB_ID, 0x54f64);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive S1-Setup Response */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(NULL, recvbuf);

    /********** Insert Subscriber in Database */
    doc = test_db_new_simple(test_ue);
    ABTS_PTR_NOTNULL(tc, doc);
    ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc));

    /* Send Attach Request */
    emmbuf = testemm_build_identity_response(test_ue);
    ABTS_PTR_NOTNULL(tc, emmbuf);

    memset(&test_ue->initial_ue_param, 0, sizeof(test_ue->initial_ue_param));
    sendbuf = test_s1ap_build_initial_ue_message(
            test_ue, emmbuf, S1AP_RRC_Establishment_Cause_mo_Signalling, false);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    /* Receive ErrorIndication */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Receive UEContextReleaseCommand */
    recvbuf = testenb_s1ap_read(s1ap);
    ABTS_PTR_NOTNULL(tc, recvbuf);
    tests1ap_recv(test_ue, recvbuf);

    /* Send UEContextReleaseComplete */
    sendbuf = test_s1ap_build_ue_context_release_complete(test_ue);
    ABTS_PTR_NOTNULL(tc, sendbuf);
    rv = testenb_s1ap_send(s1ap, sendbuf);
    ABTS_INT_EQUAL(tc, OGS_OK, rv);

    ogs_msleep(300);

    /********** Remove Subscriber in Database */
    ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue));

    /* eNB disonncect from MME */
    testenb_s1ap_close(s1ap);

    /* eNB disonncect from SGW */
    test_gtpu_close(gtpu);

    test_ue_remove(test_ue);
}
#endif

abts_suite *test_issues(abts_suite *suite)
{
    suite = ADD_SUITE(suite)

    abts_run_test(suite, issues_1431_func, NULL);
    abts_run_test(suite, issues_2287_v263_func, NULL);
    abts_run_test(suite, issues_2287_v264_func, NULL);
#if 0 /* Deprecated to resolve issue #3131 */
    abts_run_test(suite, pull_3122_v270_func, NULL);
#endif

    return suite;
}