ofproto: New feature to notify controllers of flow table changes.
[openvswitch] / tests / ovsdb-monitor.at
1 AT_BANNER([OVSDB -- ovsdb-server monitors])
2
3 # OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], DB, TABLE,
4 #                     TRANSACTIONS, OUTPUT, [COLUMNS], [KEYWORDS])
5 #
6 # Creates a database with the given SCHEMA, starts an ovsdb-server on
7 # that database, and runs each of the TRANSACTIONS (which should be a
8 # quoted list of quoted strings) against it with ovsdb-client one at a
9 # time.  COLUMNS, if specified, is passed to ovsdb-client as the set
10 # of columns and operations to select.
11 #
12 # Checks that the overall output is OUTPUT, but UUIDs in the output
13 # are replaced by markers of the form <N> where N is a number.  The
14 # first unique UUID is replaced by <0>, the next by <1>, and so on.
15 # If a given UUID appears more than once it is always replaced by the
16 # same marker.
17 #
18 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
19 m4_define([OVSDB_CHECK_MONITOR], 
20   [AT_SETUP([$1])
21    AT_KEYWORDS([ovsdb server monitor positive $9])
22    $2 > schema
23    AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
24    m4_foreach([txn], [$3],
25      [AT_CHECK([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
26    AT_CAPTURE_FILE([ovsdb-server-log])
27    AT_CHECK([ovsdb-server --detach --pidfile="`pwd`"/server-pid --remote=punix:socket --unixctl="`pwd`"/unixctl --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1],
28             [0], [], [])
29    AT_CHECK([ovsdb-client -vjsonrpc --detach --pidfile="`pwd`"/client-pid -d json monitor --format=csv unix:socket $4 $5 $8 > output], 
30             [0], [ignore], [ignore], [kill `cat server-pid`])
31    m4_foreach([txn], [$6],
32      [AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],
33                      [ignore], [ignore], [kill `cat server-pid client-pid`])])
34    AT_CHECK([ovsdb-client transact unix:socket '[["$4"]]'], [0],
35             [ignore], [ignore], [kill `cat server-pid client-pid`])
36    AT_CHECK([ovs-appctl -t "`pwd`"/unixctl -e exit], [0], [ignore], [ignore])
37    OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid])
38    AT_CHECK([perl $srcdir/ovsdb-monitor-sort.pl < output | perl $srcdir/uuidfilt.pl], [0], [$7], [ignore])
39    AT_CLEANUP])
40
41 OVSDB_CHECK_MONITOR([monitor insert into empty table],
42   [ordinal_schema],
43   [],
44   [ordinals], [ordinals],
45   [[[["ordinals",
46       {"op": "insert",
47        "table": "ordinals",
48        "row": {"number": 0, "name": "zero"}}]]]],
49   [[row,action,name,number,_version
50 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
51 ]])
52
53 OVSDB_CHECK_MONITOR([monitor insert into populated table],
54   [ordinal_schema],
55   [[[["ordinals",
56       {"op": "insert",
57        "table": "ordinals",
58        "row": {"number": 10, "name": "ten"}}]]]],
59   [ordinals], [ordinals],
60   [[[["ordinals",
61       {"op": "insert",
62        "table": "ordinals",
63        "row": {"number": 0, "name": "zero"}}]]]],
64   [[row,action,name,number,_version
65 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
66
67 row,action,name,number,_version
68 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
69 ]])
70
71 OVSDB_CHECK_MONITOR([monitor delete],
72   [ordinal_schema],
73   [[[["ordinals",
74       {"op": "insert",
75        "table": "ordinals",
76        "row": {"number": 10, "name": "ten"}}]]]],
77   [ordinals], [ordinals],
78   [[[["ordinals",
79       {"op": "delete",
80        "table": "ordinals",
81        "where": [["number", "==", 10]]}]]]],
82   [[row,action,name,number,_version
83 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
84
85 row,action,name,number,_version
86 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
87 ]])
88
89 OVSDB_CHECK_MONITOR([monitor row update],
90   [ordinal_schema],
91   [[[["ordinals",
92       {"op": "insert",
93        "table": "ordinals",
94        "row": {"number": 10, "name": "ten"}}]]]],
95   [ordinals], [ordinals],
96   [[[["ordinals",
97       {"op": "update",
98        "table": "ordinals",
99        "where": [["number", "==", 10]],
100        "row": {"name": "five plus five"}}]]]],
101   [[row,action,name,number,_version
102 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
103
104 row,action,name,number,_version
105 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
106 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
107 ]])
108
109 OVSDB_CHECK_MONITOR([monitor no-op row updates],
110   [ordinal_schema],
111   [[[["ordinals",
112       {"op": "insert",
113        "table": "ordinals",
114        "row": {"number": 10, "name": "ten"}}]]]],
115   [ordinals], [ordinals],
116   [[[["ordinals",
117       {"op": "update",
118        "table": "ordinals",
119        "where": [["number", "==", 10]],
120        "row": {"number": 10, "name": "ten"}}]]],
121    [[["ordinals",
122       {"op": "insert",
123        "table": "ordinals",
124        "row": {"number": 9, "name": "nine"}}]]]],
125   [[row,action,name,number,_version
126 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
127
128 row,action,name,number,_version
129 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
130 ]])
131
132 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
133   [ordinal_schema],
134   [[[["ordinals",
135       {"op": "insert",
136        "table": "ordinals",
137        "row": {"number": 10, "name": "ten"}}]]]],
138   [ordinals], [ordinals],
139   [[[["ordinals",
140       {"op": "insert",
141        "table": "ordinals",
142        "row": {"number": 9, "name": "nine"},
143        "uuid-name": "nine"},
144       {"op": "update",
145        "table": "ordinals",
146        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
147        "row": {"name": "three squared"}}]]]],
148   [[row,action,name,number,_version
149 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
150
151 row,action,name,number,_version
152 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
153 ]])
154
155 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
156   [ordinal_schema],
157   [[[["ordinals",
158       {"op": "insert",
159        "table": "ordinals",
160        "row": {"number": 10, "name": "ten"}}]]]],
161   [ordinals], [ordinals],
162   [[[["ordinals",
163       {"op": "insert",
164        "table": "ordinals",
165        "row": {"number": 9, "name": "nine"},
166        "uuid-name": "nine"},
167       {"op": "update",
168        "table": "ordinals",
169        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
170        "row": {"name": "three squared"}},
171       {"op": "delete",
172        "table": "ordinals",
173        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
174       {"op": "insert",
175        "table": "ordinals",
176        "row": {"number": 7, "name": "seven"}}]]]],
177   [[row,action,name,number,_version
178 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
179
180 row,action,name,number,_version
181 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
182 ]])
183
184 OVSDB_CHECK_MONITOR([monitor weak reference change],
185   [weak_schema],
186   [[[["weak",
187       {"op": "insert",
188        "table": "a",
189        "row": {"a": 0,
190                "a2a1": ["named-uuid", "a0"],
191                "a2b": ["named-uuid", "b2"]},
192        "uuid-name": "a0"},
193       {"op": "insert",
194        "table": "a",
195        "row": {"a": 1,
196                "a2a": ["named-uuid", "a0"],
197                "a2a1": ["named-uuid", "a1"],
198                "a2b": ["named-uuid", "b2"]},
199        "uuid-name": "a1"},
200       {"op": "insert",
201        "table": "b",
202        "row": {"b": 2},
203        "uuid-name": "b2"}]]]],
204   [weak], [a],
205   [[[["weak",
206       {"op": "delete",
207        "table": "a",
208        "where": [["a", "==", 0]]}]]]],
209   [[row,action,a,a2a,a2a1,a2b,_version
210 <0>,initial,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
211 <3>,initial,1,"[""uuid"",""<0>""]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<4>""]"
212
213 row,action,a,a2a,a2a1,a2b,_version
214 <0>,delete,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
215 <3>,old,,"[""uuid"",""<0>""]",,,
216 ,new,1,"[""set"",[]]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<5>""]"
217 ]])
218
219 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
220   [ordinal_schema],
221   [[[["ordinals",
222       {"op": "insert",
223        "table": "ordinals",
224        "row": {"number": 10, "name": "ten"}}]]]],
225   [ordinals], [ordinals],
226   [[[["ordinals",
227       {"op": "insert",
228        "table": "ordinals",
229        "row": {"number": 9, "name": "nine"},
230        "uuid-name": "nine"},
231       {"op": "update",
232        "table": "ordinals",
233        "where": [["_uuid", "==", ["named-uuid", "nine"]]],
234        "row": {"name": "three squared"}},
235       {"op": "delete",
236        "table": "ordinals",
237        "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
238       {"op": "insert",
239        "table": "ordinals",
240        "row": {"number": 7, "name": "seven"}}]]]],
241   [[row,action,name,number,_version
242 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
243
244 row,action,name,number,_version
245 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
246 ]])
247 \f
248 AT_BANNER([ovsdb -- ovsdb-monitor monitor only some operations])
249
250 m4_define([OVSDB_MONITOR_INITIAL],
251   [[[["ordinals",
252       {"op": "insert",
253        "table": "ordinals",
254        "row": {"number": 10, "name": "ten"}}]]]])
255 m4_define([OVSDB_MONITOR_TXNS],
256   [[[["ordinals",
257       {"op": "insert",
258        "table": "ordinals",
259        "row": {"number": 5, "name": "five"}}]]],
260    [[["ordinals",
261       {"op": "update",
262        "table": "ordinals",
263        "where": [["name", "==", "five"]],
264        "row": {"name": "FIVE"}}]]],
265    [[["ordinals",
266       {"op": "delete",
267        "table": "ordinals",
268        "where": []}]]]])
269
270 OVSDB_CHECK_MONITOR([monitor all operations],
271   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
272   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
273   [[row,action,name,number,_version
274 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
275
276 row,action,name,number,_version
277 <2>,insert,"""five""",5,"[""uuid"",""<3>""]"
278
279 row,action,name,number,_version
280 <2>,old,"""five""",,"[""uuid"",""<3>""]"
281 ,new,"""FIVE""",5,"[""uuid"",""<4>""]"
282
283 row,action,name,number,_version
284 <2>,delete,"""FIVE""",5,"[""uuid"",""<4>""]"
285 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
286 ]])
287
288 dnl A monitor with "initial" only doesn't really make sense,
289 dnl but it's still allowed and should work.
290 OVSDB_CHECK_MONITOR([monitor initial only],
291   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
292   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
293   [[row,action,name,number,_version
294 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
295 ]], [!insert,!delete,!modify])
296
297 OVSDB_CHECK_MONITOR([monitor insert only],
298   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
299   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
300   [[row,action,name,number,_version
301 <0>,insert,"""five""",5,"[""uuid"",""<1>""]"
302 ]], [!initial,!delete,!modify])
303
304 OVSDB_CHECK_MONITOR([monitor delete only],
305   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
306   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
307   [[row,action,name,number,_version
308 <0>,delete,"""FIVE""",5,"[""uuid"",""<1>""]"
309 <2>,delete,"""ten""",10,"[""uuid"",""<3>""]"
310 ]], [!initial,!insert,!modify])
311
312 OVSDB_CHECK_MONITOR([monitor modify only],
313   [ordinal_schema], [OVSDB_MONITOR_INITIAL],
314   [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
315   [[row,action,name,number,_version
316 <0>,old,"""five""",,"[""uuid"",""<1>""]"
317 ,new,"""FIVE""",5,"[""uuid"",""<2>""]"
318 ]], [!initial,!insert,!delete])