1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
20 #include "common/config.h"
22 #include "mon/MonMap.h"
23 #include "mon/MonClient.h"
24 #include "msg/Messenger.h"
25 #include "messages/MPing.h"
27 #include "common/Timer.h"
28 #include "global/global_init.h"
29 #include "common/ceph_argparse.h"
31 #include <sys/types.h>
34 #define dout_subsys ceph_subsys_ms
36 Messenger *messenger = 0;
38 Mutex test_lock("mylock");
41 uint64_t received = 0;
43 class Admin : public Dispatcher {
46 : Dispatcher(g_ceph_context)
50 bool ms_dispatch(Message *m) {
52 //cerr << "got ping from " << m->get_source() << std::endl;
53 dout(0) << "got ping from " << m->get_source() << dendl;
63 bool ms_handle_reset(Connection *con) { return false; }
64 void ms_handle_remote_reset(Connection *con) {}
65 bool ms_handle_refused(Connection *con) { return false; }
70 int main(int argc, const char **argv, const char *envp[]) {
72 vector<const char*> args;
73 argv_to_vec(argc, argv, args);
76 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
77 CODE_ENVIRONMENT_UTILITY, 0);
78 common_init_finish(g_ceph_context);
80 dout(0) << "i am mon " << args[0] << dendl;
83 MonClient mc(g_ceph_context);
84 if (mc.build_initial_monmap() < 0)
88 int whoami = mc.monmap.get_rank(args[0]);
91 ss << mc.monmap.get_addr(whoami);
92 std::string sss(ss.str());
93 g_ceph_context->_conf->set_val("public_addr", sss.c_str());
94 g_ceph_context->_conf->apply_changes(NULL);
95 std::string public_msgr_type = g_conf->ms_public_type.empty() ? g_conf->get_val<std::string>("ms_type") : g_conf->ms_public_type;
96 Messenger *rank = Messenger::create(g_ceph_context,
98 entity_name_t::MON(whoami), "tester",
100 int err = rank->bind(g_ceph_context->_conf->public_addr);
106 messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
107 messenger->add_dispatcher_head(&dispatcher);
118 while (received + isend <= sent) {
119 //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl;
120 dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl;
121 cond.Wait(test_lock);
124 int t = rand() % mc.get_num_mon();
128 if (rand() % 10 == 0) {
129 //cerr << "mark_down " << t << std::endl;
130 dout(0) << "mark_down " << t << dendl;
131 messenger->mark_down(mc.get_mon_addr(t));
133 //cerr << "pinging " << t << std::endl;
134 dout(0) << "pinging " << t << dendl;
135 messenger->send_message(new MPing, mc.get_mon_inst(t));
136 cerr << isend << "\t" << ++sent << "\t" << received << "\r";
140 // wait for messenger to finish