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
|
# Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
# Copyright (C) 2015 YAMAMOTO Takashi <yamamoto at valinux co jp>
#
# 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.
import struct
from os_ken import utils
from os_ken.lib import type_desc
from os_ken.ofproto import nicira_ext
from os_ken.ofproto import ofproto_common
from os_ken.lib.pack_utils import msg_pack_into
from os_ken.ofproto.ofproto_parser import StringifyMixin
def generate(ofp_name, ofpp_name):
import sys
ofp = sys.modules[ofp_name]
ofpp = sys.modules[ofpp_name]
class _NXFlowSpec(StringifyMixin):
_hdr_fmt_str = '!H' # 2 bit 0s, 1 bit src, 2 bit dst, 11 bit n_bits
_dst_type = None
_subclasses = {}
_TYPE = {
'nx-flow-spec-field': [
'src',
'dst',
]
}
def __init__(self, src, dst, n_bits):
self.src = src
self.dst = dst
self.n_bits = n_bits
@classmethod
def register(cls, subcls):
assert issubclass(subcls, cls)
assert subcls._dst_type not in cls._subclasses
cls._subclasses[subcls._dst_type] = subcls
@classmethod
def parse(cls, buf):
(hdr,) = struct.unpack_from(cls._hdr_fmt_str, buf, 0)
rest = buf[struct.calcsize(cls._hdr_fmt_str):]
if hdr == 0:
return None, rest # all-0 header is no-op for padding
src_type = (hdr >> 13) & 0x1
dst_type = (hdr >> 11) & 0x3
n_bits = hdr & 0x3ff
subcls = cls._subclasses[dst_type]
if src_type == 0: # subfield
src = cls._parse_subfield(rest)
rest = rest[6:]
elif src_type == 1: # immediate
src_len = (n_bits + 15) // 16 * 2
src_bin = rest[:src_len]
src = type_desc.IntDescr(size=src_len).to_user(src_bin)
rest = rest[src_len:]
if dst_type == 0: # match
dst = cls._parse_subfield(rest)
rest = rest[6:]
elif dst_type == 1: # load
dst = cls._parse_subfield(rest)
rest = rest[6:]
elif dst_type == 2: # output
dst = '' # empty
return subcls(src=src, dst=dst, n_bits=n_bits), rest
def serialize(self):
buf = bytearray()
if isinstance(self.src, tuple):
src_type = 0 # subfield
else:
src_type = 1 # immediate
# header
val = (src_type << 13) | (self._dst_type << 11) | self.n_bits
msg_pack_into(self._hdr_fmt_str, buf, 0, val)
# src
if src_type == 0: # subfield
buf += self._serialize_subfield(self.src)
elif src_type == 1: # immediate
src_len = (self.n_bits + 15) // 16 * 2
buf += type_desc.IntDescr(size=src_len).from_user(self.src)
# dst
if self._dst_type == 0: # match
buf += self._serialize_subfield(self.dst)
elif self._dst_type == 1: # load
buf += self._serialize_subfield(self.dst)
elif self._dst_type == 2: # output
pass # empty
return buf
@staticmethod
def _parse_subfield(buf):
(n, len) = ofp.oxm_parse_header(buf, 0)
assert len == 4 # only 4-bytes NXM/OXM are defined
field = ofp.oxm_to_user_header(n)
rest = buf[len:]
(ofs,) = struct.unpack_from('!H', rest, 0)
return (field, ofs)
@staticmethod
def _serialize_subfield(subfield):
(field, ofs) = subfield
buf = bytearray()
n = ofp.oxm_from_user_header(field)
ofp.oxm_serialize_header(n, buf, 0)
assert len(buf) == 4 # only 4-bytes NXM/OXM are defined
msg_pack_into('!H', buf, 4, ofs)
return buf
class NXFlowSpecMatch(_NXFlowSpec):
"""
Specification for adding match criterion
This class is used by ``NXActionLearn``.
For the usage of this class, please refer to ``NXActionLearn``.
================ ======================================================
Attribute Description
================ ======================================================
src OXM/NXM header and Start bit for source field
dst OXM/NXM header and Start bit for destination field
n_bits The number of bits from the start bit
================ ======================================================
"""
# Add a match criteria
# an example of the corresponding ovs-ofctl syntax:
# NXM_OF_VLAN_TCI[0..11]
_dst_type = 0
class NXFlowSpecLoad(_NXFlowSpec):
"""
Add NXAST_REG_LOAD actions
This class is used by ``NXActionLearn``.
For the usage of this class, please refer to ``NXActionLearn``.
================ ======================================================
Attribute Description
================ ======================================================
src OXM/NXM header and Start bit for source field
dst OXM/NXM header and Start bit for destination field
n_bits The number of bits from the start bit
================ ======================================================
"""
# Add NXAST_REG_LOAD actions
# an example of the corresponding ovs-ofctl syntax:
# NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[]
_dst_type = 1
class NXFlowSpecOutput(_NXFlowSpec):
"""
Add an OFPAT_OUTPUT action
This class is used by ``NXActionLearn``.
For the usage of this class, please refer to ``NXActionLearn``.
================ ======================================================
Attribute Description
================ ======================================================
src OXM/NXM header and Start bit for source field
dst Must be ''
n_bits The number of bits from the start bit
================ ======================================================
"""
# Add an OFPAT_OUTPUT action
# an example of the corresponding ovs-ofctl syntax:
# output:NXM_OF_IN_PORT[]
_dst_type = 2
def __init__(self, src, n_bits, dst=''):
assert dst == ''
super(NXFlowSpecOutput, self).__init__(src=src, dst=dst,
n_bits=n_bits)
class NXAction(ofpp.OFPActionExperimenter):
_fmt_str = '!H' # subtype
_subtypes = {}
_experimenter = ofproto_common.NX_EXPERIMENTER_ID
def __init__(self):
super(NXAction, self).__init__(self._experimenter)
self.subtype = self._subtype
@classmethod
def parse(cls, buf):
fmt_str = NXAction._fmt_str
(subtype,) = struct.unpack_from(fmt_str, buf, 0)
subtype_cls = cls._subtypes.get(subtype)
rest = buf[struct.calcsize(fmt_str):]
if subtype_cls is None:
return NXActionUnknown(subtype, rest)
return subtype_cls.parser(rest)
def serialize(self, buf, offset):
data = self.serialize_body()
payload_offset = (
ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE +
struct.calcsize(NXAction._fmt_str)
)
self.len = utils.round_up(payload_offset + len(data), 8)
super(NXAction, self).serialize(buf, offset)
msg_pack_into(NXAction._fmt_str,
buf,
offset + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE,
self.subtype)
buf += data
@classmethod
def register(cls, subtype_cls):
assert subtype_cls._subtype is not cls._subtypes
cls._subtypes[subtype_cls._subtype] = subtype_cls
class NXActionUnknown(NXAction):
def __init__(self, subtype, data=None,
type_=None, len_=None, experimenter=None):
self._subtype = subtype
super(NXActionUnknown, self).__init__()
self.data = data
@classmethod
def parser(cls, buf):
return cls(data=buf)
def serialize_body(self):
# fixup
return bytearray() if self.data is None else self.data
# For OpenFlow1.0 only
class NXActionSetQueue(NXAction):
r"""
Set queue action
This action sets the queue that should be used to queue
when packets are output.
And equivalent to the followings action of ovs-ofctl command.
..
set_queue:queue
..
+-------------------------+
| **set_queue**\:\ *queue*|
+-------------------------+
================ ======================================================
Attribute Description
================ ======================================================
queue_id Queue ID for the packets
================ ======================================================
.. note::
This actions is supported by
``OFPActionSetQueue``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionSetQueue(queue_id=10)]
"""
_subtype = nicira_ext.NXAST_SET_QUEUE
# queue_id
_fmt_str = '!2xI'
def __init__(self, queue_id,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionSetQueue, self).__init__()
self.queue_id = queue_id
@classmethod
def parser(cls, buf):
(queue_id,) = struct.unpack_from(cls._fmt_str, buf, 0)
return cls(queue_id)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0, self.queue_id)
return data
class NXActionPopQueue(NXAction):
"""
Pop queue action
This action restors the queue to the value it was before any
set_queue actions were applied.
And equivalent to the followings action of ovs-ofctl command.
..
pop_queue
..
+---------------+
| **pop_queue** |
+---------------+
Example::
actions += [parser.NXActionPopQueue()]
"""
_subtype = nicira_ext.NXAST_POP_QUEUE
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionPopQueue, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
class NXActionRegLoad(NXAction):
r"""
Load literal value action
This action loads a literal value into a field or part of a field.
And equivalent to the followings action of ovs-ofctl command.
..
load:value->dst[start..end]
..
+-----------------------------------------------------------------+
| **load**\:\ *value*\->\ *dst*\ **[**\ *start*\..\ *end*\ **]** |
+-----------------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``
dst OXM/NXM header for destination field
value OXM/NXM value to be loaded
================ ======================================================
Example::
actions += [parser.NXActionRegLoad(
ofs_nbits=nicira_ext.ofs_nbits(4, 31),
dst="eth_dst",
value=0x112233)]
"""
_subtype = nicira_ext.NXAST_REG_LOAD
_fmt_str = '!HIQ' # ofs_nbits, dst, value
_TYPE = {
'ascii': [
'dst',
]
}
def __init__(self, ofs_nbits, dst, value,
type_=None, len_=None, experimenter=None,
subtype=None):
super(NXActionRegLoad, self).__init__()
self.ofs_nbits = ofs_nbits
self.dst = dst
self.value = value
@classmethod
def parser(cls, buf):
(ofs_nbits, dst, value,) = struct.unpack_from(
cls._fmt_str, buf, 0)
# Right-shift instead of using oxm_parse_header for simplicity...
dst_name = ofp.oxm_to_user_header(dst >> 9)
return cls(ofs_nbits, dst_name, value)
def serialize_body(self):
hdr_data = bytearray()
n = ofp.oxm_from_user_header(self.dst)
ofp.oxm_serialize_header(n, hdr_data, 0)
(dst_num,) = struct.unpack_from('!I', bytes(hdr_data), 0)
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.ofs_nbits, dst_num, self.value)
return data
class NXActionRegLoad2(NXAction):
r"""
Load literal value action
This action loads a literal value into a field or part of a field.
And equivalent to the followings action of ovs-ofctl command.
..
set_field:value[/mask]->dst
..
+------------------------------------------------------------+
| **set_field**\:\ *value*\ **[**\/\ *mask*\ **]**\->\ *dst* |
+------------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
value OXM/NXM value to be loaded
mask Mask for destination field
dst OXM/NXM header for destination field
================ ======================================================
Example::
actions += [parser.NXActionRegLoad2(dst="tun_ipv4_src",
value="192.168.10.0",
mask="255.255.255.0")]
"""
_subtype = nicira_ext.NXAST_REG_LOAD2
_TYPE = {
'ascii': [
'dst',
'value',
]
}
def __init__(self, dst, value, mask=None,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionRegLoad2, self).__init__()
self.dst = dst
self.value = value
self.mask = mask
@classmethod
def parser(cls, buf):
(n, uv, mask, _len) = ofp.oxm_parse(buf, 0)
dst, value = ofp.oxm_to_user(n, uv, mask)
if isinstance(value, (tuple, list)):
return cls(dst, value[0], value[1])
else:
return cls(dst, value, None)
def serialize_body(self):
data = bytearray()
if self.mask is None:
value = self.value
else:
value = (self.value, self.mask)
self._TYPE['ascii'].append('mask')
n, value, mask = ofp.oxm_from_user(self.dst, value)
len_ = ofp.oxm_serialize(n, value, mask, data, 0)
msg_pack_into("!%dx" % (14 - len_), data, len_)
return data
class NXActionNote(NXAction):
r"""
Note action
This action does nothing at all.
And equivalent to the followings action of ovs-ofctl command.
..
note:[hh]..
..
+-----------------------------------+
| **note**\:\ **[**\ *hh*\ **]**\.. |
+-----------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
note A list of integer type values
================ ======================================================
Example::
actions += [parser.NXActionNote(note=[0xaa,0xbb,0xcc,0xdd])]
"""
_subtype = nicira_ext.NXAST_NOTE
# note
_fmt_str = '!%dB'
# set the integer array in a note
def __init__(self,
note,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionNote, self).__init__()
self.note = note
@classmethod
def parser(cls, buf):
note = struct.unpack_from(
cls._fmt_str % len(buf), buf, 0)
return cls(list(note))
def serialize_body(self):
assert isinstance(self.note, (tuple, list))
for n in self.note:
assert isinstance(n, int)
pad = (len(self.note) + nicira_ext.NX_ACTION_HEADER_0_SIZE) % 8
if pad:
self.note += [0x0 for i in range(8 - pad)]
note_len = len(self.note)
data = bytearray()
msg_pack_into(self._fmt_str % note_len, data, 0,
*self.note)
return data
class _NXActionSetTunnelBase(NXAction):
# _subtype, _fmt_str must be attributes of subclass.
def __init__(self,
tun_id,
type_=None, len_=None, experimenter=None, subtype=None):
super(_NXActionSetTunnelBase, self).__init__()
self.tun_id = tun_id
@classmethod
def parser(cls, buf):
(tun_id,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(tun_id)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.tun_id)
return data
class NXActionSetTunnel(_NXActionSetTunnelBase):
r"""
Set Tunnel action
This action sets the identifier (such as GRE) to the specified id.
And equivalent to the followings action of ovs-ofctl command.
.. note::
This actions is supported by
``OFPActionSetField``
in OpenFlow1.2 or later.
..
set_tunnel:id
..
+------------------------+
| **set_tunnel**\:\ *id* |
+------------------------+
================ ======================================================
Attribute Description
================ ======================================================
tun_id Tunnel ID(32bits)
================ ======================================================
Example::
actions += [parser.NXActionSetTunnel(tun_id=0xa)]
"""
_subtype = nicira_ext.NXAST_SET_TUNNEL
# tun_id
_fmt_str = '!2xI'
class NXActionSetTunnel64(_NXActionSetTunnelBase):
r"""
Set Tunnel action
This action outputs to a port that encapsulates
the packet in a tunnel.
And equivalent to the followings action of ovs-ofctl command.
.. note::
This actions is supported by
``OFPActionSetField``
in OpenFlow1.2 or later.
..
set_tunnel64:id
..
+--------------------------+
| **set_tunnel64**\:\ *id* |
+--------------------------+
================ ======================================================
Attribute Description
================ ======================================================
tun_id Tunnel ID(64bits)
================ ======================================================
Example::
actions += [parser.NXActionSetTunnel64(tun_id=0xa)]
"""
_subtype = nicira_ext.NXAST_SET_TUNNEL64
# tun_id
_fmt_str = '!6xQ'
class NXActionRegMove(NXAction):
r"""
Move register action
This action copies the src to dst.
And equivalent to the followings action of ovs-ofctl command.
..
move:src[start..end]->dst[start..end]
..
+--------------------------------------------------------+
| **move**\:\ *src*\ **[**\ *start*\..\ *end*\ **]**\->\ |
| *dst*\ **[**\ *start*\..\ *end* \ **]** |
+--------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
src_field OXM/NXM header for source field
dst_field OXM/NXM header for destination field
n_bits Number of bits
src_ofs Starting bit offset in source
dst_ofs Starting bit offset in destination
================ ======================================================
.. CAUTION::
**src_start**\ and \ **src_end**\ difference and \ **dst_start**\
and \ **dst_end**\ difference must be the same.
Example::
actions += [parser.NXActionRegMove(src_field="reg0",
dst_field="reg1",
n_bits=5,
src_ofs=0
dst_ofs=10)]
"""
_subtype = nicira_ext.NXAST_REG_MOVE
_fmt_str = '!HHH' # n_bits, src_ofs, dst_ofs
# Followed by OXM fields (src, dst) and padding to 8 bytes boundary
_TYPE = {
'ascii': [
'src_field',
'dst_field',
]
}
def __init__(self, src_field, dst_field, n_bits, src_ofs=0, dst_ofs=0,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionRegMove, self).__init__()
self.n_bits = n_bits
self.src_ofs = src_ofs
self.dst_ofs = dst_ofs
self.src_field = src_field
self.dst_field = dst_field
@classmethod
def parser(cls, buf):
(n_bits, src_ofs, dst_ofs,) = struct.unpack_from(
cls._fmt_str, buf, 0)
rest = buf[struct.calcsize(NXActionRegMove._fmt_str):]
# src field
(n, len) = ofp.oxm_parse_header(rest, 0)
src_field = ofp.oxm_to_user_header(n)
rest = rest[len:]
# dst field
(n, len) = ofp.oxm_parse_header(rest, 0)
dst_field = ofp.oxm_to_user_header(n)
rest = rest[len:]
# ignore padding
return cls(src_field, dst_field=dst_field, n_bits=n_bits,
src_ofs=src_ofs, dst_ofs=dst_ofs)
def serialize_body(self):
# fixup
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.n_bits, self.src_ofs, self.dst_ofs)
# src field
n = ofp.oxm_from_user_header(self.src_field)
ofp.oxm_serialize_header(n, data, len(data))
# dst field
n = ofp.oxm_from_user_header(self.dst_field)
ofp.oxm_serialize_header(n, data, len(data))
return data
class NXActionResubmit(NXAction):
r"""
Resubmit action
This action searches one of the switch's flow tables.
And equivalent to the followings action of ovs-ofctl command.
..
resubmit:port
..
+------------------------+
| **resubmit**\:\ *port* |
+------------------------+
================ ======================================================
Attribute Description
================ ======================================================
in_port New in_port for checking flow table
================ ======================================================
Example::
actions += [parser.NXActionResubmit(in_port=8080)]
"""
_subtype = nicira_ext.NXAST_RESUBMIT
# in_port
_fmt_str = '!H4x'
def __init__(self,
in_port=0xfff8,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionResubmit, self).__init__()
self.in_port = in_port
@classmethod
def parser(cls, buf):
(in_port,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(in_port)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.in_port)
return data
class NXActionResubmitTable(NXAction):
r"""
Resubmit action
This action searches one of the switch's flow tables.
And equivalent to the followings action of ovs-ofctl command.
..
resubmit([port],[table])
..
+------------------------------------------------+
| **resubmit(**\[\ *port*\]\,[\ *table*\]\ **)** |
+------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
in_port New in_port for checking flow table
table_id Checking flow tables
================ ======================================================
Example::
actions += [parser.NXActionResubmitTable(in_port=8080,
table_id=10)]
"""
_subtype = nicira_ext.NXAST_RESUBMIT_TABLE
# in_port, table_id
_fmt_str = '!HB3x'
def __init__(self,
in_port=0xfff8,
table_id=0xff,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionResubmitTable, self).__init__()
self.in_port = in_port
self.table_id = table_id
@classmethod
def parser(cls, buf):
(in_port,
table_id) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(in_port, table_id)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.in_port, self.table_id)
return data
class NXActionOutputReg(NXAction):
r"""
Add output action
This action outputs the packet to the OpenFlow port number read from
src.
And equivalent to the followings action of ovs-ofctl command.
..
output:src[start...end]
..
+-------------------------------------------------------+
| **output**\:\ *src*\ **[**\ *start*\...\ *end*\ **]** |
+-------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``
src OXM/NXM header for source field
max_len Max length to send to controller
================ ======================================================
Example::
actions += [parser.NXActionOutputReg(
ofs_nbits=nicira_ext.ofs_nbits(4, 31),
src="reg0",
max_len=1024)]
"""
_subtype = nicira_ext.NXAST_OUTPUT_REG
# ofs_nbits, src, max_len
_fmt_str = '!H4sH6x'
_TYPE = {
'ascii': [
'src',
]
}
def __init__(self,
ofs_nbits,
src,
max_len,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionOutputReg, self).__init__()
self.ofs_nbits = ofs_nbits
self.src = src
self.max_len = max_len
@classmethod
def parser(cls, buf):
(ofs_nbits, oxm_data, max_len) = struct.unpack_from(
cls._fmt_str, buf, 0)
(n, len_) = ofp.oxm_parse_header(oxm_data, 0)
src = ofp.oxm_to_user_header(n)
return cls(ofs_nbits,
src,
max_len)
def serialize_body(self):
data = bytearray()
src = bytearray()
oxm = ofp.oxm_from_user_header(self.src)
ofp.oxm_serialize_header(oxm, src, 0),
msg_pack_into(self._fmt_str, data, 0,
self.ofs_nbits,
bytes(src),
self.max_len)
return data
class NXActionOutputReg2(NXAction):
r"""
Add output action
This action outputs the packet to the OpenFlow port number read from
src.
And equivalent to the followings action of ovs-ofctl command.
..
output:src[start...end]
..
+-------------------------------------------------------+
| **output**\:\ *src*\ **[**\ *start*\...\ *end*\ **]** |
+-------------------------------------------------------+
.. NOTE::
Like the ``NXActionOutputReg`` but organized so
that there is room for a 64-bit experimenter OXM as 'src'.
================ ======================================================
Attribute Description
================ ======================================================
ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``
src OXM/NXM header for source field
max_len Max length to send to controller
================ ======================================================
Example::
actions += [parser.NXActionOutputReg2(
ofs_nbits=nicira_ext.ofs_nbits(4, 31),
src="reg0",
max_len=1024)]
"""
_subtype = nicira_ext.NXAST_OUTPUT_REG2
# ofs_nbits, src, max_len
_fmt_str = '!HH4s'
_TYPE = {
'ascii': [
'src',
]
}
def __init__(self,
ofs_nbits,
src,
max_len,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionOutputReg2, self).__init__()
self.ofs_nbits = ofs_nbits
self.src = src
self.max_len = max_len
@classmethod
def parser(cls, buf):
(ofs_nbits,
max_len,
oxm_data) = struct.unpack_from(
cls._fmt_str, buf, 0)
(n, len_) = ofp.oxm_parse_header(oxm_data, 0)
src = ofp.oxm_to_user_header(n)
return cls(ofs_nbits,
src,
max_len)
def serialize_body(self):
data = bytearray()
oxm_data = bytearray()
oxm = ofp.oxm_from_user_header(self.src)
ofp.oxm_serialize_header(oxm, oxm_data, 0),
msg_pack_into(self._fmt_str, data, 0,
self.ofs_nbits,
self.max_len,
bytes(oxm_data))
offset = len(data)
msg_pack_into("!%dx" % (14 - offset), data, offset)
return data
class NXActionLearn(NXAction):
r"""
Adds or modifies flow action
This action adds or modifies a flow in OpenFlow table.
And equivalent to the followings action of ovs-ofctl command.
..
learn(argument[,argument]...)
..
+---------------------------------------------------+
| **learn(**\ *argument*\[,\ *argument*\]...\ **)** |
+---------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
table_id The table in which the new flow should be inserted
specs Adds a match criterion to the new flow
Please use the
``NXFlowSpecMatch``
in order to set the following format
..
field=value
field[start..end]=src[start..end]
field[start..end]
..
| *field*\=\ *value*
| *field*\ **[**\ *start*\..\ *end*\ **]**\ =\ *src*\ **[**\ *start*\..\ *end*\ **]**
| *field*\ **[**\ *start*\..\ *end*\ **]**
|
Please use the
``NXFlowSpecLoad``
in order to set the following format
..
load:value->dst[start..end]
load:src[start..end]->dst[start..end]
..
| **load**\:\ *value*\ **->**\ *dst*\ **[**\ *start*\..\ *end*\ **]**
| **load**\:\ *src*\ **[**\ *start*\..\ *end*\ **] ->**\ *dst*\ **[**\ *start*\..\ *end*\ **]**
|
Please use the
``NXFlowSpecOutput``
in order to set the following format
..
output:field[start..end]
..
| **output:**\ field\ **[**\ *start*\..\ *end*\ **]**
idle_timeout Idle time before discarding(seconds)
hard_timeout Max time before discarding(seconds)
priority Priority level of flow entry
cookie Cookie for new flow
flags send_flow_rem
fin_idle_timeout Idle timeout after FIN(seconds)
fin_hard_timeout Hard timeout after FIN(seconds)
================ ======================================================
.. CAUTION::
The arguments specify the flow's match fields, actions,
and other properties, as follows.
At least one match criterion and one action argument
should ordinarily be specified.
Example::
actions += [
parser.NXActionLearn(able_id=10,
specs=[parser.NXFlowSpecMatch(src=0x800,
dst=('eth_type_nxm', 0),
n_bits=16),
parser.NXFlowSpecMatch(src=('reg1', 1),
dst=('reg2', 3),
n_bits=5),
parser.NXFlowSpecMatch(src=('reg3', 1),
dst=('reg3', 1),
n_bits=5),
parser.NXFlowSpecLoad(src=0,
dst=('reg4', 3),
n_bits=5),
parser.NXFlowSpecLoad(src=('reg5', 1),
dst=('reg6', 3),
n_bits=5),
parser.NXFlowSpecOutput(src=('reg7', 1),
dst="",
n_bits=5)],
idle_timeout=180,
hard_timeout=300,
priority=1,
cookie=0x64,
flags=ofproto.OFPFF_SEND_FLOW_REM,
fin_idle_timeout=180,
fin_hard_timeout=300)]
"""
_subtype = nicira_ext.NXAST_LEARN
# idle_timeout, hard_timeout, priority, cookie, flags,
# table_id, pad, fin_idle_timeout, fin_hard_timeout
_fmt_str = '!HHHQHBxHH'
# Followed by flow_mod_specs
def __init__(self,
table_id,
specs,
idle_timeout=0,
hard_timeout=0,
priority=ofp.OFP_DEFAULT_PRIORITY,
cookie=0,
flags=0,
fin_idle_timeout=0,
fin_hard_timeout=0,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionLearn, self).__init__()
self.idle_timeout = idle_timeout
self.hard_timeout = hard_timeout
self.priority = priority
self.cookie = cookie
self.flags = flags
self.table_id = table_id
self.fin_idle_timeout = fin_idle_timeout
self.fin_hard_timeout = fin_hard_timeout
self.specs = specs
@classmethod
def parser(cls, buf):
(idle_timeout,
hard_timeout,
priority,
cookie,
flags,
table_id,
fin_idle_timeout,
fin_hard_timeout,) = struct.unpack_from(
cls._fmt_str, buf, 0)
rest = buf[struct.calcsize(cls._fmt_str):]
# specs
specs = []
while len(rest) > 0:
spec, rest = _NXFlowSpec.parse(rest)
if spec is None:
continue
specs.append(spec)
return cls(idle_timeout=idle_timeout,
hard_timeout=hard_timeout,
priority=priority,
cookie=cookie,
flags=flags,
table_id=table_id,
fin_idle_timeout=fin_idle_timeout,
fin_hard_timeout=fin_hard_timeout,
specs=specs)
def serialize_body(self):
# fixup
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.idle_timeout,
self.hard_timeout,
self.priority,
self.cookie,
self.flags,
self.table_id,
self.fin_idle_timeout,
self.fin_hard_timeout)
for spec in self.specs:
data += spec.serialize()
return data
class NXActionExit(NXAction):
"""
Halt action
This action causes OpenvSwitch to immediately halt
execution of further actions.
And equivalent to the followings action of ovs-ofctl command.
..
exit
..
+----------+
| **exit** |
+----------+
Example::
actions += [parser.NXActionExit()]
"""
_subtype = nicira_ext.NXAST_EXIT
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionExit, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
# For OpenFlow1.0 only
class NXActionDecTtl(NXAction):
"""
Decrement IP TTL action
This action decrements TTL of IPv4 packet or
hop limit of IPv6 packet.
And equivalent to the followings action of ovs-ofctl command.
..
dec_ttl
..
+-------------+
| **dec_ttl** |
+-------------+
.. NOTE::
This actions is supported by
``OFPActionDecNwTtl``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionDecTtl()]
"""
_subtype = nicira_ext.NXAST_DEC_TTL
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionDecTtl, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
class NXActionController(NXAction):
r"""
Send packet in message action
This action sends the packet to the OpenFlow controller as
a packet in message.
And equivalent to the followings action of ovs-ofctl command.
..
controller(key=value...)
..
+----------------------------------------------+
| **controller(**\ *key*\=\ *value*\...\ **)** |
+----------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
max_len Max length to send to controller
controller_id Controller ID to send packet-in
reason Reason for sending the message
================ ======================================================
Example::
actions += [
parser.NXActionController(max_len=1024,
controller_id=1,
reason=ofproto.OFPR_INVALID_TTL)]
"""
_subtype = nicira_ext.NXAST_CONTROLLER
# max_len, controller_id, reason
_fmt_str = '!HHBx'
def __init__(self,
max_len,
controller_id,
reason,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionController, self).__init__()
self.max_len = max_len
self.controller_id = controller_id
self.reason = reason
@classmethod
def parser(cls, buf):
(max_len,
controller_id,
reason) = struct.unpack_from(
cls._fmt_str, buf)
return cls(max_len,
controller_id,
reason)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.max_len,
self.controller_id,
self.reason)
return data
class NXActionController2(NXAction):
r"""
Send packet in message action
This action sends the packet to the OpenFlow controller as
a packet in message.
And equivalent to the followings action of ovs-ofctl command.
..
controller(key=value...)
..
+----------------------------------------------+
| **controller(**\ *key*\=\ *value*\...\ **)** |
+----------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
max_len Max length to send to controller
controller_id Controller ID to send packet-in
reason Reason for sending the message
userdata Additional data to the controller in the packet-in
message
pause Flag to pause pipeline to resume later
================ ======================================================
Example::
actions += [
parser.NXActionController(max_len=1024,
controller_id=1,
reason=ofproto.OFPR_INVALID_TTL,
userdata=[0xa,0xb,0xc],
pause=True)]
"""
_subtype = nicira_ext.NXAST_CONTROLLER2
_fmt_str = '!6x'
_PACK_STR = '!HH'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None,
**kwargs):
super(NXActionController2, self).__init__()
for arg in kwargs:
if arg in NXActionController2Prop._NAMES:
setattr(self, arg, kwargs[arg])
@classmethod
def parser(cls, buf):
cls_data = {}
offset = 6
buf_len = len(buf)
while buf_len > offset:
(type_, length) = struct.unpack_from(cls._PACK_STR, buf, offset)
offset += 4
try:
subcls = NXActionController2Prop._TYPES[type_]
except KeyError:
subcls = NXActionController2PropUnknown
data, size = subcls.parser_prop(buf[offset:], length - 4)
offset += size
cls_data[subcls._arg_name] = data
return cls(**cls_data)
def serialize_body(self):
body = bytearray()
msg_pack_into(self._fmt_str, body, 0)
prop_list = []
for arg in self.__dict__:
if arg in NXActionController2Prop._NAMES:
prop_list.append((NXActionController2Prop._NAMES[arg],
self.__dict__[arg]))
prop_list.sort(key=lambda x: x[0].type)
for subcls, value in prop_list:
body += subcls.serialize_prop(value)
return body
class NXActionController2Prop(object):
_TYPES = {}
_NAMES = {}
@classmethod
def register_type(cls, type_):
def _register_type(subcls):
subcls.type = type_
NXActionController2Prop._TYPES[type_] = subcls
NXActionController2Prop._NAMES[subcls._arg_name] = subcls
return subcls
return _register_type
class NXActionController2PropUnknown(NXActionController2Prop):
@classmethod
def parser_prop(cls, buf, length):
size = 4
return buf, size
@classmethod
def serialize_prop(cls, argment):
data = bytearray()
return data
@NXActionController2Prop.register_type(nicira_ext.NXAC2PT_MAX_LEN)
class NXActionController2PropMaxLen(NXActionController2Prop):
# max_len
_fmt_str = "!H2x"
_arg_name = "max_len"
@classmethod
def parser_prop(cls, buf, length):
size = 4
(max_len,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return max_len, size
@classmethod
def serialize_prop(cls, max_len):
data = bytearray()
msg_pack_into("!HHH2x", data, 0,
nicira_ext.NXAC2PT_MAX_LEN,
8,
max_len)
return data
@NXActionController2Prop.register_type(nicira_ext.NXAC2PT_CONTROLLER_ID)
class NXActionController2PropControllerId(NXActionController2Prop):
# controller_id
_fmt_str = "!H2x"
_arg_name = "controller_id"
@classmethod
def parser_prop(cls, buf, length):
size = 4
(controller_id,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return controller_id, size
@classmethod
def serialize_prop(cls, controller_id):
data = bytearray()
msg_pack_into("!HHH2x", data, 0,
nicira_ext.NXAC2PT_CONTROLLER_ID,
8,
controller_id)
return data
@NXActionController2Prop.register_type(nicira_ext.NXAC2PT_REASON)
class NXActionController2PropReason(NXActionController2Prop):
# reason
_fmt_str = "!B3x"
_arg_name = "reason"
@classmethod
def parser_prop(cls, buf, length):
size = 4
(reason,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return reason, size
@classmethod
def serialize_prop(cls, reason):
data = bytearray()
msg_pack_into("!HHB3x", data, 0,
nicira_ext.NXAC2PT_REASON,
5,
reason)
return data
@NXActionController2Prop.register_type(nicira_ext.NXAC2PT_USERDATA)
class NXActionController2PropUserData(NXActionController2Prop):
# userdata
_fmt_str = "!B"
_arg_name = "userdata"
@classmethod
def parser_prop(cls, buf, length):
userdata = []
offset = 0
while offset < length:
u = struct.unpack_from(cls._fmt_str, buf, offset)
userdata.append(u[0])
offset += 1
user_size = utils.round_up(length, 4)
if user_size > 4 and (user_size % 8) == 0:
size = utils.round_up(length, 4) + 4
else:
size = utils.round_up(length, 4)
return userdata, size
@classmethod
def serialize_prop(cls, userdata):
data = bytearray()
user_buf = bytearray()
user_offset = 0
for user in userdata:
msg_pack_into('!B', user_buf, user_offset,
user)
user_offset += 1
msg_pack_into("!HH", data, 0,
nicira_ext.NXAC2PT_USERDATA,
4 + user_offset)
data += user_buf
if user_offset > 4:
user_len = utils.round_up(user_offset, 4)
brank_size = 0
if (user_len % 8) == 0:
brank_size = 4
msg_pack_into("!%dx" % (user_len - user_offset + brank_size),
data, 4 + user_offset)
else:
user_len = utils.round_up(user_offset, 4)
msg_pack_into("!%dx" % (user_len - user_offset),
data, 4 + user_offset)
return data
@NXActionController2Prop.register_type(nicira_ext.NXAC2PT_PAUSE)
class NXActionController2PropPause(NXActionController2Prop):
_arg_name = "pause"
@classmethod
def parser_prop(cls, buf, length):
pause = True
size = 4
return pause, size
@classmethod
def serialize_prop(cls, pause):
data = bytearray()
msg_pack_into("!HH4x", data, 0,
nicira_ext.NXAC2PT_PAUSE,
4)
return data
class NXActionDecTtlCntIds(NXAction):
r"""
Decrement TTL action
This action decrements TTL of IPv4 packet or
hop limits of IPv6 packet.
And equivalent to the followings action of ovs-ofctl command.
..
dec_ttl(id1[,id2]...)
..
+-------------------------------------------+
| **dec_ttl(**\ *id1*\[,\ *id2*\]...\ **)** |
+-------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
cnt_ids Controller ids
================ ======================================================
Example::
actions += [parser.NXActionDecTtlCntIds(cnt_ids=[1,2,3])]
.. NOTE::
If you want to set the following ovs-ofctl command.
Please use ``OFPActionDecNwTtl``.
+-------------+
| **dec_ttl** |
+-------------+
"""
_subtype = nicira_ext.NXAST_DEC_TTL_CNT_IDS
# controllers
_fmt_str = '!H4x'
_fmt_len = 6
def __init__(self,
cnt_ids,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionDecTtlCntIds, self).__init__()
self.cnt_ids = cnt_ids
@classmethod
def parser(cls, buf):
(controllers,) = struct.unpack_from(
cls._fmt_str, buf)
offset = cls._fmt_len
cnt_ids = []
for i in range(0, controllers):
id_ = struct.unpack_from('!H', buf, offset)
cnt_ids.append(id_[0])
offset += 2
return cls(cnt_ids)
def serialize_body(self):
assert isinstance(self.cnt_ids, (tuple, list))
for i in self.cnt_ids:
assert isinstance(i, int)
controllers = len(self.cnt_ids)
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
controllers)
offset = self._fmt_len
for id_ in self.cnt_ids:
msg_pack_into('!H', data, offset, id_)
offset += 2
id_len = (utils.round_up(controllers, 4) -
controllers)
if id_len != 0:
msg_pack_into('%dx' % id_len * 2, data, offset)
return data
# Use in only OpenFlow1.0
class NXActionMplsBase(NXAction):
# ethertype
_fmt_str = '!H4x'
def __init__(self,
ethertype,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionMplsBase, self).__init__()
self.ethertype = ethertype
@classmethod
def parser(cls, buf):
(ethertype,) = struct.unpack_from(
cls._fmt_str, buf)
return cls(ethertype)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.ethertype)
return data
# For OpenFlow1.0 only
class NXActionPushMpls(NXActionMplsBase):
r"""
Push MPLS action
This action pushes a new MPLS header to the packet.
And equivalent to the followings action of ovs-ofctl command.
..
push_mpls:ethertype
..
+-------------------------------+
| **push_mpls**\:\ *ethertype* |
+-------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
ethertype Ether type(The value must be either 0x8847 or 0x8848)
================ ======================================================
.. NOTE::
This actions is supported by
``OFPActionPushMpls``
in OpenFlow1.2 or later.
Example::
match = parser.OFPMatch(dl_type=0x0800)
actions += [parser.NXActionPushMpls(ethertype=0x8847)]
"""
_subtype = nicira_ext.NXAST_PUSH_MPLS
# For OpenFlow1.0 only
class NXActionPopMpls(NXActionMplsBase):
r"""
Pop MPLS action
This action pops the MPLS header from the packet.
And equivalent to the followings action of ovs-ofctl command.
..
pop_mpls:ethertype
..
+------------------------------+
| **pop_mpls**\:\ *ethertype* |
+------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
ethertype Ether type
================ ======================================================
.. NOTE::
This actions is supported by
``OFPActionPopMpls``
in OpenFlow1.2 or later.
Example::
match = parser.OFPMatch(dl_type=0x8847)
actions += [parser.NXActionPushMpls(ethertype=0x0800)]
"""
_subtype = nicira_ext.NXAST_POP_MPLS
# For OpenFlow1.0 only
class NXActionSetMplsTtl(NXAction):
r"""
Set MPLS TTL action
This action sets the MPLS TTL.
And equivalent to the followings action of ovs-ofctl command.
..
set_mpls_ttl:ttl
..
+---------------------------+
| **set_mpls_ttl**\:\ *ttl* |
+---------------------------+
================ ======================================================
Attribute Description
================ ======================================================
ttl MPLS TTL
================ ======================================================
.. NOTE::
This actions is supported by
``OFPActionSetMplsTtl``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionSetMplsTil(ttl=128)]
"""
_subtype = nicira_ext.NXAST_SET_MPLS_TTL
# ethertype
_fmt_str = '!B5x'
def __init__(self,
ttl,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionSetMplsTtl, self).__init__()
self.ttl = ttl
@classmethod
def parser(cls, buf):
(ttl,) = struct.unpack_from(
cls._fmt_str, buf)
return cls(ttl)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.ttl)
return data
# For OpenFlow1.0 only
class NXActionDecMplsTtl(NXAction):
"""
Decrement MPLS TTL action
This action decrements the MPLS TTL.
And equivalent to the followings action of ovs-ofctl command.
..
dec_mpls_ttl
..
+------------------+
| **dec_mpls_ttl** |
+------------------+
.. NOTE::
This actions is supported by
``OFPActionDecMplsTtl``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionDecMplsTil()]
"""
_subtype = nicira_ext.NXAST_DEC_MPLS_TTL
# ethertype
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionDecMplsTtl, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
# For OpenFlow1.0 only
class NXActionSetMplsLabel(NXAction):
r"""
Set MPLS Lavel action
This action sets the MPLS Label.
And equivalent to the followings action of ovs-ofctl command.
..
set_mpls_label:label
..
+-------------------------------+
| **set_mpls_label**\:\ *label* |
+-------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
label MPLS Label
================ ======================================================
.. NOTE::
This actions is supported by
``OFPActionSetField(mpls_label=label)``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionSetMplsLabel(label=0x10)]
"""
_subtype = nicira_ext.NXAST_SET_MPLS_LABEL
# ethertype
_fmt_str = '!2xI'
def __init__(self,
label,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionSetMplsLabel, self).__init__()
self.label = label
@classmethod
def parser(cls, buf):
(label,) = struct.unpack_from(
cls._fmt_str, buf)
return cls(label)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.label)
return data
# For OpenFlow1.0 only
class NXActionSetMplsTc(NXAction):
r"""
Set MPLS Tc action
This action sets the MPLS Tc.
And equivalent to the followings action of ovs-ofctl command.
..
set_mpls_tc:tc
..
+-------------------------+
| **set_mpls_tc**\:\ *tc* |
+-------------------------+
================ ======================================================
Attribute Description
================ ======================================================
tc MPLS Tc
================ ======================================================
.. NOTE::
This actions is supported by
``OFPActionSetField(mpls_label=tc)``
in OpenFlow1.2 or later.
Example::
actions += [parser.NXActionSetMplsLabel(tc=0x10)]
"""
_subtype = nicira_ext.NXAST_SET_MPLS_TC
# ethertype
_fmt_str = '!B5x'
def __init__(self,
tc,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionSetMplsTc, self).__init__()
self.tc = tc
@classmethod
def parser(cls, buf):
(tc,) = struct.unpack_from(
cls._fmt_str, buf)
return cls(tc)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.tc)
return data
class NXActionStackBase(NXAction):
# start, field, end
_fmt_str = '!H4sH'
_TYPE = {
'ascii': [
'field',
]
}
def __init__(self,
field,
start,
end,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionStackBase, self).__init__()
self.field = field
self.start = start
self.end = end
@classmethod
def parser(cls, buf):
(start, oxm_data, end) = struct.unpack_from(
cls._fmt_str, buf, 0)
(n, len_) = ofp.oxm_parse_header(oxm_data, 0)
field = ofp.oxm_to_user_header(n)
return cls(field, start, end)
def serialize_body(self):
data = bytearray()
oxm_data = bytearray()
oxm = ofp.oxm_from_user_header(self.field)
ofp.oxm_serialize_header(oxm, oxm_data, 0)
msg_pack_into(self._fmt_str, data, 0,
self.start,
bytes(oxm_data),
self.end)
offset = len(data)
msg_pack_into("!%dx" % (12 - offset), data, offset)
return data
class NXActionStackPush(NXActionStackBase):
r"""
Push field action
This action pushes field to top of the stack.
And equivalent to the followings action of ovs-ofctl command.
..
pop:dst[start...end]
..
+----------------------------------------------------+
| **pop**\:\ *dst*\ **[**\ *start*\...\ *end*\ **]** |
+----------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
field OXM/NXM header for source field
start Start bit for source field
end End bit for source field
================ ======================================================
Example::
actions += [parser.NXActionStackPush(field="reg2",
start=0,
end=5)]
"""
_subtype = nicira_ext.NXAST_STACK_PUSH
class NXActionStackPop(NXActionStackBase):
r"""
Pop field action
This action pops field from top of the stack.
And equivalent to the followings action of ovs-ofctl command.
..
pop:src[start...end]
..
+----------------------------------------------------+
| **pop**\:\ *src*\ **[**\ *start*\...\ *end*\ **]** |
+----------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
field OXM/NXM header for destination field
start Start bit for destination field
end End bit for destination field
================ ======================================================
Example::
actions += [parser.NXActionStackPop(field="reg2",
start=0,
end=5)]
"""
_subtype = nicira_ext.NXAST_STACK_POP
class NXActionSample(NXAction):
r"""
Sample packets action
This action samples packets and sends one sample for
every sampled packet.
And equivalent to the followings action of ovs-ofctl command.
..
sample(argument[,argument]...)
..
+----------------------------------------------------+
| **sample(**\ *argument*\[,\ *argument*\]...\ **)** |
+----------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
probability The number of sampled packets
collector_set_id The unsigned 32-bit integer identifier of
the set of sample collectors to send sampled packets
to
obs_domain_id The Unsigned 32-bit integer Observation Domain ID
obs_point_id The unsigned 32-bit integer Observation Point ID
================ ======================================================
Example::
actions += [parser.NXActionSample(probability=3,
collector_set_id=1,
obs_domain_id=2,
obs_point_id=3,)]
"""
_subtype = nicira_ext.NXAST_SAMPLE
# probability, collector_set_id, obs_domain_id, obs_point_id
_fmt_str = '!HIII'
def __init__(self,
probability,
collector_set_id=0,
obs_domain_id=0,
obs_point_id=0,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionSample, self).__init__()
self.probability = probability
self.collector_set_id = collector_set_id
self.obs_domain_id = obs_domain_id
self.obs_point_id = obs_point_id
@classmethod
def parser(cls, buf):
(probability,
collector_set_id,
obs_domain_id,
obs_point_id) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(probability,
collector_set_id,
obs_domain_id,
obs_point_id)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.probability,
self.collector_set_id,
self.obs_domain_id,
self.obs_point_id)
return data
class NXActionSample2(NXAction):
r"""
Sample packets action
This action samples packets and sends one sample for
every sampled packet.
'sampling_port' can be equal to ingress port or one of egress ports.
And equivalent to the followings action of ovs-ofctl command.
..
sample(argument[,argument]...)
..
+----------------------------------------------------+
| **sample(**\ *argument*\[,\ *argument*\]...\ **)** |
+----------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
probability The number of sampled packets
collector_set_id The unsigned 32-bit integer identifier of
the set of sample collectors to send sampled packets to
obs_domain_id The Unsigned 32-bit integer Observation Domain ID
obs_point_id The unsigned 32-bit integer Observation Point ID
sampling_port Sampling port number
================ ======================================================
Example::
actions += [parser.NXActionSample2(probability=3,
collector_set_id=1,
obs_domain_id=2,
obs_point_id=3,
sampling_port=8080)]
"""
_subtype = nicira_ext.NXAST_SAMPLE2
# probability, collector_set_id, obs_domain_id,
# obs_point_id, sampling_port
_fmt_str = '!HIIIH6x'
def __init__(self,
probability,
collector_set_id=0,
obs_domain_id=0,
obs_point_id=0,
sampling_port=0,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionSample2, self).__init__()
self.probability = probability
self.collector_set_id = collector_set_id
self.obs_domain_id = obs_domain_id
self.obs_point_id = obs_point_id
self.sampling_port = sampling_port
@classmethod
def parser(cls, buf):
(probability,
collector_set_id,
obs_domain_id,
obs_point_id,
sampling_port) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(probability,
collector_set_id,
obs_domain_id,
obs_point_id,
sampling_port)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.probability,
self.collector_set_id,
self.obs_domain_id,
self.obs_point_id,
self.sampling_port)
return data
class NXActionFinTimeout(NXAction):
r"""
Change TCP timeout action
This action changes the idle timeout or hard timeout or
both, of this OpenFlow rule when the rule matches a TCP
packet with the FIN or RST flag.
And equivalent to the followings action of ovs-ofctl command.
..
fin_timeout(argument[,argument]...)
..
+---------------------------------------------------------+
| **fin_timeout(**\ *argument*\[,\ *argument*\]...\ **)** |
+---------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
fin_idle_timeout Causes the flow to expire after the given number
of seconds of inactivity
fin_idle_timeout Causes the flow to expire after the given number
of second, regardless of activity
================ ======================================================
Example::
match = parser.OFPMatch(ip_proto=6, eth_type=0x0800)
actions += [parser.NXActionFinTimeout(fin_idle_timeout=30,
fin_hard_timeout=60)]
"""
_subtype = nicira_ext.NXAST_FIN_TIMEOUT
# fin_idle_timeout, fin_hard_timeout
_fmt_str = '!HH2x'
def __init__(self,
fin_idle_timeout,
fin_hard_timeout,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionFinTimeout, self).__init__()
self.fin_idle_timeout = fin_idle_timeout
self.fin_hard_timeout = fin_hard_timeout
@classmethod
def parser(cls, buf):
(fin_idle_timeout,
fin_hard_timeout) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(fin_idle_timeout,
fin_hard_timeout)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.fin_idle_timeout,
self.fin_hard_timeout)
return data
class NXActionConjunction(NXAction):
r"""
Conjunctive matches action
This action ties groups of individual OpenFlow flows into
higher-level conjunctive flows.
Please refer to the ovs-ofctl command manual for details.
And equivalent to the followings action of ovs-ofctl command.
..
conjunction(id,k/n)
..
+--------------------------------------------------+
| **conjunction(**\ *id*\,\ *k*\ **/**\ *n*\ **)** |
+--------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
clause Number assigned to the flow's dimension
n_clauses Specify the conjunctive flow's match condition
id\_ Conjunction ID
================ ======================================================
Example::
actions += [parser.NXActionConjunction(clause=1,
n_clauses=2,
id_=10)]
"""
_subtype = nicira_ext.NXAST_CONJUNCTION
# clause, n_clauses, id
_fmt_str = '!BBI'
def __init__(self,
clause,
n_clauses,
id_,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionConjunction, self).__init__()
self.clause = clause
self.n_clauses = n_clauses
self.id = id_
@classmethod
def parser(cls, buf):
(clause,
n_clauses,
id_,) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(clause, n_clauses, id_)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.clause,
self.n_clauses,
self.id)
return data
class NXActionMultipath(NXAction):
r"""
Select multipath link action
This action selects multipath link based on the specified parameters.
Please refer to the ovs-ofctl command manual for details.
And equivalent to the followings action of ovs-ofctl command.
..
multipath(fields, basis, algorithm, n_links, arg, dst[start..end])
..
+-------------------------------------------------------------+
| **multipath(**\ *fields*\, \ *basis*\, \ *algorithm*\, |
| *n_links*\, \ *arg*\, \ *dst*\[\ *start*\..\ *end*\]\ **)** |
+-------------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
fields One of NX_HASH_FIELDS_*
basis Universal hash parameter
algorithm One of NX_MP_ALG_*.
max_link Number of output links
arg Algorithm-specific argument
ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``
dst OXM/NXM header for source field
================ ======================================================
Example::
actions += [parser.NXActionMultipath(
fields=nicira_ext.NX_HASH_FIELDS_SYMMETRIC_L4,
basis=1024,
algorithm=nicira_ext.NX_MP_ALG_HRW,
max_link=5,
arg=0,
ofs_nbits=nicira_ext.ofs_nbits(4, 31),
dst="reg2")]
"""
_subtype = nicira_ext.NXAST_MULTIPATH
# fields, basis, algorithm, max_link,
# arg, ofs_nbits, dst
_fmt_str = '!HH2xHHI2xH4s'
_TYPE = {
'ascii': [
'dst',
]
}
def __init__(self,
fields,
basis,
algorithm,
max_link,
arg,
ofs_nbits,
dst,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionMultipath, self).__init__()
self.fields = fields
self.basis = basis
self.algorithm = algorithm
self.max_link = max_link
self.arg = arg
self.ofs_nbits = ofs_nbits
self.dst = dst
@classmethod
def parser(cls, buf):
(fields,
basis,
algorithm,
max_link,
arg,
ofs_nbits,
oxm_data) = struct.unpack_from(
cls._fmt_str, buf, 0)
(n, len_) = ofp.oxm_parse_header(oxm_data, 0)
dst = ofp.oxm_to_user_header(n)
return cls(fields,
basis,
algorithm,
max_link,
arg,
ofs_nbits,
dst)
def serialize_body(self):
data = bytearray()
dst = bytearray()
oxm = ofp.oxm_from_user_header(self.dst)
ofp.oxm_serialize_header(oxm, dst, 0),
msg_pack_into(self._fmt_str, data, 0,
self.fields,
self.basis,
self.algorithm,
self.max_link,
self.arg,
self.ofs_nbits,
bytes(dst))
return data
class _NXActionBundleBase(NXAction):
# algorithm, fields, basis, slave_type, n_slaves
# ofs_nbits
_fmt_str = '!HHHIHH'
def __init__(self, algorithm, fields, basis, slave_type, n_slaves,
ofs_nbits, dst, slaves):
super(_NXActionBundleBase, self).__init__()
self.len = utils.round_up(
nicira_ext.NX_ACTION_BUNDLE_0_SIZE + len(slaves) * 2, 8)
self.algorithm = algorithm
self.fields = fields
self.basis = basis
self.slave_type = slave_type
self.n_slaves = n_slaves
self.ofs_nbits = ofs_nbits
self.dst = dst
assert isinstance(slaves, (list, tuple))
for s in slaves:
assert isinstance(s, int)
self.slaves = slaves
@classmethod
def parser(cls, buf):
# Add dst ('I') to _fmt_str
(algorithm, fields, basis,
slave_type, n_slaves, ofs_nbits, dst) = struct.unpack_from(
cls._fmt_str + 'I', buf, 0)
offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE -
nicira_ext.NX_ACTION_HEADER_0_SIZE - 8)
if dst != 0:
(n, len_) = ofp.oxm_parse_header(buf, offset)
dst = ofp.oxm_to_user_header(n)
slave_offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE -
nicira_ext.NX_ACTION_HEADER_0_SIZE)
slaves = []
for i in range(0, n_slaves):
s = struct.unpack_from('!H', buf, slave_offset)
slaves.append(s[0])
slave_offset += 2
return cls(algorithm, fields, basis, slave_type,
n_slaves, ofs_nbits, dst, slaves)
def serialize_body(self):
data = bytearray()
slave_offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE -
nicira_ext.NX_ACTION_HEADER_0_SIZE)
self.n_slaves = len(self.slaves)
for s in self.slaves:
msg_pack_into('!H', data, slave_offset, s)
slave_offset += 2
pad_len = (utils.round_up(self.n_slaves, 4) -
self.n_slaves)
if pad_len != 0:
msg_pack_into('%dx' % pad_len * 2, data, slave_offset)
msg_pack_into(self._fmt_str, data, 0,
self.algorithm, self.fields, self.basis,
self.slave_type, self.n_slaves,
self.ofs_nbits)
offset = (nicira_ext.NX_ACTION_BUNDLE_0_SIZE -
nicira_ext.NX_ACTION_HEADER_0_SIZE - 8)
if self.dst == 0:
msg_pack_into('I', data, offset, self.dst)
else:
oxm_data = ofp.oxm_from_user_header(self.dst)
ofp.oxm_serialize_header(oxm_data, data, offset)
return data
class NXActionBundle(_NXActionBundleBase):
r"""
Select bundle link action
This action selects bundle link based on the specified parameters.
Please refer to the ovs-ofctl command manual for details.
And equivalent to the followings action of ovs-ofctl command.
..
bundle(fields, basis, algorithm, slave_type, slaves:[ s1, s2,...])
..
+-----------------------------------------------------------+
| **bundle(**\ *fields*\, \ *basis*\, \ *algorithm*\, |
| *slave_type*\, \ *slaves*\:[ \ *s1*\, \ *s2*\,...]\ **)** |
+-----------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
algorithm One of NX_MP_ALG_*.
fields One of NX_HASH_FIELDS_*
basis Universal hash parameter
slave_type Type of slaves(must be NXM_OF_IN_PORT)
n_slaves Number of slaves
ofs_nbits Start and End for the OXM/NXM field. (must be zero)
dst OXM/NXM header for source field(must be zero)
slaves List of slaves
================ ======================================================
Example::
actions += [parser.NXActionBundle(
algorithm=nicira_ext.NX_MP_ALG_HRW,
fields=nicira_ext.NX_HASH_FIELDS_ETH_SRC,
basis=0,
slave_type=nicira_ext.NXM_OF_IN_PORT,
n_slaves=2,
ofs_nbits=0,
dst=0,
slaves=[2, 3])]
"""
_subtype = nicira_ext.NXAST_BUNDLE
def __init__(self, algorithm, fields, basis, slave_type, n_slaves,
ofs_nbits, dst, slaves):
# NXAST_BUNDLE actions should have 'sofs_nbits' and 'dst' zeroed.
super(NXActionBundle, self).__init__(
algorithm, fields, basis, slave_type, n_slaves,
ofs_nbits=0, dst=0, slaves=slaves)
class NXActionBundleLoad(_NXActionBundleBase):
r"""
Select bundle link action
This action has the same behavior as the bundle action,
with one exception.
Please refer to the ovs-ofctl command manual for details.
And equivalent to the followings action of ovs-ofctl command.
..
bundle_load(fields, basis, algorithm, slave_type,
dst[start..end], slaves:[ s1, s2,...])
..
+-----------------------------------------------------------+
| **bundle_load(**\ *fields*\, \ *basis*\, \ *algorithm*\, |
| *slave_type*\, \ *dst*\[\ *start*\... \*emd*\], |
| \ *slaves*\:[ \ *s1*\, \ *s2*\,...]\ **)** | |
+-----------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
algorithm One of NX_MP_ALG_*.
fields One of NX_HASH_FIELDS_*
basis Universal hash parameter
slave_type Type of slaves(must be NXM_OF_IN_PORT)
n_slaves Number of slaves
ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``
dst OXM/NXM header for source field
slaves List of slaves
================ ======================================================
Example::
actions += [parser.NXActionBundleLoad(
algorithm=nicira_ext.NX_MP_ALG_HRW,
fields=nicira_ext.NX_HASH_FIELDS_ETH_SRC,
basis=0,
slave_type=nicira_ext.NXM_OF_IN_PORT,
n_slaves=2,
ofs_nbits=nicira_ext.ofs_nbits(4, 31),
dst="reg0",
slaves=[2, 3])]
"""
_subtype = nicira_ext.NXAST_BUNDLE_LOAD
_TYPE = {
'ascii': [
'dst',
]
}
def __init__(self, algorithm, fields, basis, slave_type, n_slaves,
ofs_nbits, dst, slaves):
super(NXActionBundleLoad, self).__init__(
algorithm, fields, basis, slave_type, n_slaves,
ofs_nbits, dst, slaves)
class NXActionCT(NXAction):
r"""
Pass traffic to the connection tracker action
This action sends the packet through the connection tracker.
And equivalent to the followings action of ovs-ofctl command.
..
ct(argument[,argument]...)
..
+------------------------------------------------+
| **ct(**\ *argument*\[,\ *argument*\]...\ **)** |
+------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
flags Zero or more(Unspecified flag bits must be zero.)
zone_src OXM/NXM header for source field
zone_ofs_nbits Start and End for the OXM/NXM field.
Setting method refer to the ``nicira_ext.ofs_nbits``.
If you need set the Immediate value for zone,
zone_src must be set to None or empty character string.
recirc_table Recirculate to a specific table
alg Well-known port number for the protocol
actions Zero or more actions may immediately follow this
action
================ ======================================================
.. NOTE::
If you set number to zone_src,
Traceback occurs when you run the to_jsondict.
Example::
match = parser.OFPMatch(eth_type=0x0800, ct_state=(0,32))
actions += [parser.NXActionCT(
flags = 1,
zone_src = "reg0",
zone_ofs_nbits = nicira_ext.ofs_nbits(4, 31),
recirc_table = 4,
alg = 0,
actions = [])]
"""
_subtype = nicira_ext.NXAST_CT
# flags, zone_src, zone_ofs_nbits, recirc_table,
# pad, alg
_fmt_str = '!H4sHB3xH'
_TYPE = {
'ascii': [
'zone_src',
]
}
# Followed by actions
def __init__(self,
flags,
zone_src,
zone_ofs_nbits,
recirc_table,
alg,
actions,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionCT, self).__init__()
self.flags = flags
self.zone_src = zone_src
self.zone_ofs_nbits = zone_ofs_nbits
self.recirc_table = recirc_table
self.alg = alg
self.actions = actions
@classmethod
def parser(cls, buf):
(flags,
oxm_data,
zone_ofs_nbits,
recirc_table,
alg,) = struct.unpack_from(
cls._fmt_str, buf, 0)
rest = buf[struct.calcsize(cls._fmt_str):]
# OXM/NXM field
if oxm_data == b'\x00' * 4:
zone_src = ""
else:
(n, len_) = ofp.oxm_parse_header(oxm_data, 0)
zone_src = ofp.oxm_to_user_header(n)
# actions
actions = []
while len(rest) > 0:
action = ofpp.OFPAction.parser(rest, 0)
actions.append(action)
rest = rest[action.len:]
return cls(flags, zone_src, zone_ofs_nbits, recirc_table,
alg, actions)
def serialize_body(self):
data = bytearray()
# If zone_src is zero, zone_ofs_nbits is zone_imm
if not self.zone_src:
zone_src = b'\x00' * 4
elif isinstance(self.zone_src, int):
zone_src = struct.pack("!I", self.zone_src)
else:
zone_src = bytearray()
oxm = ofp.oxm_from_user_header(self.zone_src)
ofp.oxm_serialize_header(oxm, zone_src, 0)
msg_pack_into(self._fmt_str, data, 0,
self.flags,
bytes(zone_src),
self.zone_ofs_nbits,
self.recirc_table,
self.alg)
for a in self.actions:
a.serialize(data, len(data))
return data
class NXActionCTClear(NXAction):
"""
Clear connection tracking state action
This action clears connection tracking state from packets.
And equivalent to the followings action of ovs-ofctl command.
..
ct_clear
..
+--------------+
| **ct_clear** |
+--------------+
Example::
actions += [parser.NXActionCTClear()]
"""
_subtype = nicira_ext.NXAST_CT_CLEAR
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionCTClear, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
class NXActionNAT(NXAction):
r"""
Network address translation action
This action sends the packet through the connection tracker.
And equivalent to the followings action of ovs-ofctl command.
.. NOTE::
The following command image does not exist in ovs-ofctl command
manual and has been created from the command response.
..
nat(src=ip_min-ip_max : proto_min-proto-max)
..
+--------------------------------------------------+
| **nat(src**\=\ *ip_min*\ **-**\ *ip_max*\ **:** |
| *proto_min*\ **-**\ *proto-max*\ **)** |
+--------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
flags Zero or more(Unspecified flag bits must be zero.)
range_ipv4_min Range ipv4 address minimun
range_ipv4_max Range ipv4 address maximun
range_ipv6_min Range ipv6 address minimun
range_ipv6_max Range ipv6 address maximun
range_proto_min Range protocol minimum
range_proto_max Range protocol maximun
================ ======================================================
.. CAUTION::
``NXActionNAT`` must be defined in the actions in the
``NXActionCT``.
Example::
match = parser.OFPMatch(eth_type=0x0800)
actions += [
parser.NXActionCT(
flags = 1,
zone_src = "reg0",
zone_ofs_nbits = nicira_ext.ofs_nbits(4, 31),
recirc_table = 255,
alg = 0,
actions = [
parser.NXActionNAT(
flags = 1,
range_ipv4_min = "10.1.12.0",
range_ipv4_max = "10.1.13.255",
range_ipv6_min = "",
range_ipv6_max = "",
range_proto_min = 1,
range_proto_max = 1023
)
]
)
]
"""
_subtype = nicira_ext.NXAST_NAT
# pad, flags, range_present
_fmt_str = '!2xHH'
# Followed by optional parameters
_TYPE = {
'ascii': [
'range_ipv4_max',
'range_ipv4_min',
'range_ipv6_max',
'range_ipv6_min',
]
}
def __init__(self,
flags,
range_ipv4_min='',
range_ipv4_max='',
range_ipv6_min='',
range_ipv6_max='',
range_proto_min=None,
range_proto_max=None,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionNAT, self).__init__()
self.flags = flags
self.range_ipv4_min = range_ipv4_min
self.range_ipv4_max = range_ipv4_max
self.range_ipv6_min = range_ipv6_min
self.range_ipv6_max = range_ipv6_max
self.range_proto_min = range_proto_min
self.range_proto_max = range_proto_max
@classmethod
def parser(cls, buf):
(flags,
range_present) = struct.unpack_from(
cls._fmt_str, buf, 0)
rest = buf[struct.calcsize(cls._fmt_str):]
# optional parameters
kwargs = dict()
if range_present & nicira_ext.NX_NAT_RANGE_IPV4_MIN:
kwargs['range_ipv4_min'] = type_desc.IPv4Addr.to_user(rest[:4])
rest = rest[4:]
if range_present & nicira_ext.NX_NAT_RANGE_IPV4_MAX:
kwargs['range_ipv4_max'] = type_desc.IPv4Addr.to_user(rest[:4])
rest = rest[4:]
if range_present & nicira_ext.NX_NAT_RANGE_IPV6_MIN:
kwargs['range_ipv6_min'] = (
type_desc.IPv6Addr.to_user(rest[:16]))
rest = rest[16:]
if range_present & nicira_ext.NX_NAT_RANGE_IPV6_MAX:
kwargs['range_ipv6_max'] = (
type_desc.IPv6Addr.to_user(rest[:16]))
rest = rest[16:]
if range_present & nicira_ext.NX_NAT_RANGE_PROTO_MIN:
kwargs['range_proto_min'] = type_desc.Int2.to_user(rest[:2])
rest = rest[2:]
if range_present & nicira_ext.NX_NAT_RANGE_PROTO_MAX:
kwargs['range_proto_max'] = type_desc.Int2.to_user(rest[:2])
return cls(flags, **kwargs)
def serialize_body(self):
# Pack optional parameters first, as range_present needs
# to be calculated.
optional_data = b''
range_present = 0
if self.range_ipv4_min != '':
range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MIN
optional_data += type_desc.IPv4Addr.from_user(
self.range_ipv4_min)
if self.range_ipv4_max != '':
range_present |= nicira_ext.NX_NAT_RANGE_IPV4_MAX
optional_data += type_desc.IPv4Addr.from_user(
self.range_ipv4_max)
if self.range_ipv6_min != '':
range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MIN
optional_data += type_desc.IPv6Addr.from_user(
self.range_ipv6_min)
if self.range_ipv6_max != '':
range_present |= nicira_ext.NX_NAT_RANGE_IPV6_MAX
optional_data += type_desc.IPv6Addr.from_user(
self.range_ipv6_max)
if self.range_proto_min is not None:
range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MIN
optional_data += type_desc.Int2.from_user(
self.range_proto_min)
if self.range_proto_max is not None:
range_present |= nicira_ext.NX_NAT_RANGE_PROTO_MAX
optional_data += type_desc.Int2.from_user(
self.range_proto_max)
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.flags,
range_present)
msg_pack_into('!%ds' % len(optional_data), data, len(data),
optional_data)
return data
class NXActionOutputTrunc(NXAction):
r"""
Truncate output action
This action truncate a packet into the specified size and outputs it.
And equivalent to the followings action of ovs-ofctl command.
..
output(port=port,max_len=max_len)
..
+--------------------------------------------------------------+
| **output(port**\=\ *port*\,\ **max_len**\=\ *max_len*\ **)** |
+--------------------------------------------------------------+
================ ======================================================
Attribute Description
================ ======================================================
port Output port
max_len Max bytes to send
================ ======================================================
Example::
actions += [parser.NXActionOutputTrunc(port=8080,
max_len=1024)]
"""
_subtype = nicira_ext.NXAST_OUTPUT_TRUNC
# port, max_len
_fmt_str = '!HI'
def __init__(self,
port,
max_len,
type_=None, len_=None, experimenter=None, subtype=None):
super(NXActionOutputTrunc, self).__init__()
self.port = port
self.max_len = max_len
@classmethod
def parser(cls, buf):
(port,
max_len) = struct.unpack_from(
cls._fmt_str, buf, 0)
return cls(port, max_len)
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0,
self.port,
self.max_len)
return data
class NXActionEncapEther(NXAction):
"""
Encap Ether
This action encaps package with ethernet
And equivalent to the followings action of ovs-ofctl command.
::
encap(ethernet)
Example::
actions += [parser.NXActionEncapEther()]
"""
_subtype = nicira_ext.NXAST_RAW_ENCAP
_fmt_str = '!HI'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionEncapEther, self).__init__()
self.hdr_size = 0
self.new_pkt_type = 0x00000000
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0, self.hdr_size, self.new_pkt_type)
return data
class NXActionEncapNsh(NXAction):
"""
Encap nsh
This action encaps package with nsh
And equivalent to the followings action of ovs-ofctl command.
::
encap(nsh(md_type=1))
Example::
actions += [parser.NXActionEncapNsh()]
"""
_subtype = nicira_ext.NXAST_RAW_ENCAP
_fmt_str = '!HI'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionEncapNsh, self).__init__()
self.hdr_size = hdr_size
self.new_pkt_type = 0x0001894F
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0, self.hdr_size, self.new_pkt_type)
return data
class NXActionDecNshTtl(NXAction):
"""
Decrement NSH TTL action
This action decrements the TTL in the Network Service Header(NSH).
This action was added in OVS v2.9.
And equivalent to the followings action of ovs-ofctl command.
::
dec_nsh_ttl
Example::
actions += [parser.NXActionDecNshTtl()]
"""
_subtype = nicira_ext.NXAST_DEC_NSH_TTL
_fmt_str = '!6x'
def __init__(self,
type_=None, len_=None, vendor=None, subtype=None):
super(NXActionDecNshTtl, self).__init__()
@classmethod
def parser(cls, buf):
return cls()
def serialize_body(self):
data = bytearray()
msg_pack_into(self._fmt_str, data, 0)
return data
def add_attr(k, v):
v.__module__ = ofpp.__name__ # Necessary for stringify stuff
setattr(ofpp, k, v)
add_attr('NXAction', NXAction)
add_attr('NXActionUnknown', NXActionUnknown)
classes = [
'NXActionSetQueue',
'NXActionPopQueue',
'NXActionRegLoad',
'NXActionRegLoad2',
'NXActionNote',
'NXActionSetTunnel',
'NXActionSetTunnel64',
'NXActionRegMove',
'NXActionResubmit',
'NXActionResubmitTable',
'NXActionOutputReg',
'NXActionOutputReg2',
'NXActionLearn',
'NXActionExit',
'NXActionDecTtl',
'NXActionController',
'NXActionController2',
'NXActionDecTtlCntIds',
'NXActionPushMpls',
'NXActionPopMpls',
'NXActionSetMplsTtl',
'NXActionDecMplsTtl',
'NXActionSetMplsLabel',
'NXActionSetMplsTc',
'NXActionStackPush',
'NXActionStackPop',
'NXActionSample',
'NXActionSample2',
'NXActionFinTimeout',
'NXActionConjunction',
'NXActionMultipath',
'NXActionBundle',
'NXActionBundleLoad',
'NXActionCT',
'NXActionCTClear',
'NXActionNAT',
'NXActionOutputTrunc',
'_NXFlowSpec', # exported for testing
'NXFlowSpecMatch',
'NXFlowSpecLoad',
'NXFlowSpecOutput',
'NXActionEncapNsh',
'NXActionEncapEther',
'NXActionDecNshTtl',
]
vars = locals()
for name in classes:
cls = vars[name]
add_attr(name, cls)
if issubclass(cls, NXAction):
NXAction.register(cls)
if issubclass(cls, _NXFlowSpec):
_NXFlowSpec.register(cls)
|