My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
runtime_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 */
24 #include "runtime_dfg.h"
25 #include "dfg_reader.h"
26 #include "logging.h"
27 #include "dfg_instantiation.h"
28 #include "msu_type.h"
29 
30 #include <stdlib.h>
31 
33 static struct dedos_dfg *DFG = NULL;
35 static struct dfg_runtime *LOCAL_RUNTIME = NULL;
36 
37 void set_local_runtime(struct dfg_runtime *rt) {
38  LOCAL_RUNTIME = rt;
39 }
40 
41 int init_runtime_dfg(char *filename, int runtime_id) {
42 
43  if (DFG != NULL) {
44  log_error("Runtime DFG already instantiated!");
45  return -1;
46  }
47 
48  DFG = parse_dfg_json_file(filename);
49  if (DFG == NULL) {
50  log_error("Error initializing DFG");
51  return -1;
52  }
53  set_dfg(DFG);
54 
55  LOCAL_RUNTIME = get_dfg_runtime(runtime_id);
56  if (LOCAL_RUNTIME == NULL) {
57  log_error("Error finding runtime %d in DFG %s",
58  runtime_id, filename);
59  return -1;
60  }
61 
62  if (init_dfg_msu_types(DFG->msu_types, DFG->n_msu_types) != 0) {
63  log_error("Error instantiating MSU types found in %s",
64  filename);
65  return -1;
66  }
67 
68  if (instantiate_dfg_runtime(LOCAL_RUNTIME) != 0) {
69  log_error("Error instantiating runtime %d from %s",
70  runtime_id, filename);
71  return -1;
72  }
73 
74  return 0;
75 }
76 
77 int controller_address(struct sockaddr_in *addr) {
78  if (DFG == NULL) {
79  log_error("Runtime DFG not instantiated");
80  return -1;
81  }
82 
83  bzero(addr, sizeof(*addr));
84  addr->sin_family = AF_INET;
85  addr->sin_addr.s_addr = DFG->global_ctl_ip;
86  addr->sin_port = htons(DFG->global_ctl_port);
87 
88  return 0;
89 }
90 
92  if (LOCAL_RUNTIME == NULL) {
93  log_error("Runtime DFG not instantiated");
94  return -1;
95  }
96  return LOCAL_RUNTIME->id;
97 }
98 
100  if (LOCAL_RUNTIME == NULL) {
101  log_error("Runtime DFG not instantiated");
102  return -1;
103  }
104  return LOCAL_RUNTIME->port;
105 }
106 
108  if (LOCAL_RUNTIME == NULL) {
109  log_error("Runtime DFG not implemented");
110  return -1;
111  }
112  return LOCAL_RUNTIME->ip;
113 }
114 
115 struct dedos_dfg *get_dfg() {
116  return DFG;
117 }
118 
120  log_info("Freeing runtime DFG");
121  free_dfg(DFG);
122  //TODO: This shouldn't be in this function
124 }
void set_local_runtime(struct dfg_runtime *rt)
Sets the local runtime to be equal to the provided rt.
Definition: runtime_dfg.c:37
int init_runtime_dfg(char *filename, int runtime_id)
Initializes the DFG as loaded from a JSON file, and sets the global variables such that the DFG and r...
Definition: runtime_dfg.c:41
uint32_t ip
IP of the node on which the runtime is running.
Definition: dfg.h:75
int controller_address(struct sockaddr_in *addr)
Gets the sockaddr associated with the global controller.
Definition: runtime_dfg.c:77
uint32_t local_runtime_ip()
Definition: runtime_dfg.c:107
int global_ctl_port
Port of the global controller.
Definition: dfg.h:242
#define log_info(fmt,...)
Definition: logging.h:88
void destroy_msu_types()
Calls the type-sepecific constructor for each instantiated MSU type.
Definition: msu_type.c:69
uint32_t global_ctl_ip
IP address of the global controller.
Definition: dfg.h:241
static struct dedos_dfg * DFG
Static (global) variable for accessing a lodaed Dfg.
Definition: runtime_dfg.c:33
Defines a type of MSU, including callback and accessor functions.
void free_dfg(struct dedos_dfg *dfg)
Frees the entirety of the DFG structure.
Definition: dfg.c:596
Instantiation of a dfg on a runtime.
int n_msu_types
The number of elements in dedos_dfg::msu_types.
Definition: dfg.h:250
struct dfg_runtime * get_dfg_runtime(unsigned int runtime_id)
Returns the runtime with the given ID.
Definition: dfg.c:64
int id
Unique identifier for the runtime.
Definition: dfg.h:74
Logging of status messages to the terminal.
Interactions with global dfg from individual runtime.
Representation of a runtime in the DFG.
Definition: dfg.h:73
#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.
struct dfg_msu_type * msu_types[32]
MSU types which may be present in the application.
Definition: dfg.h:248
int local_runtime_id()
Definition: runtime_dfg.c:91
Top-level structure holding the data-flow graph.
Definition: dfg.h:239
struct dedos_dfg * parse_dfg_json_file(const char *filename)
Converts a json file to a dfg structure.
Definition: dfg_reader.c:96
int instantiate_dfg_runtime(struct dfg_runtime *rt)
Instantiates the MSUs, routes, and threads on the specified runtime.
int local_runtime_port()
Definition: runtime_dfg.c:99
int init_dfg_msu_types(struct dfg_msu_type **msu_types, int n_msu_types)
Runs the runtime initilization function for the given MSU types.
static int runtime_id(int runtime_fd)
unsigned int uint32_t
Definition: uthash.h:96
struct dedos_dfg * get_dfg()
Definition: runtime_dfg.c:115
static struct dfg_runtime * LOCAL_RUNTIME
Static (global) variable holding this runtime's dfg.
Definition: runtime_dfg.c:35
int port
Port on which the runtime is listening for controller/inter-runtime.
Definition: dfg.h:76
void free_runtime_dfg()
Frees the runtime's static instance of the DFG.
Definition: runtime_dfg.c:119