// constructors static void gen_header(header* const hdr) { gen_random_string(hdr->SenderCompID, sizeof(hdr->SenderCompID)); gen_random_string(hdr->TargetCompID, sizeof(hdr->TargetCompID)); hdr->MsgSeqNum = rand() + 1; hdr->PossDupFlag = CHAR_FROM("YN"); gen_timestamp(&hdr->SendingTime); }
static void gen_new_order_single(fix_message_data* data) { data->hdr.MsgType = 'D'; gen_header(&data->hdr); gen_random_string(data->order.Account, sizeof(data->order.Account)); gen_random_string(data->order.ClOrdID, sizeof(data->order.ClOrdID)); gen_timestamp(&data->order.TransactTime); data->order.HandlInst = CHAR_FROM("123"); data->order.OrdType = CHAR_FROM("123456789DEGIJKLMP"); data->order.Side = CHAR_FROM("123456789ABCDEFG"); data->order.TimeInForce = CHAR_FROM("1234567"); data->order.Price = gen_price(); }
void RecurrentDnsStatsMonitor::run(unsigned int frequency, unsigned int cycles) { dns_test_frequency = frequency; max_num_cycles = cycles; if(dns_test_frequency <= 0) { // minimum frequency is 1 second return; } bool check_cycles = false; // default: no check on number of cycles executed if(max_num_cycles > 0) { check_cycles = true; } std::string random_prepending; std::stringstream domain_to_query; double latency; while(true) { // we generate one random string to prepend per cycle random_prepending = gen_random_string(10); std::time_t cur_time = std::time(NULL); std::map<int,std::string>::const_iterator it; for(it = top_domains.begin(); it != top_domains.end(); it++) { domain_to_query.str(""); domain_to_query << random_prepending << "." << it->second; // domain_name latency = dr.query_nameserver(domain_to_query.str()); ddh.update_dns_stats(it->first /*domain_id*/, latency, cur_time); } if(check_cycles) { max_num_cycles--; if(max_num_cycles == 0){ break; } } // wait for <frequency> seconds sleep(dns_test_frequency); } }
void NetworkCoding::receiveCodedBlock(NetworkCoding_t networkcoding) { printf("received coded block=%s\n",networkcoding.getName().c_str()); m_stat.totalBlockReceived++; std::string parentObjectName = networkcoding.parentObjectName; printf("unreject=%s\n",parentObjectName.c_str()); this->rejectedobject[parentObjectName] = false; const bool is_already_completed = this->networkcodingobjectsreceived.find(parentObjectName) != this->networkcodingobjectsreceived.end(); if(is_already_completed) { //do nothing return; } trackCodedBlock(parentObjectName,networkcoding); //check if we already started decoding for this object if( this->decoder.find(parentObjectName) == this->decoder.end() ) { //create decoder std::string randomFileName = "out-"+gen_random_string(10); size_t blockSize= OBJECT_BLOCK_SIZE; long fileSize = networkcoding.parentObjectFileSize; decoderptr _decoder( new codetorrentdecoder(fileSize,randomFileName.c_str(),blockSize)); this->decoder[parentObjectName] = _decoder; } std::string blockStorageId = networkcoding.getName(); printf("calling getfile\n"); codedblockptr_t block = getFile(networkcoding.getBlockIdOnly()); printf("after getfile\n"); //TODO read should be threadsafe //boost::lock_guard<boost::mutex> guard(codedblockstoragemutex); //codedblockptr block = codedblockstorage[blockStorageId]; decoderptr localDecoder = this->decoder[parentObjectName]; int gen = 0; bool isHelpful = localDecoder->store_block(gen,block->coeffs,block->sums); printf("isHelpful=%d coded block=%s isMixed=%d targetnodeid=%d\n", isHelpful,networkcoding.getName().c_str(),networkcoding.isMixed, networkcoding.targetNodeId+1); bool isDone = localDecoder->decode(); if(isDone) { m_stat.totalObjectReconstructed++; //this->RegisterObject(networkcoding.parentObjectName); this->networkcodingobjectsreceived.insert(networkcoding.parentObjectName); //clean up once constructed no longer need decoder this->decoder.erase(parentObjectName); this->cleanUpBlocksInDataStore(parentObjectName); this->parenttoblockidsmapping.erase(parentObjectName); SetIcanEvent(m_node, 0, MSG_ROUTING_ICAN_DTNMANAGER_NETWORKCODINGOBJECTCONSTRUCTED, sizeof(networkcoding), &networkcoding); } }
void RecurrentDnsStatsMonitor::single_domain_run(int domain_id, std::string domain_name) { if(dns_test_frequency <= 0) { // minimum frequency is 1 second return; } // we do not modify the class variable (it is shared) int cycles = max_num_cycles; bool check_cycles = false; // default: no check on number of cycles executed if(cycles > 0) { check_cycles = true; } std::string random_prepending; std::stringstream domain_to_query; double latency; while(true) { // we generate one random string to prepend per cycle random_prepending = gen_random_string(10); std::time_t cur_time = std::time(NULL); domain_to_query << random_prepending << "." << domain_name; latency = dr.query_nameserver(domain_to_query.str()); ddh.update_dns_stats(domain_id, latency, cur_time); if(check_cycles) { cycles--; if(cycles == 0){ break; } } // wait for <frequency> seconds sleep(dns_test_frequency); domain_to_query.str(""); } }
const TestData& MsgpackTester::GenerateData(uint32_t num) { MsgpackTestData* d = new MsgpackTestData(num); for (uint32_t i = 0; i < num; ++i) { d->objs_[i].set_key(gen_random_string(8)); d->objs_[i].set_value(rand()); } return *d; }
message *add_random_message(mail_queue *mq) { message *m = calloc(sizeof(message)); m->sender = pick_address(); m->recipient = pick_address(); m->subject = gen_random_string(5, 32); m->data = gen_random_string(5,256); m->data_length = cgc_strlen(m->data); if (mq->root != NULL) { message *next = mq->root; while (next->next != NULL) { next = next->next; } next->next = m; } return m; }
/* If the default token, which is "token", is already among frequent words, generate random string to replace "token". */ static void set_token(struct Parameters *pParam) { while (find_elem(pParam->token, pParam->ppWordTable, pParam->wordTableSize, pParam->wordTableSeed)) { gen_random_string(pParam->token, TOKENLEN - 1); } }
address *add_random_addressbook_entry() { address *a = calloc(sizeof(address)); a->name = gen_random_string(5, 32); a->home_server = gen_random_string(5, 32); a->mode = random_in_range(0,1); address *n = abook->root; if (n == NULL) { // First Entry abook->root = a; } else { while (n->next != NULL) { n = n->next; } n->next = a; } abook->num_entries++; return a; }
void Run() { for (int i = 0; i < kReaderCount; ++i) { tests_.emplace_back(new FileReaderTest()); FileReaderTest* test = tests_.back().get(); test->file_reader.reset( new FileReaderProxy(task_queue_.get(), io_task_queue_.get())); test->test_file_contents = gen_random_string(kTestFileSize); test->test_file.Write(test->test_file_contents); test->iteration = 0; test->current_read_offset = 0; test->current_read_size = 0; } for (size_t i = 0; i < tests_.size(); ++i) { tests_[i]->file_reader->Open( tests_[i]->test_file.file_path(), std::bind(&MultipleFileReadersTest::OpenCallback, this, i, std::placeholders::_1)); } task_queue_->Run(); }
//========================================================================================================== // Generate the call-id string //========================================================================================================== string ScriptReader::gen_call_id(CallIDKind kind) { switch(kind) { case RANDOM: { string res; gen_random_string(res, 1, &SipParser::inst().sip_word_chars); return res; } case MIN: { return "!"; } case MAX: { return string(50, '~'); } default: throw string("ScriptReader::gen_call_id() called with NONE"); } }
NetworkCoding_t NetworkCoding::createCodedBlockFromObject(std::string parentObjectName, unsigned targetNodeId,long parentObjectFileSize) { //check if we already started encoding for this object if( this->encoder.find(parentObjectName) == this->encoder.end() ) { //create encoder printf("creating encoder for parentObjectName=%s\n",parentObjectName.c_str()); std::string randomFileName = "input-"+gen_random_string(256);; size_t blockSize= OBJECT_BLOCK_SIZE; gen_random(randomFileName,parentObjectFileSize); encoderptr _encoder( new codetorrentencoder(randomFileName.c_str(),blockSize,parentObjectFileSize)); this->encoder[parentObjectName] = _encoder; } encoderptr localEncoder = this->encoder[parentObjectName]; bool isMixingEnabled = false; const bool is_in = this->networkcodingobjectsreceived.find(parentObjectName) != this->networkcodingobjectsreceived.end(); const bool full_cache_code = is_in && m_ncOption==nc_fullobjectonly; const bool mixing_full_cache_code = is_in && m_ncOption == nc_mixing; const bool is_in_registry = this->objectpublisherregistry.find(parentObjectName) != this->objectpublisherregistry.end(); //full cache encoding if(full_cache_code || mixing_full_cache_code ) { //check if ok to send printf("full object encoding nodeid=%d\n",this->thisNodeId); int blockId = rand() % MAXID; NetworkCoding_t networkCoding(parentObjectName, parentObjectFileSize, targetNodeId,blockId,false); CodedBlockPtr block = localEncoder->encode(); block->id = blockId; std::string blockStorageId = networkCoding.getName(); codedblockptr_t _codedblockptr(block,freeCodedBlock); writeFile(networkCoding.getBlockIdOnly(),block); //boost::lock_guard<boost::mutex> guard(codedblockstoragemutex); //this->codedblockstorage[blockStorageId] = _codedblockptr; m_stat.totalBlockGenerated++; trackCodedBlock(parentObjectName,networkCoding); printf("full encoding nodeid=%d name=%s\n",this->thisNodeId,networkCoding.getName().c_str()); return networkCoding; } //mixing else if(m_ncOption == nc_mixing){ printf("mixing nodeid=%d\n",this->thisNodeId); const bool is_in_rejected = this->rejectedobject.find(parentObjectName) != this->rejectedobject.end(); //PrintTime(NULL); //TODO if(is_in_rejected && !is_in ) { bool isStopSend = this->rejectedobject[parentObjectName]; if(isStopSend) { printf("reject stopsend=%s\n",parentObjectName.c_str()); NetworkCoding_t none; return none; } } //check if started receiving blocks and have blocks to mix if( this->decoder.find(parentObjectName) == this->decoder.end() ) { NetworkCoding_t none; return none; } decoderptr localDecoder = this->decoder[parentObjectName]; CodedBlockPtr blockMix = localDecoder->mix(); int blockId = rand() % MAXID; blockMix->id = blockId; NetworkCoding_t networkCoding(parentObjectName, parentObjectFileSize, targetNodeId,blockId,true); std::string blockStorageId = networkCoding.getName(); codedblockptr_t _codedblockptr(blockMix,freeCodedBlock); writeFile(networkCoding.getBlockIdOnly(),blockMix); //boost::lock_guard<boost::mutex> guard(codedblockstoragemutex); //this->codedblockstorage[blockStorageId] = _codedblockptr; m_stat.totalBlockGenerated++; trackCodedBlock(parentObjectName,networkCoding); printf("mixing nodeid=%d name=%s\n",this->thisNodeId,networkCoding.getName().c_str()); return networkCoding; } //forward random block not in target's bloomfilter else if(m_ncOption == nc_sourceonly && is_in && is_in_registry){ printf("source only coding nodeid=%d\n",this->thisNodeId); //can do source coding printf("generaring source block for parentObjectName=%s\n",parentObjectName.c_str()); int blockId = rand() % MAXID; NetworkCoding_t networkCoding(parentObjectName, parentObjectFileSize, targetNodeId,blockId,false); CodedBlockPtr block = localEncoder->encode(); block->print(); std::string blockStorageId = networkCoding.getName(); codedblockptr_t _codedblockptr(block,freeCodedBlock); writeFile(networkCoding.getBlockIdOnly(),block); //boost::lock_guard<boost::mutex> guard(codedblockstoragemutex); //this->codedblockstorage[blockStorageId] = _codedblockptr; m_stat.totalBlockGenerated++; trackCodedBlock(parentObjectName,networkCoding); printf("source only coding nodeid=%d name=%s\n",this->thisNodeId,networkCoding.getName().c_str()); return networkCoding; } else{ NetworkCoding_t networkCoding = this->getBlockToSendTarget(parentObjectName,targetNodeId,parentObjectFileSize); networkCoding.targetNodeId = targetNodeId; printf("forward random nodeid=%d block=%s\n",this->thisNodeId,networkCoding.getName().c_str()); return networkCoding; } }
//========================================================================================================== // Generate a random tag string, at least 4 bytes long //========================================================================================================== string ScriptReader::gen_tag() { string res; gen_random_string(res, 4, &SipParser::inst().sip_token_chars); // Must be at least 32-bits long return res; }
//========================================================================================================== // Generate a random branch string, that must begin with the constant prefix according to the spec. //========================================================================================================== string ScriptReader::gen_branch() { string res = "z9hG4bK"; // Must start with this gen_random_string(res, 10, &SipParser::inst().sip_token_chars); return res; }
int main(int argc, char ** argv) { GetPot cl(argc, argv); // Command line parsing if(!cl.search("--input")) { std::cerr << "No --input argument found!" << std::endl; usage_error(argv[0]); } const char * meshname = cl.next(""); if(!cl.search("--oldid")) { std::cerr << "No --oldid argument found!" << std::endl; usage_error(argv[0]); } long oldid = cl.next(0); if(!cl.search("--newid")) { std::cerr << "No --newid argument found!" << std::endl; usage_error(argv[0]); } long newid = cl.next(0); unsigned char flags = 0; if (cl.search("--nodesetonly")) flags |= NODES; if (cl.search("--sidesetonly")) flags |= SIDES; if (cl.search("--blockonly")) flags |= BLOCKS; if (cl.search("--dim")) flags |= EXODUS_DIM; // No command line flags were set, turn on NODES, SIDES, and BLOCKS if (!flags) flags = NODES | SIDES | BLOCKS; // ALL except EXODUS_DIM on // flags are exclusive if (flags != NODES && flags != SIDES && flags != BLOCKS && flags != EXODUS_DIM && flags != (NODES | SIDES | BLOCKS)) { std::cerr << "Only one of the following options may be active [--nodesetonly | --sidesetonly | --blockonly | --dim]!" << std::endl; usage_error(argv[0]); } // Processing std::string var_name, dim_name; int status; int nc_id, var_id, dim_id; size_t dim_len; status = nc_open (meshname, NC_WRITE, &nc_id); if (status != NC_NOERR) handle_error(status, "Error while opening file."); for (unsigned char mask = 8; mask; mask/=2) { // These are char *'s #defined in exodsuII_int.h switch (flags & mask) { case BLOCKS: dim_name = DIM_NUM_EL_BLK; var_name = VAR_ID_EL_BLK; break; case SIDES: dim_name = DIM_NUM_SS; var_name = VAR_SS_IDS; break; case NODES: dim_name = DIM_NUM_NS; var_name = VAR_NS_IDS; break; case EXODUS_DIM: dim_name = DIM_NUM_DIM; // var_name not used for setting dimension break; default: // We don't match this flag, so go to the next mask continue; } // Get the ID and length of the variable in question - stored in a dimension field status = nc_inq_dimid (nc_id, dim_name.c_str(), &dim_id); if (status != NC_NOERR) handle_error(status, "Error while inquiring about a dimension's ID."); status = nc_inq_dimlen (nc_id, dim_id, &dim_len); if (status != NC_NOERR) handle_error(status, "Error while inquiring about a dimension's length."); if ( (flags & mask) != EXODUS_DIM) { // Now get the variable values themselves std::vector<long> var_vals(dim_len); status = nc_inq_varid (nc_id, var_name.c_str(), &var_id); if (status != NC_NOERR) handle_error(status, "Error while inquiring about a variable's ID."); status = nc_get_var_long (nc_id, var_id, &var_vals[0]); if (status != NC_NOERR) handle_error(status, "Error while retrieving a variable's values."); // Update the variable value specified on the command line for (unsigned int i=0; i<dim_len; ++i) if (var_vals[i] == oldid) var_vals[i] = newid; // Save that value back to the NetCDF database status = nc_put_var_long (nc_id, var_id, &var_vals[0]); if (status != NC_NOERR) handle_error(status, "Error while writing a variable's values."); } // Redefine the dimension else { // The value stored in dim_len is actually the dimension? if (dim_len == (size_t)oldid) { // Trying to change def's always raises // Error -38: /* Operation not allowed in data mode */ // unless you are in "define" mode. So let's go there now. // Try to put the file into define mode status = nc_redef(nc_id); if (status != NC_NOERR) handle_error(status, "Error while putting file into define mode."); // Rename the "num_dim" dimension. Note: this will fail if there is already a dimension // which has the name you are trying to use. This can happen, for example if you have already // changed the dimension of this exodus file once using this very script. There appears // to be no way to delete a dimension using basic NetCDF interfaces, so to workaround this // we just rename it to an arbitrary unique string that Exodus will ignore. // Construct a string with 6 random alpha-numeric characters at the end. std::string random_dim_name; gen_random_string(random_dim_name, 6); random_dim_name = std::string("ignored_num_dim_") + random_dim_name; // Rename the old dimension variable to our randomly-chosen name status = nc_rename_dim(nc_id, dim_id, random_dim_name.c_str()); if (status != NC_NOERR) handle_error(status, "Error while trying to rename num_dim."); // Now define a new "num_dim" value of newid int dummy=0; status = nc_def_dim (nc_id, dim_name.c_str(), newid, &dummy); if (status != NC_NOERR) handle_error(status, "Error while trying to define num_dim."); // Leave define mode status = nc_enddef(nc_id); if (status != NC_NOERR) handle_error(status, "Error while leaving define mode."); } } } // end for // Write out the dataset status = nc_close(nc_id); return (status != NC_NOERR); }