5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-lte-pattern-generation.cc
Go to the documentation of this file.
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "ns3/nr-gnb-phy.h"
6#include "ns3/test.h"
7
16namespace ns3
17{
18
23class NrPatternTestCase : public TestCase
24{
25 public:
29 struct Result
30 {
31 std::map<uint32_t, std::vector<uint32_t>> m_toSendDl;
32 std::map<uint32_t, std::vector<uint32_t>> m_toSendUl;
33 std::map<uint32_t, std::vector<uint32_t>> m_generateDl;
34 std::map<uint32_t, std::vector<uint32_t>> m_generateUl;
35 std::map<uint32_t, uint32_t> m_dlHarqFb;
36 };
37
41 struct HarqResult
42 {
43 std::map<uint32_t, uint32_t> m_dlHarq;
44 };
45
50 NrPatternTestCase(const std::string& name)
51 : TestCase(name)
52 {
53 }
54
60 void CheckMap(const std::map<uint32_t, std::vector<uint32_t>>& a,
61 const std::map<uint32_t, std::vector<uint32_t>>& b);
62
68 void CheckHarqMap(const std::map<uint32_t, uint32_t>& a, const std::map<uint32_t, uint32_t>& b);
69
75 void CheckVector(const std::vector<uint32_t>& a, const std::vector<uint32_t>& b);
76
77 private:
78 void DoRun() override;
84 void TestPattern(const std::vector<LteNrTddSlotType>& pattern, const Result& result);
85
90 void Print(const std::map<uint32_t, std::vector<uint32_t>>& str);
91
96 void PrintHarq(const std::map<uint32_t, uint32_t>& str);
97
98 bool m_verbose = false;
99};
100
101void
102NrPatternTestCase::DoRun()
103{
104 auto one = {
115 };
116
117 Result a = {{
118 {0,
119 {
120 0,
121 }},
122 {1,
123 {
124 0,
125 }},
126 {4,
127 {
128 0,
129 }},
130 {5,
131 {
132 0,
133 }},
134 {6,
135 {
136 0,
137 }},
138 {9,
139 {
140 0,
141 }},
142 },
143 {
144 {0,
145 {
146 2,
147 }},
148 {1,
149 {
150 2,
151 }},
152 {5,
153 {
154 2,
155 }},
156 {6,
157 {
158 2,
159 }},
160 },
161 {
162 {2,
163 {
164 2,
165 }},
166 {3,
167 {
168 2,
169 }},
170 {4,
171 {
172 2,
173 }},
174 {7,
175 {
176 2,
177 }},
178 {8,
179 {
180 2,
181 }},
182 {9,
183 {
184 2,
185 }},
186 },
187 {
188 {3,
189 {
190 4,
191 }},
192 {4,
193 {
194 4,
195 }},
196 {8,
197 {
198 4,
199 }},
200 {9,
201 {
202 4,
203 }},
204 },
205 // Explanation of testing DL harq feedback timing:
206 // E.g. {0, 6} means that for the first DL slot from the pattern
207 // the HARQ feedback from the UE can be sent earliest after 4 slots (n1 delay),
208 // but 4th and 5th slots are the DL slots, so UE cannot use any
209 // of these slots for to transmit HARQ feedback, so it has to wait
210 // 6 slots (6th slot is the special slot, which has the uplink CTRL).
211 // Hence having the pattern:
212 // DL,0
213 // S, 1 -> DL HARQ fb can be sent after 5 slots in the S slot
214 // UL,2 -> /
215 // UL,3 -> /
216 // DL,4 -> DL HARQ fb can be sent after 4 slots in the UL slot
217 // DL,5 -> DL HARQ fb can be sent after 6 slots which is the S slot
218 // S, 6 -> DL HARQ fb can be sent after 5 slots which is the S slot
219 // UL,7 -> /
220 // UL,8 -> /
221 // DL,9 -> DL HARQ fb can be sent after 4 slots in the UL slot
222 {
223 {0, 6},
224 {1, 5},
225 {4, 4},
226 {5, 6},
227 {6, 5},
228 {9, 4},
229 }};
230
231 TestPattern(one, a);
232
233 Result b = {{
234 {0,
235 {
236 0,
237 }},
238 {1,
239 {
240 0,
241 }},
242 {3,
243 {
244 0,
245 }},
246 {4,
247 {
248 0,
249 }},
250 {5,
251 {
252 0,
253 }},
254 {6,
255 {
256 0,
257 }},
258 {8,
259 {
260 0,
261 }},
262 {9,
263 {
264 0,
265 }},
266 },
267 {
268 {0,
269 {
270 2,
271 }},
272 {5,
273 {
274 2,
275 }},
276 },
277 {
278 {1,
279 {
280 2,
281 }},
282 {2,
283 {
284 2,
285 }},
286 {3,
287 {
288 2,
289 }},
290 {4,
291 {
292 2,
293 }},
294 {6,
295 {
296 2,
297 }},
298 {7,
299 {
300 2,
301 }},
302 {8,
303 {
304 2,
305 }},
306 {9,
307 {
308 2,
309 }},
310 },
311 {
312 {3,
313 {
314 4,
315 }},
316 {8,
317 {
318 4,
319 }},
320 },
321 {
322 {0, 6},
323 {1, 5},
324 {3, 4},
325 {4, 7},
326 {5, 6},
327 {6, 5},
328 {8, 4},
329 {9, 7},
330 }};
331 auto two = {
342 };
343
344 TestPattern(two, b);
345
346 Result c = {{
347 {0,
348 {
349 0,
350 }},
351 {1,
352 {
353 0,
354 }},
355 {5,
356 {
357 0,
358 }},
359 {6,
360 {
361 0,
362 }},
363 {7,
364 {
365 0,
366 }},
367 {8,
368 {
369 0,
370 }},
371 {9,
372 {
373 0,
374 }},
375 },
376 {
377 {0,
378 {
379 2,
380 }},
381 {1,
382 {
383 2,
384 3,
385 }},
386 },
387 {
388 {3,
389 {
390 2,
391 }},
392 {4,
393 {
394 2,
395 }},
396 {5,
397 {
398 2,
399 }},
400 {6,
401 {
402 2,
403 }},
404 {7,
405 {
406 2,
407 }},
408 {8,
409 {
410 2,
411 }},
412 {9,
413 {
414 2,
415 }},
416 },
417 {
418 {8,
419 {
420 4,
421 }},
422 {9,
423 {
424 4,
425 5,
426 }},
427 },
428 {
429 {0, 4},
430 {1, 10},
431 {5, 6},
432 {6, 5},
433 {7, 4},
434 {8, 4},
435 {9, 4},
436 }};
437 auto three = {
448 };
449
450 TestPattern(three, c);
451
452 Result d = {{
453 {0,
454 {
455 0,
456 }},
457 {1,
458 {
459 0,
460 }},
461 {4,
462 {
463 0,
464 }},
465 {5,
466 {
467 0,
468 }},
469 {6,
470 {
471 0,
472 }},
473 {7,
474 {
475 0,
476 }},
477 {8,
478 {
479 0,
480 }},
481 {9,
482 {
483 0,
484 }},
485 },
486 {
487 {0,
488 {
489 2,
490 }},
491 {1,
492 {
493 2,
494 }},
495 },
496 {
497 {2,
498 {
499 2,
500 }},
501 {3,
502 {
503 2,
504 }},
505 {4,
506 {
507 2,
508 }},
509 {5,
510 {
511 2,
512 }},
513 {6,
514 {
515 2,
516 }},
517 {7,
518 {
519 2,
520 }},
521 {8,
522 {
523 2,
524 }},
525 {9,
526 {
527 2,
528 }},
529 },
530 {
531 {8,
532 {
533 4,
534 }},
535 {9,
536 {
537 4,
538 }},
539 },
540 {
541 {0, 11},
542 {1, 10},
543 {4, 7},
544 {5, 6},
545 {6, 5},
546 {7, 4},
547 {8, 4},
548 {9, 4},
549 }};
550 auto four = {
561 };
562
563 TestPattern(four, d);
564
565 Result e = {{
566 {0,
567 {
568 0,
569 }},
570 {1,
571 {
572 0,
573 }},
574 {3,
575 {
576 0,
577 }},
578 {4,
579 {
580 0,
581 }},
582 {5,
583 {
584 0,
585 }},
586 {6,
587 {
588 0,
589 }},
590 {7,
591 {
592 0,
593 }},
594 {8,
595 {
596 0,
597 }},
598 {9,
599 {
600 0,
601 }},
602 },
603 {
604 {0,
605 {
606 2,
607 }},
608 },
609 {
610 {1,
611 {
612 2,
613 }},
614 {2,
615 {
616 2,
617 }},
618 {3,
619 {
620 2,
621 }},
622 {4,
623 {
624 2,
625 }},
626 {5,
627 {
628 2,
629 }},
630 {6,
631 {
632 2,
633 }},
634 {7,
635 {
636 2,
637 }},
638 {8,
639 {
640 2,
641 }},
642 {9,
643 {
644 2,
645 }},
646 },
647 {
648 {8,
649 {
650 4,
651 }},
652 },
653 {
654 {0, 11},
655 {1, 10},
656 {3, 8},
657 {4, 7},
658 {5, 6},
659 {6, 5},
660 {7, 4},
661 {8, 4},
662 {9, 12},
663 }};
664 auto five = {
675 };
676
677 TestPattern(five, e);
678
679 Result f = {{
680 {0,
681 {
682 0,
683 }},
684 {1,
685 {
686 0,
687 }},
688 {5,
689 {
690 0,
691 }},
692 {6,
693 {
694 0,
695 }},
696 {9,
697 {
698 0,
699 }},
700 },
701 {
702 {0,
703 {
704 2,
705 }},
706 {1,
707 {
708 2,
709 3,
710 }},
711 {5,
712 {
713 2,
714 }},
715 {6,
716 {
717 2,
718 }},
719 },
720 {
721 {3,
722 {
723 2,
724 }},
725 {4,
726 {
727 2,
728 }},
729 {7,
730 {
731 2,
732 }},
733 {8,
734 {
735 2,
736 }},
737 {9,
738 {
739 2,
740 }},
741 },
742 {
743 {3,
744 {
745 4,
746 }},
747 {4,
748 {
749 4,
750 }},
751 {8,
752 {
753 4,
754 }},
755 {9,
756 {
757 4,
758 5,
759 }},
760 },
761 {
762 {0, 4},
763 {1, 5},
764 {5, 6},
765 {6, 5},
766 {9, 4},
767 }};
768 auto six = {
779 };
780 TestPattern(six, f);
781
782 Result g = {{
783 {0,
784 {
785 0,
786 }},
787 {1,
788 {
789 0,
790 }},
791 {5,
792 {
793 0,
794 }},
795 {6,
796 {
797 0,
798 }},
799 },
800 {
801 {0,
802 {
803 2,
804 }},
805 {1,
806 {
807 2,
808 3,
809 }},
810 {5,
811 {
812 2,
813 }},
814 {6,
815 {
816 2,
817 3,
818 }},
819 },
820 {
821 {3,
822 {
823 2,
824 }},
825 {4,
826 {
827 2,
828 }},
829 {8,
830 {
831 2,
832 }},
833 {9,
834 {
835 2,
836 }},
837 },
838 {
839 {3,
840 {
841 4,
842 }},
843 {4,
844 {
845 4,
846 5,
847 }},
848 {8,
849 {
850 4,
851 }},
852 {9,
853 {
854 4,
855 5,
856 }},
857 },
858 {
859 {0, 4},
860 {1, 5},
861 {5, 4},
862 {6, 5},
863 }};
864 auto zero = {
875 };
876
877 TestPattern(zero, g);
878
879 Result k = {{
880 {0,
881 {
882 0,
883 }},
884 {1,
885 {
886 0,
887 }},
888 },
889 {
890 {0,
891 {
892 2,
893 }},
894 {1, {5, 2, 3}},
895 },
896 {
897 {3,
898 {
899 2,
900 }},
901 {4,
902 {
903 2,
904 }},
905 },
906 {
907 {3,
908 {
909 4,
910 }},
911 {4, {4, 5, 7}},
912 },
913 {
914 {0, 4},
915 {1, 5},
916 }};
917 auto seven = {LteNrTddSlotType::DL,
922
923 TestPattern(seven, k);
924
925 Result h = {{
926 {0,
927 {
928 0,
929 }},
930 {1,
931 {
932 0,
933 }},
934 {2,
935 {
936 0,
937 }},
938 {3,
939 {
940 0,
941 }},
942 {4,
943 {
944 0,
945 }},
946 {5,
947 {
948 0,
949 }},
950 {6,
951 {
952 0,
953 }},
954 {7,
955 {
956 0,
957 }},
958 {8,
959 {
960 0,
961 }},
962 {9,
963 {
964 0,
965 }},
966 },
967 {
968 {0,
969 {
970 2,
971 }},
972 {1,
973 {
974 2,
975 }},
976 {2,
977 {
978 2,
979 }},
980 {3,
981 {
982 2,
983 }},
984 {4,
985 {
986 2,
987 }},
988 {5,
989 {
990 2,
991 }},
992 {6,
993 {
994 2,
995 }},
996 {7,
997 {
998 2,
999 }},
1000 {8,
1001 {
1002 2,
1003 }},
1004 {9,
1005 {
1006 2,
1007 }},
1008 },
1009 {
1010 {0,
1011 {
1012 2,
1013 }},
1014 {1,
1015 {
1016 2,
1017 }},
1018 {2,
1019 {
1020 2,
1021 }},
1022 {3,
1023 {
1024 2,
1025 }},
1026 {4,
1027 {
1028 2,
1029 }},
1030 {5,
1031 {
1032 2,
1033 }},
1034 {6,
1035 {
1036 2,
1037 }},
1038 {7,
1039 {
1040 2,
1041 }},
1042 {8,
1043 {
1044 2,
1045 }},
1046 {9,
1047 {
1048 2,
1049 }},
1050 },
1051 {
1052 {0,
1053 {
1054 4,
1055 }},
1056 {1,
1057 {
1058 4,
1059 }},
1060 {2,
1061 {
1062 4,
1063 }},
1064 {3,
1065 {
1066 4,
1067 }},
1068 {4,
1069 {
1070 4,
1071 }},
1072 {5,
1073 {
1074 4,
1075 }},
1076 {6,
1077 {
1078 4,
1079 }},
1080 {7,
1081 {
1082 4,
1083 }},
1084 {8,
1085 {
1086 4,
1087 }},
1088 {9,
1089 {
1090 4,
1091 }},
1092 },
1093 {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}, {6, 4}, {7, 4}, {8, 4}, {9, 4}}};
1094
1095 auto nr = {
1106 };
1107
1108 TestPattern(nr, h);
1109
1110 Result l = {{
1111 {0,
1112 {
1113 0,
1114 }},
1115 {1,
1116 {
1117 0,
1118 }},
1119 {2,
1120 {
1121 0,
1122 }},
1123 {3,
1124 {
1125 0,
1126 }},
1127 {4,
1128 {
1129 0,
1130 }},
1131 },
1132 {
1133 {0,
1134 {
1135 2,
1136 }},
1137 {1,
1138 {
1139 2,
1140 }},
1141 {2,
1142 {
1143 2,
1144 }},
1145 {3,
1146 {
1147 2,
1148 }},
1149 {4,
1150 {
1151 2,
1152 3,
1153 4,
1154 5,
1155 6,
1156 7,
1157 }},
1158 },
1159 {
1160 {0,
1161 {
1162 2,
1163 }},
1164 {1,
1165 {
1166 2,
1167 }},
1168 {2,
1169 {
1170 2,
1171 }},
1172 {10,
1173 {
1174 2,
1175 }},
1176 {11,
1177 {
1178 2,
1179 }},
1180 },
1181 {
1182 {0,
1183 {
1184 4,
1185 }},
1186 {1,
1187 {
1188 4,
1189 }},
1190 {2,
1191 {
1192 4,
1193 5,
1194 6,
1195 7,
1196 8,
1197 9,
1198 }},
1199 {10,
1200 {
1201 4,
1202 }},
1203 {11,
1204 {
1205 4,
1206 }},
1207 },
1208 {
1209 {0, 4},
1210 {1, 4},
1211 {2, 4},
1212 {3, 4},
1213 {4, 4},
1214 }};
1215
1216 auto twelve = {
1229 };
1230
1231 TestPattern(twelve, l);
1232
1233 Result m = {{
1234 {0,
1235 {
1236 0,
1237 }},
1238 {1,
1239 {
1240 0,
1241 }},
1242 {2,
1243 {
1244 0,
1245 }},
1246 {3,
1247 {
1248 0,
1249 }},
1250 {4,
1251 {
1252 0,
1253 }},
1254 {5,
1255 {
1256 0,
1257 }},
1258 {6,
1259 {
1260 0,
1261 }},
1262 {7,
1263 {
1264 0,
1265 }},
1266 {8,
1267 {
1268 0,
1269 }},
1270 {9,
1271 {
1272 0,
1273 }},
1274 },
1275 {
1276 {0,
1277 {
1278 2,
1279 }},
1280 {1,
1281 {
1282 2,
1283 }},
1284 {2,
1285 {
1286 2,
1287 }},
1288 {3,
1289 {
1290 2,
1291 }},
1292 {4,
1293 {
1294 2,
1295 }},
1296 {5,
1297 {
1298 2,
1299 }},
1300 {6,
1301 {
1302 2,
1303 }},
1304 {7,
1305 {
1306 2,
1307 }},
1308 {8,
1309 {
1310 2,
1311 }},
1312 {9,
1313 {
1314 2,
1315 }},
1316 },
1317 {
1318 {0,
1319 {
1320 2,
1321 }},
1322 {1,
1323 {
1324 2,
1325 }},
1326 {2,
1327 {
1328 2,
1329 }},
1330 {3,
1331 {
1332 2,
1333 }},
1334 {4,
1335 {
1336 2,
1337 }},
1338 {5,
1339 {
1340 2,
1341 }},
1342 {6,
1343 {
1344 2,
1345 }},
1346 {7,
1347 {
1348 2,
1349 }},
1350 {8,
1351 {
1352 2,
1353 }},
1354 {9,
1355 {
1356 2,
1357 }},
1358 },
1359 {},
1360 {
1361 {0, 4},
1362 {1, 4},
1363 {2, 4},
1364 {3, 4},
1365 {4, 4},
1366 {5, 4},
1367 {6, 4},
1368 {7, 4},
1369 {8, 4},
1370 {9, 4},
1371 }};
1372
1373 auto thirtheen = {
1384 };
1385
1386 TestPattern(thirtheen, m);
1387}
1388
1389void
1390NrPatternTestCase::Print(const std::map<uint32_t, std::vector<uint32_t>>& str)
1391{
1392 std::cout << "{" << std::endl;
1393 for (const auto& v : str)
1394 {
1395 std::cout << " { " << v.first << ", {";
1396 for (const auto& i : v.second)
1397 {
1398 std::cout << i << ", ";
1399 }
1400 std::cout << "} }," << std::endl;
1401 }
1402 std::cout << "}" << std::endl;
1403}
1404
1405void
1406NrPatternTestCase::PrintHarq(const std::map<uint32_t, uint32_t>& str)
1407{
1408 std::cout << "{" << std::endl;
1409 for (const auto& v : str)
1410 {
1411 std::cout << " { " << v.first << ", ";
1412 std::cout << v.second;
1413 std::cout << "}" << std::endl;
1414 }
1415 std::cout << "}" << std::endl;
1416}
1417
1418void
1419NrPatternTestCase::CheckVector(const std::vector<uint32_t>& a, const std::vector<uint32_t>& b)
1420{
1421 NS_TEST_ASSERT_MSG_EQ(a.size(), b.size(), "Two vectors have different length");
1422 for (uint32_t i = 0; i < a.size(); ++i)
1423 {
1424 NS_TEST_ASSERT_MSG_EQ(a[i], b[i], "Values in vector diffes");
1425 }
1426}
1427
1428void
1429NrPatternTestCase::CheckMap(const std::map<uint32_t, std::vector<uint32_t>>& a,
1430 const std::map<uint32_t, std::vector<uint32_t>>& b)
1431{
1432 NS_TEST_ASSERT_MSG_EQ(a.size(), b.size(), "Two maps have different length");
1433
1434 for (const std::pair<const uint32_t, std::vector<uint32_t>>& v : a)
1435 {
1436 CheckVector(a.at(v.first), b.at(v.first));
1437 }
1438}
1439
1440void
1441NrPatternTestCase::CheckHarqMap(const std::map<uint32_t, uint32_t>& a,
1442 const std::map<uint32_t, uint32_t>& b)
1443{
1444 NS_TEST_ASSERT_MSG_EQ(a.size(), b.size(), "Two HARQ maps have different length");
1445
1446 for (const auto& element : a)
1447 {
1448 NS_TEST_ASSERT_MSG_EQ(element.second,
1449 b.at(element.first),
1450 "A value in A is different from the value for the same key in B");
1451 }
1452}
1453
1454void
1455NrPatternTestCase::TestPattern(const std::vector<LteNrTddSlotType>& pattern, const Result& result)
1456{
1457 std::map<uint32_t, std::vector<uint32_t>> toSendDl;
1458 std::map<uint32_t, std::vector<uint32_t>> toSendUl;
1459 std::map<uint32_t, std::vector<uint32_t>> generateDl;
1460 std::map<uint32_t, std::vector<uint32_t>> generateUl;
1461 std::map<uint32_t, uint32_t> dlHarqFb;
1462
1463 NrGnbPhy::GenerateStructuresFromPattern(pattern,
1464 &toSendDl,
1465 &toSendUl,
1466 &generateDl,
1467 &generateUl,
1468 &dlHarqFb,
1469 0,
1470 2,
1471 4,
1472 2);
1473
1474 if (m_verbose)
1475 {
1476 std::cout << std::endl << "PATTERN to test: ";
1477 for (const auto& v : pattern)
1478 {
1479 std::cout << v << " ";
1480 }
1481 std::cout << std::endl;
1482 }
1483
1484 if (m_verbose)
1485 {
1486 std::cout << "To Send DL theoretic:" << std::endl;
1487 Print(toSendDl);
1488 std::cout << "To Send DL result:" << std::endl;
1489 Print(result.m_toSendDl);
1490 }
1491 CheckMap(toSendDl, result.m_toSendDl);
1492
1493 if (m_verbose)
1494 {
1495 std::cout << "To Send UL theoretic:" << std::endl;
1496 Print(toSendUl);
1497 std::cout << "To Send UL result:" << std::endl;
1498 Print(result.m_toSendUl);
1499 }
1500
1501 CheckMap(toSendUl, result.m_toSendUl);
1502
1503 if (m_verbose)
1504 {
1505 std::cout << "Generate DL theoretic:" << std::endl;
1506 Print(generateDl);
1507 std::cout << "Generate DL result:" << std::endl;
1508 Print(result.m_generateDl);
1509 }
1510
1511 CheckMap(generateDl, result.m_generateDl);
1512
1513 if (m_verbose)
1514 {
1515 std::cout << "Generate UL theoretic:" << std::endl;
1516 Print(generateUl);
1517 std::cout << "Generate UL result:" << std::endl;
1518 Print(result.m_generateUl);
1519 }
1520
1521 CheckMap(generateUl, result.m_generateUl);
1522
1523 if (m_verbose)
1524 {
1525 std::cout << "HarqFB theoretic:" << std::endl;
1526 PrintHarq(dlHarqFb);
1527 std::cout << "HarqFB result:" << std::endl;
1528 PrintHarq(result.m_dlHarqFb);
1529 }
1530
1531 CheckHarqMap(dlHarqFb, result.m_dlHarqFb);
1532}
1533
1537class NrPatternTestSuite : public TestSuite
1538{
1539 public:
1540 NrPatternTestSuite()
1541 : TestSuite("nr-lte-pattern-generation", Type::UNIT)
1542 {
1543 AddTestCase(new NrPatternTestCase("LTE TDD Pattern test"), Duration::QUICK);
1544 }
1545};
1546
1547static NrPatternTestSuite nrNrPatternTestSuite;
1548
1549} // namespace ns3
@ F
DL CTRL + DL DATA + UL DATA + UL CTRL.
@ S
DL CTRL + DL DATA + UL CTRL.
@ DL
DL CTRL + DL DATA.
@ UL
UL DATA + UL CTRL.
static NrPatternTestSuite nrNrPatternTestSuite
Pattern test suite.