My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
routing_strategies.c
Go to the documentation of this file.
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 */
24 #include "routing_strategies.h"
25 #include "local_msu.h"
26 #include "logging.h"
27 #include "msu_message.h"
28 
29 
30 int default_routing(struct msu_type *type, struct local_msu *sender,
31  struct msu_msg *msg, struct msu_endpoint *output) {
32 
33  struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
34  if (table == NULL) {
35  log_error("No routes available from msu %d to type %d",
36  sender->id, type->id);
37  return -1;
38  }
39  int rtn = get_route_endpoint(table, msg->hdr.key.id, output);
40  if (rtn < 0) {
41  log_error("Error getting endpoint from msu %d", sender->id);
42  return -1;
43  }
44  return 0;
45 }
46 int shortest_queue_route(struct msu_type *type, struct local_msu *sender,
47  struct msu_msg *msg, struct msu_endpoint *output) {
48  struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
49  if (table == NULL) {
50  log_error("No routes available from msu %d to type %d",
51  sender->id, type->id);
52  return -1;
53  }
54  int rtn = get_shortest_queue_endpoint(table, msg->hdr.key.id, output);
55  if (rtn < 0) {
56  log_error("Error getting shortest queue endpoint from msu %d", sender->id);
57  return -1;
58  }
59  return 0;
60 }
61 int route_to_id(struct msu_type *type, struct local_msu *sender, int msu_id,
62  struct msu_endpoint *output) {
63  struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
64  if (table == NULL) {
65  log_error("No routes available from msu %d to type %d",
66  sender->id, type->id);
67  return -1;
68  }
69  int rtn = get_endpoint_by_id(table, msu_id, output);
70  if (rtn < 0) {
71  log_error("Error getting endpoint with ID %d from msu %d", msu_id, sender->id);
72  return -1;
73  }
74  return 0;
75 }
76 int route_to_origin_runtime(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg,
77  struct msu_endpoint *output) {
78 
80 
81  struct routing_table *table = get_type_from_route_set(&sender->routes, type->id);
82  if (table == NULL) {
83  log_error("No routes available from msu %d to type %d",
84  sender->id, type->id);
85  return -1;
86  }
87 
88  int n_endpoints = get_n_endpoints(table);
89  struct msu_endpoint eps[n_endpoints];
90 
91  int n_rt_endpoints = get_endpoints_by_runtime_id(table, runtime_id, eps, n_endpoints);
92  if (n_rt_endpoints <= 0) {
93  log_error("Could not get endpoint with runtime id %d", runtime_id);
94  return -1;
95  }
96 
97  log(LOG_ROUTING_DECISIONS, "Sending to one of %d endpoints with correct runtime",
98  n_rt_endpoints);
99  *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  return 0;
103 }
104 
int get_endpoint_by_id(struct routing_table *table, int msu_id, struct msu_endpoint *endpoint)
Gets endpoint with the given MSU ID in the provided route.
Definition: routing.c:344
int id
A unque identifier for the endpoint (msu ID)
Definition: routing.h:34
int shortest_queue_route(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Chooses the local MSU with the shortest queue.
The core of the routing system, the routing table lists a route's destinations.
Definition: routing.c:47
int route_to_id(struct msu_type *type, struct local_msu *sender, int msu_id, struct msu_endpoint *output)
Chooses the MSU with the given ID.
int n_endpoints
The number of destinations this route contains.
Definition: routing.c:52
int default_routing(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
The defualt routing strategy, using the key of the MSU message to route to a pre-defined endpoint...
int32_t id
A shorter, often hashed id for the key of fixed length (used in routing)
Definition: msu_message.h:52
int get_route_endpoint(struct routing_table *table, uint32_t key, struct msu_endpoint *endpoint)
Gets the endpoint associated with the given key in the provided route.
Definition: routing.c:385
Logging of status messages to the terminal.
unsigned int id
Unique ID for a local MSU.
Definition: local_msu.h:54
struct msu_provinance_item origin
The first MSU to see this message.
Definition: msu_message.h:71
unsigned int runtime_id
Definition: msu_message.h:62
int get_endpoints_by_runtime_id(struct routing_table *table, int runtime_id, struct msu_endpoint *endpoints, int n_endpoints)
Gets all of the endpoints in the provided routing table with the right runtime id.
Definition: routing.c:359
struct route_set routes
Routing table set, containing all destination MSUs (see routing.h for details)
Definition: local_msu.h:51
struct msg_provinance provinance
Message history.
Definition: msu_message.h:89
unsigned int id
Numerical identifier for the MSU.
Definition: msu_type.h:51
#define log_error(fmt,...)
Definition: logging.h:101
Declares the structures and functions applicable to MSUs on the local machine.
The structure that represents an MSU located on the local machine.
Definition: local_msu.h:38
int get_n_endpoints(struct routing_table *table)
Definition: routing.c:378
Defines a type of MSU.
Definition: msu_type.h:46
struct routing_table * get_type_from_route_set(struct route_set *set, int type_id)
Gets the route from the provided array of routes which has the correct type ID.
Definition: routing.c:399
struct msu_msg_hdr hdr
Definition: msu_message.h:102
static int runtime_id(int runtime_fd)
unsigned int uint32_t
Definition: uthash.h:96
#define log(level, fmt,...)
Log at a custom level.
Definition: logging.h:147
A message that is to be delivered to an instance of an MSU.
Definition: msu_message.h:101
Messages passed to MSUs.
An endpoint to which an msu_msg can be delivered.
Definition: routing.h:32
int route_to_origin_runtime(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Routes an MSU message to the runtime on which the message originated.
int get_shortest_queue_endpoint(struct routing_table *table, uint32_t key, struct msu_endpoint *endpoint)
Gets the local endpoint from a route with the shortest queue length.
Definition: routing.c:299
Declares strategies that MSUs can use for routing to endpoints.
struct msu_msg_key key
Routing/state key.
Definition: msu_message.h:87