12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350 |
- /*
- This file is part of GNUnet.
- Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors)
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
- /**
- * @file ats-tests/ats-testing-experiment.c
- * @brief ats benchmark: controlled experiment execution
- * @author Christian Grothoff
- * @author Matthias Wachs
- */
- #include "platform.h"
- #include "gnunet_util_lib.h"
- #include "gnunet-ats-solver-eval.h"
- #include "gnunet-service-ats_normalization.h"
- #include "gnunet-service-ats_preferences.c"
- #define BIG_M_STRING "unlimited"
- /**
- * Handle for statistics.
- */
- struct GNUNET_STATISTICS_Handle *GSA_stats;
- static struct Experiment *e;
- static struct LoggingHandle *l;
- static struct SolverHandle *sh;
- static struct TestPeer *peer_head;
- static struct TestPeer *peer_tail;
- static double default_properties[GNUNET_ATS_PropertyCount];
- static double default_preferences[GNUNET_ATS_PreferenceCount];
- /**
- * cmd option -e: experiment file
- */
- static char *opt_exp_file;
- static char *opt_solver;
- /**
- * cmd option -l: enable logging
- */
- static int opt_log;
- /**
- * cmd option -p: enable plots
- */
- static int opt_save;
- /**
- * cmd option -v: verbose logs
- */
- static int opt_verbose;
- /**
- * cmd option -p: print logs
- */
- static int opt_print;
- /**
- * cmd option -d: disable normalization
- */
- static int opt_disable_normalization;
- static int res;
- static void
- end_now ();
- const double *
- get_property_cb (void *cls, const struct ATS_Address *address);
- static char *
- print_generator_type (enum GeneratorType g)
- {
- switch (g) {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- return "CONSTANT";
- case GNUNET_ATS_TEST_TG_LINEAR:
- return "LINEAR";
- case GNUNET_ATS_TEST_TG_RANDOM:
- return "RANDOM";
- case GNUNET_ATS_TEST_TG_SINUS:
- return "SINUS";
- default:
- return "INVALID";
- break;
- }
- }
- static struct TestPeer *
- find_peer_by_id (int id)
- {
- struct TestPeer *cur;
- for (cur = peer_head; NULL != cur; cur = cur->next)
- if (cur->id == id)
- return cur;
- return NULL;
- }
- static struct TestPeer *
- find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
- {
- struct TestPeer *cur;
- for (cur = peer_head; NULL != cur; cur = cur->next)
- if (0 == memcmp (&cur->peer_id, pid, sizeof (struct GNUNET_PeerIdentity)))
- return cur;
- return NULL;
- }
- static struct TestAddress *
- find_address_by_id (struct TestPeer *peer, int aid)
- {
- struct TestAddress *cur;
- for (cur = peer->addr_head; NULL != cur; cur = cur->next)
- if (cur->aid == aid)
- return cur;
- return NULL;
- }
- static struct TestAddress *
- find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr)
- {
- struct TestAddress *cur;
- for (cur = p->addr_head; NULL != cur; cur = cur->next)
- if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) &&
- (cur->ats_addr->addr_len == addr->addr_len) &&
- (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len)))
- return cur;
- return NULL;
- }
- /**
- * Logging
- */
- void
- GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
- {
- struct LoggingTimeStep *lts;
- struct TestPeer *cur;
- struct TestAddress *cur_addr;
- struct LoggingPeer *log_p;
- struct LoggingAddress *log_a;
- int c;
- lts = GNUNET_new (struct LoggingTimeStep);
- GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts);
- lts->timestamp = GNUNET_TIME_absolute_get();
- if (NULL == lts->prev)
- lts->delta = GNUNET_TIME_UNIT_ZERO;
- else
- lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
- lts->timestamp.abs_value_us, lts->delta.rel_value_us);
- /* Store logging data here */
- for (cur = peer_head; NULL != cur; cur = cur->next)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu\n", cur->id);
- log_p = GNUNET_new (struct LoggingPeer);
- log_p->id = cur->id;
- log_p->peer_id = cur->peer_id;
- log_p->is_requested = cur->is_requested;
- for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
- {
- log_p->pref_abs[c] = cur->pref_abs[c];
- log_p->pref_norm[c] = cur->pref_norm[c];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_preference_type(c),
- log_p->pref_abs[c], log_p->pref_norm[c]);
- }
- GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p);
- for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging peer id %llu address %llu \n",
- cur->id, cur_addr->aid);
- log_a = GNUNET_new (struct LoggingAddress);
- log_a->aid = cur_addr->aid;
- log_a->active = cur_addr->ats_addr->active;
- log_a->network = cur_addr->network;
- log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in;
- log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out;
- for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
- {
- log_a->prop_abs[c] = cur_addr->prop_abs[c];
- log_a->prop_norm[c] = cur_addr->prop_norm[c];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_property_type(c),
- log_a->prop_abs[c], log_a->prop_norm[c]);
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out);
- GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a);
- }
- }
- }
- static void
- logging_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct LoggingHandle *l = cls;
- l->logging_task = NULL;
- GNUNET_ATS_solver_logging_now (l);
- l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, &logging_task, l);
- }
- struct LoggingHandle *
- GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
- {
- struct LoggingHandle *l;
- l = GNUNET_new (struct LoggingHandle);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
- GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO));
- l->log_freq = freq;
- l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
- return l;
- }
- void
- GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
- {
- if (NULL != l->logging_task)
- GNUNET_SCHEDULER_cancel (l->logging_task);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
- l->logging_task = NULL;
- }
- static struct LoggingFileHandle *
- find_logging_file_handle (struct LoggingFileHandle *lf_head,
- struct LoggingFileHandle *lf_tail,
- int peer_id, int address_id)
- {
- struct LoggingFileHandle *res;
- for (res = lf_head; NULL != res; res = res->next)
- if ((res->pid == peer_id) && (res->aid == address_id))
- return res;
- return NULL;
- }
- void
- GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp,
- char *output_dir)
- {
- struct LoggingTimeStep *lts;
- struct LoggingPeer *log_p;
- struct LoggingAddress *log_a;
- struct LoggingFileHandle *lf_head;
- struct LoggingFileHandle *lf_tail;
- struct LoggingFileHandle *cur;
- struct LoggingFileHandle *next;
- char * filename;
- char * datastring;
- char * propstring;
- char * propstring_tmp;
- char * prefstring;
- char * prefstring_tmp;
- int c;
- int use_dir;
- use_dir = GNUNET_NO;
- if (NULL != output_dir)
- {
- if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
- {
- fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
- return;
- }
- else
- {
- fprintf (stderr, "Created directory `%s'\n", output_dir);
- use_dir = GNUNET_YES;
- }
- }
- lf_head = NULL;
- lf_tail = NULL;
- for (lts = l->head; NULL != lts; lts = lts->next)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
- (long long unsigned int) lts->timestamp.abs_value_us);
- for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
- {
- for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
- {
- cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
- log_a->aid);
- if (NULL == cur)
- {
- cur = GNUNET_new (struct LoggingFileHandle);
- cur->aid = log_a->aid;
- cur->pid = log_p->id;
- if (GNUNET_YES == add_time_stamp)
- GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
- (GNUNET_YES == use_dir) ? output_dir : "",
- (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
- e->log_prefix,
- opt_solver,
- cur->pid,
- cur->aid,
- l->head->timestamp.abs_value_us);
- else
- GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
- (GNUNET_YES == use_dir) ? output_dir : "",
- (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
- e->log_prefix,
- opt_solver,
- cur->pid,
- cur->aid);
- fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n",
- cur->pid, cur->aid, filename);
- cur->f_hd = GNUNET_DISK_file_open (filename,
- GNUNET_DISK_OPEN_READWRITE |
- GNUNET_DISK_OPEN_CREATE |
- GNUNET_DISK_OPEN_TRUNCATE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE |
- GNUNET_DISK_PERM_GROUP_READ |
- GNUNET_DISK_PERM_OTHER_READ);
- if (NULL == cur->f_hd)
- {
- fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
- GNUNET_free (filename);
- GNUNET_free (cur);
- goto cleanup;
- }
- GNUNET_free (filename);
- GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
- GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
- "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
- "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\
- "DELAY; DELAY; " \
- "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
- "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
- GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
- GNUNET_free (datastring);
- }
- prefstring = GNUNET_strdup("");
- for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
- {
- /*
- fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_preference_type(c),
- log_p->pref_abs[c], log_p->pref_norm[c]);
- */
- GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f",
- prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
- GNUNET_free (prefstring);
- prefstring = GNUNET_strdup(prefstring_tmp);
- GNUNET_free (prefstring_tmp);
- }
- propstring = GNUNET_strdup("");
- for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
- {
- if (GNUNET_ATS_NETWORK_TYPE == c)
- continue;
- /*
- fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_property_type(c),
- log_a->prop_abs[c], log_a->prop_norm[c]);*/
- GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;",
- propstring, log_a->prop_abs[c], log_a->prop_norm[c]);
- GNUNET_free (propstring);
- propstring = GNUNET_strdup(propstring_tmp);
- GNUNET_free (propstring_tmp);
- }
- GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
- GNUNET_TIME_absolute_get_difference (l->head->timestamp,
- lts->timestamp).rel_value_us / 1000, lts->delta,
- log_p->is_requested, log_a->network, log_a->active,
- log_a->assigned_bw_in, log_a->assigned_bw_out, propstring,
- prefstring);
- GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring));
- GNUNET_free (datastring);
- GNUNET_free (prefstring);
- GNUNET_free (propstring);
- }
- }
- }
- cleanup:
- next = lf_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
- if (NULL != cur->f_hd)
- GNUNET_DISK_file_close (cur->f_hd);
- GNUNET_free (cur);
- }
- }
- void
- GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
- {
- struct LoggingTimeStep *lts;
- struct LoggingPeer *log_p;
- struct LoggingAddress *log_a;
- int c;
- for (lts = l->head; NULL != lts; lts = lts->next)
- {
- fprintf (stderr, "Log step %llu %llu: \n",
- (long long unsigned int) lts->timestamp.abs_value_us,
- (long long unsigned int) lts->delta.rel_value_us);
- for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
- {
- fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id);
- for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
- {
- fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_preference_type(c),
- log_p->pref_abs[c], log_p->pref_norm[c]);
- }
- for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
- {
- fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
- log_p->id, log_a->aid, log_a->active,
- log_a->assigned_bw_in,
- log_a->assigned_bw_out);
- for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
- {
- if (GNUNET_ATS_NETWORK_TYPE == c)
- continue;
- fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
- GNUNET_ATS_print_property_type(c),
- log_a->prop_abs[c], log_a->prop_norm[c]);
- }
- }
- }
- }
- }
- void
- GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
- {
- struct LoggingTimeStep *lts_cur;
- struct LoggingTimeStep *lts_next;
- struct LoggingPeer *log_p_cur;
- struct LoggingPeer *log_p_next;
- struct LoggingAddress *log_a_cur;
- struct LoggingAddress *log_a_next;
- if (NULL != l->logging_task)
- GNUNET_SCHEDULER_cancel (l->logging_task);
- l->logging_task = NULL;
- lts_next = l->head;
- while (NULL != (lts_cur = lts_next))
- {
- lts_next = lts_cur->next;
- log_p_next = lts_cur->head;
- while (NULL != (log_p_cur = log_p_next))
- {
- log_p_next = log_p_cur->next;
- log_a_next = log_p_cur->addr_head;
- while (NULL != (log_a_cur = log_a_next))
- {
- log_a_next = log_a_cur->next;
- GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur);
- GNUNET_free (log_a_cur);
- }
- GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
- GNUNET_free (log_p_cur);
- }
- GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
- GNUNET_free (lts_cur);
- }
- GNUNET_free (l);
- }
- /**
- * Property Generators
- */
- static struct PropertyGenerator *prop_gen_head;
- static struct PropertyGenerator *prop_gen_tail;
- static double
- get_property (struct PropertyGenerator *pg)
- {
- struct GNUNET_TIME_Relative time_delta;
- double delta_value;
- double pref_value;
- /* Calculate the current preference value */
- switch (pg->type) {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- pref_value = pg->base_value;
- break;
- case GNUNET_ATS_TEST_TG_LINEAR:
- time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us %
- pg->duration_period.rel_value_us;
- delta_value = ((double) time_delta.rel_value_us /
- pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
- if ((pg->max_value < pg->base_value) &&
- ((pg->max_value - pg->base_value) > pg->base_value))
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- pref_value = pg->base_value + delta_value;
- break;
- case GNUNET_ATS_TEST_TG_RANDOM:
- delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 10000 * (pg->max_value - pg->base_value)) / 10000;
- pref_value = pg->base_value + delta_value;
- break;
- case GNUNET_ATS_TEST_TG_SINUS:
- time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us %
- pg->duration_period.rel_value_us;
- if ((pg->max_value - pg->base_value) > pg->base_value)
- {
- /* This will cause an underflow for second half of sinus period,
- * will be detected in general when experiments are loaded */
- GNUNET_break (0);
- }
- delta_value = (pg->max_value - pg->base_value) *
- sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
- time_delta.rel_value_us);
- pref_value = pg->base_value + delta_value;
- break;
- default:
- pref_value = 0.0;
- break;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
- pref_value);
- return pref_value;
- }
- static void
- set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct PropertyGenerator *pg = cls;
- struct TestPeer *p;
- struct TestAddress *a;
- double prop_value;
- struct GNUNET_ATS_Information atsi;
- pg->set_task = NULL;
- if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
- &pg->test_peer->peer_id, pg->test_address->ats_addr))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting property generation for unknown address [%u:%u]\n",
- pg->peer, pg->address_id);
- return;
- }
- if (NULL == (p = find_peer_by_id (pg->peer)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting property generation for unknown peer %u\n",
- pg->peer);
- return;
- }
- if (NULL == (a = find_address_by_id (p, pg->address_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting property generation for unknown peer %u\n",
- pg->peer);
- return;
- }
- prop_value = get_property (pg);
- a->prop_abs[pg->ats_property] = prop_value;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Setting property for peer [%u] address [%u] for %s to %f\n",
- pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
- atsi.type = htonl (pg->ats_property);
- atsi.value = htonl ((uint32_t) prop_value);
- /* set performance here! */
- sh->sf->s_bulk_start (sh->sf->cls);
- if (GNUNET_YES == opt_disable_normalization)
- {
- a->prop_abs[pg->ats_property] = prop_value;
- a->prop_norm[pg->ats_property] = prop_value;
- sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
- pg->ats_property, prop_value, prop_value);
- }
- else
- GAS_normalization_normalize_property (pg->test_address->ats_addr, &atsi, 1);
- sh->sf->s_bulk_stop (sh->sf->cls);
- pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
- &set_prop_task, pg);
- }
- /**
- * Set ats_property to 0 to find all pgs
- */
- static struct PropertyGenerator *
- find_prop_gen (unsigned int peer, unsigned int address,
- uint32_t ats_property)
- {
- struct PropertyGenerator *cur;
- for (cur = prop_gen_head; NULL != cur; cur = cur->next)
- if ((cur->peer == peer) && (cur->address_id == address))
- {
- if ((cur->ats_property == ats_property) || (0 == ats_property))
- return cur;
- }
- return NULL;
- }
- void
- GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
- {
- GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
- if (NULL != pg->set_task)
- {
- GNUNET_SCHEDULER_cancel (pg->set_task);
- pg->set_task = NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Removing old up preference generator peer [%u] address [%u] `%s'\n",
- pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type(pg->ats_property));
- GNUNET_free (pg);
- }
- /**
- * Generate between the source master and the partner and set property with a
- * value depending on the generator.
- *
- * @param peer source
- * @param address_id partner
- * @param test_peer the peer
- * @param test_address the address
- * @param type type of generator
- * @param base_value base value
- * @param value_rate maximum value
- * @param period duration of a period of generation (~ 1/frequency)
- * @param frequency how long to generate property
- * @param ats_property ATS property to generate
- * @return the property generator
- */
- struct PropertyGenerator *
- GNUNET_ATS_solver_generate_property_start (unsigned int peer,
- unsigned int address_id,
- struct TestPeer *test_peer,
- struct TestAddress *test_address,
- enum GeneratorType type,
- long int base_value,
- long int value_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative frequency,
- uint32_t ats_property)
- {
- struct PropertyGenerator *pg;
- pg = GNUNET_new (struct PropertyGenerator);
- GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
- pg->type = type;
- pg->peer = peer;
- pg->test_address = test_address;
- pg->test_peer = test_peer;
- pg->address_id = address_id;
- pg->ats_property = ats_property;
- pg->base_value = base_value;
- pg->max_value = value_rate;
- pg->duration_period = period;
- pg->frequency = frequency;
- pg->time_start = GNUNET_TIME_absolute_get();
- switch (type) {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up %s property generator peer [%u] address [%u] `%s'"\
- "max %u Bips\n",
- print_generator_type(type), pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type (ats_property),
- base_value);
- break;
- case GNUNET_ATS_TEST_TG_LINEAR:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up %s property generator peer [%u] address [%u] `%s' " \
- "min %u Bips max %u Bips\n",
- print_generator_type(type), pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type(ats_property),
- base_value, value_rate);
- break;
- case GNUNET_ATS_TEST_TG_SINUS:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up %s property generator peer [%u] address [%u] `%s' "\
- "baserate %u Bips, amplitude %u Bps\n",
- print_generator_type(type), pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type(ats_property),
- base_value, value_rate);
- break;
- case GNUNET_ATS_TEST_TG_RANDOM:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting up %s property generator peer [%u] address [%u] `%s' "\
- "min %u Bips max %u Bps\n",
- print_generator_type(type), pg->peer, pg->address_id,
- GNUNET_ATS_print_property_type(ats_property),
- base_value, value_rate);
- break;
- default:
- break;
- }
- pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
- return pg;
- }
- /**
- * Stop all preferences generators
- */
- void
- GNUNET_ATS_solver_generate_property_stop_all ()
- {
- struct PropertyGenerator *cur;
- struct PropertyGenerator *next;
- next = prop_gen_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_ATS_solver_generate_property_stop (cur);
- }
- }
- /**
- * Preference Generators
- */
- static struct PreferenceGenerator *pref_gen_head;
- static struct PreferenceGenerator *pref_gen_tail;
- static double
- get_preference (struct PreferenceGenerator *pg)
- {
- struct GNUNET_TIME_Relative time_delta;
- double delta_value;
- double pref_value;
- /* Calculate the current preference value */
- switch (pg->type) {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- pref_value = pg->base_value;
- break;
- case GNUNET_ATS_TEST_TG_LINEAR:
- time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us %
- pg->duration_period.rel_value_us;
- delta_value = ((double) time_delta.rel_value_us /
- pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
- if ((pg->max_value < pg->base_value) &&
- ((pg->max_value - pg->base_value) > pg->base_value))
- {
- /* This will cause an underflow */
- GNUNET_break (0);
- }
- pref_value = pg->base_value + delta_value;
- break;
- case GNUNET_ATS_TEST_TG_RANDOM:
- delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 10000 * (pg->max_value - pg->base_value)) / 10000;
- pref_value = pg->base_value + delta_value;
- break;
- case GNUNET_ATS_TEST_TG_SINUS:
- time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
- /* Calculate point of time in the current period */
- time_delta.rel_value_us = time_delta.rel_value_us %
- pg->duration_period.rel_value_us;
- if ((pg->max_value - pg->base_value) > pg->base_value)
- {
- /* This will cause an underflow for second half of sinus period,
- * will be detected in general when experiments are loaded */
- GNUNET_break (0);
- }
- delta_value = (pg->max_value - pg->base_value) *
- sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
- time_delta.rel_value_us);
- pref_value = pg->base_value + delta_value;
- break;
- default:
- pref_value = 0.0;
- break;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
- pref_value);
- return pref_value;
- }
- static void
- set_feedback_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct PreferenceGenerator *pg = cls;
- struct TestPeer *p;
- double feedback;
- uint32_t bw_acc_out;
- uint32_t bw_acc_in;
- uint32_t delay_acc_in;
- struct GNUNET_TIME_Relative dur;
- double p_new;
- pg->feedback_task = NULL;
- if (NULL == (p = find_peer_by_id (pg->peer)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting feedback for unknown peer %u\n", pg->peer);
- return;
- }
- switch (pg->kind)
- {
- case GNUNET_ATS_PREFERENCE_BANDWIDTH:
- dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
- bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc;
- pg->feedback_bw_in_acc = 0;
- bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc;
- p_new = get_preference (pg);
- feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) /
- (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
- break;
- case GNUNET_ATS_PREFERENCE_LATENCY:
- dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update);
- delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc;
- pg->feedback_delay_acc = 0;
- p_new = get_preference (pg);
- feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) /
- (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us);
- break;
- default:
- GNUNET_break (0);
- feedback = 0.0;
- break;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
- pg->peer, NULL + (pg->client_id),
- GNUNET_ATS_print_preference_type (pg->kind),
- feedback);
- sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
- pg->feedback_frequency, pg->kind, feedback);
- pg->feedback_last = GNUNET_TIME_absolute_get();
- pg->feedback_bw_out_acc = 0;
- pg->feedback_bw_in_acc = 0;
- pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
- pg->feedback_delay_acc = 0;
- pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
- pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
- &set_feedback_task, pg);
- }
- static void
- set_pref_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
- {
- struct PreferenceGenerator *pg = cls;
- struct TestPeer *p;
- double pref_value;
- pg->set_task = NULL;
- if (NULL == (p = find_peer_by_id (pg->peer)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting preference for unknown peer %u\n", pg->peer);
- return;
- }
- pref_value = get_preference (pg);
- switch (pg->kind) {
- case GNUNET_ATS_PREFERENCE_BANDWIDTH:
- pg->pref_bw_old = pref_value;
- break;
- case GNUNET_ATS_PREFERENCE_LATENCY:
- pg->pref_latency_old = pref_value;
- break;
- default:
- break;
- }
- p->pref_abs[pg->kind] = pref_value;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Setting preference for peer [%u] for client %p pref %s to %f\n",
- pg->peer, NULL + (pg->client_id),
- GNUNET_ATS_print_preference_type (pg->kind), pref_value);
- if (GNUNET_YES == opt_disable_normalization)
- {
- p->pref_abs[pg->kind] = pref_value;
- p->pref_norm[pg->kind] = pref_value;
- sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
- }
- else
- normalize_preference (NULL + (pg->client_id),
- &p->peer_id,
- pg->kind,
- pref_value);
- pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
- &set_pref_task,
- pg);
- }
- static struct PreferenceGenerator *
- find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
- {
- struct PreferenceGenerator *cur;
- for (cur = pref_gen_head; NULL != cur; cur = cur->next)
- if (cur->peer == peer)
- {
- if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
- return cur;
- }
- return NULL;
- }
- void
- GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
- {
- GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
- if (NULL != pg->feedback_task)
- {
- GNUNET_SCHEDULER_cancel (pg->feedback_task);
- pg->feedback_task = NULL;
- }
- if (NULL != pg->set_task)
- {
- GNUNET_SCHEDULER_cancel (pg->set_task);
- pg->set_task = NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Removing old up preference generator peer [%u] `%s'\n",
- pg->peer, GNUNET_ATS_print_preference_type(pg->kind));
- GNUNET_free (pg);
- }
- struct TestAddress*
- find_active_address (struct TestPeer *p)
- {
- struct TestAddress *cur;
- for (cur = p->addr_head; NULL != cur; cur = cur->next)
- if (GNUNET_YES == cur->ats_addr->active)
- return cur;
- return NULL;
- }
- /**
- * Generate between the source master and the partner and set property with a
- * value depending on the generator.
- *
- * @param peer source
- * @param address_id partner
- * @param client_id the client
- * @param type type of generator
- * @param base_value base value
- * @param value_rate maximum value
- * @param period duration of a period of generation (~ 1/frequency)
- * @param frequency how long to generate property
- * @param kind ATS preference to generate
- * @param feedback_frequency how often to give feedback
- * @return the preference generator
- */
- struct PreferenceGenerator *
- GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
- unsigned int address_id,
- unsigned int client_id,
- enum GeneratorType type,
- long int base_value,
- long int value_rate,
- struct GNUNET_TIME_Relative period,
- struct GNUNET_TIME_Relative frequency,
- enum GNUNET_ATS_PreferenceKind kind,
- struct GNUNET_TIME_Relative feedback_frequency)
- {
- struct PreferenceGenerator *pg;
- struct TestPeer *p;
- if (NULL == (p = find_peer_by_id (peer)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Starting preference for unknown peer %u\n", peer);
- return NULL;
- }
- pg = GNUNET_new (struct PreferenceGenerator);
- GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
- pg->type = type;
- pg->peer = peer;
- pg->client_id = client_id;
- pg->kind = kind;
- pg->base_value = base_value;
- pg->max_value = value_rate;
- pg->duration_period = period;
- pg->frequency = frequency;
- pg->time_start = GNUNET_TIME_absolute_get();
- pg->feedback_frequency = feedback_frequency;
- switch (type) {
- case GNUNET_ATS_TEST_TG_CONSTANT:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
- print_generator_type (type), pg->peer,
- GNUNET_ATS_print_preference_type(kind),
- base_value);
- break;
- case GNUNET_ATS_TEST_TG_LINEAR:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
- print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
- base_value, value_rate);
- break;
- case GNUNET_ATS_TEST_TG_SINUS:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
- print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
- base_value, value_rate);
- break;
- case GNUNET_ATS_TEST_TG_RANDOM:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
- print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind),
- base_value, value_rate);
- break;
- default:
- break;
- }
- pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
- if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us)
- {
- struct TestAddress * addr = find_active_address(p);
- const double *properties = get_property_cb (NULL, addr->ats_addr);
- pg->last_assigned_bw_in = p->assigned_bw_in;
- pg->last_assigned_bw_out = p->assigned_bw_out;
- pg->feedback_bw_in_acc = 0;
- pg->feedback_bw_out_acc = 0;
- pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY];
- pg->feedback_delay_acc = 0;
- pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
- pg->feedback_last_delay_update = GNUNET_TIME_absolute_get();
- pg->feedback_last = GNUNET_TIME_absolute_get();
- pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
- &set_feedback_task, pg);
- }
- return pg;
- }
- /**
- * Stop all preferences generators
- */
- void
- GNUNET_ATS_solver_generate_preferences_stop_all ()
- {
- struct PreferenceGenerator *cur;
- struct PreferenceGenerator *next;
- next = pref_gen_head;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- GNUNET_ATS_solver_generate_preferences_stop(cur);
- }
- }
- /**
- * Experiments
- */
- const char *
- print_op (enum OperationType op)
- {
- switch (op) {
- case SOLVER_OP_ADD_ADDRESS:
- return "ADD_ADDRESS";
- case SOLVER_OP_DEL_ADDRESS:
- return "DEL_ADDRESS";
- case SOLVER_OP_START_SET_PREFERENCE:
- return "START_SET_PREFERENCE";
- case SOLVER_OP_STOP_SET_PREFERENCE:
- return "STOP_STOP_PREFERENCE";
- case SOLVER_OP_START_SET_PROPERTY:
- return "START_SET_PROPERTY";
- case SOLVER_OP_STOP_SET_PROPERTY:
- return "STOP_SET_PROPERTY";
- case SOLVER_OP_START_REQUEST:
- return "START_REQUEST";
- case SOLVER_OP_STOP_REQUEST:
- return "STOP_REQUEST";
- default:
- break;
- }
- return "";
- }
- static struct Experiment *
- create_experiment ()
- {
- struct Experiment *e;
- e = GNUNET_new (struct Experiment);
- e->name = NULL;
- e->start = NULL;
- e->total_duration = GNUNET_TIME_UNIT_ZERO;
- return e;
- }
- static void
- free_experiment (struct Experiment *e)
- {
- struct Episode *cur;
- struct Episode *next;
- struct GNUNET_ATS_TEST_Operation *cur_o;
- struct GNUNET_ATS_TEST_Operation *next_o;
- next = e->start;
- for (cur = next; NULL != cur; cur = next)
- {
- next = cur->next;
- next_o = cur->head;
- for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
- {
- next_o = cur_o->next;
- GNUNET_free_non_null (cur_o->address);
- GNUNET_free_non_null (cur_o->plugin);
- GNUNET_free (cur_o);
- }
- GNUNET_free (cur);
- }
- GNUNET_free_non_null (e->name);
- GNUNET_free_non_null (e->log_prefix);
- GNUNET_free_non_null (e->log_output_dir);
- GNUNET_free_non_null (e->cfg_file);
- GNUNET_free (e);
- }
- static int
- load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- char *op_network;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_id))
- {
- fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* plugin */
- GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &o->plugin))
- {
- fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address */
- GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &o->address))
- {
- fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* session */
- GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_session))
- {
- fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* network */
- GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &op_network))
- {
- fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n",
- op_counter, "ADD_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- else
- {
- GNUNET_STRINGS_utf8_toupper (op_network,op_network);
- if (0 == strcmp(op_network, "UNSPECIFIED"))
- {
- o->address_network = GNUNET_ATS_NET_UNSPECIFIED;
- }
- else if (0 == strcmp(op_network, "LOOPBACK"))
- {
- o->address_network = GNUNET_ATS_NET_LOOPBACK;
- }
- else if (0 == strcmp(op_network, "LAN"))
- {
- o->address_network = GNUNET_ATS_NET_LAN;
- }
- else if (0 == strcmp(op_network, "WAN"))
- {
- o->address_network = GNUNET_ATS_NET_WAN;
- }
- else if (0 == strcmp(op_network, "WLAN"))
- {
- o->address_network = GNUNET_ATS_NET_WLAN;
- }
- else if (0 == strcmp(op_network, "BT"))
- {
- o->address_network = GNUNET_ATS_NET_BT;
- }
- else
- {
- fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
- op_counter, "ADD_ADDRESS", op_name, op_network);
- GNUNET_free (op_network);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_network);
- GNUNET_free (op_name);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
- "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
- return GNUNET_OK;
- }
- static int
- load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- //char *op_network;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "DEL_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_id))
- {
- fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
- op_counter, "DEL_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- #if 0
- /* plugin */
- GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &o->plugin))
- {
- fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
- op_counter, "DEL_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address */
- GNUNET_asprintf(&op_name, "op-%u-address", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &o->address))
- {
- fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
- op_counter, "DEL_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* session */
- GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_session))
- {
- fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n",
- op_counter, "DEL_ADDRESS", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- #endif
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
- "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
- return GNUNET_OK;
- }
- static enum GNUNET_ATS_Property
- parse_preference_string (const char * str)
- {
- int c = 0;
- char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
- for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
- if (0 == strcmp(str, props[c]))
- return c;
- return 0;
- };
- static int
- load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- char *type;
- char *pref;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->client_id))
- {
- fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* generator */
- GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
- if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
- sec_name, op_name, &type)) )
- {
- fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- /* Load arguments for set_rate, start_send, set_preference */
- if (0 == strcmp (type, "constant"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
- }
- else if (0 == strcmp (type, "linear"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
- }
- else if (0 == strcmp (type, "sinus"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
- }
- else if (0 == strcmp (type, "random"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
- }
- else
- {
- fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (type);
- GNUNET_free (op_name);
- /* Get base rate */
- GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->base_rate))
- {
- fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get max rate */
- GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->max_rate))
- {
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_name);
- /* Get period */
- GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->period))
- {
- o->period = e->duration;
- }
- GNUNET_free (op_name);
- /* Get frequency */
- GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->frequency))
- {
- fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get preference */
- GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &pref))
- {
- fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- if (0 == (o->pref_type = parse_preference_string(pref)))
- {
- fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- GNUNET_free (pref);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- /* Get feedback delay */
- GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->feedback_delay))
- {
- fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n",
- (long long unsigned int) o->feedback_delay.rel_value_us,
- op_counter, op_name, e->id);
- }
- else
- o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
- GNUNET_free (op_name);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu]: %s = %llu\n",
- "START_SET_PREFERENCE", o->peer_id, o->address_id,
- GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate);
- return GNUNET_OK;
- }
- static int
- load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- char *pref;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_id))
- {
- fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get preference */
- GNUNET_asprintf(&op_name, "op-%u-pref", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &pref))
- {
- fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PREFERENCE", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- if (0 == (o->pref_type = parse_preference_string(pref)))
- {
- fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- GNUNET_free (pref);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu]: %s\n",
- "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
- GNUNET_ATS_print_preference_type(o->pref_type));
- return GNUNET_OK;
- }
- static enum GNUNET_ATS_Property
- parse_property_string (const char *str)
- {
- enum GNUNET_ATS_Property c;
- for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
- if (0 == strcmp(str,
- GNUNET_ATS_print_property_type (c)))
- return c;
- return 0;
- }
- static int
- load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- char *type;
- char *prop;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_id))
- {
- fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* generator */
- GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter);
- if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
- sec_name, op_name, &type)) )
- {
- fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
- op_counter, "START_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- /* Load arguments for set_rate, start_send, set_preference */
- if (0 == strcmp (type, "constant"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
- }
- else if (0 == strcmp (type, "linear"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
- }
- else if (0 == strcmp (type, "sinus"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
- }
- else if (0 == strcmp (type, "random"))
- {
- o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
- }
- else
- {
- fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (type);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (type);
- GNUNET_free (op_name);
- /* Get base rate */
- GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->base_rate))
- {
- fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get max rate */
- GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->max_rate))
- {
- if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
- (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
- {
- fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- }
- GNUNET_free (op_name);
- /* Get period */
- GNUNET_asprintf(&op_name, "op-%u-period", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->period))
- {
- o->period = e->duration;
- }
- GNUNET_free (op_name);
- /* Get frequency */
- GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
- sec_name, op_name, &o->frequency))
- {
- fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get preference */
- GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &prop))
- {
- fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- GNUNET_free_non_null (prop);
- return GNUNET_SYSERR;
- }
- if (0 == (o->prop_type = parse_property_string(prop)))
- {
- fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- GNUNET_free (prop);
- return GNUNET_SYSERR;
- }
- GNUNET_free (prop);
- GNUNET_free (op_name);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu] %s = %llu\n",
- "START_SET_PROPERTY", o->peer_id, o->address_id,
- GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
- return GNUNET_OK;
- }
- static int
- load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- char *pref;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* address pid */
- GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->address_id))
- {
- fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- /* Get property */
- GNUNET_asprintf(&op_name, "op-%u-property", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
- sec_name, op_name, &pref))
- {
- fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_SET_PROPERTY", op_name);
- GNUNET_free (op_name);
- GNUNET_free_non_null (pref);
- return GNUNET_SYSERR;
- }
- if (0 == (o->prop_type = parse_property_string(pref)))
- {
- fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
- op_counter, op_name, e->id);
- GNUNET_free (op_name);
- GNUNET_free_non_null (pref);
- return GNUNET_SYSERR;
- }
- GNUNET_free (pref);
- GNUNET_free (op_name);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Found operation %s: [%llu:%llu] %s\n",
- "STOP_SET_PROPERTY", o->peer_id, o->address_id,
- GNUNET_ATS_print_property_type (o->prop_type));
- return GNUNET_OK;
- }
- static int
- load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "START_REQUEST", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- return GNUNET_OK;
- }
- static int
- load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
- struct Episode *e,
- int op_counter,
- char *sec_name,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- char *op_name;
- /* peer pid */
- GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
- sec_name, op_name, &o->peer_id))
- {
- fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
- op_counter, "STOP_REQUEST", op_name);
- GNUNET_free (op_name);
- return GNUNET_SYSERR;
- }
- GNUNET_free (op_name);
- return GNUNET_OK;
- }
- static int
- load_episode (struct Experiment *e, struct Episode *cur,
- struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- struct GNUNET_ATS_TEST_Operation *o;
- char *sec_name;
- char *op_name;
- char *op;
- int op_counter = 0;
- int res;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id);
- GNUNET_asprintf(&sec_name, "episode-%u", cur->id);
- while (1)
- {
- /* Load operation */
- GNUNET_asprintf(&op_name, "op-%u-operation", op_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg,
- sec_name, op_name, &op))
- {
- GNUNET_free (op_name);
- break;
- }
- o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
- cur->id, op_name);
- /* operations = set_rate, start_send, stop_send, set_preference */
- if (0 == strcmp (op, "address_add"))
- {
- o->type = SOLVER_OP_ADD_ADDRESS;
- res = load_op_add_address (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "address_del"))
- {
- o->type = SOLVER_OP_DEL_ADDRESS;
- res = load_op_del_address (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "start_set_property"))
- {
- o->type = SOLVER_OP_START_SET_PROPERTY;
- res = load_op_start_set_property (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "stop_set_property"))
- {
- o->type = SOLVER_OP_STOP_SET_PROPERTY;
- res = load_op_stop_set_property (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "start_set_preference"))
- {
- o->type = SOLVER_OP_START_SET_PREFERENCE;
- res = load_op_start_set_preference (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "stop_set_preference"))
- {
- o->type = SOLVER_OP_STOP_SET_PREFERENCE;
- res = load_op_stop_set_preference (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "start_request"))
- {
- o->type = SOLVER_OP_START_REQUEST;
- res = load_op_start_request (o, cur,
- op_counter, sec_name, cfg);
- }
- else if (0 == strcmp (op, "stop_request"))
- {
- o->type = SOLVER_OP_STOP_REQUEST;
- res = load_op_stop_request(o, cur,
- op_counter, sec_name, cfg);
- }
- else
- {
- fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
- op_counter, op, cur->id);
- res = GNUNET_SYSERR;
- }
- GNUNET_free (op);
- GNUNET_free (op_name);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_free (o);
- GNUNET_free (sec_name);
- return GNUNET_SYSERR;
- }
- GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o);
- op_counter++;
- }
- GNUNET_free (sec_name);
- return GNUNET_OK;
- }
- static int
- load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- int e_counter = 0;
- char *sec_name;
- struct GNUNET_TIME_Relative e_duration;
- struct Episode *cur;
- struct Episode *last;
- e_counter = 0;
- last = NULL;
- while (1)
- {
- GNUNET_asprintf(&sec_name, "episode-%u", e_counter);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg,
- sec_name, "duration", &e_duration))
- {
- GNUNET_free (sec_name);
- break;
- }
- cur = GNUNET_new (struct Episode);
- cur->duration = e_duration;
- cur->id = e_counter;
- if (GNUNET_OK != load_episode (e, cur, cfg))
- {
- GNUNET_free (sec_name);
- GNUNET_free (cur);
- return GNUNET_SYSERR;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
- e_counter,
- GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
- /* Update experiment */
- e->num_episodes ++;
- e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration);
- /* Put in linked list */
- if (NULL == last)
- e->start = cur;
- else
- last->next = cur;
- GNUNET_free (sec_name);
- e_counter ++;
- last = cur;
- }
- return e_counter;
- }
- static void
- timeout_experiment (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
- {
- struct Experiment *e = cls;
- e->experiment_timeout_task = NULL;
- fprintf (stderr, "Experiment timeout!\n");
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time),
- GNUNET_SYSERR);
- }
- struct ATS_Address *
- create_ats_address (const struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- uint32_t session_id,
- uint32_t network)
- {
- struct ATS_Address *aa = NULL;
- aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
- aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
- aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
- aa->atsi[0].value = htonl (network);
- aa->atsi_count = 1;
- aa->peer = *peer;
- aa->addr_len = plugin_addr_len;
- aa->addr = &aa[1];
- aa->plugin = (char *) &aa[1] + plugin_addr_len;
- memcpy (&aa[1], plugin_addr, plugin_addr_len);
- memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
- aa->session_id = session_id;
- return aa;
- }
- static void
- enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct TestPeer *p;
- struct TestAddress *a;
- int c;
- if (NULL == (p = find_peer_by_id (op->peer_id)))
- {
- p = GNUNET_new (struct TestPeer);
- p->id = op->peer_id;
- p->assigned_bw_in = 0;
- p->assigned_bw_out = 0;
- memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
- for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
- {
- p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
- p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
- }
- GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
- }
- if (NULL != (find_address_by_id (p, op->address_id)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
- op->address_id, op->peer_id);
- return;
- }
- a = GNUNET_new (struct TestAddress);
- a->aid = op->address_id;
- a->network = op->address_network;
- a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
- strlen (op->address) + 1, op->address_session, op->address_network);
- memset (&p->peer_id, op->peer_id, sizeof (p->peer_id));
- GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
- for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
- a->prop_norm[c] = DEFAULT_REL_QUALITY;
- GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n",
- op->address_id, op->peer_id, GNUNET_ATS_print_network_type(a->network));
- sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
- }
- static void
- enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct TestPeer *p;
- struct TestAddress *a;
- struct PropertyGenerator *pg;
- if (NULL == (p = find_peer_by_id (op->peer_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Deleting address for unknown peer %u\n", op->peer_id);
- return;
- }
- if (NULL == (a =find_address_by_id (p, op->address_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Deleting address for unknown peer %u\n", op->peer_id);
- return;
- }
- while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
- {
- GNUNET_ATS_solver_generate_property_stop (pg);
- }
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
- &p->peer_id,
- a->ats_addr));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Removing address %u for peer %u\n",
- op->address_id,
- op->peer_id);
- sh->sf->s_del (sh->sf->cls, a->ats_addr, GNUNET_NO);
- if (NULL != l)
- {
- GNUNET_ATS_solver_logging_now (l);
- }
- GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a);
- GNUNET_free_non_null(a->ats_addr->atsi);
- GNUNET_free (a->ats_addr);
- GNUNET_free (a);
- }
- static void
- enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct PropertyGenerator *pg;
- struct TestPeer *p;
- struct TestAddress *a;
- if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
- {
- GNUNET_ATS_solver_generate_property_stop (pg);
- GNUNET_free (pg);
- }
- if (NULL == (p = find_peer_by_id (op->peer_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Starting property generation for unknown peer %u\n", op->peer_id);
- return;
- }
- if (NULL == (a = find_address_by_id (p, op->address_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Setting property for unknown address %u\n", op->peer_id);
- return;
- }
- GNUNET_ATS_solver_generate_property_start (op->peer_id,
- op->address_id,
- p, a,
- op->gen_type,
- op->base_rate,
- op->max_rate,
- op->period,
- op->frequency,
- op->prop_type);
- }
- static void
- enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id,
- op->prop_type);
- if (NULL != pg)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Stopping preference generation for peer %u address %u\n", op->peer_id,
- op->address_id);
- GNUNET_ATS_solver_generate_property_stop (pg);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot find preference generator for peer %u address %u\n",
- op->peer_id, op->address_id);
- GNUNET_break (0);
- }
- }
- static void
- enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct PreferenceGenerator *pg;
- if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
- {
- GNUNET_ATS_solver_generate_preferences_stop (pg);
- GNUNET_free (pg);
- }
- if (NULL == (find_peer_by_id (op->peer_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Starting preference generation for unknown peer %u\n", op->peer_id);
- return;
- }
- GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
- op->address_id,
- op->client_id,
- op->gen_type,
- op->base_rate,
- op->max_rate,
- op->period,
- op->frequency,
- op->pref_type,
- op->frequency);
- }
- static void
- enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct PreferenceGenerator *pg = find_pref_gen(op->peer_id,
- op->pref_type);
- if (NULL != pg)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Stopping property generation for peer %u address %u\n", op->peer_id,
- op->address_id);
- GNUNET_ATS_solver_generate_preferences_stop (pg);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot find preference generator for peer %u address %u\n",
- op->peer_id, op->address_id);
- GNUNET_break (0);
- }
- }
- static void
- enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct TestPeer *p;
- const struct ATS_Address *res;
- if (NULL == (p = find_peer_by_id (op->peer_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Requesting address for unknown peer %u\n", op->peer_id);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
- op->peer_id);
- p->is_requested = GNUNET_YES;
- res = sh->sf->s_get (sh->sf->cls, &p->peer_id);
- if (NULL != res)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Suggested address for peer %u: %llu %llu\n",
- op->peer_id,
- res->assigned_bw_in,
- res->assigned_bw_out);
- if (NULL != l)
- GNUNET_ATS_solver_logging_now (l);
- }
- }
- static void
- enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
- {
- struct TestPeer *p;
- if (NULL == (p = find_peer_by_id (op->peer_id)))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Requesting address for unknown peer %u\n", op->peer_id);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop requesting address for peer %u\n",
- op->peer_id);
- p->is_requested = GNUNET_NO;
- p->assigned_bw_in = 0;
- p->assigned_bw_out = 0;
- sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
- if (NULL != l)
- {
- GNUNET_ATS_solver_logging_now (l);
- }
- }
- static void enforce_episode (struct Episode *ep)
- {
- struct GNUNET_ATS_TEST_Operation *cur;
- for (cur = ep->head; NULL != cur; cur = cur->next)
- {
- switch (cur->type) {
- case SOLVER_OP_ADD_ADDRESS:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
- print_op (cur->type), cur->peer_id, cur->address_id);
- enforce_add_address (cur);
- break;
- case SOLVER_OP_DEL_ADDRESS:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
- print_op (cur->type), cur->peer_id, cur->address_id);
- enforce_del_address (cur);
- break;
- case SOLVER_OP_START_SET_PROPERTY:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
- print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
- enforce_start_property (cur);
- break;
- case SOLVER_OP_STOP_SET_PROPERTY:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
- print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
- enforce_stop_property (cur);
- break;
- case SOLVER_OP_START_SET_PREFERENCE:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
- print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
- enforce_start_preference (cur);
- break;
- case SOLVER_OP_STOP_SET_PREFERENCE:
- fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
- print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate);
- enforce_stop_preference (cur);
- break;
- case SOLVER_OP_START_REQUEST:
- fprintf (stderr, "Enforcing operation: %s [%llu]\n",
- print_op (cur->type), cur->peer_id);
- enforce_start_request (cur);
- break;
- case SOLVER_OP_STOP_REQUEST:
- fprintf (stderr, "Enforcing operation: %s [%llu]\n",
- print_op (cur->type), cur->peer_id);
- enforce_stop_request (cur);
- break;
- default:
- break;
- }
- }
- }
- static void
- timeout_episode (void *cls, const struct GNUNET_SCHEDULER_TaskContext* tc)
- {
- struct Experiment *e = cls;
- e->episode_timeout_task = NULL;
- if (NULL != e->ep_done_cb)
- e->ep_done_cb (e->cur);
- /* Scheduling next */
- e->cur = e->cur->next;
- if (NULL == e->cur)
- {
- /* done */
- fprintf (stderr, "Last episode done!\n");
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK);
- return;
- }
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
- enforce_episode(e->cur);
- }
- void
- GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
- GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb,
- GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb)
- {
- fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
- GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES));
- e->e_done_cb = e_done_cb;
- e->ep_done_cb = ep_done_cb;
- e->start_time = GNUNET_TIME_absolute_get();
- /* Start total time out */
- e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
- &timeout_experiment, e);
- /* Start */
- if (NULL == e->start)
- {
- GNUNET_break (0);
- return;
- }
- e->cur = e->start;
- fprintf (stderr, "Running episode %u with timeout %s\n",
- e->cur->id,
- GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES));
- e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
- &timeout_episode, e);
- enforce_episode(e->cur);
- }
- void
- GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
- {
- if (NULL != e->experiment_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
- e->experiment_timeout_task = NULL;
- }
- if (NULL != e->episode_timeout_task)
- {
- GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
- e->episode_timeout_task = NULL;
- }
- if (NULL != e->cfg)
- {
- GNUNET_CONFIGURATION_destroy(e->cfg);
- e->cfg = NULL;
- }
- free_experiment (e);
- }
- struct Experiment *
- GNUNET_ATS_solvers_experimentation_load (char *filename)
- {
- struct Experiment *e;
- struct GNUNET_CONFIGURATION_Handle *cfg;
- e = NULL;
- cfg = GNUNET_CONFIGURATION_create();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
- {
- fprintf (stderr, "Failed to load `%s'\n", filename);
- GNUNET_CONFIGURATION_destroy (cfg);
- return NULL;
- }
- e = create_experiment ();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
- "name", &e->name))
- {
- fprintf (stderr, "Invalid %s \n", "name");
- free_experiment (e);
- return NULL;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment",
- "log_prefix", &e->log_prefix))
- {
- fprintf (stderr, "Invalid %s \n", "log_prefix");
- free_experiment (e);
- return NULL;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
- e->log_prefix);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
- "log_output_dir", &e->log_output_dir))
- {
- e->log_output_dir = NULL;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n",
- e->log_output_dir);
- if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg,
- "experiment", "log_append_time_stamp")))
- e->log_append_time_stamp = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n",
- (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment",
- "cfg_file", &e->cfg_file))
- {
- fprintf (stderr, "Invalid %s \n", "cfg_file");
- free_experiment (e);
- return NULL;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file);
- e->cfg = GNUNET_CONFIGURATION_create();
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
- {
- fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
- free_experiment (e);
- return NULL;
- }
- }
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
- "log_freq", &e->log_freq))
- {
- fprintf (stderr, "Invalid %s \n", "log_freq");
- free_experiment (e);
- return NULL;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES));
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
- "max_duration", &e->max_duration))
- {
- fprintf (stderr, "Invalid %s", "max_duration");
- free_experiment (e);
- return NULL;
- }
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
- GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES));
- if (GNUNET_SYSERR == load_episodes (e, cfg))
- {
- GNUNET_ATS_solvers_experimentation_stop (e);
- GNUNET_CONFIGURATION_destroy (cfg);
- e = NULL;
- fprintf (stderr, "Failed to load experiment\n");
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n",
- e->num_episodes,
- GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES));
- GNUNET_CONFIGURATION_destroy (cfg);
- return e;
- }
- /**
- * Solver
- */
- static int
- free_all_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
- {
- struct ATS_Address *address = value;
- GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses,
- key, value));
- GNUNET_free (address);
- return GNUNET_OK;
- }
- void
- GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
- {
- GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
- GNUNET_NO);
- GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
- sh->sf = NULL;
- GAS_normalization_stop();
- GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
- &free_all_it,
- NULL);
- GNUNET_CONTAINER_multipeermap_destroy(sh->addresses);
- GNUNET_free (sh->plugin);
- GNUNET_free (sh);
- }
- /**
- * Load quotas for networks from configuration
- *
- * @param cfg configuration handle
- * @param out_dest where to write outbound quotas
- * @param in_dest where to write inbound quotas
- * @param dest_length length of inbound and outbound arrays
- * @return number of networks loaded
- */
- unsigned int
- GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
- unsigned long long *out_dest,
- unsigned long long *in_dest,
- int dest_length)
- {
- char * entry_in = NULL;
- char * entry_out = NULL;
- char * quota_out_str;
- char * quota_in_str;
- int c;
- int res;
- for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
- {
- in_dest[c] = 0;
- out_dest[c] = 0;
- GNUNET_asprintf (&entry_out,
- "%s_QUOTA_OUT",
- GNUNET_ATS_print_network_type (c));
- GNUNET_asprintf (&entry_in,
- "%s_QUOTA_IN",
- GNUNET_ATS_print_network_type (c));
- /* quota out */
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str))
- {
- res = GNUNET_NO;
- if (0 == strcmp(quota_out_str, BIG_M_STRING))
- {
- out_dest[c] = GNUNET_ATS_MaxBandwidth;
- res = GNUNET_YES;
- }
- if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
- res = GNUNET_YES;
- if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c])))
- res = GNUNET_YES;
- if (GNUNET_NO == res)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
- GNUNET_ATS_print_network_type (c),
- quota_out_str,
- GNUNET_ATS_DefaultBandwidth);
- out_dest[c] = GNUNET_ATS_DefaultBandwidth;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Outbound quota configure for network `%s' is %llu\n",
- GNUNET_ATS_print_network_type (c),
- out_dest[c]);
- }
- GNUNET_free (quota_out_str);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
- GNUNET_ATS_print_network_type (c),
- GNUNET_ATS_DefaultBandwidth);
- out_dest[c] = GNUNET_ATS_DefaultBandwidth;
- }
- /* quota in */
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str))
- {
- res = GNUNET_NO;
- if (0 == strcmp(quota_in_str, BIG_M_STRING))
- {
- in_dest[c] = GNUNET_ATS_MaxBandwidth;
- res = GNUNET_YES;
- }
- if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
- res = GNUNET_YES;
- if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c])))
- res = GNUNET_YES;
- if (GNUNET_NO == res)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
- GNUNET_ATS_print_network_type (c),
- quota_in_str,
- GNUNET_ATS_DefaultBandwidth);
- in_dest[c] = GNUNET_ATS_DefaultBandwidth;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inbound quota configured for network `%s' is %llu\n",
- GNUNET_ATS_print_network_type (c),
- in_dest[c]);
- }
- GNUNET_free (quota_in_str);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
- GNUNET_ATS_print_network_type (c),
- GNUNET_ATS_DefaultBandwidth);
- out_dest[c] = GNUNET_ATS_DefaultBandwidth;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Loaded quota for network `%s' (in/out): %llu %llu\n",
- GNUNET_ATS_print_network_type (c),
- in_dest[c],
- out_dest[c]);
- GNUNET_free (entry_out);
- GNUNET_free (entry_in);
- }
- return GNUNET_ATS_NetworkTypeCount;
- }
- /**
- * Information callback for the solver
- *
- * @param cls the closure
- * @param op the solver operation
- * @param stat status of the solver operation
- * @param add additional solver information
- */
- static void
- solver_info_cb (void *cls,
- enum GAS_Solver_Operation op,
- enum GAS_Solver_Status stat,
- enum GAS_Solver_Additional_Information add)
- {
- char *add_info;
- switch (add) {
- case GAS_INFO_NONE:
- add_info = "GAS_INFO_NONE";
- break;
- case GAS_INFO_FULL:
- add_info = "GAS_INFO_MLP_FULL";
- break;
- case GAS_INFO_UPDATED:
- add_info = "GAS_INFO_MLP_UPDATED";
- break;
- case GAS_INFO_PROP_ALL:
- add_info = "GAS_INFO_PROP_ALL";
- break;
- case GAS_INFO_PROP_SINGLE:
- add_info = "GAS_INFO_PROP_SINGLE";
- break;
- default:
- add_info = "INVALID";
- break;
- }
- switch (op)
- {
- case GAS_OP_SOLVE_START:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
- return;
- case GAS_OP_SOLVE_STOP:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
- return;
- case GAS_OP_SOLVE_SETUP_START:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_SETUP_STOP:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_MLP_LP_START:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_MLP_LP_STOP:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_MLP_MLP_START:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_MLP_MLP_STOP:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
- (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
- return;
- default:
- break;
- }
- }
- static void
- solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
- {
- struct GNUNET_TIME_Relative duration;
- struct TestPeer *p;
- static struct PreferenceGenerator *pg;
- uint32_t delta;
- if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Solver notified to disconnect peer `%s'\n",
- GNUNET_i2s (&address->peer));
- }
- p = find_peer_by_pid(&address->peer);
- if (NULL == p)
- return;
- p->assigned_bw_out = address->assigned_bw_out;
- p->assigned_bw_in = address->assigned_bw_in;
- for (pg = pref_gen_head; NULL != pg; pg = pg->next)
- {
- if (pg->peer == p->id)
- {
- duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update);
- delta = duration.rel_value_us * pg->last_assigned_bw_out;
- pg->feedback_bw_out_acc += delta;
- delta = duration.rel_value_us * pg->last_assigned_bw_in;
- pg->feedback_bw_in_acc += delta;
- pg->last_assigned_bw_in = address->assigned_bw_in;
- pg->last_assigned_bw_out = address->assigned_bw_out;
- pg->feedback_last_bw_update = GNUNET_TIME_absolute_get();
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
- GNUNET_i2s (&address->peer),
- address,
- address->assigned_bw_out,
- address->assigned_bw_in);
- if (NULL != l)
- GNUNET_ATS_solver_logging_now (l);
- return;
- }
- const double *
- get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
- {
- struct TestPeer *p;
- if (GNUNET_YES == opt_disable_normalization)
- {
- if (NULL == (p = find_peer_by_pid (id)))
- return NULL;
- return p->pref_abs;
- }
- else
- return GAS_normalization_get_preferences_by_peer (NULL,
- id);
- }
- const double *
- get_property_cb (void *cls, const struct ATS_Address *address)
- {
- struct TestPeer *p;
- struct TestAddress *a;
- if (GNUNET_YES == opt_disable_normalization)
- {
- p = find_peer_by_pid (&address->peer);
- if (NULL == p)
- return NULL;
- a = find_address_by_ats_address (p, address);
- return a->prop_abs;
- }
- return GAS_normalization_get_properties (NULL,
- address);
- }
- struct SolverHandle *
- GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
- {
- struct SolverHandle *sh;
- char * solver_str;
- switch (type) {
- case GNUNET_ATS_SOLVER_PROPORTIONAL:
- solver_str = "proportional";
- break;
- case GNUNET_ATS_SOLVER_MLP:
- solver_str = "mlp";
- break;
- case GNUNET_ATS_SOLVER_RIL:
- solver_str = "ril";
- break;
- default:
- GNUNET_break (0);
- return NULL;
- break;
- }
- sh = GNUNET_new (struct SolverHandle);
- GNUNET_asprintf (&sh->plugin,
- "libgnunet_plugin_ats_%s",
- solver_str);
- sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
- /* setup environment */
- sh->env.cfg = e->cfg;
- sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
- sh->env.addresses = sh->addresses;
- sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
- sh->env.get_preferences = &get_preferences_cb;
- sh->env.get_property = &get_property_cb;
- sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
- sh->env.info_cb = &solver_info_cb;
- sh->env.network_count = GNUNET_ATS_NetworkTypeCount;
- /* start normalization */
- GAS_normalization_start ();
- /* load quotas */
- if (GNUNET_ATS_NetworkTypeCount != GNUNET_ATS_solvers_load_quotas (e->cfg,
- sh->env.out_quota, sh->env.in_quota, GNUNET_ATS_NetworkTypeCount))
- {
- GNUNET_break(0);
- GNUNET_free (sh->plugin);
- GNUNET_free (sh);
- end_now ();
- return NULL;
- }
- sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
- if (NULL == sh->sf)
- {
- fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
- GNUNET_break(0);
- GNUNET_free (sh->plugin);
- GNUNET_free (sh);
- end_now ();
- return NULL;
- }
- return sh;
- }
- static void
- done ()
- {
- struct TestPeer *cur;
- struct TestPeer *next;
- struct TestAddress *cur_a;
- struct TestAddress *next_a;
- /* Stop logging */
- GNUNET_ATS_solver_logging_stop (l);
- /* Stop all preference generation */
- GNUNET_ATS_solver_generate_preferences_stop_all ();
- /* Stop all property generation */
- GNUNET_ATS_solver_generate_property_stop_all ();
- if (opt_print)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
- GNUNET_ATS_solver_logging_eval (l);
- }
- if (opt_save)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
- GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
- e->log_output_dir);
- }
- if (NULL != l)
- {
- GNUNET_ATS_solver_logging_free (l);
- l = NULL;
- }
- /* Clean up experiment */
- if (NULL != e)
- {
- GNUNET_ATS_solvers_experimentation_stop (e);
- e = NULL;
- }
- next = peer_head;
- while (NULL != (cur = next))
- {
- next = cur->next;
- GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
- next_a = cur->addr_head;
- while (NULL != (cur_a = next_a))
- {
- next_a = cur_a->next;
- GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
- GNUNET_free (cur_a);
- }
- GNUNET_free (cur);
- }
- if (NULL != sh)
- {
- GNUNET_ATS_solvers_solver_stop (sh);
- sh = NULL;
- }
- /* Shutdown */
- end_now();
- }
- static void
- experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success)
- {
- if (GNUNET_OK == success)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
- GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
- GNUNET_SCHEDULER_add_now (&done, NULL);
- }
- static void
- episode_done_cb (struct Episode *ep)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
- }
- /**
- * Do shutdown
- */
- static void
- end_now ()
- {
- if (NULL != e)
- {
- GNUNET_ATS_solvers_experimentation_stop (e);
- e = NULL;
- }
- if (NULL != sh)
- {
- GNUNET_ATS_solvers_solver_stop (sh);
- sh = NULL;
- }
- }
- static void
- run (void *cls, char * const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
- {
- enum GNUNET_ATS_Solvers solver;
- int c;
- if (NULL == opt_exp_file)
- {
- fprintf (stderr, "No experiment given ...\n");
- res = 1;
- end_now ();
- return;
- }
- if (NULL == opt_solver)
- {
- fprintf (stderr, "No solver given ...\n");
- res = 1;
- end_now ();
- return;
- }
- if (0 == strcmp(opt_solver, "mlp"))
- {
- solver = GNUNET_ATS_SOLVER_MLP;
- }
- else if (0 == strcmp(opt_solver, "proportional"))
- {
- solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
- }
- else if (0 == strcmp(opt_solver, "ril"))
- {
- solver = GNUNET_ATS_SOLVER_RIL;
- }
- else
- {
- fprintf (stderr, "No solver given ...");
- res = 1;
- end_now ();
- return;
- }
- for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
- default_properties[c] = DEFAULT_REL_QUALITY;
- for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
- default_preferences[c] = DEFAULT_REL_PREFERENCE;
- /* load experiment */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
- e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
- if (NULL == e)
- {
- fprintf (stderr, "Failed to load experiment ...\n");
- res = 1;
- end_now ();
- return;
- }
- /* load solver */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
- sh = GNUNET_ATS_solvers_solver_start (solver);
- if (NULL == sh)
- {
- fprintf (stderr, "Failed to start solver ...\n");
- end_now ();
- res = 1;
- return;
- }
- /* start logging */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
- l = GNUNET_ATS_solver_logging_start (e->log_freq);
- /* run experiment */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
- GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
- experiment_done_cb);
- /* WAIT */
- }
- /**
- * Main function of the benchmark
- *
- * @param argc argument count
- * @param argv argument values
- */
- int
- main (int argc, char *argv[])
- {
- opt_exp_file = NULL;
- opt_solver = NULL;
- opt_log = GNUNET_NO;
- opt_save = GNUNET_NO;
- res = 0;
- static struct GNUNET_GETOPT_CommandLineOption options[] =
- {
- { 's', "solver", NULL,
- gettext_noop ("solver to use"),
- 1, &GNUNET_GETOPT_set_string, &opt_solver},
- { 'e', "experiment", NULL,
- gettext_noop ("experiment to use"),
- 1, &GNUNET_GETOPT_set_string, &opt_exp_file},
- { 'V', "verbose", NULL,
- gettext_noop ("be verbose"),
- 0, &GNUNET_GETOPT_set_one, &opt_verbose},
- { 'p', "print", NULL,
- gettext_noop ("print logging"),
- 0, &GNUNET_GETOPT_set_one, &opt_print},
- { 'f', "file", NULL,
- gettext_noop ("save logging to disk"),
- 0, &GNUNET_GETOPT_set_one, &opt_save},
- { 'd', "dn", NULL,
- gettext_noop ("disable normalization"),
- 0, &GNUNET_GETOPT_set_one, &opt_disable_normalization},
- GNUNET_GETOPT_OPTION_END
- };
- GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
- NULL, options, &run, argv[0]);
- return res;
- }
- /* end of file ats-testing-experiment.c*/
|