From patchwork Thu Apr 28 16:18:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Arguello, Sebastian" X-Patchwork-Id: 616329 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qwhpk3Ptgz9t7R for ; Fri, 29 Apr 2016 02:18:54 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 591B610712; Thu, 28 Apr 2016 09:18:50 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 8632D105F6 for ; Thu, 28 Apr 2016 09:18:49 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id 0FEE01E05A1 for ; Thu, 28 Apr 2016 10:18:49 -0600 (MDT) X-ASG-Debug-ID: 1461860328-09eadd40452e760001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id 19WekzQOj2oDdzAx (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Thu, 28 Apr 2016 10:18:48 -0600 (MDT) X-Barracuda-Envelope-From: sebastian.arguello@hpe.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.110.132) by mx1-pf1.cudamail.com with ESMTPS (AES256-SHA encrypted); 28 Apr 2016 16:18:47 -0000 Received-SPF: none (mx1-pf1.cudamail.com: domain at hpe.com does not designate permitted sender hosts) X-Barracuda-Apparent-Source-IP: 157.56.110.132 X-Barracuda-RBL-IP: 157.56.110.132 Received: from DF4PR84MB0283.NAMPRD84.PROD.OUTLOOK.COM (10.162.193.21) by DF4PR84MB0284.NAMPRD84.PROD.OUTLOOK.COM (10.162.193.22) with Microsoft SMTP Server (TLS) id 15.1.477.8; Thu, 28 Apr 2016 16:18:45 +0000 Received: from DF4PR84MB0283.NAMPRD84.PROD.OUTLOOK.COM ([10.162.193.21]) by DF4PR84MB0283.NAMPRD84.PROD.OUTLOOK.COM ([10.162.193.21]) with mapi id 15.01.0477.014; Thu, 28 Apr 2016 16:18:45 +0000 X-CudaMail-Envelope-Sender: sebastian.arguello@hpe.com From: "Arguello, Sebastian" To: "dev@openvswitch.org" X-CudaMail-MID: CM-E1-427043465 X-CudaMail-DTE: 042816 X-CudaMail-Originating-IP: 157.56.110.132 Thread-Topic: Subject: [PATCH v3 3/3] ovsdb-idl: Add on-demand columns tests X-ASG-Orig-Subj: [##CM-E1-427043465##]Subject: [PATCH v3 3/3] ovsdb-idl: Add on-demand columns tests Thread-Index: AdGhaQWTjsVRCnz3Sfm/nxjVRZ/2ZQ== Date: Thu, 28 Apr 2016 16:18:45 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: openvswitch.org; dkim=none (message not signed) header.d=none; openvswitch.org; dmarc=none action=none header.from=hpe.com; x-originating-ip: [15.195.195.13] x-ms-office365-filtering-correlation-id: 4dec05e3-de7b-4622-995c-08d36f80c5da x-microsoft-exchange-diagnostics: 1; DF4PR84MB0284; 5:5q8YJG7qPlH/2qXyq8U4Y4JmOv1aGCby2ao/UzCXu5Acw0TLgvZGNE2lg9EDu55a7DZvVzRrDiCJ6FvCKd7tv1eCq7I2v3byjr/ZXffcLX6i/XACinwIZs5czjg+wJH2BJ3b9kc6kK23TQ/mdPhgfw==; 24:zPcOdfvsqpp29f7UXlmmnc26hKfMWE7cBEZdE7wgYplrVGeYwS2v8Omtoq8+czlGpOvHs707X+OFWAE/+mVyAoT0nqdLiiHX/aVtnCL7QVc=; 7:Gpz6/BHshSUYLy2suG4s5b78YevjWjHwOz3p86YGROoGLfwLY/1offihbzlc6PlK+OYkRbj5Eff+ZdYG5p1ke3ScojMm15B/VlcjHRTh6YVn6mZbKHCkLBXJEnRImxkLoymFP3RKvu65FPI158tCEFcPpJi44OqFm0o4ilgbuZ4IksKV75TPTvSBvojRbseu x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0284; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:DF4PR84MB0284; BCL:0; PCL:0; RULEID:; SRVR:DF4PR84MB0284; x-forefront-prvs: 0926B0E013 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(2351001)(6116002)(450100001)(5004730100002)(102836003)(10400500002)(229853001)(5008740100001)(189998001)(2501003)(77096005)(3846002)(575784001)(1730700002)(86362001)(99286002)(11100500001)(1220700001)(15975445007)(1096002)(5002640100001)(5003600100002)(92566002)(5640700001)(2900100001)(19580395003)(19580405001)(3660700001)(586003)(9686002)(110136002)(3280700002)(107886002)(122556002)(81166005)(2906002)(54356999)(87936001)(551934003)(33656002)(66066001)(50986999); DIR:OUT; SFP:1102; SCL:1; SRVR:DF4PR84MB0284; H:DF4PR84MB0283.NAMPRD84.PROD.OUTLOOK.COM; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Apr 2016 16:18:45.3744 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0284 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1461860328 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_RULE7568M, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.29133 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS Subject: [ovs-dev] Subject: [PATCH v3 3/3] ovsdb-idl: Add on-demand columns tests X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" Add tests for the OVSDB IDL on-demand column mode. This commit includes three tests to verify the correct functionality of the on-demand fetching at row, column, and table level. Co-Authored-By: Randall Esquivel Co-Authored-By: Arnoldo Lutz Signed-off-by: Sebastian Arguello Signed-off-by: Arnoldo Lutz Signed-off-by: Randall Esquivel --- This is the pull request with this change: https://github.com/openvswitch/ovs/pull/110 --- tests/ovsdb-idl.at | 165 ++++++++++++++++++++++++++++++++++++ tests/test-ovsdb.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 408 insertions(+) diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index 33d508c..efd8217 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -800,3 +800,168 @@ OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, various ops], 014: updated columns: ba i ia r ra s 015: done ]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-column-row unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW([on-demand-fetch-col-row, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After changes with fetch for ua column in only one row +002: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<1> +003: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-column unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN([on-demand-fetch-column, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After fetch for entire s column +002: i=1 r=2 b=true s=name u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +003: i=1 r=2 b=true s=name u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-table unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE([on-demand-fetch-table, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "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"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After complete table fetch +002: i=1 r=2 b=true s=name u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<1> +003: i=1 r=2 b=true s=name u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<2> +]]) diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index dbb6897..1633c0d 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (C) 2016 Hewlett Packard Enterprise Development LP * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -198,6 +199,11 @@ usage(void) " connect to SERVER and dump the contents of the database\n" " as seen initially by the IDL implementation and after\n" " executing each TRANSACTION. (Each TRANSACTION must modify\n" + " the database or this command will hang.)\n" + " idl-fetch SERVER [TRANSACTION...]\n" + " connect to SERVER and dump the contents of the database\n" + " as seen initially by the IDL implementation and after\n" + " executing each TRANSACTION. (Each TRANSACTION must modify\n" " the database or this command will hang.)\n", program_name, program_name); vlog_usage(); @@ -2179,6 +2185,240 @@ do_idl(struct ovs_cmdl_context *ctx) printf("%03d: done\n", step); } +static void +do_fetch_column_row(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* get ondemand column of second row */ + printf("%03d: After changes with fetch for ua column in only one row\n", + step); + s = idltest_simple_first(idl); + idltest_simple_fetch_ua(idl, s); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_row_fetch_pending(s)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + +static void +do_fetch_column(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* Print simple data after fetching s column */ + printf("%03d: After fetch for entire s column\n", step); + s = idltest_simple_first(idl); + idltest_simple_fetch_col_s(idl); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_s_fetch_pending(idl)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + +static void +do_fetch_table(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* fetch complete table */ + printf("%03d: After complete table fetch\n", step); + idltest_simple_fetch_table(idl); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_table_fetch_pending(idl)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + static struct ovs_cmdl_command all_commands[] = { { "log-io", NULL, 2, INT_MAX, do_log_io }, { "default-atoms", NULL, 0, 0, do_default_atoms }, @@ -2207,6 +2447,9 @@ static struct ovs_cmdl_command all_commands[] = { { "execute", NULL, 2, INT_MAX, do_execute }, { "trigger", NULL, 2, INT_MAX, do_trigger }, { "idl", NULL, 1, INT_MAX, do_idl }, + { "idl-fetch-column-row", NULL, 1, INT_MAX, do_fetch_column_row }, + { "idl-fetch-column", NULL, 1, INT_MAX, do_fetch_column }, + { "idl-fetch-table", NULL, 1, INT_MAX, do_fetch_table }, { "help", NULL, 0, INT_MAX, do_help }, { NULL, NULL, 0, 0, NULL }, };