mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
using node_* functions for tools
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@44 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
36e6b20ad5
commit
30a922fa21
6 changed files with 54 additions and 51 deletions
8
Makefile
8
Makefile
|
@ -20,10 +20,10 @@ CFLAGS += -D__GIT_REV__='"$(GIT_REV)"' -D__GIT_TAG__='"$(GIT_TAG)"'
|
|||
all: $(TARGETS)
|
||||
|
||||
server: node.o msg.o utils.o path.o cfg.o caps.o
|
||||
send: msg.o utils.o
|
||||
receive: msg.o utils.o
|
||||
random: msg.o utils.o
|
||||
test: msg.o utils.o
|
||||
send: node.o msg.o utils.o
|
||||
receive: node.o msg.o utils.o
|
||||
random: node.o msg.o utils.o
|
||||
test: node.o msg.o utils.o
|
||||
|
||||
%.d: %.c
|
||||
$(CC) -MM $(CFLAGS) $< -o $@
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "cfg.h"
|
||||
#include "utils.h"
|
||||
|
@ -51,9 +50,6 @@ int node_connect(struct node *n)
|
|||
if (bind(n->sd, (struct sockaddr *) &n->local, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to bind to socket");
|
||||
|
||||
debug(1, " We listen for node %s at %s:%u", n->name, inet_ntoa(n->local.sin_addr), ntohs(n->local.sin_port));
|
||||
debug(1, " We sent to node %s at %s:%u", n->name, inet_ntoa(n->remote.sin_addr), ntohs(n->remote.sin_port));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,24 +52,24 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGTERM, &sa_quit, NULL);
|
||||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
/* Resolve address */
|
||||
/* Resolve addresses */
|
||||
struct sockaddr_in local;
|
||||
struct sockaddr_in remote;
|
||||
|
||||
if (resolve(local_str, &local, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
error("Failed to resolve remote address: %s", local_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0)
|
||||
perror("Failed to create socket");
|
||||
/* Print header */
|
||||
fprintf(stderr, "# %-6s %-8s %-12s\n", "dev_id", "seq_no", "data");
|
||||
|
||||
/* Bind socket */
|
||||
if (bind(sd, (struct sockaddr *) &local, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to bind to socket");
|
||||
/* Create node */
|
||||
struct node n;
|
||||
node_create(&n, NULL, NODE_SERVER, local, remote);
|
||||
node_connect(&n);
|
||||
|
||||
struct msg m;
|
||||
while (1) {
|
||||
recv(sd, &m, sizeof(struct msg), 0);
|
||||
msg_recv(&m, &n);
|
||||
msg_fprint(stdout, &m);
|
||||
}
|
||||
|
||||
|
|
35
src/send.c
35
src/send.c
|
@ -32,17 +32,19 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
struct sockaddr_in sa;
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s REMOTE VALUES\n", argv[0]);
|
||||
if (argc != 3 && argc != 4) {
|
||||
printf("Usage: %s VALUES REMOTE [LOCAL]\n", argv[0]);
|
||||
printf(" REMOTE is a IP:PORT combination of the remote host\n");
|
||||
printf(" LOCAL is an optional IP:PORT combination of the local host\n");
|
||||
printf(" VALUES is the number of values to be read from stdin\n\n");
|
||||
printf("s2ss Simulator2Simulator Server v%s\n", VERSION);
|
||||
printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
const char *remote_str = argv[1];
|
||||
int values = atoi(argv[2]);
|
||||
int values = atoi(argv[1]);
|
||||
const char *remote_str = argv[2];
|
||||
const char *local_str = argv[3];
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
|
@ -55,26 +57,31 @@ int main(int argc, char *argv[])
|
|||
sigaction(SIGINT, &sa_quit, NULL);
|
||||
|
||||
/* Resolve addresses */
|
||||
struct sockaddr_in remote;
|
||||
struct sockaddr_in local;
|
||||
struct sockaddr_in remote;
|
||||
|
||||
if (argc == 4 && resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
else {
|
||||
local.sin_family = AF_INET;
|
||||
local.sin_addr.s_addr = INADDR_ANY;
|
||||
local.sin_port = 0;
|
||||
}
|
||||
|
||||
if (resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve remote address: %s", remote_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0)
|
||||
perror("Failed to create socket");
|
||||
|
||||
/* Connect socket */
|
||||
if (connect(sd, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to connect socket");
|
||||
/* Create node */
|
||||
struct node n;
|
||||
node_create(&n, NULL, NODE_SERVER, local, remote);
|
||||
node_connect(&n);
|
||||
|
||||
struct msg m;
|
||||
m.length = values * sizeof(double);
|
||||
|
||||
while (!feof(stdin)) {
|
||||
msg_fscan(stdin, &m);
|
||||
send(sd, &m, 8 + m.length, 0);
|
||||
msg_send(&m, &n);
|
||||
msg_fprint(stdout, &m);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "cfg.h"
|
||||
|
@ -28,6 +29,9 @@ void start()
|
|||
struct node *n = &config.nodes[i];
|
||||
|
||||
node_connect(n);
|
||||
|
||||
debug(1, " We listen for node '%s' at %s:%u", n->name, inet_ntoa(n->local.sin_addr), ntohs(n->local.sin_port));
|
||||
debug(1, " We sent to node '%s' at %s:%u", n->name, inet_ntoa(n->remote.sin_addr), ntohs(n->remote.sin_port));
|
||||
}
|
||||
|
||||
for (int i = 0; i < config.path_count; i++) {
|
||||
|
|
34
src/test.c
34
src/test.c
|
@ -38,7 +38,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
const char *test = argv[1];
|
||||
const char *remote_str = argv[2];
|
||||
const char *local_str = (argc == 4) ? argv[3] : NULL;
|
||||
const char *local_str = argv[3];
|
||||
|
||||
/* Setup signals */
|
||||
struct sigaction sa_quit = {
|
||||
|
@ -54,24 +54,21 @@ int main(int argc, char *argv[])
|
|||
struct sockaddr_in remote;
|
||||
struct sockaddr_in local;
|
||||
|
||||
if (argc == 4 && resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
else {
|
||||
local.sin_family = AF_INET;
|
||||
local.sin_addr.s_addr = INADDR_ANY;
|
||||
local.sin_port = 0;
|
||||
}
|
||||
|
||||
if (resolve(remote_str, &remote, 0))
|
||||
error("Failed to resolve remote address: %s", remote_str);
|
||||
|
||||
if (resolve(local_str, &local, 0))
|
||||
error("Failed to resolve local address: %s", local_str);
|
||||
|
||||
/* Create socket */
|
||||
sd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sd < 0)
|
||||
perror("Failed to create socket");
|
||||
|
||||
/* Bind socket */
|
||||
if (bind(sd, (struct sockaddr *) &local, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to bind to socket");
|
||||
|
||||
/* Connect socket */
|
||||
if (connect(sd, (struct sockaddr *) &remote, sizeof(struct sockaddr_in)))
|
||||
perror("Failed to connect socket");
|
||||
/* Create node */
|
||||
struct node n;
|
||||
node_create(&n, NULL, NODE_SERVER, local, remote);
|
||||
node_connect(&n);
|
||||
|
||||
if (!strcmp(test, "latency")) {
|
||||
struct msg m2, m1 = {
|
||||
|
@ -87,9 +84,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
while (1) {
|
||||
clock_gettime(CLOCK_REALTIME, ts1);
|
||||
send(sd, &m1, 8 + m1.length, 0);
|
||||
|
||||
recv(sd, &m2, sizeof(struct msg), 0);
|
||||
msg_send(&m1, &n);
|
||||
msg_recv(&m2, &n);
|
||||
clock_gettime(CLOCK_REALTIME, ts3);
|
||||
|
||||
rtt = ts3->tv_nsec - ts2->tv_nsec;
|
||||
|
|
Loading…
Add table
Reference in a new issue