From: Roald J. van Loon Date: Sat, 7 Sep 2013 13:27:33 +0000 (+0200) Subject: automake cleanup: moving tests to test subdir X-Git-Tag: v0.71~163^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0b267b3038728770357e382e2bd40db47da769b7;p=ceph.git automake cleanup: moving tests to test subdir This are tests and should be in the src/test subdir. Signed-off-by: Roald J. van Loon --- diff --git a/src/Makefile.am b/src/Makefile.am index 7513ed85085d..9a2317537cbc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -239,7 +239,7 @@ ceph_test_rewrite_latency_SOURCES = test/test_rewrite_latency.cc ceph_test_rewrite_latency_LDADD = libcommon.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS) bin_DEBUGPROGRAMS += ceph_test_rewrite_latency -ceph_test_msgr_SOURCES = testmsgr.cc +ceph_test_msgr_SOURCES = test/testmsgr.cc ceph_test_msgr_LDADD = $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += ceph_test_msgr @@ -249,12 +249,12 @@ bin_DEBUGPROGRAMS += ceph_test_ioctls ceph_dupstore_SOURCES = dupstore.cc ceph_dupstore_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS} ceph_dupstore_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA) -ceph_streamtest_SOURCES = streamtest.cc +ceph_streamtest_SOURCES = test/streamtest.cc ceph_streamtest_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS} ceph_streamtest_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += ceph_dupstore ceph_streamtest -ceph_test_trans_SOURCES = test_trans.cc +ceph_test_trans_SOURCES = test/test_trans.cc ceph_test_trans_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS} ceph_test_trans_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA) bin_DEBUGPROGRAMS += ceph_test_trans @@ -516,12 +516,12 @@ bin_PROGRAMS += rbd endif -ceph_test_crypto_SOURCES = testcrypto.cc +ceph_test_crypto_SOURCES = test/testcrypto.cc ceph_test_crypto_LDADD = $(LIBGLOBAL_LDA) ceph_test_crypto_CXXFLAGS = ${AM_CXXFLAGS} bin_DEBUGPROGRAMS += ceph_test_crypto -ceph_test_keys_SOURCES = testkeys.cc +ceph_test_keys_SOURCES = test/testkeys.cc ceph_test_keys_LDADD = libmon.a $(LIBGLOBAL_LDA) ceph_test_keys_CXXFLAGS = ${AM_CXXFLAGS} bin_DEBUGPROGRAMS += ceph_test_keys diff --git a/src/barclass.cc b/src/barclass.cc deleted file mode 100644 index f5354f1e0f3a..000000000000 --- a/src/barclass.cc +++ /dev/null @@ -1,48 +0,0 @@ - - - -#include -#include -#include - -#include "objclass/objclass.h" - -CLS_VER(1,0) -CLS_NAME(bar) - -cls_handle_t h_class; - -cls_method_handle_t h_foo; - -int foo_method(cls_method_context_t ctx, char *indata, int datalen, - char **outdata, int *outdatalen) -{ - int i; - - cls_log("hello world, this is bar"); - cls_log("indata=%s", indata); - - *outdata = (char *)malloc(128); - for (i=0; i -#include -#include - -#include "objclass/objclass.h" - -CLS_VER(1,0) -CLS_NAME(foo) - -cls_handle_t h_class; - -cls_method_handle_t h_foo; - -int foo_method(cls_method_context_t ctx, char *indata, int datalen, - char **outdata, int *outdatalen) -{ - int i; - - cls_log("hello world, this is foo"); - cls_log("indata=%s", indata); - - *outdata = (char *)malloc(128); - for (i=0; i - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include "os/FileStore.h" -#include "global/global_init.h" -#include "common/ceph_argparse.h" -#include "common/debug.h" - -#undef dout_prefix -#define dout_prefix *_dout - -struct io { - utime_t start, ack, commit; - bool done() { - return ack.sec() && commit.sec(); - } -}; -map writes; -Cond cond; -Mutex lock("streamtest.cc lock"); - -unsigned concurrent = 1; -void throttle() -{ - Mutex::Locker l(lock); - while (writes.size() >= concurrent) { - //generic_dout(0) << "waiting" << dendl; - cond.Wait(lock); - } -} - -double total_ack = 0; -double total_commit = 0; -int total_num = 0; - -void pr(off_t off) -{ - io &i = writes[off]; - if (false) cout << off << "\t" - << (i.ack - i.start) << "\t" - << (i.commit - i.start) << std::endl; - total_num++; - total_ack += (i.ack - i.start); - total_commit += (i.commit - i.start); - writes.erase(off); - cond.Signal(); -} - -void set_start(off_t off, utime_t t) -{ - Mutex::Locker l(lock); - writes[off].start = t; -} - -void set_ack(off_t off, utime_t t) -{ - Mutex::Locker l(lock); - //generic_dout(0) << "ack " << off << dendl; - writes[off].ack = t; - if (writes[off].done()) - pr(off); -} - -void set_commit(off_t off, utime_t t) -{ - Mutex::Locker l(lock); - //generic_dout(0) << "commit " << off << dendl; - writes[off].commit = t; - if (writes[off].done()) - pr(off); -} - - -struct C_Ack : public Context { - off_t off; - C_Ack(off_t o) : off(o) {} - void finish(int r) { - set_ack(off, ceph_clock_now(g_ceph_context)); - } -}; -struct C_Commit : public Context { - off_t off; - C_Commit(off_t o) : off(o) {} - void finish(int r) { - set_commit(off, ceph_clock_now(g_ceph_context)); - } -}; - - -int main(int argc, const char **argv) -{ - vector args; - argv_to_vec(argc, argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - - // args - if (args.size() < 3) return -1; - const char *filename = args[0]; - int seconds = atoi(args[1]); - int bytes = atoi(args[2]); - const char *journal = 0; - if (args.size() >= 4) - journal = args[3]; - if (args.size() >= 5) - concurrent = atoi(args[4]); - - cout << "concurrent = " << concurrent << std::endl; - - buffer::ptr bp(bytes); - bp.zero(); - bufferlist bl; - bl.push_back(bp); - - //float interval = 1.0 / 1000; - - cout << "#dev " << filename - << ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl; - - ObjectStore *fs = new FileStore(filename, journal); - - if (fs->mkfs() < 0) { - cout << "mkfs failed" << std::endl; - return -1; - } - - if (fs->mount() < 0) { - cout << "mount failed" << std::endl; - return -1; - } - - ObjectStore::Transaction ft; - ft.create_collection(coll_t()); - fs->apply_transaction(ft); - - utime_t now = ceph_clock_now(g_ceph_context); - utime_t start = now; - utime_t end = now; - end += seconds; - off_t pos = 0; - //cout << "stop at " << end << std::endl; - cout << "# offset\tack\tcommit" << std::endl; - while (now < end) { - sobject_t poid(object_t("streamtest"), 0); - - set_start(pos, ceph_clock_now(g_ceph_context)); - ObjectStore::Transaction *t = new ObjectStore::Transaction; - t->write(coll_t(), hobject_t(poid), pos, bytes, bl); - fs->queue_transaction(NULL, t, new C_Ack(pos), new C_Commit(pos)); - pos += bytes; - - throttle(); - - now = ceph_clock_now(g_ceph_context); - - // wait? - /* - utime_t next = start; - next += interval; - if (now < next) { - float s = next - now; - s *= 1000 * 1000; // s -> us - //cout << "sleeping for " << s << " us" << std::endl; - usleep((int)s); - } - */ - } - - cout << "total num " << total_num << std::endl; - cout << "avg ack\t" << (total_ack / (double)total_num) << std::endl; - cout << "avg commit\t" << (total_commit / (double)total_num) << std::endl; - cout << "tput\t" << prettybyte_t((double)(total_num * bytes) / (double)(end-start)) << "/sec" << std::endl; - - fs->umount(); - -} - diff --git a/src/test/barclass.cc b/src/test/barclass.cc new file mode 100644 index 000000000000..f5354f1e0f3a --- /dev/null +++ b/src/test/barclass.cc @@ -0,0 +1,48 @@ + + + +#include +#include +#include + +#include "objclass/objclass.h" + +CLS_VER(1,0) +CLS_NAME(bar) + +cls_handle_t h_class; + +cls_method_handle_t h_foo; + +int foo_method(cls_method_context_t ctx, char *indata, int datalen, + char **outdata, int *outdatalen) +{ + int i; + + cls_log("hello world, this is bar"); + cls_log("indata=%s", indata); + + *outdata = (char *)malloc(128); + for (i=0; i +#include +#include + +#include "objclass/objclass.h" + +CLS_VER(1,0) +CLS_NAME(foo) + +cls_handle_t h_class; + +cls_method_handle_t h_foo; + +int foo_method(cls_method_context_t ctx, char *indata, int datalen, + char **outdata, int *outdatalen) +{ + int i; + + cls_log("hello world, this is foo"); + cls_log("indata=%s", indata); + + *outdata = (char *)malloc(128); + for (i=0; i + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include "os/FileStore.h" +#include "global/global_init.h" +#include "common/ceph_argparse.h" +#include "common/debug.h" + +#undef dout_prefix +#define dout_prefix *_dout + +struct io { + utime_t start, ack, commit; + bool done() { + return ack.sec() && commit.sec(); + } +}; +map writes; +Cond cond; +Mutex lock("streamtest.cc lock"); + +unsigned concurrent = 1; +void throttle() +{ + Mutex::Locker l(lock); + while (writes.size() >= concurrent) { + //generic_dout(0) << "waiting" << dendl; + cond.Wait(lock); + } +} + +double total_ack = 0; +double total_commit = 0; +int total_num = 0; + +void pr(off_t off) +{ + io &i = writes[off]; + if (false) cout << off << "\t" + << (i.ack - i.start) << "\t" + << (i.commit - i.start) << std::endl; + total_num++; + total_ack += (i.ack - i.start); + total_commit += (i.commit - i.start); + writes.erase(off); + cond.Signal(); +} + +void set_start(off_t off, utime_t t) +{ + Mutex::Locker l(lock); + writes[off].start = t; +} + +void set_ack(off_t off, utime_t t) +{ + Mutex::Locker l(lock); + //generic_dout(0) << "ack " << off << dendl; + writes[off].ack = t; + if (writes[off].done()) + pr(off); +} + +void set_commit(off_t off, utime_t t) +{ + Mutex::Locker l(lock); + //generic_dout(0) << "commit " << off << dendl; + writes[off].commit = t; + if (writes[off].done()) + pr(off); +} + + +struct C_Ack : public Context { + off_t off; + C_Ack(off_t o) : off(o) {} + void finish(int r) { + set_ack(off, ceph_clock_now(g_ceph_context)); + } +}; +struct C_Commit : public Context { + off_t off; + C_Commit(off_t o) : off(o) {} + void finish(int r) { + set_commit(off, ceph_clock_now(g_ceph_context)); + } +}; + + +int main(int argc, const char **argv) +{ + vector args; + argv_to_vec(argc, argv, args); + env_to_vec(args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + // args + if (args.size() < 3) return -1; + const char *filename = args[0]; + int seconds = atoi(args[1]); + int bytes = atoi(args[2]); + const char *journal = 0; + if (args.size() >= 4) + journal = args[3]; + if (args.size() >= 5) + concurrent = atoi(args[4]); + + cout << "concurrent = " << concurrent << std::endl; + + buffer::ptr bp(bytes); + bp.zero(); + bufferlist bl; + bl.push_back(bp); + + //float interval = 1.0 / 1000; + + cout << "#dev " << filename + << ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl; + + ObjectStore *fs = new FileStore(filename, journal); + + if (fs->mkfs() < 0) { + cout << "mkfs failed" << std::endl; + return -1; + } + + if (fs->mount() < 0) { + cout << "mount failed" << std::endl; + return -1; + } + + ObjectStore::Transaction ft; + ft.create_collection(coll_t()); + fs->apply_transaction(ft); + + utime_t now = ceph_clock_now(g_ceph_context); + utime_t start = now; + utime_t end = now; + end += seconds; + off_t pos = 0; + //cout << "stop at " << end << std::endl; + cout << "# offset\tack\tcommit" << std::endl; + while (now < end) { + sobject_t poid(object_t("streamtest"), 0); + + set_start(pos, ceph_clock_now(g_ceph_context)); + ObjectStore::Transaction *t = new ObjectStore::Transaction; + t->write(coll_t(), hobject_t(poid), pos, bytes, bl); + fs->queue_transaction(NULL, t, new C_Ack(pos), new C_Commit(pos)); + pos += bytes; + + throttle(); + + now = ceph_clock_now(g_ceph_context); + + // wait? + /* + utime_t next = start; + next += interval; + if (now < next) { + float s = next - now; + s *= 1000 * 1000; // s -> us + //cout << "sleeping for " << s << " us" << std::endl; + usleep((int)s); + } + */ + } + + cout << "total num " << total_num << std::endl; + cout << "avg ack\t" << (total_ack / (double)total_num) << std::endl; + cout << "avg commit\t" << (total_commit / (double)total_num) << std::endl; + cout << "tput\t" << prettybyte_t((double)(total_num * bytes) / (double)(end-start)) << "/sec" << std::endl; + + fs->umount(); + +} + diff --git a/src/test/test_trans.cc b/src/test/test_trans.cc new file mode 100644 index 000000000000..43821c13aecc --- /dev/null +++ b/src/test/test_trans.cc @@ -0,0 +1,77 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include "common/ceph_argparse.h" +#include "common/debug.h" +#include "os/FileStore.h" +#include "global/global_init.h" +#include "include/assert.h" + +#define dout_subsys ceph_subsys_filestore +#undef dout_prefix +#define dout_prefix *_dout + +struct Foo : public Thread { + void *entry() { + dout(0) << "foo started" << dendl; + sleep(1); + dout(0) << "foo asserting 0" << dendl; + assert(0); + } +} foo; + +int main(int argc, const char **argv) +{ + vector args; + argv_to_vec(argc, argv, args); + env_to_vec(args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + // args + if (args.size() < 2) return -1; + const char *filename = args[0]; + int mb = atoi(args[1]); + + cout << "#dev " << filename << std::endl; + cout << "#mb " << mb << std::endl; + + ObjectStore *fs = new FileStore(filename, NULL); + if (fs->mount() < 0) { + cout << "mount failed" << std::endl; + return -1; + } + + ObjectStore::Transaction t; + char buf[1 << 20]; + bufferlist bl; + bl.append(buf, sizeof(buf)); + t.create_collection(coll_t()); + + for (int i=0; iapply_transaction(t); + +} + diff --git a/src/test/testclass.cc b/src/test/testclass.cc new file mode 100644 index 000000000000..22a97be6dcbb --- /dev/null +++ b/src/test/testclass.cc @@ -0,0 +1,57 @@ + + + +#include +#include +#include + +#include "objclass/objclass.h" + +CLS_VER(1,0) +CLS_NAME(test) + +cls_handle_t h_class; + +cls_method_handle_t h_foo; + +int foo_method(cls_method_context_t ctx, char *indata, int datalen, + char **outdata, int *outdatalen) +{ + int i, r; + + cls_log("hello world"); + cls_log("indata=%s", indata); + + *outdata = (char *)cls_alloc(128); + for (i=0; i args; + argv_to_vec(argc, argv, args); + env_to_vec(args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + KeyRing extra; + KeyServer server(g_ceph_context, &extra); + + generic_dout(0) << "server created" << dendl; + + getchar(); + +#if 0 + char aes_key[AES_KEY_LEN]; + memset(aes_key, 0x77, sizeof(aes_key)); + bufferptr keybuf(aes_key, sizeof(aes_key)); + CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf); + + const char *msg="hello! this is a message\n"; + char pad[16]; + memset(pad, 0, 16); + bufferptr ptr(msg, strlen(msg)); + bufferlist enc_in; + enc_in.append(ptr); + enc_in.append(msg, strlen(msg)); + + bufferlist enc_out; + if (key.encrypt(enc_in, enc_out) < 0) { + derr(0) << "couldn't encode!" << dendl; + exit(1); + } + + const char *enc_buf = enc_out.c_str(); + for (unsigned i=0; i + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include +#include +using namespace std; + +#include "common/config.h" + +#include "mon/MonMap.h" +#include "mon/MonClient.h" +#include "msg/Messenger.h" +#include "messages/MPing.h" + +#include "common/Timer.h" +#include "global/global_init.h" +#include "common/ceph_argparse.h" + +#ifndef DARWIN +#include +#endif // DARWIN + +#include +#include + +#define dout_subsys ceph_subsys_ms + +Messenger *messenger = 0; + +Mutex lock("mylock"); +Cond cond; + +uint64_t received = 0; + +class Admin : public Dispatcher { +public: + Admin() + : Dispatcher(g_ceph_context) + { + } +private: + bool ms_dispatch(Message *m) { + + //cerr << "got ping from " << m->get_source() << std::endl; + dout(0) << "got ping from " << m->get_source() << dendl; + lock.Lock(); + ++received; + cond.Signal(); + lock.Unlock(); + + m->put(); + return true; + } + + bool ms_handle_reset(Connection *con) { return false; } + void ms_handle_remote_reset(Connection *con) {} + +} dispatcher; + + +int main(int argc, const char **argv, const char *envp[]) { + + vector args; + argv_to_vec(argc, argv, args); + env_to_vec(args); + + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); + common_init_finish(g_ceph_context); + + dout(0) << "i am mon " << args[0] << dendl; + + // get monmap + MonClient mc(g_ceph_context); + if (mc.build_initial_monmap() < 0) + return -1; + + // start up network + int whoami = mc.monmap.get_rank(args[0]); + assert(whoami >= 0); + ostringstream ss; + ss << mc.monmap.get_addr(whoami); + std::string sss(ss.str()); + g_ceph_context->_conf->set_val("public_addr", sss.c_str()); + g_ceph_context->_conf->apply_changes(NULL); + Messenger *rank = Messenger::create(g_ceph_context, + entity_name_t::MON(whoami), "tester", + getpid()); + int err = rank->bind(g_ceph_context->_conf->public_addr); + if (err < 0) + return 1; + + // start monitor + messenger = rank; + messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH); + messenger->add_dispatcher_head(&dispatcher); + + rank->start(); + + int isend = 0; + if (whoami == 0) + isend = 100; + + lock.Lock(); + uint64_t sent = 0; + while (1) { + while (received + isend <= sent) { + //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl; + dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl; + cond.Wait(lock); + } + + int t = rand() % mc.get_num_mon(); + if (t == whoami) + continue; + + if (rand() % 10 == 0) { + //cerr << "mark_down " << t << std::endl; + dout(0) << "mark_down " << t << dendl; + messenger->mark_down(mc.get_mon_addr(t)); + } + //cerr << "pinging " << t << std::endl; + dout(0) << "pinging " << t << dendl; + messenger->send_message(new MPing, mc.get_mon_inst(t)); + cerr << isend << "\t" << ++sent << "\t" << received << "\r"; + } + lock.Unlock(); + + // wait for messenger to finish + rank->wait(); + + return 0; +} + diff --git a/src/test_trans.cc b/src/test_trans.cc deleted file mode 100644 index 43821c13aecc..000000000000 --- a/src/test_trans.cc +++ /dev/null @@ -1,77 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2004-2006 Sage Weil - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include "common/ceph_argparse.h" -#include "common/debug.h" -#include "os/FileStore.h" -#include "global/global_init.h" -#include "include/assert.h" - -#define dout_subsys ceph_subsys_filestore -#undef dout_prefix -#define dout_prefix *_dout - -struct Foo : public Thread { - void *entry() { - dout(0) << "foo started" << dendl; - sleep(1); - dout(0) << "foo asserting 0" << dendl; - assert(0); - } -} foo; - -int main(int argc, const char **argv) -{ - vector args; - argv_to_vec(argc, argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - - // args - if (args.size() < 2) return -1; - const char *filename = args[0]; - int mb = atoi(args[1]); - - cout << "#dev " << filename << std::endl; - cout << "#mb " << mb << std::endl; - - ObjectStore *fs = new FileStore(filename, NULL); - if (fs->mount() < 0) { - cout << "mount failed" << std::endl; - return -1; - } - - ObjectStore::Transaction t; - char buf[1 << 20]; - bufferlist bl; - bl.append(buf, sizeof(buf)); - t.create_collection(coll_t()); - - for (int i=0; iapply_transaction(t); - -} - diff --git a/src/testclass.cc b/src/testclass.cc deleted file mode 100644 index 22a97be6dcbb..000000000000 --- a/src/testclass.cc +++ /dev/null @@ -1,57 +0,0 @@ - - - -#include -#include -#include - -#include "objclass/objclass.h" - -CLS_VER(1,0) -CLS_NAME(test) - -cls_handle_t h_class; - -cls_method_handle_t h_foo; - -int foo_method(cls_method_context_t ctx, char *indata, int datalen, - char **outdata, int *outdatalen) -{ - int i, r; - - cls_log("hello world"); - cls_log("indata=%s", indata); - - *outdata = (char *)cls_alloc(128); - for (i=0; i args; - argv_to_vec(argc, argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - KeyRing extra; - KeyServer server(g_ceph_context, &extra); - - generic_dout(0) << "server created" << dendl; - - getchar(); - -#if 0 - char aes_key[AES_KEY_LEN]; - memset(aes_key, 0x77, sizeof(aes_key)); - bufferptr keybuf(aes_key, sizeof(aes_key)); - CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf); - - const char *msg="hello! this is a message\n"; - char pad[16]; - memset(pad, 0, 16); - bufferptr ptr(msg, strlen(msg)); - bufferlist enc_in; - enc_in.append(ptr); - enc_in.append(msg, strlen(msg)); - - bufferlist enc_out; - if (key.encrypt(enc_in, enc_out) < 0) { - derr(0) << "couldn't encode!" << dendl; - exit(1); - } - - const char *enc_buf = enc_out.c_str(); - for (unsigned i=0; i - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#include -#include -#include -using namespace std; - -#include "common/config.h" - -#include "mon/MonMap.h" -#include "mon/MonClient.h" -#include "msg/Messenger.h" -#include "messages/MPing.h" - -#include "common/Timer.h" -#include "global/global_init.h" -#include "common/ceph_argparse.h" - -#ifndef DARWIN -#include -#endif // DARWIN - -#include -#include - -#define dout_subsys ceph_subsys_ms - -Messenger *messenger = 0; - -Mutex lock("mylock"); -Cond cond; - -uint64_t received = 0; - -class Admin : public Dispatcher { -public: - Admin() - : Dispatcher(g_ceph_context) - { - } -private: - bool ms_dispatch(Message *m) { - - //cerr << "got ping from " << m->get_source() << std::endl; - dout(0) << "got ping from " << m->get_source() << dendl; - lock.Lock(); - ++received; - cond.Signal(); - lock.Unlock(); - - m->put(); - return true; - } - - bool ms_handle_reset(Connection *con) { return false; } - void ms_handle_remote_reset(Connection *con) {} - -} dispatcher; - - -int main(int argc, const char **argv, const char *envp[]) { - - vector args; - argv_to_vec(argc, argv, args); - env_to_vec(args); - - global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0); - common_init_finish(g_ceph_context); - - dout(0) << "i am mon " << args[0] << dendl; - - // get monmap - MonClient mc(g_ceph_context); - if (mc.build_initial_monmap() < 0) - return -1; - - // start up network - int whoami = mc.monmap.get_rank(args[0]); - assert(whoami >= 0); - ostringstream ss; - ss << mc.monmap.get_addr(whoami); - std::string sss(ss.str()); - g_ceph_context->_conf->set_val("public_addr", sss.c_str()); - g_ceph_context->_conf->apply_changes(NULL); - Messenger *rank = Messenger::create(g_ceph_context, - entity_name_t::MON(whoami), "tester", - getpid()); - int err = rank->bind(g_ceph_context->_conf->public_addr); - if (err < 0) - return 1; - - // start monitor - messenger = rank; - messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH); - messenger->add_dispatcher_head(&dispatcher); - - rank->start(); - - int isend = 0; - if (whoami == 0) - isend = 100; - - lock.Lock(); - uint64_t sent = 0; - while (1) { - while (received + isend <= sent) { - //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl; - dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl; - cond.Wait(lock); - } - - int t = rand() % mc.get_num_mon(); - if (t == whoami) - continue; - - if (rand() % 10 == 0) { - //cerr << "mark_down " << t << std::endl; - dout(0) << "mark_down " << t << dendl; - messenger->mark_down(mc.get_mon_addr(t)); - } - //cerr << "pinging " << t << std::endl; - dout(0) << "pinging " << t << dendl; - messenger->send_message(new MPing, mc.get_mon_inst(t)); - cerr << isend << "\t" << ++sent << "\t" << received << "\r"; - } - lock.Unlock(); - - // wait for messenger to finish - rank->wait(); - - return 0; -} -