double InterferenceHelper::CalculateChunkSuccessRate (double snir, Time duration, WifiMode mode) const { if (duration == NanoSeconds (0)) { return 1.0; } uint32_t rate = mode.GetPhyRate (); uint64_t nbits = (uint64_t)(rate * duration.GetSeconds ()); double csr = m_errorRateModel->GetChunkSuccessRate (mode, snir, (uint32_t)nbits); return csr; }
Producer::Config::Config( const string& file, uint32_t id ) { // set default values prefix = Name("unnamed"); sigverif_delay = NanoSeconds( 30345 ); bloom_delay = NanoSeconds( 2535 ); // database and vm structs unqlite* db; unqlite_vm* vm; // initialize database int rc = unqlite_open( &db, ":mem:", UNQLITE_OPEN_READONLY ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: creating unqlite database: " << err << endl; exit(1); } // initialize unqlite vm rc = unqlite_compile_file( db, file.c_str(), &vm ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: compiling config script: " << err << endl; exit(1); } unqlite_value* id_val = unqlite_vm_new_scalar( vm ); unqlite_value_int64( id_val, id ); rc = unqlite_vm_config( vm, UNQLITE_VM_CONFIG_CREATE_VAR, "ID", id_val ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: exporting ID to config: " << err << endl; exit(1); } unqlite_vm_release_value( vm, id_val ); // execute config script rc = unqlite_vm_exec( vm ); if( rc != UNQLITE_OK ) { // something went wrong const char* err; int errlen; unqlite_config( db, UNQLITE_CONFIG_JX9_ERR_LOG, &err, &errlen ); cout << "Error: executing config script: " << err << endl; exit(1); } // retrieve config values const char* str; int len; unqlite_value* val; val = unqlite_vm_extract_variable( vm, "prefix" ); if( val ) { str = unqlite_value_to_string( val, &len ); prefix = string(str, len ); } val = unqlite_vm_extract_variable( vm, "sigverif_delay" ); if( unqlite_value_is_float( val ) ) sigverif_delay = Seconds( unqlite_value_to_double( val ) ); if( unqlite_value_is_int( val ) ) sigverif_delay = Seconds( unqlite_value_to_int64( val ) ); val = unqlite_vm_extract_variable( vm, "bloom_delay" ); if( unqlite_value_is_float( val ) ) bloom_delay = Seconds( unqlite_value_to_double( val ) ); if( unqlite_value_is_int( val ) ) bloom_delay = Seconds( unqlite_value_to_int64( val ) ); val = unqlite_vm_extract_variable( vm, "contents" ); if( val && unqlite_value_is_json_array( val ) ) { size_t count = unqlite_array_count( val ); for( size_t i = 0 ; i < count ; i++ ) { stringstream ss; string key; ss << i; ss >> key; unqlite_value* elem = unqlite_array_fetch ( val, key.c_str(), key.size() ); if( elem && unqlite_value_is_json_object( elem ) ) { unqlite_value* name_val = unqlite_array_fetch ( elem, "name", -1 ); unqlite_value* size_val = unqlite_array_fetch ( elem, "size", -1 ); unqlite_value* access_val = unqlite_array_fetch( elem, "access_level", -1 ); if( name_val && size_val && access_val && unqlite_value_is_string( name_val ) && unqlite_value_is_int( size_val ) && unqlite_value_is_int( access_val ) ) { str = unqlite_value_to_string( name_val, &len ); size_t size = unqlite_value_to_int( size_val ); uint8_t access_level = unqlite_value_to_int ( access_val ); contents.emplace( string( str, len ), Config::Content { size, access_level } ); } } } }
uint64_t Synchronizer::NanosecondToTimeStep (uint64_t ns) { NS_LOG_FUNCTION (this << ns); return NanoSeconds (ns).GetTimeStep (); }
/* * Note: if the link bandwidth changes in the course of the * simulation, the bandwidth-dependent RED parameters do not change. * This should be fixed, but it would require some extra parameters, * and didn't seem worth the trouble... */ void RedQueue::InitializeParams (void) { NS_LOG_FUNCTION (this); NS_ASSERT (m_minTh <= m_maxTh); m_stats.forcedDrop = 0; m_stats.unforcedDrop = 0; m_stats.qLimDrop = 0; m_cautious = 0; m_ptc = m_linkBandwidth.GetBitRate () / (8.0 * m_meanPktSize); m_qAvg = 0.0; m_count = 0; m_countBytes = 0; m_old = 0; m_idle = 1; double th_diff = (m_maxTh - m_minTh); if (th_diff == 0) { th_diff = 1.0; } m_vA = 1.0 / th_diff; m_curMaxP = 1.0 / m_lInterm; m_vB = -m_minTh / th_diff; if (m_isGentle) { m_vC = (1.0 - m_curMaxP) / m_maxTh; m_vD = 2.0 * m_curMaxP - 1.0; } m_idleTime = NanoSeconds (0); /* * If m_qW=0, set it to a reasonable value of 1-exp(-1/C) * This corresponds to choosing m_qW to be of that value for * which the packet time constant -1/ln(1-m)qW) per default RTT * of 100ms is an order of magnitude more than the link capacity, C. * * If m_qW=-1, then the queue weight is set to be a function of * the bandwidth and the link propagation delay. In particular, * the default RTT is assumed to be three times the link delay and * transmission delay, if this gives a default RTT greater than 100 ms. * * If m_qW=-2, set it to a reasonable value of 1-exp(-10/C). */ if (m_qW == 0.0) { m_qW = 1.0 - std::exp (-1.0 / m_ptc); } else if (m_qW == -1.0) { double rtt = 3.0 * (m_linkDelay.GetSeconds () + 1.0 / m_ptc); if (rtt < 0.1) { rtt = 0.1; } m_qW = 1.0 - std::exp (-1.0 / (10 * rtt * m_ptc)); } else if (m_qW == -2.0) { m_qW = 1.0 - std::exp (-10.0 / m_ptc); } /// \todo implement adaptive RED NS_LOG_DEBUG ("\tm_delay " << m_linkDelay.GetSeconds () << "; m_isWait " << m_isWait << "; m_qW " << m_qW << "; m_ptc " << m_ptc << "; m_minTh " << m_minTh << "; m_maxTh " << m_maxTh << "; m_isGentle " << m_isGentle << "; th_diff " << th_diff << "; lInterm " << m_lInterm << "; va " << m_vA << "; cur_max_p " << m_curMaxP << "; v_b " << m_vB << "; m_vC " << m_vC << "; m_vD " << m_vD); }