1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

more work for simple test client (should envolve to file dumper, reader)

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@13 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-06-05 09:34:40 +00:00
parent 92ea1a7802
commit 70dca6f79c
2 changed files with 77 additions and 24 deletions

View file

@ -21,20 +21,29 @@
static struct node *nodes[MAX_NODES] = { NULL };
static struct path *paths[MAX_PATHS] = { NULL };
int dumper(struct msg *m)
{
msg_fprint(stdout, m);
}
/**
* Do your configuration here
*/
void init()
{
nodes[0] = node_create("opal", SERVER, "localhost", 10200);
nodes[1] = node_create("sintef", SERVER, "localhost", 10201);
nodes[0] = node_create("test", SERVER, "*:10201", "localhost:10200");
//nodes[1] = node_create("sintef", SERVER, "localhost", 10201);
paths[0] = path_create(nodes[0], &nodes[1], 1);
paths[1] = path_create(nodes[1], &nodes[0], 1);
paths[0] = path_create(nodes[0], nodes[0]);
for (int i = 0; i < MAX_PATHS && paths[i]; i++) {
path_start(paths[i]);
}
path_start(paths[0]);
paths[0]->hooks[0] = dumper;
//paths[1] = path_create(nodes[1], &nodes[0], 1);
//for (int i = 0; i < MAX_PATHS && paths[i]; i++) {
// path_start(paths[i]);
//}
}
void quit()
@ -44,13 +53,17 @@ void quit()
path_destroy(paths[i]);
}
for (int i = 0; i < MAX_NODES && nodes[i]; i++) {
for (int i = 0; i < MAX_NODES && nodes[i]; i++)
node_destroy(nodes[i]);
}
print(INFO, "Goodbye!");
_exit(0);
}
int main(int argc, char *argv[])
{
atexit(&quit);
if (argc != 1) {
printf("Usage: s2ss [config]\n");
printf(" config is an optional path to a configuration file\n\n");
@ -61,7 +74,8 @@ int main(int argc, char *argv[])
print(INFO, "Good morning! This is s2ss v%s", VERSION);
init();
init(); /* Setup paths and nodes manually */
signal(SIGINT, quit);
pause();

View file

@ -10,6 +10,8 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -19,6 +21,25 @@
#include "utils.h"
#include "msg.h"
int dev_id;
int sd;
void quit()
{
print(INFO, "Goodbye");
exit(EXIT_SUCCESS);
}
void tick()
{
struct msg m;
msg_random(&m, dev_id);
msg_fprint(stdout, &m);
send(sd, &m, sizeof(struct msg), 0);
}
int main(int argc, char *argv[])
{
if (argc != 4) {
@ -31,35 +52,53 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
int dev_id = atoi(argv[1]);
dev_id = atoi(argv[1]);
int ret;
print(INFO, "Test node started on %s:%s with id=%u", argv[2], argv[3], dev_id);
int sd = socket(AF_INET, SOCK_DGRAM, 0);
sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0)
print(FATAL, "Failed to create socket: %s", strerror(errno));
struct sockaddr_in sa;
struct msg m;
sa.sin_family = AF_INET;
sa.sin_port = htons(atoi(argv[3]));
struct sockaddr_in sa = {
.sin_family = AF_INET,
.sin_port = htons(atoi(argv[3]))
};
inet_aton(argv[2], &sa.sin_addr);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGUSR1);
//sigprocmask(SIG_SETMASK, &mask, NULL);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
ret = bind(sd, &sa, sizeof(struct sockaddr_in));
ret = connect(sd, &sa, sizeof(struct sockaddr_in));
if (ret < 0)
print(FATAL, "Failed to connect socket: %s", strerror(errno));
while (1) {
msg_random(&m, dev_id);
msg_fprint(stdout, &m);
struct sigevent si = {
.sigev_notify = SIGEV_SIGNAL,
.sigev_signo = SIGUSR1
};
send(sd, &m, sizeof(struct msg), 0);
struct itimerspec its = {
{ 0, 250000000 },
{ 0, 500000000 }
};
sleep(3);
}
timer_t t;
timer_create(CLOCK_MONOTONIC, &si, &t);
timer_settime(t, 0, &its, NULL);
signal(SIGUSR1, tick);
signal(SIGINT, quit);
while(1) pause();
timer_delete(t);
pause();
return 0;
}