LCOV - code coverage report
Current view: top level - runtime - routing_strategies.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 44 0.0 %
Date: 2018-01-11 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             : START OF LICENSE STUB
       3             :     DeDOS: Declarative Dispersion-Oriented Software
       4             :     Copyright (C) 2017 University of Pennsylvania, Georgetown University
       5             : 
       6             :     This program is free software: you can redistribute it and/or modify
       7             :     it under the terms of the GNU General Public License as published by
       8             :     the Free Software Foundation, either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     This program is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :     GNU General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : END OF LICENSE STUB
      19             : */
      20             : /**
      21             :  * @file routing_strategies.c
      22             :  * Defines strategies that MSUs can use for routing to endpoints
      23             :  */
      24             : #include "routing_strategies.h"
      25             : #include "local_msu.h"
      26             : #include "logging.h"
      27             : #include "msu_message.h"
      28             : 
      29             : 
      30           0 : int default_routing(struct msu_type *type, struct local_msu *sender,
      31             :                     struct msu_msg *msg, struct msu_endpoint *output) {
      32             : 
      33           0 :     struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
      34           0 :     if (table == NULL) {
      35           0 :         log_error("No routes available from msu %d to type %d",
      36             :                   sender->id, type->id);
      37           0 :         return -1;
      38             :     }
      39           0 :     int rtn = get_route_endpoint(table, msg->hdr.key.id, output);
      40           0 :     if (rtn < 0) {
      41           0 :         log_error("Error getting endpoint from msu %d", sender->id);
      42           0 :         return -1;
      43             :     }
      44           0 :     return 0;
      45             : }
      46           0 : int shortest_queue_route(struct msu_type *type, struct local_msu *sender,
      47             :                          struct msu_msg *msg, struct msu_endpoint *output) {
      48           0 :     struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
      49           0 :     if (table == NULL) {
      50           0 :         log_error("No routes available from msu %d to type %d",
      51             :                   sender->id, type->id);
      52           0 :         return -1;
      53             :     }
      54           0 :     int rtn = get_shortest_queue_endpoint(table, msg->hdr.key.id, output);
      55           0 :     if (rtn < 0) {
      56           0 :         log_error("Error getting shortest queue endpoint from msu %d", sender->id);
      57           0 :         return -1;
      58             :     }
      59           0 :     return 0;
      60             : }
      61           0 : int route_to_id(struct msu_type *type, struct local_msu *sender, int msu_id,
      62             :                 struct msu_endpoint *output) {
      63           0 :     struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
      64           0 :     if (table == NULL) {
      65           0 :         log_error("No routes available from msu %d to type %d",
      66             :                   sender->id, type->id);
      67           0 :         return -1;
      68             :     }
      69           0 :     int rtn = get_endpoint_by_id(table, msu_id, output);
      70           0 :     if (rtn < 0) {
      71           0 :         log_error("Error getting endpoint with ID %d from msu %d", msu_id, sender->id);
      72           0 :         return -1;
      73             :     }
      74           0 :     return 0;
      75             : }
      76           0 : int route_to_origin_runtime(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg,
      77             :                             struct msu_endpoint *output) {
      78             : 
      79           0 :     uint32_t runtime_id = msg->hdr.provinance.origin.runtime_id;
      80             : 
      81           0 :     struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
      82           0 :     if (table == NULL) {
      83           0 :          log_error("No routes available from msu %d to type %d",
      84             :                   sender->id, type->id);
      85           0 :         return -1;
      86             :     }
      87             : 
      88           0 :     int n_endpoints = get_n_endpoints(table);
      89           0 :     struct msu_endpoint eps[n_endpoints];
      90             : 
      91           0 :     int n_rt_endpoints = get_endpoints_by_runtime_id(table, runtime_id, eps, n_endpoints);
      92           0 :     if (n_rt_endpoints <= 0) {
      93           0 :         log_error("Could not get endpoint with runtime id %d", runtime_id);
      94           0 :         return -1;
      95             :     }
      96             : 
      97             :     log(LOG_ROUTING_DECISIONS, "Sending to one of %d endpoints with correct runtime",
      98             :         n_rt_endpoints);
      99           0 :     *output = eps[((unsigned int)msg->hdr.key.id) % n_rt_endpoints];
     100             :     log(LOG_ROUTING_DECISIONS, "Chose endpoint %d (idx: %d)",
     101             :         output->id, ((unsigned int)msg->hdr.key.id) % n_rt_endpoints);
     102           0 :     return 0;
     103             : }
     104             : 

Generated by: LCOV version 1.10