1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lnet/selftest/conctl.c
38 * Test client & Server
40 * Author: Liang Zhen <liangzhen@clusterfs.com>
45 #define LST_PING_TEST_MAGIC 0xbabeface
48 cfs_spinlock_t pnd_lock; /* serialize */
49 int pnd_counter; /* sequence counter */
52 static lst_ping_data_t lst_ping_data;
55 ping_client_init(sfw_test_instance_t *tsi)
57 LASSERT (tsi->tsi_is_client);
59 cfs_spin_lock_init(&lst_ping_data.pnd_lock);
60 lst_ping_data.pnd_counter = 0;
66 ping_client_fini (sfw_test_instance_t *tsi)
68 sfw_session_t *sn = tsi->tsi_batch->bat_session;
72 LASSERT (tsi->tsi_is_client);
74 errors = cfs_atomic_read(&sn->sn_ping_errors);
76 CWARN ("%d pings have failed.\n", errors);
78 CDEBUG (D_NET, "Ping test finished OK.\n");
82 ping_client_prep_rpc(sfw_test_unit_t *tsu,
83 lnet_process_id_t dest, srpc_client_rpc_t **rpc)
85 srpc_ping_reqst_t *req;
89 rc = sfw_create_test_rpc(tsu, dest, 0, 0, rpc);
93 req = &(*rpc)->crpc_reqstmsg.msg_body.ping_reqst;
95 req->pnr_magic = LST_PING_TEST_MAGIC;
97 cfs_spin_lock(&lst_ping_data.pnd_lock);
98 req->pnr_seq = lst_ping_data.pnd_counter ++;
99 cfs_spin_unlock(&lst_ping_data.pnd_lock);
102 req->pnr_time_sec = tv.tv_sec;
103 req->pnr_time_usec = tv.tv_usec;
109 ping_client_done_rpc (sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
111 sfw_test_instance_t *tsi = tsu->tsu_instance;
112 sfw_session_t *sn = tsi->tsi_batch->bat_session;
113 srpc_ping_reqst_t *reqst = &rpc->crpc_reqstmsg.msg_body.ping_reqst;
114 srpc_ping_reply_t *reply = &rpc->crpc_replymsg.msg_body.ping_reply;
117 LASSERT (sn != NULL);
119 if (rpc->crpc_status != 0) {
120 if (!tsi->tsi_stopping) /* rpc could have been aborted */
121 cfs_atomic_inc(&sn->sn_ping_errors);
122 CERROR ("Unable to ping %s (%d): %d\n",
123 libcfs_id2str(rpc->crpc_dest),
124 reqst->pnr_seq, rpc->crpc_status);
128 if (rpc->crpc_replymsg.msg_magic != SRPC_MSG_MAGIC) {
129 __swab32s(&reply->pnr_seq);
130 __swab32s(&reply->pnr_magic);
131 __swab32s(&reply->pnr_status);
134 if (reply->pnr_magic != LST_PING_TEST_MAGIC) {
135 rpc->crpc_status = -EBADMSG;
136 cfs_atomic_inc(&sn->sn_ping_errors);
137 CERROR ("Bad magic %u from %s, %u expected.\n",
138 reply->pnr_magic, libcfs_id2str(rpc->crpc_dest),
139 LST_PING_TEST_MAGIC);
143 if (reply->pnr_seq != reqst->pnr_seq) {
144 rpc->crpc_status = -EBADMSG;
145 cfs_atomic_inc(&sn->sn_ping_errors);
146 CERROR ("Bad seq %u from %s, %u expected.\n",
147 reply->pnr_seq, libcfs_id2str(rpc->crpc_dest),
153 CDEBUG (D_NET, "%d reply in %u usec\n", reply->pnr_seq,
154 (unsigned)((tv.tv_sec - (unsigned)reqst->pnr_time_sec) * 1000000
155 + (tv.tv_usec - reqst->pnr_time_usec)));
160 ping_server_handle (srpc_server_rpc_t *rpc)
162 srpc_service_t *sv = rpc->srpc_service;
163 srpc_msg_t *reqstmsg = &rpc->srpc_reqstbuf->buf_msg;
164 srpc_ping_reqst_t *req = &reqstmsg->msg_body.ping_reqst;
165 srpc_ping_reply_t *rep = &rpc->srpc_replymsg.msg_body.ping_reply;
167 LASSERT (sv->sv_id == SRPC_SERVICE_PING);
169 if (reqstmsg->msg_magic != SRPC_MSG_MAGIC) {
170 LASSERT (reqstmsg->msg_magic == __swab32(SRPC_MSG_MAGIC));
172 __swab32s(&reqstmsg->msg_type);
173 __swab32s(&req->pnr_seq);
174 __swab32s(&req->pnr_magic);
175 __swab64s(&req->pnr_time_sec);
176 __swab64s(&req->pnr_time_usec);
178 LASSERT (reqstmsg->msg_type == srpc_service2request(sv->sv_id));
180 if (req->pnr_magic != LST_PING_TEST_MAGIC) {
181 CERROR ("Unexpect magic %08x from %s\n",
182 req->pnr_magic, libcfs_id2str(rpc->srpc_peer));
186 rep->pnr_seq = req->pnr_seq;
187 rep->pnr_magic = LST_PING_TEST_MAGIC;
189 CDEBUG (D_NET, "Get ping %d from %s\n",
190 req->pnr_seq, libcfs_id2str(rpc->srpc_peer));
194 sfw_test_client_ops_t ping_test_client;
195 void ping_init_test_client(void)
197 ping_test_client.tso_init = ping_client_init;
198 ping_test_client.tso_fini = ping_client_fini;
199 ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
200 ping_test_client.tso_done_rpc = ping_client_done_rpc;
203 srpc_service_t ping_test_service;
204 void ping_init_test_service(void)
206 ping_test_service.sv_id = SRPC_SERVICE_PING;
207 ping_test_service.sv_name = "ping_test";
208 ping_test_service.sv_handler = ping_server_handle;