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
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052 | // Copyright (C) 2017-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <asiolink/io_address.h>
#include <dhcp/option.h>
#include <dhcp/option_int.h>
#include <dhcp/option6_client_fqdn.h>
#include <dhcp/option6_addrlst.h>
#include <dhcp/testutils/iface_mgr_test_config.h>
#include <dhcpsrv/cfg_subnets6.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcp6/json_config_parser.h>
#include <dhcp6/tests/dhcp6_client.h>
#include <dhcp6/tests/dhcp6_test_utils.h>
#include <cc/command_interpreter.h>
#include <stats/stats_mgr.h>
#include <boost/pointer_cast.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <functional><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <vector><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc;
using namespace isc::asiolink;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::stats;
namespace {
/// @brief Array of server configurations used throughout the tests.
const char* NETWORKS_CONFIG[] = {
// Configuration #0.
// - one shared network with two subnets, each with address and prefix pools
// - one plain subnet
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"comment\": \"example\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ],"
" \"pd-pools\": ["
" {"
" \"prefix\": \"4000::\","
" \"prefix-len\": 96,"
" \"delegated-len\": 96"
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ],"
" \"pd-pools\": ["
" {"
" \"prefix\": \"5000::\","
" \"prefix-len\": 96,"
" \"delegated-len\": 96"
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"3000::/96\","
" \"id\": 1000,"
" \"interface\": \"eth0\","
" \"pools\": ["
" {"
" \"pool\": \"3000::1 - 3000::1\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #1.
// - one shared network with relay-ip specified and one subnet with address pool
// - one plain subnet with relay-ip specified and one address pool
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"relay\": {"
" \"ip-addresses\": [ \"3001::1\" ]"
" },"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 1000,"
" \"relay\": {"
" \"ip-addresses\": [ \"3001::2\" ]"
" },"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #2.
// - two classes specified
// - one shared network with two subnets (the first has class restrictions)
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ],"
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #3.
// - two classes defined
// - one shared network with two subnets, each with a different class restriction
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ],"
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ],"
" \"client-classes\": [ \"b-devices\" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #4.
// - one shared network with two subnets. Each subnet has:
// - address and prefix pool
// - reservation
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"pd-pools\": ["
" {"
" \"prefix\": \"4000::\","
" \"prefix-len\": 96,"
" \"delegated-len\": 96"
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::1 - 2001:db8:2::64\""
" }"
" ],"
" \"pd-pools\": ["
" {"
" \"prefix\": \"5000::\","
" \"prefix-len\": 96,"
" \"delegated-len\": 112"
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:11:22:33:44:55:66\","
" \"ip-addresses\": [ \"2001:db8:2::28\" ],"
" \"prefixes\": [ \"5000::8:0000/112\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #5 (similar to #4, but without prefix pool and using different
// DUID for reservations)
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:11:22:33:44:55:66\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::1 - 2001:db8:2::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:2::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #6.
// - one class
// - one shared network with two subnets:
// - first subnet has address pool, class restriction and a reservation
// - second subnet has just an address pool
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"client-classes\": [ \"a-devices\" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::16 - 2001:db8:2::16\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #7.
// - option defined on global level
// - one shared network with two options and two subnets
// - the first subnet has its own options defined as well
// - plain subnet with its own options
"{"
" \"option-data\": ["
" {"
" \"name\": \"nis-servers\","
" \"data\": \"3000::20\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"3001::21\""
" },"
" {"
" \"name\": \"nisp-servers\","
" \"data\": \"3002::34\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"option-data\": ["
" {"
" \"name\": \"sntp-servers\","
" \"data\": \"4004::22\""
" },"
" {"
" \"name\": \"nisp-servers\","
" \"data\": \"3003::33\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"3000::/96\","
" \"id\": 1000,"
" \"interface\": \"eth0\","
" \"option-data\": ["
" {"
" \"name\": \"nisp-servers\","
" \"data\": \"4000::5\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"3000::1 - 3000::1\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #8.
// - two shared networks
// - first network with two subnets, each with its own address pool
// - second network with two subnets, each with its own address pool
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" },"
" {"
" \"name\": \"dog\","
" \"interface\": \"eth0\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:3::/64\","
" \"id\": 1000,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:3::20 - 2001:db8:3::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:4::/64\","
" \"id\": 10000,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:4::20 - 2001:db8:4::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #9 (similar to #8, but with relay-ip addresses specified)
// - two shared networks, each with relay IP addresses specified
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"relay\": {"
" \"ip-addresses\": [ \"3000::1\" ]"
" },"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" },"
" {"
" \"name\": \"dog\","
" \"relay\": {"
" \"ip-addresses\": [ \"3000::2\" ]"
" },"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:3::/64\","
" \"id\": 1000,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:3::20 - 2001:db8:3::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:4::/64\","
" \"id\": 10000,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:4::20 - 2001:db8:4::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #10.
// - one class with an option (and not test expression)
// - one shared network with two subnets
// - first subnet with one address pool
// - second with a pool and reservation that assigns client to a class
"{"
" \"client-classes\": ["
" {"
" \"name\": \"class-with-dns-servers\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::50\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::30\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:11:22:33:44:55:66\","
" \"ip-addresses\": [ \"2001:db8:2::20\" ],"
" \"hostname\": \"test.example.org\","
" \"client-classes\": [ \"class-with-dns-servers\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #11.
// - two classes defined
// - two shared networks, each with one subnet and class restriction
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"client-classes\": [ \"a-devices\" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" }"
" ]"
" },"
" {"
" \"name\": \"dog\","
" \"interface\": \"eth1\","
" \"client-classes\": [ \"b-devices\" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 1000,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #12.
// - one client class
// - one shared network with two subnets, the second subnet has class restriction
"{"
" \"client-classes\": ["
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ],"
" \"client-classes\": [ \"b-devices\" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #13.
// - one shared network, with two subnets, each with the same relay-ip addresses
// - one plain subnet, with its own (different) relay-ip address
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"relay\": {"
" \"ip-addresses\": [ \"3001::1\" ]"
" },"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"relay\": {"
" \"ip-addresses\": [ \"3001::1\" ]"
" },"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:3::/64\","
" \"id\": 1000,"
" \"relay\": {"
" \"ip-addresses\": [ \"3001::2\" ]"
" },"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:3::20 - 2001:db8:3::20\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #14.
// - one share network with interface-id specified and one subnet
// - one plain subnet, with its own interface-id
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface-id\": \"vlan10\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 1000,"
" \"interface-id\": \"vlan1000\","
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #15.
// - one shared network, with two subnets, each with the same interface-id
// - one plain subnet, with its own interface-id
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"interface-id\": \"vlan10\","
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 11,"
" \"interface-id\": \"vlan10\","
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::10 - 2001:db8:2::10\""
" }"
" ]"
" }"
" ]"
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:2::1/64\","
" \"id\": 1000,"
" \"interface-id\": \"vlan1000\","
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #16.
// - one shared network with three subnets, each with different option value
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"4004::22\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"5555::33\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:3::/64\","
" \"id\": 1000,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"1234::23\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:3::20 - 2001:db8:3::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #17.
// - one shared network with two subnets, both have rapid-commit enabled
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"rapid-commit\": true,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"rapid-commit\": true,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #18.
// - one shared network with rapid-commit enabled
// - two subnets (which should derive the rapid-commit setting)
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"rapid-commit\": true,"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\""
" }"
" ]"
" },"
" {"
" \"subnet\": \"2001:db8:2::/64\","
" \"id\": 100,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:2::20 - 2001:db8:2::20\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #19.
// - one shared network with one subnet and two pools (the first has
// class restrictions)
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #20.
// - one shared network with one subnet and two pools (each with class
// restriction)
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\","
" \"client-classes\": [ \"b-devices\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #21.
// - one plain subnet with two pools (the first has class restrictions)
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"interface\": \"eth1\","
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\""
" }"
" ]"
" }"
" ]"
"}",
// Configuration #22.
// - one plain subnet with two pools (each with class restriction)
"{"
" \"client-classes\": ["
" {"
" \"name\": \"a-devices\","
" \"test\": \"option[1234].hex == 0x0001\""
" },"
" {"
" \"name\": \"b-devices\","
" \"test\": \"option[1234].hex == 0x0002\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::20 - 2001:db8:1::20\","
" \"client-classes\": [ \"a-devices\" ]"
" },"
" {"
" \"pool\": \"2001:db8:1::50 - 2001:db8:1::50\","
" \"client-classes\": [ \"b-devices\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #23.
// - a shared network with two subnets
// - first subnet uses the FLQ allocator
// - second subnet uses the random allocator
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"id\": 100, "
" \"subnet\": \"2001:db8:1::/64\","
" \"pd-allocator\": \"flq\","
" \"pd-pools\": ["
" {"
" \"prefix\": \"2001:db8:1::\","
" \"prefix-len\": 64,"
" \"delegated-len\": 68"
" }"
" ]"
" },"
" {"
" \"id\": 10, "
" \"subnet\": \"2001:db8:2::/64\","
" \"pd-allocator\": \"random\","
" \"pd-pools\": ["
" {"
" \"prefix\": \"2001:db8:2::\","
" \"prefix-len\": 64,"
" \"delegated-len\": 68"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}",
// Configuration #24.
// - a shared network with two subnets
// - first subnet uses the random allocator
// - second subnet uses the FLQ allocator
"{"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"id\": 100, "
" \"subnet\": \"2001:db8:1::/64\","
" \"pd-allocator\": \"random\","
" \"pd-pools\": ["
" {"
" \"prefix\": \"2001:db8:1::\","
" \"prefix-len\": 64,"
" \"delegated-len\": 68"
" }"
" ]"
" },"
" {"
" \"id\": 10, "
" \"subnet\": \"2001:db8:2::/64\","
" \"pd-allocator\": \"flq\","
" \"pd-pools\": ["
" {"
" \"prefix\": \"2001:db8:2::\","
" \"prefix-len\": 64,"
" \"delegated-len\": 68"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}"
};
/// @Brief Test fixture class for DHCPv6 server using shared networks.
class Dhcpv6SharedNetworkTest : public Dhcpv6SrvTest {
public:
/// @brief Indicates how test functions should check presence of a lease on
/// the server.
enum class LeaseOnServer{
MUST_EXIST,
MUST_NOT_EXIST,
};
/// @brief Constructor.
Dhcpv6SharedNetworkTest()
: Dhcpv6SrvTest(),
iface_mgr_test_config_(true) {
IfaceMgr::instance().openSockets6();
StatsMgr::instance().removeAll();
}
/// @brief Verifies lease statistics against values held by StatsMgr.
///
/// This method retrieves lease statistics from the database and then compares it
/// against values held by the StatsMgr. The compared statistics are number of
/// assigned addresses and prefixes for a subnet.
void verifyAssignedStats() {
LeaseStatsQueryPtr query = LeaseMgrFactory::instance().startLeaseStatsQuery6();
LeaseStatsRow row;
while (query->getNextRow(row)) {
// Only check valid leases.
if (row.lease_state_ == Lease::STATE_DEFAULT) {
std::string stat_name;
// Addresses
if (row.lease_type_ == Lease::TYPE_NA) {
stat_name = StatsMgr::generateName("subnet", row.subnet_id_,
"assigned-nas");
// Prefixes.
} else if (row.lease_type_ == Lease::TYPE_PD) {
stat_name = StatsMgr::generateName("subnet", row.subnet_id_,
"assigned-pds");
}
// Number of leases held in the database should match the information
// held in the Stats Manager.
if (!stat_name.empty()) {
ASSERT_EQ(row.state_count_, getStatsAssignedLeases(stat_name))
<< "test failed for statistic " << stat_name;
}
}
}
}
/// @brief Retrieves statistics for a subnet.
///
/// @param stat_name Name of the statistics to be retrieved, e.g. subnet[1234].assigned-nas.
/// @return Number of assigned leases for a subnet.
int64_t getStatsAssignedLeases(const std::string& stat_name) const {
// Top element is a map with a subnet[id].assigned-addresses parameter.
ConstElementPtr top_element = StatsMgr::instance().get(stat_name);
if (top_element && (top_element->getType() == Element::map)) {
// It contains two lists (nested).
ConstElementPtr first_list = top_element->get(stat_name);
if (first_list && (first_list->getType() == Element::list) &&
(first_list->size() > 0)) {
// Get the nested list which should have two elements, of which first
// is the statistics value we're looking for.
ConstElementPtr second_list = first_list->get(0);
if (second_list && (second_list->getType() == Element::list)) {
ConstElementPtr addresses_element = second_list->get(0);
if (addresses_element && (addresses_element->getType() == Element::integer)) {
return (addresses_element->intValue());
}
}
}
}
// Statistics invalid or not found.
return (0);
}
/// @brief Launches specific operation and verifies lease statistics before and
/// after this operation.
///
/// @param operation Operation to be launched.
void testAssigned(const std::function<void()>& operation) {
ASSERT_NO_FATAL_FAILURE(verifyAssignedStats());
operation();
ASSERT_NO_FATAL_FAILURE(verifyAssignedStats());
}
/// @brief Returns subnet having specified address or prefix in range.
///
/// @param type Resource type: NA or PD.
/// @param resource Address or prefix for which subnet is being searched.
/// @return Pointer to the subnet having an resource in range or null pointer
/// if no subnet found.
Subnet6Ptr getConfiguredSubnet(const Lease::Type& type, const IOAddress& resource) const {
CfgSubnets6Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSubnets6();
const Subnet6Collection* subnets = cfg->getAll();
for (auto const& subnet_it : *subnets) {
if (subnet_it->inPool(type, resource)) {
return (subnet_it);
}
}
return (Subnet6Ptr());
}
/// @brief Check if client has a lease for the specified address.
///
/// Apart from checking whether the client has got the lease it also
/// checks whether this lease is stored in the lease database and that
/// it holds valid subnet identifier.
///
/// @param client Reference to the client.
/// @param address Leased address.
/// @param lease_on_server Specify whether the lease should be also present or
/// absent in the lease database.
///
/// @return true if the lease for the client has been found both in the
/// database and in the server's response.
bool hasLeaseForAddress(Dhcp6Client& client, const IOAddress& address,
const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) {
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, address);
// Sanity check the lease.
if (lease) {
Subnet6Ptr subnet = getConfiguredSubnet(Lease::TYPE_NA, address);
if (!subnet) {
ADD_FAILURE() << "unable to find configured subnet for the"
" address " << address;
return (false);
}
// Make sure that the subnet id is not messed up in the lease.
if (subnet->getID() != lease->subnet_id_) {
ADD_FAILURE() << "invalid subnet identifier found in the lease for"
" address " << address << ", expected " << subnet->getID()
<< ", got " << lease->subnet_id_;
return (false);
}
}
return ((((lease_on_server == LeaseOnServer::MUST_EXIST) && lease) ||
((lease_on_server == LeaseOnServer::MUST_NOT_EXIST) && !lease)) &&
client.hasLeaseForAddress(address));
}
/// @brief Check if client has a lease for the specified prefix.
///
/// Apart from checking whether the client has got the lease it also
/// checks whether this lease is stored in the lease database and that
/// it holds valid subnet identifier.
///
/// @param client Reference to the client.
/// @param prefix Leased prefix.
/// @param prefix_len Leased prefix length.
/// @param lease_on_server Specify whether the lease should be also present or
/// absent in the lease database.
///
/// @return true if the lease for the client has been found both in the
/// database and in the server's response.
bool hasLeaseForPrefix(Dhcp6Client& client, const IOAddress& prefix,
const uint8_t prefix_len, const IAID& iaid,
const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) {
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, prefix);
// Sanity check the lease.
if (lease) {
Subnet6Ptr subnet = getConfiguredSubnet(Lease::TYPE_PD, prefix);
if (!subnet) {
ADD_FAILURE() << "unable to find configured subnet for the"
" prefix " << prefix;
return (false);
}
// Make sure that the subnet id is not messed up in the lease.
if (subnet->getID() != lease->subnet_id_) {
ADD_FAILURE() << "invalid subnet identifier found in the lease for"
" prefix " << prefix;
return (false);
}
}
return ((((lease_on_server == LeaseOnServer::MUST_EXIST) && lease &&
(lease->prefixlen_ = prefix_len) && (lease->iaid_ == iaid)) ||
((lease_on_server == LeaseOnServer::MUST_NOT_EXIST) && !lease)) &&
client.hasLeaseForPrefix(prefix, prefix_len, iaid));
}
/// @brief Check if client has a lease belonging to address range.
///
/// Apart from checking whether the client has got the lease it also
/// checks whether this lease is stored in the lease database.
///
/// @param client Reference to the client.
/// @param first Lower bound of the address range.
/// @param last Upper bound of the address range.
/// @param lease_on_server Specify whether the lease should be also present or
/// absent in the lease database.
bool hasLeaseForAddressRange(Dhcp6Client& client, const IOAddress& first, const IOAddress& last,
const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) {
std::vector<Lease6> leases = client.getLeasesByAddressRange(first, last);
for (auto const& lease_it : leases) {
// Take into account only valid leases.
if (lease_it.valid_lft_ == 0) {
continue;
}
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA, lease_it.addr_);
if ((lease && (lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) ||
(!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) {
return (false);
}
}
return (!leases.empty());
}
/// @brief Check if client has a lease belonging to a prefix pool.
///
/// Apart from checking whether the client has got the lease it also
/// checks whether this lease is stored in the lease database.
///
/// @param client Reference to the client.
/// @param prefix Pool prefix.
/// @param prefix_len Prefix length.
/// @param delegated_len Delegated prefix length.
/// @param lease_on_server Specify whether the lease should be also present or
/// absent in the lease database.
///
/// @return true if client has a lease belonging to specified pool,
/// false otherwise.
bool hasLeaseForPrefixPool(Dhcp6Client& client, const asiolink::IOAddress& prefix,
const uint8_t prefix_len, const uint8_t delegated_len,
const LeaseOnServer& lease_on_server = LeaseOnServer::MUST_EXIST) {
std::vector<Lease6> leases = client.getLeasesByPrefixPool(prefix, prefix_len, delegated_len);
for (auto const& lease_it : leases) {
// Take into account only valid leases.
if (lease_it.valid_lft_ == 0) {
continue;
}
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_PD, lease_it.addr_);
if ((lease && (lease->prefixlen_ == lease->prefixlen_) &&
(lease_on_server == LeaseOnServer::MUST_NOT_EXIST)) ||
(!lease && (lease_on_server == LeaseOnServer::MUST_EXIST))) {
return (false);
}
}
return (!leases.empty());
}
/// @brief Tests that for a given configuration the rapid-commit works (or not)
///
/// The provided configuration is expected to be able to handle two clients.
/// The second parameter governs whether rapid-commit is expected to be enabled
/// or disabled. Third and fourth parameters are text representations of expected
/// leases to be assigned (if rapid-commit is enabled)
///
/// @param config - text version of the configuration to be tested
/// @param enabled - true = rapid-commit is expected to work
/// @param exp_addr1 - an address the first client is expected to get (if
/// rapid-commit is enabled).
/// @param exp_addr2 - an address the second client is expected to get (if
/// rapid-commit is enabled).
void testRapidCommit(const std::string& config, bool enabled,
const std::string& exp_addr1,
const std::string& exp_addr2) {
// Create client #1. This clients wants to use rapid-commit.
Dhcp6Client client1;
client1.setInterface("eth1");
client1.useRapidCommit(true);
Dhcp6Client client2;
client2.setInterface("eth1");
client2.useRapidCommit(true);
// Configure the server with a shared network.
ASSERT_NO_FATAL_FAILURE(configure(config, *client1.getServer()));
// Ok, client should have one
EXPECT_EQ(0, client1.getLeaseNum());
// Client #1 should be assigned an address from shared network. The first
// subnet has rapid-commit enabled, so the address should be assigned.
// We provide a hint for this allocation to make sure that the address
// from the first subnet is allocated. In theory, an address from the
// second subnet could be allocated as well if the hint was not provided.
IOAddress requested_address = exp_addr1.empty() ? IOAddress::IPV6_ZERO_ADDRESS() :
IOAddress(exp_addr1);
ASSERT_NO_THROW(client1.requestAddress(0xabca0, requested_address));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSolicit());
});
// Make sure something was sent back.
ASSERT_TRUE(client1.getContext().response_);
if (enabled) {
// rapid-commit enabled.
// Make sure that REPLY was sent back.
EXPECT_EQ(DHCPV6_REPLY, client1.getContext().response_->getType());
// Just make sure the client didn't get an address.
EXPECT_TRUE(hasLeaseForAddress(client1, IOAddress(exp_addr1),
LeaseOnServer::MUST_EXIST));
} else {
// rapid-commit disabled.
// Make sure that ADVERTISE was sent back.
EXPECT_EQ(DHCPV6_ADVERTISE, client1.getContext().response_->getType());
// And that it doesn't have any leases.
EXPECT_EQ(0, client1.getLeaseNum());
}
// Create client #2. This client behaves the same as the first one, but the
// first subnet is already full (it's a really small subnet) and the second
// subnet does not allow rapid-commit.
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSolicit());
});
// Make sure something was sent back.
ASSERT_TRUE(client2.getContext().response_);
if (enabled) {
// rapid-commit enabled.
// Make sure that REPLY was sent back.
EXPECT_EQ(DHCPV6_REPLY, client2.getContext().response_->getType());
// Just make sure the client didn't get an address.
EXPECT_TRUE(hasLeaseForAddress(client2, IOAddress(exp_addr2),
LeaseOnServer::MUST_EXIST));
} else {
// rapid-commit disabled.
// Make sure that ADVERTISE was sent back.
EXPECT_EQ(DHCPV6_ADVERTISE, client1.getContext().response_->getType());
// And that it doesn't have any leases.
EXPECT_EQ(0, client1.getLeaseNum());
}
}
/// @brief Check precedence.
///
/// @param config the configuration.
/// @param ns_address expected name server address.
void testPrecedence(const std::string& config, const std::string& ns_address) {
// Create client and set DUID to the one that has a reservation.
Dhcp6Client client;
client.setInterface("eth1");
client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff");
client.requestAddress(0xabca, IOAddress("2001:db8:1::28"));
// Request dns-servers.
client.requestOption(D6O_NAME_SERVERS);
// Create server configuration.
configure(config, *client.getServer());
// Perform SARR.
ASSERT_NO_THROW(client.doSARR());
// Check response.
EXPECT_EQ(1, client.getLeaseNum());
Pkt6Ptr resp = client.getContext().response_;
ASSERT_TRUE(resp);
// Check dns-servers option.
OptionPtr opt = resp->getOption(D6O_NAME_SERVERS);
ASSERT_TRUE(opt);
Option6AddrLstPtr servers =
boost::dynamic_pointer_cast<Option6AddrLst>(opt);
ASSERT_TRUE(servers);
auto addrs = servers->getAddresses();
ASSERT_EQ(1, addrs.size());
EXPECT_EQ(ns_address, addrs[0].toText());
}
// @brief Test that different allocator types can be used within a shared network.
//
// All available prefixes should be delegated from the subnets belonging to
// the shared network.
//
/// @param config server configuration that should contain a shared network with
/// two subnets. Each subnet should contain a prefix pool with 16 prefixes.
void testDifferentAllocatorsInNetwork(const std::string& config) {
// Create the base client and server configuration.
Dhcp6Client client;
ASSERT_NO_FATAL_FAILURE(configure(config, *client.getServer()));
// Record what prefixes have been allocated.
std::set<std::string> allocated_set;
// Simulate allocations from different clients.
for (auto i = 0; i < 32; ++i) {
// Create a client from the base client.
Dhcp6Client next_client(client.getServer());
next_client.setInterface("eth1");
next_client.requestPrefix();
// Run 4-way exchange.
ASSERT_NO_THROW(next_client.doSARR());
// Make sure that the server responded.
ASSERT_TRUE(next_client.getContext().response_);
auto leases = next_client.getLeasesByType(Lease::TYPE_PD);
ASSERT_EQ(1, leases.size());
// Make sure that the prefix is not zero.
ASSERT_FALSE(leases[0].addr_.isV6Zero());
// Remember the allocated prefix uniqueness.
allocated_set.insert(leases[0].addr_.toText());
}
// Make sure that we have 32 distinct allocations.
ASSERT_EQ(32, allocated_set.size());
// Try one more time. This time no leases should be allocated because
// the pools are exhausted.
Dhcp6Client next_client(client.getServer());
next_client.setInterface("eth1");
next_client.requestPrefix();
ASSERT_NO_THROW(next_client.doSARR());
ASSERT_TRUE(next_client.getContext().response_);
auto leases = next_client.getLeasesByType(Lease::TYPE_PD);
EXPECT_TRUE(leases.empty());
}
/// @brief Destructor.
virtual ~Dhcpv6SharedNetworkTest() {
StatsMgr::instance().removeAll();
}
/// @brief Interface Manager's fake configuration control.
IfaceMgrTestConfig iface_mgr_test_config_;
};
// Check user-context parsing
TEST_F(Dhcpv6SharedNetworkTest, parse) {<--- syntax error
// Create client
Dhcp6Client client1;
// Don't use configure from utils
Parser6Context ctx;
ConstElementPtr json;
ASSERT_NO_THROW(json = parseDHCP6(NETWORKS_CONFIG[0], true));
ConstElementPtr status;
disableIfacesReDetect(json);
EXPECT_NO_THROW(status = configureDhcp6Server(*client1.getServer(), json));
ASSERT_TRUE(status);
int rcode;
ConstElementPtr comment = config::parseAnswer(rcode, status);
ASSERT_EQ(0, rcode);
CfgMgr::instance().commit();
CfgSharedNetworks6Ptr cfg = CfgMgr::instance().getCurrentCfg()->getCfgSharedNetworks6();
SharedNetwork6Ptr network = cfg->getByName("frog");
ConstElementPtr context = network->getContext();
ASSERT_TRUE(context);
ASSERT_EQ(1, context->size());
ASSERT_TRUE(context->get("comment"));
EXPECT_EQ("\"example\"", context->get("comment")->str());
}
// Running out of addresses within a subnet in a shared network.
TEST_F(Dhcpv6SharedNetworkTest, addressPoolInSharedNetworkShortage) {
// Create client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
// Configure the server with one shared network including two subnets and
// one subnet outside of the shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[0], *client1.getServer()));
// Client #1 requests an address in first subnet within a shared network.
ASSERT_NO_THROW(client1.requestAddress(0xabca0, IOAddress("2001:db8:1::20")));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Client #2 The second client will request a lease and should be assigned
// an address from the second subnet.
Dhcp6Client client2(client1.getServer());
client2.setInterface("eth1");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
// Client #3. It sends Solicit which should result in NoAddrsAvail status
// code because all addresses available for this link have been assigned.
Dhcp6Client client3(client1.getServer());
client3.setInterface("eth1");
ASSERT_NO_THROW(client3.requestAddress(0xabca0));
testAssigned([&client3] {
ASSERT_NO_THROW(client3.doSolicit(true));
});
EXPECT_EQ(0, client3.getLeaseNum());
// Client #3 should be assigned an address if subnet 3 is selected for it.
client3.setInterface("eth0");
testAssigned([&client3] {
ASSERT_NO_THROW(client3.doSolicit(true));
});
EXPECT_EQ(1, client3.getLeaseNum());
// Client #1 should be able to renew its lease.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRenew());
});
EXPECT_EQ(1, client1.getLeaseNum());
EXPECT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Client #2 should be able to renew its lease too.
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(1, client2.getLeaseNum());
EXPECT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
}
// Shared network is selected based on relay link address.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectedByRelay) {
// Create client #1. This is a relayed client which is using relay address
// matching configured shared network.
Dhcp6Client client1;
client1.useRelay(true, IOAddress("3001::1"));
// Configure the server with one shared network and one subnet outside of the
// shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[1], *client1.getServer()));
// Client #1 should be assigned an address from shared network.
ASSERT_NO_THROW(client1.requestAddress(0xabca0));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Create client #2. This is a relayed client which is using relay
// address matching subnet outside of the shared network.
Dhcp6Client client2(client1.getServer());
client2.useRelay(true, IOAddress("3001::2"));
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
}
// Providing a hint for any address belonging to a shared network.
TEST_F(Dhcpv6SharedNetworkTest, hintWithinSharedNetwork) {
// Create client #1.
Dhcp6Client client;
client.setInterface("eth1");
// Configure the server with one shared network including two subnets and
// one subnet outside of the shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[0], *client.getServer()));
// Provide a hint to an existing address within first subnet. This address
// should be offered out of this subnet.
ASSERT_NO_THROW(client.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSolicit(true));
});
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::20"),
LeaseOnServer::MUST_NOT_EXIST));
// Similarly, we should be offered an address from another subnet within
// the same shared network when we ask for it.
client.clearRequestedIAs();
ASSERT_NO_THROW(client.requestAddress(0xabca, IOAddress("2001:db8:2::20")));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSolicit(true));
});
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::20"),
LeaseOnServer::MUST_NOT_EXIST));
// Asking for an address that is not in address pool should result in getting
// an address from one of the subnets, but generally hard to tell from which one.
client.clearRequestedIAs();
ASSERT_NO_THROW(client.requestAddress(0xabca, IOAddress("3002::123")));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSolicit(true));
});
std::vector<Lease6> leases = client.getLeasesByType(Lease::TYPE_NA);
ASSERT_EQ(1, leases.size());
if (!hasLeaseForAddress(client, IOAddress("2001:db8:1::20"),
LeaseOnServer::MUST_NOT_EXIST) &&
!hasLeaseForAddress(client, IOAddress("2001:db8:2::20"),
LeaseOnServer::MUST_NOT_EXIST)) {
ADD_FAILURE() << "Unexpected address advertised by the server " << leases.at(0).addr_;
}
}
// Shared network is selected based on the client class specified.
TEST_F(Dhcpv6SharedNetworkTest, subnetInSharedNetworkSelectedByClass) {
// Create client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
// Configure the server with one shared network including two subnets and
// one subnet outside of the shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[2], *client1.getServer()));
// Client #1 requests an address in the restricted subnet but can't be assigned
// this address because the client doesn't belong to a certain class.
ASSERT_NO_THROW(client1.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:2::20")));
// Release the lease that the client has got, because we'll need this address
// further in the test.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRelease());
});
// Add option 1234 which would cause the client to be classified as "a-devices".
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0001));
client1.addExtraOption(option1234);
// This time, the allocation of the address provided as hint should be successful.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Client 2 should be assigned an address from the unrestricted subnet.
Dhcp6Client client2(client1.getServer());
client2.setInterface("eth1");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
// Now, let's reconfigure the server to also apply restrictions on the
// subnet to which client2 now belongs.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[3], *client1.getServer()));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(0, client2.getLeaseNum());
// If we add option 1234 with a value matching this class, the lease should
// get renewed.
OptionPtr option1234_bis(new OptionUint16(Option::V6, 1234, 0x0002));
client2.addExtraOption(option1234_bis);
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(1, client2.getLeaseNum());
}
// IPv6 address reservation exists in one of the subnets within shared network.
TEST_F(Dhcpv6SharedNetworkTest, reservationInSharedNetwork) {
// Create client #1. Explicitly set client's DUID to the one that has a
// reservation in the second subnet within shared network.
Dhcp6Client client1;
client1.setInterface("eth1");
client1.setDUID("00:03:00:01:11:22:33:44:55:66");
// Create server configuration with a shared network including two subnets. There
// is an IP address reservation in each subnet for two respective clients.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[4], *client1.getServer()));
// Client #1 should get his reserved address from the second subnet.
ASSERT_NO_THROW(client1.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:2::28")));
// Create client #2.
Dhcp6Client client2;
client2.setInterface("eth1");
client2.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff");
// Client #2 should get its reserved address from the first subnet.
ASSERT_NO_THROW(client2.requestAddress(0xabca, IOAddress("2001:db8:1::30")));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:1::28")));
// Reconfigure the server. Now, the first client get's second client's
// reservation and vice versa.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[5], *client1.getServer(), true, true, false));
// The first client is trying to renew the lease but should get a different lease
// because its lease is now reserved for some other client. The client won't be
// assigned a lease for which it has a reservation because another client holds
// this lease.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRenew());
});
ASSERT_TRUE(client1.hasLeaseWithZeroLifetimeForAddress(IOAddress("2001:db8:2::28")));
ASSERT_FALSE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::28")));
// The client should be allocated a lease from one of the dynamic pools.
if (!hasLeaseForAddressRange(client1, IOAddress("2001:db8:2::1"), IOAddress("2001:db8:2::64")) &&
!hasLeaseForAddressRange(client1, IOAddress("2001:db8:1::1"), IOAddress("2001:db8:1::64"))) {
ADD_FAILURE() << "unexpected lease allocated for renewing client";
}
// Client #2 is now renewing its lease and should get its newly reserved address.
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
ASSERT_TRUE(client2.hasLeaseWithZeroLifetimeForAddress(IOAddress("2001:db8:1::28")));
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::28")));
// Same for client #1.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRenew());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::28")));
}
// Reserved address can't be assigned as long as access to a subnet is
// restricted by classification.
TEST_F(Dhcpv6SharedNetworkTest, reservationAccessRestrictedByClass) {
// Create client #1. Explicitly set client's DUID to the one that has a
// reservation in the firstsubnet within shared network.
Dhcp6Client client;
client.setInterface("eth1");
client.setDUID("00:03:00:01:aa:bb:cc:dd:ee:ff");
// Create server configuration with a shared network including two subnets. Access to
// one of the subnets is restricted by client classification.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[6], *client.getServer()));
// Assigned address should be allocated from the second subnet, because the
// client doesn't belong to the "a-devices" class.
ASSERT_NO_THROW(client.requestAddress(0xabca));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::16")));
// Add option 1234 which would cause the client to be classified as "a-devices".
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0001));
client.addExtraOption(option1234);
// The client should now be assigned the reserved address from the first subnet.
testAssigned([&client] {
ASSERT_NO_THROW(client.doRenew());
});
ASSERT_TRUE(client.hasLeaseWithZeroLifetimeForAddress(IOAddress("2001:db8:2::16")));
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::28")));
}
// Subnet in which the client is renewing an address is restricted by classification.
TEST_F(Dhcpv6SharedNetworkTest, renewalRestrictedByClass) {
// Create client.
Dhcp6Client client;
client.setInterface("eth1");
// Create server configuration with a shared network including two subnets. Access to
// the second subnet is restricted by client classification.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[12], *client.getServer()));
// Add option 1234 to cause the client to belong to the class.
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0002));
client.addExtraOption(option1234);
// Client requests an address from the second subnet which should be successful.
ASSERT_NO_THROW(client.requestAddress(0xabca, IOAddress("2001:db8:2::20")));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::20")));
// Now remove the client from this class.
client.clearExtraOptions();
// The client should not be able to renew the existing lease because it is now
// prohibited by the classification. Instead, the client should get a lease from the
// unrestricted subnet.
testAssigned([&client] {
ASSERT_NO_THROW(client.doRenew());
});
ASSERT_TRUE(client.hasLeaseWithZeroLifetimeForAddress(IOAddress("2001:db8:2::20")));
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::20")));
}
// Some options are specified on the shared subnet level, some on the
// subnets level.
TEST_F(Dhcpv6SharedNetworkTest, optionsDerivation) {
// Client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[7], *client1.getServer()));
// Client #1 belongs to shared network. By providing a hint "2001:db8:1::20 we force
// the server to select first subnet within the shared network for this client.
ASSERT_NO_THROW(client1.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
// Request all configured options.
ASSERT_NO_THROW(client1.requestOption(D6O_NIS_SERVERS));
ASSERT_NO_THROW(client1.requestOption(D6O_NISP_SERVERS));
ASSERT_NO_THROW(client1.requestOption(D6O_NAME_SERVERS));
ASSERT_NO_THROW(client1.requestOption(D6O_SNTP_SERVERS));
// Perform 4-way exchange and make sure we have been assigned address from the
// subnet we wanted.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// This option is specified on the global level.
ASSERT_TRUE(client1.hasOptionWithAddress(D6O_NIS_SERVERS, "3000::20"));
// Subnet specific value should override a value specified on the shared network level.
ASSERT_TRUE(client1.hasOptionWithAddress(D6O_NISP_SERVERS, "3003::33"));
// Shared network level value should be derived to the subnet.
ASSERT_TRUE(client1.hasOptionWithAddress(D6O_NAME_SERVERS, "3001::21"));
// This option is only specified in the subnet level.
ASSERT_TRUE(client1.hasOptionWithAddress(D6O_SNTP_SERVERS, "4004::22"));
// Client #2.
Dhcp6Client client2(client1.getServer());
client2.setInterface("eth1");
// Request an address from the second subnet within the shared network.
ASSERT_NO_THROW(client2.requestAddress(0xabca, IOAddress("2001:db8:2::20")));
// Request all configured options.
ASSERT_NO_THROW(client2.requestOption(D6O_NIS_SERVERS));
ASSERT_NO_THROW(client2.requestOption(D6O_NISP_SERVERS));
ASSERT_NO_THROW(client2.requestOption(D6O_NAME_SERVERS));
ASSERT_NO_THROW(client2.requestOption(D6O_SNTP_SERVERS));
// Perform 4-way exchange and make sure we have been assigned address from the
// subnet we wanted.
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
// This option is specified on the global level.
ASSERT_TRUE(client2.hasOptionWithAddress(D6O_NIS_SERVERS, "3000::20"));
// Shared network level value should be derived to the subnet.
ASSERT_TRUE(client2.hasOptionWithAddress(D6O_NAME_SERVERS, "3001::21"));
ASSERT_TRUE(client2.hasOptionWithAddress(D6O_NISP_SERVERS, "3002::34"));
// Client #3.
Dhcp6Client client3(client1.getServer());
client3.setInterface("eth0");
// Request an address from the subnet outside of the shared network.
ASSERT_NO_THROW(client3.requestAddress(0xabca, IOAddress("3000::1")));
// Request all configured options.
ASSERT_NO_THROW(client3.requestOption(D6O_NIS_SERVERS));
ASSERT_NO_THROW(client3.requestOption(D6O_NISP_SERVERS));
ASSERT_NO_THROW(client3.requestOption(D6O_NAME_SERVERS));
ASSERT_NO_THROW(client3.requestOption(D6O_SNTP_SERVERS));
// Perform 4-way exchange and make sure we have been assigned address from the
// subnet we wanted.
testAssigned([&client3] {
ASSERT_NO_THROW(client3.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client3, IOAddress("3000::1")));
// This option is specified on the global level.
ASSERT_TRUE(client3.hasOptionWithAddress(D6O_NIS_SERVERS, "3000::20"));
// Subnet specific value should be assigned.
ASSERT_TRUE(client3.hasOptionWithAddress(D6O_NISP_SERVERS, "4000::5"));
}
// The same option is specified differently for each subnet belonging to the
// same shared network.
TEST_F(Dhcpv6SharedNetworkTest, optionsFromSelectedSubnet) {
// Create a client.
Dhcp6Client client;
client.setInterface("eth1");
// Create configuration with one shared network including three subnets with
// the same option having different values.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[16], *client.getServer()));
// Client provides no hint and any subnet can be picked from the shared network.
ASSERT_NO_THROW(client.requestAddress(0xabca));
// Request Name Servers option.
ASSERT_NO_THROW(client.requestOption(D6O_NAME_SERVERS));
// Send solicit without a hint. The client should be offered an address from the
// shared network. Depending on the subnet from which the address has been allocated
// a specific value of the Name Servers option should be returned.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSolicit(true));
});
if (client.hasLeaseForAddress(IOAddress("2001:db8:1::20"))) {
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "4004::22"));
} else if (client.hasLeaseForAddress(IOAddress("2001:db8:2::20"))) {
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
} else if (client.hasLeaseForAddress(IOAddress("2001:db8:3::20"))) {
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "1234::23"));
}
// This time let's provide a hint.
client.clearRequestedIAs();
client.requestAddress(0xabca, IOAddress("2001:db8:2::20"));
testAssigned([&client] {
ASSERT_NO_THROW(client.doSolicit(true));
});
ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
// This time, let's do the 4-way exchange.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
// And renew the lease.
testAssigned([&client] {
ASSERT_NO_THROW(client.doRenew());
});
ASSERT_TRUE(client.hasLeaseForAddress(IOAddress("2001:db8:2::20")));
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "5555::33"));
}
// Different shared network is selected for different local interface.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectionByInterface) {
// Create client #1. The server receives requests from this client
// via interface eth1 and should assign shared network "frog" for
// this client.
Dhcp6Client client1;
client1.setInterface("eth1");
client1.requestAddress(0xabca);
// Create server configuration with two shared networks selected
// by the local interface: eth1 and eth0.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[8], *client1.getServer()));
// Client #1 should be assigned an address from one of the two subnets
// belonging to the first shared network.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
if (!hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")) &&
!hasLeaseForAddress(client1, IOAddress("2001:db8:2::20"))) {
ADD_FAILURE() << "unexpected shared network selected for the client";
}
// Client #2.
Dhcp6Client client2;
client2.setInterface("eth0");
client2.requestAddress(0xabca);
// Client #2 should be assigned an address from one of the two subnets
// belonging to the second shared network.
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
if (!hasLeaseForAddress(client2, IOAddress("2001:db8:3::20")) &&
!hasLeaseForAddress(client2, IOAddress("2001:db8:4::20"))) {
ADD_FAILURE() << "unexpected shared network selected for the client";
}
}
// Different shared network is selected for different relay address.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectionByRelay) {
// Create relayed client #1.
Dhcp6Client client1;
client1.useRelay(true, IOAddress("3000::1"));
client1.requestAddress(0xabcd);
// Create server configuration with two shared networks selected
// by the relay address.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[9], *client1.getServer()));
// Client #1 should be assigned an address from one of the two subnets
// belonging to the first shared network.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
if (!hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")) &&
!hasLeaseForAddress(client1, IOAddress("2001:db8:2::20"))) {
ADD_FAILURE() << "unexpected shared network selected for the client";
}
// Create relayed client #2.
Dhcp6Client client2;
client2.useRelay(true, IOAddress("3000::2"));
client2.requestAddress(0xabca);
// Client #2 should be assigned an address from one of the two subnets
// belonging to the second shared network
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
if (!hasLeaseForAddress(client2, IOAddress("2001:db8:3::20")) &&
!hasLeaseForAddress(client2, IOAddress("2001:db8:4::20"))) {
ADD_FAILURE() << "unexpected shared network selected for the client";
}
}
// Host reservations include hostname and client class.
TEST_F(Dhcpv6SharedNetworkTest, variousFieldsInReservation) {
// Create client #1.
Dhcp6Client client;
client.setInterface("eth1");
client.setDUID("00:03:00:01:11:22:33:44:55:66");
ASSERT_NO_THROW(client.requestAddress(0xabcd));
ASSERT_NO_THROW(client.requestOption(D6O_NAME_SERVERS));
ASSERT_NO_THROW(client.useFQDN(Option6ClientFqdn::FLAG_S,
"bird.example.org",
Option6ClientFqdn::FULL));
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[10], *client.getServer()));
// Perform 4-way exchange.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
// The client should get an FQDN from the reservation, rather than
// the FQDN it has sent to the server. If there is a logic error,
// the server would use the first subnet from the shared network to
// assign the FQDN. This subnet has no reservation so it would
// return the same FQDN that the client has sent. We expect
// that the FQDN being sent is the one that is included in the
// reservations.
ASSERT_TRUE(client.getContext().response_);
OptionPtr opt_fqdn = client.getContext().response_->getOption(D6O_CLIENT_FQDN);
ASSERT_TRUE(opt_fqdn);
Option6ClientFqdnPtr fqdn = boost::dynamic_pointer_cast<Option6ClientFqdn>(opt_fqdn);
ASSERT_TRUE(fqdn);
ASSERT_EQ("test.example.org.", fqdn->getDomainName());
// Make sure that the correct hostname has been stored in the database.
Lease6Ptr lease = LeaseMgrFactory::instance().getLease6(Lease::TYPE_NA,
IOAddress("2001:db8:2::20"));
ASSERT_TRUE(lease);
EXPECT_EQ("test.example.org.", lease->hostname_);
// The DNS servers option should be derived from the client class based on the
// static class reservations.
ASSERT_TRUE(client.hasOptionWithAddress(D6O_NAME_SERVERS, "2001:db8:1::50"));
}
// Shared network is selected based on the client class specified.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectedByClass) {
// Create client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
client1.requestAddress(0xabcd);
// Add option 1234 which would cause the client1 to be classified as "b-devices".
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0002));
client1.addExtraOption(option1234);
// Configure the server with two shared networks which can be accessed
// by clients belonging to "a-devices" and "b-devices" classes
// respectively.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[11], *client1.getServer()));
// The client 1 should be offered an address from the second subnet.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSolicit(true));
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:2::20"),
LeaseOnServer::MUST_NOT_EXIST));
// Create another client which will belong to a different class.
Dhcp6Client client2;
client2.setInterface("eth1");
client2.requestAddress(0xabcd);
/// Add option 1234 which will cause the client 2 to be classified as "a-devices".
option1234.reset(new OptionUint16(Option::V6, 1234, 0x0001));
client2.addExtraOption(option1234);
// Client 2 should be offered an address from the first subnet.
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSolicit(true));
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:1::20"),
LeaseOnServer::MUST_NOT_EXIST));
}
// Client requests two addresses and two prefixes and obtains them from two
// different subnets.
TEST_F(Dhcpv6SharedNetworkTest, assignmentsFromDifferentSubnets) {
// Create client.
Dhcp6Client client;
client.setInterface("eth1");
client.requestAddress(0xabcd);
client.requestAddress(0x1234);
client.requestPrefix(0x1111);
client.requestPrefix(0x2222);
// Configure the server with a shared network including two subnets. Each
// subnet has an address and prefix pool with a single available address
// and prefix respectively.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[0], *client.getServer()));
// 4-way exchange.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
// The two addresses should come from different subnets.
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::20")));
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::20")));
// Same for prefixes.
ASSERT_TRUE(hasLeaseForPrefixPool(client, IOAddress("4000::"), 96, 96));
ASSERT_TRUE(hasLeaseForPrefixPool(client, IOAddress("5000::"), 96, 96));
// Try to renew.
testAssigned([&client] {
ASSERT_NO_THROW(client.doRenew());
});
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::20")));
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::20")));
ASSERT_TRUE(hasLeaseForPrefixPool(client, IOAddress("4000::"), 96, 96));
ASSERT_TRUE(hasLeaseForPrefixPool(client, IOAddress("5000::"), 96, 96));
}
// Client requests 2 addresses and 2 prefixes. There is one address and one prefix
// reserved for the client.
TEST_F(Dhcpv6SharedNetworkTest, reservedAddressAndPrefix) {
// Create client.
Dhcp6Client client;
client.setInterface("eth1");
client.setDUID("00:03:00:01:11:22:33:44:55:66");
// Client will request two addresses and two prefixes.
client.requestAddress(0xabcd);
client.requestAddress(0x1234);
client.requestPrefix(0x1111);
client.requestPrefix(0x2222);
// The server configuration contains a shared network with two subnets. Each
// subnet has an address and prefix pool. One of the subnets includes a reservation
// for an address and prefix.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[4], *client.getServer()));
// 4-way exchange.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
ASSERT_EQ(4, client.getLeaseNum());
// The client should have got one reserved address and one reserved prefix.
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::28")));
ASSERT_TRUE(hasLeaseForPrefix(client, IOAddress("5000::8:0000"), 112, IAID(0x1111)));
// The client should have got dynamically allocated address too and it must be
// different than the reserved address.
std::vector<Lease6> leases_1234 = client.getLeasesByIAID(0x1234);
ASSERT_EQ(1, leases_1234.size());
ASSERT_NE("2001:db8:2::28", leases_1234[0].addr_.toText());
// Same for prefix.
std::vector<Lease6> leases_2222 = client.getLeasesByIAID(0x2222);
ASSERT_EQ(1, leases_2222.size());
ASSERT_NE("1234::", leases_2222[0].addr_.toText());
// Try to renew and check this again.
testAssigned([&client] {
ASSERT_NO_THROW(client.doRenew());
});
ASSERT_EQ(4, client.getLeaseNum());
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::28")));
ASSERT_TRUE(hasLeaseForPrefix(client, IOAddress("5000::8:0000"), 112, IAID(0x1111)));
leases_1234 = client.getLeasesByIAID(0x1234);
ASSERT_EQ(1, leases_1234.size());
ASSERT_NE("2001:db8:2::28", leases_1234[0].addr_.toText());
leases_2222 = client.getLeasesByIAID(0x2222);
ASSERT_EQ(1, leases_2222.size());
ASSERT_NE(IOAddress("5000::8:0000").toText(), leases_2222[0].addr_.toText());
}
// Relay address is specified for each subnet within shared network.
TEST_F(Dhcpv6SharedNetworkTest, relaySpecifiedForEachSubnet) {
// Create client.
Dhcp6Client client;
client.useRelay(true, IOAddress("3001::1"));
// Client will request two addresses.
client.requestAddress(0xabcd);
client.requestAddress(0x1234);
// Configure the server with three subnets. Two of them belong to a shared network.
// Each subnet is configured with relay info, i.e. IP address of the relay agent
// for which the shared network is used.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[13], *client.getServer()));
// 4-way exchange.
testAssigned([&client] {
ASSERT_NO_THROW(client.doSARR());
});
ASSERT_EQ(2, client.getLeaseNum());
// The client should have got two leases, one from each subnet within the
// shared network.
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:1::20")));
ASSERT_TRUE(hasLeaseForAddress(client, IOAddress("2001:db8:2::20")));
}
// Shared network is selected based on interface id.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectedByInterfaceId) {
// Create client #1. This is a relayed client for which interface id
// has been specified and this interface id is matching the one specified
// for the shared network.
Dhcp6Client client1;
client1.useRelay(true, IOAddress("3001::1"));
client1.useInterfaceId("vlan10");
// Configure the server with one shared network and one subnet outside of the
// shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[14], *client1.getServer()));
// Client #1 should be assigned an address from shared network.
ASSERT_NO_THROW(client1.requestAddress(0xabca0));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Create client #2. This is a relayed client which is using interface id
// matching a subnet outside of the shared network.
Dhcp6Client client2(client1.getServer());
client2.useRelay(true, IOAddress("3001::2"));
client2.useInterfaceId("vlan1000");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
}
// Shared network is selected based on interface id specified for a subnet
// belonging to a shared network.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkSelectedByInterfaceIdInSubnet) {
// Create client #1. This is a relayed client for which interface id
// has been specified and this interface id is matching the one specified
// for the shared network.
Dhcp6Client client1;
client1.useRelay(true, IOAddress("3001::1"));
client1.useInterfaceId("vlan10");
// Configure the server with one shared network and one subnet outside of the
// shared network.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[15], *client1.getServer()));
// Client #1 should be assigned an address from shared network.
ASSERT_NO_THROW(client1.requestAddress(0xabca0));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Create client #2. This is a relayed client which is using interface id
// matching a subnet outside of the shared network.
Dhcp6Client client2(client1.getServer());
client2.useRelay(true, IOAddress("3001::2"));
client2.useInterfaceId("vlan1000");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:2::20")));
}
// Check that the rapid-commit works with shared networks. Rapid-commit
// enabled on each subnet separately.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkRapidCommit1) {
testRapidCommit(NETWORKS_CONFIG[17], true, "2001:db8:1::20", "2001:db8:2::20");
}
// Check that the rapid-commit works with shared networks. Rapid-commit
// enabled for the whole shared network. This should be applied to both
// subnets.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkRapidCommit2) {
testRapidCommit(NETWORKS_CONFIG[18], true, "2001:db8:1::20", "2001:db8:2::20");
}
// Check that the rapid-commit is disabled by default.
TEST_F(Dhcpv6SharedNetworkTest, sharedNetworkRapidCommit3) {
testRapidCommit(NETWORKS_CONFIG[1], false, "", "");
}
// Pool is selected based on the client class specified.
TEST_F(Dhcpv6SharedNetworkTest, poolInSharedNetworkSelectedByClass) {
// Create client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
// Configure the server with one shared network including one subnet and
// two pools. The access to one of the pools is restricted by
// by client classification.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[19], *client1.getServer()));
// Client #1 requests an address in the restricted pool but can't be assigned
// this address because the client doesn't belong to a certain class.
ASSERT_NO_THROW(client1.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::50")));
// Release the lease that the client has got, because we'll need this address
// further in the test.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRelease());
});
// Add option 1234 which would cause the client to be classified as "a-devices".
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0001));
client1.addExtraOption(option1234);
// This time, the allocation of the address provided as hint should be successful.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Client 2 should be assigned an address from the unrestricted pool.
Dhcp6Client client2(client1.getServer());
client2.setInterface("eth1");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:1::50")));
// Now, let's reconfigure the server to also apply restrictions on the
// pool to which client2 now belongs.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[20], *client1.getServer()));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(0, client2.getLeasesWithNonZeroLifetime().size());
// If we add option 1234 with a value matching this class, the lease should
// get renewed.
OptionPtr option1234_bis(new OptionUint16(Option::V6, 1234, 0x0002));
client2.addExtraOption(option1234_bis);
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(1, client2.getLeaseNum());
EXPECT_EQ(1, client2.getLeasesWithNonZeroLifetime().size());
}
// Pool is selected based on the client class specified using a plain subnet.
TEST_F(Dhcpv6SharedNetworkTest, poolInSubnetSelectedByClass) {
// Create client #1.
Dhcp6Client client1;
client1.setInterface("eth1");
// Configure the server with one plain subnet including two pools.
// The access to one of the pools is restricted by client classification.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[21], *client1.getServer()));
// Client #1 requests an address in the restricted pool but can't be assigned
// this address because the client doesn't belong to a certain class.
ASSERT_NO_THROW(client1.requestAddress(0xabca, IOAddress("2001:db8:1::20")));
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::50")));
// Release the lease that the client has got, because we'll need this address
// further in the test.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doRelease());
});
// Add option 1234 which would cause the client to be classified as "a-devices".
OptionPtr option1234(new OptionUint16(Option::V6, 1234, 0x0001));
client1.addExtraOption(option1234);
// This time, the allocation of the address provided as hint should be successful.
testAssigned([&client1] {
ASSERT_NO_THROW(client1.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client1, IOAddress("2001:db8:1::20")));
// Client 2 should be assigned an address from the unrestricted pool.
Dhcp6Client client2(client1.getServer());
client2.setInterface("eth1");
ASSERT_NO_THROW(client2.requestAddress(0xabca0));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doSARR());
});
ASSERT_TRUE(hasLeaseForAddress(client2, IOAddress("2001:db8:1::50")));
// Now, let's reconfigure the server to also apply restrictions on the
// pool to which client2 now belongs.
ASSERT_NO_FATAL_FAILURE(configure(NETWORKS_CONFIG[22], *client1.getServer()));
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(0, client2.getLeasesWithNonZeroLifetime().size());
// If we add option 1234 with a value matching this class, the lease should
// get renewed.
OptionPtr option1234_bis(new OptionUint16(Option::V6, 1234, 0x0002));
client2.addExtraOption(option1234_bis);
testAssigned([&client2] {
ASSERT_NO_THROW(client2.doRenew());
});
EXPECT_EQ(1, client2.getLeaseNum());
EXPECT_EQ(1, client2.getLeasesWithNonZeroLifetime().size());
}
// Test that different allocator types can be used within a shared network.
// The first subnet uses the random allocator. The second subnet uses the FLQ
// allocator.
TEST_F(Dhcpv6SharedNetworkTest, randomAndFlqAllocation) {
testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[23]);
}
// Test that different allocator types can be used within a shared network.
// The first subnet uses the FLQ allocator. The second subnet uses the random
// allocator.
TEST_F(Dhcpv6SharedNetworkTest, flqAndRandomAllocation) {
testDifferentAllocatorsInNetwork(NETWORKS_CONFIG[24]);
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceGlobal) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::1");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceClass) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::2");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceClasses) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"beta\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" },"
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::3\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
// Class order is the insert order
testPrecedence(config, "2001:db8:1::2");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceNetworkClass) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::3\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::3");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceSubnet) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::3\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::4\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\""
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::4");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedencePool) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::3\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::4\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::5\""
" }"
" ]"
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::5");
}
// Verify option processing precedence
// Order is global < class < shared-network < subnet < pools < host reservation
TEST_F(Dhcpv6SharedNetworkTest, precedenceReservation) {
const std::string config =
"{"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::1\""
" }"
" ],"
" \"client-classes\": ["
" {"
" \"name\": \"alpha\","
" \"test\": \"'' == ''\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::2\""
" }"
" ]"
" }"
" ],"
" \"shared-networks\": ["
" {"
" \"name\": \"frog\","
" \"interface\": \"eth1\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::3\""
" }"
" ],"
" \"subnet6\": ["
" {"
" \"subnet\": \"2001:db8:1::/64\","
" \"id\": 10,"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::4\""
" }"
" ],"
" \"pools\": ["
" {"
" \"pool\": \"2001:db8:1::1 - 2001:db8:1::64\","
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::5\""
" }"
" ]"
" }"
" ],"
" \"reservations\": ["
" {"
" \"duid\": \"00:03:00:01:aa:bb:cc:dd:ee:ff\","
" \"ip-addresses\": [ \"2001:db8:1::28\" ],"
" \"option-data\": ["
" {"
" \"name\": \"dns-servers\","
" \"data\": \"2001:db8:1::6\""
" }"
" ]"
" }"
" ]"
" }"
" ]"
" }"
" ]"
"}";
testPrecedence(config, "2001:db8:1::6");
}
} // end of anonymous namespace
|