summaryrefslogtreecommitdiffstats
path: root/nat/nat-api/src/main/yang/ietf-nat@2018-02-23.yang
blob: 77e2d7be723da95e32efff919412497d0b29a8c6 (plain)
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
module ietf-nat {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:ietf-nat";
  prefix "nat";

  import ietf-inet-types {
    prefix inet;
    reference
      "Section 4 of RFC 6991";
  }

  import ietf-yang-types {
    prefix yang;
    reference
      "Section 3 of RFC 6991";
  }

  import ietf-interfaces {
    prefix if;
    reference
      "RFC 8343: A YANG Data Model for Interface Management";
  }

  organization
    "IETF OPSAWG (Operations and Management Area Working Group)";

  contact

    "WG Web:   <https://datatracker.ietf.org/wg/opsawg/>
     WG List:  <mailto:opsawg@ietf.org>

     Editor:  Mohamed Boucadair
              <mailto:mohamed.boucadair@orange.com>

     Editor:  Senthil Sivakumar
              <mailto:ssenthil@cisco.com>

     Editor:  Christian Jacquenet
              <mailto:christian.jacquenet@orange.com>

     Editor:  Suresh Vinapamula
              <mailto:sureshk@juniper.net>

     Editor:  Qin Wu
              <mailto:bill.wu@huawei.com>";

  description
    "This module is a YANG module for NAT implementations.

     NAT44, Network Address and Protocol Translation from IPv6
     Clients to IPv4 Servers (NAT64), Customer-side transLATor (CLAT),
     Stateless IP/ICMP Translation (SIIT), Explicit Address Mappings
     for Stateless IP/ICMP Translation (SIIT EAM), IPv6 Network
     Prefix Translation (NPTv6), and Destination NAT are covered.

     Copyright (c) 2018 IETF Trust and the persons identified as
     authors of the code.  All rights reserved.

     Redistribution and use in source and binary forms, with or
     without modification, is permitted pursuant to, and subject
     to the license terms contained in, the Simplified BSD License
     set forth in Section 4.c of the IETF Trust's Legal Provisions
     Relating to IETF Documents
     (http://trustee.ietf.org/license-info).

     This version of this YANG module is part of RFC XXXX; see
     the RFC itself for full legal notices.";

  revision 2018-02-23 {
    description
      "Initial revision.";
    reference
      "RFC XXXX: A YANG Module for Network Address Translation
                 (NAT) and Network Prefix Translation (NPT)";
  }

  /*
   * Definitions
   */

  typedef percent {
    type uint8 {
      range "0 .. 100";
    }
    description
      "Percentage";
  }

  /*
   * Features
   */

  feature basic-nat44{
    description
      "Basic NAT44 translation is limited to IP addresses alone.";
    reference
      "RFC 3022: Traditional IP Network Address Translator
                 (Traditional NAT)";
  }

  feature napt44 {
    description
      "Network Address/Port Translator (NAPT): translation is
      extended to include IP addresses and transport identifiers
      (such as a TCP/UDP port or ICMP query ID).

      If the internal IP address is not sufficient to uniquely
      disambiguate NAPT44 mappings, an additional attribute is
      required. For example, that additional attribute may
      be an IPv6 address (a.k.a., DS-Lite) or
      a Layer 2 identifier (a.k.a., Per-Interface NAT)";
    reference
      "RFC 3022: Traditional IP Network Address Translator
                 (Traditional NAT)";
  }

  feature dst-nat {
    description
      "Destination NAT is a translation that acts on the destination
       IP address and/or destination port number. This flavor is
       usually deployed in load balancers or at devices
       in front of public servers.";
  }

  feature nat64 {
    description
      "NAT64 translation allows IPv6-only clients to contact IPv4
       servers using unicast UDP, TCP, or   ICMP.  One or more
       public IPv4 addresses assigned to a NAT64 translator are
       shared among several IPv6-only clients.";
    reference
      "RFC 6146: Stateful NAT64: Network Address and Protocol
                 Translation from IPv6 Clients to IPv4 Servers";
  }

  feature siit {
    description
      "The Stateless IP/ICMP Translation Algorithm (SIIT), which
       translates between IPv4 and IPv6 packet headers (including
       ICMP headers).

       In the stateless mode, an IP/ICMP translator converts IPv4
       addresses to IPv6 and vice versa solely based on the
       configuration of the stateless IP/ICMP translator and
       information contained within the packet being translated.

       The translator must support the stateless address mapping
       algorithm defined in RFC6052, which is the default behavior.";
    reference
      "RFC 7915: IP/ICMP Translation Algorithm";
  }

  feature clat {
    description
      "CLAT is customer-side translator that algorithmically
       translates 1:1 private IPv4 addresses to global IPv6 addresses,
       and vice versa.

       When a dedicated /64 prefix is not available for translation
       from DHCPv6-PD, the CLAT may perform NAT44 for all IPv4 LAN
       packets so that all the LAN-originated IPv4 packets appear
       from a single IPv4 address and are then statelessly translated
       to one interface IPv6 address that is claimed by the CLAT via
       the Neighbor Discovery Protocol (NDP) and defended with
       Duplicate Address Detection.";
    reference
      "RFC 6877: 464XLAT: Combination of Stateful and Stateless
                 Translation";
  }

  feature eam {
    description
      "Explicit Address Mapping (EAM) is a bidirectional coupling
       between an IPv4 Prefix and an IPv6 Prefix.";
    reference
     "RFC 7757: Explicit Address Mappings for Stateless IP/ICMP
                Translation";
  }

  feature nptv6 {
    description
      "NPTv6 is a stateless transport-agnostic IPv6-to-IPv6
       prefix translation.";
    reference
      "RFC 6296: IPv6-to-IPv6 Network Prefix Translation";
  }

  /*
   * Identities
   */

  identity nat-type {
    description
      "Base identity for nat type.";
  }

  identity basic-nat44 {
    base nat:nat-type;
    description
      "Identity for Basic NAT support.";
    reference
      "RFC 3022: Traditional IP Network Address Translator
                 (Traditional NAT)";
  }

  identity napt44 {
    base nat:nat-type;
    description
      "Identity for NAPT support.";
    reference
      "RFC 3022: Traditional IP Network Address Translator
                 (Traditional NAT)";
  }

  identity dst-nat {
    base nat:nat-type;
    description
      "Identity for Destination NAT support.";
  }

  identity nat64 {
    base nat:nat-type;
    description
      "Identity for NAT64 support.";
    reference
      "RFC 6146: Stateful NAT64: Network Address and Protocol
                 Translation from IPv6 Clients to IPv4 Servers";
  }

  identity siit {
    base nat:nat-type;
    description
      "Identity for SIIT support.";
    reference
      "RFC 7915: IP/ICMP Translation Algorithm";
  }

  identity clat {
    base nat:nat-type;
    description
      "Identity for CLAT support.";
    reference
      "RFC 6877: 464XLAT: Combination of Stateful and Stateless
                 Translation";
  }

  identity eam {
    base nat:nat-type;
    description
      "Identity for EAM support.";
    reference
     "RFC 7757: Explicit Address Mappings for Stateless IP/ICMP
                Translation";
  }

  identity nptv6 {
    base nat:nat-type;
    description
      "Identity for NPTv6 support.";
    reference
      "RFC 6296: IPv6-to-IPv6 Network Prefix Translation";
  }

 /*
  * Grouping
  */

  grouping port-number {
    description
      "Individual port or a range of ports.
       When only start-port-number is present,
       it represents a single port number.";

    leaf start-port-number {
      type inet:port-number;
      description
        "Beginning of the port range.";
      reference
        "Section 3.2.9 of RFC 8045.";
    }

    leaf end-port-number {
      type inet:port-number;

      must ". >= ../start-port-number"
        {
          error-message
            "The end-port-number must be greater than or
             equal to start-port-number.";
        }
      description
        "End of the port range.";
      reference
        "Section 3.2.10 of RFC 8045.";
    }
  }

  grouping port-set {
    description
      "Indicates a set of ports.

       It may be a simple port range, or use the Port Set ID (PSID)
       algorithm to represent a range of transport layer
       ports which will be used by a NAPT.";

    choice port-type {
      default port-range;
      description
        "Port type: port-range or port-set-algo.";
      case port-range {
         uses port-number;
       }

      case port-set-algo {
        leaf psid-offset {
          type uint8 {
            range 0..15;
          }

          description
            "The number of offset bits (a.k.a., 'a' bits).

             Specifies the numeric value for the excluded port
             range/offset bits.

             Allowed values are between 0 and 15 ";

          reference
            "Section 5.1 of RFC 7597";
        }

        leaf psid-len {
          type uint8 {
             range 0..15;
          }
          mandatory true;

         description
           "The length of PSID, representing the sharing
            ratio for an IPv4 address.

            (also known as 'k').

            The address-sharing ratio would be 2^k.";
          reference
            "Section 5.1 of RFC 7597";
        }

        leaf psid {
          type uint16;
          mandatory true;
          description
            "Port Set Identifier (PSID) value, which
             identifies a set of ports algorithmically.";
          reference
            "Section 5.1 of RFC 7597";
        }
      }
      reference
        "Section 7597: Mapping of Address and Port with
                       Encapsulation (MAP-E)";
    }
  }

  grouping mapping-entry {
    description
      "NAT mapping entry.

       If an attribute is not stored in the mapping/session table,
       this means the corresponding fields of a packet that
       matches this entry is not rewritten by the NAT or this
       information is not required for NAT filtering purposes.";

    leaf index {
      type uint32;
      description
        "A unique identifier of a mapping entry. This identifier can be
         automatically assigned by the NAT instance or be explicitly
         configured.";
    }

    leaf type {
      type enumeration {
        enum "static"  {
          description
            "The mapping entry is explicitly configured
             (e.g., via command-line interface).";
        }

        enum "dynamic-implicit" {
          description
            "This mapping is created implicitly as a side effect
             of processing a packet that requires a new mapping.";

        }

        enum "dynamic-explicit" {
          description
            "This mapping is created as a result of an explicit
             request, e.g., a PCP message.";

        }
      }
        description
          "Indicates the type of a mapping entry. E.g.,
           a mapping can be: static, implicit dynamic
           or explicit dynamic.";
    }

    leaf transport-protocol {
      type uint8;
      description
        "Upper-layer protocol associated with this mapping.
         Values are taken from the IANA protocol registry.
         For example, this field contains 6 (TCP) for a TCP
         mapping or 17 (UDP) for a UDP mapping.

         If this leaf is not instantiated, then the mapping
         applies to any protocol.";
    }

    leaf internal-src-address {
    // TODO(HC2VPP-325): original model uses inet:ip-prefix;
      type inet:ip-address;
      description
        "Corresponds to the source IPv4/IPv6 address/prefix
         of the packet received on an internal
         interface.";
    }

    container internal-src-port {
      description
        "Corresponds to the source port of the packet received
         on an internal interface.

         It is used also to indicate the internal source ICMP
         identifier.

         As a reminder, all the ICMP Query messages contain
         an 'Identifier' field, which is referred to in this
         document as the 'ICMP Identifier'.";

       uses port-number;
    }

    leaf external-src-address {
    // TODO(HC2VPP-325): original model uses inet:ip-prefix;
      type inet:ipv4-address;
      description
        "Source IP address/prefix of the packet sent on an
         external interface of the NAT.";
    }

    container external-src-port {
      description
        "Source port of the packet sent on an external
         interface of the NAT.
         It is used also to indicate the external source ICMP
         identifier.";

      uses port-number;
    }

    leaf internal-dst-address {
    // TODO(HC2VPP-325): original model uses inet:ip-prefix;
      type inet:ipv4-prefix;
      description
        "Corresponds to the destination IP address/prefix
         of the packet received on an internal interface
         of the NAT.

         For example, some NAT implementations support
         the translation of both source and destination
         addresses and ports, sometimes referred to
         as 'Twice NAT'.";
      }

    container internal-dst-port {
      description
        "Corresponds to the destination port of the
         IP packet received on the internal interface.

         It is used also to include the internal
         destination ICMP identifier.";

      uses port-number;
    }

    leaf external-dst-address {
    // TODO(HC2VPP-325): original model uses inet:ip-prefix;
      type inet:ipv4-address;
      description
        "Corresponds to the destination IP address/prefix
         of the packet sent on an external interface
         of the NAT.";
    }

    container external-dst-port {
      description
        "Corresponds to the destination port number of
         the packet sent on the external interface
         of the NAT.

         It is used also to include the external
         destination ICMP identifier.";

      uses port-number;
    }

    leaf lifetime {
      type uint32;
      units "seconds";
      description
        "When specified, it is used to track the connection that is
         fully-formed (e.g., once the three-way handshake
         TCP is completed) or the duration for maintaining
         an explicit mapping alive. The mapping entry will be
         removed by the NAT instance once this lifetime is expired.

         When reported in a get operation, the lifetime indicates
         the remaining validity lifetime.

         Static mappings may not be associated with a
         lifetime. If no lifetime is associated with a
         static mapping, an explicit action is required to
         remove that mapping.";
    }
  }

 /*
  * NAT Module
  */

  container nat {
    description
      "NAT module";

    container instances {
      description
        "NAT instances";

      list instance {
        key "id";

        description
          "A NAT instance. This identifier can be automatically assigned
           or explicitly configured.";

        leaf id {
          type uint32;
          must ". >= 1";
          description
            "NAT instance identifier.

             The identifier must be greater than zero.";
          reference
            "RFC 7659: Definitions of Managed Objects for Network
                     Address Translators (NATs)";
        }

        leaf name {
          type string;
          description
            "A name associated with the NAT instance.";
          reference
            "RFC 7659: Definitions of Managed Objects for Network
                     Address Translators (NATs)";
        }

        leaf enable {
          type boolean;
          description
            "Status of the  NAT instance.";
        }

        container capabilities {
          config false;

          description
            "NAT capabilities";

          leaf-list nat-flavor {
            type identityref {
              base nat-type;
            }
            description
              "Supported translation type(s).";
          }

          leaf-list per-interface-binding {
            type enumeration {
              enum "unsupported"  {
                description
                  "No capability to associate a NAT binding with
                   an extra identifier.";
            }

            enum "layer-2"  {
              description
                "The NAT instance is able to associate a mapping with
                 a layer-2 identifier.";
            }

            enum "dslite"  {
              description
                "The NAT instance is able to associate a mapping with
                 an IPv6 address (a.k.a., DS-Lite).";
            }
          }
          description
            "Indicates the capability of a NAT to associate a particular
             NAT session not only with the five tuples used for the
             transport connection on both sides of the NAT but also with
             the internal interface on which the user device is
             connected to the NAT.";
          reference
            "Section 4 of RFC 6619";
        }

        list transport-protocols {
          key protocol-id;

          description
            "List of supported protocols.";

          leaf protocol-id {
            type uint8;
            mandatory true;
            description
              "Upper-layer protocol associated with this mapping.

               Values are taken from the IANA protocol registry:
               https://www.iana.org/assignments/protocol-numbers/
               protocol-numbers.xhtml

               For example, this field contains 6 (TCP) for a TCP
               mapping or 17 (UDP) for a UDP mapping.";
          }

          leaf protocol-name {
            type string;
            description
              "The name of the Upper-layer protocol associated
               with this mapping.

               Values are taken from the IANA protocol registry:
               https://www.iana.org/assignments/protocol-numbers/
               protocol-numbers.xhtml

               For example, TCP, UDP, DCCP, and SCTP.";
          }
        }

        leaf restricted-port-support {
          type boolean;
          description
            "Indicates source port NAT restriction support.";
          reference
             "RFC 7596: Lightweight 4over6: An Extension to
                        the Dual-Stack Lite Architecture.";
        }

        leaf static-mapping-support {
          type boolean;
          description
            "Indicates whether static mappings are supported.";
        }

        leaf port-randomization-support {
          type boolean;
          description
            "Indicates whether port randomization is supported.";
          reference
            "Section 4.2.1 of RFC 4787.";
        }

        leaf port-range-allocation-support {
          type boolean;
          description
            "Indicates whether port range allocation is supported.";
          reference
            "Section 1.1 of RFC 7753.";
        }

        leaf port-preservation-suport {
          type boolean;
          description
            "Indicates whether port preservation is supported.";
          reference
            "Section 4.2.1 of RFC 4787.";
        }

        leaf port-parity-preservation-support {
          type boolean;
          description
            "Indicates whether port parity preservation is
             supported.";
          reference
            "Section 8 of RFC 7857.";
        }

        leaf address-roundrobin-support {
          type boolean;
          description
           "Indicates whether address allocation round robin is
            supported.";
        }

        leaf paired-address-pooling-support {
          type boolean;
          description
            "Indicates whether paired-address-pooling is
             supported";
           reference
             "REQ-2 of RFC 4787.";
        }

        leaf endpoint-independent-mapping-support {
          type boolean;
          description
            "Indicates whether endpoint-independent-
             mapping is supported.";
           reference
             "Section 4 of RFC 4787.";
        }

        leaf address-dependent-mapping-support {
          type boolean;
          description
            "Indicates whether address-dependent-mapping is
             supported.";
           reference
             "Section 4 of RFC 4787.";
        }

        leaf address-and-port-dependent-mapping-support {
          type boolean;
          description
            "Indicates whether address-and-port-dependent-mapping is
             supported.";
           reference
             "Section 4 of RFC 4787.";
        }

        leaf endpoint-independent-filtering-support {
          type boolean;
          description
            "Indicates whether endpoint-independent-filtering is
             supported.";
           reference
             "Section 5 of RFC 4787.";
        }

        leaf address-dependent-filtering {
          type boolean;
          description
            "Indicates whether address-dependent-filtering is
             supported.";
           reference
             "Section 5 of RFC 4787.";
        }

        leaf address-and-port-dependent-filtering {
          type boolean;
          description
            "Indicates whether address-and-port-dependent is
             supported.";
           reference
             "Section 5 of RFC 4787.";
        }

        leaf fragment-behavior {
          type enumeration {
            enum "unsupported"  {
              description
                "No capability to translate incoming fragments.
                 All received fragments are dropped.";
            }

            enum "in-order"  {
              description
                "The NAT instance is able to translate fragments only if
                 they are received in order. That is, in particular the
                 header is in the first packet. Fragments received
                 out of order are dropped. ";
            }

            enum "out-of-order"  {
              description
                "The NAT instance is able to translate a fragment even
                 if it is received out of order.

                 This behavior is recommended.";
              reference
                "REQ-14 of RFC 4787";
            }
          }
          description
            "The fragment behavior is the NAT instance's capability to
             translate fragments received on the external interface of
             the NAT.";
        }
      }

      leaf type {
        type identityref {
          base nat-type;
        }
        description
          "Specify the translation type. Particularly useful when
           multiple  translation flavors are supported.

           If one type is supported by a NAT, this parameter is by
           default set to that type.";
      }

      leaf per-interface-binding {
        type enumeration {
          enum "disabled"  {
            description
              "Disable the capability to associate an extra identifier
               with NAT mappings.";
          }

          enum "layer-2"  {
            description
              "The NAT instance is able to associate a mapping with
               a layer-2 identifier.";
          }

          enum "dslite"  {
            description
              "The NAT instance is able to associate a mapping with
               an IPv6 address (a.k.a., DS-Lite).";
          }
        }
        description
          "A NAT that associates a particular NAT session not only with
           the five tuples used for the transport connection on both
           sides of the NAT but also with the internal interface on
           which the user device is connected to the NAT.

           If supported, this mode of operation should be configurable,
           and it should be disabled by default in general-purpose NAT
           devices.

           If one single per-interface binding behavior is supported by
           a NAT, this parameter is by default set to that behavior.";
        reference
          "Section 4 of RFC 6619";
      }

      list nat-pass-through {
        if-feature "basic-nat44 or napt44 or dst-nat";
        key id;

        description
         "IP prefix NAT pass through.";

        leaf id {
          type uint32;
          description
            "An identifier of the IP prefix pass through.";
        }

        leaf prefix {
          type inet:ip-prefix;
          mandatory true;
          description
            "The IP addresses that match should not be translated.

             It must be possible to administratively turn
             off translation for specific destination addresses
             and/or ports.";
          reference
            "REQ#6 of RFC 6888.";
        }

        leaf port {
          type inet:port-number;
          description
            "It must be possible to administratively turn off
             translation for specific destination addresses
             and/or ports.

             If no prefix is defined, the NAT pass through bound
             to a given port applies for any destination address.";
          reference
            "REQ#6 of RFC 6888.";
        }
      }

     list policy {
       key id;
       description
         "NAT parameters for a given instance";

       leaf id {
         type uint32;
         description
           "An identifier of the NAT policy. It must be unique
            within the NAT instance.";
       }

       container clat-parameters {
         if-feature clat;
         description
           "CLAT parameters.";

         list clat-ipv6-prefixes {
           key ipv6-prefix;
           description
             "464XLAT double translation treatment is stateless when a
              dedicated /64 is available for translation on the CLAT.
              Otherwise, the CLAT will have both stateful and stateless
              since it requires NAT44 from the LAN to a single IPv4
              address and then stateless translation to a single
              IPv6 address.";
            reference
              "RFC 6877: 464XLAT: Combination of Stateful and Stateless
                         Translation";

            leaf ipv6-prefix {
              type inet:ipv6-prefix;
              description
                "An IPv6 prefix used for CLAT.";
            }
          }

          list ipv4-prefixes {
            key ipv4-prefix;
            description
              "Pool of IPv4 addresses used for CLAT.
               192.0.0.0/29 is the IPv4 service continuity prefix.";
            reference
              "RFC 7335: IPv4 Service Continuity Prefix";

            leaf ipv4-prefix {
              type inet:ipv4-prefix;
              description
                "464XLAT double translation treatment is
                 stateless when a dedicated /64 is available
                 for translation on the CLAT.  Otherwise, the
                 CLAT will have both stateful and stateless
                 since it requires NAT44 from the LAN to
                 a single IPv4 address and then stateless
                 translation to a single IPv6 address.
                 The CLAT performs NAT44 for all IPv4 LAN
                 packets so that all the LAN-originated IPv4
                 packets appear from a single IPv4 address
                 and are then statelessly translated to one
                 interface IPv6 address that is claimed by
                 the CLAT.

                 An IPv4 address from this pool is also
                 provided to an application that makes
                 use of literals.";

             reference
               "RFC 6877: 464XLAT: Combination of Stateful and Stateless
                          Translation";
           }
         }
       }

       list nptv6-prefixes {
         if-feature nptv6;
         key internal-ipv6-prefix ;
         description
           "Provides one or a list of (internal IPv6 prefix,
            external IPv6 prefix) required for NPTv6.

            In its simplest form, NPTv6 interconnects two network
            links, one of which is an 'internal' network link
            attached to a leaf network within a single
            administrative domain and the other of which is an
            'external' network with connectivity to the global
            Internet.";
          reference
            "RFC 6296: IPv6-to-IPv6 Network Prefix Translation";

          leaf internal-ipv6-prefix {
            type inet:ipv6-prefix;
            mandatory true;
            description
              "An IPv6 prefix used by an internal interface of NPTv6.";
            reference
              "RFC 6296: IPv6-to-IPv6 Network Prefix Translation";
         }

         leaf external-ipv6-prefix {
           type inet:ipv6-prefix;
            mandatory true;
           description
             "An IPv6 prefix used by the external interface of NPTv6.";
           reference
             "RFC 6296: IPv6-to-IPv6 Network Prefix Translation";
         }
       }

       list eam {
         if-feature eam;
         key ipv4-prefix;
         description
           "The Explicit Address Mapping Table, a conceptual
            table in which each row represents an EAM.

            Each EAM describes a mapping between IPv4 and IPv6
            prefixes/addresses.";
         reference
           "Section 3.1 of RFC 7757.";

         leaf ipv4-prefix {
           type inet:ipv4-prefix;
           mandatory true;
           description
             "The IPv4 prefix of an EAM.";
           reference
             "Section 3.2 of RFC 7757.";
         }

         leaf ipv6-prefix {
           type inet:ipv6-prefix;
            mandatory true;
           description
             "The IPv6 prefix of an EAM.";
           reference
             "Section 3.2 of RFC 7757.";
         }
       }

       list nat64-prefixes {
         if-feature "siit or nat64 or clat";
         key nat64-prefix;
         description
           "Provides one or a list of NAT64 prefixes
            with or without a list of destination IPv4 prefixes.
            It allows mapping IPv4 address ranges to IPv6 prefixes.

            For example:
            192.0.2.0/24 is mapped to 2001:db8:122:300::/56.
            198.51.100.0/24 is mapped to 2001:db8:122::/48.";
         reference
           "Section 5.1 of RFC 7050.";

         leaf nat64-prefix {
           type inet:ipv6-prefix;
           mandatory true;
           description
             "A NAT64 prefix. Can be Network-Specific Prefix (NSP) or
              Well-Known Prefix (WKP).

              Organizations deploying stateless IPv4/IPv6 translation
              should assign a Network-Specific Prefix to their
              IPv4/IPv6 translation service.

              For stateless NAT64, IPv4-translatable IPv6 addresses
              must use the selected Network-Specific Prefix.

              Both IPv4-translatable IPv6 addresses and IPv4-converted
              IPv6 addresses should use the same prefix.";
           reference
             "Sections 3.3 and 3.4 of RFC 6052.";
         }

         list destination-ipv4-prefix {
           key ipv4-prefix;
           description
             "An IPv4 prefix/address.";

           leaf ipv4-prefix {
             type inet:ipv4-prefix;
             description
               "An IPv4 address/prefix.";
            }
          }

          leaf stateless-enable {
            type boolean;
            default false;
            description
              "Enable explicitly stateless NAT64.";
         }
       }

       list external-ip-address-pool {
         if-feature "basic-nat44 or napt44 or nat64";
         key pool-id;

         description
           "Pool of external IP addresses used to service internal
            hosts.

            A pool is a set of IP prefixes.";

         leaf pool-id {
           type uint32;
           must ". >= 1";
           description
             "An identifier that uniquely identifies the address pool
              within a NAT instance.

              The identifier must be greater than zero.";
           reference
             "RFC 7659: Definitions of Managed Objects for
                        Network Address Translators (NATs)";
         }

         leaf external-ip-pool {
           type inet:ipv4-prefix;
           mandatory true;
           description
             "An IPv4 prefix used for NAT purposes.";
         }
       }

       container port-set-restrict {
         if-feature "napt44 or nat64";
         description
           "Configures contiguous and non-contiguous port ranges.

            The port set is used to restrict the external source
            port numbers used by the translator.";

         uses port-set;
       }

       leaf dst-nat-enable {
         if-feature "basic-nat44 or napt44";
         type boolean;
         default false;
         description
           "Enable/Disable destination NAT.
            A NAT44 may be configured to enable Destination
            NAT, too.";
        }

        list dst-ip-address-pool {
          if-feature dst-nat;
          key pool-id;
          description
            "Pool of IP addresses used for destination NAT.";

          leaf pool-id {
            type uint32;
            description
              "An identifier of the address pool.";
          }

          leaf dst-in-ip-pool {
            type inet:ip-prefix;
            description
              "Is used to identify an internal destination
               IP prefix/address to be translated.";
          }

          leaf dst-out-ip-pool {
            type inet:ip-prefix;
            mandatory true;
            description
              "IP address/prefix used for destination NAT.";
          }
        }

        list transport-protocols {
          if-feature "napt44 or nat64 or dst-nat";
          key protocol-id;

          description
            "Configure the transport protocols to be handled by
             the translator.

             TCP and UDP are supported by default.";

          leaf protocol-id {
            type uint8;
            mandatory true;
            description
              "Upper-layer protocol associated with this mapping.

               Values are taken from the IANA protocol registry:
               https://www.iana.org/assignments/protocol-numbers/
               protocol-numbers.xhtml

               For example, this field contains 6 (TCP) for a TCP
               mapping or 17 (UDP) for a UDP mapping.";
          }

          leaf protocol-name {
            type string;
            description
              "The name of the Upper-layer protocol associated
               with this mapping.

               Values are taken from the IANA protocol registry:
               https://www.iana.org/assignments/protocol-numbers/
               protocol-numbers.xhtml

               For example, TCP, UDP, DCCP, and SCTP.";
          }
        }

        leaf subscriber-mask-v6 {
          type uint8 {
            range "0 .. 128";
          }

          description
            "The subscriber mask is an integer that indicates
             the length of significant bits to be applied on
             the source IPv6 address (internal side) to
             unambiguously identify a user device (e.g., CPE).

             Subscriber mask is a system-wide configuration
             parameter that is used to enforce generic
             per-subscriber policies (e.g., port-quota).

             The enforcement of these generic policies does not
             require the configuration of every subscriber's
             prefix.

             Example: suppose the 2001:db8:100:100::/56 prefix
             is assigned to a NAT64 serviced CPE. Suppose also
             that 2001:db8:100:100::1 is the IPv6 address used
             by the client that resides in that CPE. When the
             NAT64 receives a packet from this client,
             it applies the subscriber-mask-v6 (e.g., 56) on
             the source IPv6 address to compute the associated
             prefix for this client (2001:db8:100:100::/56).
             Then, the NAT64 enforces policies based on that
             prefix (2001:db8:100:100::/56), not on the exact
             source IPv6 address.";
        }

        list subscriber-match {
          if-feature "basic-nat44 or napt44 or dst-nat";
          key match-id;

          description
            "IP prefix match.
             A subscriber is identified by a subnet.";

          leaf match-id {
            type uint32;
            description
              "An identifier of the subscriber match.";
          }

          leaf subnet {
            type inet:ip-prefix;
            mandatory true;
            description
              "The IP address subnets that match
               should be translated. E.g., all addresses
               that belong to the 192.0.2.0/24 prefix must
               be processed by the NAT.";
          }
        }

        leaf address-allocation-type {
          type enumeration {
            enum "arbitrary"  {
              if-feature "basic-nat44 or napt44 or nat64";
              description
                "Arbitrary pooling behavior means that the NAT
                 instance may create the new port mapping using any
                 address in the pool that has a free port for the
                 protocol concerned.";
            }

            enum "roundrobin"  {
              if-feature "basic-nat44 or napt44 or nat64";
              description
                "Round robin allocation.";
            }

            enum "paired"  {
              if-feature "napt44 or nat64";
              description
                "Paired address pooling informs the NAT
                 that all the flows from an internal IP
                 address must be assigned the same external
                 address. This is the recommended behavior for
                 NAPT/NAT64.";
              reference
                "RFC 4787: Network Address Translation (NAT)
                           Behavioral Requirements for Unicast UDP";
            }
          }
          description
            "Specifies how external IP addresses are allocated.";
        }

        leaf port-allocation-type {
          if-feature "napt44 or nat64";
          type enumeration {
            enum "random"  {
              description
                "Port randomization is enabled. A NAT port allocation
                 scheme should make it hard for attackers to guess
                 port numbers";
              reference
                "REQ-15 of RFC 6888";
            }

            enum "port-preservation"  {
              description
                "Indicates whether the NAT should preserve the internal
                 port number.";
            }

            enum "port-parity-preservation"  {
              description
                "Indicates whether the NAT should preserve the port
                 parity of the internal port number.";
            }

            enum "port-range-allocation"  {
              description
                "Indicates whether the NAT assigns a range of ports
                 for an internal host. This scheme allows to minimize
                 log volume.";
              reference
                "REQ-14 of RFC 6888";
            }
          }
            description
              "Indicates the type of port allocation.";
        }

        leaf mapping-type {
          if-feature "napt44 or nat64";
          type enumeration {
            enum "eim"  {
              description
                "endpoint-independent-mapping.";
              reference
                "Section 4 of RFC 4787.";
            }

            enum "adm"  {
              description
                "address-dependent-mapping.";
              reference
                "Section 4 of RFC 4787.";
            }

            enum "edm"  {
              description
                "address-and-port-dependent-mapping.";
              reference
                "Section 4 of RFC 4787.";
            }
          }
          description
            "Indicates the type of a NAT mapping.";
        }

        leaf filtering-type {
          if-feature "napt44 or nat64";
          type enumeration {
            enum "eif"  {
              description
                "endpoint-independent-filtering.";
              reference
                "Section 5 of RFC 4787.";
            }

            enum "adf"  {
              description
                "address-dependent-filtering.";
              reference
                "Section 5 of RFC 4787.";
            }

            enum "edf"  {
              description
                "address-and-port-dependent-filtering";
              reference
                "Section 5 of RFC 4787.";
            }
          }
            description
              "Indicates the type of a NAT filtering.";
        }

        leaf fragment-behavior {
          if-feature "napt44 or nat64";
          type enumeration {
            enum "drop-all"  {
              description
                "All received fragments are dropped.";
            }

            enum "in-order"  {
              description
                "Translate fragments only if they are received
                 in order.";
            }

            enum "out-of-order"  {
              description
                "Translate a fragment even if it is received out
                 of order.

                 This behavior is recommended.";
              reference
                "REQ-14 of RFC 4787";
             }
           }
           description
             "The fragment behavior instructs the NAT about the
              behavior to follow to translate fragments received
              on the external interface of the NAT.";
          }

        list port-quota {
          if-feature "napt44 or nat64";
          key quota-type;
          description
            "Configures a port quota to be assigned per subscriber.
             It corresponds to the maximum number of ports to be
             used by a subscriber.";

          leaf port-limit {
            type uint16;
            description
              "Configures a port quota to be assigned per subscriber.
               It corresponds to the maximum number of ports to be
               used by a subscriber.";
            reference
              "REQ-4 of RFC 6888.";
          }

          leaf quota-type {
              type uint8;
              description
                "Indicates whether the port quota applies to
                 all protocols (0) or to a specific protocol.";
          }
        }

        container port-set {

          when "../port-allocation-type = 'port-range-allocation'";

          if-feature "napt44 or nat64";
          description
            "Manages port-set assignments.";

          leaf port-set-size {
            type uint16;
            // TODO(HC2VPP-328)
            // mandatory true;
            description
              "Indicates the size of assigned port sets.";
          }

          leaf port-set-timeout {
            type uint32;
            units "seconds";
            description
              "inactivity timeout for port sets.";
          }
        }

        container timers {
          if-feature "napt44 or nat64";
          description
            "Configure values of various timeouts.";

            leaf udp-timeout {
              type uint32;
              units "seconds";
              default 300;
              description
                "UDP inactivity timeout. That is the time a mapping
                 will stay active without packets traversing the NAT.";
              reference
                "RFC 4787: Network Address Translation (NAT)
                           Behavioral Requirements for Unicast UDP";
            }

            leaf tcp-idle-timeout {
              type uint32;
              units "seconds";
              default 7440;
              description
                "TCP Idle timeout should be 2 hours and 4 minutes.";
              reference
                "RFC 5382: NAT Behavioral Requirements for TCP";
            }

            leaf tcp-trans-open-timeout {
              type uint32;
              units "seconds";
              default 240;
              description
                "The value of the transitory open connection
                 idle-timeout.

                 A NAT should provide different configurable
                 parameters for configuring the open and
                 closing idle timeouts.

                 To accommodate deployments that consider
                 a partially open timeout of 4 minutes as being
                 excessive from a security standpoint, a NAT may
                 allow the configured timeout to be less than
                 4 minutes.

                 However, a minimum default transitory connection
                 idle-timeout of 4 minutes is recommended.";
              reference
                "Section 2.1 of RFC 7857.";
            }

            leaf tcp-trans-close-timeout {
              type uint32;
              units "seconds";
              default 240;
              description
                "The value of the transitory close connection
                idle-timeout.

                A NAT should provide different configurable
                parameters for configuring the open and
                closing idle timeouts.";
              reference
                "Section 2.1 of RFC 7857.";
            }

            leaf tcp-in-syn-timeout {
              type uint32;
              units "seconds";
              default 6;
              description
                "A NAT must not respond to an unsolicited
                inbound SYN packet for at least 6 seconds
                after the packet is received.  If during
                this interval the NAT receives and translates
                an outbound SYN for the connection the NAT
                must silently drop the original unsolicited
                inbound SYN packet.";
             reference
                "RFC 5382 NAT Behavioral Requirements for TCP";
            }

            leaf fragment-min-timeout {
              when "../../fragment-behavior='out-of-order'";
              type uint32;
              units "seconds";
              default 2;
              description
                "As long as the NAT has available resources,
                the NAT allows the fragments to arrive
                over fragment-min-timeout interval.
                The default value is inspired from RFC6146.";
            }

            leaf icmp-timeout {
              type uint32;
              units "seconds";
              default 60;
              description
                "An ICMP Query session timer must not expire
                 in less than 60 seconds. It is recommended
                 that the ICMP Query session timer be made
                 configurable";
              reference
                "RFC 5508: NAT Behavioral Requirements for ICMP";
            }

            list per-port-timeout {
              key port-number;
              description
                "Some NATs are configurable with short timeouts
                 for some ports, e.g., as 10 seconds on
                 port 53 (DNS) and 123 (NTP) and longer timeouts
                 on other ports.";

              leaf port-number {
                type inet:port-number;
                description
                  "A port number.";
              }

              leaf timeout {
                type uint32;
                units "seconds";
                mandatory true;
                description
                  "Timeout for this port number";
              }
            }

            leaf hold-down-timeout {
              type uint32;
              units "seconds";
              default 120;
              description
                "Hold down timer.

                 Ports in the hold down pool are not reassigned until
                 hold-down-timeout expires.

                 The length of time and the maximum number of ports in
                 this state must be configurable by the administrator.

                 This is necessary in order to prevent collisions
                 between old and new mappings and sessions. It ensures
                 that all established sessions are broken instead of
                 redirected to a different peer.";
              reference
                "REQ#8 of RFC 6888.";
            }

            leaf hold-down-max {
              type uint32;
              description
                "Maximum ports in the Hold down timer pool.

                 Ports in the hold down pool are not reassigned
                 until hold-down-timeout expires.

                 The length of time and the maximum
                 number of ports in this state must be
                 configurable by the administrator.
                 This is necessary in order
                 to prevent collisions between old
                 and new mappings and sessions. It ensures
                 that all established sessions are broken
                 instead of redirected to a different peer.";
              reference
                "REQ#8 of RFC 6888.";
            }
          }

          leaf fragments-limit{
            when "../fragment-behavior='out-of-order'";
            type uint32;
            description
              "Limits the number of out of order fragments that can
               be handled.";
            reference
              "Section 11 of RFC 4787.";
          }

          list algs {
            key name;
            description
              "ALG-related features.";

            leaf name {
              type string;
              description
                "The name of the ALG.";
            }

            leaf transport-protocol {
              type uint32;
              description
                "The transport protocol used by the ALG
                 (e.g., TCP, UDP).";
            }

            container dst-transport-port {
              uses port-number;
              description
                "The destination port number(s) used by the ALG.
                 For example,
                   - 21 for the FTP ALG
                   - 53 for the DNS ALG.";
            }

            container src-transport-port {
              uses port-number;
              description
                "The source port number(s) used by the ALG.";
            }

            leaf status {
              type boolean;
              description
                "Enable/disable the ALG.";
            }
          }

          leaf all-algs-enable {
            type boolean;
            description
             "Enable/disable all ALGs.

              When specified, this parameter overrides the one
              that may be indicated, eventually, by the 'status'
              of an individual ALG.";
          }

          container notify-pool-usage {
            if-feature "basic-nat44 or napt44 or nat64";
            description
              "Notification of pool usage when certain criteria
               are met.";

            leaf pool-id {
              type uint32;
              description
                "Pool-ID for which the notification criteria
                 is defined";
            }

            leaf high-threshold {
              type percent;
              description
                "Notification must be generated when the defined high
                 threshold is reached.

                 For example, if a notification is required when the
                 pool utilization reaches 90%, this configuration
                 parameter must be set to 90.

                 0% indicates that no high threshold is enabled.";
            }

            leaf low-threshold {
              type percent;
              must ". >= ../high-threshold" {
                error-message
                  "The upper port number must be greater than or
                   equal to lower port number.";
              }
              description
                "Notification must be generated when the defined low
                 threshold is reached.

                 For example, if a notification is required when the
                 pool utilization reaches below 10%, this
                 configuration parameter must be set to 10";
            }

            leaf notify-interval {
              type uint32 {
                 range "1 .. 3600";
              }
              units "seconds";
              default '20';
              description
                "Minimum number of seconds between successive
                 notifications for this pool.";

              reference
                "RFC 7659: Definitions of Managed Objects for
                           Network Address Translators (NATs)";
            }
          }

          container external-realm {
            description
              "Identifies the external realm of the NAT instance.";

            choice realm-type {
              description
                "Can be an interface, VRF instance, etc.";

              case interface {
                description
                  "External interface.";

                leaf external-interface {
                  type if:interface-ref;
                  description
                    "Name of the external interface.";
                }
              }
            }
          }
        }

        container mapping-limits {
          if-feature "napt44 or nat64";
          description
            "Information about the configuration parameters that
             limits the mappings based upon various criteria.";

          leaf limit-subscribers {
            type uint32;
            description
              "Maximum number of subscribers that can be serviced
               by a NAT instance.

               A subscriber is identified by a given prefix.";
             reference
               "RFC 7659: Definitions of Managed Objects for
                          Network Address Translators (NATs)";
          }

          leaf limit-address-mappings {
            type uint32;
            description
              "Maximum number of address mappings that can be
               handled by a NAT instance.

               When this limit is reached, packets that would
               normally trigger translation, will be dropped.";
             reference
               "RFC 7659: Definitions of Managed Objects
                          for Network Address Translators
                          (NATs)";
          }

          leaf limit-port-mappings {
            type uint32;
            description
              "Maximum number of port mappings that can be handled
               by a NAT instance.

               When this limit is reached, packets that would
               normally trigger translation, will be dropped.";
             reference
               "RFC 7659: Definitions of Managed Objects for
                          Network Address Translators (NATs)";
          }

          list limit-per-protocol {
            if-feature "napt44 or nat64 or dst-nat";
            key protocol-id;

            description
              "Configure limits per transport protocol";

            leaf protocol-id {
              type uint8;
              mandatory true;
              description
                "Upper-layer protocol associated with this mapping.

                 Values are taken from the IANA protocol registry:
                 https://www.iana.org/assignments/protocol-numbers/
                 protocol-numbers.xhtml

                 For example, this field contains 6 (TCP) for a TCP
                 mapping or 17 (UDP) for a UDP mapping.";
            }

            leaf limit {
              type uint32;
              description
                "Maximum number of protocol-specific NAT mappings
                 per instance.";
            }
          }
        }

        container connection-limits {
          if-feature "basic-nat44 or napt44 or nat64";
          description
            "Information about the configuration parameters that
             rate limit the translation based upon various criteria.";

          leaf limit-per-subscriber {
            type uint32;
            units "bits/second";
            description
              "Rate-limit the number of new mappings and sessions
               per subscriber.";
           }

          leaf limit-per-instance {
            type uint32;
            units "bits/second";
            // TODO(HC2VPP-328)
            // mandatory true;
            description
              "Rate-limit the number of new mappings and sessions
               per instance.";
          }

          list limit-per-protocol {
            if-feature "napt44 or nat64";
            key protocol-id;
            description
              "Configure limits per transport protocol";

            leaf protocol-id {
              type uint8;
              mandatory true;
              description
                "Upper-layer protocol associated with this mapping.

                 Values are taken from the IANA protocol registry:
                 https://www.iana.org/assignments/protocol-numbers/
                 protocol-numbers.xhtml

                 For example, this field contains 6 (TCP) for a TCP
                 mapping or 17 (UDP) for a UDP mapping.";
            }

            leaf limit {
              type uint32;
              description
                "Rate-limit the number of protocol-specific mappings
                 and sessions per instance.";
            }
          }
        }

        container notification-limits {
          description "Sets notification limits.";

        leaf notify-interval {
            if-feature "basic-nat44 or napt44 or nat64";
            type uint32 {
                 range "1 .. 3600";
            }
            units "seconds";
            default '10';
            description
                "Minimum number of seconds between successive
                 notifications for this NAT instance.";
            reference
              "RFC 7659: Definitions of Managed Objects
                         for Network Address Translators (NATs)";
        }

        leaf notify-addresses-usage {
            if-feature "basic-nat44 or napt44 or nat64";
            type percent;
            description
              "Notification of address mappings usage over
               the whole NAT instance.

               Notification must be generated when the defined
               threshold is reached.

               For example, if a notification is required when
               the address mappings utilization reaches 90%,
               this configuration parameter must be set
               to 90.";
         }

        leaf notify-ports-usage {
            if-feature "napt44 or nat64";
            type percent;
            description
              "Notification of port mappings usage over the
               whole NAT instance.

               Notification must be generated when the defined
               threshold is reached.

               For example, if a notification is required when
               the port mappings utilization reaches 90%, this
               configuration parameter must be set to 90.";
         }

        leaf notify-subscribers-limit {
            if-feature "basic-nat44 or napt44 or nat64";
            type uint32;
            description
              "Notification of active subscribers per NAT
               instance.

               Notification must be generated when the defined
               threshold is reached.";
         }
        }

        leaf logging-enable {
          if-feature "basic-nat44 or napt44 or nat64";
          type boolean;
          description
            "Enable logging features.";
          reference
            "Section 2.3 of RFC 6908 and REQ-12 of RFC 6888.";
        }

        container mapping-table {
          if-feature "basic-nat44 or napt44 " +
               "or nat64 or clat or dst-nat";
          description
            "NAT mapping table. Applicable for functions which maintain
             static and/or dynamic mappings, such as NAT44, Destination
             NAT, NAT64, or CLAT.";

          list mapping-entry {
            key "index";
            description "NAT mapping entry.";
            uses mapping-entry;
          }
        }

        container statistics {
          config false;

          description
            "Statistics related to the NAT instance.";

          leaf discontinuity-time {
            type yang:date-and-time;
            mandatory true;
            description
              "The time on the most recent occasion at which the NAT
               instance suffered a discontinuity.  This must be
               initialized when the NAT instance is configured
               or rebooted.";
          }

          container traffic-statistics {
            description
              "Generic traffic statistics.";

            leaf sent-packets {
              type yang:zero-based-counter64;
              description
                "Number of packets sent.";
            }

            leaf sent-bytes {
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter for sent traffic in bytes.";
            }

            leaf rcvd-packets {
              type yang:zero-based-counter64;
              description
                "Number of received packets.";
            }

            leaf rcvd-bytes {
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter for received traffic in bytes.";
            }

            leaf dropped-packets {
              type yang:zero-based-counter64;
              description
                "Number of dropped packets.";
            }

            leaf dropped-bytes {
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter for dropped traffic in bytes.";
            }

            leaf dropped-fragments {
              if-feature "napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped fragments on the external realm.";
            }

            leaf dropped-address-limit-packets {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped packets because an address limit
                  is reached.";
            }

            leaf dropped-address-limit-bytes {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter of dropped packets because an address limit
                  is reached, in bytes.";
            }

            leaf dropped-address-packets {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped packets because no address is
                 available for allocation.";
            }

            leaf dropped-address-bytes {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter of dropped packets because no address is
                 available for allocation, in bytes.";
            }

            leaf dropped-port-limit-packets {
              if-feature "napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped packets because a port limit
                 is reached.";
            }

            leaf dropped-port-limit-bytes {
              if-feature "napt44 or nat64";
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter of dropped packets because a port limit
                 is reached, in bytes.";
            }

            leaf dropped-port-packets {
              if-feature "napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped packets because no port is
                 available for allocation.";
            }

            leaf dropped-port-bytes {
              if-feature "napt44 or nat64";
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter of dropped packets because no port is
                 available for allocation, in bytes.";
            }

            leaf dropped-subscriber-limit-packets {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              description
                "Number of dropped packets because the subscriber
                 limit per instance is reached.";
            }

            leaf dropped-subscriber-limit-bytes {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:zero-based-counter64;
              units 'bytes';
              description
                "Counter of dropped packets because the subscriber
                  limit per instance is reached, in bytes.";
            }
          }

          container mappings-statistics {
            description
              "Mappings statistics.";

            leaf total-active-subscribers {
              if-feature "basic-nat44 or napt44 or nat64";
              type yang:gauge32;
              description
                "Total number of active subscribers (that is,
                 subscribers for which the NAT maintains active
                 mappings.

                 A subscriber is identified by a subnet,
                 subscriber-mask, etc.";
            }

            leaf total-address-mappings {
              if-feature "basic-nat44 or napt44 " +
               "or nat64 or clat or dst-nat";
              type yang:gauge32;
              description
                "Total number of address mappings present at a given
                 time. It includes both static and dynamic mappings.";
              reference
                "Section 3.3.8 of RFC 7659";
            }

            leaf total-port-mappings {
              if-feature "napt44 or nat64";
              type yang:gauge32;
              description
                "Total number of NAT port mappings present at
                 a given time. It includes both static and dynamic
                 mappings.";
              reference
                "Section 3.3.9 of RFC 7659";
            }

            list total-per-protocol {
              if-feature "napt44 or nat64";
              key protocol-id;
              description
                "Total mappings for each enabled/supported protocol.";

              leaf protocol-id {
                type uint8;
                mandatory true;
                description
                  "Upper-layer protocol associated with this mapping.
                   For example, this field contains 6 (TCP) for a TCP
                   mapping or 17 (UDP) for a UDP mapping.";
              }

              leaf total {
                type yang:gauge32;
                description
                  "Total number of a protocol-specific mappings present
                   at a given time. The protocol is identified by
                   protocol-id.";
              }
            }
          }

          container pools-stats {
            if-feature "basic-nat44 or napt44 or nat64";
            description
              "Statistics related to address/prefix pools
               usage";

            leaf addresses-allocated {
              type yang:gauge32;
              description
                "Number of all allocated addresses.";
            }

            leaf addresses-free {
              type yang:gauge32;
              description
                "Number of unallocated addresses of all pools at
                 a given time. The sum of unallocated and allocated
                 addresses is the total number of addresses of
                 the pools.";
            }

            container ports-stats {
              if-feature "napt44 or nat64";

              description
                "Statistics related to port numbers usage.";

              leaf ports-allocated {
                type yang:gauge32;
                description
                  "Number of allocated ports from all pools.";
              }

              leaf ports-free {
                type yang:gauge32;
                description
                  "Number of unallocated addresses from all pools.";
              }
            }

            list per-pool-stats {
              if-feature "basic-nat44 or napt44 or nat64";
              key "pool-id";
              description
                "Statistics related to address/prefix pool usage";

              leaf pool-id {
                type uint32;
                description
                  "Unique Identifier that represents a pool of
                   addresses/prefixes.";
              }

              leaf discontinuity-time {
                type yang:date-and-time;
                mandatory true;
                description
                  "The time on the most recent occasion at which this
                   pool counters suffered a discontinuity.  This must
                   be initialized when the address pool is
                   configured.";
              }

              container pool-stats {
                description
                  "Statistics related to address/prefix pool usage";

                leaf addresses-allocated {
                  type yang:gauge32;
                  description
                    "Number of allocated addresses from this pool.";
                }

                leaf addresses-free {
                  type yang:gauge32;
                  description
                    "Number of unallocated addresses in this pool.";
                }
              }

              container port-stats {
                if-feature "napt44 or nat64";
                description
                  "Statistics related to port numbers usage.";

                leaf ports-allocated {
                  type yang:gauge32;
                  description
                    "Number of allocated ports from this pool.";
                }

                leaf ports-free {
                  type yang:gauge32;
                  description
                    "Number of unallocated addresses from this pool.";
                }
              }
            }
          }
        }
      }
    }
  }

  /*
   * Notifications
   */

  notification nat-pool-event {
    if-feature "basic-nat44 or napt44 or nat64";
    description
      "Notifications must be generated when the defined high/low
       threshold is reached. Related configuration parameters
       must be provided to trigger the notifications.";

    leaf id {
      type leafref {
        path "/nat/instances/instance/id";
      }
      mandatory true;
      description
        "NAT instance Identifier.";
    }

    leaf policy-id {
      type leafref {
        path "/nat/instances/instance/policy/id";
      }

      description
        "Policy Identifier.";
    }

    leaf pool-id {
      type leafref {
        path "/nat/instances/instance/policy/" +
             "external-ip-address-pool/pool-id";
      }
      mandatory true;
      description
        "Pool Identifier.";
    }

    leaf notify-pool-threshold {
      type percent;
      mandatory true;
      description
        "A threshold (high-threshold or low-threshold) has
         been fired.";
    }
  }

  notification nat-instance-event {
    if-feature "basic-nat44 or napt44 or nat64";
    description
      "Notifications must be generated when notify-addresses-usage
       and/or notify-ports-usage threshold are reached.";

    leaf id {
      type leafref {
        path "/nat/instances/instance/id";
      }
      mandatory true;
      description
        "NAT instance Identifier.";
    }

    leaf notify-subscribers-threshold {
      type uint32;
      description
        "The notify-subscribers-limit threshold has been fired.";
    }

    leaf notify-addresses-threshold {
      type percent;
      description
        "The notify-addresses-usage threshold has been fired.";
    }

    leaf notify-ports-threshold {
      type percent;
      description
        "The notify-ports-usage threshold has been fired.";
    }
  }
}