aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-10-07 16:49:41 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-10-07 16:49:41 +0000
commit5e8acfff954e7d5b39f9c3451d4674368871615e (patch)
tree3a1d21656acd361ab529be8c416258a98e18b52c /src
parent644907f75bc0e24b1294f7cf39416b0e4216bcb3 (diff)
downloadgnunet-5e8acfff954e7d5b39f9c3451d4674368871615e.tar.gz
gnunet-5e8acfff954e7d5b39f9c3451d4674368871615e.zip
ats_ril: - bug fixed in address_add()
- small reward function implementation
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ats/gnunet-service-ats-solver_ril.c107
1 files changed, 80 insertions, 27 deletions
diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c
index 1a9614fd3..2320f295e 100755
--- a/src/ats/gnunet-service-ats-solver_ril.c
+++ b/src/ats/gnunet-service-ats-solver_ril.c
@@ -49,10 +49,6 @@
49 * General description 49 * General description
50 */ 50 */
51 51
52/**
53 * TODO! implement reward calculation 1 and 2 (i.e. meeting preferences and taking scores)
54 */
55
56enum RIL_Action_Type 52enum RIL_Action_Type
57{ 53{
58 RIL_ACTION_NOTHING = 0, 54 RIL_ACTION_NOTHING = 0,
@@ -662,6 +658,45 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
662} 658}
663 659
664/** 660/**
661 * For all networks a peer has an address in, this gets the maximum bandwidth which could
662 * theoretically be available in one of the networks. This is used for bandwidth normalization.
663 * @param solver the solver handle
664 * @param agent the agent handle
665 * @param direction_in whether the inbound bandwidth should be considered. Returns the maximum outbound bandwidth if GNUNET_NO
666 */
667static long long unsigned
668ril_get_max_bw(struct RIL_Peer_Agent *agent, int direction_in)
669{
670 /*
671 * get the maximum bandwidth possible for a peer, e.g. among all addresses which addresses'
672 * network could provide the maximum bandwidth if all that bandwidth was used on that one peer.
673 */
674 int max = 0;
675 struct RIL_Address_Wrapped *cur;
676 struct RIL_Network *net;
677
678 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
679 {
680 net = cur->address_naked->solver_information;
681 if (direction_in)
682 {
683 if (net->bw_in_available > max)
684 {
685 max = net->bw_in_available;
686 }
687 }
688 else
689 {
690 if (net->bw_out_available > max)
691 {
692 max = net->bw_out_available;
693 }
694 }
695 }
696 return max;
697}
698
699/**
665 * Gets the reward of the last performed step 700 * Gets the reward of the last performed step
666 * @param solver solver handle 701 * @param solver solver handle
667 * @return the reward 702 * @return the reward
@@ -669,10 +704,33 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
669static double 704static double
670envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 705envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
671{ 706{
672 //TODO! implement reward calculation 707 /*
708 * Match the preferences of the peer with the current assignment.
709 */
710 const double *preferences;
711 const double *properties;
712 double pref_match = 0;
713 double bw_norm;
714 struct RIL_Network *net;
715
716 preferences = solver->callbacks->get_preferences (solver->callbacks->get_preferences_cls, &agent->peer);
717 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls,
718 agent->address_inuse);
719 pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * properties[GNUNET_ATS_QUALITY_NET_DELAY];
720 bw_norm = GNUNET_MAX(2, (((
721 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) +
722 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO))
723 ) / 2
724 ) + 1));
725 pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm;
726
727 net = agent->address_inuse->solver_information;
728 if ((net->bw_in_assigned > net->bw_in_available) || net->bw_out_assigned > net->bw_out_available)
729 {
730 return -1;
731 }
673 732
674 return (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) 733 return pref_match;
675 / (double) UINT32_MAX;
676} 734}
677 735
678/** 736/**
@@ -1338,6 +1396,7 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1338 struct GAS_RIL_Handle *s = solver; 1396 struct GAS_RIL_Handle *s = solver;
1339 struct RIL_Peer_Agent *agent; 1397 struct RIL_Peer_Agent *agent;
1340 struct RIL_Address_Wrapped *address_wrapped; 1398 struct RIL_Address_Wrapped *address_wrapped;
1399 struct RIL_Network *net;
1341 unsigned int m_new; 1400 unsigned int m_new;
1342 unsigned int m_old; 1401 unsigned int m_old;
1343 unsigned int n_new; 1402 unsigned int n_new;
@@ -1346,7 +1405,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1346 unsigned int zero; 1405 unsigned int zero;
1347 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 1406 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1348 1407
1349 address->solver_information = ril_get_network (s, network); 1408 net = ril_get_network (s, network);
1409 address->solver_information = net;
1350 1410
1351 if (!ril_network_is_active (s, network)) 1411 if (!ril_network_is_active (s, network))
1352 { 1412 {
@@ -1393,6 +1453,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1393 1453
1394 if (NULL == agent->address_inuse) 1454 if (NULL == agent->address_inuse)
1395 { 1455 {
1456 net->bw_in_assigned += min_bw;
1457 net->bw_out_assigned += min_bw;
1396 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO); 1458 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
1397 } 1459 }
1398 1460
@@ -1411,7 +1473,7 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1411void 1473void
1412GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only) 1474GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
1413{ 1475{
1414 //TODO! delete session only 1476 //TODO? use session as feature
1415 struct GAS_RIL_Handle *s = solver; 1477 struct GAS_RIL_Handle *s = solver;
1416 struct RIL_Peer_Agent *agent; 1478 struct RIL_Peer_Agent *agent;
1417 struct RIL_Address_Wrapped *address_wrapped; 1479 struct RIL_Address_Wrapped *address_wrapped;
@@ -1550,7 +1612,7 @@ GAS_ril_address_session_changed (void *solver,
1550 uint32_t cur_session, 1612 uint32_t cur_session,
1551 uint32_t new_session) 1613 uint32_t new_session)
1552{ 1614{
1553 //TODO? consider session changed in solver behaviour 1615 //TODO? consider session change in solver behaviour
1554 /* 1616 /*
1555 * Potentially add session activity as a feature in state vector 1617 * Potentially add session activity as a feature in state vector
1556 */ 1618 */
@@ -1569,10 +1631,7 @@ GAS_ril_address_session_changed (void *solver,
1569void 1631void
1570GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use) 1632GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
1571{ 1633{
1572 //TODO! consider address_inuse_changed according to matthias' email 1634 /* Nothing to do here */
1573 /**
1574 * See matthias' email
1575 */
1576 LOG(GNUNET_ERROR_TYPE_DEBUG, 1635 LOG(GNUNET_ERROR_TYPE_DEBUG,
1577 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", 1636 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
1578 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); 1637 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
@@ -1613,8 +1672,8 @@ GAS_ril_address_change_network (void *solver,
1613 agent = ril_get_agent (s, &address->peer, GNUNET_NO); 1672 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
1614 if (NULL == agent) 1673 if (NULL == agent)
1615 { 1674 {
1616 //no agent there yet, so add as if address is new 1675 GNUNET_assert(!ril_network_is_active (solver, current_network));
1617 address->solver_information = ril_get_network (s, new_network); 1676
1618 GAS_ril_address_add (s, address, new_network); 1677 GAS_ril_address_add (s, address, new_network);
1619 return; 1678 return;
1620 } 1679 }
@@ -1647,7 +1706,7 @@ GAS_ril_address_preference_feedback (void *solver,
1647 enum GNUNET_ATS_PreferenceKind kind, 1706 enum GNUNET_ATS_PreferenceKind kind,
1648 double score) 1707 double score)
1649{ 1708{
1650 //TODO! collect reward until next reward calculation 1709 //TODO! talk to Matthias about feedback
1651 LOG(GNUNET_ERROR_TYPE_DEBUG, 1710 LOG(GNUNET_ERROR_TYPE_DEBUG,
1652 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " 1711 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
1653 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN", 1712 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
@@ -1662,14 +1721,10 @@ GAS_ril_address_preference_feedback (void *solver,
1662void 1721void
1663GAS_ril_bulk_start (void *solver) 1722GAS_ril_bulk_start (void *solver)
1664{ 1723{
1665 //TODO? consideration: keep bulk counter and stop agents during bulk
1666 /* 1724 /*
1667 * bulk counter up, but not really relevant, because there is no complete calculation of the 1725 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1668 * bandwidth assignment triggered anyway. Therefore, changes to addresses can come and go as 1726 * happens in the proportional and the mlp solver, there is no need to block this solver.
1669 * they want. Consideration: Step-pause during bulk-start-stop period...
1670 */ 1727 */
1671
1672 //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start()\n");
1673} 1728}
1674 1729
1675/** 1730/**
@@ -1678,12 +1733,10 @@ GAS_ril_bulk_start (void *solver)
1678void 1733void
1679GAS_ril_bulk_stop (void *solver) 1734GAS_ril_bulk_stop (void *solver)
1680{ 1735{
1681 //TODO? consideration: keep bulk counter and stop agents during bulk
1682 /* 1736 /*
1683 * bulk counter down, see bulk_start() 1737 * Since new calculations of the assignment are not triggered by a change of preferences, as it
1738 * happens in the proportional and the mlp solver, there is no need to block this solver.
1684 */ 1739 */
1685
1686 //LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop()\n");
1687} 1740}
1688 1741
1689/** 1742/**