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