My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
controller_dfg.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 */
20 #include "dfg.h"
21 #include "logging.h"
22 #include "dfg_reader.h"
23 #include "controller_stats.h"
24 #include "haproxy.h"
25 
26 #include <stdlib.h>
27 
28 static struct dedos_dfg *DFG = NULL;
29 
30 int init_controller_dfg(char *filename) {
31 
32  DFG = parse_dfg_json_file(filename);
33 
34  if (DFG == NULL) {
35  log_error("Error initializing DFG");
36  return -1;
37  }
38  set_dfg(DFG);
39 
41 
42  return 0;
43 }
44 
46  if (DFG == NULL) {
47  return -1;
48  }
49  return DFG->global_ctl_port;
50 }
51 
52 static int max_msu_id = -1;
53 
55  for (int i=0; i<DFG->n_msus; i++) {
56  if (DFG->msus[i]->id > max_msu_id) {
57  max_msu_id = DFG->msus[i]->id;
58  }
59  }
60  max_msu_id++;
61  return max_msu_id;
62 }
63 
64 #define MAX_ROUTE_ID 9999
65 
67  for (int id = 0; id < MAX_ROUTE_ID; id++) {
68  if (get_dfg_route(id) == NULL) {
69  return id;
70  }
71  }
72  return -1;
73 }
74 
76  if (route->n_endpoints == 0) {
77  return 1;
78  }
79  return route->endpoints[route->n_endpoints-1]->key + 1;
80 }
81 
82 pthread_mutex_t dfg_mutex;
83 
85  return pthread_mutex_init(&dfg_mutex, NULL);
86 }
87 
88 int lock_dfg() {
89  int rtn = pthread_mutex_lock(&dfg_mutex);
90  if (rtn < 0) {
91  log_error("Error locking dfg");
92  return -1;
93  }
94  return 0;
95 }
96 
97 int unlock_dfg() {
98  int rtn = pthread_mutex_unlock(&dfg_mutex);
99  if (rtn < 0) {
100  log_perror("Error unlocking dfg");
101  return -1;
102  }
103  return 0;
104 }
105 struct dedos_dfg *get_dfg(void) {
106  return DFG;
107 }
struct dedos_dfg * get_dfg(void)
int n_msus
The number of MSUs in dedos_dfg::msus.
Definition: dfg.h:255
static struct dedos_dfg * DFG
int lock_dfg()
int global_ctl_port
Port of the global controller.
Definition: dfg.h:242
static int max_msu_id
struct dfg_route * get_dfg_route(unsigned int id)
Returns the route with the given ID.
Definition: dfg.c:76
int init_dfg_lock()
static int route(struct msu_type *type, struct local_msu *sender, struct msu_msg *msg, struct msu_endpoint *output)
Definition: baremetal_msu.c:30
int generate_route_id()
#define log_perror(fmt,...)
Definition: logging.h:102
Logging of status messages to the terminal.
pthread_mutex_t dfg_mutex
struct dfg_route_endpoint * endpoints[256]
The endpoints of the route.
Definition: dfg.h:156
int n_endpoints
The number of endpoints in dfg_route::endpoints.
Definition: dfg.h:157
int local_listen_port()
int unlock_dfg()
#define log_error(fmt,...)
Definition: logging.h:101
void set_dfg(struct dedos_dfg *dfg_in)
Sets the local copy of the DFG, so it doesn't have to be passed in for each call. ...
Definition: dfg.c:34
Declares function for converting JSON to dedos_dfg.
int id
A unique identifier for the MSU.
Definition: dfg.h:217
int init_controller_dfg(char *filename)
Top-level structure holding the data-flow graph.
Definition: dfg.h:239
A route through which MSU messages can be passed.
Definition: dfg.h:152
#define MAX_ROUTE_ID
struct dedos_dfg * parse_dfg_json_file(const char *filename)
Converts a json file to a dfg structure.
Definition: dfg_reader.c:96
void set_haproxy_weights(int rt_id, int offset)
Definition: haproxy.c:102
Interfaces for the creation and modification of the data-flow-graph and and general description of th...
uint32_t key
The key associated with this endpoint.
Definition: dfg.h:140
uint32_t generate_endpoint_key(struct dfg_route *route)
unsigned int uint32_t
Definition: uthash.h:96
int generate_msu_id()
struct dfg_msu * msus[512]
The MSUs present in the application.
Definition: dfg.h:253