4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lnet/selftest/conctl.c
36 * Test client & Server
38 * Author: Liang Zhen <liangzhen@clusterfs.com>
43 #define LST_PING_TEST_MAGIC 0xbabeface
46 cfs_spinlock_t pnd_lock; /* serialize */
47 int pnd_counter; /* sequence counter */
50 static lst_ping_data_t lst_ping_data;
53 ping_client_init(sfw_test_instance_t *tsi)
55 LASSERT (tsi->tsi_is_client);
57 cfs_spin_lock_init(&lst_ping_data.pnd_lock);
58 lst_ping_data.pnd_counter = 0;
64 ping_client_fini (sfw_test_instance_t *tsi)
66 sfw_session_t *sn = tsi->tsi_batch->bat_session;
70 LASSERT (tsi->tsi_is_client);
72 errors = cfs_atomic_read(&sn->sn_ping_errors);
74 CWARN ("%d pings have failed.\n", errors);
76 CDEBUG (D_NET, "Ping test finished OK.\n");
80 ping_client_prep_rpc(sfw_test_unit_t *tsu,
81 lnet_process_id_t dest, srpc_client_rpc_t **rpc)
83 srpc_ping_reqst_t *req;
87 rc = sfw_create_test_rpc(tsu, dest, 0, 0, rpc);
91 req = &(*rpc)->crpc_reqstmsg.msg_body.ping_reqst;
93 req->pnr_magic = LST_PING_TEST_MAGIC;
95 cfs_spin_lock(&lst_ping_data.pnd_lock);
96 req->pnr_seq = lst_ping_data.pnd_counter ++;
97 cfs_spin_unlock(&lst_ping_data.pnd_lock);
100 req->pnr_time_sec = tv.tv_sec;
101 req->pnr_time_usec = tv.tv_usec;
107 ping_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
109 sfw_test_instance_t *tsi = tsu->tsu_instance;
110 sfw_session_t *sn = tsi->tsi_batch->bat_session;
111 srpc_ping_reqst_t *reqst = &rpc->crpc_reqstmsg.msg_body.ping_reqst;
112 srpc_ping_reply_t *reply = &rpc->crpc_replymsg.msg_body.ping_reply;
115 LASSERT (sn != NULL);
117 if (rpc->crpc_status != 0) {
118 if (!tsi->tsi_stopping) /* rpc could have been aborted */
119 cfs_atomic_inc(&sn->sn_ping_errors);
120 CERROR ("Unable to ping %s (%d): %d\n",
121 libcfs_id2str(rpc->crpc_dest),
122 reqst->pnr_seq, rpc->crpc_status);
126 if (rpc->crpc_replymsg.msg_magic != SRPC_MSG_MAGIC) {
127 __swab32s(&reply->pnr_seq);
128 __swab32s(&reply->pnr_magic);
129 __swab32s(&reply->pnr_status);
132 if (reply->pnr_magic != LST_PING_TEST_MAGIC) {
133 rpc->crpc_status = -EBADMSG;
134 cfs_atomic_inc(&sn->sn_ping_errors);
135 CERROR ("Bad magic %u from %s, %u expected.\n",
136 reply->pnr_magic, libcfs_id2str(rpc->crpc_dest),
137 LST_PING_TEST_MAGIC);
141 if (reply->pnr_seq != reqst->pnr_seq) {
142 rpc->crpc_status = -EBADMSG;
143 cfs_atomic_inc(&sn->sn_ping_errors);
144 CERROR ("Bad seq %u from %s, %u expected.\n",
145 reply->pnr_seq, libcfs_id2str(rpc->crpc_dest),
151 CDEBUG (D_NET, "%d reply in %u usec\n", reply->pnr_seq,
152 (unsigned)((tv.tv_sec - (unsigned)reqst->pnr_time_sec) * 1000000
153 + (tv.tv_usec - reqst->pnr_time_usec)));
158 ping_server_handle (srpc_server_rpc_t *rpc)
160 srpc_service_t *sv = rpc->srpc_service;
161 srpc_msg_t *reqstmsg = &rpc->srpc_reqstbuf->buf_msg;
162 srpc_ping_reqst_t *req = &reqstmsg->msg_body.ping_reqst;
163 srpc_ping_reply_t *rep = &rpc->srpc_replymsg.msg_body.ping_reply;
165 LASSERT (sv->sv_id == SRPC_SERVICE_PING);
167 if (reqstmsg->msg_magic != SRPC_MSG_MAGIC) {
168 LASSERT (reqstmsg->msg_magic == __swab32(SRPC_MSG_MAGIC));
170 __swab32s(&reqstmsg->msg_type);
171 __swab32s(&req->pnr_seq);
172 __swab32s(&req->pnr_magic);
173 __swab64s(&req->pnr_time_sec);
174 __swab64s(&req->pnr_time_usec);
176 LASSERT (reqstmsg->msg_type == srpc_service2request(sv->sv_id));
178 if (req->pnr_magic != LST_PING_TEST_MAGIC) {
179 CERROR ("Unexpect magic %08x from %s\n",
180 req->pnr_magic, libcfs_id2str(rpc->srpc_peer));
184 rep->pnr_seq = req->pnr_seq;
185 rep->pnr_magic = LST_PING_TEST_MAGIC;
187 CDEBUG (D_NET, "Get ping %d from %s\n",
188 req->pnr_seq, libcfs_id2str(rpc->srpc_peer));
192 sfw_test_client_ops_t ping_test_client;
193 void ping_init_test_client(void)
195 ping_test_client.tso_init = ping_client_init;
196 ping_test_client.tso_fini = ping_client_fini;
197 ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
198 ping_test_client.tso_done_rpc = ping_client_done_rpc;
201 srpc_service_t ping_test_service;
202 void ping_init_test_service(void)
204 ping_test_service.sv_id = SRPC_SERVICE_PING;
205 ping_test_service.sv_name = "ping_test";
206 ping_test_service.sv_handler = ping_server_handle;