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 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548
|
/* Copyright (c) 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <config.h>
#include "ovn-controller.h"
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bfd.h"
#include "binding.h"
#include "chassis.h"
#include "command-line.h"
#include "compiler.h"
#include "daemon.h"
#include "dirs.h"
#include "openvswitch/dynamic-string.h"
#include "encaps.h"
#include "fatal-signal.h"
#include "lib/id-pool.h"
#include "if-status.h"
#include "ip-mcast.h"
#include "openvswitch/hmap.h"
#include "lb.h"
#include "lflow.h"
#include "lflow-cache.h"
#include "lib/lflow-conj-ids.h"
#include "lib/vswitch-idl.h"
#include "lib/ovsdb-types.h"
#include "local_data.h"
#include "lport.h"
#include "memory.h"
#include "ofctrl.h"
#include "lib/ofctrl-seqno.h"
#include "openvswitch/vconn.h"
#include "openvswitch/vlog.h"
#include "ovn/actions.h"
#include "ovn/features.h"
#include "lib/chassis-index.h"
#include "lib/extend-table.h"
#include "lib/ip-mcast-index.h"
#include "lib/mac-binding-index.h"
#include "lib/mcast-group-index.h"
#include "lib/ovn-dirs.h"
#include "lib/ovn-sb-idl.h"
#include "lib/ovn-util.h"
#include "ovsport.h"
#include "patch.h"
#include "vif-plug.h"
#include "vif-plug-provider.h"
#include "physical.h"
#include "pinctrl.h"
#include "openvswitch/poll-loop.h"
#include "lib/bitmap.h"
#include "lib/hash.h"
#include "simap.h"
#include "smap.h"
#include "sset.h"
#include "stream-ssl.h"
#include "stream.h"
#include "unixctl.h"
#include "util.h"
#include "timeval.h"
#include "timer.h"
#include "stopwatch.h"
#include "lib/inc-proc-eng.h"
#include "lib/ovn-l7.h"
#include "hmapx.h"
#include "mirror.h"
#include "mac-cache.h"
#include "statctrl.h"
#include "lib/dns-resolve.h"
#include "ct-zone.h"
#include "ovn-dns.h"
#include "acl-ids.h"
#include "route.h"
#include "route-exchange.h"
#include "route-table-notify.h"
#include "garp_rarp.h"
#include "host-if-monitor.h"
#include "neighbor.h"
#include "neighbor-exchange.h"
#include "neighbor-table-notify.h"
#include "evpn-arp.h"
#include "evpn-binding.h"
#include "evpn-fdb.h"
VLOG_DEFINE_THIS_MODULE(main);
static unixctl_cb_func ct_zone_list;
static unixctl_cb_func extend_table_list;
static unixctl_cb_func inject_pkt;
static unixctl_cb_func engine_recompute_cmd;
static unixctl_cb_func cluster_state_reset_cmd;
static unixctl_cb_func debug_pause_execution;
static unixctl_cb_func debug_resume_execution;
static unixctl_cb_func debug_status_execution;
static unixctl_cb_func debug_dump_local_bindings;
static unixctl_cb_func debug_dump_local_datapaths;
static unixctl_cb_func debug_dump_related_lports;
static unixctl_cb_func debug_dump_local_template_vars;
static unixctl_cb_func debug_dump_local_mac_bindings;
static unixctl_cb_func debug_dump_peer_ports;
static unixctl_cb_func debug_dump_lflow_conj_ids;
static unixctl_cb_func lflow_cache_flush_cmd;
static unixctl_cb_func lflow_cache_show_stats_cmd;
static unixctl_cb_func debug_delay_nb_cfg_report;
#define DEFAULT_BRIDGE_NAME "br-int"
#define DEFAULT_DATAPATH "system"
#define CONTROLLER_LOOP_STOPWATCH_NAME "flow-generation"
#define OFCTRL_PUT_STOPWATCH_NAME "flow-installation"
#define PINCTRL_RUN_STOPWATCH_NAME "pinctrl-run"
#define PATCH_RUN_STOPWATCH_NAME "patch-run"
#define CT_ZONE_COMMIT_STOPWATCH_NAME "ct-zone-commit"
#define IF_STATUS_MGR_RUN_STOPWATCH_NAME "if-status-mgr-run"
#define IF_STATUS_MGR_UPDATE_STOPWATCH_NAME "if-status-mgr-update"
#define OFCTRL_SEQNO_RUN_STOPWATCH_NAME "ofctrl-seqno-run"
#define BFD_RUN_STOPWATCH_NAME "bfd-run"
#define VIF_PLUG_RUN_STOPWATCH_NAME "vif-plug-run"
#define OVS_NB_CFG_NAME "ovn-nb-cfg"
#define OVS_NB_CFG_TS_NAME "ovn-nb-cfg-ts"
#define OVS_STARTUP_TS_NAME "ovn-startup-ts"
struct br_int_remote {
char *target;
int probe_interval;
};
static char *parse_options(int argc, char *argv[]);
OVS_NO_RETURN static void usage(void);
/* SSL/TLS options. */
static const char *ssl_private_key_file;
static const char *ssl_certificate_file;
static const char *ssl_ca_cert_file;
/* --unixctl-path: Path to use for unixctl server socket. */
static char *unixctl_path;
/* By default don't set an upper bound for the lflow cache and enable auto
* trimming above 10K logical flows when reducing cache size by 50%.
*/
#define DEFAULT_LFLOW_CACHE_MAX_ENTRIES UINT32_MAX
#define DEFAULT_LFLOW_CACHE_MAX_MEM_KB (UINT64_MAX / 1024)
#define DEFAULT_LFLOW_CACHE_TRIM_LIMIT 10000
#define DEFAULT_LFLOW_CACHE_WMARK_PERC 50
#define DEFAULT_LFLOW_CACHE_TRIM_TO_MS 30000
struct controller_engine_ctx {
struct lflow_cache *lflow_cache;
struct if_status_mgr *if_mgr;
};
/* Pending packet to be injected into connected OVS. */
struct pending_pkt {
/* Setting 'conn' indicates that a request is pending. */
struct unixctl_conn *conn;
char *flow_s;
};
/* Registered ofctrl seqno type for nb_cfg propagation. */
static size_t ofctrl_seq_type_nb_cfg;
static void
remove_newline(char *s)
{
char *last = &s[strlen(s) - 1];
switch (*last) {
case '\n':
case '\r':
*last = '\0';
default:
return;
}
}
static char *get_file_system_id(void)
{
char *ret = NULL;
char *filename = xasprintf("%s/system-id-override", ovn_sysconfdir());
errno = 0;
FILE *f = fopen(filename, "r");
if (f) {
char system_id[64];
if (fgets(system_id, sizeof system_id, f)) {
remove_newline(system_id);
ret = xstrdup(system_id);
}
fclose(f);
}
free(filename);
return ret;
}
/* Only set monitor conditions on tables that are available in the
* server schema.
*/
#define sb_table_set_opt_mon_condition(idl, table, cond) \
(sbrec_server_has_##table##_table(idl) \
? sbrec_##table##_set_condition(idl, cond) \
: 0)
/* Assume the table exists in the server schema and set its condition. */
#define sb_table_set_req_mon_condition(idl, table, cond) \
sbrec_##table##_set_condition(idl, cond)
static unsigned int
update_sb_monitors(struct ovsdb_idl *ovnsb_idl,
const struct sbrec_chassis *chassis,
const struct simap *local_ifaces,
const struct shash *local_bindings,
struct hmap *local_datapaths,
bool monitor_all)
{
/* Monitor Port_Bindings rows for local interfaces and local datapaths.
*
* Monitor Logical_Flow, MAC_Binding, FDB, Multicast_Group, and DNS tables
* for local datapaths.
*
* Monitor Controller_Event rows for local chassis.
*
* Monitor IP_Multicast for local datapaths.
*
* Monitor IGMP_Groups for local chassis.
*
* Monitor Template_Var for local chassis.
*
* Monitor ECMP_Nexthop for local datapaths.
*
* Monitor Advertised/Learned_Route for local datapaths.
*
* We always monitor patch ports because they allow us to see the linkages
* between related logical datapaths. That way, when we know that we have
* a VIF on a particular logical switch, we immediately know to monitor all
* the connected logical routers and logical switches. */
struct ovsdb_idl_condition pb = OVSDB_IDL_CONDITION_INIT(&pb);
struct ovsdb_idl_condition lf = OVSDB_IDL_CONDITION_INIT(&lf);
struct ovsdb_idl_condition ldpg = OVSDB_IDL_CONDITION_INIT(&ldpg);
struct ovsdb_idl_condition mb = OVSDB_IDL_CONDITION_INIT(&mb);
struct ovsdb_idl_condition fdb = OVSDB_IDL_CONDITION_INIT(&fdb);
struct ovsdb_idl_condition mg = OVSDB_IDL_CONDITION_INIT(&mg);
struct ovsdb_idl_condition dns = OVSDB_IDL_CONDITION_INIT(&dns);
struct ovsdb_idl_condition ce = OVSDB_IDL_CONDITION_INIT(&ce);
struct ovsdb_idl_condition ip_mcast = OVSDB_IDL_CONDITION_INIT(&ip_mcast);
struct ovsdb_idl_condition igmp = OVSDB_IDL_CONDITION_INIT(&igmp);
struct ovsdb_idl_condition chprv = OVSDB_IDL_CONDITION_INIT(&chprv);
struct ovsdb_idl_condition tv = OVSDB_IDL_CONDITION_INIT(&tv);
struct ovsdb_idl_condition nh = OVSDB_IDL_CONDITION_INIT(&nh);
struct ovsdb_idl_condition ar = OVSDB_IDL_CONDITION_INIT(&ar);
struct ovsdb_idl_condition lr = OVSDB_IDL_CONDITION_INIT(&lr);
struct ovsdb_idl_condition amb = OVSDB_IDL_CONDITION_INIT(&amb);
/* Always monitor all logical datapath groups. Otherwise, DPG updates may
* be received *after* the lflows using it are seen by ovn-controller.
* Since the number of DPGs are relatively small, we monitor all DPGs to
* avoid the unnecessarily extra wake-ups of ovn-controller. */
ovsdb_idl_condition_add_clause_true(&ldpg);
/* Always monitor all learned routes. Otherwise, when we have a new local
* datapath we directly try to learn routes from the vrf (if it exists).
* If we then do not know all learned routes of this datapath we can get
* duplicates.
* XXX: This should be optimized, e.g. if we find a way to defer to learn
* routes until db conditions are updated. */
ovsdb_idl_condition_add_clause_true(&lr);
if (monitor_all) {
/* Monitor all Southbound tables unconditionally. Do that even for
* tables that could be easily filtered by chassis name (like
* Chassis_Private). That's because the current ovsdb-server
* implementation uses a cache whose efficiency significantly
* decreases when monitor conditions are present. */
ovsdb_idl_condition_add_clause_true(&pb);
ovsdb_idl_condition_add_clause_true(&lf);
ovsdb_idl_condition_add_clause_true(&mb);
ovsdb_idl_condition_add_clause_true(&fdb);
ovsdb_idl_condition_add_clause_true(&mg);
ovsdb_idl_condition_add_clause_true(&dns);
ovsdb_idl_condition_add_clause_true(&ce);
ovsdb_idl_condition_add_clause_true(&ip_mcast);
ovsdb_idl_condition_add_clause_true(&igmp);
ovsdb_idl_condition_add_clause_true(&chprv);
ovsdb_idl_condition_add_clause_true(&tv);
ovsdb_idl_condition_add_clause_true(&nh);
ovsdb_idl_condition_add_clause_true(&ar);
ovsdb_idl_condition_add_clause_true(&amb);
goto out;
}
sbrec_port_binding_add_clause_type(&pb, OVSDB_F_EQ, "patch");
/* XXX: We can optimize this, if we find a way to only monitor
* ports that have a Gateway_Chassis that point's to our own
* chassis */
sbrec_port_binding_add_clause_type(&pb, OVSDB_F_EQ, "chassisredirect");
sbrec_port_binding_add_clause_type(&pb, OVSDB_F_EQ, "external");
if (chassis) {
/* This should be mostly redundant with the other clauses for port
* bindings, but it allows us to catch any ports that are assigned to
* us but should not be. That way, we can clear their chassis
* assignments. */
sbrec_port_binding_add_clause_chassis(&pb, OVSDB_F_EQ,
&chassis->header_.uuid);
sbrec_port_binding_add_clause_requested_chassis(
&pb, OVSDB_F_EQ, &chassis->header_.uuid);
/* Ensure that we find out about l2gateway and l3gateway ports that
* should be present on this chassis. Otherwise, we might never find
* out about those ports, if their datapaths don't otherwise have a VIF
* in this chassis. */
const char *id = chassis->name;
const struct smap l2 = SMAP_CONST1(&l2, "l2gateway-chassis", id);
sbrec_port_binding_add_clause_options(&pb, OVSDB_F_INCLUDES, &l2);
const struct smap l3 = SMAP_CONST1(&l3, "l3gateway-chassis", id);
sbrec_port_binding_add_clause_options(&pb, OVSDB_F_INCLUDES, &l3);
sbrec_controller_event_add_clause_chassis(&ce, OVSDB_F_EQ,
&chassis->header_.uuid);
sbrec_igmp_group_add_clause_chassis(&igmp, OVSDB_F_EQ,
&chassis->header_.uuid);
/* Monitors Chassis_Private record for current chassis only. */
sbrec_chassis_private_add_clause_name(&chprv, OVSDB_F_EQ,
chassis->name);
sbrec_chassis_template_var_add_clause_chassis(&tv, OVSDB_F_EQ,
chassis->name);
} else {
/* During initialization, we monitor all records in Chassis_Private so
* that we don't try to recreate existing ones. */
ovsdb_idl_condition_add_clause_true(&chprv);
/* Also, to avoid traffic disruption (e.g., conntrack flushing for
* zones that are used by OVN but not yet known due to the SB initial
* contents not being available), monitor all port bindings
* connected to gateways; they might be claimed as soon as the
* chassis is available.
*/
sbrec_port_binding_add_clause_type(&pb, OVSDB_F_EQ, "l2gateway");
sbrec_port_binding_add_clause_type(&pb, OVSDB_F_EQ, "l3gateway");
/* Monitor all advertised routes during startup.
* Otherwise, once we claim a port on startup we do not yet know the
* routes to advertise and might wrongly delete already installed
* ones. */
ovsdb_idl_condition_add_clause_true(&ar);
}
if (local_ifaces) {
const char *name;
ovs_assert(local_bindings);
const struct simap_node *n;
SIMAP_FOR_EACH (n, local_ifaces) {
name = n->name;
/* Skip the VIFs we bound already, we should have a local datapath
* for those. */
const struct sbrec_port_binding *local_pb
= local_binding_get_primary_pb(local_bindings, name);
if (local_pb && get_lport_type(local_pb) == LP_VIF &&
local_pb->chassis == chassis) {
continue;
}
sbrec_port_binding_add_clause_logical_port(&pb, OVSDB_F_EQ, name);
}
/* Monitor all sub-ports unconditionally; we don't expect a lot of
* them in the SB database. */
sbrec_port_binding_add_clause_parent_port(&pb, OVSDB_F_NE, NULL);
}
if (local_datapaths) {
const struct local_datapath *ld;
HMAP_FOR_EACH (ld, hmap_node, local_datapaths) {
struct uuid *uuid = CONST_CAST(struct uuid *,
&ld->datapath->header_.uuid);
sbrec_port_binding_add_clause_datapath(&pb, OVSDB_F_EQ, uuid);
sbrec_logical_flow_add_clause_logical_datapath(&lf, OVSDB_F_EQ,
uuid);
sbrec_mac_binding_add_clause_datapath(&mb, OVSDB_F_EQ, uuid);
sbrec_fdb_add_clause_dp_key(&fdb, OVSDB_F_EQ,
ld->datapath->tunnel_key);
sbrec_multicast_group_add_clause_datapath(&mg, OVSDB_F_EQ, uuid);
sbrec_dns_add_clause_datapaths(&dns, OVSDB_F_INCLUDES, &uuid, 1);
sbrec_ip_multicast_add_clause_datapath(&ip_mcast, OVSDB_F_EQ,
uuid);
sbrec_ecmp_nexthop_add_clause_datapath(&nh, OVSDB_F_EQ, uuid);
sbrec_advertised_route_add_clause_datapath(&ar, OVSDB_F_EQ, uuid);
sbrec_advertised_mac_binding_add_clause_datapath(&amb, OVSDB_F_EQ,
uuid);
}
/* Datapath groups are immutable, which means a new group record is
* created when a datapath is added to a group. The logical flows
* referencing a datapath group are also updated in such cases but the
* new group UUID is not known by ovn-controller until the SB update
* is received. To avoid unnecessarily removing and adding lflows
* that reference datapath groups, set the monitor condition to always
* request all of them.
*/
sbrec_logical_flow_add_clause_logical_dp_group(&lf, OVSDB_F_NE, NULL);
}
out:;
unsigned int cond_seqnos[] = {
sb_table_set_req_mon_condition(ovnsb_idl, port_binding, &pb),
sb_table_set_req_mon_condition(ovnsb_idl, logical_flow, &lf),
sb_table_set_req_mon_condition(ovnsb_idl, logical_dp_group, &ldpg),
sb_table_set_req_mon_condition(ovnsb_idl, mac_binding, &mb),
sb_table_set_req_mon_condition(ovnsb_idl, fdb, &fdb),
sb_table_set_req_mon_condition(ovnsb_idl, multicast_group, &mg),
sb_table_set_req_mon_condition(ovnsb_idl, dns, &dns),
sb_table_set_req_mon_condition(ovnsb_idl, controller_event, &ce),
sb_table_set_req_mon_condition(ovnsb_idl, ip_multicast, &ip_mcast),
sb_table_set_req_mon_condition(ovnsb_idl, igmp_group, &igmp),
sb_table_set_req_mon_condition(ovnsb_idl, chassis_private, &chprv),
sb_table_set_opt_mon_condition(ovnsb_idl, chassis_template_var, &tv),
sb_table_set_opt_mon_condition(ovnsb_idl, ecmp_nexthop, &nh),
sb_table_set_opt_mon_condition(ovnsb_idl, advertised_route, &ar),
sb_table_set_opt_mon_condition(ovnsb_idl, learned_route, &lr),
sb_table_set_opt_mon_condition(ovnsb_idl, advertised_mac_binding,
&amb),
};
unsigned int expected_cond_seqno = 0;
for (size_t i = 0; i < ARRAY_SIZE(cond_seqnos); i++) {
expected_cond_seqno = MAX(expected_cond_seqno, cond_seqnos[i]);
}
ovsdb_idl_condition_destroy(&pb);
ovsdb_idl_condition_destroy(&lf);
ovsdb_idl_condition_destroy(&ldpg);
ovsdb_idl_condition_destroy(&mb);
ovsdb_idl_condition_destroy(&fdb);
ovsdb_idl_condition_destroy(&mg);
ovsdb_idl_condition_destroy(&dns);
ovsdb_idl_condition_destroy(&ce);
ovsdb_idl_condition_destroy(&ip_mcast);
ovsdb_idl_condition_destroy(&igmp);
ovsdb_idl_condition_destroy(&chprv);
ovsdb_idl_condition_destroy(&tv);
ovsdb_idl_condition_destroy(&nh);
ovsdb_idl_condition_destroy(&ar);
ovsdb_idl_condition_destroy(&lr);
ovsdb_idl_condition_destroy(&amb);
return expected_cond_seqno;
}
static const char *
br_int_name(const struct ovsrec_open_vswitch_table *ovs_table)
{
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
return get_chassis_external_id_value(&cfg->external_ids, chassis_id,
"ovn-bridge", DEFAULT_BRIDGE_NAME);
}
static const struct ovsrec_bridge *
create_br_int(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_open_vswitch_table *ovs_table)
{
const struct ovsrec_open_vswitch *cfg;
cfg = ovsrec_open_vswitch_table_first(ovs_table);
if (!cfg) {
return NULL;
}
const char *bridge_name = br_int_name(ovs_table);
ovsdb_idl_txn_add_comment(ovs_idl_txn,
"ovn-controller: creating integration bridge '%s'", bridge_name);
struct ovsrec_interface *iface;
iface = ovsrec_interface_insert(ovs_idl_txn);
ovsrec_interface_set_name(iface, bridge_name);
ovsrec_interface_set_type(iface, "internal");
struct ovsrec_port *port;
port = ovsrec_port_insert(ovs_idl_txn);
ovsrec_port_set_name(port, bridge_name);
ovsrec_port_set_interfaces(port, &iface, 1);
struct ovsrec_bridge *bridge;
bridge = ovsrec_bridge_insert(ovs_idl_txn);
ovsrec_bridge_set_name(bridge, bridge_name);
ovsrec_bridge_set_fail_mode(bridge, "secure");
ovsrec_bridge_set_ports(bridge, &port, 1);
struct smap oc = SMAP_INITIALIZER(&oc);
smap_add(&oc, "disable-in-band", "true");
/* When a first non-local port is added to the integration bridge, it
* results in the recalculation of datapath-id by ovs-vswitchd forcing all
* active connections to the controllers to reconnect.
*
* We can avoid the disconnection by setting the 'other_config:hwaddr' for
* the integration bridge. ovs-vswitchd uses this hwaddr to calculate the
* datapath-id and it doesn't recalculate the datapath-id later when the
* first non-local port is added.
*
* So generate a random mac and set the 'hwaddr' option in the
* other_config.
* */
struct eth_addr br_hwaddr;
eth_addr_random(&br_hwaddr);
char ea_s[ETH_ADDR_STRLEN + 1];
snprintf(ea_s, sizeof ea_s, ETH_ADDR_FMT,
ETH_ADDR_ARGS(br_hwaddr));
smap_add(&oc, "hwaddr", ea_s);
ovsrec_bridge_set_other_config(bridge, &oc);
smap_destroy(&oc);
struct ovsrec_bridge **bridges;
size_t bytes = sizeof *bridges * cfg->n_bridges;
bridges = xmalloc(bytes + sizeof *bridges);
if (cfg->n_bridges) {
memcpy(bridges, cfg->bridges, bytes);
}
bridges[cfg->n_bridges] = bridge;
ovsrec_open_vswitch_verify_bridges(cfg);
ovsrec_open_vswitch_set_bridges(cfg, bridges, cfg->n_bridges + 1);
free(bridges);
return bridge;
}
static const struct ovsrec_datapath *
create_br_datapath(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_open_vswitch *cfg,
const char *datapath_type)
{
ovsdb_idl_txn_add_comment(ovs_idl_txn,
"ovn-controller: creating bridge datapath '%s'",
datapath_type);
struct ovsrec_datapath *dp = ovsrec_datapath_insert(ovs_idl_txn);
ovsrec_open_vswitch_verify_datapaths(cfg);
ovsrec_open_vswitch_update_datapaths_setkey(cfg, datapath_type, dp);
return dp;
}
#define N_FLOW_TABLES 255
static void
update_flow_table_prefixes(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_bridge *br_int)
{
const struct ovsdb_type *server_type;
struct ds ds = DS_EMPTY_INITIALIZER;
const char *prefixes[] = {
"ip_src", "ip_dst", "ipv6_src", "ipv6_dst",
};
struct ovsrec_flow_table *ft;
size_t max_prefixes;
size_t i;
/* We must not attempt setting more prefixes than our IDL supports.
* Note: This should be a build time assertion, but IDL structures
* are not defined as constants. */
ovs_assert(
ARRAY_SIZE(prefixes) <=
ovsrec_flow_table_columns[OVSREC_FLOW_TABLE_COL_PREFIXES].type.n_max);
server_type = ovsrec_flow_table_prefixes_server_type(
ovsdb_idl_txn_get_idl(ovs_idl_txn));
if (!server_type) {
/* Not connected or not in the server's schema somehow. */
return;
}
max_prefixes = MIN(server_type->n_max, ARRAY_SIZE(prefixes));
if (br_int->n_flow_tables == N_FLOW_TABLES &&
br_int->value_flow_tables[0]->n_prefixes == max_prefixes) {
/* Already up to date. Ideally, we would check every table,
* but it seems excessive. */
return;
}
for (i = 1; i < br_int->n_flow_tables; i++) {
if (br_int->value_flow_tables[i] != br_int->value_flow_tables[0]) {
break;
}
}
if (i == N_FLOW_TABLES) {
/* Correct number of flow tables and all pointing to the same row. */
ft = br_int->value_flow_tables[0];
} else {
/* Unexpected configuration. Let's create a new flow table row.
* Old ones will be garbage collected by the database. */
struct ovsrec_flow_table *values[N_FLOW_TABLES];
int64_t keys[N_FLOW_TABLES];
ft = ovsrec_flow_table_insert(ovs_idl_txn);
for (i = 0; i < ARRAY_SIZE(values); i++) {
keys[i] = i;
values[i] = ft;
}
ovsrec_bridge_set_flow_tables(br_int, keys, values,
ARRAY_SIZE(values));
}
ds_put_cstr(&ds, "Setting flow table prefixes:");
for (i = 0 ; i < max_prefixes; i++) {
ds_put_char(&ds, ' ');
ds_put_cstr(&ds, prefixes[i]);
ds_put_char(&ds, ',');
}
ds_chomp(&ds, ',');
VLOG_INFO("%s.", ds_cstr_ro(&ds));
ds_destroy(&ds);
ovsrec_flow_table_set_prefixes(ft, prefixes, max_prefixes);
}
static const struct ovsrec_bridge *
get_br_int(const struct ovsrec_bridge_table *bridge_table,
const struct ovsrec_open_vswitch_table *ovs_table)
{
const struct ovsrec_open_vswitch *cfg;
cfg = ovsrec_open_vswitch_table_first(ovs_table);
if (!cfg) {
return NULL;
}
return get_bridge(bridge_table, br_int_name(ovs_table));
}
static const struct ovsrec_datapath *
get_br_datapath(const struct ovsrec_open_vswitch *cfg,
const char *datapath_type)
{
for (size_t i = 0; i < cfg->n_datapaths; i++) {
if (!strcmp(cfg->key_datapaths[i], datapath_type)) {
return cfg->value_datapaths[i];
}
}
return NULL;
}
static void
process_br_int(struct ovsdb_idl_txn *ovs_idl_txn,
const struct ovsrec_bridge_table *bridge_table,
const struct ovsrec_open_vswitch_table *ovs_table,
const struct ovsrec_bridge **br_int_,
const struct ovsrec_datapath **br_int_dp)
{
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
ovs_assert(br_int_);
if (ovs_idl_txn) {
if (!br_int) {
br_int = create_br_int(ovs_idl_txn, ovs_table);
}
if (br_int) {
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
ovs_assert(cfg);
/* Propagate "ovn-bridge-datapath-type" from OVS table, if any.
* Otherwise use the datapath-type set in br-int, if any.
* Finally, assume "system" datapath if none configured.
*/
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const char *datapath_type =
get_chassis_external_id_value(
&cfg->external_ids, chassis_id,
"ovn-bridge-datapath-type", NULL);
if (!datapath_type) {
if (br_int->datapath_type[0]) {
datapath_type = br_int->datapath_type;
} else {
datapath_type = DEFAULT_DATAPATH;
}
}
if (strcmp(br_int->datapath_type, datapath_type)) {
ovsrec_bridge_set_datapath_type(br_int, datapath_type);
}
if (!br_int->fail_mode || strcmp(br_int->fail_mode, "secure")) {
ovsrec_bridge_set_fail_mode(br_int, "secure");
VLOG_WARN("Integration bridge fail-mode changed to 'secure'.");
}
if (br_int_dp) {
*br_int_dp = get_br_datapath(cfg, datapath_type);
if (!(*br_int_dp)) {
*br_int_dp = create_br_datapath(ovs_idl_txn, cfg,
datapath_type);
}
}
update_flow_table_prefixes(ovs_idl_txn, br_int);
}
}
*br_int_ = br_int;
}
static void
update_ssl_config(const struct ovsrec_ssl_table *ssl_table)
{
const struct ovsrec_ssl *ssl = ovsrec_ssl_table_first(ssl_table);
if (ssl) {
stream_ssl_set_key_and_cert(ssl->private_key, ssl->certificate);
stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert);
} else {
if (ssl_private_key_file && ssl_certificate_file) {
stream_ssl_set_key_and_cert(ssl_private_key_file,
ssl_certificate_file);
}
if (ssl_ca_cert_file) {
stream_ssl_set_ca_cert_file(ssl_ca_cert_file, false);
}
}
}
/* Retrieves the pointer to the OVN Southbound database from 'ovs_idl' and
* updates 'sbdb_idl' with that pointer. */
static void
update_sb_db(struct ovsdb_idl *ovs_idl, struct ovsdb_idl *ovnsb_idl,
bool *monitor_all_p, bool *reset_ovnsb_idl_min_index,
struct controller_engine_ctx *ctx,
unsigned int *sb_cond_seqno)
{
const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
if (!cfg) {
return;
}
/* Set remote based on user configuration. */
const struct ovsrec_open_vswitch_table *ovs_table =
ovsrec_open_vswitch_table_get(ovs_idl);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const char *remote =
get_chassis_external_id_value(
&cfg->external_ids, chassis_id, "ovn-remote", NULL);
ovsdb_idl_set_remote(ovnsb_idl, remote, true);
/* Set probe interval, based on user configuration and the remote. */
int interval =
get_chassis_external_id_value_int(
&cfg->external_ids, chassis_id, "ovn-remote-probe-interval", -1);
set_idl_probe_interval(ovnsb_idl, remote, interval);
bool monitor_all =
get_chassis_external_id_value_bool(
&cfg->external_ids, chassis_id, "ovn-monitor-all", false);
if (monitor_all) {
/* Always call update_sb_monitors when monitor_all is true.
* Otherwise, don't call it here, because there would be unnecessary
* extra cost. Instead, it is called after the engine execution only
* when it is necessary. */
unsigned int next_cond_seqno =
update_sb_monitors(ovnsb_idl, NULL, NULL, NULL, NULL, true);
if (sb_cond_seqno) {
*sb_cond_seqno = next_cond_seqno;
}
}
if (monitor_all_p) {
*monitor_all_p = monitor_all;
}
if (reset_ovnsb_idl_min_index && *reset_ovnsb_idl_min_index) {
VLOG_INFO("Resetting southbound database cluster state");
engine_set_force_recompute();
ovsdb_idl_reset_min_index(ovnsb_idl);
*reset_ovnsb_idl_min_index = false;
}
if (ctx) {
lflow_cache_enable(
ctx->lflow_cache,
get_chassis_external_id_value_bool(
&cfg->external_ids, chassis_id,
"ovn-enable-lflow-cache", true),
get_chassis_external_id_value_uint(
&cfg->external_ids, chassis_id,
"ovn-limit-lflow-cache",
DEFAULT_LFLOW_CACHE_MAX_ENTRIES),
get_chassis_external_id_value_ullong(
&cfg->external_ids, chassis_id,
"ovn-memlimit-lflow-cache-kb",
DEFAULT_LFLOW_CACHE_MAX_MEM_KB),
get_chassis_external_id_value_uint(
&cfg->external_ids, chassis_id,
"ovn-trim-limit-lflow-cache",
DEFAULT_LFLOW_CACHE_TRIM_LIMIT),
get_chassis_external_id_value_uint(
&cfg->external_ids, chassis_id,
"ovn-trim-wmark-perc-lflow-cache",
DEFAULT_LFLOW_CACHE_WMARK_PERC),
get_chassis_external_id_value_uint(
&cfg->external_ids, chassis_id,
"ovn-trim-timeout-ms",
DEFAULT_LFLOW_CACHE_TRIM_TO_MS));
}
}
/* Connection tracking zones. */
struct ed_type_ct_zones {
struct ct_zone_ctx ctx;
/* Tracked data. */
bool recomputed;
};
static uint64_t
get_nb_cfg(const struct sbrec_sb_global_table *sb_global_table,
unsigned int cond_seqno, unsigned int expected_cond_seqno)
{
static uint64_t nb_cfg = 0;
/* Delay getting nb_cfg if there are monitor condition changes
* in flight. It might be that those changes would instruct the
* server to send updates that happened before SB_Global.nb_cfg.
*/
if (cond_seqno != expected_cond_seqno) {
return nb_cfg;
}
const struct sbrec_sb_global *sb
= sbrec_sb_global_table_first(sb_global_table);
nb_cfg = sb ? sb->nb_cfg : 0;
return nb_cfg;
}
/* Propagates the local cfg seqno, 'cur_cfg', to the chassis_private record
* and to the local OVS DB.
*/
static void
store_nb_cfg(struct ovsdb_idl_txn *sb_txn, struct ovsdb_idl_txn *ovs_txn,
const struct sbrec_chassis_private *chassis,
const struct ovsrec_bridge *br_int,
unsigned int delay_nb_cfg_report,
bool enable_ch_nb_cfg_update)
{
struct ofctrl_acked_seqnos *acked_nb_cfg_seqnos =
ofctrl_acked_seqnos_get(ofctrl_seq_type_nb_cfg);
uint64_t cur_cfg = acked_nb_cfg_seqnos->last_acked;
int64_t startup_ts = daemon_startup_ts();
if (ovs_txn && br_int
&& startup_ts != smap_get_ullong(&br_int->external_ids,
OVS_STARTUP_TS_NAME, 0)) {
char *startup_ts_str = xasprintf("%"PRId64, startup_ts);
ovsrec_bridge_update_external_ids_setkey(br_int, OVS_STARTUP_TS_NAME,
startup_ts_str);
free(startup_ts_str);
}
if (!cur_cfg) {
goto done;
}
long long ts_now = time_wall_msec();
if (sb_txn && chassis && cur_cfg != chassis->nb_cfg
&& enable_ch_nb_cfg_update) {
sbrec_chassis_private_set_nb_cfg(chassis, cur_cfg);
sbrec_chassis_private_set_nb_cfg_timestamp(chassis, ts_now);
if (delay_nb_cfg_report) {
VLOG_INFO("Sleep for %u sec", delay_nb_cfg_report);
xsleep(delay_nb_cfg_report);
}
}
if (ovs_txn && br_int && cur_cfg != smap_get_ullong(&br_int->external_ids,
OVS_NB_CFG_NAME, 0)) {
char *cur_cfg_ts_str = xasprintf("%lld", ts_now);
char *cur_cfg_str = xasprintf("%"PRId64, cur_cfg);
ovsrec_bridge_update_external_ids_setkey(br_int, OVS_NB_CFG_NAME,
cur_cfg_str);
ovsrec_bridge_update_external_ids_setkey(br_int, OVS_NB_CFG_TS_NAME,
cur_cfg_ts_str);
free(cur_cfg_ts_str);
free(cur_cfg_str);
}
done:
ofctrl_acked_seqnos_destroy(acked_nb_cfg_seqnos);
}
static const char *
get_transport_zones(const struct ovsrec_open_vswitch_table *ovs_table)
{
const struct ovsrec_open_vswitch *cfg
= ovsrec_open_vswitch_table_first(ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
return get_chassis_external_id_value(&cfg->external_ids, chassis_id,
"ovn-transport-zones", "");
}
static bool
get_ovn_cleanup_on_exit(const struct ovsrec_open_vswitch_table *ovs_table)
{
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
if (!cfg || !chassis_id) {
return false;
}
return get_chassis_external_id_value_bool(&cfg->external_ids, chassis_id,
"ovn-cleanup-on-exit", true);
}
static void
ctrl_register_ovs_idl(struct ovsdb_idl *ovs_idl)
{
/* We do not monitor all tables by default, so modules must register
* their interest explicitly.
* XXX: when the same column is monitored in different modes by different
* modules, there is a chance that "track" flag added by
* ovsdb_idl_track_add_column by one module being overwritten by a
* following ovsdb_idl_add_column by another module. Before this is fixed
* in OVSDB IDL, we need to be careful about the order so that the "track"
* calls are after the "non-track" calls. */
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_open_vswitch);
ovsdb_idl_add_column(ovs_idl, &ovsrec_open_vswitch_col_other_config);
ovsdb_idl_add_column(ovs_idl, &ovsrec_open_vswitch_col_bridges);
ovsdb_idl_add_column(ovs_idl, &ovsrec_open_vswitch_col_datapaths);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_interface);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_port);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_bridge);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_ports);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_name);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_fail_mode);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_flow_tables);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_other_config);
ovsdb_idl_add_column(ovs_idl, &ovsrec_bridge_col_external_ids);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_flow_table);
ovsdb_idl_add_column(ovs_idl, &ovsrec_flow_table_col_prefixes);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_ssl);
ovsdb_idl_add_column(ovs_idl, &ovsrec_ssl_col_bootstrap_ca_cert);
ovsdb_idl_add_column(ovs_idl, &ovsrec_ssl_col_ca_cert);
ovsdb_idl_add_column(ovs_idl, &ovsrec_ssl_col_certificate);
ovsdb_idl_add_column(ovs_idl, &ovsrec_ssl_col_private_key);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_datapath);
ovsdb_idl_add_column(ovs_idl, &ovsrec_datapath_col_capabilities);
ovsdb_idl_add_column(ovs_idl, &ovsrec_datapath_col_ct_zones);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_flow_sample_collector_set);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_qos);
ovsdb_idl_add_column(ovs_idl, &ovsrec_qos_col_other_config);
ovsdb_idl_add_column(ovs_idl, &ovsrec_qos_col_external_ids);
ovsdb_idl_add_column(ovs_idl, &ovsrec_qos_col_queues);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_queue);
ovsdb_idl_add_column(ovs_idl, &ovsrec_queue_col_other_config);
ovsdb_idl_add_column(ovs_idl, &ovsrec_queue_col_external_ids);
ovsdb_idl_add_column(ovs_idl, &ovsrec_interface_col_link_state);
ovsdb_idl_add_table(ovs_idl, &ovsrec_table_ct_zone);
ovsdb_idl_add_column(ovs_idl, &ovsrec_ct_zone_col_limit);
chassis_register_ovs_idl(ovs_idl);
encaps_register_ovs_idl(ovs_idl);
binding_register_ovs_idl(ovs_idl);
bfd_register_ovs_idl(ovs_idl);
physical_register_ovs_idl(ovs_idl);
vif_plug_register_ovs_idl(ovs_idl);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_open_vswitch_col_external_ids);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_name);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_bfd);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_bfd_status);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_mtu);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_type);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_options);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_ofport);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_external_ids);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_interface_col_link_speed);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_port_col_name);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_port_col_interfaces);
ovsdb_idl_track_add_column(ovs_idl, &ovsrec_port_col_external_ids);
ovsdb_idl_track_add_column(ovs_idl,
&ovsrec_flow_sample_collector_set_col_bridge);
ovsdb_idl_track_add_column(ovs_idl,
&ovsrec_flow_sample_collector_set_col_id);
mirror_register_ovs_idl(ovs_idl);
/* XXX: There is a potential bug in CT zone I-P node,
* the fact that we have to call recompute for the change of
* OVS.bridge.external_ids be reflected. Currently, we don't
* track that column which should be addressed in the future. */
}
struct ed_type_ofctrl_is_connected {
bool connected;
};
static void *
en_ofctrl_is_connected_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_ofctrl_is_connected *data = xzalloc(sizeof *data);
return data;
}
static void
en_ofctrl_is_connected_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_ofctrl_is_connected_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
struct ed_type_ofctrl_is_connected *of_data = data;
if (of_data->connected != ofctrl_is_connected()) {
of_data->connected = !of_data->connected;
/* Flush ofctrl seqno requests when the ofctrl connection goes down. */
if (!of_data->connected) {
ofctrl_seqno_flush();
if_status_mgr_clear(ctrl_ctx->if_mgr);
}
return EN_UPDATED;
}
return EN_UNCHANGED;
}
struct ed_type_if_status_mgr {
const struct if_status_mgr *manager;
const struct ovsrec_interface_table *iface_table;
};
static void *
en_if_status_mgr_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_if_status_mgr *data = xzalloc(sizeof *data);
return data;
}
static void
en_if_status_mgr_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_if_status_mgr_run(struct engine_node *node, void *data_)
{
enum engine_node_state state = EN_UNCHANGED;
struct ed_type_if_status_mgr *data = data_;
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
data->manager = ctrl_ctx->if_mgr;
data->iface_table = EN_OVSDB_GET(engine_get_input("OVS_interface", node));
const struct ovsrec_interface *iface;
OVSREC_INTERFACE_TABLE_FOR_EACH (iface, data->iface_table) {
if (if_status_mgr_iface_update(data->manager, iface)) {
state = EN_UPDATED;
}
}
return state;
}
static enum engine_input_handler_result
if_status_mgr_ovs_interface_handler(struct engine_node *node OVS_UNUSED,
void *data)
{
struct ed_type_if_status_mgr *data_ = data;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
const struct ovsrec_interface *iface;
OVSREC_INTERFACE_TABLE_FOR_EACH_TRACKED (iface, data_->iface_table) {
if (if_status_mgr_iface_update(data_->manager, iface)) {
result = EN_HANDLED_UPDATED;
}
}
return result;
}
/* This engine node is to wrap the OVS_interface input and maintain a copy of
* the old version of data for the column external_ids.
*
* There are some special considerations of this engine node:
* 1. It has a single input OVS_interface, and it transparently passes the
* input changes as its own output data to its dependants. So there is no
* processing to OVS_interface changes but simply mark the node status as
* UPDATED (and so the run() and the change handler is the same).
* 2. The iface_table_external_ids_old is computed/updated in the member
* clear_tracked_data(), because that is when the last round of processing
* has completed but the new IDL data is yet to refresh, so we replace the
* old data with the current data. */
struct ed_type_ovs_interface_shadow {
const struct ovsrec_interface_table *iface_table;
struct shash iface_table_external_ids_old;
};
static void *
en_ovs_interface_shadow_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_ovs_interface_shadow *data = xzalloc(sizeof *data);
data->iface_table = NULL;
shash_init(&data->iface_table_external_ids_old);
return data;
}
static void
iface_table_external_ids_old_destroy(struct shash *table_ext_ids)
{
struct shash_node *node;
SHASH_FOR_EACH (node, table_ext_ids) {
struct smap *ext_ids = node->data;
smap_destroy(ext_ids);
}
shash_destroy_free_data(table_ext_ids);
}
static void
en_ovs_interface_shadow_cleanup(void *data_)
{
struct ed_type_ovs_interface_shadow *data = data_;
iface_table_external_ids_old_destroy(&data->iface_table_external_ids_old);
}
static void
en_ovs_interface_shadow_clear_tracked_data(void *data_)
{
struct ed_type_ovs_interface_shadow *data = data_;
iface_table_external_ids_old_destroy(&data->iface_table_external_ids_old);
shash_init(&data->iface_table_external_ids_old);
if (!data->iface_table) {
return;
}
const struct ovsrec_interface *iface_rec;
OVSREC_INTERFACE_TABLE_FOR_EACH (iface_rec, data->iface_table) {
struct smap *external_ids = xmalloc(sizeof *external_ids);
smap_clone(external_ids, &iface_rec->external_ids);
shash_add(&data->iface_table_external_ids_old, iface_rec->name,
external_ids);
}
}
static enum engine_node_state
en_ovs_interface_shadow_run(struct engine_node *node, void *data_)
{
struct ed_type_ovs_interface_shadow *data = data_;
const struct ovsrec_interface_table *iface_table =
EN_OVSDB_GET(engine_get_input("OVS_interface", node));
data->iface_table = iface_table;
return EN_UPDATED;
}
static enum engine_input_handler_result
ovs_interface_shadow_ovs_interface_handler(struct engine_node *node,
void *data_)
{
enum engine_node_state state = en_ovs_interface_shadow_run(node, data_);
if (state == EN_UPDATED) {
return EN_HANDLED_UPDATED;
} else {
return EN_HANDLED_UNCHANGED;
}
}
struct ed_type_activated_ports {
struct ovs_list *activated_ports;
};
static void *
en_activated_ports_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_activated_ports *data = xzalloc(sizeof *data);
data->activated_ports = NULL;
return data;
}
static void
en_activated_ports_cleanup(void *data_)
{
struct ed_type_activated_ports *data = data_;
if (!data->activated_ports) {
return;
}
struct activated_port *pp;
LIST_FOR_EACH_POP (pp, list, data->activated_ports) {
free(pp);
}
free(data->activated_ports);
data->activated_ports = NULL;
}
static void
en_activated_ports_clear_tracked_data(void *data)
{
en_activated_ports_cleanup(data);
}
static enum engine_node_state
en_activated_ports_run(struct engine_node *node OVS_UNUSED, void *data_)
{
struct ed_type_activated_ports *data = data_;
enum engine_node_state state = EN_UNCHANGED;
data->activated_ports = get_ports_to_activate_in_engine();
if (data->activated_ports) {
state = EN_UPDATED;
}
return state;
}
struct ed_type_postponed_ports {
struct sset *postponed_ports;
};
static void *
en_postponed_ports_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_postponed_ports *data = xzalloc(sizeof *data);
data->postponed_ports = get_postponed_ports();
return data;
}
static void
en_postponed_ports_cleanup(void *data_)
{
struct ed_type_postponed_ports *data = data_;
if (!data->postponed_ports) {
return;
}
data->postponed_ports = NULL;
}
static enum engine_node_state
en_postponed_ports_run(struct engine_node *node OVS_UNUSED, void *data_)
{
struct ed_type_postponed_ports *data = data_;
enum engine_node_state state = EN_UNCHANGED;
data->postponed_ports = get_postponed_ports();
if (!sset_is_empty(data->postponed_ports)) {
state = EN_UPDATED;
}
return state;
}
struct ed_type_runtime_data {
/* Contains "struct local_datapath" nodes. */
struct hmap local_datapaths;
struct local_binding_data lbinding_data;
/* Contains the name of each logical port resident on the local
* hypervisor. These logical ports include the VIFs (and their child
* logical ports, if any) that belong to VMs running on the hypervisor,
* l2gateway ports for which options:l2gateway-chassis designates the
* local hypervisor, and localnet ports.
* The value is mapped to enum binding_local_lport_status. */
struct simap local_lports;
/* Port bindings that are relevant to the local chassis (VIFs bound
* localy, patch ports).
*/
struct related_lports related_lports;
struct sset active_tunnels;
/* runtime data engine private data. */
struct hmap qos_map;
struct smap local_iface_ids;
/* Tracked data. See below for more details and comments. */
bool tracked;
bool local_lports_changed;
bool localnet_learn_fdb;
bool localnet_learn_fdb_changed;
struct hmap tracked_dp_bindings;
struct shash local_active_ports_ipv6_pd;
struct shash local_active_ports_ras;
struct sset *postponed_ports;
};
/* struct ed_type_runtime_data has the below members for tracking the
* changes done to the runtime_data engine by the runtime_data engine
* handlers. Since this engine is an input to the flow_output engine,
* the flow output runtime data handler will make use of this tracked data.
*
* ------------------------------------------------------------------------
* | | This is a hmap of |
* | | 'struct tracked_datapath' defined in |
* | | ldata.h. Runtime data handlers for OVS |
* | | Interface and Port Binding changes store the |
* | @tracked_dp_bindings | changed datapaths (datapaths added/removed from |
* | | local_datapaths) and changed port bindings |
* | | (added/updated/deleted in 'lbinding_data'). |
* | | So any changes to the runtime data - |
* | | local_datapaths and lbinding_data is captured |
* | | here. |
* ------------------------------------------------------------------------
* | | This is a bool which represents if the runtime |
* | | data 'local_lports' changed by the runtime data |
* | | handlers for OVS Interface and Port Binding |
* | | changes. If 'local_lports' is updated and also |
* | | results in any port binding updates, it is |
* |@local_lports_changed | captured in the @tracked_dp_bindings. So there |
* | | is no need to capture the changes in the |
* | | local_lports. If @local_lports_changed is true |
* | | but without anydata in the @tracked_dp_bindings,|
* | | it means we needto only update the SB monitor |
* | | clauses and there isno need for any flow |
* | | (re)computations. |
* ------------------------------------------------------------------------
* | | This represents if the data was tracked or not |
* | | by the runtime data handlers during the engine |
* | @tracked | run. If the runtime data recompute is |
* | | triggered, it means there is no tracked data. |
* ------------------------------------------------------------------------
*
*
* The changes to the following runtime_data variables are not tracked.
*
* ---------------------------------------------------------------------
* | local_datapaths | The changes to these runtime data is captured in |
* | lbinding_data | the @tracked_dp_bindings indirectly and hence it |
* | local_lport_ids | is not tracked explicitly. |
* ---------------------------------------------------------------------
* | local_iface_ids | This is used internally within the runtime data |
* | qos_map | engine (used only in binding.c) and hence there |
* | | there is no need to track. |
* ---------------------------------------------------------------------
* | | Active tunnels is built in the |
* | | bfd_calculate_active_tunnels() for the tunnel |
* | | OVS interfaces. Any changes to non VIF OVS |
* | | interfaces results in triggering the full |
* | active_tunnels | recompute of runtime data engine and hence there |
* | | the tracked data doesn't track it. When we |
* | | support handling changes to non VIF OVS |
* | | interfaces we need to track the changes to the |
* | | active tunnels. |
* ---------------------------------------------------------------------
*
*/
static void
en_runtime_data_clear_tracked_data(void *data_)
{
struct ed_type_runtime_data *data = data_;
tracked_datapaths_destroy(&data->tracked_dp_bindings);
hmap_init(&data->tracked_dp_bindings);
data->local_lports_changed = false;
data->tracked = false;
}
static void *
en_runtime_data_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_runtime_data *data = xzalloc(sizeof *data);
hmap_init(&data->local_datapaths);
simap_init(&data->local_lports);
related_lports_init(&data->related_lports);
sset_init(&data->active_tunnels);
hmap_init(&data->qos_map);
smap_init(&data->local_iface_ids);
local_binding_data_init(&data->lbinding_data);
shash_init(&data->local_active_ports_ipv6_pd);
shash_init(&data->local_active_ports_ras);
/* Init the tracked data. */
hmap_init(&data->tracked_dp_bindings);
return data;
}
static void
en_runtime_data_cleanup(void *data)
{
struct ed_type_runtime_data *rt_data = data;
simap_destroy(&rt_data->local_lports);
related_lports_destroy(&rt_data->related_lports);
sset_destroy(&rt_data->active_tunnels);
destroy_qos_map(&rt_data->qos_map);
smap_destroy(&rt_data->local_iface_ids);
local_datapaths_destroy(&rt_data->local_datapaths);
shash_destroy(&rt_data->local_active_ports_ipv6_pd);
shash_destroy(&rt_data->local_active_ports_ras);
local_binding_data_destroy(&rt_data->lbinding_data);
}
static void
init_binding_ctx(struct engine_node *node,
struct ed_type_runtime_data *rt_data,
struct binding_ctx_in *b_ctx_in,
struct binding_ctx_out *b_ctx_out)
{
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
ovs_assert(br_int && chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct ed_type_ovs_interface_shadow *iface_shadow =
engine_get_input_data("ovs_interface_shadow", node);
const struct ovsrec_qos_table *qos_table =
EN_OVSDB_GET(engine_get_input("OVS_qos", node));
const struct sbrec_port_binding_table *pb_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
struct ovsdb_idl_index *sbrec_datapath_binding_by_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_datapath_binding", node),
"key");
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ovsdb_idl_index *sbrec_port_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"datapath");
struct ovsdb_idl_index *ovsrec_port_by_qos =
engine_ovsdb_node_get_index(
engine_get_input("OVS_port", node), "qos");
struct ovsdb_idl_index *ovsrec_queue_by_external_ids =
engine_ovsdb_node_get_index(
engine_get_input("OVS_queue", node), "external_ids");
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
b_ctx_in->ovnsb_idl_txn = engine_get_context()->ovnsb_idl_txn;
b_ctx_in->ovs_idl_txn = engine_get_context()->ovs_idl_txn;
b_ctx_in->sbrec_datapath_binding_by_key = sbrec_datapath_binding_by_key;
b_ctx_in->sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath;
b_ctx_in->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
b_ctx_in->ovsrec_port_by_qos = ovsrec_port_by_qos;
b_ctx_in->ovsrec_queue_by_external_ids = ovsrec_queue_by_external_ids;
b_ctx_in->iface_table = iface_shadow->iface_table;
b_ctx_in->iface_table_external_ids_old =
&iface_shadow->iface_table_external_ids_old;
b_ctx_in->qos_table = qos_table;
b_ctx_in->port_binding_table = pb_table;
b_ctx_in->br_int = br_int;
b_ctx_in->chassis_rec = chassis;
b_ctx_in->active_tunnels = &rt_data->active_tunnels;
b_ctx_in->bridge_table = bridge_table;
b_ctx_in->ovs_table = ovs_table;
b_ctx_out->local_datapaths = &rt_data->local_datapaths;
b_ctx_out->local_active_ports_ipv6_pd =
&rt_data->local_active_ports_ipv6_pd;
b_ctx_out->local_active_ports_ras =
&rt_data->local_active_ports_ras;
b_ctx_out->local_lports = &rt_data->local_lports;
b_ctx_out->local_lports_changed = false;
b_ctx_out->related_lports = &rt_data->related_lports;
b_ctx_out->related_lports_changed = false;
b_ctx_out->non_vif_ports_changed = false;
b_ctx_out->qos_map = &rt_data->qos_map;
b_ctx_out->lbinding_data = &rt_data->lbinding_data;
b_ctx_out->local_iface_ids = &rt_data->local_iface_ids;
b_ctx_out->postponed_ports = rt_data->postponed_ports;
b_ctx_out->tracked_dp_bindings = NULL;
b_ctx_out->if_mgr = ctrl_ctx->if_mgr;
b_ctx_out->localnet_learn_fdb = rt_data->localnet_learn_fdb;
b_ctx_out->localnet_learn_fdb_changed = false;
}
static enum engine_node_state
en_runtime_data_run(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data = data;
struct hmap *local_datapaths = &rt_data->local_datapaths;
struct shash *local_active_ipv6_pd = &rt_data->local_active_ports_ipv6_pd;
struct shash *local_active_ras = &rt_data->local_active_ports_ras;
struct simap *local_lports = &rt_data->local_lports;
struct sset *active_tunnels = &rt_data->active_tunnels;
static bool first_run = true;
if (first_run) {
/* don't cleanup since there is no data yet */
first_run = false;
} else {
local_datapaths_destroy(local_datapaths);
shash_clear(local_active_ipv6_pd);
shash_clear(local_active_ras);
local_binding_data_destroy(&rt_data->lbinding_data);
simap_destroy(local_lports);
related_lports_destroy(&rt_data->related_lports);
sset_destroy(active_tunnels);
destroy_qos_map(&rt_data->qos_map);
smap_destroy(&rt_data->local_iface_ids);
hmap_init(local_datapaths);
simap_init(local_lports);
related_lports_init(&rt_data->related_lports);
sset_init(active_tunnels);
hmap_init(&rt_data->qos_map);
smap_init(&rt_data->local_iface_ids);
local_binding_data_init(&rt_data->lbinding_data);
}
struct ed_type_postponed_ports *pp_data =
engine_get_input_data("postponed_ports", node);
rt_data->postponed_ports = pp_data->postponed_ports;
struct binding_ctx_in b_ctx_in;
struct binding_ctx_out b_ctx_out;
init_binding_ctx(node, rt_data, &b_ctx_in, &b_ctx_out);
struct ed_type_ofctrl_is_connected *ed_ofctrl_is_connected =
engine_get_input_data("ofctrl_is_connected", node);
if (ed_ofctrl_is_connected->connected) {
/* Calculate the active tunnels only if have an an active
* OpenFlow connection to br-int.
* If we don't have a connection to br-int, it could mean
* ovs-vswitchd is down for some reason and the BFD status
* in the Interface rows could be stale. So its better to
* consider 'active_tunnels' set to be empty if it's not
* connected. */
bfd_calculate_active_tunnels(b_ctx_in.br_int, active_tunnels);
}
binding_run(&b_ctx_in, &b_ctx_out);
rt_data->localnet_learn_fdb = b_ctx_out.localnet_learn_fdb;
return EN_UPDATED;
}
struct ed_type_sb_ro {
bool sb_readonly;
};
static void *
en_sb_ro_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_sb_ro *data = xzalloc(sizeof *data);
return data;
}
static enum engine_node_state
en_sb_ro_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_sb_ro *sb_ro_data = data;
bool sb_readonly = !engine_get_context()->ovnsb_idl_txn;
if (sb_ro_data->sb_readonly != sb_readonly) {
sb_ro_data->sb_readonly = sb_readonly;
if (!sb_ro_data->sb_readonly) {
return EN_UPDATED;
}
}
return EN_UNCHANGED;
}
static void
en_sb_ro_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_input_handler_result
runtime_data_sb_ro_handler(struct engine_node *node, void *data)
{
const struct sbrec_chassis *chassis = NULL;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
struct ovsrec_open_vswitch_table *ovs_table =
(struct ovsrec_open_vswitch_table *)EN_OVSDB_GET(
engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_port_binding_table *pb_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
if (chassis_id) {
chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
}
if (chassis) {
struct ed_type_runtime_data *rt_data = data;
struct controller_engine_ctx *ctrl_ctx =
engine_get_context()->client_ctx;
if (if_status_handle_claims(ctrl_ctx->if_mgr, &rt_data->lbinding_data,
chassis, &rt_data->tracked_dp_bindings,
pb_table)) {
result = EN_HANDLED_UPDATED;
rt_data->tracked = true;
}
}
return result;
}
static enum engine_input_handler_result
runtime_data_ovs_interface_shadow_handler(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data = data;
struct binding_ctx_in b_ctx_in;
struct binding_ctx_out b_ctx_out;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
init_binding_ctx(node, rt_data, &b_ctx_in, &b_ctx_out);
rt_data->tracked = true;
b_ctx_out.tracked_dp_bindings = &rt_data->tracked_dp_bindings;
if (!binding_handle_ovs_interface_changes(&b_ctx_in, &b_ctx_out)) {
return EN_UNHANDLED;
}
if (b_ctx_out.local_lports_changed) {
result = EN_HANDLED_UPDATED;
rt_data->local_lports_changed = b_ctx_out.local_lports_changed;
}
return result;
}
static enum engine_input_handler_result
runtime_data_sb_port_binding_handler(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data = data;
struct binding_ctx_in b_ctx_in;
struct binding_ctx_out b_ctx_out;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
init_binding_ctx(node, rt_data, &b_ctx_in, &b_ctx_out);
if (!b_ctx_in.chassis_rec) {
return EN_UNHANDLED;
}
rt_data->tracked = true;
b_ctx_out.tracked_dp_bindings = &rt_data->tracked_dp_bindings;
if (!binding_handle_port_binding_changes(&b_ctx_in, &b_ctx_out)) {
return EN_UNHANDLED;
}
rt_data->local_lports_changed = b_ctx_out.local_lports_changed;
rt_data->localnet_learn_fdb = b_ctx_out.localnet_learn_fdb;
rt_data->localnet_learn_fdb_changed = b_ctx_out.localnet_learn_fdb_changed;
if (b_ctx_out.related_lports_changed ||
b_ctx_out.non_vif_ports_changed ||
b_ctx_out.local_lports_changed ||
b_ctx_out.localnet_learn_fdb_changed ||
!hmap_is_empty(b_ctx_out.tracked_dp_bindings)) {
result = EN_HANDLED_UPDATED;
}
return result;
}
static enum engine_input_handler_result
runtime_data_sb_datapath_binding_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
struct sbrec_datapath_binding_table *dp_table =
(struct sbrec_datapath_binding_table *)EN_OVSDB_GET(
engine_get_input("SB_datapath_binding", node));
const struct sbrec_datapath_binding *dp;
struct ed_type_runtime_data *rt_data = data;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_table) {
if (sbrec_datapath_binding_is_deleted(dp)) {
if (get_local_datapath(&rt_data->local_datapaths,
dp->tunnel_key)) {
return EN_UNHANDLED;
}
}
if (sbrec_datapath_binding_is_updated(
dp, SBREC_DATAPATH_BINDING_COL_TUNNEL_KEY) &&
!sbrec_datapath_binding_is_new(dp)) {
/* If the tunnel key got updated, get_local_datapath will not find
* the ld. Use get_local_datapath_no_hash which does not
* rely on the hash.
*/
if (get_local_datapath_no_hash(&rt_data->local_datapaths,
dp->tunnel_key)) {
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UNCHANGED;
}
static void
local_templates_to_string(const struct smap *local_templates,
struct ds *out_data)
{
const struct smap_node **nodes = smap_sort(local_templates);
for (size_t i = 0; i < smap_count(local_templates); i++) {
const struct smap_node *node = nodes[i];
ds_put_format(out_data, "name: '%s' value: '%s'\n",
node->key, node->value);
}
free(nodes);
}
struct ed_type_template_vars {
struct smap local_templates;
bool change_tracked;
struct sset new;
struct sset deleted;
struct sset updated;
};
static void
template_vars_init(struct ovsdb_idl_index *tv_index_by_chassis,
const struct sbrec_chassis *chassis,
struct smap *local_templates)
{
const struct sbrec_chassis_template_var *tv;
struct sbrec_chassis_template_var *tv_key =
sbrec_chassis_template_var_index_init_row(tv_index_by_chassis);
sbrec_chassis_template_var_index_set_chassis(tv_key, chassis->name);
tv = sbrec_chassis_template_var_index_find(tv_index_by_chassis, tv_key);
if (tv) {
smap_destroy(local_templates);
smap_clone(local_templates, &tv->variables);
}
sbrec_chassis_template_var_index_destroy_row(tv_key);
}
static void
template_vars_update(const struct sbrec_chassis_template_var_table *tv_table,
const struct sbrec_chassis *chassis,
struct smap *local_templates, struct sset *new,
struct sset *deleted, struct sset *updated)
{
const struct sbrec_chassis_template_var *tv;
struct smap_node *node;
SBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH_TRACKED (tv, tv_table) {
if (strcmp(tv->chassis, chassis->name)) {
continue;
}
if (sbrec_chassis_template_var_is_deleted(tv)) {
SMAP_FOR_EACH (node, local_templates) {
sset_add(deleted, node->key);
}
} else if (sbrec_chassis_template_var_is_new(tv)) {
ovs_assert(smap_count(local_templates) == 0);
SMAP_FOR_EACH (node, &tv->variables) {
sset_add(new, node->key);
}
} else {
SMAP_FOR_EACH (node, &tv->variables) {
struct smap_node *old = smap_get_node(local_templates,
node->key);
if (old) {
if (strcmp(old->value, node->value)) {
sset_add(updated, node->key);
}
} else {
sset_add(new, node->key);
}
}
SMAP_FOR_EACH (node, local_templates) {
sset_add (deleted, node->key);
}
}
smap_destroy(local_templates);
smap_clone(local_templates, &tv->variables);
return;
}
}
static void *
en_template_vars_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_template_vars *tv_data = xzalloc(sizeof *tv_data);
smap_init(&tv_data->local_templates);
tv_data->change_tracked = false;
sset_init(&tv_data->new);
sset_init(&tv_data->deleted);
sset_init(&tv_data->updated);
return tv_data;
}
static enum engine_node_state
en_template_vars_run(struct engine_node *node, void *data)
{
struct ed_type_template_vars *tv_data = data;
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis =
chassis_lookup_by_name(sbrec_chassis_by_name,
get_ovs_chassis_id(ovs_table));
struct ovsdb_idl_index *sbrec_chassis_template_var_index_by_chassis =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis_template_var", node),
"chassis");
smap_clear(&tv_data->local_templates);
template_vars_init(sbrec_chassis_template_var_index_by_chassis,
chassis, &tv_data->local_templates);
return EN_UPDATED;
}
static enum engine_input_handler_result
template_vars_sb_chassis_template_var_handler(struct engine_node *node,
void *data)
{
struct ed_type_template_vars *tv_data = data;
enum engine_input_handler_result result;
const struct sbrec_chassis_template_var_table *tv_table =
EN_OVSDB_GET(engine_get_input("SB_chassis_template_var", node));
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis =
chassis_lookup_by_name(sbrec_chassis_by_name,
get_ovs_chassis_id(ovs_table));
template_vars_update(tv_table, chassis, &tv_data->local_templates,
&tv_data->new, &tv_data->deleted, &tv_data->updated);
if (!sset_is_empty(&tv_data->new) || !sset_is_empty(&tv_data->deleted) ||
!sset_is_empty(&tv_data->updated)) {
result = EN_HANDLED_UPDATED;
} else {
result = EN_HANDLED_UNCHANGED;
}
tv_data->change_tracked = true;
return result;
}
static void
en_template_vars_clear_tracked_data(void *data)
{
struct ed_type_template_vars *tv_data = data;
sset_clear(&tv_data->new);
sset_clear(&tv_data->deleted);
sset_clear(&tv_data->updated);
tv_data->change_tracked = false;
}
static void
en_template_vars_cleanup(void *data)
{
struct ed_type_template_vars *tv_data = data;
smap_destroy(&tv_data->local_templates);
sset_destroy(&tv_data->new);
sset_destroy(&tv_data->deleted);
sset_destroy(&tv_data->updated);
}
struct ed_type_addr_sets {
struct shash addr_sets;
bool change_tracked;
struct sset new;
struct sset deleted;
struct shash updated;
};
static void *
en_addr_sets_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_addr_sets *as = xzalloc(sizeof *as);
shash_init(&as->addr_sets);
as->change_tracked = false;
sset_init(&as->new);
sset_init(&as->deleted);
shash_init(&as->updated);
return as;
}
static void
en_addr_sets_clear_tracked_data(void *data)
{
struct ed_type_addr_sets *as = data;
sset_clear(&as->new);
sset_clear(&as->deleted);
struct shash_node *node;
SHASH_FOR_EACH_SAFE (node, &as->updated) {
struct addr_set_diff *asd = node->data;
expr_constant_set_destroy(asd->added);
free(asd->added);
expr_constant_set_destroy(asd->deleted);
free(asd->deleted);
}
shash_clear_free_data(&as->updated);
as->change_tracked = false;
}
static void
en_addr_sets_cleanup(void *data)
{
en_addr_sets_clear_tracked_data(data);
struct ed_type_addr_sets *as = data;
expr_const_sets_destroy(&as->addr_sets);
shash_destroy(&as->addr_sets);
sset_destroy(&as->new);
sset_destroy(&as->deleted);
shash_destroy(&as->updated);
}
/* Iterate address sets in the southbound database. Create and update the
* corresponding symtab entries as necessary. */
static void
addr_sets_init(const struct sbrec_address_set_table *address_set_table,
struct shash *addr_sets)
{
const struct sbrec_address_set *as;
SBREC_ADDRESS_SET_TABLE_FOR_EACH (as, address_set_table) {
expr_const_sets_add_integers(addr_sets, as->name,
(const char *const *) as->addresses,
as->n_addresses);
}
}
static void
addr_sets_update(const struct sbrec_address_set_table *address_set_table,
struct shash *addr_sets, struct sset *added,
struct sset *deleted, struct shash *updated)
{
const struct sbrec_address_set *as;
SBREC_ADDRESS_SET_TABLE_FOR_EACH_TRACKED (as, address_set_table) {
if (sbrec_address_set_is_deleted(as)) {
expr_const_sets_remove(addr_sets, as->name);
sset_add(deleted, as->name);
}
}
SBREC_ADDRESS_SET_TABLE_FOR_EACH_TRACKED (as, address_set_table) {
if (!sbrec_address_set_is_deleted(as)) {
struct expr_constant_set *cs_old = shash_find_data(addr_sets,
as->name);
if (!cs_old) {
sset_add(added, as->name);
expr_const_sets_add_integers(addr_sets, as->name,
(const char *const *) as->addresses, as->n_addresses);
} else {
/* Find out the diff for the updated address set. */
struct expr_constant_set *cs_new =
expr_constant_set_create_integers(
(const char *const *) as->addresses, as->n_addresses);
struct addr_set_diff *as_diff = xmalloc(sizeof *as_diff);
expr_constant_set_integers_diff(cs_old, cs_new,
&as_diff->added,
&as_diff->deleted);
if (!as_diff->added && !as_diff->deleted) {
/* The address set may have been updated, but the change
* doesn't has any impact to the generated constant-set.
* For example, ff::01 is changed to ff::00:01. */
free(as_diff);
expr_constant_set_destroy(cs_new);
free(cs_new);
continue;
}
shash_add(updated, as->name, as_diff);
expr_const_sets_add(addr_sets, as->name, cs_new);
}
}
}
}
static enum engine_node_state
en_addr_sets_run(struct engine_node *node, void *data)
{
struct ed_type_addr_sets *as = data;
expr_const_sets_destroy(&as->addr_sets);
struct sbrec_address_set_table *as_table =
(struct sbrec_address_set_table *)EN_OVSDB_GET(
engine_get_input("SB_address_set", node));
addr_sets_init(as_table, &as->addr_sets);
as->change_tracked = false;
return EN_UPDATED;
}
static enum engine_input_handler_result
addr_sets_sb_address_set_handler(struct engine_node *node, void *data)
{
struct ed_type_addr_sets *as = data;
enum engine_input_handler_result result;
struct sbrec_address_set_table *as_table =
(struct sbrec_address_set_table *)EN_OVSDB_GET(
engine_get_input("SB_address_set", node));
addr_sets_update(as_table, &as->addr_sets, &as->new,
&as->deleted, &as->updated);
if (!sset_is_empty(&as->new) || !sset_is_empty(&as->deleted) ||
!shash_is_empty(&as->updated)) {
result = EN_HANDLED_UPDATED;
} else {
result = EN_HANDLED_UNCHANGED;
}
as->change_tracked = true;
return result;
}
struct ed_type_port_groups{
/* A copy of SB port_groups, each converted as a sset for efficient lport
* lookup. */
struct shash port_group_ssets;
/* Const sets containing local lports, used for expr parsing. */
struct shash port_groups_cs_local;
bool change_tracked;
struct sset new;
struct sset deleted;
struct sset updated;
};
static void
port_group_ssets_add_or_update(struct shash *port_group_ssets,
const struct sbrec_port_group *pg)
{
struct sset *lports = shash_find_data(port_group_ssets, pg->name);
if (lports) {
sset_clear(lports);
} else {
lports = xzalloc(sizeof *lports);
sset_init(lports);
shash_add(port_group_ssets, pg->name, lports);
}
for (size_t i = 0; i < pg->n_ports; i++) {
sset_add(lports, pg->ports[i]);
}
}
static void
port_group_ssets_delete(struct shash *port_group_ssets,
const char *pg_name)
{
struct shash_node *node = shash_find(port_group_ssets, pg_name);
if (node) {
struct sset *lports = node->data;
shash_delete(port_group_ssets, node);
sset_destroy(lports);
free(lports);
}
}
/* Delete and free all ssets in port_group_ssets, but not
* destroying the shash itself. */
static void
port_group_ssets_clear(struct shash *port_group_ssets)
{
struct shash_node *node;
SHASH_FOR_EACH_SAFE (node, port_group_ssets) {
struct sset *lports = node->data;
shash_delete(port_group_ssets, node);
sset_destroy(lports);
free(lports);
}
}
static void *
en_port_groups_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_port_groups *pg = xzalloc(sizeof *pg);
shash_init(&pg->port_group_ssets);
shash_init(&pg->port_groups_cs_local);
pg->change_tracked = false;
sset_init(&pg->new);
sset_init(&pg->deleted);
sset_init(&pg->updated);
return pg;
}
static void
en_port_groups_cleanup(void *data)
{
struct ed_type_port_groups *pg = data;
expr_const_sets_destroy(&pg->port_groups_cs_local);
shash_destroy(&pg->port_groups_cs_local);
port_group_ssets_clear(&pg->port_group_ssets);
shash_destroy(&pg->port_group_ssets);
sset_destroy(&pg->new);
sset_destroy(&pg->deleted);
sset_destroy(&pg->updated);
}
static void
port_groups_init(const struct sbrec_port_group_table *port_group_table,
const struct sset *local_lports,
struct shash *port_group_ssets,
struct shash *port_groups_cs_local)
{
const struct sbrec_port_group *pg;
SBREC_PORT_GROUP_TABLE_FOR_EACH (pg, port_group_table) {
port_group_ssets_add_or_update(port_group_ssets, pg);
expr_const_sets_add_strings(port_groups_cs_local, pg->name,
(const char *const *) pg->ports,
pg->n_ports, local_lports);
}
}
static void
port_groups_update(const struct sbrec_port_group_table *port_group_table,
const struct sset *local_lports,
struct shash *port_group_ssets,
struct shash *port_groups_cs_local,
struct sset *new, struct sset *deleted,
struct sset *updated)
{
const struct sbrec_port_group *pg;
SBREC_PORT_GROUP_TABLE_FOR_EACH_TRACKED (pg, port_group_table) {
if (sbrec_port_group_is_deleted(pg)) {
expr_const_sets_remove(port_groups_cs_local, pg->name);
port_group_ssets_delete(port_group_ssets, pg->name);
sset_add(deleted, pg->name);
}
}
SBREC_PORT_GROUP_TABLE_FOR_EACH_TRACKED (pg, port_group_table) {
if (!sbrec_port_group_is_deleted(pg)) {
port_group_ssets_add_or_update(port_group_ssets, pg);
expr_const_sets_add_strings(port_groups_cs_local, pg->name,
(const char *const *) pg->ports,
pg->n_ports, local_lports);
if (sbrec_port_group_is_new(pg)) {
sset_add(new, pg->name);
} else {
sset_add(updated, pg->name);
}
}
}
}
static void
en_port_groups_clear_tracked_data(void *data_)
{
struct ed_type_port_groups *pg = data_;
sset_clear(&pg->new);
sset_clear(&pg->deleted);
sset_clear(&pg->updated);
pg->change_tracked = false;
}
static enum engine_node_state
en_port_groups_run(struct engine_node *node, void *data)
{
struct ed_type_port_groups *pg = data;
expr_const_sets_destroy(&pg->port_groups_cs_local);
port_group_ssets_clear(&pg->port_group_ssets);
const struct sbrec_port_group_table *pg_table =
EN_OVSDB_GET(engine_get_input("SB_port_group", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
port_groups_init(pg_table, &rt_data->related_lports.lport_names,
&pg->port_group_ssets, &pg->port_groups_cs_local);
return EN_UPDATED;
}
static enum engine_input_handler_result
port_groups_sb_port_group_handler(struct engine_node *node, void *data)
{
struct ed_type_port_groups *pg = data;
enum engine_input_handler_result result;
const struct sbrec_port_group_table *pg_table =
EN_OVSDB_GET(engine_get_input("SB_port_group", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
port_groups_update(pg_table, &rt_data->related_lports.lport_names,
&pg->port_group_ssets, &pg->port_groups_cs_local,
&pg->new, &pg->deleted, &pg->updated);
if (!sset_is_empty(&pg->new) || !sset_is_empty(&pg->deleted) ||
!sset_is_empty(&pg->updated)) {
result = EN_HANDLED_UPDATED;
} else {
result = EN_HANDLED_UNCHANGED;
}
pg->change_tracked = true;
return result;
}
static enum engine_input_handler_result
port_groups_runtime_data_handler(struct engine_node *node, void *data)
{
const struct sbrec_port_group_table *pg_table =
EN_OVSDB_GET(engine_get_input("SB_port_group", node));
struct ed_type_port_groups *pg = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
enum engine_input_handler_result result;
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
if (hmap_is_empty(&rt_data->tracked_dp_bindings)) {
goto out;
}
const struct sbrec_port_group *pg_sb;
SBREC_PORT_GROUP_TABLE_FOR_EACH (pg_sb, pg_table) {
struct sset *pg_lports = shash_find_data(&pg->port_group_ssets,
pg_sb->name);
ovs_assert(pg_lports);
struct tracked_datapath *tdp;
bool need_update = false;
HMAP_FOR_EACH (tdp, node, &rt_data->tracked_dp_bindings) {
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &tdp->lports) {
struct tracked_lport *lport = shash_node->data;
if (sset_contains(pg_lports, lport->pb->logical_port)) {
/* At least one local port-binding change is related to the
* port_group, so the port_group_cs_local needs update. */
need_update = true;
break;
}
}
if (need_update) {
break;
}
}
if (need_update) {
expr_const_sets_add_strings(&pg->port_groups_cs_local, pg_sb->name,
(const char *const *) pg_sb->ports,
pg_sb->n_ports,
&rt_data->related_lports.lport_names);
sset_add(&pg->updated, pg_sb->name);
}
}
out:
if (!sset_is_empty(&pg->new) || !sset_is_empty(&pg->deleted) ||
!sset_is_empty(&pg->updated)) {
result = EN_HANDLED_UPDATED;
} else {
result = EN_HANDLED_UNCHANGED;
}
pg->change_tracked = true;
return result;
}
static void *
en_ct_zones_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_ct_zones *data = xzalloc(sizeof *data);
ct_zone_ctx_init(&data->ctx);
return data;
}
static void
en_ct_zones_clear_tracked_data(void *data_)
{
struct ed_type_ct_zones *data = data_;
data->recomputed = false;
}
static void
en_ct_zones_cleanup(void *data)
{
struct ed_type_ct_zones *ct_zones_data = data;
ct_zone_ctx_destroy(&ct_zones_data->ctx);
}
static enum engine_node_state
en_ct_zones_run(struct engine_node *node, void *data)
{
struct ed_type_ct_zones *ct_zones_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
ct_zones_restore(&ct_zones_data->ctx, ovs_table, dp_table, br_int);
ct_zones_update(&rt_data->local_lports, ovs_table,
&rt_data->local_datapaths, &ct_zones_data->ctx);
ct_zones_limits_sync(&ct_zones_data->ctx, &rt_data->local_datapaths,
&rt_data->lbinding_data.lports);
ct_zones_data->recomputed = true;
return EN_UPDATED;
}
/* Handles datapath binding changes for the ct_zones engine.
* Returns false if the datapath is deleted or if the requested snat
* ct zone doesn't match with the ct_zones data. */
static enum engine_input_handler_result
ct_zones_datapath_binding_handler(struct engine_node *node, void *data)
{
struct ed_type_ct_zones *ct_zones_data = data;
const struct sbrec_datapath_binding *dp;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_table) {
const struct local_datapath *local_dp=
get_local_datapath(&rt_data->local_datapaths, dp->tunnel_key);
if (!local_dp) {
continue;
}
if (sbrec_datapath_binding_is_deleted(dp) ||
sbrec_datapath_binding_is_new(dp)) {
/* Fall back to full recompute of ct_zones engine. */
return EN_UNHANDLED;
}
if (!ct_zone_handle_dp_update(&ct_zones_data->ctx, local_dp,
&rt_data->lbinding_data.lports)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
ct_zones_runtime_data_handler(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
/* There is no tracked data. Fall back to full recompute of ct_zones. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct ed_type_ct_zones *ct_zones_data = data;
struct hmap *tracked_dp_bindings = &rt_data->tracked_dp_bindings;
int scan_start, min_ct_zone, max_ct_zone;
struct tracked_datapath *tdp;
bool updated = false;
ct_zones_parse_range(ovs_table, &min_ct_zone, &max_ct_zone);
scan_start = min_ct_zone;
HMAP_FOR_EACH (tdp, node, tracked_dp_bindings) {
if (tdp->tracked_type == TRACKED_RESOURCE_NEW) {
/* A new datapath has been added. Fall back to full recompute. */
return EN_UNHANDLED;
}
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &tdp->lports) {
struct tracked_lport *t_lport = shash_node->data;
if (strcmp(t_lport->pb->type, "")
&& strcmp(t_lport->pb->type, "localport")
&& strcmp(t_lport->pb->type, "l3gateway")
&& strcmp(t_lport->pb->type, "localnet")
&& strcmp(t_lport->pb->type, "patch")) {
/* We allocate zone-id's only to VIF, localport, l3gateway,
* localnet and patch (enabled ACL) lports. */
continue;
}
/* For patch ports without ACL flag, delete the ct_zone. */
if (!strcmp(t_lport->pb->type, "patch") &&
!smap_get_bool(&t_lport->pb->options,
"enable_router_port_acl", false)) {
updated |= ct_zone_handle_port_update(&ct_zones_data->ctx,
t_lport->pb,
false, &scan_start,
min_ct_zone,
max_ct_zone);
continue;
}
bool port_updated =
t_lport->tracked_type == TRACKED_RESOURCE_NEW ||
t_lport->tracked_type == TRACKED_RESOURCE_UPDATED;
updated |= ct_zone_handle_port_update(&ct_zones_data->ctx,
t_lport->pb,
port_updated, &scan_start,
min_ct_zone, max_ct_zone);
}
}
return updated ? EN_HANDLED_UPDATED : EN_HANDLED_UNCHANGED;
}
/* The data in the ct_zones node is always valid (i.e., no stale pointers). */
static bool
en_ct_zones_is_valid(struct engine_node *node OVS_UNUSED)
{
return true;
}
struct ed_type_mff_ovn_geneve {
enum mf_field_id mff_ovn_geneve;
};
static void *
en_mff_ovn_geneve_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_mff_ovn_geneve *data = xzalloc(sizeof *data);
return data;
}
static void
en_mff_ovn_geneve_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_mff_ovn_geneve_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve = data;
enum mf_field_id mff_ovn_geneve = ofctrl_get_mf_field_id();
if (ed_mff_ovn_geneve->mff_ovn_geneve != mff_ovn_geneve) {
ed_mff_ovn_geneve->mff_ovn_geneve = mff_ovn_geneve;
return EN_UPDATED;
}
return EN_UNCHANGED;
}
/* Stores the load balancers that are applied to the datapath 'dp'. */
struct load_balancers_by_dp {
struct hmap_node node;
const struct sbrec_datapath_binding *dp;
struct vector dp_lbs; /* Vector of const struct sbrec_load_balancer *. */
};
static struct load_balancers_by_dp *
load_balancers_by_dp_create(struct hmap *lbs,
const struct sbrec_datapath_binding *dp)
{
struct load_balancers_by_dp *lbs_by_dp = xzalloc(sizeof *lbs_by_dp);
lbs_by_dp->dp = dp;
lbs_by_dp->dp_lbs =
VECTOR_EMPTY_INITIALIZER(const struct sbrec_load_balancer *);
hmap_insert(lbs, &lbs_by_dp->node, hash_uint64(dp->tunnel_key));
return lbs_by_dp;
}
static void
load_balancers_by_dp_destroy(struct load_balancers_by_dp *lbs_by_dp)
{
if (!lbs_by_dp) {
return;
}
vector_destroy(&lbs_by_dp->dp_lbs);
free(lbs_by_dp);
}
static struct load_balancers_by_dp *
load_balancers_by_dp_find(struct hmap *lbs,
const struct sbrec_datapath_binding *dp)
{
uint32_t hash = hash_uint64(dp->tunnel_key);
struct load_balancers_by_dp *lbs_by_dp;
HMAP_FOR_EACH_WITH_HASH (lbs_by_dp, node, hash, lbs) {
if (lbs_by_dp->dp == dp) {
return lbs_by_dp;
}
}
return NULL;
}
static void
load_balancers_by_dp_add_one(const struct hmap *local_datapaths,
const struct sbrec_datapath_binding *datapath,
const struct sbrec_load_balancer *lb,
struct hmap *lbs)
{
struct local_datapath *ldp =
get_local_datapath(local_datapaths, datapath->tunnel_key);
if (!ldp) {
return;
}
struct load_balancers_by_dp *lbs_by_dp =
load_balancers_by_dp_find(lbs, ldp->datapath);
if (!lbs_by_dp) {
lbs_by_dp = load_balancers_by_dp_create(lbs, ldp->datapath);
}
vector_push(&lbs_by_dp->dp_lbs, &lb);
}
/* Builds and returns a hmap of 'load_balancers_by_dp', one record for each
* local datapath.
*/
static struct hmap *
load_balancers_by_dp_init(const struct hmap *local_datapaths,
const struct sbrec_load_balancer_table *lb_table)
{
struct hmap *lbs = xmalloc(sizeof *lbs);
hmap_init(lbs);
const struct sbrec_load_balancer *lb;
SBREC_LOAD_BALANCER_TABLE_FOR_EACH (lb, lb_table) {
for (size_t i = 0; i < lb->n_datapaths; i++) {
load_balancers_by_dp_add_one(local_datapaths,
lb->datapaths[i], lb, lbs);
}
/* datapath_group column is deprecated. */
for (size_t i = 0; lb->datapath_group
&& i < lb->datapath_group->n_datapaths; i++) {
load_balancers_by_dp_add_one(local_datapaths,
lb->datapath_group->datapaths[i],
lb, lbs);
}
for (size_t i = 0; lb->ls_datapath_group
&& i < lb->ls_datapath_group->n_datapaths; i++) {
load_balancers_by_dp_add_one(local_datapaths,
lb->ls_datapath_group->datapaths[i],
lb, lbs);
}
for (size_t i = 0; lb->lr_datapath_group
&& i < lb->lr_datapath_group->n_datapaths; i++) {
load_balancers_by_dp_add_one(local_datapaths,
lb->lr_datapath_group->datapaths[i],
lb, lbs);
}
}
return lbs;
}
static void
load_balancers_by_dp_cleanup(struct hmap *lbs)
{
if (!lbs) {
return;
}
struct load_balancers_by_dp *lbs_by_dp;
HMAP_FOR_EACH_POP (lbs_by_dp, node, lbs) {
load_balancers_by_dp_destroy(lbs_by_dp);
}
hmap_destroy(lbs);
free(lbs);
}
/* Engine node which is used to handle runtime related data to
* load balancers. */
struct ed_type_lb_data {
/* Locally installed 'struct ovn_controller_lb' by UUID. */
struct hmap local_lbs;
/* 'struct ovn_lb_five_tuple' removed during last run. */
struct hmap removed_tuples;
/* Load balancer <-> resource cross reference */
struct objdep_mgr deps_mgr;
/* Objects processed in the current engine execution.
* Cleared by 'en_lb_data_clear_tracked_data' before each engine
* execution. */
struct uuidset objs_processed;
bool change_tracked;
/* Load balancers removed/updated during last run. */
struct hmap old_lbs;
/* uuids of load balancers removed during last run. */
struct uuidset deleted;
/* uuids of load balancers updated during last run. */
struct uuidset updated;
/* uuids of load balancers added during last run. */
struct uuidset new;
};
struct lb_data_ctx_in {
const struct sbrec_load_balancer_table *lb_table;
const struct hmap *local_datapaths;
const struct smap *template_vars;
};
static void
lb_data_removed_five_tuples_add(struct ed_type_lb_data *lb_data,
const struct ovn_controller_lb *lb)
{
if (!ovs_feature_is_supported(OVS_CT_TUPLE_FLUSH_SUPPORT) ||
!lb->ct_flush) {
return;
}
for (size_t i = 0; i < lb->n_vips; i++) {
struct ovn_lb_vip *vip = &lb->vips[i];
const struct ovn_lb_backend *backend;
VECTOR_FOR_EACH_PTR (&vip->backends, backend) {
ovn_lb_5tuple_add(&lb_data->removed_tuples, vip, backend,
lb->proto);
}
}
}
static void
lb_data_removed_five_tuples_remove(struct ed_type_lb_data *lb_data,
const struct ovn_controller_lb *lb)
{
if (!ovs_feature_is_supported(OVS_CT_TUPLE_FLUSH_SUPPORT) ||
!lb->ct_flush) {
return;
}
for (size_t i = 0; i < lb->n_vips; i++) {
struct ovn_lb_vip *vip = &lb->vips[i];
const struct ovn_lb_backend *backend;
VECTOR_FOR_EACH_PTR (&vip->backends, backend) {
struct ovn_lb_5tuple tuple;
ovn_lb_5tuple_init(&tuple, vip, backend, lb->proto);
ovn_lb_5tuple_find_and_delete(&lb_data->removed_tuples, &tuple);
}
}
}
static void
lb_data_local_lb_add(struct ed_type_lb_data *lb_data,
const struct sbrec_load_balancer *sbrec_lb,
const struct smap *template_vars, bool tracked)
{
struct sset template_vars_ref = SSET_INITIALIZER(&template_vars_ref);
const struct uuid *uuid = &sbrec_lb->header_.uuid;
struct ovn_controller_lb *lb =
ovn_controller_lb_create(sbrec_lb, template_vars, &template_vars_ref);
hmap_insert(&lb_data->local_lbs, &lb->hmap_node, uuid_hash(uuid));
const char *tv_name;
SSET_FOR_EACH (tv_name, &template_vars_ref) {
objdep_mgr_add(&lb_data->deps_mgr, OBJDEP_TYPE_TEMPLATE, tv_name,
uuid);
}
sset_destroy(&template_vars_ref);
lb_data_removed_five_tuples_remove(lb_data, lb);
if (!tracked) {
return;
}
if (ovn_controller_lb_find(&lb_data->old_lbs, uuid)) {
uuidset_insert(&lb_data->updated, uuid);
uuidset_find_and_delete(&lb_data->deleted, uuid);
} else {
uuidset_insert(&lb_data->new, uuid);
}
}
static void
lb_data_local_lb_remove(struct ed_type_lb_data *lb_data,
struct ovn_controller_lb *lb)
{
const struct uuid *uuid = &lb->slb->header_.uuid;
objdep_mgr_remove_obj(&lb_data->deps_mgr, uuid);
hmap_remove(&lb_data->local_lbs, &lb->hmap_node);
lb_data_removed_five_tuples_add(lb_data, lb);
hmap_insert(&lb_data->old_lbs, &lb->hmap_node, uuid_hash(uuid));
uuidset_insert(&lb_data->deleted, uuid);
}
static bool
lb_data_handle_changed_ref(enum objdep_type type, const char *res_name,
struct uuidset *objs_todo, const void *in_arg,
void *out_arg)
{
const struct lb_data_ctx_in *ctx_in = in_arg;
struct ed_type_lb_data *lb_data = out_arg;
struct uuidset_node *ofrn;
UUIDSET_FOR_EACH (ofrn, objs_todo) {
struct uuid *uuid = &ofrn->uuid;
VLOG_DBG("Reprocess LB "UUID_FMT" for resource type: %s, name: %s",
UUID_ARGS(uuid), objdep_type_name(type), res_name);
struct ovn_controller_lb *lb =
ovn_controller_lb_find(&lb_data->local_lbs, uuid);
if (!lb) {
continue;
}
lb_data_local_lb_remove(lb_data, lb);
const struct sbrec_load_balancer *sbrec_lb =
sbrec_load_balancer_table_get_for_uuid(ctx_in->lb_table, uuid);
if (!lb_is_local(sbrec_lb, ctx_in->local_datapaths)) {
continue;
}
lb_data_local_lb_add(lb_data, sbrec_lb, ctx_in->template_vars, true);
}
uuidset_destroy(objs_todo);
return true;
}
static void *
en_lb_data_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_lb_data *lb_data = xzalloc(sizeof *lb_data);
hmap_init(&lb_data->local_lbs);
hmap_init(&lb_data->removed_tuples);
objdep_mgr_init(&lb_data->deps_mgr);
uuidset_init(&lb_data->objs_processed);
lb_data->change_tracked = false;
hmap_init(&lb_data->old_lbs);
uuidset_init(&lb_data->deleted);
uuidset_init(&lb_data->updated);
uuidset_init(&lb_data->new);
return lb_data;
}
static enum engine_node_state
en_lb_data_run(struct engine_node *node, void *data)
{
struct ed_type_lb_data *lb_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_template_vars *tv_data =
engine_get_input_data("template_vars", node);
const struct sbrec_load_balancer_table *lb_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
objdep_mgr_clear(&lb_data->deps_mgr);
struct ovn_controller_lb *lb;
HMAP_FOR_EACH_SAFE (lb, hmap_node, &lb_data->local_lbs) {
hmap_remove(&lb_data->local_lbs, &lb->hmap_node);
lb_data_removed_five_tuples_add(lb_data, lb);
ovn_controller_lb_destroy(lb);
}
const struct sbrec_load_balancer *sbrec_lb;
SBREC_LOAD_BALANCER_TABLE_FOR_EACH (sbrec_lb, lb_table) {
if (!lb_is_local(sbrec_lb, &rt_data->local_datapaths)) {
continue;
}
lb_data_local_lb_add(lb_data, sbrec_lb,
&tv_data->local_templates, false);
}
return EN_UPDATED;
}
static enum engine_input_handler_result
lb_data_sb_load_balancer_handler(struct engine_node *node, void *data)
{
struct ed_type_lb_data *lb_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_template_vars *tv_data =
engine_get_input_data("template_vars", node);
const struct sbrec_load_balancer_table *lb_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
const struct sbrec_load_balancer *sbrec_lb;
SBREC_LOAD_BALANCER_TABLE_FOR_EACH_TRACKED (sbrec_lb, lb_table) {
struct ovn_controller_lb *lb;
if (!sbrec_load_balancer_is_new(sbrec_lb)) {
lb = ovn_controller_lb_find(&lb_data->local_lbs,
&sbrec_lb->header_.uuid);
if (lb) {
lb_data_local_lb_remove(lb_data, lb);
}
}
if (sbrec_load_balancer_is_deleted(sbrec_lb) ||
!lb_is_local(sbrec_lb, &rt_data->local_datapaths)) {
continue;
}
lb_data_local_lb_add(lb_data, sbrec_lb,
&tv_data->local_templates, true);
}
lb_data->change_tracked = true;
if (!uuidset_is_empty(&lb_data->deleted) ||
!uuidset_is_empty(&lb_data->updated) ||
!uuidset_is_empty(&lb_data->new)) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
lb_data_template_var_handler(struct engine_node *node, void *data)
{
struct ed_type_lb_data *lb_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_template_vars *tv_data =
engine_get_input_data("template_vars", node);
const struct sbrec_load_balancer_table *lb_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
if (!tv_data->change_tracked) {
return EN_UNHANDLED;
}
const struct lb_data_ctx_in ctx_in = {
.lb_table = lb_table,
.local_datapaths = &rt_data->local_datapaths,
.template_vars = &tv_data->local_templates
};
const char *res_name;
bool changed;
SSET_FOR_EACH (res_name, &tv_data->deleted) {
if (!objdep_mgr_handle_change(&lb_data->deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lb_data_handle_changed_ref,
&lb_data->objs_processed,
&ctx_in, lb_data, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (res_name, &tv_data->updated) {
if (!objdep_mgr_handle_change(&lb_data->deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lb_data_handle_changed_ref,
&lb_data->objs_processed,
&ctx_in, lb_data, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (res_name, &tv_data->new) {
if (!objdep_mgr_handle_change(&lb_data->deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lb_data_handle_changed_ref,
&lb_data->objs_processed,
&ctx_in, lb_data, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
lb_data->change_tracked = true;
return result;
}
static enum engine_input_handler_result
lb_data_runtime_data_handler(struct engine_node *node, void *data OVS_UNUSED)
{
struct ed_type_lb_data *lb_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_template_vars *tv_data =
engine_get_input_data("template_vars", node);
const struct sbrec_load_balancer_table *lb_table =
EN_OVSDB_GET(engine_get_input("SB_load_balancer", node));
/* There are no tracked data. Fall back to full recompute of
* lb_ct_tuple. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct hmap *tracked_dp_bindings = &rt_data->tracked_dp_bindings;
if (hmap_is_empty(tracked_dp_bindings)) {
return EN_HANDLED_UNCHANGED;
}
struct hmap *lbs = NULL;
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, tracked_dp_bindings) {
if (tdp->tracked_type != TRACKED_RESOURCE_NEW) {
continue;
}
if (!lbs) {
lbs = load_balancers_by_dp_init(&rt_data->local_datapaths,
lb_table);
}
struct load_balancers_by_dp *lbs_by_dp =
load_balancers_by_dp_find(lbs, tdp->dp);
if (!lbs_by_dp) {
continue;
}
const struct sbrec_load_balancer *sbrec_lb;
VECTOR_FOR_EACH (&lbs_by_dp->dp_lbs, sbrec_lb) {
struct ovn_controller_lb *lb =
ovn_controller_lb_find(&lb_data->local_lbs,
&sbrec_lb->header_.uuid);
if (!lb && lb_is_local(sbrec_lb, &rt_data->local_datapaths)) {
lb_data_local_lb_add(lb_data, sbrec_lb,
&tv_data->local_templates, true);
}
}
}
load_balancers_by_dp_cleanup(lbs);
lb_data->change_tracked = true;
if (!uuidset_is_empty(&lb_data->deleted) ||
!uuidset_is_empty(&lb_data->updated) ||
!uuidset_is_empty(&lb_data->new)) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static void
en_lb_data_clear_tracked_data(void *data)
{
struct ed_type_lb_data *lb_data = data;
struct ovn_controller_lb *lb;
HMAP_FOR_EACH_POP (lb, hmap_node, &lb_data->old_lbs) {
ovn_controller_lb_destroy(lb);
}
hmap_clear(&lb_data->old_lbs);
uuidset_clear(&lb_data->objs_processed);
uuidset_clear(&lb_data->deleted);
uuidset_clear(&lb_data->updated);
uuidset_clear(&lb_data->new);
lb_data->change_tracked = false;
}
static void
en_lb_data_cleanup(void *data)
{
struct ed_type_lb_data *lb_data = data;
ovn_controller_lbs_destroy(&lb_data->local_lbs);
ovn_lb_5tuples_destroy(&lb_data->removed_tuples);
objdep_mgr_destroy(&lb_data->deps_mgr);
uuidset_destroy(&lb_data->objs_processed);
ovn_controller_lbs_destroy(&lb_data->old_lbs);
uuidset_destroy(&lb_data->deleted);
uuidset_destroy(&lb_data->updated);
uuidset_destroy(&lb_data->new);
}
static void
mac_binding_add_sb(struct mac_cache_data *data,
const struct sbrec_mac_binding *smb)
{
struct mac_binding_data mb_data;
if (!mac_binding_data_from_sbrec(&mb_data, smb)) {
return;
}
mac_binding_add(&data->mac_bindings, mb_data, smb, 0);
}
static void
mac_binding_remove_sb(struct mac_cache_data *data,
const struct sbrec_mac_binding *smb)
{
struct mac_binding_data mb_data;
if (!mac_binding_data_from_sbrec(&mb_data, smb)) {
return;
}
struct mac_binding *mb = mac_binding_find(&data->mac_bindings, &mb_data);
if (!mb) {
return;
}
mac_binding_remove(&data->mac_bindings, mb);
}
static void
fdb_add_sb(struct mac_cache_data *data, const struct sbrec_fdb *sfdb)
{
struct fdb_data fdb_data;
if (!fdb_data_from_sbrec(&fdb_data, sfdb)) {
return;
}
struct fdb *fdb = fdb_add(&data->fdbs, fdb_data, 0);
fdb->sbrec_fdb = sfdb;
}
static void
fdb_remove_sb(struct mac_cache_data *data, const struct sbrec_fdb *sfdb)
{
struct fdb_data fdb_data;
if (!fdb_data_from_sbrec(&fdb_data, sfdb)) {
return;
}
struct fdb *fdb = fdb_find(&data->fdbs, &fdb_data);
if (!fdb) {
return;
}
fdb_remove(&data->fdbs, fdb);
}
static void
mac_cache_mb_handle_for_datapath(struct mac_cache_data *data,
const struct sbrec_datapath_binding *dp,
struct ovsdb_idl_index *sbrec_mb_by_dp)
{
bool has_threshold = !!mac_cache_threshold_find(data, dp->tunnel_key);
struct sbrec_mac_binding *mb_index_row =
sbrec_mac_binding_index_init_row(sbrec_mb_by_dp);
sbrec_mac_binding_index_set_datapath(mb_index_row, dp);
const struct sbrec_mac_binding *mb;
SBREC_MAC_BINDING_FOR_EACH_EQUAL (mb, mb_index_row, sbrec_mb_by_dp) {
if (has_threshold) {
mac_binding_add_sb(data, mb);
} else {
mac_binding_remove_sb(data, mb);
}
}
sbrec_mac_binding_index_destroy_row(mb_index_row);
}
static void
mac_cache_fdb_handle_for_datapath(struct mac_cache_data *data,
const struct sbrec_datapath_binding *dp,
struct ovsdb_idl_index *sbrec_fdb_by_dp_key)
{
bool has_threshold = !!mac_cache_threshold_find(data, dp->tunnel_key);
struct sbrec_fdb *fdb_index_row =
sbrec_fdb_index_init_row(sbrec_fdb_by_dp_key);
sbrec_fdb_index_set_dp_key(fdb_index_row, dp->tunnel_key);
const struct sbrec_fdb *fdb;
SBREC_FDB_FOR_EACH_EQUAL (fdb, fdb_index_row, sbrec_fdb_by_dp_key) {
if (has_threshold) {
fdb_add_sb(data, fdb);
} else {
fdb_remove_sb(data, fdb);
}
}
sbrec_fdb_index_destroy_row(fdb_index_row);
}
static void *
en_mac_cache_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct mac_cache_data *cache_data = xzalloc(sizeof *cache_data);
hmap_init(&cache_data->thresholds);
hmap_init(&cache_data->mac_bindings);
hmap_init(&cache_data->fdbs);
return cache_data;
}
static enum engine_node_state
en_mac_cache_run(struct engine_node *node, void *data)
{
struct mac_cache_data *cache_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
struct ovsdb_idl_index *sbrec_mb_by_dp =
engine_ovsdb_node_get_index(
engine_get_input("SB_mac_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_fdb_by_dp_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_fdb", node),
"dp_key");
mac_cache_thresholds_clear(cache_data);
mac_bindings_clear(&cache_data->mac_bindings);
fdbs_clear(&cache_data->fdbs);
const struct sbrec_datapath_binding *sbrec_dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH (sbrec_dp, dp_table) {
if (!get_local_datapath(&rt_data->local_datapaths,
sbrec_dp->tunnel_key)) {
continue;
}
mac_cache_threshold_add(cache_data, sbrec_dp);
mac_cache_mb_handle_for_datapath(cache_data, sbrec_dp,
sbrec_mb_by_dp);
mac_cache_fdb_handle_for_datapath(cache_data, sbrec_dp,
sbrec_fdb_by_dp_key);
}
return EN_UPDATED;
}
static enum engine_input_handler_result
mac_cache_sb_mac_binding_handler(struct engine_node *node, void *data)
{
struct mac_cache_data *cache_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_mac_binding_table *mb_table =
EN_OVSDB_GET(engine_get_input("SB_mac_binding", node));
size_t previous_size = hmap_count(&cache_data->mac_bindings);
const struct sbrec_mac_binding *sbrec_mb;
SBREC_MAC_BINDING_TABLE_FOR_EACH_TRACKED (sbrec_mb, mb_table) {
if (!sbrec_mac_binding_is_new(sbrec_mb)) {
mac_binding_remove_sb(cache_data, sbrec_mb);
}
if (sbrec_mac_binding_is_deleted(sbrec_mb) ||
!get_local_datapath(&rt_data->local_datapaths,
sbrec_mb->datapath->tunnel_key)) {
continue;
}
if (mac_cache_threshold_find(cache_data,
sbrec_mb->datapath->tunnel_key)) {
mac_binding_add_sb(cache_data, sbrec_mb);
}
}
if (hmap_count(&cache_data->mac_bindings) != previous_size) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
mac_cache_sb_fdb_handler(struct engine_node *node, void *data)
{
struct mac_cache_data *cache_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_fdb_table *fdb_table =
EN_OVSDB_GET(engine_get_input("SB_fdb", node));
size_t previous_size = hmap_count(&cache_data->fdbs);
struct local_datapath *local_dp;
const struct sbrec_fdb *sbrec_fdb;
SBREC_FDB_TABLE_FOR_EACH_TRACKED (sbrec_fdb, fdb_table) {
if (!sbrec_fdb_is_new(sbrec_fdb)) {
fdb_remove_sb(cache_data, sbrec_fdb);
}
local_dp = get_local_datapath(&rt_data->local_datapaths,
sbrec_fdb->dp_key);
if (sbrec_fdb_is_deleted(sbrec_fdb) || !local_dp) {
continue;
}
if (mac_cache_threshold_find(cache_data, sbrec_fdb->dp_key)) {
fdb_add_sb(cache_data, sbrec_fdb);
}
}
if (hmap_count(&cache_data->fdbs) != previous_size) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
mac_cache_runtime_data_handler(struct engine_node *node, void *data OVS_UNUSED)
{
struct mac_cache_data *cache_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ovsdb_idl_index *sbrec_mb_by_dp =
engine_ovsdb_node_get_index(
engine_get_input("SB_mac_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_fdb_by_dp_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_fdb", node),
"dp_key");
/* There are no tracked data. Fall back to full recompute. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
size_t previous_mb_size = hmap_count(&cache_data->mac_bindings);
size_t previous_fdb_size = hmap_count(&cache_data->fdbs);
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, &rt_data->tracked_dp_bindings) {
if (tdp->tracked_type == TRACKED_RESOURCE_UPDATED) {
continue;
}
mac_cache_threshold_replace(cache_data, tdp->dp,
&rt_data->local_datapaths);
}
HMAP_FOR_EACH (tdp, node, &rt_data->tracked_dp_bindings) {
mac_cache_mb_handle_for_datapath(cache_data, tdp->dp,
sbrec_mb_by_dp);
mac_cache_fdb_handle_for_datapath(cache_data, tdp->dp,
sbrec_fdb_by_dp_key);
}
if (hmap_count(&cache_data->mac_bindings) != previous_mb_size ||
hmap_count(&cache_data->fdbs) != previous_fdb_size) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
mac_cache_sb_datapath_binding_handler(struct engine_node *node, void *data)
{
struct mac_cache_data *cache_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
struct ovsdb_idl_index *sbrec_mb_by_dp =
engine_ovsdb_node_get_index(
engine_get_input("SB_mac_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_fdb_by_dp_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_fdb", node),
"dp_key");
size_t previous_mb_size = hmap_count(&cache_data->mac_bindings);
size_t previous_fdb_size = hmap_count(&cache_data->fdbs);
bool sync_needed = false;
const struct sbrec_datapath_binding *sbrec_dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (sbrec_dp, dp_table) {
if (!sbrec_datapath_binding_is_new(sbrec_dp) &&
sbrec_datapath_binding_is_updated(
sbrec_dp, SBREC_DATAPATH_BINDING_COL_TUNNEL_KEY)) {
sync_needed = true;
}
mac_cache_threshold_replace(cache_data, sbrec_dp,
&rt_data->local_datapaths);
}
if (sync_needed) {
mac_cache_thresholds_sync(cache_data, &rt_data->local_datapaths);
}
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (sbrec_dp, dp_table) {
mac_cache_mb_handle_for_datapath(cache_data, sbrec_dp,
sbrec_mb_by_dp);
mac_cache_fdb_handle_for_datapath(cache_data, sbrec_dp,
sbrec_fdb_by_dp_key);
}
if (hmap_count(&cache_data->mac_bindings) != previous_mb_size ||
hmap_count(&cache_data->fdbs) != previous_fdb_size) {
return EN_HANDLED_UPDATED;
}
return EN_HANDLED_UNCHANGED;
}
static void
en_mac_cache_cleanup(void *data)
{
struct mac_cache_data *cache_data = data;
mac_cache_thresholds_clear(cache_data);
hmap_destroy(&cache_data->thresholds);
mac_bindings_clear(&cache_data->mac_bindings);
hmap_destroy(&cache_data->mac_bindings);
fdbs_clear(&cache_data->fdbs);
hmap_destroy(&cache_data->fdbs);
}
struct ed_type_bfd_chassis {
struct sset bfd_chassis;
};
static void *
en_bfd_chassis_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_bfd_chassis *data = xzalloc(sizeof *data);
sset_init(&data->bfd_chassis);
return data;
}
static enum engine_node_state
en_bfd_chassis_run(struct engine_node *node, void *data OVS_UNUSED)
{
struct ed_type_bfd_chassis *bfd_chassis = data;
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct sbrec_ha_chassis_group_table *ha_chassis_grp_table =
EN_OVSDB_GET(engine_get_input("SB_ha_chassis_group", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
sset_clear(&bfd_chassis->bfd_chassis);
bfd_calculate_chassis(chassis, ha_chassis_grp_table,
&bfd_chassis->bfd_chassis);
return EN_UPDATED;
}
static void
en_bfd_chassis_cleanup(void *data OVS_UNUSED){
struct ed_type_bfd_chassis *bfd_chassis = data;
sset_destroy(&bfd_chassis->bfd_chassis);
}
static void *
en_dns_cache_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
ovn_dns_cache_init();
return NULL;
}
static enum engine_node_state
en_dns_cache_run(struct engine_node *node, void *data OVS_UNUSED)
{
const struct sbrec_dns_table *dns_table =
EN_OVSDB_GET(engine_get_input("SB_dns", node));
ovn_dns_sync_cache(dns_table);
return EN_UPDATED;
}
static enum engine_input_handler_result
dns_cache_sb_dns_handler(struct engine_node *node, void *data OVS_UNUSED)
{
const struct sbrec_dns_table *dns_table =
EN_OVSDB_GET(engine_get_input("SB_dns", node));
ovn_dns_update_cache(dns_table);
return EN_HANDLED_UPDATED;
}
static void
en_dns_cache_cleanup(void *data OVS_UNUSED)
{
ovn_dns_cache_destroy();
}
/* Engine node which is used to handle the Non VIF data like
* - OVS patch ports
* - Tunnel ports and the related chassis information.
*/
struct ed_type_non_vif_data {
struct simap patch_ofports; /* simap of patch ovs ports. */
struct hmap chassis_tunnels; /* hmap of 'struct chassis_tunnel' from the
* tunnel OVS ports. */
struct flow_based_tunnel flow_tunnels[TUNNEL_TYPE_MAX];
/* Array of flow-based tunnels indexed by
* tunnel type. */
bool use_flow_based_tunnels; /* Enable flow-based tunnels. */
};
static void *
en_non_vif_data_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_non_vif_data *data = xzalloc(sizeof *data);
simap_init(&data->patch_ofports);
hmap_init(&data->chassis_tunnels);
flow_based_tunnels_init(data->flow_tunnels);
data->use_flow_based_tunnels = false;
return data;
}
static void
en_non_vif_data_cleanup(void *data OVS_UNUSED)
{
struct ed_type_non_vif_data *ed_non_vif_data = data;
simap_destroy(&ed_non_vif_data->patch_ofports);
chassis_tunnels_destroy(&ed_non_vif_data->chassis_tunnels);
flow_based_tunnels_destroy(ed_non_vif_data->flow_tunnels);
}
static enum engine_node_state
en_non_vif_data_run(struct engine_node *node, void *data)
{
struct ed_type_non_vif_data *ed_non_vif_data = data;
simap_destroy(&ed_non_vif_data->patch_ofports);
chassis_tunnels_destroy(&ed_non_vif_data->chassis_tunnels);
flow_based_tunnels_destroy(ed_non_vif_data->flow_tunnels);
simap_init(&ed_non_vif_data->patch_ofports);
hmap_init(&ed_non_vif_data->chassis_tunnels);
flow_based_tunnels_init(ed_non_vif_data->flow_tunnels);
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(br_int && chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
ed_non_vif_data->use_flow_based_tunnels =
is_flow_based_tunnels_enabled(ovs_table, chassis);
local_nonvif_data_run(br_int, chassis,
&ed_non_vif_data->patch_ofports,
&ed_non_vif_data->chassis_tunnels,
ed_non_vif_data->flow_tunnels);
return EN_UPDATED;
}
static enum engine_input_handler_result
non_vif_data_ovs_iface_handler(struct engine_node *node, void *data OVS_UNUSED)
{
const struct ovsrec_interface_table *iface_table =
EN_OVSDB_GET(engine_get_input("OVS_interface", node));
if (local_nonvif_data_handle_ovs_iface_changes(iface_table)) {
return EN_HANDLED_UNCHANGED;
} else {
return EN_UNHANDLED;
}
}
struct ed_type_northd_options {
bool explicit_arp_ns_output;
bool always_tunnel; /* Indicates if the traffic to the
* logical port of a bridged logical
* switch (i.e with localnet port) should
* be tunnelled or sent via the localnet
* port. Default value is 'false'. */
bool register_consolidation;
bool enable_ch_nb_cfg_update;
};
static void *
en_northd_options_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_northd_options *n_opts = xzalloc(sizeof *n_opts);
return n_opts;
}
static void
en_northd_options_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_northd_options_run(struct engine_node *node, void *data)
{
struct ed_type_northd_options *n_opts = data;
const struct sbrec_sb_global_table *sb_global_table =
EN_OVSDB_GET(engine_get_input("SB_sb_global", node));
const struct sbrec_sb_global *sb_global =
sbrec_sb_global_table_first(sb_global_table);
n_opts->explicit_arp_ns_output =
sb_global
? smap_get_bool(&sb_global->options, "arp_ns_explicit_output",
false)
: false;
n_opts->always_tunnel =
sb_global
? smap_get_bool(&sb_global->options, "always_tunnel",
false)
: false;
n_opts->register_consolidation =
sb_global
? smap_get_bool(&sb_global->options, "register_consolidation",
false)
: false;
n_opts->enable_ch_nb_cfg_update =
sb_global
? smap_get_bool(&sb_global->options, "enable_chassis_nb_cfg_update",
true)
: true;
return EN_UPDATED;
}
static enum engine_input_handler_result
en_northd_options_sb_sb_global_handler(struct engine_node *node, void *data)
{
struct ed_type_northd_options *n_opts = data;
const struct sbrec_sb_global_table *sb_global_table =
EN_OVSDB_GET(engine_get_input("SB_sb_global", node));
const struct sbrec_sb_global *sb_global =
sbrec_sb_global_table_first(sb_global_table);
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
bool explicit_arp_ns_output =
sb_global
? smap_get_bool(&sb_global->options, "arp_ns_explicit_output",
false)
: false;
if (explicit_arp_ns_output != n_opts->explicit_arp_ns_output) {
n_opts->explicit_arp_ns_output = explicit_arp_ns_output;
result = EN_HANDLED_UPDATED;
}
bool always_tunnel =
sb_global
? smap_get_bool(&sb_global->options, "always_tunnel",
false)
: false;
if (always_tunnel != n_opts->always_tunnel) {
n_opts->always_tunnel = always_tunnel;
result = EN_HANDLED_UPDATED;
}
bool register_consolidation =
sb_global
? smap_get_bool(&sb_global->options, "register_consolidation",
false)
: false;
if (register_consolidation != n_opts->register_consolidation) {
n_opts->register_consolidation = register_consolidation;
result = EN_HANDLED_UPDATED;
}
bool enable_ch_nb_cfg_update =
sb_global
? smap_get_bool(&sb_global->options, "enable_chassis_nb_cfg_update",
true)
: true;
if (enable_ch_nb_cfg_update != n_opts->enable_ch_nb_cfg_update) {
n_opts->enable_ch_nb_cfg_update = enable_ch_nb_cfg_update;
result = EN_HANDLED_UPDATED;
}
return result;
}
struct ed_type_dhcp_options {
struct hmap v4_opts;
struct hmap v6_opts;
};
static void *
en_dhcp_options_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_dhcp_options *dhcp_opts = xzalloc(sizeof *dhcp_opts);
hmap_init(&dhcp_opts->v4_opts);
hmap_init(&dhcp_opts->v6_opts);
return dhcp_opts;
}
static void
en_dhcp_options_cleanup(void *data)
{
struct ed_type_dhcp_options *dhcp_opts = data;
dhcp_opts_destroy(&dhcp_opts->v4_opts);
dhcp_opts_destroy(&dhcp_opts->v6_opts);
}
static enum engine_node_state
en_dhcp_options_run(struct engine_node *node, void *data)
{
struct ed_type_dhcp_options *dhcp_opts = data;
const struct sbrec_dhcp_options_table *dhcp_table =
EN_OVSDB_GET(engine_get_input("SB_dhcp_options", node));
const struct sbrec_dhcpv6_options_table *dhcpv6_table =
EN_OVSDB_GET(engine_get_input("SB_dhcpv6_options", node));
dhcp_opts_clear(&dhcp_opts->v4_opts);
dhcp_opts_clear(&dhcp_opts->v6_opts);
const struct sbrec_dhcp_options *dhcp_opt_row;
SBREC_DHCP_OPTIONS_TABLE_FOR_EACH (dhcp_opt_row, dhcp_table) {
dhcp_opt_add(&dhcp_opts->v4_opts, dhcp_opt_row->name,
dhcp_opt_row->code, dhcp_opt_row->type);
}
const struct sbrec_dhcpv6_options *dhcpv6_opt_row;
SBREC_DHCPV6_OPTIONS_TABLE_FOR_EACH (dhcpv6_opt_row, dhcpv6_table) {
dhcp_opt_add(&dhcp_opts->v6_opts, dhcpv6_opt_row->name,
dhcpv6_opt_row->code, dhcpv6_opt_row->type);
}
return EN_UPDATED;
}
struct lflow_output_persistent_data {
struct lflow_cache *lflow_cache;
};
struct ed_type_lflow_output {
/* Logical flow table */
struct ovn_desired_flow_table flow_table;
/* group ids for load balancing */
struct ovn_extend_table group_table;
/* meter ids for QoS */
struct ovn_extend_table meter_table;
/* lflow <-> resource cross reference */
struct objdep_mgr lflow_deps_mgr;;
/* conjunciton ID usage information of lflows */
struct conj_ids conj_ids;
/* objects (lflows) processed in the current engine execution.
* Cleared by en_lflow_output_clear_tracked_data before each engine
* execution. */
struct uuidset objs_processed;
/* Data which is persistent and not cleared during
* full recompute. */
struct lflow_output_persistent_data pd;
/* Fixed neighbor discovery supported options. */
struct hmap nd_ra_opts;
/* Fixed controller_event supported options. */
struct controller_event_options controller_event_opts;
/* Configured Flow Sample Collector Sets. */
struct flow_collector_ids collector_ids;
};
static void
init_lflow_ctx(struct engine_node *node,
struct ed_type_lflow_output *fo,
struct lflow_ctx_in *l_ctx_in,
struct lflow_ctx_out *l_ctx_out)
{
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ovsdb_idl_index *sbrec_port_binding_by_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"key");
struct ovsdb_idl_index *sbrec_logical_flow_by_dp =
engine_ovsdb_node_get_index(
engine_get_input("SB_logical_flow", node),
"logical_datapath");
struct ovsdb_idl_index *sbrec_logical_flow_by_dp_group =
engine_ovsdb_node_get_index(
engine_get_input("SB_logical_flow", node),
"logical_dp_group");
struct ovsdb_idl_index *sbrec_mc_group_by_name_dp =
engine_ovsdb_node_get_index(
engine_get_input("SB_multicast_group", node),
"name_datapath");
struct ovsdb_idl_index *sbrec_fdb_by_dp_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_fdb", node),
"dp_key");
struct ovsdb_idl_index *sbrec_mac_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_mac_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_static_mac_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_static_mac_binding", node),
"datapath");
const struct sbrec_port_binding_table *port_binding_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
const struct sbrec_mac_binding_table *mac_binding_table =
EN_OVSDB_GET(engine_get_input("SB_mac_binding", node));
const struct sbrec_logical_flow_table *logical_flow_table =
EN_OVSDB_GET(engine_get_input("SB_logical_flow", node));
const struct sbrec_logical_dp_group_table *logical_dp_group_table =
EN_OVSDB_GET(engine_get_input("SB_logical_dp_group", node));
const struct sbrec_multicast_group_table *multicast_group_table =
EN_OVSDB_GET(engine_get_input("SB_multicast_group", node));
const struct sbrec_fdb_table *fdb_table =
EN_OVSDB_GET(engine_get_input("SB_fdb", node));
const struct sbrec_static_mac_binding_table *smb_table =
EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node));
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct sbrec_chassis *chassis = NULL;
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
if (chassis_id) {
chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
}
ovs_assert(chassis);
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct ed_type_addr_sets *as_data =
engine_get_input_data("addr_sets", node);
struct shash *addr_sets = &as_data->addr_sets;
struct ed_type_port_groups *pg_data =
engine_get_input_data("port_groups", node);
struct shash *port_groups = &pg_data->port_groups_cs_local;
struct ed_type_northd_options *n_opts =
engine_get_input_data("northd_options", node);
struct ed_type_dhcp_options *dhcp_opts =
engine_get_input_data("dhcp_options", node);
struct ed_type_template_vars *template_vars =
engine_get_input_data("template_vars", node);
struct ed_type_lb_data *lb_data =
engine_get_input_data("lb_data", node);
l_ctx_in->sbrec_multicast_group_by_name_datapath =
sbrec_mc_group_by_name_dp;
l_ctx_in->sbrec_logical_flow_by_logical_datapath =
sbrec_logical_flow_by_dp;
l_ctx_in->sbrec_logical_flow_by_logical_dp_group =
sbrec_logical_flow_by_dp_group;
l_ctx_in->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
l_ctx_in->sbrec_port_binding_by_key = sbrec_port_binding_by_key;
l_ctx_in->sbrec_fdb_by_dp_key = sbrec_fdb_by_dp_key;
l_ctx_in->sbrec_mac_binding_by_datapath = sbrec_mac_binding_by_datapath;
l_ctx_in->sbrec_static_mac_binding_by_datapath =
sbrec_static_mac_binding_by_datapath;
l_ctx_in->port_binding_table = port_binding_table;
l_ctx_in->mac_binding_table = mac_binding_table;
l_ctx_in->logical_flow_table = logical_flow_table;
l_ctx_in->logical_dp_group_table = logical_dp_group_table;
l_ctx_in->mc_group_table = multicast_group_table;
l_ctx_in->fdb_table = fdb_table,
l_ctx_in->chassis = chassis;
l_ctx_in->static_mac_binding_table = smb_table;
l_ctx_in->local_datapaths = &rt_data->local_datapaths;
l_ctx_in->addr_sets = addr_sets;
l_ctx_in->port_groups = port_groups;
l_ctx_in->active_tunnels = &rt_data->active_tunnels;
l_ctx_in->related_lport_ids = &rt_data->related_lports.lport_ids;
l_ctx_in->binding_lports = &rt_data->lbinding_data.lports;
l_ctx_in->localnet_learn_fdb = rt_data->localnet_learn_fdb;
l_ctx_in->localnet_learn_fdb_changed = rt_data->localnet_learn_fdb_changed;
l_ctx_in->chassis_tunnels = &non_vif_data->chassis_tunnels;
l_ctx_in->explicit_arp_ns_output = n_opts->explicit_arp_ns_output;
l_ctx_in->register_consolidation = n_opts->register_consolidation;
l_ctx_in->nd_ra_opts = &fo->nd_ra_opts;
l_ctx_in->dhcp_opts = &dhcp_opts->v4_opts;
l_ctx_in->dhcpv6_opts = &dhcp_opts->v6_opts;
l_ctx_in->controller_event_opts = &fo->controller_event_opts;
l_ctx_in->template_vars = &template_vars->local_templates;
l_ctx_in->collector_ids = &fo->collector_ids;
l_ctx_in->local_lbs = &lb_data->local_lbs;
l_ctx_in->lbinding_lports = &rt_data->lbinding_data.bindings;
l_ctx_out->flow_table = &fo->flow_table;
l_ctx_out->group_table = &fo->group_table;
l_ctx_out->meter_table = &fo->meter_table;
l_ctx_out->lflow_deps_mgr = &fo->lflow_deps_mgr;
l_ctx_out->conj_ids = &fo->conj_ids;
l_ctx_out->objs_processed = &fo->objs_processed;
l_ctx_out->lflow_cache = fo->pd.lflow_cache;
}
static void *
en_lflow_output_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_lflow_output *data = xzalloc(sizeof *data);
ovn_desired_flow_table_init(&data->flow_table);
ovn_extend_table_init(&data->group_table, "group-table", 0);
ovn_extend_table_init(&data->meter_table, "meter-table", 0);
objdep_mgr_init(&data->lflow_deps_mgr);
lflow_conj_ids_init(&data->conj_ids);
uuidset_init(&data->objs_processed);
nd_ra_opts_init(&data->nd_ra_opts);
controller_event_opts_init(&data->controller_event_opts);
flow_collector_ids_init(&data->collector_ids);
return data;
}
static void
en_lflow_output_clear_tracked_data(void *data)
{
struct ed_type_lflow_output *flow_output_data = data;
uuidset_clear(&flow_output_data->objs_processed);
}
static void
en_lflow_output_cleanup(void *data)
{
struct ed_type_lflow_output *flow_output_data = data;
ovn_desired_flow_table_destroy(&flow_output_data->flow_table);
ovn_extend_table_destroy(&flow_output_data->group_table);
ovn_extend_table_destroy(&flow_output_data->meter_table);
objdep_mgr_destroy(&flow_output_data->lflow_deps_mgr);
lflow_conj_ids_destroy(&flow_output_data->conj_ids);
uuidset_destroy(&flow_output_data->objs_processed);
lflow_cache_destroy(flow_output_data->pd.lflow_cache);
nd_ra_opts_destroy(&flow_output_data->nd_ra_opts);
controller_event_opts_destroy(&flow_output_data->controller_event_opts);
flow_collector_ids_destroy(&flow_output_data->collector_ids);
}
static enum engine_node_state
en_lflow_output_run(struct engine_node *node, void *data)
{
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct ovsrec_flow_sample_collector_set_table *flow_collector_table =
EN_OVSDB_GET(engine_get_input("OVS_flow_sample_collector_set", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis = NULL;
if (chassis_id) {
chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
}
ovs_assert(br_int && chassis);
const struct ovsrec_flow_sample_collector_set *set;
OVSREC_FLOW_SAMPLE_COLLECTOR_SET_TABLE_FOR_EACH (set,
flow_collector_table) {
if (set->bridge == br_int) {
struct ed_type_lflow_output *lfo = data;
flow_collector_ids_clear(&lfo->collector_ids);
flow_collector_ids_init_from_table(&lfo->collector_ids,
flow_collector_table);
}
}
struct ed_type_lflow_output *fo = data;
struct ovn_desired_flow_table *lflow_table = &fo->flow_table;
struct ovn_extend_table *group_table = &fo->group_table;
struct ovn_extend_table *meter_table = &fo->meter_table;
struct objdep_mgr *lflow_deps_mgr = &fo->lflow_deps_mgr;
static bool first_run = true;
if (first_run) {
first_run = false;
} else {
ovn_desired_flow_table_clear(lflow_table);
ovn_extend_table_clear(group_table, false /* desired */);
ovn_extend_table_clear(meter_table, false /* desired */);
objdep_mgr_clear(lflow_deps_mgr);
lflow_conj_ids_clear(&fo->conj_ids);
}
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
fo->pd.lflow_cache = ctrl_ctx->lflow_cache;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
lflow_run(&l_ctx_in, &l_ctx_out);
return EN_UPDATED;
}
static enum engine_input_handler_result
lflow_output_sb_logical_flow_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *fo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
if (lflow_handle_changed_flows(&l_ctx_in, &l_ctx_out)) {
return EN_HANDLED_UPDATED;
}
return EN_UNHANDLED;
}
static enum engine_input_handler_result
lflow_output_flow_sample_collector_set_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct ovsrec_flow_sample_collector_set_table *flow_collector_table =
EN_OVSDB_GET(engine_get_input("OVS_flow_sample_collector_set", node));
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
if (!cfg) {
return EN_HANDLED_UNCHANGED;
}
const struct ovsrec_bridge *br_int;
br_int = get_bridge(bridge_table, br_int_name(ovs_table));
if (!br_int) {
return EN_HANDLED_UNCHANGED;
}
const struct ovsrec_flow_sample_collector_set *set;
OVSREC_FLOW_SAMPLE_COLLECTOR_SET_TABLE_FOR_EACH_TRACKED (set,
flow_collector_table) {
if (set->bridge == br_int) {
struct ed_type_lflow_output *lfo = data;
flow_collector_ids_clear(&lfo->collector_ids);
flow_collector_ids_init_from_table(&lfo->collector_ids,
flow_collector_table);
return EN_UNHANDLED;
}
}
return EN_HANDLED_UPDATED;
}
static void
pflow_output_get_debug(struct engine_node *node, struct physical_debug *debug)
{
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct sbrec_sb_global_table *sb_global_table =
EN_OVSDB_GET(engine_get_input("SB_sb_global", node));
const struct sbrec_sb_global *sb_global =
sbrec_sb_global_table_first(sb_global_table);
if (!debug) {
return;
}
debug->collector_set_id = 0;
debug->obs_domain_id = 0;
const struct ovsrec_open_vswitch *ovs_cfg =
ovsrec_open_vswitch_table_first(ovs_table);
if (!ovs_cfg) {
return;
}
const struct ovsrec_bridge *br_int;
br_int = get_bridge(bridge_table, br_int_name(ovs_table));
if (!br_int) {
return;
}
const uint32_t debug_collector_set =
smap_get_uint(&sb_global->options, "debug_drop_collector_set", 0);
if (!debug_collector_set) {
return;
}
struct ovsdb_idl_index *ovsrec_flow_sample_collector_set_by_id =
engine_ovsdb_node_get_index(
engine_get_input("OVS_flow_sample_collector_set", node), "id");
struct ovsrec_flow_sample_collector_set *s =
ovsrec_flow_sample_collector_set_index_init_row(
ovsrec_flow_sample_collector_set_by_id);
ovsrec_flow_sample_collector_set_index_set_id(s, debug_collector_set);
ovsrec_flow_sample_collector_set_index_set_bridge(s, br_int);
if (!ovsrec_flow_sample_collector_set_index_find(
ovsrec_flow_sample_collector_set_by_id, s)) {
ovsrec_flow_sample_collector_set_index_destroy_row(s);
return;
}
ovsrec_flow_sample_collector_set_index_destroy_row(s);
debug->collector_set_id = debug_collector_set;
debug->obs_domain_id = smap_get_uint(&sb_global->options,
"debug_drop_domain_id", 0);
}
static enum engine_input_handler_result
lflow_output_sb_mac_binding_handler(struct engine_node *node, void *data)
{
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
const struct sbrec_mac_binding_table *mac_binding_table =
EN_OVSDB_GET(engine_get_input("SB_mac_binding", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct hmap *local_datapaths = &rt_data->local_datapaths;
struct ed_type_lflow_output *lfo = data;
lflow_handle_changed_mac_bindings(sbrec_port_binding_by_name,
mac_binding_table, local_datapaths, &lfo->flow_table);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
lflow_output_sb_static_mac_binding_handler(struct engine_node *node,
void *data)
{
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
const struct sbrec_static_mac_binding_table *smb_table =
EN_OVSDB_GET(engine_get_input("SB_static_mac_binding", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct hmap *local_datapaths = &rt_data->local_datapaths;
struct ed_type_lflow_output *lfo = data;
lflow_handle_changed_static_mac_bindings(sbrec_port_binding_by_name,
smb_table, local_datapaths, &lfo->flow_table);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
lflow_output_sb_multicast_group_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *lfo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, lfo, &l_ctx_in, &l_ctx_out);
if (!lflow_handle_changed_mc_groups(&l_ctx_in, &l_ctx_out)) {
return EN_UNHANDLED;
}
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
lflow_output_sb_port_binding_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *lfo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, lfo, &l_ctx_in, &l_ctx_out);
if (!lflow_handle_changed_port_bindings(&l_ctx_in, &l_ctx_out)) {
return EN_UNHANDLED;
}
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
lflow_output_addr_sets_handler(struct engine_node *node, void *data)
{
struct ed_type_addr_sets *as_data =
engine_get_input_data("addr_sets", node);
struct ed_type_lflow_output *fo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
bool changed;
const char *ref_name;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
if (!as_data->change_tracked) {
return EN_UNHANDLED;
}
SSET_FOR_EACH (ref_name, &as_data->deleted) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_ADDRSET, ref_name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &as_data->updated) {
struct addr_set_diff *as_diff = shash_node->data;
if (!lflow_handle_addr_set_update(shash_node->name, as_diff, &l_ctx_in,
&l_ctx_out, &changed)) {
VLOG_DBG("Can't incrementally handle the change of address set %s."
" Reprocess related lflows.", shash_node->name);
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_ADDRSET,
shash_node->name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (ref_name, &as_data->new) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_ADDRSET, ref_name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
return result;
}
static enum engine_input_handler_result
lflow_output_port_groups_handler(struct engine_node *node, void *data)
{
struct ed_type_port_groups *pg_data =
engine_get_input_data("port_groups", node);
struct ed_type_lflow_output *fo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
bool changed;
const char *ref_name;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
if (!pg_data->change_tracked) {
return EN_UNHANDLED;
}
SSET_FOR_EACH (ref_name, &pg_data->deleted) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_PORTGROUP, ref_name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (ref_name, &pg_data->updated) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_PORTGROUP, ref_name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (ref_name, &pg_data->new) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_PORTGROUP, ref_name,
lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
return result;
}
static enum engine_input_handler_result
lflow_output_template_vars_handler(struct engine_node *node, void *data)
{
struct ed_type_template_vars *tv_data =
engine_get_input_data("template_vars", node);
struct ed_type_lflow_output *fo = data;
struct lflow_ctx_out l_ctx_out;
struct lflow_ctx_in l_ctx_in;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
const char *res_name;
bool changed;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
if (!tv_data->change_tracked) {
return EN_UNHANDLED;
}
SSET_FOR_EACH (res_name, &tv_data->deleted) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (res_name, &tv_data->updated) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
SSET_FOR_EACH (res_name, &tv_data->new) {
if (!objdep_mgr_handle_change(l_ctx_out.lflow_deps_mgr,
OBJDEP_TYPE_TEMPLATE,
res_name, lflow_handle_changed_ref,
l_ctx_out.objs_processed,
&l_ctx_in, &l_ctx_out, &changed)) {
return EN_UNHANDLED;
}
if (changed) {
result = EN_HANDLED_UPDATED;
}
}
return result;
}
static enum engine_input_handler_result
lflow_output_runtime_data_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
/* There is no tracked data. Fall back to full recompute of
* flow_output. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct hmap *tracked_dp_bindings = &rt_data->tracked_dp_bindings;
if (hmap_is_empty(tracked_dp_bindings)) {
return rt_data->local_lports_changed
? EN_HANDLED_UPDATED
: EN_HANDLED_UNCHANGED;
}
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
struct ed_type_lflow_output *fo = data;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, tracked_dp_bindings) {
if (tdp->tracked_type == TRACKED_RESOURCE_NEW) {
if (!lflow_add_flows_for_datapath(tdp->dp, &l_ctx_in,
&l_ctx_out)) {
return EN_UNHANDLED;
}
}
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &tdp->lports) {
struct tracked_lport *lport = shash_node->data;
if (!lflow_handle_flows_for_lport(
lport->pb, &l_ctx_in, &l_ctx_out,
lport->tracked_type == TRACKED_RESOURCE_REMOVED)) {
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
lflow_output_lb_data_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *fo = data;
struct ed_type_lb_data *lb_data = engine_get_input_data("lb_data", node);
if (!lb_data->change_tracked) {
return EN_UNHANDLED;
}
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
bool handled = lflow_handle_changed_lbs(&l_ctx_in, &l_ctx_out,
&lb_data->deleted,
&lb_data->updated,
&lb_data->new);
return handled ? EN_HANDLED_UPDATED : EN_UNHANDLED;
}
static enum engine_input_handler_result
lflow_output_sb_fdb_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *fo = data;
struct lflow_ctx_in l_ctx_in;
struct lflow_ctx_out l_ctx_out;
init_lflow_ctx(node, fo, &l_ctx_in, &l_ctx_out);
bool handled = lflow_handle_changed_fdbs(&l_ctx_in, &l_ctx_out);
return handled ? EN_HANDLED_UPDATED : EN_UNHANDLED;
}
static enum engine_input_handler_result
lflow_output_sb_meter_handler(struct engine_node *node, void *data)
{
struct ed_type_lflow_output *fo = data;
const struct sbrec_meter_table *meter_table =
EN_OVSDB_GET(engine_get_input("SB_meter", node));
const struct sbrec_meter *iter;
SBREC_METER_TABLE_FOR_EACH_TRACKED (iter, meter_table) {
if (ovn_extend_table_desired_lookup_by_name(&fo->meter_table,
iter->name)) {
return EN_HANDLED_UPDATED;
}
}
return EN_HANDLED_UNCHANGED;
}
struct ed_type_pflow_output {
/* Desired physical flows. */
struct ovn_desired_flow_table flow_table;
/* Drop debugging options. */
struct physical_debug debug;
};
static void
parse_encap_ips(const struct ovsrec_open_vswitch_table *ovs_table,
size_t *n_encap_ips, const char * **encap_ips)
{
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const char *encap_ips_str =
get_chassis_external_id_value(&cfg->external_ids, chassis_id,
"ovn-encap-ip", NULL);
struct sset encap_ip_set;
sset_from_delimited_string(&encap_ip_set, encap_ips_str, ",");
/* Sort the ips so that their index is deterministic. */
*encap_ips = sset_sort(&encap_ip_set);
/* Copy the strings so that we can destroy the sset. */
for (size_t i = 0; (*encap_ips)[i]; i++) {
(*encap_ips)[i] = xstrdup((*encap_ips)[i]);
}
*n_encap_ips = sset_count(&encap_ip_set);
sset_destroy(&encap_ip_set);
/* Move the default encap IP, if configured, to the first so that it will
* have index 0, because we use index as encap-id and we need 0 to be the
* default encap-id. */
const char *encap_ip_default =
get_chassis_external_id_value(&cfg->external_ids, chassis_id,
"ovn-encap-ip-default", NULL);
if (encap_ip_default) {
for (size_t i = 0; i < *n_encap_ips; i++) {
if (!strcmp(encap_ip_default, (*encap_ips)[i])) {
const char *tmp = (*encap_ips)[0];
(*encap_ips)[0] = (*encap_ips)[i];
(*encap_ips)[i] = tmp;
break;
}
}
}
}
struct ed_type_evpn_vtep_binding {
/* Contains 'struct evpn_binding'. */
struct hmap bindings;
/* Contains pointers to 'struct evpn_binding'. */
struct hmapx updated_bindings;
/* Contains 'flow_uuid' from removed 'struct evpn_binding'. */
struct uuidset removed_bindings;
/* Contains 'struct evpn_datapath'. */
struct hmap datapaths;
/* Contains 'struct evpn_multicast_group'. */
struct hmap multicast_groups;
/* Contains pointers to 'struct evpn_multicast_group'. */
struct hmapx updated_multicast_groups;
/* Contains 'flow_uuid' from removed 'struct evpn_multicast_group'. */
struct uuidset removed_multicast_groups;
/* Contains 'struct tnlid_node". */
struct hmap tunnel_keys;
};
struct ed_type_evpn_fdb {
/* Contains 'struct evpn_fdb'. */
struct hmap fdbs;
/* Contains pointers to 'struct evpn_fdb'. */
struct hmapx updated_fdbs;
/* Contains 'flow_uuid' from removed 'struct evpn_fdb'. */
struct uuidset removed_fdbs;
};
struct ed_type_evpn_arp {
/* Contains 'struct evpn_arp'. */
struct hmap arps;
/* Contains pointers to 'struct evpn_arp'. */
struct hmapx updated_arps;
/* Contains 'flow_uuid' from removed 'struct evpn_arps'. */
struct uuidset removed_arps;
};
static void init_physical_ctx(struct engine_node *node,
struct ed_type_runtime_data *rt_data,
struct ed_type_non_vif_data *non_vif_data,
struct physical_ctx *p_ctx)
{
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ovsdb_idl_index *sbrec_port_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"datapath");
const struct sbrec_multicast_group_table *multicast_group_table =
EN_OVSDB_GET(engine_get_input("SB_multicast_group", node));
const struct sbrec_port_binding_table *port_binding_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
const struct sbrec_chassis_table *chassis_table =
EN_OVSDB_GET(engine_get_input("SB_chassis", node));
const struct ed_type_mff_ovn_geneve *ed_mff_ovn_geneve =
engine_get_input_data("mff_ovn_geneve", node);
const struct ovsrec_interface_table *ovs_interface_table =
EN_OVSDB_GET(engine_get_input("if_status_mgr", node));
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct sbrec_chassis *chassis = NULL;
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
if (chassis_id) {
chassis = chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
}
ovs_assert(br_int && chassis);
struct ed_type_ct_zones *ct_zones_data =
engine_get_input_data("ct_zones", node);
struct shash *ct_zones = &ct_zones_data->ctx.current;
struct ed_type_northd_options *n_opts =
engine_get_input_data("northd_options", node);
struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
struct ed_type_evpn_fdb *efdb_data =
engine_get_input_data("evpn_fdb", node);
struct ed_type_evpn_arp *earp_data =
engine_get_input_data("evpn_arp", node);
parse_encap_ips(ovs_table, &p_ctx->n_encap_ips, &p_ctx->encap_ips);
p_ctx->sbrec_port_binding_by_name = sbrec_port_binding_by_name;
p_ctx->sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath;
p_ctx->sbrec_chassis_by_name = sbrec_chassis_by_name;
p_ctx->port_binding_table = port_binding_table;
p_ctx->ovs_interface_table = ovs_interface_table;
p_ctx->mc_group_table = multicast_group_table;
p_ctx->br_int = br_int;
p_ctx->chassis_table = chassis_table;
p_ctx->chassis = chassis;
p_ctx->active_tunnels = &rt_data->active_tunnels;
p_ctx->local_datapaths = &rt_data->local_datapaths;
p_ctx->ct_zones = ct_zones;
p_ctx->mff_ovn_geneve = ed_mff_ovn_geneve->mff_ovn_geneve;
p_ctx->local_bindings = &rt_data->lbinding_data.bindings;
p_ctx->patch_ofports = &non_vif_data->patch_ofports;
p_ctx->chassis_tunnels = &non_vif_data->chassis_tunnels;
p_ctx->flow_tunnels = non_vif_data->flow_tunnels;
p_ctx->use_flow_based_tunnels = non_vif_data->use_flow_based_tunnels;
p_ctx->always_tunnel = n_opts->always_tunnel;
p_ctx->evpn_bindings = &eb_data->bindings;
p_ctx->evpn_multicast_groups = &eb_data->multicast_groups;
p_ctx->evpn_fdbs = &efdb_data->fdbs;
p_ctx->evpn_arps = &earp_data->arps;
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
p_ctx->if_mgr = ctrl_ctx->if_mgr;
pflow_output_get_debug(node, &p_ctx->debug);
sset_init(&p_ctx->reprocessed_pbs);
}
static void
destroy_physical_ctx(struct physical_ctx *p_ctx)
{
for (size_t i = 0; i < p_ctx->n_encap_ips; i++) {
free((char *)(p_ctx->encap_ips[i]));
}
free(p_ctx->encap_ips);
sset_destroy(&p_ctx->reprocessed_pbs);
}
static void *
en_pflow_output_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_pflow_output *data = xzalloc(sizeof *data);
ovn_desired_flow_table_init(&data->flow_table);
return data;
}
static void
en_pflow_output_cleanup(void *data OVS_UNUSED)
{
struct ed_type_pflow_output *pfo = data;
ovn_desired_flow_table_destroy(&pfo->flow_table);
}
static enum engine_node_state
en_pflow_output_run(struct engine_node *node, void *data)
{
struct ed_type_pflow_output *pfo = data;
struct ovn_desired_flow_table *pflow_table = &pfo->flow_table;
static bool first_run = true;
if (first_run) {
first_run = false;
} else {
ovn_desired_flow_table_clear(pflow_table);
}
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
physical_run(&p_ctx, pflow_table);
destroy_physical_ctx(&p_ctx);
return EN_UPDATED;
}
static enum engine_input_handler_result
pflow_output_if_status_mgr_handler(struct engine_node *node,
void *data)
{
struct ed_type_pflow_output *pfo = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct ed_type_if_status_mgr *if_mgr_data =
engine_get_input_data("if_status_mgr", node);
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
const struct ovsrec_interface *iface;
enum engine_input_handler_result result = EN_HANDLED_UNCHANGED;
OVSREC_INTERFACE_TABLE_FOR_EACH_TRACKED (iface, if_mgr_data->iface_table) {
const char *iface_id = smap_get(&iface->external_ids, "iface-id");
if (!iface_id) {
continue;
}
const struct sbrec_port_binding *pb = lport_lookup_by_name(
p_ctx.sbrec_port_binding_by_name, iface_id);
if (!pb) {
continue;
}
if (pb->n_additional_chassis) {
/* Update flows for all ports in datapath. */
physical_multichassis_reprocess(pb, &p_ctx, &pfo->flow_table);
} else {
/* If any multichassis ports, update flows for the port. */
bool removed = sbrec_port_binding_is_deleted(pb);
if (!physical_handle_flows_for_lport(pb, removed, &p_ctx,
&pfo->flow_table)) {
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
}
result = EN_HANDLED_UPDATED;
}
destroy_physical_ctx(&p_ctx);
return result;
}
static enum engine_input_handler_result
pflow_output_sb_port_binding_handler(struct engine_node *node,
void *data)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct ed_type_pflow_output *pfo = data;
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
/* We handle port-binding changes for physical flow processing
* only. flow_output runtime data handler takes care of processing
* logical flows for any port binding changes.
*/
const struct sbrec_port_binding *pb;
SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, p_ctx.port_binding_table) {
/* Trigger a full recompute if type column is updated. */
if (sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_TYPE)) {
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
bool removed = sbrec_port_binding_is_deleted(pb);
if (!physical_handle_flows_for_lport(pb, removed, &p_ctx,
&pfo->flow_table)) {
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
}
destroy_physical_ctx(&p_ctx);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_sb_multicast_group_handler(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct ed_type_pflow_output *pfo = data;
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
physical_handle_mc_group_changes(&p_ctx, &pfo->flow_table);
destroy_physical_ctx(&p_ctx);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_runtime_data_handler(struct engine_node *node, void *data)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
/* There is no tracked data. Fall back to full recompute of
* pflow_output. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct hmap *tracked_dp_bindings = &rt_data->tracked_dp_bindings;
if (hmap_is_empty(tracked_dp_bindings)) {
return EN_HANDLED_UNCHANGED;
}
struct ed_type_pflow_output *pfo = data;
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, tracked_dp_bindings) {
if (tdp->tracked_type != TRACKED_RESOURCE_UPDATED) {
/* Fall back to full recompute when a local datapath
* is added or deleted. */
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &tdp->lports) {
struct tracked_lport *lport = shash_node->data;
bool removed =
lport->tracked_type == TRACKED_RESOURCE_REMOVED ? true: false;
if (!physical_handle_flows_for_lport(lport->pb, removed, &p_ctx,
&pfo->flow_table)) {
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
}
}
destroy_physical_ctx(&p_ctx);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_ct_zones_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
struct ed_type_ct_zones *ct_zones_data =
engine_get_input_data("ct_zones", node);
/* If ct_zones engine node was recomputed, then fall back to full
* recompute of pflow_output. Otherwise there is no need to do
* anything for the following reasons:
* - When an lport is claimed, ct zone handler for the
* runtime_data allocates the zone id for the lport (and it is
* saved in the br-int external_ids).
* - pflow_output handler for the runtime_data adds the physical
* flows for the claimed lport.
* */
return ct_zones_data->recomputed ? EN_UNHANDLED : EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
pflow_output_activated_ports_handler(struct engine_node *node, void *data)
{
struct ed_type_activated_ports *ap =
engine_get_input_data("activated_ports", node);
if (!ap->activated_ports) {
return EN_HANDLED_UNCHANGED;
}
struct ed_type_pflow_output *pfo = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct physical_ctx p_ctx;
init_physical_ctx(node, rt_data, non_vif_data, &p_ctx);
struct activated_port *pp;
LIST_FOR_EACH (pp, list, ap->activated_ports) {
struct ovsdb_idl_index *sbrec_datapath_binding_by_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_datapath_binding", node),
"key");
struct ovsdb_idl_index *sbrec_port_binding_by_key =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"key");
const struct sbrec_port_binding *pb = lport_lookup_by_key(
sbrec_datapath_binding_by_key, sbrec_port_binding_by_key,
pp->dp_key, pp->port_key);
if (pb) {
if (!physical_handle_flows_for_lport(pb, false, &p_ctx,
&pfo->flow_table)) {
destroy_physical_ctx(&p_ctx);
return EN_UNHANDLED;
}
tag_port_as_activated_in_engine(pp);
}
}
destroy_physical_ctx(&p_ctx);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_debug_handler(struct engine_node *node, void *data)
{
struct ed_type_pflow_output *pfo = data;
struct physical_debug debug;
pflow_output_get_debug(node, &debug);
if (pfo->debug.collector_set_id != debug.collector_set_id ||
pfo->debug.obs_domain_id != debug.obs_domain_id) {
pfo->debug = debug;
return EN_UNHANDLED;
}
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_evpn_binding_handler(struct engine_node *node, void *data)
{
struct ed_type_pflow_output *pfo = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_non_vif_data *non_vif_data =
engine_get_input_data("non_vif_data", node);
struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
struct physical_ctx ctx;
init_physical_ctx(node, rt_data, non_vif_data, &ctx);
physical_handle_evpn_binding_changes(&ctx, &pfo->flow_table,
&eb_data->updated_bindings,
&eb_data->updated_multicast_groups,
&eb_data->removed_bindings,
&eb_data->removed_multicast_groups);
destroy_physical_ctx(&ctx);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_fdb_handler(struct engine_node *node, void *data)
{
struct ed_type_pflow_output *pfo = data;
struct ed_type_evpn_fdb *ef_data =
engine_get_input_data("evpn_fdb", node);
physical_handle_evpn_fdb_changes(&pfo->flow_table, &ef_data->updated_fdbs,
&ef_data->removed_fdbs);
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
pflow_output_arp_handler(struct engine_node *node, void *data)
{
struct ed_type_pflow_output *pfo = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ed_type_evpn_arp *ea_data =
engine_get_input_data("evpn_arp", node);
physical_handle_evpn_arp_changes(&rt_data->local_datapaths,
&pfo->flow_table,
&ea_data->updated_arps,
&ea_data->removed_arps);
return EN_HANDLED_UPDATED;
}
static void *
en_controller_output_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
return NULL;
}
static void
en_controller_output_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_controller_output_run(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_UPDATED;
}
static enum engine_input_handler_result
controller_output_pflow_output_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_lflow_output_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_mac_cache_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_bfd_chassis_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_acl_id_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_route_exchange_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
static enum engine_input_handler_result
controller_output_garp_rarp_handler(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
return EN_HANDLED_UPDATED;
}
/* Handles sbrec_chassis changes.
* If a new chassis is added or removed return false, so that
* flows are recomputed. For any updates, there is no need for
* any flow computation. Encap changes will also result in
* sbrec_chassis changes, but we handle encap changes separately.
*/
static enum engine_input_handler_result
pflow_lflow_output_sb_chassis_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct sbrec_chassis_table *chassis_table =
EN_OVSDB_GET(engine_get_input("SB_chassis", node));
const struct sbrec_chassis *ch;
SBREC_CHASSIS_TABLE_FOR_EACH_TRACKED (ch, chassis_table) {
if (sbrec_chassis_is_deleted(ch) || sbrec_chassis_is_new(ch)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
struct ed_type_route {
/* Contains struct tracked_datapath entries for local datapaths subject to
* route exchange. */
struct hmap tracked_route_datapaths;
/* Contains the tracked_ports that in the last run were bound locally. */
struct sset tracked_ports_local;
/* Contains the tracked_ports that in the last run were not bound
* locally. */
struct sset tracked_ports_remote;
/* Contains all the currently configured dynamic-routing-port-name values
* on all datapaths.
*/
struct sset filtered_ports;
/* Contains struct advertise_datapath_entry */
struct hmap announce_routes;
struct ovsdb_idl *ovnsb_idl;
};
static enum engine_node_state
en_route_run(struct engine_node *node, void *data)
{
struct ed_type_route *re_data = data;
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_advertised_route_table *advertised_route_table =
EN_OVSDB_GET(engine_get_input("SB_advertised_route", node));
const struct ovsrec_open_vswitch *cfg
= ovsrec_open_vswitch_table_first(ovs_table);
const char *dynamic_routing_port_mapping =
smap_get(&cfg->external_ids, "dynamic-routing-port-mapping");
struct route_ctx_in r_ctx_in = {
.advertised_route_table = advertised_route_table,
.sbrec_port_binding_by_name = sbrec_port_binding_by_name,
.chassis = chassis,
.dynamic_routing_port_mapping = dynamic_routing_port_mapping,
.local_datapaths = &rt_data->local_datapaths,
.local_bindings = &rt_data->lbinding_data.bindings,
};
struct route_ctx_out r_ctx_out = {
.tracked_re_datapaths = &re_data->tracked_route_datapaths,
.tracked_ports_local = &re_data->tracked_ports_local,
.filtered_ports = &re_data->filtered_ports,
.tracked_ports_remote = &re_data->tracked_ports_remote,
.announce_routes = &re_data->announce_routes,
};
route_cleanup(&re_data->announce_routes);
tracked_datapaths_clear(r_ctx_out.tracked_re_datapaths);
sset_clear(r_ctx_out.tracked_ports_local);
sset_clear(r_ctx_out.tracked_ports_remote);
sset_clear(r_ctx_out.filtered_ports);
route_run(&r_ctx_in, &r_ctx_out);
return EN_UPDATED;
}
static void *
en_route_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg)
{
struct ed_type_route *data = xzalloc(sizeof *data);
hmap_init(&data->tracked_route_datapaths);
sset_init(&data->tracked_ports_local);
sset_init(&data->tracked_ports_remote);
sset_init(&data->filtered_ports);
hmap_init(&data->announce_routes);
data->ovnsb_idl = arg->sb_idl;
return data;
}
static void
en_route_cleanup(void *data)
{
struct ed_type_route *re_data = data;
tracked_datapaths_destroy(&re_data->tracked_route_datapaths);
sset_destroy(&re_data->tracked_ports_local);
sset_destroy(&re_data->tracked_ports_remote);
sset_destroy(&re_data->filtered_ports);
route_cleanup(&re_data->announce_routes);
hmap_destroy(&re_data->announce_routes);
}
static enum engine_input_handler_result
route_runtime_data_handler(struct engine_node *node, void *data)
{
struct ed_type_route *re_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
/* There are the following cases where we need to handle updates to
* runtime_data:
* 1. A datapath binding has changed that is already taking part in route
* exchange.
* 2. A route-exchange relevant port went form local to remote or the
* other way round.
* 3. A tracked_port went from local to remote or the other way round.
* */
struct tracked_datapath *t_dp;
HMAP_FOR_EACH (t_dp, node, &rt_data->tracked_dp_bindings) {
struct tracked_datapath *re_t_dp =
tracked_datapath_find(&re_data->tracked_route_datapaths, t_dp->dp);
if (re_t_dp) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &t_dp->lports) {
struct tracked_lport *lport = shash_node->data;
if (route_exchange_find_port(sbrec_port_binding_by_name, chassis,
lport->pb, NULL)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
/* When the port is removed we went from local to remote,
* otherwise it's from remote to local. */
struct sset *tracked_ports =
lport->tracked_type == TRACKED_RESOURCE_REMOVED
? &re_data->tracked_ports_local
: &re_data->tracked_ports_remote;
const char *name = lport->pb->logical_port;
if (sset_contains(tracked_ports, name)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
/* If this logical port name is used to filter on which router
* ports learning should happen then process the changes. */
if (sset_find(&re_data->filtered_ports, name)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
const char *dp_name = smap_get(&lport->pb->options,
"distributed-port");
if (dp_name && sset_contains(tracked_ports, dp_name)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
route_sb_port_binding_data_handler(struct engine_node *node, void *data)
{
struct ed_type_route *re_data = data;
const struct sbrec_port_binding_table *pb_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
/* There are the following cases where we need to handle updates to the
* port_binding table:
* 1. The port_binding is part of a router datapath that already takes
* part in route exchange.
* 2. The port_binding is now becoming part of route exchange.
*
* We do not need to handle port_bindings that are tracked_ports and switch
* between being local and remote. This is handled as part of the
* runtime_data handler. */
const struct sbrec_port_binding *sbrec_pb;
SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (sbrec_pb, pb_table) {
struct tracked_datapath *re_t_dp =
tracked_datapath_find(&re_data->tracked_route_datapaths,
sbrec_pb->datapath);
if (re_t_dp) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
if (route_exchange_find_port(sbrec_port_binding_by_name,
chassis, sbrec_pb, NULL)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
/* If this logical port name is used to filter on which router
* ports learning should happen then process the changes. */
if (sset_find(&re_data->filtered_ports, sbrec_pb->logical_port)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
const char *dp_name = smap_get(&sbrec_pb->options, "distributed-port");
if (dp_name && sset_contains(&re_data->tracked_ports_local,
dp_name)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
if (dp_name && sset_contains(&re_data->tracked_ports_remote,
dp_name)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
route_sb_advertised_route_data_handler(struct engine_node *node, void *data)
{
struct ed_type_route *re_data = data;
const struct sbrec_advertised_route_table *advertised_route_table =
EN_OVSDB_GET(engine_get_input("SB_advertised_route", node));
/* There are the following cases where we need to handle updates to the
* advertised_route table:
* 1. The advertised_route is created or deleted and we know about its
* datapath locally.
*
* Updates to advertised_route can generally be ignored as northd will not
* update these entries. For exceptions see below.
* We also get update notifications if a referenced port_binding is
* updated, but these are handled in the runtime_data handler. */
const struct sbrec_advertised_route *sbrec_route;
SBREC_ADVERTISED_ROUTE_TABLE_FOR_EACH_TRACKED (sbrec_route,
advertised_route_table) {
struct tracked_datapath *re_t_dp =
tracked_datapath_find(&re_data->tracked_route_datapaths,
sbrec_route->datapath);
if (!re_t_dp) {
continue;
}
if (sbrec_advertised_route_is_new(sbrec_route) ||
sbrec_advertised_route_is_deleted(sbrec_route)) {
/* XXX: Until we get I-P support for route exchange we need to
* request recompute. */
return EN_UNHANDLED;
}
if (sbrec_route->tracked_port) {
const char *name = sbrec_route->tracked_port->logical_port;
if (!(sset_contains(&re_data->tracked_ports_local, name) ||
sset_contains(&re_data->tracked_ports_remote, name))) {
/* Advertised_Routes are generally not changed by northd.
* However if we did not monitor for the Port_Binding
* referenced by tracked_port previously then it would have
* been NULL. If we notice that we have now loaded the
* Port_Binding we need to recompute to correctly update
* the route priority. */
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
route_sb_datapath_binding_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding *dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_table) {
if (sbrec_datapath_binding_is_new(dp) ||
sbrec_datapath_binding_is_deleted(dp)) {
/* We are reflecting only datapaths that are becoming or are
* removed from being local, that is taken care of by runtime_data
* handler. */
return EN_HANDLED_UNCHANGED;
}
struct local_datapath *ld =
get_local_datapath(&rt_data->local_datapaths, dp->tunnel_key);
if (!ld || ld->is_switch) {
continue;
}
if (sbrec_datapath_binding_is_updated(
dp, SBREC_DATAPATH_BINDING_COL_EXTERNAL_IDS)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
struct ed_type_route_exchange {
/* We need the idl to check if the Learned_Route table exists. */
struct ovsdb_idl *sb_idl;
/* Set to true when SB is readonly and we have routes that need
* to be inserted into SB. */
bool sb_changes_pending;
};
static enum engine_node_state
en_route_exchange_run(struct engine_node *node, void *data)
{
struct ed_type_route_exchange *re = data;
struct ovsdb_idl_index *sbrec_learned_route_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_learned_route", node),
"datapath");
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ed_type_route *route_data =
engine_get_input_data("route", node);
/* There can not actually be any routes to advertise unless we also have
* the Learned_Route table, since they where introduced in the same
* release. */
if (!sbrec_server_has_learned_route_table(re->sb_idl)) {
return EN_STALE;
}
struct route_exchange_ctx_in r_ctx_in = {
.ovnsb_idl_txn = engine_get_context()->ovnsb_idl_txn,
.sbrec_learned_route_by_datapath = sbrec_learned_route_by_datapath,
.sbrec_port_binding_by_name = sbrec_port_binding_by_name,
.announce_routes = &route_data->announce_routes,
};
struct route_exchange_ctx_out r_ctx_out = {
.sb_changes_pending = false,
};
hmap_init(&r_ctx_out.route_table_watches);
route_exchange_run(&r_ctx_in, &r_ctx_out);
route_table_notify_update_watches(&r_ctx_out.route_table_watches);
route_table_watch_request_cleanup(&r_ctx_out.route_table_watches);
hmap_destroy(&r_ctx_out.route_table_watches);
re->sb_changes_pending = r_ctx_out.sb_changes_pending;
return EN_UPDATED;
}
static enum engine_input_handler_result
route_exchange_sb_ro_handler(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_route_exchange *re = data;
if (re->sb_changes_pending) {
return EN_UNHANDLED;
}
return EN_HANDLED_UNCHANGED;
}
static void *
en_route_exchange_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg)
{
struct ed_type_route_exchange *re = xzalloc(sizeof *re);
re->sb_idl = arg->sb_idl;
return re;
}
static void
en_route_exchange_cleanup(void *data OVS_UNUSED)
{
}
struct ed_type_route_table_notify {
/* For incremental processing this could be tracked per datapath in
* the future. */
bool changed;
};
static enum engine_node_state
en_route_table_notify_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_route_table_notify *rtn = data;
enum engine_node_state state;
if (rtn->changed) {
state = EN_UPDATED;
} else {
state = EN_UNCHANGED;
}
rtn->changed = false;
return state;
}
static void *
en_route_table_notify_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_route_table_notify *rtn = xzalloc(sizeof *rtn);
rtn->changed = true;
return rtn;
}
static void
en_route_table_notify_cleanup(void *data OVS_UNUSED)
{
}
struct ed_type_route_exchange_status {
bool netlink_trigger_run;
};
static void *
en_route_exchange_status_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
return xzalloc(sizeof(struct ed_type_route_exchange_status));
}
static enum engine_node_state
en_route_exchange_status_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_route_exchange_status *res = data;
enum engine_node_state state;
if (res->netlink_trigger_run) {
state = EN_UPDATED;
} else {
state = EN_UNCHANGED;
}
res->netlink_trigger_run = false;
return state;
}
static void
en_route_exchange_status_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_garp_rarp_run(struct engine_node *node, void *data_)
{
struct ed_type_garp_rarp *data = data_;
struct controller_engine_ctx *ctrl_ctx =
engine_get_context()->client_ctx;
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
const struct ovsrec_open_vswitch *cfg
= ovsrec_open_vswitch_table_first(ovs_table);
struct ovsdb_idl_index *sbrec_port_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip =
engine_ovsdb_node_get_index(
engine_get_input("SB_mac_binding", node),
"lport_ip");
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct garp_rarp_ctx_in r_ctx_in = {
.ovnsb_idl_txn = engine_get_context()->ovnsb_idl_txn,
.cfg = cfg,
.sbrec_port_binding_by_datapath = sbrec_port_binding_by_datapath,
.sbrec_port_binding_by_name = sbrec_port_binding_by_name,
.sbrec_mac_binding_by_lport_ip = sbrec_mac_binding_by_lport_ip,
.chassis = chassis,
.active_tunnels = &rt_data->active_tunnels,
.local_datapaths = &rt_data->local_datapaths,
.data = data,
.mgr = ctrl_ctx->if_mgr,
};
garp_rarp_run(&r_ctx_in);
return EN_UPDATED;
}
static void *
en_garp_rarp_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
return garp_rarp_init();
}
static void
en_garp_rarp_cleanup(void *data)
{
garp_rarp_cleanup(data);
}
static enum engine_input_handler_result
garp_rarp_sb_port_binding_handler(struct engine_node *node,
void *data_)
{
/* We need to handle a change if there was change on a datapath with
* a localnet port.
* Also the ha_chassis status of a port binding might change. */
struct ed_type_garp_rarp *data = data_;
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const struct sbrec_chassis *chassis
= chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_port_binding_table *port_binding_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
struct controller_engine_ctx *ctrl_ctx = engine_get_context()->client_ctx;
const struct sbrec_port_binding *pb;
SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, port_binding_table) {
struct local_datapath *ld = get_local_datapath(
&rt_data->local_datapaths, pb->datapath->tunnel_key);
if (!ld) {
continue;
}
if (ld->localnet_port) {
/* XXX: actually handle this incrementally. */
return EN_UNHANDLED;
}
if (sset_contains(&data->non_local_lports, pb->logical_port) &&
lport_is_chassis_resident(sbrec_port_binding_by_name, chassis,
pb->logical_port)) {
/* XXX: actually handle this incrementally. */
return EN_UNHANDLED;
}
if (sset_contains(&data->local_lports, pb->logical_port) &&
!lport_is_chassis_resident(sbrec_port_binding_by_name, chassis,
pb->logical_port)) {
/* XXX: actually handle this incrementally. */
return EN_UNHANDLED;
}
/* If the cr_port was updated, bound to a different chassis in idl
* and (re)bound to our chassis in runtime data, make sure to reset
* garp timers*/
if (sbrec_port_binding_is_updated(pb,
SBREC_PORT_BINDING_COL_CHASSIS) &&
if_status_reclaimed(ctrl_ctx->if_mgr, pb->logical_port)) {
garp_rarp_node_reset_timers(pb->logical_port);
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
garp_rarp_sb_datapath_binding_handler(struct engine_node *node,
void *data_ OVS_UNUSED)
{
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding_table *dp_binding_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
const struct sbrec_datapath_binding *dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_binding_table) {
struct local_datapath *ld = get_local_datapath(
&rt_data->local_datapaths, dp->tunnel_key);
if (!ld || ld->is_switch) {
continue;
}
if (sbrec_datapath_binding_is_updated(
dp, SBREC_DATAPATH_BINDING_COL_EXTERNAL_IDS)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
garp_rarp_runtime_data_handler(struct engine_node *node, void *data OVS_UNUSED)
{
/* We use two elements from rt_data:
* 1. active_tunnels: There is currently not incremental processing for
* this in runtime_data. So we just fall back to a recompute.
* 2. local_datapaths: This has incremental processing on the runtime_data
* side. We are only interested in datapaths with a localnet port so
* we just recompute if there is one in there. Otherwise the change is
* irrelevant for us. */
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
/* There are no tracked data. Fall back to full recompute. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, &rt_data->tracked_dp_bindings) {
if (tdp->tracked_type == TRACKED_RESOURCE_REMOVED) {
/* This is currently not handled incrementally in runtime_data
* so it should never happen. Recompute just in case. */
return EN_UNHANDLED;
}
struct local_datapath *ld = get_local_datapath(
&rt_data->local_datapaths, tdp->dp->tunnel_key);
if (!ld) {
continue;
}
if (ld->localnet_port) {
/* XXX: actually handle this incrementally. */
return EN_UNHANDLED;
}
/* The localnet port might also have been removed. */
struct tracked_lport *tlp;
struct shash_node *sn;
SHASH_FOR_EACH (sn, &tdp->lports) {
tlp = sn->data;
if (!strcmp(tlp->pb->type, "localnet")) {
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UNCHANGED;
}
struct ed_type_host_if_monitor {
/* For incremental processing this could be tracked per interface in
* the future. */
bool changed;
};
static void *
en_host_if_monitor_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_host_if_monitor *hifm = xmalloc(sizeof *hifm);
*hifm = (struct ed_type_host_if_monitor) {
.changed = true,
};
return hifm;
}
static void
en_host_if_monitor_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_host_if_monitor_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_host_if_monitor *hifm = data;
enum engine_node_state state;
if (hifm->changed) {
state = EN_UPDATED;
} else {
state = EN_UNCHANGED;
}
hifm->changed = false;
return state;
}
struct ed_type_neighbor {
/* Contains struct neighbor_interface_monitor pointers. */
struct vector monitored_interfaces;
/* Contains set of PB names that are currently advertised. */
struct sset advertised_pbs;
};
static void *
en_neighbor_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_neighbor *data = xzalloc(sizeof *data);
*data = (struct ed_type_neighbor) {
.monitored_interfaces =
VECTOR_EMPTY_INITIALIZER(struct neighbor_interface_monitor *),
.advertised_pbs = SSET_INITIALIZER(&data->advertised_pbs),
};
return data;
}
static void
en_neighbor_cleanup(void *data)
{
struct ed_type_neighbor *ne_data = data;
neighbor_cleanup(&ne_data->monitored_interfaces);
vector_destroy(&ne_data->monitored_interfaces);
sset_destroy(&ne_data->advertised_pbs);
}
static enum engine_node_state
en_neighbor_run(struct engine_node *node OVS_UNUSED, void *data)
{
struct ed_type_neighbor *ne_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ovsdb_idl_index *sbrec_port_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"datapath");
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
struct ovsdb_idl_index *sbrec_advertised_mac_binding_by_datapath =
engine_ovsdb_node_get_index(
engine_get_input("SB_advertised_mac_binding", node),
"datapath");
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
const struct sbrec_chassis *chassis =
chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
struct neighbor_ctx_in n_ctx_in = {
.local_datapaths = &rt_data->local_datapaths,
.sbrec_pb_by_dp = sbrec_port_binding_by_datapath,
.sbrec_amb_by_dp = sbrec_advertised_mac_binding_by_datapath,
.sbrec_pb_by_name = sbrec_port_binding_by_name,
.chassis = chassis,
};
struct neighbor_ctx_out n_ctx_out = {
.monitored_interfaces = &ne_data->monitored_interfaces,
.advertised_pbs = &ne_data->advertised_pbs,
};
neighbor_cleanup(&ne_data->monitored_interfaces);
sset_clear(&ne_data->advertised_pbs);
neighbor_run(&n_ctx_in, &n_ctx_out);
return EN_UPDATED;
}
static enum engine_input_handler_result
neighbor_runtime_data_handler(struct engine_node *node, void *data)
{
struct ed_type_neighbor *ne_data = data;
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
struct ovsdb_idl_index *sbrec_port_binding_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_port_binding", node),
"name");
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
struct ovsdb_idl_index *sbrec_chassis_by_name =
engine_ovsdb_node_get_index(
engine_get_input("SB_chassis", node),
"name");
const char *chassis_id = get_ovs_chassis_id(ovs_table);
ovs_assert(chassis_id);
const struct sbrec_chassis *chassis =
chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id);
ovs_assert(chassis);
/* There are no tracked data. Fall back to full recompute. */
if (!rt_data->tracked) {
return EN_UNHANDLED;
}
struct tracked_datapath *tdp;
HMAP_FOR_EACH (tdp, node, &rt_data->tracked_dp_bindings) {
struct local_datapath *ld =
get_local_datapath(&rt_data->local_datapaths, tdp->dp->tunnel_key);
if (!ld || !ld->is_switch) {
continue;
}
int64_t vni = ovn_smap_get_llong(&tdp->dp->external_ids,
"dynamic-routing-vni", -1);
if (!ovn_is_valid_vni(vni)) {
continue;
}
if (tdp->tracked_type == TRACKED_RESOURCE_NEW ||
tdp->tracked_type == TRACKED_RESOURCE_REMOVED) {
return EN_UNHANDLED;
}
enum neigh_redistribute_mode mode =
parse_neigh_dynamic_redistribute(&ld->datapath->external_ids);
if (mode == NRM_NONE) {
continue;
}
const struct shash_node *shash_node;
SHASH_FOR_EACH (shash_node, &tdp->lports) {
if (neighbor_is_relevant_port_updated(sbrec_port_binding_by_name,
chassis,
&ne_data->advertised_pbs,
shash_node->data)) {
return EN_UNHANDLED;
}
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
neighbor_sb_datapath_binding_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding *dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_table) {
if (sbrec_datapath_binding_is_new(dp) ||
sbrec_datapath_binding_is_deleted(dp)) {
/* We are reflecting only datapaths that are becoming or are
* removed from being local, that is taken care of by runtime_data
* handler. */
return EN_HANDLED_UNCHANGED;
}
struct local_datapath *ld =
get_local_datapath(&rt_data->local_datapaths, dp->tunnel_key);
if (!ld || !ld->is_switch) {
continue;
}
if (sbrec_datapath_binding_is_updated(
dp, SBREC_DATAPATH_BINDING_COL_EXTERNAL_IDS)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
neighbor_sb_port_binding_handler(struct engine_node *node, void *data)
{
struct ed_type_neighbor *ne_data = data;
const struct sbrec_port_binding_table *pb_table =
EN_OVSDB_GET(engine_get_input("SB_port_binding", node));
const struct sbrec_port_binding *pb;
SBREC_PORT_BINDING_TABLE_FOR_EACH_TRACKED (pb, pb_table) {
if (sbrec_port_binding_is_new(pb) ||
sbrec_port_binding_is_deleted(pb)) {
/* The removal and addition is handled via runtime_data. */
return EN_HANDLED_UNCHANGED;
}
if (sbrec_port_binding_is_updated(pb, SBREC_PORT_BINDING_COL_MAC) &&
sset_contains(&ne_data->advertised_pbs, pb->logical_port)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
struct ed_type_neighbor_table_notify {
/* For incremental processing this could be tracked per interface in
* the future. */
bool changed;
};
static void *
en_neighbor_table_notify_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_neighbor_table_notify *ntn = xmalloc(sizeof *ntn);
*ntn = (struct ed_type_neighbor_table_notify) {
.changed = true,
};
return ntn;
}
static void
en_neighbor_table_notify_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_neighbor_table_notify_run(struct engine_node *node OVS_UNUSED,
void *data)
{
struct ed_type_neighbor_table_notify *ntn = data;
enum engine_node_state state;
if (ntn->changed) {
state = EN_UPDATED;
} else {
state = EN_UNCHANGED;
}
ntn->changed = false;
return state;
}
struct ed_type_neighbor_exchange {
/* Contains 'struct evpn_remote_vtep'. */
struct hmap remote_vteps;
/* Contains 'struct evpn_static_entry', remote FDB entries learned through
* EVPN. */
struct hmap static_fdbs;
/* Contains 'struct evpn_static_entry', remote ARP entries learned through
* EVPN. */
struct hmap static_arps;
};
static void *
en_neighbor_exchange_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_neighbor_exchange *data = xmalloc(sizeof *data);
*data = (struct ed_type_neighbor_exchange) {
.remote_vteps = HMAP_INITIALIZER(&data->remote_vteps),
.static_fdbs = HMAP_INITIALIZER(&data->static_fdbs),
.static_arps = HMAP_INITIALIZER(&data->static_arps),
};
return data;
}
static void
en_neighbor_exchange_cleanup(void *data_)
{
struct ed_type_neighbor_exchange *data = data_;
evpn_remote_vteps_clear(&data->remote_vteps);
evpn_static_entries_clear(&data->static_fdbs);
evpn_static_entries_clear(&data->static_arps);
hmap_destroy(&data->remote_vteps);
hmap_destroy(&data->static_fdbs);
hmap_destroy(&data->static_arps);
}
static enum engine_node_state
en_neighbor_exchange_run(struct engine_node *node, void *data_)
{
struct ed_type_neighbor_exchange *data = data_;
const struct ed_type_neighbor *neighbor_data =
engine_get_input_data("neighbor", node);
evpn_remote_vteps_clear(&data->remote_vteps);
evpn_static_entries_clear(&data->static_fdbs);
evpn_static_entries_clear(&data->static_arps);
struct neighbor_exchange_ctx_in n_ctx_in = {
.monitored_interfaces = &neighbor_data->monitored_interfaces,
};
struct neighbor_exchange_ctx_out n_ctx_out = {
.neighbor_table_watches =
HMAP_INITIALIZER(&n_ctx_out.neighbor_table_watches),
.remote_vteps = &data->remote_vteps,
.static_fdbs = &data->static_fdbs,
.static_arps = &data->static_arps,
};
neighbor_exchange_run(&n_ctx_in, &n_ctx_out);
neighbor_table_notify_update_watches(&n_ctx_out.neighbor_table_watches);
neighbor_table_watch_request_cleanup(&n_ctx_out.neighbor_table_watches);
hmap_destroy(&n_ctx_out.neighbor_table_watches);
return EN_UPDATED;
}
struct ed_type_neighbor_exchange_status {
bool netlink_trigger_run;
};
static void *
en_neighbor_exchange_status_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
return xzalloc(sizeof(struct ed_type_neighbor_exchange_status));
}
static void
en_neighbor_exchange_status_cleanup(void *data OVS_UNUSED)
{
}
static enum engine_node_state
en_neighbor_exchange_status_run(struct engine_node *node OVS_UNUSED,
void *data OVS_UNUSED)
{
struct ed_type_neighbor_exchange_status *res = data;
enum engine_node_state state;
if (res->netlink_trigger_run) {
state = EN_UPDATED;
} else {
state = EN_UNCHANGED;
}
res->netlink_trigger_run = false;
return state;
}
static void *
en_evpn_vtep_binding_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_evpn_vtep_binding *data = xmalloc(sizeof *data);
*data = (struct ed_type_evpn_vtep_binding) {
.bindings = HMAP_INITIALIZER(&data->bindings),
.updated_bindings = HMAPX_INITIALIZER(&data->updated_bindings),
.removed_bindings = UUIDSET_INITIALIZER(&data->removed_bindings),
.datapaths = HMAP_INITIALIZER(&data->datapaths),
.multicast_groups = HMAP_INITIALIZER(&data->multicast_groups),
.updated_multicast_groups =
HMAPX_INITIALIZER(&data->updated_multicast_groups),
.removed_multicast_groups =
UUIDSET_INITIALIZER(&data->removed_multicast_groups),
.tunnel_keys = HMAP_INITIALIZER(&data->tunnel_keys),
};
return data;
}
static void
en_evpn_vtep_binding_clear_tracked_data(void *data_)
{
struct ed_type_evpn_vtep_binding *data = data_;
hmapx_clear(&data->updated_bindings);
uuidset_clear(&data->removed_bindings);
evpn_datapaths_clear(&data->datapaths);
hmapx_clear(&data->updated_multicast_groups);
uuidset_clear(&data->removed_multicast_groups);
}
static void
en_evpn_vtep_binding_cleanup(void *data_)
{
struct ed_type_evpn_vtep_binding *data = data_;
evpn_bindings_destroy(&data->bindings);
hmapx_destroy(&data->updated_bindings);
uuidset_destroy(&data->removed_bindings);
evpn_datapaths_destroy(&data->datapaths);
evpn_multicast_groups_destroy(&data->multicast_groups);
hmapx_clear(&data->updated_multicast_groups);
uuidset_clear(&data->removed_multicast_groups);
ovn_destroy_tnlids(&data->tunnel_keys);
}
static enum engine_node_state
en_evpn_vtep_binding_run(struct engine_node *node, void *data_)
{
struct ed_type_evpn_vtep_binding *data = data_;
const struct ed_type_neighbor_exchange *ne_data =
engine_get_input_data("neighbor_exchange", node);
const struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct ovsrec_open_vswitch_table *ovs_table =
EN_OVSDB_GET(engine_get_input("OVS_open_vswitch", node));
const struct ovsrec_bridge_table *bridge_table =
EN_OVSDB_GET(engine_get_input("OVS_bridge", node));
const struct ovsrec_bridge *br_int = get_br_int(bridge_table, ovs_table);
struct evpn_binding_ctx_in b_ctx_in = {
.br_int = br_int,
.local_datapaths = &rt_data->local_datapaths,
.remote_vteps = &ne_data->remote_vteps,
};
struct evpn_binding_ctx_out b_ctx_out = {
.bindings = &data->bindings,
.updated_bindings = &data->updated_bindings,
.removed_bindings = &data->removed_bindings,
.datapaths = &data->datapaths,
.multicast_groups = &data->multicast_groups,
.updated_multicast_groups = &data->updated_multicast_groups,
.removed_multicast_groups = &data->removed_multicast_groups,
.tunnel_keys = &data->tunnel_keys,
};
evpn_binding_run(&b_ctx_in, &b_ctx_out);
if (hmapx_count(&data->updated_bindings) ||
uuidset_count(&data->removed_bindings) ||
hmapx_count(&data->updated_multicast_groups) ||
uuidset_count(&data->removed_multicast_groups)) {
return EN_UPDATED;
}
return EN_UNCHANGED;
}
static enum engine_input_handler_result
evpn_vtep_binding_ovs_interface_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct ovsrec_interface_table *iface_table =
EN_OVSDB_GET(engine_get_input("OVS_interface", node));
const struct ovsrec_interface *iface;
OVSREC_INTERFACE_TABLE_FOR_EACH_TRACKED (iface, iface_table) {
if (!smap_get_bool(&iface->external_ids, "ovn-evpn-tunnel", false)) {
continue;
}
if (ovsrec_interface_is_new(iface) ||
ovsrec_interface_is_deleted(iface) ||
ovsrec_interface_is_updated(iface, OVSREC_INTERFACE_COL_OFPORT)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static enum engine_input_handler_result
evpn_vtep_binding_datapath_binding_handler(struct engine_node *node,
void *data OVS_UNUSED)
{
const struct sbrec_datapath_binding_table *dp_table =
EN_OVSDB_GET(engine_get_input("SB_datapath_binding", node));
const struct ed_type_runtime_data *rt_data =
engine_get_input_data("runtime_data", node);
const struct sbrec_datapath_binding *dp;
SBREC_DATAPATH_BINDING_TABLE_FOR_EACH_TRACKED (dp, dp_table) {
if (sbrec_datapath_binding_is_new(dp) ||
sbrec_datapath_binding_is_deleted(dp)) {
/* The removal and addition is handled via the
* en_neighbor_exchange I-P node. */
return EN_HANDLED_UNCHANGED;
}
struct local_datapath *ld =
get_local_datapath(&rt_data->local_datapaths, dp->tunnel_key);
if (!ld || !ld->is_switch) {
continue;
}
int64_t vni = ovn_smap_get_llong(&dp->external_ids,
"dynamic-routing-vni", -1);
if (!ovn_is_valid_vni(vni)) {
continue;
}
if (sbrec_datapath_binding_is_updated(
dp, SBREC_DATAPATH_BINDING_COL_TUNNEL_KEY)) {
return EN_UNHANDLED;
}
}
return EN_HANDLED_UNCHANGED;
}
static void *
en_evpn_fdb_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_evpn_fdb *data = xmalloc(sizeof *data);
*data = (struct ed_type_evpn_fdb) {
.fdbs = HMAP_INITIALIZER(&data->fdbs),
.updated_fdbs = HMAPX_INITIALIZER(&data->updated_fdbs),
.removed_fdbs = UUIDSET_INITIALIZER(&data->removed_fdbs),
};
return data;
}
static void
en_evpn_fdb_clear_tracked_data(void *data_)
{
struct ed_type_evpn_fdb *data = data_;
hmapx_clear(&data->updated_fdbs);
uuidset_clear(&data->removed_fdbs);
}
static void
en_evpn_fdb_cleanup(void *data_)
{
struct ed_type_evpn_fdb *data = data_;
evpn_fdbs_destroy(&data->fdbs);
hmapx_destroy(&data->updated_fdbs);
uuidset_destroy(&data->removed_fdbs);
}
static enum engine_node_state
en_evpn_fdb_run(struct engine_node *node, void *data_)
{
struct ed_type_evpn_fdb *data = data_;
const struct ed_type_neighbor_exchange *ne_data =
engine_get_input_data("neighbor_exchange", node);
const struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
struct evpn_fdb_ctx_in f_ctx_in = {
.static_fdbs = &ne_data->static_fdbs,
.bindings = &eb_data->bindings,
};
struct evpn_fdb_ctx_out f_ctx_out = {
.fdbs = &data->fdbs,
.updated_fdbs = &data->updated_fdbs,
.removed_fdbs = &data->removed_fdbs,
};
evpn_fdb_run(&f_ctx_in, &f_ctx_out);
if (hmapx_count(&data->updated_fdbs) ||
uuidset_count(&data->removed_fdbs)) {
return EN_UPDATED;
}
return EN_UNCHANGED;
}
static enum engine_input_handler_result
evpn_fdb_vtep_binding_handler(struct engine_node *node, void *data OVS_UNUSED)
{
const struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
if (hmapx_is_empty(&eb_data->updated_bindings) &&
uuidset_is_empty(&eb_data->removed_bindings)) {
return EN_HANDLED_UNCHANGED;
}
return EN_UNHANDLED;
}
static void *
en_evpn_arp_init(struct engine_node *node OVS_UNUSED,
struct engine_arg *arg OVS_UNUSED)
{
struct ed_type_evpn_arp *data = xmalloc(sizeof *data);
*data = (struct ed_type_evpn_arp) {
.arps = HMAP_INITIALIZER(&data->arps),
.updated_arps = HMAPX_INITIALIZER(&data->updated_arps),
.removed_arps = UUIDSET_INITIALIZER(&data->removed_arps),
};
return data;
}
static void
en_evpn_arp_clear_tracked_data(void *data_)
{
struct ed_type_evpn_arp *data = data_;
hmapx_clear(&data->updated_arps);
uuidset_clear(&data->removed_arps);
}
static void
en_evpn_arp_cleanup(void *data_)
{
struct ed_type_evpn_arp *data = data_;
evpn_arps_destroy(&data->arps);
hmapx_destroy(&data->updated_arps);
uuidset_destroy(&data->removed_arps);
}
static enum engine_node_state
en_evpn_arp_run(struct engine_node *node, void *data_)
{
struct ed_type_evpn_arp *data = data_;
const struct ed_type_neighbor_exchange *ne_data =
engine_get_input_data("neighbor_exchange", node);
const struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
struct evpn_arp_ctx_in f_ctx_in = {
.datapaths = &eb_data->datapaths,
.static_arps = &ne_data->static_arps,
};
struct evpn_arp_ctx_out f_ctx_out = {
.arps = &data->arps,
.updated_arps = &data->updated_arps,
.removed_arps = &data->removed_arps,
};
evpn_arp_run(&f_ctx_in, &f_ctx_out);
if (hmapx_count(&data->updated_arps) ||
uuidset_count(&data->removed_arps)) {
return EN_UPDATED;
}
return EN_UNCHANGED;
}
static enum engine_input_handler_result
evpn_arp_vtep_binding_handler(struct engine_node *node, void *data OVS_UNUSED)
{
const struct ed_type_evpn_vtep_binding *eb_data =
engine_get_input_data("evpn_vtep_binding", node);
if (hmapx_is_empty(&eb_data->updated_bindings) &&
uuidset_is_empty(&eb_data->removed_bindings)) {
return EN_HANDLED_UNCHANGED;
}
return EN_UNHANDLED;
}
/* Define engine node functions for nodes that represent SB tables.
*
* en_sb_<TABLE_NAME>_run()
* en_sb_<TABLE_NAME>_init()
* en_sb_<TABLE_NAME>_cleanup()
* en_sb_<TABLE_NAME>_compute_failure_info()
*/
#define SB_NODES \
SB_NODE(sb_global) \
SB_NODE(chassis) \
SB_NODE(ha_chassis_group) \
SB_NODE(encap) \
SB_NODE(address_set) \
SB_NODE(port_group) \
SB_NODE(multicast_group) \
SB_NODE(datapath_binding) \
SB_NODE(logical_dp_group) \
SB_NODE(port_binding) \
SB_NODE(mac_binding) \
SB_NODE(logical_flow) \
SB_NODE(dhcp_options) \
SB_NODE(dhcpv6_options) \
SB_NODE(dns) \
SB_NODE(load_balancer) \
SB_NODE(fdb) \
SB_NODE(meter) \
SB_NODE(static_mac_binding) \
SB_NODE(chassis_template_var) \
SB_NODE(acl_id) \
SB_NODE(advertised_route) \
SB_NODE(learned_route) \
SB_NODE(advertised_mac_binding)
enum sb_engine_node {
#define SB_NODE(NAME) SB_##NAME,
SB_NODES
#undef SB_NODE
};
#define SB_NODE(NAME) ENGINE_FUNC_SB(NAME);
SB_NODES
#undef SB_NODE
/* Define engine node functions for nodes that represent OVS tables.
*
* en_ovs_<TABLE_NAME>_run()
* en_ovs_<TABLE_NAME>_init()
* en_ovs_<TABLE_NAME>_cleanup()
* en_ovs_<TABLE_NAME>_compute_failure_info()
*/
#define OVS_NODES \
OVS_NODE(open_vswitch) \
OVS_NODE(bridge) \
OVS_NODE(port) \
OVS_NODE(interface) \
OVS_NODE(qos) \
OVS_NODE(queue) \
OVS_NODE(flow_sample_collector_set)
enum ovs_engine_node {
#define OVS_NODE(NAME) OVS_##NAME,
OVS_NODES
#undef OVS_NODE
};
#define OVS_NODE(NAME) ENGINE_FUNC_OVS(NAME);
OVS_NODES
#undef OVS_NODE
/* Define engine nodes for SB and OVS tables.
*
* struct engine_node en_sb_<TABLE_NAME>
* struct engine_node en_ovs_<TABLE_NAME>
*
* Define nodes as static to avoid sparse errors.
*/
#define SB_NODE(NAME) static ENGINE_NODE_SB(NAME);
SB_NODES
#undef SB_NODE
#define OVS_NODE(NAME) static ENGINE_NODE_OVS(NAME);
OVS_NODES
#undef OVS_NODE
/* Define engine nodes for other nodes. They should be defined as static to
* avoid sparse errors. */
static ENGINE_NODE(sb_ro);
static ENGINE_NODE(template_vars, CLEAR_TRACKED_DATA);
static ENGINE_NODE(ct_zones, CLEAR_TRACKED_DATA, IS_VALID);
static ENGINE_NODE(ovs_interface_shadow, CLEAR_TRACKED_DATA);
static ENGINE_NODE(runtime_data, CLEAR_TRACKED_DATA, SB_WRITE);
static ENGINE_NODE(non_vif_data);
static ENGINE_NODE(mff_ovn_geneve);
static ENGINE_NODE(ofctrl_is_connected);
static ENGINE_NODE(activated_ports, CLEAR_TRACKED_DATA);
static ENGINE_NODE(postponed_ports);
static ENGINE_NODE(pflow_output);
static ENGINE_NODE(lflow_output, CLEAR_TRACKED_DATA);
static ENGINE_NODE(controller_output);
static ENGINE_NODE(addr_sets, CLEAR_TRACKED_DATA);
static ENGINE_NODE(port_groups, CLEAR_TRACKED_DATA);
static ENGINE_NODE(northd_options);
static ENGINE_NODE(dhcp_options);
static ENGINE_NODE(if_status_mgr);
static ENGINE_NODE(lb_data, CLEAR_TRACKED_DATA);
static ENGINE_NODE(mac_cache);
static ENGINE_NODE(bfd_chassis);
static ENGINE_NODE(dns_cache);
static ENGINE_NODE(acl_id, IS_VALID);
static ENGINE_NODE(route);
static ENGINE_NODE(route_table_notify);
static ENGINE_NODE(route_exchange, SB_WRITE);
static ENGINE_NODE(route_exchange_status);
static ENGINE_NODE(garp_rarp, SB_WRITE);
static ENGINE_NODE(host_if_monitor);
static ENGINE_NODE(neighbor);
static ENGINE_NODE(neighbor_table_notify);
static ENGINE_NODE(neighbor_exchange);
static ENGINE_NODE(neighbor_exchange_status);
static ENGINE_NODE(evpn_vtep_binding, CLEAR_TRACKED_DATA);
static ENGINE_NODE(evpn_fdb, CLEAR_TRACKED_DATA);
static ENGINE_NODE(evpn_arp, CLEAR_TRACKED_DATA);
static void
inc_proc_ovn_controller_init(
struct ovsdb_idl_loop *sb_idl_loop, struct ovsdb_idl_loop *ovs_idl_loop,
struct ovsdb_idl_index *sbrec_chassis_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_name,
struct ovsdb_idl_index *sbrec_port_binding_by_key,
struct ovsdb_idl_index *sbrec_datapath_binding_by_key,
struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip,
struct ovsdb_idl_index *ovsrec_flow_sample_collector_set_by_id,
struct ovsdb_idl_index *ovsrec_port_by_qos,
struct ovsdb_idl_index *ovsrec_interface_by_name,
struct ovsdb_idl_index *ovsrec_queue_by_external_ids)
{
/* Define relationships between nodes where first argument is dependent
* on the second argument. */
engine_add_input(&en_template_vars, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_template_vars, &en_sb_chassis, NULL);
engine_add_input(&en_template_vars, &en_sb_chassis_template_var,
template_vars_sb_chassis_template_var_handler);
engine_add_input(&en_lb_data, &en_sb_load_balancer,
lb_data_sb_load_balancer_handler);
engine_add_input(&en_lb_data, &en_template_vars,
lb_data_template_var_handler);
engine_add_input(&en_lb_data, &en_runtime_data,
lb_data_runtime_data_handler);
engine_add_input(&en_route, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_route, &en_sb_chassis, NULL);
engine_add_input(&en_route, &en_sb_port_binding,
route_sb_port_binding_data_handler);
engine_add_input(&en_route, &en_runtime_data,
route_runtime_data_handler);
engine_add_input(&en_route, &en_sb_advertised_route,
route_sb_advertised_route_data_handler);
engine_add_input(&en_route, &en_sb_datapath_binding,
route_sb_datapath_binding_handler);
engine_add_input(&en_route_exchange, &en_route, NULL);
engine_add_input(&en_route_exchange, &en_sb_learned_route,
engine_noop_handler);
engine_add_input(&en_route_exchange, &en_sb_port_binding,
engine_noop_handler);
engine_add_input(&en_route_exchange, &en_route_table_notify, NULL);
engine_add_input(&en_route_exchange, &en_route_exchange_status, NULL);
engine_add_input(&en_route_exchange, &en_sb_ro,
route_exchange_sb_ro_handler);
engine_add_input(&en_addr_sets, &en_sb_address_set,
addr_sets_sb_address_set_handler);
engine_add_input(&en_port_groups, &en_sb_port_group,
port_groups_sb_port_group_handler);
/* port_groups computation requires runtime_data's lbinding_data for the
* locally bound ports. */
engine_add_input(&en_port_groups, &en_runtime_data,
port_groups_runtime_data_handler);
engine_add_input(&en_non_vif_data, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_non_vif_data, &en_ovs_bridge, NULL);
engine_add_input(&en_non_vif_data, &en_sb_chassis, NULL);
engine_add_input(&en_non_vif_data, &en_ovs_interface,
non_vif_data_ovs_iface_handler);
engine_add_input(&en_if_status_mgr, &en_ovs_interface,
if_status_mgr_ovs_interface_handler);
engine_add_input(&en_bfd_chassis, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_bfd_chassis, &en_sb_chassis, NULL);
engine_add_input(&en_bfd_chassis, &en_sb_ha_chassis_group, NULL);
/* Note: The order of inputs is important, all OVS interface changes must
* be handled before any ct_zone changes.
*/
engine_add_input(&en_pflow_output, &en_non_vif_data,
NULL);
engine_add_input(&en_pflow_output, &en_northd_options, NULL);
engine_add_input(&en_pflow_output, &en_ct_zones,
pflow_output_ct_zones_handler);
engine_add_input(&en_pflow_output, &en_sb_chassis,
pflow_lflow_output_sb_chassis_handler);
engine_add_input(&en_pflow_output, &en_if_status_mgr,
pflow_output_if_status_mgr_handler);
engine_add_input(&en_pflow_output, &en_sb_port_binding,
pflow_output_sb_port_binding_handler);
engine_add_input(&en_pflow_output, &en_sb_multicast_group,
pflow_output_sb_multicast_group_handler);
/* pflow_output needs to access the SB datapath binding and hence a noop
* handler.
*/
engine_add_input(&en_pflow_output, &en_sb_datapath_binding,
engine_noop_handler);
engine_add_input(&en_pflow_output, &en_activated_ports,
pflow_output_activated_ports_handler);
engine_add_input(&en_pflow_output, &en_runtime_data,
pflow_output_runtime_data_handler);
engine_add_input(&en_pflow_output, &en_sb_encap, NULL);
engine_add_input(&en_pflow_output, &en_mff_ovn_geneve, NULL);
engine_add_input(&en_pflow_output, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_pflow_output, &en_ovs_bridge, NULL);
engine_add_input(&en_pflow_output, &en_ovs_flow_sample_collector_set,
pflow_output_debug_handler);
engine_add_input(&en_pflow_output, &en_sb_sb_global,
pflow_output_debug_handler);
engine_add_input(&en_northd_options, &en_sb_sb_global,
en_northd_options_sb_sb_global_handler);
engine_add_input(&en_dhcp_options, &en_sb_dhcp_options, NULL);
engine_add_input(&en_dhcp_options, &en_sb_dhcpv6_options, NULL);
engine_add_input(&en_lflow_output, &en_northd_options, NULL);
engine_add_input(&en_lflow_output, &en_dhcp_options, NULL);
/* Keep en_addr_sets before en_runtime_data because
* lflow_output_runtime_data_handler may *partially* reprocess a lflow when
* the lflow is attached to a DP group and a new DP in that DP group is
* added locally, i.e. reprocessing the lflow for the new DP only but not
* for the other DPs in the group. If we handle en_addr_sets after this,
* incrementally processing an updated address set for the added IPs may
* end up adding redundant flows/conjunctions for the lflow agaist the new
* DP because it has been processed on the DP already. */
engine_add_input(&en_lflow_output, &en_addr_sets,
lflow_output_addr_sets_handler);
engine_add_input(&en_lflow_output, &en_port_groups,
lflow_output_port_groups_handler);
engine_add_input(&en_lflow_output, &en_template_vars,
lflow_output_template_vars_handler);
engine_add_input(&en_lflow_output, &en_runtime_data,
lflow_output_runtime_data_handler);
engine_add_input(&en_lflow_output, &en_non_vif_data,
NULL);
engine_add_input(&en_lflow_output, &en_sb_multicast_group,
lflow_output_sb_multicast_group_handler);
engine_add_input(&en_lflow_output, &en_sb_chassis,
pflow_lflow_output_sb_chassis_handler);
engine_add_input(&en_lflow_output, &en_sb_port_binding,
lflow_output_sb_port_binding_handler);
engine_add_input(&en_lflow_output, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_lflow_output, &en_ovs_bridge, NULL);
engine_add_input(&en_lflow_output, &en_ovs_flow_sample_collector_set,
lflow_output_flow_sample_collector_set_handler);
engine_add_input(&en_lflow_output, &en_sb_mac_binding,
lflow_output_sb_mac_binding_handler);
engine_add_input(&en_lflow_output, &en_sb_static_mac_binding,
lflow_output_sb_static_mac_binding_handler);
engine_add_input(&en_lflow_output, &en_sb_logical_flow,
lflow_output_sb_logical_flow_handler);
/* Using a noop handler since we don't really need any data from datapath
* groups or a full recompute. Update of a datapath group will put
* logical flow into the tracked list, so the logical flow handler will
* process all changes. */
engine_add_input(&en_lflow_output, &en_sb_logical_dp_group,
engine_noop_handler);
engine_add_input(&en_lflow_output, &en_lb_data,
lflow_output_lb_data_handler);
engine_add_input(&en_lflow_output, &en_sb_fdb,
lflow_output_sb_fdb_handler);
engine_add_input(&en_lflow_output, &en_sb_meter,
lflow_output_sb_meter_handler);
engine_add_input(&en_ct_zones, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_ct_zones, &en_ovs_bridge, NULL);
engine_add_input(&en_ct_zones, &en_sb_datapath_binding,
ct_zones_datapath_binding_handler);
engine_add_input(&en_ct_zones, &en_runtime_data,
ct_zones_runtime_data_handler);
engine_add_input(&en_ovs_interface_shadow, &en_ovs_interface,
ovs_interface_shadow_ovs_interface_handler);
engine_add_input(&en_runtime_data, &en_ofctrl_is_connected, NULL);
engine_add_input(&en_runtime_data, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_runtime_data, &en_ovs_bridge, NULL);
engine_add_input(&en_runtime_data, &en_ovs_qos, NULL);
engine_add_input(&en_runtime_data, &en_ovs_queue, NULL);
engine_add_input(&en_runtime_data, &en_sb_chassis, NULL);
engine_add_input(&en_runtime_data, &en_sb_datapath_binding,
runtime_data_sb_datapath_binding_handler);
engine_add_input(&en_runtime_data, &en_sb_port_binding,
runtime_data_sb_port_binding_handler);
/* Reuse the same handler for any previously postponed ports. */
engine_add_input(&en_runtime_data, &en_postponed_ports,
runtime_data_sb_port_binding_handler);
/* Run sb_ro_handler after port_binding_handler in case port get deleted */
engine_add_input(&en_runtime_data, &en_sb_ro, runtime_data_sb_ro_handler);
/* The OVS interface handler for runtime_data changes MUST be executed
* after the sb_port_binding_handler as port_binding deletes must be
* processed first.
*
* runtime_data needs to access the OVS Port data and hence a noop
* handler.
*/
engine_add_input(&en_runtime_data, &en_ovs_port,
engine_noop_handler);
engine_add_input(&en_runtime_data, &en_ovs_interface_shadow,
runtime_data_ovs_interface_shadow_handler);
engine_add_input(&en_mac_cache, &en_runtime_data,
mac_cache_runtime_data_handler);
engine_add_input(&en_mac_cache, &en_sb_mac_binding,
mac_cache_sb_mac_binding_handler);
engine_add_input(&en_mac_cache, &en_sb_fdb,
mac_cache_sb_fdb_handler);
engine_add_input(&en_mac_cache, &en_sb_datapath_binding,
mac_cache_sb_datapath_binding_handler);
engine_add_input(&en_mac_cache, &en_sb_port_binding,
engine_noop_handler);
engine_add_input(&en_dns_cache, &en_sb_dns,
dns_cache_sb_dns_handler);
engine_add_input(&en_garp_rarp, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_garp_rarp, &en_sb_chassis, NULL);
engine_add_input(&en_garp_rarp, &en_sb_port_binding,
garp_rarp_sb_port_binding_handler);
engine_add_input(&en_garp_rarp, &en_sb_datapath_binding,
garp_rarp_sb_datapath_binding_handler);
/* The mac_binding data is just used in an index to filter duplicates when
* inserting data to the southbound. */
engine_add_input(&en_garp_rarp, &en_sb_mac_binding, engine_noop_handler);
engine_add_input(&en_garp_rarp, &en_runtime_data,
garp_rarp_runtime_data_handler);
engine_add_input(&en_neighbor, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_neighbor, &en_sb_chassis, NULL);
engine_add_input(&en_neighbor, &en_sb_advertised_mac_binding, NULL);
engine_add_input(&en_neighbor, &en_runtime_data,
neighbor_runtime_data_handler);
engine_add_input(&en_neighbor, &en_sb_datapath_binding,
neighbor_sb_datapath_binding_handler);
engine_add_input(&en_neighbor, &en_sb_port_binding,
neighbor_sb_port_binding_handler);
engine_add_input(&en_neighbor_exchange, &en_neighbor, NULL);
engine_add_input(&en_neighbor_exchange, &en_host_if_monitor, NULL);
engine_add_input(&en_neighbor_exchange, &en_neighbor_table_notify, NULL);
engine_add_input(&en_neighbor_exchange, &en_neighbor_exchange_status,
NULL);
engine_add_input(&en_evpn_vtep_binding, &en_ovs_open_vswitch, NULL);
engine_add_input(&en_evpn_vtep_binding, &en_ovs_bridge, NULL);
engine_add_input(&en_evpn_vtep_binding, &en_neighbor_exchange, NULL);
/* The runtime_data are needed only for local datapaths, any update of
* local datapath will be reflected via en_neighbor_exchange. */
engine_add_input(&en_evpn_vtep_binding, &en_runtime_data,
engine_noop_handler);
engine_add_input(&en_evpn_vtep_binding, &en_ovs_interface,
evpn_vtep_binding_ovs_interface_handler);
engine_add_input(&en_evpn_vtep_binding, &en_sb_datapath_binding,
evpn_vtep_binding_datapath_binding_handler);
engine_add_input(&en_evpn_fdb, &en_neighbor_exchange, NULL);
engine_add_input(&en_evpn_fdb, &en_evpn_vtep_binding,
evpn_fdb_vtep_binding_handler);
engine_add_input(&en_evpn_arp, &en_neighbor_exchange, NULL);
engine_add_input(&en_evpn_arp, &en_evpn_vtep_binding,
evpn_arp_vtep_binding_handler);
engine_add_input(&en_pflow_output, &en_evpn_vtep_binding,
pflow_output_evpn_binding_handler);
engine_add_input(&en_pflow_output, &en_evpn_fdb,
pflow_output_fdb_handler);
engine_add_input(&en_pflow_output, &en_evpn_arp,
pflow_output_arp_handler);
engine_add_input(&en_controller_output, &en_dns_cache,
NULL);
engine_add_input(&en_controller_output, &en_lflow_output,
controller_output_lflow_output_handler);
engine_add_input(&en_controller_output, &en_pflow_output,
controller_output_pflow_output_handler);
engine_add_input(&en_controller_output, &en_mac_cache,
controller_output_mac_cache_handler);
engine_add_input(&en_controller_output, &en_bfd_chassis,
controller_output_bfd_chassis_handler);
engine_add_input(&en_controller_output, &en_route_exchange,
controller_output_route_exchange_handler);
engine_add_input(&en_controller_output, &en_garp_rarp,
controller_output_garp_rarp_handler);
engine_add_input(&en_acl_id, &en_sb_acl_id, NULL);
engine_add_input(&en_controller_output, &en_acl_id,
controller_output_acl_id_handler);
struct engine_arg engine_arg = {
.sb_idl = sb_idl_loop->idl,
.ovs_idl = ovs_idl_loop->idl,
};
engine_init(&en_controller_output, &engine_arg);
engine_ovsdb_node_add_index(&en_sb_chassis, "name", sbrec_chassis_by_name);
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath
= mcast_group_index_create(sb_idl_loop->idl);
engine_ovsdb_node_add_index(&en_sb_multicast_group, "name_datapath",
sbrec_multicast_group_by_name_datapath);
struct ovsdb_idl_index *sbrec_logical_flow_by_logical_datapath
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_logical_flow_col_logical_datapath);
engine_ovsdb_node_add_index(&en_sb_logical_flow, "logical_datapath",
sbrec_logical_flow_by_logical_datapath);
struct ovsdb_idl_index *sbrec_logical_flow_by_logical_dp_group
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_logical_flow_col_logical_dp_group);
engine_ovsdb_node_add_index(&en_sb_logical_flow, "logical_dp_group",
sbrec_logical_flow_by_logical_dp_group);
engine_ovsdb_node_add_index(&en_sb_port_binding, "name",
sbrec_port_binding_by_name);
engine_ovsdb_node_add_index(&en_sb_port_binding, "key",
sbrec_port_binding_by_key);
struct ovsdb_idl_index *sbrec_port_binding_by_datapath
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_port_binding_col_datapath);
engine_ovsdb_node_add_index(&en_sb_port_binding, "datapath",
sbrec_port_binding_by_datapath);
engine_ovsdb_node_add_index(&en_sb_datapath_binding, "key",
sbrec_datapath_binding_by_key);
struct ovsdb_idl_index *sbrec_fdb_by_dp_key
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_fdb_col_dp_key);
engine_ovsdb_node_add_index(&en_sb_fdb, "dp_key",
sbrec_fdb_by_dp_key);
struct ovsdb_idl_index *sbrec_mac_binding_by_datapath
= mac_binding_by_datapath_index_create(sb_idl_loop->idl);
engine_ovsdb_node_add_index(&en_sb_mac_binding, "datapath",
sbrec_mac_binding_by_datapath);
struct ovsdb_idl_index *sbrec_static_mac_binding_by_datapath
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_static_mac_binding_col_datapath);
engine_ovsdb_node_add_index(&en_sb_static_mac_binding, "datapath",
sbrec_static_mac_binding_by_datapath);
struct ovsdb_idl_index *sbrec_chassis_template_var_index_by_chassis
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_chassis_template_var_col_chassis);
engine_ovsdb_node_add_index(&en_sb_chassis_template_var, "chassis",
sbrec_chassis_template_var_index_by_chassis);
struct ovsdb_idl_index *sbrec_learned_route_index_by_datapath
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_learned_route_col_datapath);
engine_ovsdb_node_add_index(&en_sb_learned_route, "datapath",
sbrec_learned_route_index_by_datapath);
struct ovsdb_idl_index *sbrec_advertised_mac_binding_index_by_dp
= ovsdb_idl_index_create1(sb_idl_loop->idl,
&sbrec_advertised_mac_binding_col_datapath);
engine_ovsdb_node_add_index(&en_sb_advertised_mac_binding, "datapath",
sbrec_advertised_mac_binding_index_by_dp);
engine_ovsdb_node_add_index(&en_sb_mac_binding, "lport_ip",
sbrec_mac_binding_by_lport_ip);
engine_ovsdb_node_add_index(&en_ovs_flow_sample_collector_set, "id",
ovsrec_flow_sample_collector_set_by_id);
engine_ovsdb_node_add_index(&en_ovs_port, "qos", ovsrec_port_by_qos);
engine_ovsdb_node_add_index(&en_ovs_interface, "name",
ovsrec_interface_by_name);
engine_ovsdb_node_add_index(&en_ovs_queue, "external_ids",
ovsrec_queue_by_external_ids);
}
/* Returns false if the northd internal version stored in SB_Global
* and ovn-controller internal version don't match.
*/
static bool
check_northd_version(struct ovsdb_idl *ovs_idl, struct ovsdb_idl *ovnsb_idl,
const char *version)
{
static bool version_mismatch;
const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
const struct ovsrec_open_vswitch_table *ovs_table =
ovsrec_open_vswitch_table_get(ovs_idl);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
if (!cfg || !get_chassis_external_id_value_bool(
&cfg->external_ids, chassis_id,
"ovn-match-northd-version", false)) {
version_mismatch = false;
return true;
}
const struct sbrec_sb_global *sb = sbrec_sb_global_first(ovnsb_idl);
if (!sb) {
version_mismatch = true;
return false;
}
const char *northd_version =
smap_get_def(&sb->options, "northd_internal_version", "");
if (strcmp(northd_version, version)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_WARN_RL(&rl, "controller version - %s mismatch with northd "
"version - %s", version, northd_version);
version_mismatch = true;
return false;
}
/* If there used to be a mismatch and ovn-northd got updated, force a
* full recompute.
*/
if (version_mismatch) {
engine_set_force_recompute();
}
version_mismatch = false;
return true;
}
static void
br_int_remote_update(struct br_int_remote *remote,
const struct ovsrec_bridge *br_int,
const struct ovsrec_open_vswitch_table *ovs_table)
{
if (!br_int) {
return;
}
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
const char *ext_target =
smap_get(&cfg->external_ids, "ovn-bridge-remote");
char *target = ext_target
? xstrdup(ext_target)
: xasprintf("unix:%s/%s.mgmt", ovs_rundir(), br_int->name);
if (!remote->target || strcmp(remote->target, target)) {
free(remote->target);
remote->target = target;
} else {
free(target);
}
unsigned long long probe_interval =
smap_get_ullong(&cfg->external_ids,
"ovn-bridge-remote-probe-interval", 0);
remote->probe_interval = MIN(probe_interval / 1000, INT_MAX);
}
static void
ovsdb_idl_loop_next_cfg_inc(struct ovsdb_idl_loop *idl_loop)
{
if (idl_loop->next_cfg == INT64_MAX) {
idl_loop->next_cfg = 0;
} else {
idl_loop->next_cfg++;
}
}
int
main(int argc, char *argv[])
{
struct unixctl_server *unixctl;
struct ovn_exit_args exit_args = {0};
struct br_int_remote br_int_remote = {0};
int retval;
/* Read from system-id-override file once on startup. */
file_system_id = get_file_system_id();
ovs_cmdl_proctitle_init(argc, argv);
ovn_set_program_name(argv[0]);
service_start(&argc, &argv);
char *ovs_remote = parse_options(argc, argv);
fatal_ignore_sigpipe();
daemonize_start(true, false);
char *abs_unixctl_path = get_abs_unix_ctl_path(unixctl_path);
retval = unixctl_server_create(abs_unixctl_path, &unixctl);
free(abs_unixctl_path);
if (retval) {
exit(EXIT_FAILURE);
}
unixctl_command_register("exit", "", 0, 1, ovn_exit_command_callback,
&exit_args);
daemonize_complete();
/* Register ofctrl seqno types. */
ofctrl_seq_type_nb_cfg = ofctrl_seqno_add_type();
patch_init();
pinctrl_init();
lflow_init();
mirror_init();
vif_plug_provider_initialize();
statctrl_init();
dns_resolve_init(true);
/* Connect to OVS OVSDB instance. */
struct ovsdb_idl_loop ovs_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create(ovs_remote, &ovsrec_idl_class, false, true));
ctrl_register_ovs_idl(ovs_idl_loop.idl);
struct ovsdb_idl_index *ovsrec_port_by_interfaces
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_port_col_interfaces);
struct ovsdb_idl_index *ovsrec_port_by_name
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_port_col_name);
struct ovsdb_idl_index *ovsrec_port_by_qos
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_port_col_qos);
struct ovsdb_idl_index *ovsrec_interface_by_name
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_interface_col_name);
struct ovsdb_idl_index *ovsrec_flow_sample_collector_set_by_id
= ovsdb_idl_index_create2(ovs_idl_loop.idl,
&ovsrec_flow_sample_collector_set_col_bridge,
&ovsrec_flow_sample_collector_set_col_id);
struct ovsdb_idl_index *ovsrec_queue_by_external_ids
= ovsdb_idl_index_create1(ovs_idl_loop.idl,
&ovsrec_queue_col_external_ids);
ovsdb_idl_get_initial_snapshot(ovs_idl_loop.idl);
/* Configure OVN SB database. */
struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create_unconnected(&sbrec_idl_class, true));
ovsdb_idl_set_leader_only(ovnsb_idl_loop.idl, false);
unixctl_command_register("connection-status", "", 0, 0,
ovn_conn_show, ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_chassis_by_name
= chassis_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_chassis_private_by_name
= chassis_private_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_meter_by_name
= ovsdb_idl_index_create1(ovnsb_idl_loop.idl, &sbrec_meter_col_name);
struct ovsdb_idl_index *sbrec_port_binding_by_name
= ovsdb_idl_index_create1(ovnsb_idl_loop.idl,
&sbrec_port_binding_col_logical_port);
struct ovsdb_idl_index *sbrec_port_binding_by_key
= ovsdb_idl_index_create2(ovnsb_idl_loop.idl,
&sbrec_port_binding_col_tunnel_key,
&sbrec_port_binding_col_datapath);
struct ovsdb_idl_index *sbrec_port_binding_by_type
= ovsdb_idl_index_create1(ovnsb_idl_loop.idl,
&sbrec_port_binding_col_type);
struct ovsdb_idl_index *sbrec_port_binding_by_requested_chassis
= ovsdb_idl_index_create1(ovnsb_idl_loop.idl,
&sbrec_port_binding_col_requested_chassis);
struct ovsdb_idl_index *sbrec_datapath_binding_by_key
= ovsdb_idl_index_create1(ovnsb_idl_loop.idl,
&sbrec_datapath_binding_col_tunnel_key);
struct ovsdb_idl_index *sbrec_mac_binding_by_lport_ip
= mac_binding_by_lport_ip_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_ip_multicast
= ip_mcast_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_igmp_group
= igmp_group_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_fdb_by_dp_key_mac
= ovsdb_idl_index_create2(ovnsb_idl_loop.idl,
&sbrec_fdb_col_mac,
&sbrec_fdb_col_dp_key);
struct ovsdb_idl_index *sbrec_encaps_index_by_ip_and_type
= ovsdb_idl_index_create2(ovnsb_idl_loop.idl,
&sbrec_encap_col_type, &sbrec_encap_col_ip);
ovsdb_idl_track_add_all(ovnsb_idl_loop.idl);
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl,
&sbrec_chassis_private_col_nb_cfg);
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl,
&sbrec_chassis_private_col_nb_cfg_timestamp);
/* Omit the timestamp columns of the MAC_Binding and FDB tables.
* ovn-controller doesn't need to react to changes in timestamp
* values (it does read them to implement aging). Therefore we
* can disable change tracking and alerting for these columns. */
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_mac_binding_col_timestamp);
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_fdb_col_timestamp);
/* Omit the external_ids column of all the tables except for -
* - DNS. pinctrl.c uses the external_ids column of DNS,
* which it shouldn't. This should be removed.
*
* - Datapath_binding - lflow.c is using this to check if the datapath
* is switch or not. This should be removed.
* */
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_sb_global_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_logical_flow_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_port_binding_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_ssl_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_gateway_chassis_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_ha_chassis_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_ha_chassis_group_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_advertised_route_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_learned_route_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_advertised_mac_binding_col_external_ids);
/* We don't want to monitor Connection table at all. So omit all the
* columns. */
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_external_ids);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_inactivity_probe);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_is_connected);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_max_backoff);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_other_config);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_read_only);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_role);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_status);
ovsdb_idl_omit(ovnsb_idl_loop.idl, &sbrec_connection_col_target);
/* Omit alerts to the Chassis external_ids column, the configuration
* from the local open_vswitch table has now being moved to the
* other_config column so we no longer need to monitor it */
ovsdb_idl_omit_alert(ovnsb_idl_loop.idl, &sbrec_chassis_col_external_ids);
/* Do not monitor Chassis_Private external_ids */
ovsdb_idl_omit(ovnsb_idl_loop.idl,
&sbrec_chassis_private_col_external_ids);
update_sb_monitors(ovnsb_idl_loop.idl, NULL, NULL, NULL, NULL, false);
stopwatch_create(CONTROLLER_LOOP_STOPWATCH_NAME, SW_MS);
stopwatch_create(OFCTRL_PUT_STOPWATCH_NAME, SW_MS);
stopwatch_create(PINCTRL_RUN_STOPWATCH_NAME, SW_MS);
stopwatch_create(PATCH_RUN_STOPWATCH_NAME, SW_MS);
stopwatch_create(CT_ZONE_COMMIT_STOPWATCH_NAME, SW_MS);
stopwatch_create(IF_STATUS_MGR_RUN_STOPWATCH_NAME, SW_MS);
stopwatch_create(IF_STATUS_MGR_UPDATE_STOPWATCH_NAME, SW_MS);
stopwatch_create(OFCTRL_SEQNO_RUN_STOPWATCH_NAME, SW_MS);
stopwatch_create(BFD_RUN_STOPWATCH_NAME, SW_MS);
stopwatch_create(VIF_PLUG_RUN_STOPWATCH_NAME, SW_MS);
inc_proc_ovn_controller_init(&ovnsb_idl_loop, &ovs_idl_loop,
sbrec_chassis_by_name,
sbrec_port_binding_by_name,
sbrec_port_binding_by_key,
sbrec_datapath_binding_by_key,
sbrec_mac_binding_by_lport_ip,
ovsrec_flow_sample_collector_set_by_id,
ovsrec_port_by_qos,
ovsrec_interface_by_name,
ovsrec_queue_by_external_ids);
struct ed_type_lflow_output *lflow_output_data =
engine_get_internal_data(&en_lflow_output);
struct ed_type_pflow_output *pflow_output_data =
engine_get_internal_data(&en_pflow_output);
struct ed_type_ct_zones *ct_zones_data =
engine_get_internal_data(&en_ct_zones);
struct ed_type_bfd_chassis *bfd_chassis_data =
engine_get_internal_data(&en_bfd_chassis);
struct ed_type_runtime_data *runtime_data =
engine_get_internal_data(&en_runtime_data);
struct ed_type_template_vars *template_vars_data =
engine_get_internal_data(&en_template_vars);
struct ed_type_lb_data *lb_data =
engine_get_internal_data(&en_lb_data);
struct mac_cache_data *mac_cache_data =
engine_get_internal_data(&en_mac_cache);
struct ed_type_neighbor_exchange *ne_data =
engine_get_internal_data(&en_neighbor_exchange);
struct ed_type_evpn_vtep_binding *eb_data =
engine_get_internal_data(&en_evpn_vtep_binding);
struct ed_type_evpn_fdb *efdb_data =
engine_get_internal_data(&en_evpn_fdb);
struct ed_type_evpn_arp *earp_data =
engine_get_internal_data(&en_evpn_arp);
ofctrl_init(&lflow_output_data->group_table,
&lflow_output_data->meter_table);
unixctl_command_register("group-table-list", "", 0, 0,
extend_table_list,
&lflow_output_data->group_table);
unixctl_command_register("meter-table-list", "", 0, 0,
extend_table_list,
&lflow_output_data->meter_table);
unixctl_command_register("ct-zone-list", "", 0, 0,
ct_zone_list,
&ct_zones_data->ctx.current);
unixctl_command_register("evpn/remote-vtep-list", "", 0, 0,
evpn_remote_vtep_list,
&ne_data->remote_vteps);
unixctl_command_register("evpn/vtep-binding-list", "", 0, 0,
evpn_vtep_binding_list,
&eb_data->bindings);
unixctl_command_register("evpn/vtep-multicast-group-list", "", 0, 0,
evpn_multicast_group_list,
&eb_data->multicast_groups);
unixctl_command_register("evpn/vtep-fdb-list", "", 0, 0,
evpn_fdb_list,
&efdb_data->fdbs);
unixctl_command_register("evpn/vtep-arp-list", "", 0, 0,
evpn_arp_list,
&earp_data->arps);
struct pending_pkt pending_pkt = { .conn = NULL };
unixctl_command_register("inject-pkt", "MICROFLOW", 1, 1, inject_pkt,
&pending_pkt);
unixctl_command_register("recompute", "[deprecated]", 0, 0,
engine_recompute_cmd,
NULL);
unixctl_command_register("lflow-cache/flush", "", 0, 0,
lflow_cache_flush_cmd,
&lflow_output_data->pd);
/* Keep deprecated 'flush-lflow-cache' command for now. */
unixctl_command_register("flush-lflow-cache", "[deprecated]", 0, 0,
lflow_cache_flush_cmd,
&lflow_output_data->pd);
unixctl_command_register("lflow-cache/show-stats", "", 0, 0,
lflow_cache_show_stats_cmd,
&lflow_output_data->pd);
bool reset_ovnsb_idl_min_index = false;
unixctl_command_register("sb-cluster-state-reset", "", 0, 0,
cluster_state_reset_cmd,
&reset_ovnsb_idl_min_index);
bool paused = false;
unixctl_command_register("debug/pause", "", 0, 0, debug_pause_execution,
&paused);
unixctl_command_register("debug/resume", "", 0, 0, debug_resume_execution,
&paused);
unixctl_command_register("debug/status", "", 0, 0, debug_status_execution,
&paused);
unsigned int delay_nb_cfg_report = 0;
unixctl_command_register("debug/delay-nb-cfg-report", "SECONDS", 1, 1,
debug_delay_nb_cfg_report, &delay_nb_cfg_report);
unixctl_command_register("debug/dump-local-bindings", "", 0, 0,
debug_dump_local_bindings,
&runtime_data->lbinding_data);
unixctl_command_register("debug/dump-local-datapaths", "", 0, 0,
debug_dump_local_datapaths,
&runtime_data->local_datapaths);
unixctl_command_register("debug/dump-related-ports", "", 0, 0,
debug_dump_related_lports,
&runtime_data->related_lports);
unixctl_command_register("debug/dump-lflow-conj-ids", "", 0, 0,
debug_dump_lflow_conj_ids,
&lflow_output_data->conj_ids);
unixctl_command_register("debug/dump-peer-ports", "", 0, 0,
debug_dump_peer_ports,
&runtime_data->local_datapaths);
unixctl_command_register("debug/dump-local-template-vars", "", 0, 0,
debug_dump_local_template_vars,
&template_vars_data->local_templates);
unixctl_command_register("debug/dump-mac-bindings", "", 0, 0,
debug_dump_local_mac_bindings,
&mac_cache_data->mac_bindings);
ovn_debug_commands_register();
unsigned int ovs_cond_seqno = UINT_MAX;
unsigned int ovnsb_cond_seqno = UINT_MAX;
unsigned int ovnsb_expected_cond_seqno = UINT_MAX;
struct controller_engine_ctx ctrl_engine_ctx = {
.lflow_cache = lflow_cache_create(),
.if_mgr = if_status_mgr_create(),
};
struct if_status_mgr *if_mgr = ctrl_engine_ctx.if_mgr;
struct shash vif_plug_deleted_iface_ids =
SHASH_INITIALIZER(&vif_plug_deleted_iface_ids);
struct shash vif_plug_changed_iface_ids =
SHASH_INITIALIZER(&vif_plug_changed_iface_ids);
char *ovn_version = ovn_get_internal_version();
VLOG_INFO("OVN internal version is : [%s]", ovn_version);
/* Main loop. */
int ovnsb_txn_status = 1;
bool sb_monitor_all = false;
struct tracked_acl_ids *tracked_acl_ids = NULL;
while (!exit_args.exiting) {
ovsrcu_quiesce_end();
memory_run();
if (memory_should_report()) {
struct simap usage = SIMAP_INITIALIZER(&usage);
lflow_cache_get_memory_usage(ctrl_engine_ctx.lflow_cache, &usage);
ofctrl_get_memory_usage(&usage);
if_status_mgr_get_memory_usage(if_mgr, &usage);
local_datapath_memory_usage(&usage);
ovsdb_idl_get_memory_usage(ovnsb_idl_loop.idl, &usage);
ovsdb_idl_get_memory_usage(ovs_idl_loop.idl, &usage);
memory_report(&usage);
simap_destroy(&usage);
}
/* If we're paused just run the unixctl server and skip most of the
* processing loop.
*/
if (paused) {
unixctl_server_run(unixctl);
unixctl_server_wait(unixctl);
goto loop_done;
}
engine_init_run();
struct ovsdb_idl_txn *ovs_idl_txn = ovsdb_idl_loop_run(&ovs_idl_loop);
unsigned int new_ovs_cond_seqno
= ovsdb_idl_get_condition_seqno(ovs_idl_loop.idl);
if (new_ovs_cond_seqno != ovs_cond_seqno) {
if (!new_ovs_cond_seqno) {
VLOG_INFO("OVS IDL reconnected, force recompute.");
engine_set_force_recompute();
}
ovs_cond_seqno = new_ovs_cond_seqno;
}
update_sb_db(ovs_idl_loop.idl, ovnsb_idl_loop.idl, &sb_monitor_all,
&reset_ovnsb_idl_min_index,
&ctrl_engine_ctx, &ovnsb_expected_cond_seqno);
update_ssl_config(ovsrec_ssl_table_get(ovs_idl_loop.idl));
struct ovsdb_idl_txn *ovnsb_idl_txn
= ovsdb_idl_loop_run(&ovnsb_idl_loop);
unsigned int new_ovnsb_cond_seqno
= ovsdb_idl_get_condition_seqno(ovnsb_idl_loop.idl);
if (ovnsb_idl_txn && ovnsb_txn_status == -1) {
ovsdb_idl_loop_next_cfg_inc(&ovnsb_idl_loop);
}
if (new_ovnsb_cond_seqno != ovnsb_cond_seqno) {
if (!new_ovnsb_cond_seqno) {
VLOG_INFO("OVNSB IDL reconnected, force recompute.");
engine_set_force_recompute();
}
ovnsb_cond_seqno = new_ovnsb_cond_seqno;
}
/* Check if we have received all initial dumps of the southbound
* based on the monitor condtions we set.
* If we have sb_monitor_all that means we have all data that we would
* ever need.
* In other cases we depend on engine runs. This is handled below. */
if (ovnsb_cond_seqno == ovnsb_expected_cond_seqno
&& ovnsb_expected_cond_seqno != UINT_MAX && sb_monitor_all) {
daemon_started_recently_ignore();
}
struct engine_context eng_ctx = {
.ovs_idl_txn = ovs_idl_txn,
.ovnsb_idl_txn = ovnsb_idl_txn,
.client_ctx = &ctrl_engine_ctx
};
engine_set_context(&eng_ctx);
bool northd_version_match =
check_northd_version(ovs_idl_loop.idl, ovnsb_idl_loop.idl,
ovn_version);
const struct ovsrec_bridge_table *bridge_table =
ovsrec_bridge_table_get(ovs_idl_loop.idl);
const struct ovsrec_open_vswitch_table *ovs_table =
ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);
const struct ovsrec_bridge *br_int = NULL;
const struct ovsrec_datapath *br_int_dp = NULL;
const struct ovsrec_open_vswitch *cfg =
ovsrec_open_vswitch_table_first(ovs_table);
process_br_int(ovs_idl_txn, bridge_table, ovs_table, &br_int,
ovsrec_server_has_datapath_table(ovs_idl_loop.idl)
? &br_int_dp
: NULL);
br_int_remote_update(&br_int_remote, br_int, ovs_table);
statctrl_update_swconn(br_int_remote.target,
br_int_remote.probe_interval);
pinctrl_update_swconn(br_int_remote.target,
br_int_remote.probe_interval);
/* Enable ACL matching for double tagged traffic. */
if (ovs_idl_txn && cfg) {
int vlan_limit = smap_get_int(
&cfg->other_config, "vlan-limit", -1);
if (vlan_limit != 0) {
ovsrec_open_vswitch_update_other_config_setkey(
cfg, "vlan-limit", "0");
}
}
static bool chassis_idx_stored = false;
if (ovs_idl_txn && !chassis_idx_stored) {
store_chassis_index_if_needed(ovs_table);
chassis_idx_stored = true;
}
if (ovsdb_idl_has_ever_connected(ovnsb_idl_loop.idl) &&
northd_version_match && cfg) {
/* Unconditionally remove all deleted lflows from the lflow
* cache.
*/
if (lflow_cache_is_enabled(ctrl_engine_ctx.lflow_cache)) {
lflow_handle_cached_flows(
ctrl_engine_ctx.lflow_cache,
sbrec_logical_flow_table_get(ovnsb_idl_loop.idl));
}
/* Contains the transport zones that this Chassis belongs to */
struct sset transport_zones = SSET_INITIALIZER(&transport_zones);
sset_from_delimited_string(&transport_zones,
get_transport_zones(ovsrec_open_vswitch_table_get(
ovs_idl_loop.idl)), ",");
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct sbrec_chassis *chassis = NULL;
const struct sbrec_chassis_private *chassis_private = NULL;
if (chassis_id) {
chassis = chassis_run(ovnsb_idl_txn, sbrec_chassis_by_name,
sbrec_chassis_private_by_name,
ovs_table, chassis_id,
br_int, &transport_zones,
&chassis_private,
sbrec_encaps_index_by_ip_and_type);
}
/* If any OVS feature support changed, force a full recompute.
* 'br_int_dp' is valid only if an OVS transaction is possible.
*/
if (ovs_idl_txn
&& ovs_feature_support_run(br_int_dp ?
&br_int_dp->capabilities : NULL,
br_int_remote.target,
br_int_remote.probe_interval)) {
VLOG_INFO("OVS feature set changed, force recompute.");
engine_set_force_recompute();
struct ed_type_lflow_output *lflow_out_data =
engine_get_internal_data(&en_lflow_output);
ovn_extend_table_reinit(&lflow_out_data->group_table,
ovs_feature_max_select_groups_get());
ovn_extend_table_reinit(&lflow_out_data->meter_table,
ovs_feature_max_meters_get());
}
if (br_int) {
ct_zones_data = engine_get_data(&en_ct_zones);
if (ofctrl_run(br_int_remote.target,
br_int_remote.probe_interval, ovs_table,
ct_zones_data ? &ct_zones_data->ctx.pending
: NULL,
tracked_acl_ids)) {
static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_INFO_RL(&rl, "OVS OpenFlow connection reconnected,"
"force recompute.");
engine_set_force_recompute();
}
const struct sbrec_sb_global *sbg =
sbrec_sb_global_first(ovnsb_idl_loop.idl);
if (chassis && sbg && ovs_feature_set_discovered()) {
encaps_run(ovs_idl_txn, ovnsb_idl_txn, br_int,
sbrec_chassis_table_get(ovnsb_idl_loop.idl),
chassis,
sbg,
ovs_table,
&transport_zones,
bridge_table);
struct ed_type_route_table_notify *rtn =
engine_get_internal_data(&en_route_table_notify);
rtn->changed = route_table_notify_run();
struct ed_type_host_if_monitor *hifm =
engine_get_internal_data(&en_host_if_monitor);
hifm->changed = host_if_monitor_run();
struct ed_type_neighbor_table_notify *ntn =
engine_get_internal_data(&en_neighbor_table_notify);
ntn->changed = neighbor_table_notify_run();
struct ed_type_route_exchange_status *rt_res =
engine_get_internal_data(&en_route_exchange_status);
rt_res->netlink_trigger_run =
!!route_exchange_status_run();
struct ed_type_neighbor_exchange_status *neigh_res =
engine_get_internal_data(&en_neighbor_exchange_status);
neigh_res->netlink_trigger_run =
!!neighbor_exchange_status_run();
stopwatch_start(CONTROLLER_LOOP_STOPWATCH_NAME,
time_msec());
/* Recompute is not allowed in following cases: */
/* 1. No ovnsb_idl_txn */
/* Even if there's no SB DB transaction available,
* try to run the engine so that we can handle any
* incremental changes that don't require a recompute.
* If a recompute is required, the engine will cancel,
* triggerring a full run in the next iteration.
*/
/* 2. ofctrl_has_backlog */
/* When there are in-flight messages pending to
* ovs-vswitchd, we should hold on recomputing so
* that the previous flow installations won't be
* delayed. However, we still want to try if
* recompute is not needed and we can quickly
* incrementally process the new changes, to avoid
* unnecessarily forced recomputes later on. This
* is because the OVSDB change tracker cannot
* preserve tracked changes across iterations. If
* change tracking is improved, we can simply skip
* this round of engine_run and continue processing
* acculated changes incrementally later when
* ofctrl_has_backlog() returns false. */
bool recompute_allowed = (ovnsb_idl_txn &&
!ofctrl_has_backlog());
engine_run(recompute_allowed);
tracked_acl_ids = engine_get_data(&en_acl_id);
stopwatch_stop(CONTROLLER_LOOP_STOPWATCH_NAME,
time_msec());
ct_zones_data = engine_get_data(&en_ct_zones);
bfd_chassis_data = engine_get_data(&en_bfd_chassis);
if (ovs_idl_txn) {
if (ct_zones_data) {
stopwatch_start(CT_ZONE_COMMIT_STOPWATCH_NAME,
time_msec());
ct_zones_commit(br_int, br_int_dp, ovs_idl_txn,
&ct_zones_data->ctx);
stopwatch_stop(CT_ZONE_COMMIT_STOPWATCH_NAME,
time_msec());
}
if (bfd_chassis_data) {
stopwatch_start(
BFD_RUN_STOPWATCH_NAME, time_msec());
bfd_run(
ovsrec_interface_table_get(ovs_idl_loop.idl),
br_int, &bfd_chassis_data->bfd_chassis,
chassis, sbrec_sb_global_table_get(
ovnsb_idl_loop.idl),
ovs_table
);
stopwatch_stop(
BFD_RUN_STOPWATCH_NAME, time_msec());
}
}
runtime_data = engine_get_data(&en_runtime_data);
if (runtime_data) {
stopwatch_start(PATCH_RUN_STOPWATCH_NAME, time_msec());
patch_run(ovs_idl_txn,
sbrec_port_binding_by_type,
ovsrec_bridge_table_get(ovs_idl_loop.idl),
ovsrec_open_vswitch_table_get(ovs_idl_loop.idl),
ovsrec_port_by_name,
br_int, chassis, &runtime_data->local_datapaths);
stopwatch_stop(PATCH_RUN_STOPWATCH_NAME, time_msec());
if (vif_plug_provider_has_providers() && ovs_idl_txn) {
struct vif_plug_ctx_in vif_plug_ctx_in = {
.ovs_idl_txn = ovs_idl_txn,
.sbrec_port_binding_by_name =
sbrec_port_binding_by_name,
.sbrec_port_binding_by_requested_chassis =
sbrec_port_binding_by_requested_chassis,
.ovsrec_port_by_interfaces =
ovsrec_port_by_interfaces,
.ovsrec_interface_by_name =
ovsrec_interface_by_name,
.ovs_table = ovs_table,
.br_int = br_int,
.iface_table =
ovsrec_interface_table_get(
ovs_idl_loop.idl),
.chassis_rec = chassis,
.local_bindings =
&runtime_data->lbinding_data.bindings,
};
struct vif_plug_ctx_out vif_plug_ctx_out = {
.deleted_iface_ids =
&vif_plug_deleted_iface_ids,
.changed_iface_ids =
&vif_plug_changed_iface_ids,
};
stopwatch_start(VIF_PLUG_RUN_STOPWATCH_NAME,
time_msec());
vif_plug_run(&vif_plug_ctx_in,
&vif_plug_ctx_out);
stopwatch_stop(VIF_PLUG_RUN_STOPWATCH_NAME,
time_msec());
}
stopwatch_start(PINCTRL_RUN_STOPWATCH_NAME,
time_msec());
pinctrl_update(ovnsb_idl_loop.idl);
pinctrl_run(ovnsb_idl_txn,
sbrec_datapath_binding_by_key,
sbrec_port_binding_by_key,
sbrec_port_binding_by_name,
sbrec_mac_binding_by_lport_ip,
sbrec_igmp_group,
sbrec_ip_multicast,
sbrec_fdb_by_dp_key_mac,
sbrec_controller_event_table_get(
ovnsb_idl_loop.idl),
sbrec_service_monitor_table_get(
ovnsb_idl_loop.idl),
sbrec_mac_binding_table_get(
ovnsb_idl_loop.idl),
sbrec_bfd_table_get(ovnsb_idl_loop.idl),
sbrec_ecmp_nexthop_table_get(
ovnsb_idl_loop.idl),
chassis,
&runtime_data->local_datapaths,
&runtime_data->local_active_ports_ipv6_pd,
&runtime_data->local_active_ports_ras,
ovsrec_open_vswitch_table_get(
ovs_idl_loop.idl),
ovnsb_idl_loop.cur_cfg);
stopwatch_stop(PINCTRL_RUN_STOPWATCH_NAME,
time_msec());
mirror_run(ovs_idl_txn,
ovsrec_mirror_table_get(ovs_idl_loop.idl),
sbrec_mirror_table_get(ovnsb_idl_loop.idl),
br_int,
&runtime_data->lbinding_data.bindings);
/* Updating monitor conditions if runtime data or
* logical datapath goups changed. */
if (engine_node_changed(&en_runtime_data)
|| engine_node_changed(&en_sb_logical_dp_group)) {
bool had_all_data = ovnsb_cond_seqno ==
ovnsb_expected_cond_seqno;
ovnsb_expected_cond_seqno =
update_sb_monitors(
ovnsb_idl_loop.idl, chassis,
&runtime_data->local_lports,
&runtime_data->lbinding_data.bindings,
&runtime_data->local_datapaths,
sb_monitor_all);
bool condition_changed = ovnsb_cond_seqno !=
ovnsb_expected_cond_seqno;
if (had_all_data && condition_changed) {
/* We limit the amount of condition updates
* that we treat as daemon_started_recently.
* This allows us to proceed even if there is
* a continuous reason for monitor updates. */
daemon_started_recently_countdown();
}
}
/* If there is no new expected seqno we have finished
* loading all needed data from southbound. We then
* need to run one more time since we might behave
* differently. */
if (daemon_started_recently()) {
bool condition_changed = ovnsb_cond_seqno !=
ovnsb_expected_cond_seqno;
if (!condition_changed) {
daemon_started_recently_ignore();
poll_immediate_wake();
}
}
if (ovs_idl_txn) {
update_qos(sbrec_port_binding_by_name, ovs_idl_txn,
ovsrec_port_by_qos,
ovsrec_qos_table_get(ovs_idl_loop.idl),
&runtime_data->qos_map,
ovs_table, bridge_table);
}
}
mac_cache_data = engine_get_data(&en_mac_cache);
if (mac_cache_data) {
statctrl_run(ovnsb_idl_txn, sbrec_port_binding_by_name,
chassis, mac_cache_data);
}
ofctrl_seqno_update_create(
ofctrl_seq_type_nb_cfg,
get_nb_cfg(sbrec_sb_global_table_get(
ovnsb_idl_loop.idl),
ovnsb_cond_seqno,
ovnsb_expected_cond_seqno));
struct local_binding_data *binding_data =
runtime_data ? &runtime_data->lbinding_data : NULL;
stopwatch_start(IF_STATUS_MGR_UPDATE_STOPWATCH_NAME,
time_msec());
if_status_mgr_update(if_mgr, binding_data, chassis,
ovsrec_interface_table_get(
ovs_idl_loop.idl),
sbrec_port_binding_table_get(
ovnsb_idl_loop.idl),
!ovs_idl_txn,
!ovnsb_idl_txn);
stopwatch_stop(IF_STATUS_MGR_UPDATE_STOPWATCH_NAME,
time_msec());
lflow_output_data = engine_get_data(&en_lflow_output);
pflow_output_data = engine_get_data(&en_pflow_output);
lb_data = engine_get_data(&en_lb_data);
if (lflow_output_data && pflow_output_data &&
ct_zones_data && lb_data) {
stopwatch_start(OFCTRL_PUT_STOPWATCH_NAME,
time_msec());
ofctrl_put(&lflow_output_data->flow_table,
&pflow_output_data->flow_table,
&ct_zones_data->ctx.pending,
&ct_zones_data->ctx.current,
&lb_data->removed_tuples,
runtime_data ?
&runtime_data->local_datapaths : NULL,
sbrec_meter_by_name,
sbrec_ecmp_nexthop_table_get(
ovnsb_idl_loop.idl),
ofctrl_seqno_get_req_cfg(),
engine_node_changed(&en_lflow_output),
engine_node_changed(&en_pflow_output),
tracked_acl_ids,
!daemon_started_recently());
stopwatch_stop(OFCTRL_PUT_STOPWATCH_NAME, time_msec());
}
stopwatch_start(OFCTRL_SEQNO_RUN_STOPWATCH_NAME,
time_msec());
ofctrl_seqno_run(ofctrl_get_cur_cfg());
stopwatch_stop(OFCTRL_SEQNO_RUN_STOPWATCH_NAME,
time_msec());
stopwatch_start(IF_STATUS_MGR_RUN_STOPWATCH_NAME,
time_msec());
if_status_mgr_run(if_mgr, binding_data, chassis,
ovsrec_interface_table_get(
ovs_idl_loop.idl),
sbrec_port_binding_table_get(
ovnsb_idl_loop.idl),
!ovnsb_idl_txn, !ovs_idl_txn);
stopwatch_stop(IF_STATUS_MGR_RUN_STOPWATCH_NAME,
time_msec());
}
}
if (!engine_has_run()) {
if (engine_need_run()) {
VLOG_DBG("engine did not run, force recompute next time: "
"br_int %p, chassis %p", br_int, chassis);
engine_set_force_recompute_immediate();
} else {
VLOG_DBG("engine did not run, and it was not needed"
" either: br_int %p, chassis %p",
br_int, chassis);
}
} else if (engine_canceled()) {
VLOG_DBG("engine was canceled, force recompute next time: "
"br_int %p, chassis %p", br_int, chassis);
engine_set_force_recompute_immediate();
} else {
engine_clear_force_recompute();
}
struct ed_type_northd_options *n_opts =
engine_get_data(&en_northd_options);
store_nb_cfg(ovnsb_idl_txn, ovs_idl_txn, chassis_private,
br_int, delay_nb_cfg_report,
n_opts ? n_opts->enable_ch_nb_cfg_update : true);
if (pending_pkt.conn) {
struct ed_type_addr_sets *as_data =
engine_get_data(&en_addr_sets);
struct ed_type_port_groups *pg_data =
engine_get_data(&en_port_groups);
struct ed_type_template_vars *tv_data =
engine_get_data(&en_template_vars);
if (br_int && chassis && as_data && pg_data && tv_data) {
char *error = ofctrl_inject_pkt(br_int, pending_pkt.flow_s,
&as_data->addr_sets, &pg_data->port_groups_cs_local,
&tv_data->local_templates);
if (error) {
unixctl_command_reply_error(pending_pkt.conn, error);
free(error);
} else {
unixctl_command_reply(pending_pkt.conn, NULL);
}
} else {
VLOG_DBG("Pending_pkt conn but br_int %p or chassis "
"%p not ready.", br_int, chassis);
unixctl_command_reply_error(pending_pkt.conn,
"ovn-controller not ready.");
}
pending_pkt.conn = NULL;
free(pending_pkt.flow_s);
}
sset_destroy(&transport_zones);
if (br_int) {
ofctrl_wait();
pinctrl_wait(ovnsb_idl_txn);
statctrl_wait(ovnsb_idl_txn);
}
binding_wait();
route_table_notify_wait();
host_if_monitor_wait();
neighbor_table_notify_wait();
}
unixctl_server_run(unixctl);
unixctl_server_wait(unixctl);
if (exit_args.exiting || pending_pkt.conn) {
poll_immediate_wake();
}
ovnsb_txn_status = ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
if (!ovnsb_txn_status) {
VLOG_INFO("OVNSB commit failed, force recompute next time.");
engine_set_force_recompute_immediate();
} else if (ovnsb_txn_status == 1) {
ovsdb_idl_loop_next_cfg_inc(&ovnsb_idl_loop);
} else if (ovnsb_txn_status == -1) {
/* The commit is still in progress */
} else {
OVS_NOT_REACHED();
}
int ovs_txn_status = ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop);
if (!ovs_txn_status) {
/* The transaction failed. */
vif_plug_clear_deleted(
&vif_plug_deleted_iface_ids);
vif_plug_clear_changed(
&vif_plug_changed_iface_ids);
} else if (ovs_txn_status == 1) {
/* The transaction committed successfully
* (or it did not change anything in the database). */
ct_zones_data = engine_get_data(&en_ct_zones);
if (ct_zones_data) {
ct_zones_pending_clear_commited(&ct_zones_data->ctx.pending);
}
vif_plug_finish_deleted(
&vif_plug_deleted_iface_ids);
vif_plug_finish_changed(
&vif_plug_changed_iface_ids);
} else if (ovs_txn_status == -1) {
/* The commit is still in progress */
} else {
OVS_NOT_REACHED();
}
ovsdb_idl_track_clear(ovnsb_idl_loop.idl);
ovsdb_idl_track_clear(ovs_idl_loop.idl);
lflow_cache_run(ctrl_engine_ctx.lflow_cache);
lflow_cache_wait(ctrl_engine_ctx.lflow_cache);
loop_done:
memory_wait();
ovsrcu_quiesce_start();
poll_block();
if (should_service_stop()) {
exit_args.exiting = true;
}
}
const struct ovsrec_open_vswitch_table *ovs_table =
ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);
bool restart = exit_args.restart || !get_ovn_cleanup_on_exit(ovs_table);
VLOG_INFO("Exiting ovn-controller, resource cleanup: %s",
restart ? "False (--restart)" : "True");
/* It's time to exit. Clean up the databases if we are not restarting */
if (!restart) {
bool done = !ovsdb_idl_has_ever_connected(ovnsb_idl_loop.idl);
while (!done) {
update_sb_db(ovs_idl_loop.idl, ovnsb_idl_loop.idl,
NULL, NULL, NULL, NULL);
update_ssl_config(ovsrec_ssl_table_get(ovs_idl_loop.idl));
struct ovsdb_idl_txn *ovs_idl_txn
= ovsdb_idl_loop_run(&ovs_idl_loop);
struct ovsdb_idl_txn *ovnsb_idl_txn
= ovsdb_idl_loop_run(&ovnsb_idl_loop);
const struct ovsrec_bridge_table *bridge_table
= ovsrec_bridge_table_get(ovs_idl_loop.idl);
const struct sbrec_port_binding_table *port_binding_table
= sbrec_port_binding_table_get(ovnsb_idl_loop.idl);
const struct ovsrec_bridge *br_int = get_br_int(bridge_table,
ovs_table);
const char *chassis_id = get_ovs_chassis_id(ovs_table);
const struct sbrec_chassis *chassis
= (chassis_id
? chassis_lookup_by_name(sbrec_chassis_by_name, chassis_id)
: NULL);
const struct sbrec_chassis_private *chassis_private
= (chassis_id
? chassis_private_lookup_by_name(
sbrec_chassis_private_by_name, chassis_id)
: NULL);
/* Run all of the cleanup functions, even if one of them returns
* false. We're done if all of them return true. */
done = binding_cleanup(ovnsb_idl_txn, port_binding_table, chassis);
done = chassis_cleanup(ovs_idl_txn, ovnsb_idl_txn, ovs_table,
chassis, chassis_private) && done;
done = encaps_cleanup(ovs_idl_txn, br_int) && done;
done = igmp_group_cleanup(ovnsb_idl_txn, sbrec_igmp_group, chassis)
&& done;
if (done) {
poll_immediate_wake();
}
ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
int ovs_txn_status = ovsdb_idl_loop_commit_and_wait(&ovs_idl_loop);
if (!ovs_txn_status) {
/* The transaction failed. */
vif_plug_clear_deleted(
&vif_plug_deleted_iface_ids);
vif_plug_clear_changed(
&vif_plug_changed_iface_ids);
} else if (ovs_txn_status == 1) {
/* The transaction committed successfully
* (or it did not change anything in the database). */
vif_plug_finish_deleted(
&vif_plug_deleted_iface_ids);
vif_plug_finish_changed(
&vif_plug_changed_iface_ids);
}
poll_block();
}
route_exchange_cleanup_vrfs();
}
/* The engine cleanup should happen only after threads have been
* destroyed and joined in case they are accessing engine data. */
pinctrl_destroy();
statctrl_destroy();
engine_set_context(NULL);
engine_cleanup();
free(ovn_version);
lflow_destroy();
ofctrl_destroy();
ofctrl_seqno_destroy();
binding_destroy();
patch_destroy();
mirror_destroy();
encaps_destroy();
if_status_mgr_destroy(if_mgr);
shash_destroy(&vif_plug_deleted_iface_ids);
shash_destroy(&vif_plug_changed_iface_ids);
vif_plug_provider_destroy_all();
ovsdb_idl_loop_destroy(&ovs_idl_loop);
ovsdb_idl_loop_destroy(&ovnsb_idl_loop);
ovs_feature_support_destroy();
free(br_int_remote.target);
free(ovs_remote);
free(file_system_id);
free(cli_system_id);
ovn_exit_args_finish(&exit_args);
unixctl_server_destroy(unixctl);
service_stop();
ovsrcu_exit();
dns_resolve_destroy();
route_exchange_destroy();
route_table_notify_destroy();
exit(retval);
}
static void
inc_proc_graph_dump(const char *end_node)
{
struct ovsdb_idl_loop ovs_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create_unconnected(&ovsrec_idl_class, true));
struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
ovsdb_idl_create_unconnected(&sbrec_idl_class, true));
inc_proc_ovn_controller_init(&ovnsb_idl_loop, &ovs_idl_loop,
NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL);
engine_dump_graph(end_node);
ovsdb_idl_loop_destroy(&ovs_idl_loop);
ovsdb_idl_loop_destroy(&ovnsb_idl_loop);
}
static char *
parse_options(int argc, char *argv[])
{
enum {
OPT_PEER_CA_CERT = UCHAR_MAX + 1,
OPT_BOOTSTRAP_CA_CERT,
VLOG_OPTION_ENUMS,
OVN_DAEMON_OPTION_ENUMS,
SSL_OPTION_ENUMS,
OPT_ENABLE_DUMMY_VIF_PLUG,
OPT_DUMP_INC_PROC_GRAPH,
};
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{"unixctl", required_argument, NULL, 'u'},
VLOG_LONG_OPTIONS,
OVN_DAEMON_LONG_OPTIONS,
STREAM_SSL_LONG_OPTIONS,
{"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
{"chassis", required_argument, NULL, 'n'},
{"enable-dummy-vif-plug", no_argument, NULL,
OPT_ENABLE_DUMMY_VIF_PLUG},
{"dump-inc-proc-graph", optional_argument, NULL,
OPT_DUMP_INC_PROC_GRAPH},
{NULL, 0, NULL, 0}
};
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c;
c = getopt_long(argc, argv, short_options, long_options, NULL);
if (c == -1) {
break;
}
switch (c) {
case 'h':
usage();
case 'V':
ovs_print_version(OFP15_VERSION, OFP15_VERSION);
printf("SB DB Schema %s\n", sbrec_get_db_version());
exit(EXIT_SUCCESS);
case 'u':
unixctl_path = optarg;
break;
VLOG_OPTION_HANDLERS
OVN_DAEMON_OPTION_HANDLERS
case 'p':
ssl_private_key_file = optarg;
break;
case 'c':
ssl_certificate_file = optarg;
break;
case 'C':
ssl_ca_cert_file = optarg;
break;
case OPT_SSL_PROTOCOLS:
stream_ssl_set_protocols(optarg);
break;
case OPT_SSL_CIPHERS:
stream_ssl_set_ciphers(optarg);
break;
case OPT_SSL_CIPHERSUITES:
stream_ssl_set_ciphersuites(optarg);
break;
case OPT_SSL_SERVER_NAME:
stream_ssl_set_server_name(optarg);
break;
case OPT_PEER_CA_CERT:
stream_ssl_set_peer_ca_cert_file(optarg);
break;
case OPT_BOOTSTRAP_CA_CERT:
stream_ssl_set_ca_cert_file(optarg, true);
break;
case OPT_ENABLE_DUMMY_VIF_PLUG:
vif_plug_dummy_enable();
break;
/* --dump-inc-proc-graph[=<i-p-node>]: Whether to dump the I-P engine
* graph representation in DOT format to stdout. Optionally only up
* to <i-p-node>.
*/
case OPT_DUMP_INC_PROC_GRAPH:
inc_proc_graph_dump(optarg);
exit(EXIT_SUCCESS);
case 'n':
free(cli_system_id);
cli_system_id = xstrdup(optarg);
break;
case '?':
exit(EXIT_FAILURE);
default:
abort();
}
}
free(short_options);
argc -= optind;
argv += optind;
char *ovs_remote;
if (argc == 0) {
ovs_remote = xasprintf("unix:%s/db.sock", ovs_rundir());
} else if (argc == 1) {
ovs_remote = xstrdup(argv[0]);
} else {
VLOG_FATAL("exactly zero or one non-option argument required; "
"use --help for usage");
}
return ovs_remote;
}
static void
usage(void)
{
printf("%s: OVN controller\n"
"usage %s [OPTIONS] [OVS-DATABASE]\n"
"where OVS-DATABASE is a socket on which the OVS OVSDB server is listening.\n",
program_name, program_name);
stream_usage("OVS-DATABASE", true, false, true);
daemon_usage();
vlog_usage();
printf("\nOther options:\n"
" -u, --unixctl=SOCKET set control socket name\n"
" -n custom chassis name\n"
" -h, --help display this help message\n"
" -V, --version display version information\n");
exit(EXIT_SUCCESS);
}
static void
ct_zone_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *ct_zones_)
{
struct shash *ct_zones = ct_zones_;
struct ds ds = DS_EMPTY_INITIALIZER;
struct shash_node *node;
SHASH_FOR_EACH (node, ct_zones) {
struct ct_zone *ct_zone = node->data;
ds_put_format(&ds, "%s %d\n", node->name, ct_zone->zone);
}
unixctl_command_reply(conn, ds_cstr(&ds));
ds_destroy(&ds);
}
static void
extend_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *extend_table_)
{
struct ovn_extend_table *extend_table = extend_table_;
struct ds ds = DS_EMPTY_INITIALIZER;
struct simap items = SIMAP_INITIALIZER(&items);
struct ovn_extend_table_info *item;
HMAP_FOR_EACH (item, hmap_node, &extend_table->existing) {
simap_put(&items, item->name, item->table_id);
}
const struct simap_node **nodes = simap_sort(&items);
size_t n_nodes = simap_count(&items);
for (size_t i = 0; i < n_nodes; i++) {
const struct simap_node *node = nodes[i];
ds_put_format(&ds, "%s: %d\n", node->name, node->data);
}
free(nodes);
simap_destroy(&items);
unixctl_command_reply(conn, ds_cstr(&ds));
ds_destroy(&ds);
}
static void
inject_pkt(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[], void *pending_pkt_)
{
struct pending_pkt *pending_pkt = pending_pkt_;
if (pending_pkt->conn) {
unixctl_command_reply_error(conn, "already pending packet injection");
return;
}
pending_pkt->conn = conn;
pending_pkt->flow_s = xstrdup(argv[1]);
}
static void
engine_recompute_cmd(struct unixctl_conn *conn OVS_UNUSED, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *arg OVS_UNUSED)
{
engine_trigger_recompute();
unixctl_command_reply(conn, NULL);
}
static void
lflow_cache_flush_cmd(struct unixctl_conn *conn OVS_UNUSED,
int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
void *arg_)
{
VLOG_INFO("User triggered lflow cache flush.");
struct lflow_output_persistent_data *fo_pd = arg_;
lflow_cache_flush(fo_pd->lflow_cache);
engine_set_force_recompute_immediate();
unixctl_command_reply(conn, NULL);
}
static void
lflow_cache_show_stats_cmd(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *arg_)
{
struct lflow_output_persistent_data *fo_pd = arg_;
struct lflow_cache *lc = fo_pd->lflow_cache;
struct ds ds = DS_EMPTY_INITIALIZER;
lflow_cache_get_stats(lc, &ds);
unixctl_command_reply(conn, ds_cstr(&ds));
ds_destroy(&ds);
}
static void
cluster_state_reset_cmd(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *idl_reset_)
{
bool *idl_reset = idl_reset_;
*idl_reset = true;
poll_immediate_wake();
unixctl_command_reply(conn, NULL);
}
static void
debug_pause_execution(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *paused_)
{
bool *paused = paused_;
VLOG_INFO("User triggered execution pause.");
*paused = true;
unixctl_command_reply(conn, NULL);
}
static void
debug_resume_execution(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *paused_)
{
bool *paused = paused_;
VLOG_INFO("User triggered execution resume.");
*paused = false;
poll_immediate_wake();
unixctl_command_reply(conn, NULL);
}
static void
debug_status_execution(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *paused_)
{
bool *paused = paused_;
if (*paused) {
unixctl_command_reply(conn, "paused");
} else {
unixctl_command_reply(conn, "running");
}
}
static void
debug_delay_nb_cfg_report(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[], void *delay_)
{
unsigned int *delay = delay_;
if (!str_to_uint(argv[1], 10, delay)) {
unixctl_command_reply_error(conn, "unsigned integer required");
return;
}
char *msg;
if (*delay) {
msg = xasprintf("delay nb_cfg report for %u seconds.", *delay);
unixctl_command_reply(conn, msg);
free(msg);
} else {
unixctl_command_reply(conn, "no delay for nb_cfg report.");
}
}
static void
debug_dump_local_bindings(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *local_bindings)
{
struct ds binding_data = DS_EMPTY_INITIALIZER;
binding_dump_local_bindings(local_bindings, &binding_data);
unixctl_command_reply(conn, ds_cstr(&binding_data));
ds_destroy(&binding_data);
}
static void
debug_dump_local_datapaths(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED,
void *local_datapaths)
{
struct ds local_dps_data = DS_EMPTY_INITIALIZER;
binding_dump_local_datapaths(local_datapaths, &local_dps_data);
unixctl_command_reply(conn, ds_cstr(&local_dps_data));
ds_destroy(&local_dps_data);
}
static void
debug_dump_related_lports(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *related_lports)
{
struct ds data = DS_EMPTY_INITIALIZER;
binding_dump_related_lports(related_lports, &data);
unixctl_command_reply(conn, ds_cstr(&data));
ds_destroy(&data);
}
static void
debug_dump_peer_ports(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *local_datapaths)
{
struct ds peer_ports = DS_EMPTY_INITIALIZER;
local_data_dump_peer_ports(local_datapaths, &peer_ports);
unixctl_command_reply(conn, ds_cstr(&peer_ports));
ds_destroy(&peer_ports);
}
static void
debug_dump_lflow_conj_ids(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *conj_ids)
{
struct ds conj_ids_dump = DS_EMPTY_INITIALIZER;
lflow_conj_ids_dump(conj_ids, &conj_ids_dump);
unixctl_command_reply(conn, ds_cstr(&conj_ids_dump));
ds_destroy(&conj_ids_dump);
}
static void
debug_dump_local_template_vars(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED, void *local_vars)
{
struct ds tv_str = DS_EMPTY_INITIALIZER;
ds_put_cstr(&tv_str, "Local template vars:\n");
local_templates_to_string(local_vars, &tv_str);
unixctl_command_reply(conn, ds_cstr(&tv_str));
ds_destroy(&tv_str);
}
static void
debug_dump_local_mac_bindings(struct unixctl_conn *conn, int argc OVS_UNUSED,
const char *argv[] OVS_UNUSED,
void *mac_bindings)
{
struct ds mb_str = DS_EMPTY_INITIALIZER;
ds_put_cstr(&mb_str, "Local MAC bindings:\n");
mac_bindings_to_string(mac_bindings, &mb_str);
unixctl_command_reply(conn, ds_cstr(&mb_str));
ds_destroy(&mb_str);
}
|