summaryrefslogtreecommitdiff
path: root/tests/ovsdb-idl.at
blob: 978a6677bd6aea025c6cdbbd1302e3f7653c6092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
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
AT_BANNER([OVSDB -- interface description language (IDL)])

m4_divert_text([PREPARE_TESTS], [
# ovsdb_cluster_leader [REMOTES] [DATABASE]
#
# Returns the leader of the DATABASE cluster.
ovsdb_cluster_leader () {
   remotes=$(echo $1 | tr "," "\n")
   for remote in $remotes; do
      ovsdb-client dump $remote _Server Database name leader | grep $2 | grep -q true
      if [[ $? == 0 ]]; then
        port=$(echo $remote | cut -d':' -f 3)
        log=$(grep --include=s\*.log -rlnw -e "listening on port $port" ./)
        pid=$(echo $log | sed 's/\(.*\.\)log/\1pid/' )
        echo "${remote}|${pid}"
        return
      fi
   done
}])


# OVSDB_START_IDLTEST([REMOTE], [SCHEMA])
#
# Creates a database using SCHEMA (default: idltest.ovsschema) and
# starts a database server listening on punix:socket and REMOTE (if
# specified).
m4_define([OVSDB_START_IDLTEST],
[
  AT_CHECK([ovsdb-tool create db dnl
              m4_if([$2], [], [$abs_srcdir/idltest.ovsschema], [$2])])
  PKIDIR=$abs_top_builddir/tests
  AT_CHECK([ovsdb-server -vconsole:warn --log-file --detach --no-chdir dnl
              --pidfile --remote=punix:socket dnl
              m4_if(m4_substr($1, 0, 5), [pssl:],
                    [--private-key=$PKIDIR/testpki-privkey2.pem dnl
                     --certificate=$PKIDIR/testpki-cert2.pem dnl
                     --ca-cert=$PKIDIR/testpki-cacert.pem], []) dnl
              m4_if([$1], [], [], [--remote=$1]) db dnl
  ])
  on_exit 'kill `cat ovsdb-server.pid`'
])


# OVSDB_CLUSTER_START_IDLTEST([N], [REMOTE])
#
# Creates a clustered database using idltest.ovsschema and starts a database
# cluster of N servers listening on punix:socket and REMOTE (if specified).
m4_define([OVSDB_CLUSTER_START_IDLTEST],
  [n=$1
   AT_CHECK([ovsdb-tool create-cluster s1.db \
                        $abs_srcdir/idltest.ovsschema unix:s1.raft])
   cid=$(ovsdb-tool db-cid s1.db)
   schema_name=$(ovsdb-tool schema-name $abs_srcdir/idltest.ovsschema)
   for i in $(seq 2 $n); do
     AT_CHECK([ovsdb-tool join-cluster s$i.db \
                          $schema_name unix:s$i.raft unix:s1.raft])
   done
   on_exit 'kill $(cat s*.pid)'
   for i in $(seq $n); do
     AT_CHECK([ovsdb-server -vraft -vconsole:warn --detach --no-chdir \
                   --log-file=s$i.log --pidfile=s$i.pid --unixctl=s$i \
                   --remote=punix:s$i.ovsdb                           \
                   m4_if([$2], [], [], [--remote=$2]) s$i.db])
   done

   for i in $(seq $n); do
       OVS_WAIT_UNTIL([ovs-appctl -t $(pwd)/s$i cluster/status ${schema_name} \
                                           | grep -q 'Status: cluster member'])
   done
])


# OVSDB_CHECK_IDL_C(TITLE, [PRE-IDL-TXN], TRANSACTIONS, OUTPUT, [KEYWORDS],
#                   [FILTER])
#
# Creates a database with a schema derived from idltest.ovsidl, runs
# each PRE-IDL-TXN (if any), starts an ovsdb-server on that database,
# and runs "test-ovsdb idl" passing each of the TRANSACTIONS along.
#
# Checks that the overall output is OUTPUT.  Before comparison, the
# output is sorted (using "sort") and UUIDs in the output are replaced
# by markers of the form <N> where N is a number.  The first unique
# UUID is replaced by <0>, the next by <1>, and so on.  If a given
# UUID appears more than once it is always replaced by the same
# marker.  If FILTER is supplied then the output is also filtered
# through the specified program.
#
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_IDL_C],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses OVSDB_IDL_WRITE_CHANGED_ONLY.
m4_define([OVSDB_CHECK_IDL_WRITE_CHANGED_ONLY_C],
  [AT_SETUP([$1 - write-changed-only - C])
   AT_KEYWORDS([ovsdb server idl positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 --write-changed-only idl unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses tcp.
m4_define([OVSDB_CHECK_IDL_TCP_C],
  [AT_SETUP([$1 - C - tcp])
   AT_KEYWORDS([ovsdb server idl positive tcp socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl tcp:127.0.0.1:$TCP_PORT $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses tcp6.
m4_define([OVSDB_CHECK_IDL_TCP6_C],
  [AT_SETUP([$1 - C - tcp6])
   AT_SKIP_IF([test "$IS_WIN32" = "yes"])
   AT_SKIP_IF([test $HAVE_IPV6 = no])
   AT_KEYWORDS([ovsdb server idl positive tcp6 socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact tcp:[[::1]]:$TCP_PORT $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl tcp:[[::1]]:$TCP_PORT $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses the Python IDL implementation.
m4_define([OVSDB_CHECK_IDL_PY],
  [AT_SETUP([$1 - Python3])
   AT_KEYWORDS([ovsdb server idl positive Python $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY],
  [AT_SETUP([$1 - Python3 - register_columns])
   AT_KEYWORDS([ovsdb server idl positive Python register_columns $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket ?simple:b,ba,i,ia,r,ra,s,sa,u,ua?simple3:name,uset,uref?simple4:name?simple6:name,weak_ref?link1:i,k,ka,l2?link2:i,l1?singleton:name $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses the Python IDL implementation with tcp
m4_define([OVSDB_CHECK_IDL_TCP_PY],
  [AT_SETUP([$1 - Python3 - tcp])
   AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema tcp:127.0.0.1:$TCP_PORT $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses the Python IDL implementation with tcp
# with multiple remotes with only one remote reachable
m4_define([OVSDB_CHECK_IDL_TCP_MULTIPLE_REMOTES_PY],
  [AT_SETUP([$1 - Python3 (multiple remotes) - tcp])
   AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   WRONG_PORT_1=$((TCP_PORT + 101))
   WRONG_PORT_2=$((TCP_PORT + 102))
   remote=tcp:127.0.0.1:$WRONG_PORT_1,tcp:127.0.0.1:$TCP_PORT,tcp:127.0.0.1:$WRONG_PORT_2
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact tcp:127.0.0.1:$TCP_PORT $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t20 idl $srcdir/idltest.ovsschema $remote $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses the Python IDL implementation with tcp6
m4_define([OVSDB_CHECK_IDL_TCP6_PY],
  [AT_SETUP([$1 - Python3 - tcp6])
   AT_SKIP_IF([test "$IS_WIN32" = "yes"])
   AT_SKIP_IF([test $HAVE_IPV6 = no])
   AT_KEYWORDS([ovsdb server idl positive Python with tcp6 socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   echo "TCP_PORT=$TCP_PORT"

   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact "tcp:[[::1]]:$TCP_PORT" $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema tcp:[[::1]]:$TCP_PORT $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_TCP6_MULTIPLE_REMOTES_PY],
  [AT_SETUP([$1 - Python3 - tcp6])
   AT_SKIP_IF([test "$IS_WIN32" = "yes"])
   AT_SKIP_IF([test $HAVE_IPV6 = no])
   AT_KEYWORDS([ovsdb server idl positive Python with tcp6 socket $5])
   OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   WRONG_PORT_1=$((TCP_PORT + 101))
   WRONG_PORT_2=$((TCP_PORT + 102))
   remote="tcp:[[::1]]:$WRONG_PORT_1,tcp:[[::1]]:$TCP_PORT,tcp:[[::1]]:$WRONG_PORT_2"
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact "tcp:[[::1]]:$TCP_PORT" $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t20 idl $srcdir/idltest.ovsschema $remote $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

# same as OVSDB_CHECK_IDL but uses the Python IDL implementation with SSL
m4_define([OVSDB_CHECK_IDL_SSL_PY],
  [AT_SETUP([$1 - Python3 - SSL])
   AT_SKIP_IF([test "$HAVE_OPENSSL" = no])
   $PYTHON3 -c "import ssl"
   SSL_PRESENT=$?
   AT_SKIP_IF([test $SSL_PRESENT != 0])
   AT_KEYWORDS([ovsdb server idl positive Python with ssl socket $5])
   AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema],
             [0], [stdout], [ignore])
   PKIDIR=$abs_top_builddir/tests
   AT_CHECK([ovsdb-server -vconsole:warn --log-file --detach --no-chdir \
             --pidfile \
             --private-key=$PKIDIR/testpki-privkey2.pem \
             --certificate=$PKIDIR/testpki-cert2.pem \
             --ca-cert=$PKIDIR/testpki-cacert.pem \
             --remote=pssl:0:127.0.0.1 db])
   on_exit 'kill `cat ovsdb-server.pid`'
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client \
                --private-key=$PKIDIR/testpki-privkey2.pem \
                --certificate=$PKIDIR/testpki-cert2.pem \
                --ca-cert=$PKIDIR/testpki-cacert.pem \
                transact "ssl:127.0.0.1:$TCP_PORT" $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema \
             ssl:127.0.0.1:$TCP_PORT $PKIDIR/testpki-privkey.pem \
             $PKIDIR/testpki-cert.pem $PKIDIR/testpki-cacert.pem $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL],
  [OVSDB_CHECK_IDL_C($@)
  OVSDB_CHECK_IDL_WRITE_CHANGED_ONLY_C($@)
   OVSDB_CHECK_IDL_TCP_C($@)
   OVSDB_CHECK_IDL_TCP6_C($@)
   OVSDB_CHECK_IDL_PY($@)
   OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY($@)
   OVSDB_CHECK_IDL_TCP_PY($@)
   OVSDB_CHECK_IDL_TCP_MULTIPLE_REMOTES_PY($@)
   OVSDB_CHECK_IDL_TCP6_PY($@)
   OVSDB_CHECK_IDL_TCP6_MULTIPLE_REMOTES_PY($@)
   OVSDB_CHECK_IDL_SSL_PY($@)])

# This test uses the Python IDL implementation with passive tcp
m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
  [AT_SETUP([$1 - Python3 - ptcp])
   AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
   # find free TCP port
   OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   OVSDB_SERVER_SHUTDOWN
   rm -f db

   # start OVSDB server in passive mode
   OVSDB_START_IDLTEST(["tcp:127.0.0.1:$TCP_PORT"])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl_passive $srcdir/idltest.ovsschema ptcp:127.0.0.1:$TCP_PORT $3],
      [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP
   ])

OVSDB_CHECK_IDL_PASSIVE_TCP_PY([simple passive idl, initially empty, select empty],
  [],
  [['["idltest",{"op":"select","table":"link1","where":[]}]']],
  [[000: empty
001: {"error":null,"result":[{"rows":[]}]}
002: done
]])

OVSDB_CHECK_IDL([simple idl, initially empty, no ops],
  [],
  [],
  [000: empty
001: done
])

OVSDB_CHECK_IDL([simple idl, initially empty, various ops],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": true}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"r": 123.5}}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": -1,
               "r": 125,
               "b": false,
               "s": "",
               "ia": ["set", [1]],
               "ra": ["set", [1.5]],
               "ba": ["set", [false]],
               "sa": ["set", []],
               "ua": ["set", []]}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [["i", "<", 1]],
       "row": {"s": "newstring"}}]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": [["i", "==", 0]]}]' \
    'reconnect']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
002: table simple: i=0 r=0 b=false s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
003: {"error":null,"result":[{"count":2}]}
004: table simple: i=0 r=0 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: table simple: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
005: {"error":null,"result":[{"count":2}]}
006: table simple: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
006: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
008: table simple: i=-1 r=125 b=false s= u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
008: table simple: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
008: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
009: {"error":null,"result":[{"count":2}]}
010: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
010: table simple: i=0 r=123.5 b=true s=newstring u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
010: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
011: {"error":null,"result":[{"count":1}]}
012: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
012: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
013: reconnect
014: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
014: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
015: done
]])

OVSDB_CHECK_IDL([simple idl, initially populated],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": true}}]']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
000: table simple: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
001: {"error":null,"result":[{"count":2}]}
002: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
003: done
]])

OVSDB_CHECK_IDL([simple idl, writing via IDL],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['verify 0 b, verify 1 r, set 0 b 1, set 1 r 3.5' \
    'insert 2, verify 2 i, verify 1 b, delete 1']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
000: table simple: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
001: commit, status=success
002: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=3.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<5>
003: commit, status=success
004: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: table simple: i=2 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<6>
005: done
]])

OVSDB_CHECK_IDL([simple idl, writing via IDL with unicode],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "(╯°□°)╯︵ ┻━┻"}}]']],
  [['set 0 b 1, insert 1, set 1 s "¯\_(ツ)_/¯"']],
  [[000: table simple: i=0 r=0 b=false s=(╯°□°)╯︵ ┻━┻ u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
001: commit, status=success
002: table simple: i=0 r=0 b=true s=(╯°□°)╯︵ ┻━┻ u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=0 b=false s="¯\_(ツ)_/¯" u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
003: done
]])

m4_define([OVSDB_CHECK_IDL_PY_WITH_EXPOUT],
  [AT_SETUP([$1 - Python3])
   AT_KEYWORDS([ovsdb server idl positive Python $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $3],
            [0], [stdout], [ignore])
   echo "$4" > expout
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [expout])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_PY_WITH_EXPOUT([simple idl, writing large data via IDL with unicode],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "'$(printf "测试超过四千零九十六个字节的中文字符串以使解码出现问题。%.0s" {1..50})'"}}]']],
  [['set 0 b 1, insert 1, set 1 s '$(printf "测试超过四千零九十六个字节的中文字符串以使解码出现问题。%.0s" {1..100})'']],
  [[000: table simple: i=0 r=0 b=false s=$(printf "测试超过四千零九十六个字节的中文字符串以使解码出现问题。%.0s" {1..50}) u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
001: commit, status=success
002: table simple: i=0 r=0 b=true s=$(printf "测试超过四千零九十六个字节的中文字符串以使解码出现问题。%.0s" {1..50}) u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=0 b=false s=$(printf "测试超过四千零九十六个字节的中文字符串以使解码出现问题。%.0s" {1..100}) u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
003: done]])

OVSDB_CHECK_IDL([simple idl, handling verification failure],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['set 0 b 1' \
    '+["idltest",
       {"op": "update",
        "table": "simple",
        "where": [["i", "==", 1]],
        "row": {"r": 5.0}}]' \
    '+verify 1 r, set 1 r 3' \
    'verify 1 r, set 1 r 3' \
    ]],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
000: table simple: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
001: commit, status=success
002: {"error":null,"result":[{"count":1}]}
003: commit, status=try again
004: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: table simple: i=1 r=5 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
005: commit, status=success
006: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
006: table simple: i=1 r=3 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
007: done
]])

OVSDB_CHECK_IDL([simple idl, increment operation],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['set 0 r 2.0, increment 0']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
001: commit, status=success, increment=1
002: table simple: i=1 r=2 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
003: done
]])

OVSDB_CHECK_IDL([simple idl, aborting],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['set 0 r 2.0, abort' \
'+set 0 b 1']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
001: commit, status=aborted
002: commit, status=success
003: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: done
]])

OVSDB_CHECK_IDL([simple idl, destroy without commit or abort],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['set 0 r 2.0, destroy' \
'+set 0 b 1']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
001: destroy
002: commit, status=success
003: table simple: i=0 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, false condition],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [true]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, true condition],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [true]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: done
]])

dnl This test ensures that the first explicitly set monitor condition
dnl is sent to the server.
OVSDB_CHECK_IDL([simple idl, conditional, wait for condition],
  [],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}}]' \
     'condition simple [true]' \
     '^["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 2,
               "r": 4.0,
               "b": true}}]']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
002: table simple: i=1 r=2 b=true s= u=<1> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
003: simple: conditions unchanged
004: {"error":null,"result":[{"uuid":["uuid","<2>"]}]}
005: table simple: i=1 r=2 b=true s= u=<1> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
005: table simple: i=2 r=4 b=true s= u=<1> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
006: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, multiple clauses in condition],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}},
       {"op": "insert",
       "table": "simple",
       "row": {"i": 2,
               "r": 3.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [["i","==",1],["i","==",2]]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
003: table simple: i=2 r=3 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
004: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, modify as insert due to condition],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [["i","==",1]]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, modify as delete due to condition],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [["i","==",1],["i","==",2]]' \
    'condition simple [["i","==",2]]' \
    '["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 2,
               "r": 3.0,
               "b": true}}]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: simple: change conditions
005: empty
006: {"error":null,"result":[{"uuid":["uuid","<2>"]}]}
007: table simple: i=2 r=3 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
008: done
]])

OVSDB_CHECK_IDL([simple idl, conditional, multiple tables],
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true}},
       {"op": "insert",
       "table": "link1",
       "row": {"i": 0, "k": ["named-uuid", "self"]},
       "uuid-name": "self"},
        {"op": "insert",
       "table": "link2",
       "row": {"i": 2},
       "uuid-name": "row0"}]']],
  [['condition simple [];link1 [];link2 []' \
    'condition simple [["i","==",1]]' \
    'condition link1 [["i","==",0]]' \
    'condition link2 [["i","==",3]]' \
    '+["idltest",
       {"op": "insert",
       "table": "link2",
       "row": {"i": 3},
        "uuid-name": "row0"}]']],
  [[000: link1: change conditions
000: link2: change conditions
000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: link1: change conditions
005: table link1: i=0 k=0 ka=[] l2= uuid=<2>
005: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
006: link2: change conditions
007: {"error":null,"result":[{"uuid":["uuid","<3>"]}]}
008: table link1: i=0 k=0 ka=[] l2= uuid=<2>
008: table link2: i=3 l1= uuid=<3>
008: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
009: done
]])

OVSDB_CHECK_IDL([self-linking idl, consistent ops],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 0, "k": ["named-uuid", "self"]},
       "uuid-name": "self"}]' \
    '["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 1, "k": ["named-uuid", "row2"]},
       "uuid-name": "row1"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 2, "k": ["named-uuid", "row1"]},
       "uuid-name": "row2"}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [["i", "==", 1]],
       "row": {"k": ["uuid", "#1#"]}}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [],
       "row": {"k": ["uuid", "#0#"]}}]']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
002: table link1: i=0 k=0 ka=[] l2= uuid=<0>
003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
004: table link1: i=0 k=0 ka=[] l2= uuid=<0>
004: table link1: i=1 k=2 ka=[] l2= uuid=<1>
004: table link1: i=2 k=1 ka=[] l2= uuid=<2>
005: {"error":null,"result":[{"count":1}]}
006: table link1: i=0 k=0 ka=[] l2= uuid=<0>
006: table link1: i=1 k=1 ka=[] l2= uuid=<1>
006: table link1: i=2 k=1 ka=[] l2= uuid=<2>
007: {"error":null,"result":[{"count":3}]}
008: table link1: i=0 k=0 ka=[] l2= uuid=<0>
008: table link1: i=1 k=0 ka=[] l2= uuid=<1>
008: table link1: i=2 k=0 ka=[] l2= uuid=<2>
009: done
]])

OVSDB_CHECK_IDL([self-linking idl, inconsistent ops],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 0, "k": ["uuid", "cf197cc5-c8c9-42f5-82d5-c71a9f2cb96b"]}}]' \
    '+["idltest",
      {"op": "insert",
       "table": "link1",
       "uuid-name": "one",
       "row": {"i": 1, "k": ["named-uuid", "one"]}},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 2, "k": ["named-uuid", "one"]}}]' \
     '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [],
       "row": {"k": ["uuid", "c2fca39a-e69a-42a4-9c56-5eca85839ce9"]}}]' \
     '+["idltest",
      {"op": "delete",
       "table": "link1",
       "where": [["_uuid", "==", ["uuid", "#1#"]]]}]' \
     '+["idltest",
      {"op": "delete",
       "table": "link1",
       "where": [["_uuid", "==", ["uuid", "#2#"]]]}]' \
     '["idltest",
      {"op": "delete",
       "table": "link1",
       "where": []}]' \
]],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"details":"Table link1 column k row <0> references nonexistent row <1> in table link1.","error":"referential integrity violation"}]}
002: {"error":null,"result":[{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
003: table link1: i=1 k=1 ka=[] l2= uuid=<2>
003: table link1: i=2 k=1 ka=[] l2= uuid=<3>
004: {"error":null,"result":[{"count":2},{"details":"Table link1 column k row <x> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
005: {"error":null,"result":[{"count":1},{"details":"cannot delete link1 row <2> because of 1 remaining reference(s)","error":"referential integrity violation"}]}
006: {"error":null,"result":[{"count":1}]}
007: table link1: i=1 k=1 ka=[] l2= uuid=<2>
008: {"error":null,"result":[{"count":1}]}
009: empty
010: done
]],
  [],
  [[sed -e '/004:/s/row <[23]> references/row <x> references/']])

OVSDB_CHECK_IDL([self-linking idl, sets],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 0, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i0"]]]},
       "uuid-name": "i0"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 1, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i1"]]]},
       "uuid-name": "i1"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 2, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i2"]]]},
       "uuid-name": "i2"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 3, "k": ["named-uuid", "i0"], "ka": ["set", [["named-uuid", "i3"]]]},
       "uuid-name": "i3"}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [],
       "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "#1#"], ["uuid", "#2#"], ["uuid", "#3#"]]]}}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [["i", "==", 2]],
       "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "88702e78-845b-4a6e-ad08-cf68922ae84a"], ["uuid", "#2#"]]]}}]' \
    '+["idltest",
      {"op": "delete",
       "table": "link1",
       "where": []}]']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
002: table link1: i=0 k=0 ka=[0] l2= uuid=<0>
002: table link1: i=1 k=0 ka=[1] l2= uuid=<1>
002: table link1: i=2 k=0 ka=[2] l2= uuid=<2>
002: table link1: i=3 k=0 ka=[3] l2= uuid=<3>
003: {"error":null,"result":[{"count":4}]}
004: table link1: i=0 k=0 ka=[0 1 2 3] l2= uuid=<0>
004: table link1: i=1 k=0 ka=[0 1 2 3] l2= uuid=<1>
004: table link1: i=2 k=0 ka=[0 1 2 3] l2= uuid=<2>
004: table link1: i=3 k=0 ka=[0 1 2 3] l2= uuid=<3>
005: {"error":null,"result":[{"count":1},{"details":"Table link1 column ka row <2> references nonexistent row <4> in table link1.","error":"referential integrity violation"}]}
006: {"error":null,"result":[{"count":4}]}
007: empty
008: done
]])

OVSDB_CHECK_IDL([external-linking idl, consistent ops],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link2",
       "row": {"i": 0},
       "uuid-name": "row0"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 1, "k": ["named-uuid", "row1"], "l2": ["set", [["named-uuid", "row0"]]]},
       "uuid-name": "row1"}]']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
002: table link1: i=1 k=1 ka=[] l2=0 uuid=<1>
002: table link2: i=0 l1= uuid=<0>
003: done
]])

OVSDB_CHECK_IDL([singleton idl, constraints],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "singleton",
       "row": {"name": "foo"}}]' \
    '["idltest",
      {"op": "insert",
       "table": "singleton",
       "row": {"name": "bar"}}]' \
    '+["idltest",
      {"op": "delete",
       "table": "singleton",
       "where": [["_uuid", "==", ["uuid", "#0#"]]]},
      {"op": "insert",
       "table": "singleton",
       "row": {"name": "bar"}}]']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
002: table singleton: name=foo uuid=<0>
003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"details":"transaction causes \"singleton\" table to contain 2 rows, greater than the schema-defined limit of 1 row(s)","error":"constraint violation"}]}
004: {"error":null,"result":[{"count":1},{"uuid":["uuid","<2>"]}]}
005: table singleton: name=bar uuid=<2>
006: done
]])

dnl This test creates a database with references and checks that deleting both
dnl source and destination rows of a reference in a single update doesn't leak
dnl rows that got orphaned when processing the update.
OVSDB_CHECK_IDL([simple idl, references, multiple deletes],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"},
       "uuid-name": "weak_row0"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "first_row",
               "weak_ref": ["set",
                             [["named-uuid", "weak_row0"]]
                           ]}}]']],
  [['["idltest",
      {"op": "delete",
       "table": "simple",
       "where": [["s", "==", "row0_s"]]},
      {"op": "delete",
       "table": "simple6",
       "where": [["name", "==", "first_row"]]}]']],
  [[000: table simple6: name=first_row weak_ref=[<0>] uuid=<1>
000: table simple: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
001: {"error":null,"result":[{"count":1},{"count":1}]}
002: empty
003: done
]])

OVSDB_CHECK_IDL_PY([external-linking idl, insert ops],
  [],
  [['linktest']],
  [[000: empty
001: commit, status=success
002: table link1: i=1 k=1 ka=[1] l2= uuid=<0>
002: table link1: i=2 k=1 ka=[1 2] l2= uuid=<1>
003: done
]])

OVSDB_CHECK_IDL_PY([getattr idl, insert ops],
  [],
  [['getattrtest']],
  [[000: empty
001: commit, status=success
002: table link1: i=2 k=2 ka=[] l2= uuid=<0>
003: done
]])

OVSDB_CHECK_IDL_PY([row-from-json idl, whats this],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['notifytest insert 2, notifytest set 1 b 1, notifytest delete 0']],
  [[000: table simple: i=0 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
000: table simple: i=1 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
001: commit, status=success, events=create|2|None, delete|0|None, update|1|b
002: table simple: i=1 r=0 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
002: table simple: i=2 r=0 b=false s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
003: done
]])

AT_SETUP([idl handling of missing tables and columns - C])
AT_KEYWORDS([ovsdb server idl positive])

# idltest2.ovsschema is the same as idltest.ovsschema, except that
# table link2 and column l2 have been deleted.  But the IDL still
# expects them to be there, so this test checks that it properly
# tolerates them being missing.
OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest2.ovsschema"])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket ['["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 0, "k": ["named-uuid", "self"]},
       "uuid-name": "self"}]' \
    '["idltest",
      {"op": "insert",
       "table": "link1",
       "row": {"i": 1, "k": ["named-uuid", "row2"]},
       "uuid-name": "row1"},
      {"op": "insert",
       "table": "link1",
       "row": {"i": 2, "k": ["named-uuid", "row1"]},
       "uuid-name": "row2"}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [["i", "==", 1]],
       "row": {"k": ["uuid", "#1#"]}}]' \
    '["idltest",
      {"op": "update",
       "table": "link1",
       "where": [],
       "row": {"k": ["uuid", "#0#"]}}]']],
         [0], [stdout], [stderr])
AT_CHECK([sort stdout | uuidfilt], [0],
    [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
002: table link1: i=0 k=0 ka=[] l2= uuid=<0>
003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
004: table link1: i=0 k=0 ka=[] l2= uuid=<0>
004: table link1: i=1 k=2 ka=[] l2= uuid=<1>
004: table link1: i=2 k=1 ka=[] l2= uuid=<2>
005: {"error":null,"result":[{"count":1}]}
006: table link1: i=0 k=0 ka=[] l2= uuid=<0>
006: table link1: i=1 k=1 ka=[] l2= uuid=<1>
006: table link1: i=2 k=1 ka=[] l2= uuid=<2>
007: {"error":null,"result":[{"count":3}]}
008: table link1: i=0 k=0 ka=[] l2= uuid=<0>
008: table link1: i=1 k=0 ka=[] l2= uuid=<1>
008: table link1: i=2 k=0 ka=[] l2= uuid=<2>
009: done
]])

# Check that ovsdb-idl figured out that table link2 and column l2 are missing.
AT_CHECK([grep ovsdb_idl stderr | sort], [0], [dnl
test-ovsdb|ovsdb_idl|idltest database lacks indexed table (database needs upgrade?)
test-ovsdb|ovsdb_idl|idltest database lacks link2 table (database needs upgrade?)
test-ovsdb|ovsdb_idl|idltest database lacks simple5 table (database needs upgrade?)
test-ovsdb|ovsdb_idl|idltest database lacks simple6 table (database needs upgrade?)
test-ovsdb|ovsdb_idl|idltest database lacks singleton table (database needs upgrade?)
test-ovsdb|ovsdb_idl|link1 table in idltest database lacks l2 column (database needs upgrade?)
test-ovsdb|ovsdb_idl|simple7 table in idltest database lacks id column (database needs upgrade?)
])

# Check that ovsdb-idl sent on "monitor" request and that it didn't
# mention that table or column, and (for paranoia) that it did mention another
# table and column.
AT_CHECK([grep -c '"monitor\|monitor_cond"' stderr], [0], [2
])
AT_CHECK([grep '"monitor\|monitor_cond"' stderr | grep link2], [1])
AT_CHECK([grep '"monitor\|monitor_cond"' stderr | grep l2], [1])
AT_CHECK([grep '"monitor\|monitor_cond"' stderr | grep -c '"link1"'], [0], [1
])
AT_CHECK([grep '"monitor\|monitor_cond"' stderr | grep -c '"ua"'], [0], [1
])
OVSDB_SERVER_SHUTDOWN
AT_CLEANUP

m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PY],
  [AT_SETUP([$1 - Python3 - fetch])
   AT_KEYWORDS([ovsdb server idl positive Python increment fetch $6])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket [$3] $4],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$7],,, [[| $7]]),
            [0], [$5])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS],
   [OVSDB_CHECK_IDL_FETCH_COLUMNS_PY($@)])

OVSDB_CHECK_IDL_FETCH_COLUMNS([simple idl, initially populated],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [?simple:i,r!],
  ['fetch 0 r'],
  [[000: table simple: i=0 uuid=<0>
000: table simple: i=1 uuid=<1>
001: commit, status=success
002: table simple: i=0 r=0 uuid=<0>
002: table simple: i=1 uuid=<1>
003: done
]])

m4_define([OVSDB_CHECK_IDL_WO_MONITOR_COND_PY],
  [AT_SETUP([$1 - Python3])
   AT_KEYWORDS([ovsdb server idl Python monitor $4])
   OVSDB_START_IDLTEST
   AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/disable-monitor-cond])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $2],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$5],,, [[| $5]]),
            [0], [$3])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_WO_MONITOR_COND],
   [OVSDB_CHECK_IDL_WO_MONITOR_COND_PY($@)])


OVSDB_CHECK_IDL_WO_MONITOR_COND([simple idl disable monitor-cond],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": true}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"r": 123.5}}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": -1,
               "r": 125,
               "b": false,
               "s": "",
               "ia": ["set", [1]],
               "ra": ["set", [1.5]],
               "ba": ["set", [false]],
               "sa": ["set", []],
               "ua": ["set", []]}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [["i", "<", 1]],
       "row": {"s": "newstring"}}]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": [["i", "==", 0]]}]' \
    'reconnect']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
002: table simple: i=0 r=0 b=false s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
002: table simple: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
003: {"error":null,"result":[{"count":2}]}
004: table simple: i=0 r=0 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: table simple: i=1 r=2 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
005: {"error":null,"result":[{"count":2}]}
006: table simple: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
006: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
008: table simple: i=-1 r=125 b=false s= u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
008: table simple: i=0 r=123.5 b=true s= u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
008: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
009: {"error":null,"result":[{"count":2}]}
010: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
010: table simple: i=0 r=123.5 b=true s=newstring u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
010: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
011: {"error":null,"result":[{"count":1}]}
012: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
012: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
013: reconnect
014: table simple: i=-1 r=125 b=false s=newstring u=<2> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
014: table simple: i=1 r=123.5 b=true s=mystring u=<3> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<4> <5>] uuid=<0>
015: done
]])

m4_define([OVSDB_CHECK_IDL_TRACK_C],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl tracking positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_TRACK_WRITE_CHANGED_ONLY_C],
  [AT_SETUP([$1 - write-changed-only - C])
   AT_KEYWORDS([ovsdb server idl tracking positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c --write-changed-only idl unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_TRACK],
  [OVSDB_CHECK_IDL_TRACK_C($@)
   OVSDB_CHECK_IDL_TRACK_WRITE_CHANGED_ONLY_C($@)])

OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]']],
  [['["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": true}}]']],
  [[000: table simple: inserted row: i=1 r=2 b=true s=mystring u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<1> <2>] uuid=<3>
000: table simple: updated columns: b ba i ia r ra s sa u ua
001: {"error":null,"result":[{"count":2}]}
002: table simple: i=0 r=0 b=true s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<5>
002: table simple: i=1 r=2 b=true s=mystring u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<1> <2>] uuid=<3>
002: table simple: updated columns: b
003: done
]])

dnl This test creates database with weak references and checks that orphan
dnl rows created for weak references are not available for iteration via
dnl list of tracked changes.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, orphan weak references],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"},
       "uuid-name": "weak_row0"},
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row1_s"},
       "uuid-name": "weak_row1"},
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row2_s"},
       "uuid-name": "weak_row2"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "first_row",
               "weak_ref": ["set",
                             [["named-uuid", "weak_row0"],
                              ["named-uuid", "weak_row1"],
                              ["named-uuid", "weak_row2"]]
                           ]}}]']],
  [['condition simple []' \
    'condition simple [["s","==","row1_s"]]' \
    '["idltest",
      {"op": "update",
      "table": "simple6",
      "where": [],
      "row": {"name": "new_name"}}]' \
    '["idltest",
      {"op": "delete",
      "table": "simple6",
      "where": []}]']],
  [[000: simple: change conditions
001: table simple6: inserted row: name=first_row weak_ref=[] uuid=<0>
001: table simple6: updated columns: name weak_ref
002: simple: change conditions
003: table simple6: name=first_row weak_ref=[<1>] uuid=<0>
003: table simple: inserted row: i=0 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
003: table simple: updated columns: s
004: {"error":null,"result":[{"count":1}]}
005: table simple6: name=new_name weak_ref=[<1>] uuid=<0>
005: table simple6: updated columns: name
006: {"error":null,"result":[{"count":1}]}
007: table simple: i=0 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
008: done
]])

dnl This test creates database with weak references and checks that the
dnl content of orphaned rows created for weak references after monitor
dnl condition change are not leaked when the row is reinserted and deleted.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, orphan rows, conditional],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"},
       "uuid-name": "weak_row0"},
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row1_s"},
       "uuid-name": "weak_row1"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "first_row",
               "weak_ref": ["set",
                             [["named-uuid", "weak_row0"]]
                           ]}}]']],
  [['condition simple []' \
    'condition simple [["s","==","row0_s"]]' \
    'condition simple [["s","==","row1_s"]]' \
    'condition simple [["s","==","row0_s"]]' \
    '["idltest",
      {"op": "delete",
      "table": "simple6",
      "where": []}]']],
  [[000: simple: change conditions
001: table simple6: inserted row: name=first_row weak_ref=[] uuid=<0>
001: table simple6: updated columns: name weak_ref
002: simple: change conditions
003: table simple6: name=first_row weak_ref=[<1>] uuid=<0>
003: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
003: table simple: updated columns: s
004: simple: change conditions
005: table simple6: name=first_row weak_ref=[] uuid=<0>
005: table simple: deleted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
005: table simple: inserted row: i=0 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
005: table simple: updated columns: s
006: simple: change conditions
007: table simple6: name=first_row weak_ref=[<1>] uuid=<0>
007: table simple: deleted row: i=0 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
007: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
007: table simple: updated columns: s
008: {"error":null,"result":[{"count":1}]}
009: table simple: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
010: done
]])

dnl This test checks that deleting the destination of a weak reference
dnl without deleting the source, through monitor condition change, updates
dnl the source tracked record.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, references, conditional delete],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s", "i": 0},
       "uuid-name": "weak_row0"},
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row1_s", "i": 1},
       "uuid-name": "weak_row1"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "first_row",
               "weak_ref": ["set",
                             [["named-uuid", "weak_row0"],
                              ["named-uuid", "weak_row1"]]
                           ]}}]']],
  [['condition simple []' \
    'condition simple [["s","==","row0_s"]]' \
    'condition simple [["s","==","row1_s"]]' \
    '["idltest",
      {"op": "update",
      "table": "simple6",
      "where": [],
      "row": {"name": "new_name"}}]' \
    '["idltest",
      {"op": "delete",
      "table": "simple6",
      "where": []}]']],
  [[000: simple: change conditions
001: table simple6: inserted row: name=first_row weak_ref=[] uuid=<0>
001: table simple6: updated columns: name weak_ref
002: simple: change conditions
003: table simple6: name=first_row weak_ref=[<1>] uuid=<0>
003: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
003: table simple: updated columns: s
004: simple: change conditions
005: table simple6: name=first_row weak_ref=[<3>] uuid=<0>
005: table simple: deleted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
005: table simple: inserted row: i=1 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
005: table simple: updated columns: i s
006: {"error":null,"result":[{"count":1}]}
007: table simple6: name=new_name weak_ref=[<3>] uuid=<0>
007: table simple6: updated columns: name
008: {"error":null,"result":[{"count":1}]}
009: table simple: i=1 r=0 b=false s=row1_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
010: done
]])

dnl This test checks that deleting the destination of a reference updates the
dnl source tracked record.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, references, single delete],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"},
       "uuid-name": "uuid_row0_s"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "row0_s6",
               "weak_ref": ["set",
                             [["named-uuid", "uuid_row0_s"]]
                           ]}}]']],
  [['condition simple [true];simple6 [true]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": []}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"}}]']],
  [[000: simple6: conditions unchanged
000: simple: conditions unchanged
001: table simple6: inserted row: name=row0_s6 weak_ref=[<0>] uuid=<1>
001: table simple6: updated columns: name weak_ref
001: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
001: table simple: updated columns: s
002: {"error":null,"result":[{"count":1}]}
003: table simple6: name=row0_s6 weak_ref=[] uuid=<1>
003: table simple6: updated columns: weak_ref
003: table simple: deleted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
004: {"error":null,"result":[{"uuid":["uuid","<3>"]}]}
005: table simple6: name=row0_s6 weak_ref=[] uuid=<1>
005: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
005: table simple: updated columns: s
006: done
]])

dnl This test checks that deleting both the destination and source of the
dnl reference doesn't remove the reference in the source tracked record.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, weak references, multiple deletes],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"},
       "uuid-name": "uuid_row0_s"},
      {"op": "insert",
       "table": "simple6",
       "row": {"name": "row0_s6",
               "weak_ref": ["set",
                             [["named-uuid", "uuid_row0_s"]]
                           ]}}]']],
  [['condition simple [true];simple6 [true]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": []},
      {"op": "delete",
       "table": "simple6",
       "where": []}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"}}]']],
  [[000: simple6: conditions unchanged
000: simple: conditions unchanged
001: table simple6: inserted row: name=row0_s6 weak_ref=[<0>] uuid=<1>
001: table simple6: updated columns: name weak_ref
001: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
001: table simple: updated columns: s
002: {"error":null,"result":[{"count":1},{"count":1}]}
003: table simple6: deleted row: name=row0_s6 weak_ref=[<0>] uuid=<1>
003: table simple: deleted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<0>
004: {"error":null,"result":[{"uuid":["uuid","<3>"]}]}
005: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<2> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
005: table simple: updated columns: s
006: done
]])

dnl This test checks that deleting both the destination and source of the
dnl reference doesn't remove the reference in the source tracked record.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, strong references, multiple deletes],
  [['["idltest",
      {"op": "insert",
       "table": "simple4",
       "row": {"name": "row0_s4"},
       "uuid-name": "uuid_row0_s4"},
      {"op": "insert",
       "table": "simple3",
       "row": {"name": "row0_s3",
               "uref": ["set",
                         [["named-uuid", "uuid_row0_s4"]]
                       ]}}]']],
  [['condition simple [true];simple3 [true];simple4 [true]' \
    '["idltest",
      {"op": "delete",
       "table": "simple3",
       "where": []},
      {"op": "delete",
       "table": "simple4",
       "where": []}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"}}]']],
  [[000: simple3: conditions unchanged
000: simple4: conditions unchanged
000: simple: conditions unchanged
001: table simple3: inserted row: name=row0_s3 uset=[] uref=[<0>] uuid=<1>
001: table simple3: updated columns: name uref
001: table simple4: inserted row: name=row0_s4 uuid=<0>
001: table simple4: updated columns: name
002: {"error":null,"result":[{"count":1},{"count":1}]}
003: table simple3: deleted row: name=row0_s3 uset=[] uref=[<0>] uuid=<1>
003: table simple4: deleted row: name=row0_s4 uuid=<0>
004: {"error":null,"result":[{"uuid":["uuid","<2>"]}]}
005: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<3> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
005: table simple: updated columns: s
006: done
]])

dnl This test checks that changing conditions to not include the target of
dnl a strong reference also updates the source row when change tracking is
dnl enabled.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially populated, strong references, conditional],
  [['["idltest",
      {"op": "insert",
       "table": "simple4",
       "row": {"name": "row0_s4"},
       "uuid-name": "uuid_row0_s4"},
      {"op": "insert",
       "table": "simple3",
       "row": {"name": "row0_s3",
               "uref": ["set",
                         [["named-uuid", "uuid_row0_s4"]]
                       ]}}]']],
  [['condition simple [true];simple3 [true];simple4 [true]' \
    'condition simple4 []' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"}}]']],
  [[000: simple3: conditions unchanged
000: simple4: conditions unchanged
000: simple: conditions unchanged
001: table simple3: inserted row: name=row0_s3 uset=[] uref=[<0>] uuid=<1>
001: table simple3: updated columns: name uref
001: table simple4: inserted row: name=row0_s4 uuid=<0>
001: table simple4: updated columns: name
002: simple4: change conditions
003: table simple3: name=row0_s3 uset=[] uref=[] uuid=<1>
003: table simple4: deleted row: name=row0_s4 uuid=<0>
004: {"error":null,"result":[{"uuid":["uuid","<2>"]}]}
005: table simple3: name=row0_s3 uset=[] uref=[] uuid=<1>
005: table simple: inserted row: i=0 r=0 b=false s=row0_s u=<3> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
005: table simple: updated columns: s
006: done
]])

dnl This test checks that changing conditions to not include the target of
dnl a strong reference also updates the source row when change tracking is
dnl disabled.
OVSDB_CHECK_IDL([simple idl, initially populated, strong references, conditional],
  [['["idltest",
      {"op": "insert",
       "table": "simple4",
       "row": {"name": "row0_s4"},
       "uuid-name": "uuid_row0_s4"},
      {"op": "insert",
       "table": "simple3",
       "row": {"name": "row0_s3",
               "uref": ["set",
                         [["named-uuid", "uuid_row0_s4"]]
                       ]}}]']],
  [['condition simple [true];simple3 [true];simple4 [true]' \
    'condition simple4 []' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"s": "row0_s"}}]']],
  [[000: simple3: conditions unchanged
000: simple4: conditions unchanged
000: simple: conditions unchanged
001: table simple3: name=row0_s3 uset=[] uref=[<0>] uuid=<1>
001: table simple4: name=row0_s4 uuid=<0>
002: simple4: change conditions
003: table simple3: name=row0_s3 uset=[] uref=[] uuid=<1>
004: {"error":null,"result":[{"uuid":["uuid","<2>"]}]}
005: table simple3: name=row0_s3 uset=[] uref=[] uuid=<1>
005: table simple: i=0 r=0 b=false s=row0_s u=<3> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
006: done
]])

dnl This test checks that deleting a row that refers to a row that was inserted
dnl in the current IDL run works properly.
OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, strong references, insert and delete],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link1",
       "uuid-name": "uuid_l1",
       "row": {"i": 1, "k": ["named-uuid", "uuid_l1"]}},
      {"op": "insert",
       "table": "link2",
       "row": {"i": 2, "l1": ["set", [["named-uuid", "uuid_l1"]]]}}
      ]' \
    '+["idltest",
      {"op": "delete",
       "table": "link2",
       "where": [["i", "==", 2]]}]'
  ]],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
002: {"error":null,"result":[{"count":1}]}
003: table link1: inserted row: i=1 k=1 ka=[] l2= uuid=<0>
003: table link1: updated columns: i k
004: done
]])

OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, various ops],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": true}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"r": 123.5}}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": -1,
               "r": 125,
               "b": false,
               "s": "",
               "ia": ["set", [1]],
               "ra": ["set", [1.5]],
               "ba": ["set", [false]],
               "sa": ["set", []],
               "ua": ["set", []]}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [["i", "<", 1]],
       "row": {"s": "newstring"}}]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": [["i", "==", 0]]}]' \
    'reconnect']],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]}
002: table simple: inserted row: i=1 r=2 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
002: table simple: updated columns: b ba i ia r ra s sa u ua
003: {"error":null,"result":[{"count":2}]}
004: table simple: i=0 r=0 b=true s= u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: table simple: updated columns: b
005: {"error":null,"result":[{"count":2}]}
006: table simple: i=0 r=123.5 b=true s= u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
006: table simple: i=1 r=123.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
006: table simple: updated columns: r
006: table simple: updated columns: r
007: {"error":null,"result":[{"uuid":["uuid","<6>"]}]}
008: table simple: inserted row: i=-1 r=125 b=false s= u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
008: table simple: updated columns: ba i ia r ra
009: {"error":null,"result":[{"count":2}]}
010: table simple: i=-1 r=125 b=false s=newstring u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
010: table simple: i=0 r=123.5 b=true s=newstring u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
010: table simple: updated columns: s
010: table simple: updated columns: s
011: {"error":null,"result":[{"count":1}]}
012: table simple: deleted row: i=0 r=123.5 b=true s=newstring u=<5> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
013: reconnect
014: table simple: inserted row: i=-1 r=125 b=false s=newstring u=<5> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<6>
014: table simple: inserted row: i=1 r=123.5 b=true s=mystring u=<2> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<0>
014: table simple: updated columns: b ba i ia r ra s sa u ua
014: table simple: updated columns: ba i ia r ra s
015: done
]])

m4_define([OVSDB_CHECK_IDL_PARTIAL_UPDATE_MAP_COLUMN],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl partial update map column positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-partial-update-map-column unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_PARTIAL_UPDATE_MAP_COLUMN([map, simple2 idl-partial-update-map-column, initially populated],
[['["idltest", {"op":"insert", "table":"simple2",
                "row":{"name":"myString1","smap":["map",[["key1","value1"],["key2","value2"]]]} }]']
],
[],
[[000: Getting records
001: name=myString1 smap=[[key1 : value1],[key2 : value2]] imap=[]
002: After insert element
003: name=String2 smap=[[key1 : myList1],[key2 : value2]] imap=[[3 : myids2]]
004: After insert duplicated element
005: name=String2 smap=[[key1 : myList1],[key2 : value2]] imap=[[3 : myids2]]
006: After delete element
007: name=String2 smap=[[key2 : value2]] imap=[[3 : myids2]]
008: After trying to delete a deleted element
009: name=String2 smap=[[key2 : value2]] imap=[[3 : myids2]]
010: End test
]])

OVSDB_CHECK_IDL_PY([partial-map idl],
[['["idltest", {"op":"insert", "table":"simple2",
                "row":{"name":"myString1","smap":["map",[["key1","value1"],["key2","value2"]]]} }]']
],
  [?simple2:name,smap,imap 'partialmapinsertelement' 'partialmapinsertmultipleelements' 'partialmapdelelements' 'partialmapmutatenew'],
[[000: table simple2: name=myString1 smap=[(key1 value1) (key2 value2)] imap=[] uuid=<0>
001: commit, status=success
002: table simple2: name=String2 smap=[(key1 myList1) (key2 value2)] imap=[(3 myids2)] uuid=<0>
003: commit, status=success
004: table simple2: name=String2 smap=[(key1 myList1) (key2 myList2) (key3 myList3) (key4 myList4)] imap=[(3 myids2)] uuid=<0>
005: commit, status=success
006: table simple2: name=String2 smap=[(key2 myList2)] imap=[(3 myids2)] uuid=<0>
007: commit, status=success
008: table simple2: name=String2 smap=[(key2 myList2)] imap=[(3 myids2)] uuid=<0>
008: table simple2: name=String2New smap=[(key1 newList1) (key2 newList2)] imap=[] uuid=<1>
009: done
]])

OVSDB_CHECK_IDL_PY([partial-map update set refmap idl],
[['["idltest", {"op":"insert", "table":"simple3", "row":{"name":"myString1"}},
               {"op":"insert", "table":"simple5", "row":{"name":"myString2"}}]']],
['partialmapmutateirefmap'],
[[000: table simple3: name=myString1 uset=[] uref=[] uuid=<0>
000: table simple5: name=myString2 irefmap=[] uuid=<1>
001: commit, status=success
002: table simple3: name=myString1 uset=[] uref=[] uuid=<0>
002: table simple5: name=myString2 irefmap=[(1 <0>)] uuid=<1>
003: done
]])

m4_define([OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl partial update set column positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-partial-update-set-column unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN([set, simple3 idl-partial-update-set-column, initially populated],
[['["idltest", {"op":"insert", "table":"simple3",
                "row":{"name":"mySet1","uset":["set", [[ "uuid", "0005b872-f9e5-43be-ae02-3184b9680e75" ], [ "uuid", "000d2f6a-76af-412f-b59d-e7bcd3e84eff" ]]]} }]']
],
[],
[[000: Getting records
001: table simple3: name=mySet1 uset=[<0>,<1>] uref=[] uuid=<2>
002: After rename+add new value
003: table simple3: name=String2 uset=[<0>,<1>,<3>] uref=[] uuid=<2>
004: After add new value
005: table simple3: name=String2 uset=[<0>,<1>,<3>,<4>] uref=[] uuid=<2>
006: After delete value
007: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[] uuid=<2>
008: After trying to delete a deleted value
009: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[] uuid=<2>
010: After add to other table + set of strong ref
011: table simple3: name=String2 uset=[<0>,<1>,<4>] uref=[<5>] uuid=<2>
012: End test
]])

OVSDB_CHECK_IDL_PY([partial-set idl],
[['["idltest", {"op":"insert", "table":"simple3", "uuid-name":"newrow",
                    "row":{"name":"mySet1","uset":["set", [[ "uuid", "0005b872-f9e5-43be-ae02-3184b9680e75" ]]]} },
               {"op":"insert", "table":"simple4", "row":{"name":"seed"}},
               {"op":"mutate", "table":"simple3", "where":[["_uuid", "==", ["named-uuid", "newrow"]]],
                    "mutations": [["uset", "insert", ["set", [["uuid", "000d2f6a-76af-412f-b59d-e7bcd3e84eff"]]]]]}]']
],
  ['partialrenamesetadd' 'partialduplicateadd' 'partialsetdel' 'partialsetref' 'partialsetoverrideops' 'partialsetadddelete' 'partialsetmutatenew'],
[[000: table simple3: name=mySet1 uset=[<0> <1>] uref=[] uuid=<2>
001: commit, status=success
002: table simple3: name=String2 uset=[<0> <1> <3>] uref=[] uuid=<2>
003: commit, status=success
004: table simple3: name=String2 uset=[<0> <1> <3> <4>] uref=[] uuid=<2>
005: commit, status=success
006: table simple3: name=String2 uset=[<0> <1> <4>] uref=[] uuid=<2>
007: commit, status=success
008: table simple3: name=String2 uset=[<0> <1> <4>] uref=[<5>] uuid=<2>
008: table simple4: name=test uuid=<5>
009: commit, status=success
010: table simple3: name=String2 uset=[<4>] uref=[<5>] uuid=<2>
010: table simple4: name=test uuid=<5>
011: commit, status=success
012: table simple3: name=String2 uset=[<6> <7>] uref=[<5>] uuid=<2>
012: table simple4: name=test uuid=<5>
013: commit, status=success
014: table simple3: name=String2 uset=[<6> <7>] uref=[<5>] uuid=<2>
014: table simple3: name=String3 uset=[<8>] uref=[] uuid=<9>
014: table simple4: name=test uuid=<5>
015: done
]])

m4_define([OVSDB_CHECK_IDL_NOTIFY],
   [OVSDB_CHECK_IDL_PY([$1], [], [$2], [$3], [notify $4], [$5])
    OVSDB_CHECK_IDL_SSL_PY([$1], [], [$2], [$3], [notify $4], [$5])])

OVSDB_CHECK_IDL_NOTIFY([simple link idl verify notify],
  [['track-notify' \
    '["idltest",
       {"op": "insert",
       "table": "link1",
       "row": {"i": 1, "k": ["named-uuid", "l1row"], "l2": ["set", [["named-uuid", "l2row"]]]},
       "uuid-name": "l1row"},
      {"op": "insert",
       "table": "link2",
       "uuid-name": "l2row",
       "row": {"i": 2, "l1": ["set", [["named-uuid", "l1row"]]]}}]']],
[[000: empty
000: event:create, row={}, uuid=<0>, updates=None
000: event:create, row={}, uuid=<1>, updates=None
001: {"error":null,"result":[{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
002: event:create, row={i=1 l2=[<3>]}, uuid=<2>, updates=None
002: event:create, row={i=2 l1=[<2>]}, uuid=<3>, updates=None
002: table link1: i=1 k=1 ka=[] l2=2 uuid=<2>
002: table link2: i=2 l1=1 uuid=<3>
003: done
]])

OVSDB_CHECK_IDL_NOTIFY([simple idl verify notify],
  [['track-notify' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 2.0,
               "b": true,
               "s": "mystring",
               "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"],
               "ia": ["set", [1, 2, 3]],
               "ra": ["set", [-0.5]],
               "ba": ["set", [true]],
               "sa": ["set", ["abc", "def"]],
               "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"],
                              ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}},
      {"op": "insert",
       "table": "simple",
       "row": {}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"b": false}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [],
       "row": {"r": 123.5}}]' \
    '["idltest",
      {"op": "insert",
       "table": "simple",
       "row": {"i": -1,
               "r": 125,
               "b": false,
               "s": "",
               "ia": ["set", [1]],
               "ra": ["set", [1.5]],
               "ba": ["set", [false]],
               "sa": ["set", []],
               "ua": ["set", []]}}]' \
    '["idltest",
      {"op": "update",
       "table": "simple",
       "where": [["i", "<", 1]],
       "row": {"s": "newstring"}}]' \
    '["idltest",
      {"op": "delete",
       "table": "simple",
       "where": [["i", "==", 0]]}]' \
    'reconnect']],
  [[000: empty
000: event:create, row={}, uuid=<0>, updates=None
000: event:create, row={}, uuid=<1>, updates=None
001: {"error":null,"result":[{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]}
002: event:create, row={i=0 r=0 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[]}, uuid=<3>, updates=None
002: event:create, row={i=1 r=2 b=true s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>]}, uuid=<2>, updates=None
002: table simple: i=0 r=0 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
002: table simple: i=1 r=2 b=true s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
003: {"error":null,"result":[{"count":2}]}
004: event:update, row={i=1 r=2 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>]}, uuid=<2>, updates={b=true}
004: table simple: i=0 r=0 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
004: table simple: i=1 r=2 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
005: {"error":null,"result":[{"count":2}]}
006: event:update, row={i=0 r=123.5 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[]}, uuid=<3>, updates={r=0}
006: event:update, row={i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>]}, uuid=<2>, updates={r=2}
006: table simple: i=0 r=123.5 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
006: table simple: i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
007: {"error":null,"result":[{"uuid":["uuid","<8>"]}]}
008: event:create, row={i=-1 r=125 b=false s= u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[]}, uuid=<8>, updates=None
008: table simple: i=-1 r=125 b=false s= u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<8>
008: table simple: i=0 r=123.5 b=false s= u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
008: table simple: i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
009: {"error":null,"result":[{"count":2}]}
010: event:update, row={i=-1 r=125 b=false s=newstring u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[]}, uuid=<8>, updates={s=}
010: event:update, row={i=0 r=123.5 b=false s=newstring u=<4> ia=[] ra=[] ba=[] sa=[] ua=[]}, uuid=<3>, updates={s=}
010: table simple: i=-1 r=125 b=false s=newstring u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<8>
010: table simple: i=0 r=123.5 b=false s=newstring u=<4> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<3>
010: table simple: i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
011: {"error":null,"result":[{"count":1}]}
012: event:delete, row={i=0 r=123.5 b=false s=newstring u=<4> ia=[] ra=[] ba=[] sa=[] ua=[]}, uuid=<3>, updates=None
012: table simple: i=-1 r=125 b=false s=newstring u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<8>
012: table simple: i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
013: reconnect
014: event:create, row={i=-1 r=125 b=false s=newstring u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[]}, uuid=<8>, updates=None
014: event:create, row={i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>]}, uuid=<2>, updates=None
014: event:create, row={}, uuid=<0>, updates=None
014: event:create, row={}, uuid=<1>, updates=None
014: table simple: i=-1 r=125 b=false s=newstring u=<4> ia=[1] ra=[1.5] ba=[false] sa=[] ua=[] uuid=<8>
014: table simple: i=1 r=123.5 b=false s=mystring u=<5> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<6> <7>] uuid=<2>
015: done
]])

# Tests to verify the functionality of the one column compound index.
# It tests index for one column string and integer indexes.
# The run of test-ovsdb generates the output of the display of data using the different indexes defined in
# the program.
# Then, some at_checks are used to verify the correctness of the corresponding index as well as the existence
# of all the rows involved in the test.
m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl compound_index_single_column compound_index positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
# Generate the data to be tested.
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-compound-index unix:socket $3],
            [0], [stdout], [ignore])
# Filter the rows of data that corresponds to the string index eliminating the extra columns of data.
# This is done to verifiy that the output data is in the correct and expected order.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: s=.*' | sed -e 's/ i=.*//g']],
            [0], [$4])
# Here, the data is filtered and sorted in order to have all the rows in the index and be
# able to determined that all the involved rows are present.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: s=.*' | sort -k 1,1n -k 2,2 -k 3,3]],
            [0], [$5])
# Filter the rows of data that corresponds to the integer index eliminating the extra columns of data.
# This is done to verifiy that the output data is in the correct and expected order.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: i=.*' | sed -e 's/ s=.*//g']],
            [0], [$6])
# Here again, the data is filtered and sorted in order to have all the rows in the index and be
# able to determined that all the involved rows are present.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: i=.*' | sort -k 1,1n -k 2,2 -k 3,3]],
            [0], [$7])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C([Compound_index, single column test ],
    [['["idltest",
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 1, "b":true, "r":101.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 2, "b":false, "r":102.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 10, "b":true, "r":110.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 1, "b":false, "r":110.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 2, "b":true, "r":120.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 2, "b":true, "r":122.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 4, "b":true, "r":130.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List005", "i": 5, "b":true, "r":130.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List020", "i": 20, "b":true, "r":220.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List020", "i": 19, "b":true, "r":219.0}}
      ]']],
    [idl_compound_index_single_column],
    [001: s=List000
001: s=List000
001: s=List000
001: s=List001
001: s=List001
001: s=List001
001: s=List001
001: s=List005
001: s=List020
001: s=List020
003: s=List001
003: s=List001
003: s=List001
003: s=List001
],
[001: s=List000 i=1 b=True r=101.000000
001: s=List000 i=10 b=True r=110.000000
001: s=List000 i=2 b=False r=102.000000
001: s=List001 i=1 b=False r=110.000000
001: s=List001 i=2 b=True r=120.000000
001: s=List001 i=2 b=True r=122.000000
001: s=List001 i=4 b=True r=130.000000
001: s=List005 i=5 b=True r=130.000000
001: s=List020 i=19 b=True r=219.000000
001: s=List020 i=20 b=True r=220.000000
003: s=List001 i=1 b=False r=110.000000
003: s=List001 i=2 b=True r=120.000000
003: s=List001 i=2 b=True r=122.000000
003: s=List001 i=4 b=True r=130.000000
],
[002: i=1
002: i=1
002: i=2
002: i=2
002: i=2
002: i=4
002: i=5
002: i=10
002: i=19
002: i=20
004: i=5
005: i=4
005: i=5
006: i=5
006: i=10
006: i=19
006: i=20
006: i=54
007: i=5
007: i=19
007: i=20
007: i=30
007: i=54
008: i=1
008: i=1
008: i=2
008: i=2
008: i=2
008: i=5
008: i=19
008: i=20
008: i=30
008: i=54
],
[002: i=1 s=List000 b=True r=101.000000
002: i=1 s=List001 b=False r=110.000000
002: i=10 s=List000 b=True r=110.000000
002: i=19 s=List020 b=True r=219.000000
002: i=2 s=List000 b=False r=102.000000
002: i=2 s=List001 b=True r=120.000000
002: i=2 s=List001 b=True r=122.000000
002: i=20 s=List020 b=True r=220.000000
002: i=4 s=List001 b=True r=130.000000
002: i=5 s=List005 b=True r=130.000000
004: i=5 s=List005 b=True r=130.000000
005: i=4 s=List001 b=True r=130.000000
005: i=5 s=List005 b=True r=130.000000
006: i=10 s=List000 b=True r=110.000000
006: i=19 s=List020 b=True r=219.000000
006: i=20 s=List020 b=True r=220.000000
006: i=5 s=List005 b=True r=130.000000
006: i=54 s=Lista054 b=False r=0.000000
007: i=19 s=List020 b=True r=219.000000
007: i=20 s=List020 b=True r=220.000000
007: i=30 s=List000 b=True r=110.000000
007: i=5 s=List005 b=True r=130.000000
007: i=54 s=Lista054 b=False r=0.000000
008: i=1 s=List000 b=True r=101.000000
008: i=1 s=List001 b=False r=110.000000
008: i=19 s=List020 b=True r=219.000000
008: i=2 s=List000 b=False r=102.000000
008: i=2 s=List001 b=True r=120.000000
008: i=2 s=List001 b=True r=122.000000
008: i=20 s=List020 b=True r=220.000000
008: i=30 s=List000 b=True r=110.000000
008: i=5 s=List005 b=True r=130.000000
008: i=54 s=Lista054 b=False r=0.000000
])

# Tests to verify the functionality of two column compound index.
# It tests index for two columns using string and integer fields.
# The run of test-ovsdb generates the output of the display of data using the different indexes defined in
# the program.
# Then, some at_checks are used to verify the correctness of the corresponding index as well as the existence
# of all the rows involved in the test.
m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_DOUBLE_COLUMN_C],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl compound_index_double_column compound_index positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
# Generate the data to be tested.
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-compound-index unix:socket $3],
            [0], [stdout], [ignore])
# Filter the rows of data that corresponds to the string-integer index eliminating the extra columns of data.
# This is done to verifiy that the output data is in the correct and expected order.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: s=.*' | sed -e 's/ b=.*//g']],
            [0], [$4])
# Here, the data is filtered and sorted in order to have all the rows in the index and be
# able to determined that all the involved rows are present.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: s=.*' | sort -k 1,1n -k 2,2 -k 3,3]],
            [0], [$5])
# Filter the rows of data that corresponds to the integer index eliminating the extra columns of data.
# This is done to verifiy that the output data is in the correct and expected order.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: i=.*' | sed -e 's/ b=.*//g']],
            [0], [$6])
# Here again, the data is filtered and sorted in order to have all the rows in the index and be
# able to determined that all the involved rows are present.
   AT_CHECK([[cat stdout | grep -oh '[0-9]\{3\}: i=.*' | sort -k 1,1n -k 2,2 -k 3,3]],
            [0], [$7])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_COMPOUND_INDEX_DOUBLE_COLUMN_C([Compound_index, double column test ],
    [['["idltest",
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 1, "b":true, "r":101.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 2, "b":false, "r":102.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List000", "i": 10, "b":true, "r":110.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 1, "b":false, "r":110.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 2, "b":true, "r":120.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 2, "b":true, "r":122.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List001", "i": 4, "b":true, "r":130.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List005", "i": 5, "b":true, "r":130.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List020", "i": 20, "b":true, "r":220.0}},
      {"op": "insert", "table": "simple", "row": {"s":"List020", "i": 19, "b":true, "r":219.0}}
      ]']],
    [idl_compound_index_double_column],
    [001: s=List000 i=1
001: s=List000 i=2
001: s=List000 i=10
001: s=List001 i=1
001: s=List001 i=2
001: s=List001 i=2
001: s=List001 i=4
001: s=List005 i=5
001: s=List020 i=19
001: s=List020 i=20
002: s=List000 i=10
002: s=List000 i=2
002: s=List000 i=1
002: s=List001 i=4
002: s=List001 i=2
002: s=List001 i=2
002: s=List001 i=1
002: s=List005 i=5
002: s=List020 i=20
002: s=List020 i=19
003: s=List000 i=10
004: s=List001 i=1
004: s=List001 i=2
004: s=List001 i=2
004: s=List001 i=4
004: s=List005 i=5
],
    [001: s=List000 i=1 b=True r=101.000000
001: s=List000 i=10 b=True r=110.000000
001: s=List000 i=2 b=False r=102.000000
001: s=List001 i=1 b=False r=110.000000
001: s=List001 i=2 b=True r=120.000000
001: s=List001 i=2 b=True r=122.000000
001: s=List001 i=4 b=True r=130.000000
001: s=List005 i=5 b=True r=130.000000
001: s=List020 i=19 b=True r=219.000000
001: s=List020 i=20 b=True r=220.000000
002: s=List000 i=1 b=True r=101.000000
002: s=List000 i=10 b=True r=110.000000
002: s=List000 i=2 b=False r=102.000000
002: s=List001 i=1 b=False r=110.000000
002: s=List001 i=2 b=True r=120.000000
002: s=List001 i=2 b=True r=122.000000
002: s=List001 i=4 b=True r=130.000000
002: s=List005 i=5 b=True r=130.000000
002: s=List020 i=19 b=True r=219.000000
002: s=List020 i=20 b=True r=220.000000
003: s=List000 i=10 b=True r=110.000000
004: s=List001 i=1 b=False r=110.000000
004: s=List001 i=2 b=True r=120.000000
004: s=List001 i=2 b=True r=122.000000
004: s=List001 i=4 b=True r=130.000000
004: s=List005 i=5 b=True r=130.000000
],
    [005: i=1 s=List000
005: i=1 s=List001
005: i=2 s=List000
005: i=2 s=List001
005: i=2 s=List001
005: i=4 s=List001
005: i=5 s=List005
005: i=10 s=List000
005: i=19 s=List020
005: i=20 s=List020
006: i=20 s=List020
006: i=19 s=List020
006: i=10 s=List000
006: i=5 s=List005
006: i=4 s=List001
006: i=2 s=List000
006: i=2 s=List001
006: i=2 s=List001
006: i=1 s=List000
006: i=1 s=List001
],
    [005: i=1 s=List000 b=True r=101.000000
005: i=1 s=List001 b=False r=110.000000
005: i=10 s=List000 b=True r=110.000000
005: i=19 s=List020 b=True r=219.000000
005: i=2 s=List000 b=False r=102.000000
005: i=2 s=List001 b=True r=120.000000
005: i=2 s=List001 b=True r=122.000000
005: i=20 s=List020 b=True r=220.000000
005: i=4 s=List001 b=True r=130.000000
005: i=5 s=List005 b=True r=130.000000
006: i=1 s=List000 b=True r=101.000000
006: i=1 s=List001 b=False r=110.000000
006: i=10 s=List000 b=True r=110.000000
006: i=19 s=List020 b=True r=219.000000
006: i=2 s=List000 b=False r=102.000000
006: i=2 s=List001 b=True r=120.000000
006: i=2 s=List001 b=True r=122.000000
006: i=20 s=List020 b=True r=220.000000
006: i=4 s=List001 b=True r=130.000000
006: i=5 s=List005 b=True r=130.000000
])

m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_WITH_REF],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([ovsdb server idl compound_index compound_index_with_ref positive $5])
   OVSDB_START_IDLTEST
   m4_if([$2], [], [],
     [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-compound-index-with-ref unix:socket $3],
            [0], [stdout], [ignore])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
            [0], [$4])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

OVSDB_CHECK_IDL_COMPOUND_INDEX_WITH_REF([set, simple3 idl-compound-index-with-ref, initially populated],
[],
[],
[[000: After add to other table + set of strong ref
001: table simple3: name= uset=[] uref=[<0>] uuid=<1>
002: check simple4: not empty
003: Query using index with reference
004: table simple3: name= uset=[] uref=[<0>] uuid=<1>
005: After delete
007: check simple4: empty
008: End test
]])

m4_define([CHECK_STREAM_OPEN_BLOCK],
  [AT_SETUP([Check stream open block - $1 - $3])
   AT_SKIP_IF([test "$3" = "tcp6" && test "$IS_WIN32" = "yes"])
   AT_SKIP_IF([test "$3" = "tcp6" && test "$HAVE_IPV6" = "no"])
   AT_SKIP_IF([test "$3" = "ssl6" && test "$IS_WIN32" = "yes"])
   AT_SKIP_IF([test "$3" = "ssl6" && test "$HAVE_IPV6" = "no"])
   AT_SKIP_IF([test "$3" = "ssl" && test "$HAVE_OPENSSL" = "no"])
   $PYTHON3 -c "import ssl"
   SSL_PRESENT=$?
   AT_SKIP_IF([test "$3" = "ssl" && test $SSL_PRESENT != 0])
   AT_SKIP_IF([test "$3" = "ssl6" && test "$HAVE_OPENSSL" = "no"])
   AT_SKIP_IF([test "$3" = "ssl6" && test $SSL_PRESENT != 0])
   AT_KEYWORDS([ovsdb server stream open_block $3])
   PKIDIR=$abs_top_builddir/tests
   m4_define([PROTOCOL], [m4_substr([$3], [0], [3])])
   OVSDB_START_IDLTEST([m4_join([], [p], PROTOCOL, [:0:], $4)])
   PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
   WRONG_PORT=$(($TCP_PORT + 101))
   SSL_KEY_ARGS="$PKIDIR/testpki-privkey.pem $PKIDIR/testpki-cert.pem $PKIDIR/testpki-cacert.pem"
   AT_CHECK([$2 PROTOCOL:$4:$TCP_PORT $SSL_KEY_ARGS], [0], [ignore])
   AT_CHECK([$2 PROTOCOL:$4:$WRONG_PORT $SSL_KEY_ARGS], [1], [ignore],
            [ignore])
   OVSDB_SERVER_SHUTDOWN
   AT_CHECK([$2 PROTOCOL:$4:$TCP_PORT $SSL_KEY_ARGS], [1], [ignore], [ignore])
   AT_CLEANUP])

CHECK_STREAM_OPEN_BLOCK([C], [test-stream], [tcp], [127.0.0.1])
CHECK_STREAM_OPEN_BLOCK([C], [test-stream], [tcp6], [[[::1]]])
CHECK_STREAM_OPEN_BLOCK([Python3], [$PYTHON3 $srcdir/test-stream.py],
                        [tcp], [127.0.0.1])
CHECK_STREAM_OPEN_BLOCK([Python3], [$PYTHON3 $srcdir/test-stream.py],
                        [tcp6], [[[::1]]])
CHECK_STREAM_OPEN_BLOCK([C], [test-stream], [ssl], [127.0.0.1])
CHECK_STREAM_OPEN_BLOCK([C], [test-stream], [ssl6], [[[::1]]])
CHECK_STREAM_OPEN_BLOCK([Python3], [$PYTHON3 $srcdir/test-stream.py],
                        [ssl], [127.0.0.1])
CHECK_STREAM_OPEN_BLOCK([Python3], [$PYTHON3 $srcdir/test-stream.py],
                        [ssl6], [[[::1]]])

# same as OVSDB_CHECK_IDL but uses Python IDL implementation with tcp
# with multiple remotes to assert the idl connects to the leader of the Raft cluster
m4_define([OVSDB_CHECK_IDL_LEADER_ONLY_PY],
  [AT_SETUP([$1 - Python3 (leader only)])
   AT_SKIP_IF([test "$IS_ARM64" = "yes"])
   AT_KEYWORDS([ovsdb server idl Python leader_only with tcp socket])
   m4_define([LPBK],[127.0.0.1])
   OVSDB_CLUSTER_START_IDLTEST([$2], ["ptcp:0:"LPBK])
   PARSE_LISTENING_PORT([s2.log], [TCP_PORT_1])
   PARSE_LISTENING_PORT([s3.log], [TCP_PORT_2])
   PARSE_LISTENING_PORT([s1.log], [TCP_PORT_3])
   remotes=tcp:LPBK:$TCP_PORT_1,tcp:LPBK:$TCP_PORT_2,tcp:LPBK:$TCP_PORT_3
   pids=$(cat s2.pid s3.pid s1.pid | tr '\n' ',')
   echo $pids
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t30 idl-cluster $srcdir/idltest.ovsschema $remotes $pids $3],
        [0], [stdout], [ignore])
   remote=$(ovsdb_cluster_leader $remotes "idltest")
   leader=$(echo $remote | cut -d'|' -f 1)
   AT_CHECK([grep -F -- "${leader}" stdout], [0], [ignore])
   AT_CLEANUP])

OVSDB_CHECK_IDL_LEADER_ONLY_PY([Check Python IDL connects to leader], 3, ['remote'])
OVSDB_CHECK_IDL_LEADER_ONLY_PY([Check Python IDL reconnects to leader], 3, ['remote' '+remotestop' 'remote'])

# OVSDB_CHECK_CLUSTER_IDL_C(TITLE, N_SERVERS, [PRE-IDL-TXN], TRANSACTIONS,
#                           OUTPUT, [KEYWORDS], [FILTER], [LOG_FILTER])
#
# Creates a clustered database with a schema derived from idltest.ovsidl, runs
# each PRE-IDL-TXN (if any), starts N_SERVERS ovsdb-server instances in RAFT,
# on that database, and runs "test-ovsdb idl" passing each of the TRANSACTIONS
# along.
#
# Checks that the overall output is OUTPUT.  Before comparison, the
# output is sorted (using "sort") and UUIDs in the output are replaced
# by markers of the form <N> where N is a number.  The first unique
# UUID is replaced by <0>, the next by <1>, and so on.  If a given
# UUID appears more than once it is always replaced by the same
# marker.  If FILTER is supplied then the output is also filtered
# through the specified program.
#
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
#
# If LOG_FILTER is provided, checks that the contents of LOG_FILTER
# are not matched by grep in the test-ovsdb logs.
m4_define([OVSDB_CHECK_CLUSTER_IDL_C],
  [AT_SETUP([$1 - C - tcp])
   AT_KEYWORDS([ovsdb server idl tcp $6])
   m4_define([LPBK],[127.0.0.1])
   OVSDB_CLUSTER_START_IDLTEST([$2], ["ptcp:0:"LPBK])
   PARSE_LISTENING_PORT([s1.log], [TCP_PORT_1])
   PARSE_LISTENING_PORT([s2.log], [TCP_PORT_2])
   PARSE_LISTENING_PORT([s3.log], [TCP_PORT_3])
   remotes=tcp:LPBK:$TCP_PORT_1,tcp:LPBK:$TCP_PORT_2,tcp:LPBK:$TCP_PORT_3

   m4_if([$3], [], [],
     [AT_CHECK([ovsdb-client transact $remotes $3], [0], [ignore], [ignore])])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl tcp:LPBK:$TCP_PORT_1 $4],
            [0], [stdout], [stderr])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$7],,, [[| $7]]),
            [0], [$5])
   m4_ifval([$8], [AT_CHECK([grep '$8' stderr], [1])], [], [])
   AT_CLEANUP])

# Same as OVSDB_CHECK_CLUSTER_IDL_C but uses the Python IDL implementation.
m4_define([OVSDB_CHECK_CLUSTER_IDL_PY],
  [AT_SETUP([$1 - Python3 - tcp])
   AT_KEYWORDS([ovsdb server idl tcp $6])
   m4_define([LPBK],[127.0.0.1])
   OVSDB_CLUSTER_START_IDLTEST([$2], ["ptcp:0:"LPBK])
   PARSE_LISTENING_PORT([s1.log], [TCP_PORT_1])
   PARSE_LISTENING_PORT([s2.log], [TCP_PORT_2])
   PARSE_LISTENING_PORT([s3.log], [TCP_PORT_3])
   remotes=tcp:LPBK:$TCP_PORT_1,tcp:LPBK:$TCP_PORT_2,tcp:LPBK:$TCP_PORT_3

   m4_if([$3], [], [],
     [AT_CHECK([ovsdb-client transact $remotes $3], [0], [ignore], [ignore])])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema tcp:LPBK:$TCP_PORT_1 $4],
            [0], [stdout], [stderr])
   AT_CHECK([sort stdout | uuidfilt]m4_if([$7],,, [[| $7]]),
            [0], [$5])
   m4_if([$8], [AT_CHECK([grep '$8' stderr], [1])], [], [])
   AT_CLEANUP])

m4_define([OVSDB_CHECK_CLUSTER_IDL],
  [OVSDB_CHECK_CLUSTER_IDL_C($@)
   OVSDB_CHECK_CLUSTER_IDL_PY($@)])

# Checks that monitor_cond_since works fine when disconnects happen
# with cond_change requests in flight (i.e., IDL is properly updated).
OVSDB_CHECK_CLUSTER_IDL([simple idl, monitor_cond_since, cluster disconnect],
  3,
  [['["idltest",
       {"op": "insert",
       "table": "simple",
       "row": {"i": 1,
               "r": 1.0,
               "b": true}},
       {"op": "insert",
       "table": "simple",
       "row": {"i": 2,
               "r": 1.0,
               "b": true}}]']],
  [['condition simple []' \
    'condition simple [["i","==",2]]' \
    'condition simple [["i","==",1]]' \
    '+reconnect' \
    '?["idltest",
      {"op": "update",
       "table": "simple",
       "where": [["i", "==", 1]],
       "row": {"r": 2.0 }}]']],
  [[000: simple: change conditions
001: empty
002: simple: change conditions
003: table simple: i=2 r=1 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<1>
004: simple: change conditions
005: reconnect
006: table simple
007: {"error":null,"result":[{"count":1}]}
008: table simple: i=1 r=2 b=true s= u=<0> ia=[] ra=[] ba=[] sa=[] ua=[] uuid=<2>
009: done
]])

dnl This test checks that IDL keeps the existing connection to the server if
dnl it's still on a list of remotes after update.
OVSDB_CHECK_IDL_C([simple idl, initially empty, set remotes],
  [],
  [['set-remote unix:socket' \
    '+set-remote unix:bad_socket,unix:socket' \
    '+set-remote unix:bad_socket' \
    '+set-remote unix:socket' \
    'set-remote unix:bad_socket,unix:socket' \
    '+set-remote unix:socket' \
    '+reconnect']],
  [[000: empty
001: new remotes: unix:socket, is connected: true
002: new remotes: unix:bad_socket,unix:socket, is connected: true
003: new remotes: unix:bad_socket, is connected: false
004: new remotes: unix:socket, is connected: false
005: empty
006: new remotes: unix:bad_socket,unix:socket, is connected: true
007: new remotes: unix:socket, is connected: true
008: reconnect
009: empty
010: done
]])

dnl This test checks that forceful reconnects triggered by the IDL
dnl happen immediately (they should not use backoff).
OVSDB_CHECK_CLUSTER_IDL([simple idl, initially empty, force reconnect],
  3,
  [],
  [['+reconnect' \
    'reconnect' \
    'reconnect' \
    'reconnect']],
  [[000: reconnect
001: empty
002: reconnect
003: empty
004: reconnect
005: empty
006: reconnect
007: empty
008: done
]],
[],
[],
reconnect.*waiting .* seconds before reconnect)

AT_SETUP([idl table and column presence check])
AT_KEYWORDS([ovsdb server idl table column check])
OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest2.ovsschema"])

AT_CHECK(ovsdb-tool create db2 $abs_srcdir/idltest.ovsschema)
AT_CHECK(ovsdb-server -vconsole:warn --log-file=ovsdb-server2.log --detach dnl
           --no-chdir --pidfile=ovsdb-server2.pid --remote=punix:socket2 db2)
on_exit 'kill `cat ovsdb-server2.pid`'

dnl In this test, test-ovsdb first connects to the server with schema
dnl idltest2.ovsschema and outputs the presence of tables and columns.
dnl And then it connectes to the server with the schema idltest.ovsschema
dnl and does the same.
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 dnl
                 idl-table-column-check unix:socket unix:socket2], [0], [dnl
unix:socket remote has table simple
unix:socket remote has table link1
unix:socket remote doesn't have table link2
unix:socket remote doesn't have table simple5
unix:socket remote doesn't have col irefmap in table simple5
unix:socket remote doesn't have col l2 in table link1
unix:socket remote has col i in table link1
unix:socket remote doesn't have col id in table simple7
--- remote unix:socket done ---
unix:socket2 remote has table simple
unix:socket2 remote has table link1
unix:socket2 remote has table link2
unix:socket2 remote has table simple5
unix:socket2 remote has col irefmap in table simple5
unix:socket2 remote has col l2 in table link1
unix:socket2 remote has col i in table link1
unix:socket2 remote has col id in table simple7
--- remote unix:socket2 done ---
], [stderr])

OVSDB_SERVER_SHUTDOWN
AT_CLEANUP

dnl This test checks that inserting and deleting the source of a reference
dnl doesn't remove the reference in the (deleted) source tracked record.
OVSDB_CHECK_IDL_TRACK([track, insert and delete, refs to link1],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link2",
       "uuid-name": "l2row0",
       "row": {"i": 1, "l1": ["set", [["named-uuid", "l1row0"]]]}
      },
      {"op": "insert",
       "table": "link1",
       "uuid-name": "l1row0",
       "row": {"i": 1, "k": ["named-uuid", "l1row0"]}
      },
      {"op": "insert",
       "table": "link2",
       "uuid-name": "l2row1",
       "row": {"i": 2, "l1": ["set", [["named-uuid", "l1row0"]]]}
      }
    ]' \
    '+["idltest",
      {"op": "delete",
       "table": "link2",
       "where": [["i", "==", 2]]}
       ]' \
    '["idltest",
      {"op": "delete",
       "table": "link2",
       "where": [["i", "==", 1]]}
       ]'
  ]],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
002: {"error":null,"result":[{"count":1}]}
003: table link1: inserted row: i=1 k=1 ka=[] l2= uuid=<1>
003: table link1: updated columns: i k
003: table link2: inserted row: i=1 l1=1 uuid=<0>
003: table link2: inserted/deleted row: i=2 l1=1 uuid=<2>
003: table link2: updated columns: i l1
003: table link2: updated columns: i l1
004: {"error":null,"result":[{"count":1}]}
005: table link1: i=1 k=1 ka=[] l2= uuid=<1>
006: done
]])
OVSDB_CHECK_IDL_TRACK([track, insert and delete, refs to link2],
  [],
  [['["idltest",
      {"op": "insert",
       "table": "link1",
       "uuid-name": "l1row0",
       "row": {"i": 1, "k": ["named-uuid", "l1row0"], "l2": ["set", [["named-uuid", "l2row0"]]]}
      },
      {"op": "insert",
       "table": "link2",
       "uuid-name": "l2row0",
       "row": {"i": 1}
      },
      {"op": "insert",
       "table": "link1",
       "uuid-name": "l1row1",
       "row": {"i": 2, "k": ["named-uuid", "l1row0"], "l2": ["set", [["named-uuid", "l2row0"]]]}
      }
    ]' \
    '+["idltest",
      {"op": "delete",
       "table": "link1",
       "where": [["i", "==", 2]]}
       ]' \
    '["idltest",
      {"op": "delete",
       "table": "link1",
       "where": [["i", "==", 1]]}
       ]'
  ]],
  [[000: empty
001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
002: {"error":null,"result":[{"count":1}]}
003: table link1: inserted row: i=1 k=1 ka=[] l2=1 uuid=<0>
003: table link1: inserted/deleted row: i=2 k=1 ka=[] l2=1 uuid=<2>
003: table link1: updated columns: i k l2
003: table link1: updated columns: i k l2
003: table link2: inserted row: i=1 l1= uuid=<1>
003: table link2: updated columns: i
004: {"error":null,"result":[{"count":1}]}
005: table link2: i=1 l1= uuid=<1>
006: done
]])

m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_C],
  [AT_SETUP([$1 - C])
   AT_KEYWORDS([idl persistent uuid insert])
   OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest.ovsschema"])
   AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket $2],
            [0], [stdout], [stderr])
   AT_CHECK([sort stdout],
            [0], [$3])
   AT_CHECK([grep $4 stderr], [0], [ignore])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])

m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_PY],
  [AT_SETUP([$1 - Python3])
   AT_KEYWORDS([idl persistent uuid insert])
   OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest.ovsschema"])
   AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py  -t10 idl $srcdir/idltest.ovsschema unix:socket $2],
            [0], [stdout], [stderr])
   AT_CHECK([sort stdout],
            [0], [$3])
   AT_CHECK([grep $4 stderr], [0], [ignore])
   OVSDB_SERVER_SHUTDOWN
   AT_CLEANUP])


m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT],
  [OVSDB_CHECK_IDL_PERS_UUID_INSERT_C($@)
   OVSDB_CHECK_IDL_PERS_UUID_INSERT_PY($@)])

OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert],
  [['insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df2222 2, insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df3333 3' \
    'insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df4444 4, insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df2222 5' \
    'insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df4444 4' \
    'delete 2' \
    'insert_uuid c5cc12f8-eaa1-43a7-8a73-bccd18df2222 5'
    ]],
  [[000: empty
001: commit, status=success
002: table simple: i=2 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df2222
002: table simple: i=3 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df3333
003: commit, status=error
004: table simple: i=2 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df2222
004: table simple: i=3 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df3333
005: commit, status=success
006: table simple: i=2 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df2222
006: table simple: i=3 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df3333
006: table simple: i=4 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df4444
007: commit, status=success
008: table simple: i=3 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df3333
008: table simple: i=4 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df4444
009: commit, status=success
010: table simple: i=3 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df3333
010: table simple: i=4 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df4444
010: table simple: i=5 r=0 b=false s= u=00000000-0000-0000-0000-000000000000 ia=[] ra=[] ba=[] sa=[] ua=[] uuid=c5cc12f8-eaa1-43a7-8a73-bccd18df2222
011: done
]],
  [['This UUID would duplicate a UUID already present within the table or deleted within the same transaction']])