2014-06-05 09:34:29 +00:00
|
|
|
/**
|
|
|
|
* Main routine
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <error.h>
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "cfg.h"
|
2014-06-05 09:34:29 +00:00
|
|
|
#include "msg.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "path.h"
|
|
|
|
#include "node.h"
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
/// Global settings
|
|
|
|
struct config config;
|
2014-06-05 09:34:40 +00:00
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
void quit()
|
2014-06-05 09:34:29 +00:00
|
|
|
{
|
2014-06-05 09:34:50 +00:00
|
|
|
for (int i = 0; i < config.path_count; i++) {
|
|
|
|
struct path *p = &config.paths[i];
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
path_stop(p);
|
2014-06-05 09:34:40 +00:00
|
|
|
|
2014-06-05 09:34:57 +00:00
|
|
|
info("Path %u stopped:", i);
|
|
|
|
info(" %u messages received", p->received);
|
|
|
|
info(" %u messages duplicated", p->duplicated);
|
|
|
|
info(" %u messages delayed", p->delayed);
|
2014-06-05 09:34:40 +00:00
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
path_destroy(p);
|
|
|
|
}
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
for (int i = 0; i < config.node_count; i++) {
|
|
|
|
node_destroy(&config.nodes[i]);
|
2014-06-05 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
free(config.paths);
|
|
|
|
free(config.nodes);
|
|
|
|
config_destroy(&config.obj);
|
2014-06-05 09:34:40 +00:00
|
|
|
|
2014-06-05 09:34:45 +00:00
|
|
|
_exit(EXIT_SUCCESS);
|
2014-06-05 09:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2014-06-05 09:34:40 +00:00
|
|
|
atexit(&quit);
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s CONFIG\n", argv[0]);
|
|
|
|
printf(" CONFIG is a required path to a configuration file\n\n");
|
2014-06-05 09:34:45 +00:00
|
|
|
printf("Simulator2Simulator Server %s (%s %s)\n", VERSION, __DATE__, __TIME__);
|
|
|
|
printf(" Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
|
|
|
printf(" Steffen Vogel <stvogel@eonerc.rwth-aachen.de>\n\n");
|
2014-06-05 09:34:29 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
info("This is s2ss %s", VERSION);
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
// Default settings
|
|
|
|
config.filename = argv[1];
|
|
|
|
config.debug = 0;
|
|
|
|
config.nice = 0;
|
|
|
|
config.affinity = 0xC0;
|
|
|
|
config.protocol = 0;
|
|
|
|
|
|
|
|
config_init(&config.obj);
|
|
|
|
config_parse(&config.obj, &config);
|
|
|
|
|
|
|
|
if (config.path_count)
|
|
|
|
info("Parsed %u nodes and %u paths", config.node_count, config.path_count);
|
|
|
|
else
|
|
|
|
error("No paths found. Terminating...");
|
|
|
|
|
|
|
|
for (int i = 0; i < config.path_count; i++) {
|
|
|
|
path_start(&config.paths[i]);
|
|
|
|
}
|
2014-06-05 09:34:40 +00:00
|
|
|
|
2014-06-05 09:34:29 +00:00
|
|
|
signal(SIGINT, quit);
|
|
|
|
pause();
|
|
|
|
|
2014-06-05 09:34:50 +00:00
|
|
|
quit();
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|