aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-20 09:13:10 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-20 09:13:10 +0000
commit110f7cda16a96257ad4bdcf604b1e188a00a1200 (patch)
tree21e62439333dc25107cf75deb04e26bb5b0d845d /src/ats
parent10c3f79a9c8e9aa777329874cff6d9ef15d41751 (diff)
downloadgnunet-110f7cda16a96257ad4bdcf604b1e188a00a1200.tar.gz
gnunet-110f7cda16a96257ad4bdcf604b1e188a00a1200.zip
changes
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_performance.c83
-rw-r--r--src/ats/test_ats_api_performance_monitor.c43
2 files changed, 113 insertions, 13 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index a6760b368..74b9650c9 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -534,7 +534,6 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
534 struct MonitorResponseMessage *mrm; 534 struct MonitorResponseMessage *mrm;
535 size_t msglen; 535 size_t msglen;
536 536
537
538 msglen = sizeof (struct MonitorResponseMessage) + 537 msglen = sizeof (struct MonitorResponseMessage) +
539 ats_count * sizeof (struct GNUNET_ATS_Information); 538 ats_count * sizeof (struct GNUNET_ATS_Information);
540 mrm = GNUNET_malloc (msglen); 539 mrm = GNUNET_malloc (msglen);
@@ -551,13 +550,67 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
551 mrm->id = curm->id; 550 mrm->id = curm->id;
552 GNUNET_SERVER_notification_context_unicast (nc, 551 GNUNET_SERVER_notification_context_unicast (nc,
553 cur->client, 552 cur->client,
554 (struct GNUNET_MessageHeader *) &mrm, 553 (struct GNUNET_MessageHeader *) mrm,
555 GNUNET_YES); 554 GNUNET_YES);
556 } 555 }
557 GNUNET_free (mrm); 556 GNUNET_free (mrm);
558} 557}
559 558
560 559
560static void
561mon_peerinfo_it (void *cls,
562 const struct GNUNET_PeerIdentity *id,
563 const char *plugin_name,
564 const void *plugin_addr, size_t plugin_addr_len,
565 const int active,
566 const struct GNUNET_ATS_Information *atsi,
567 uint32_t atsi_count,
568 struct GNUNET_BANDWIDTH_Value32NBO
569 bandwidth_out,
570 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
571{
572 struct PerformanceMonitorClient *pmc = cls;
573 struct MonitorResponseMessage *mrm;
574 size_t msglen;
575
576 if (NULL == id)
577 return; /* last callback */
578
579 msglen = sizeof (struct MonitorResponseMessage) +
580 atsi_count * sizeof (struct GNUNET_ATS_Information);
581 mrm = GNUNET_malloc (msglen);
582
583 mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
584 mrm->header.size = htons (msglen);
585 mrm->ats_count = htonl (atsi_count);
586 mrm->peer = *id;
587 mrm->id = pmc->id;
588
589 /* Send initial information about peers to client */
590/*
591 GNUNET_SERVER_notification_context_unicast (nc,
592 pmc->client,
593 (struct GNUNET_MessageHeader *) mrm,
594 GNUNET_YES);
595*/
596 GNUNET_free (mrm);
597}
598
599/**
600 * Iterator for GAS_handle_monitor
601 *
602 * @param cls the performance monitoring client requesting information
603 * @param id result
604 */
605static void
606mon_peer_it (void *cls,
607 const struct GNUNET_PeerIdentity *id)
608{
609 struct PerformanceMonitorClient *pmc = cls;
610 if (NULL != id)
611 GAS_addresses_get_peer_info (GSA_addresses, id, &mon_peerinfo_it, pmc);
612}
613
561 614
562void 615void
563GAS_handle_monitor (void *cls, 616GAS_handle_monitor (void *cls,
@@ -565,7 +618,7 @@ GAS_handle_monitor (void *cls,
565 const struct GNUNET_MessageHeader *message) 618 const struct GNUNET_MessageHeader *message)
566{ 619{
567 struct PerformanceClient *pc; 620 struct PerformanceClient *pc;
568 struct PerformanceMonitorClient *res; 621 struct PerformanceMonitorClient *pmc;
569 struct MonitorMessage *mm = (struct MonitorMessage *) message; 622 struct MonitorMessage *mm = (struct MonitorMessage *) message;
570 size_t msg_size; 623 size_t msg_size;
571 uint32_t id; 624 uint32_t id;
@@ -588,38 +641,42 @@ GAS_handle_monitor (void *cls,
588 id = ntohl (mm->id); 641 id = ntohl (mm->id);
589 op = ntohl (mm->op); 642 op = ntohl (mm->op);
590 643
591 for (res = pc->pm_head; NULL != res; res = res->next) 644 for (pmc = pc->pm_head; NULL != pmc; pmc = pmc->next)
592 if ((res->id == id) && (client == res->client)) 645 if ((pmc->id == id) && (client == pmc->client))
593 break; 646 break;
594 647
595 if (GNUNET_YES == op) 648 if (GNUNET_YES == op)
596 { 649 {
597 /* Start monitoring */ 650 /* Start monitoring */
598 if (NULL != res) 651 if (NULL != pmc)
599 { 652 {
600 GNUNET_break (0); 653 GNUNET_break (0);
601 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 654 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
602 return; /* Duplicate*/ 655 return; /* Duplicate*/
603 } 656 }
604 res = GNUNET_malloc (sizeof (struct PerformanceMonitorClient)); 657 pmc = GNUNET_malloc (sizeof (struct PerformanceMonitorClient));
605 res->client = client; 658 pmc->client = client;
606 res->id = id; 659 pmc->id = id;
607 GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, res); 660 GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, pmc);
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Added performance monitoring client %p id %u\n", 662 "Added performance monitoring client %p id %u\n",
610 client, id); 663 client, id);
664
665 /* Return all values here */
666 GAS_addresses_iterate_peers (GSA_addresses, &mon_peer_it, pc);
667
611 } 668 }
612 else if (GNUNET_NO == op) 669 else if (GNUNET_NO == op)
613 { 670 {
614 /* Stop monitoring */ 671 /* Stop monitoring */
615 if (NULL == res) 672 if (NULL == pmc)
616 { 673 {
617 GNUNET_break (0); 674 GNUNET_break (0);
618 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 675 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
619 return; /* Not existing */ 676 return; /* Not existing */
620 } 677 }
621 GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, res); 678 GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, pmc);
622 GNUNET_free (res); 679 GNUNET_free (pmc);
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "Removed performance monitoring client %p id %u\n", 681 "Removed performance monitoring client %p id %u\n",
625 client, id); 682 client, id);
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c
index e89b46b04..6187a87e1 100644
--- a/src/ats/test_ats_api_performance_monitor.c
+++ b/src/ats/test_ats_api_performance_monitor.c
@@ -36,12 +36,41 @@ static GNUNET_SCHEDULER_TaskIdentifier stage_task;
36 36
37struct GNUNET_CONFIGURATION_Handle *cfg; 37struct GNUNET_CONFIGURATION_Handle *cfg;
38 38
39static struct GNUNET_ATS_SchedulingHandle *sh;
40
39static struct GNUNET_ATS_PerformanceHandle *ph; 41static struct GNUNET_ATS_PerformanceHandle *ph;
40 42
41static struct GNUNET_ATS_PerformanceMonitorHandle *phm; 43static struct GNUNET_ATS_PerformanceMonitorHandle *phm;
42 44
45static struct GNUNET_HELLO_Address addr;
46
47static struct GNUNET_ATS_Information atsi[3];
48
43static int ret; 49static int ret;
44 50
51static void cleanup_addresses ()
52{
53 GNUNET_ATS_address_destroyed (sh, &addr, NULL);
54}
55
56static void setup_addresses ()
57{
58 memset (&addr.peer,'\0', sizeof (addr.peer));
59 addr.transport_name = "test";
60 addr.address = NULL;
61 addr.address_length = 0;
62 atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE);
63 atsi[0].value = htonl(GNUNET_ATS_NET_LAN);
64
65 atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
66 atsi[1].value = htonl(100);
67
68 atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE);
69 atsi[2].value = htonl(5);
70
71 GNUNET_ATS_address_add (sh, &addr, NULL, atsi, 3);
72}
73
45 74
46static void 75static void
47end_now (int res) 76end_now (int res)
@@ -56,6 +85,9 @@ end_now (int res)
56 GNUNET_SCHEDULER_cancel (die_task); 85 GNUNET_SCHEDULER_cancel (die_task);
57 die_task = GNUNET_SCHEDULER_NO_TASK; 86 die_task = GNUNET_SCHEDULER_NO_TASK;
58 } 87 }
88 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
89
90 cleanup_addresses ();
59 91
60 if (NULL != phm) 92 if (NULL != phm)
61 { 93 {
@@ -68,6 +100,12 @@ end_now (int res)
68 GNUNET_ATS_performance_done (ph); 100 GNUNET_ATS_performance_done (ph);
69 ph = NULL; 101 ph = NULL;
70 } 102 }
103
104 if (NULL != sh)
105 {
106 GNUNET_ATS_scheduling_done (sh);
107 sh = NULL;
108 }
71 ret = res; 109 ret = res;
72} 110}
73 111
@@ -124,6 +162,11 @@ run (void *cls,
124 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 162 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
125 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 163 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
126 164
165 sh = GNUNET_ATS_scheduling_init (cfg, NULL, NULL);
166 GNUNET_assert (NULL != sh);
167
168 setup_addresses ();
169
127 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 170 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
128 GNUNET_assert (NULL != ph); 171 GNUNET_assert (NULL != ph);
129 172