Skip to content
Snippets Groups Projects
Commit 333761c7 authored by clohr's avatar clohr
Browse files

Modif de la stack xAAL pour afficher les @IP

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/C/trunk@1274 b32b6428-25c9-4566-ad07-03861ab6144f
parent 46232234
No related branches found
No related tags found
No related merge requests found
libxaal.o
netprobe.o
netprobe
PROG = netprobe
CFLAGS = -Wall -I. -g
LDFLAGS = -ljson-c -luuid -lm -L. -lxaal
LDFLAGS = -ljson-c -luuid -lm -L. libxaal.c
SHELL = /bin/bash
......@@ -15,7 +15,7 @@ proper: clean
-rm -f $(PROG)
test: $(PROG)
-LD_LIBRARY_PATH+=:. ./$(PROG) -a 224.0.29.200 -p 1234
./$(PROG) -a 224.0.29.200 -p 1234
Makefile.dep: $(PROG).c
$(CC) $(CFLAGS) -MM $^ > $@
......@@ -28,4 +28,3 @@ include Makefile.dep
svnignore: .svnignore
svn propset svn:ignore -F $< .
\ No newline at end of file
This diff is collapsed.
/* xAAL bus monitoring
* (c) 2015 Christophe Lohr <christophe.lohr@telecom-bretagne.eu>
* (c) 2016 Christophe Lohr <christophe.lohr@telecom-bretagne.eu>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -25,6 +25,7 @@
#include <signal.h>
#include <limits.h>
#include <float.h>
#include <errno.h>
#include <sys/queue.h>
#include <json-c/json.h>
......@@ -40,6 +41,7 @@ typedef LIST_HEAD(listhead, entry) seen_devs_t;
typedef struct entry {
char addr[37];
char *type;
char *ip;
unsigned long long bytes, msgs;
LIST_ENTRY(entry) entries;
} seen_dev_t;
......@@ -58,6 +60,7 @@ seen_dev_t *append_dev(seen_devs_t *seen_devs, const char *addr, const char *dev
np->type = strdup(devType);
np->bytes = 0;
np->msgs = 0;
np->ip = NULL;
LIST_INSERT_HEAD(seen_devs, np, entries);
return np;
}
......@@ -84,6 +87,7 @@ void init_data() {
LIST_FOREACH(np, seen_devs, entries) {
LIST_REMOVE(np, entries);
free(np->type);
free(np->ip);
free(np);
}
else {
......@@ -120,7 +124,7 @@ void print_report(int s) {
LIST_FOREACH(np, seen_devs, entries) {
bw_dev = (double)(np->bytes) / (double)(elapsed.tv_sec + elapsed.tv_usec*1E-6);
printf("%s %s bw:%.3g%% count:%.3g%%\n", np->addr, np->type, bw_dev/bw*100.0, (double)(np->msgs)/(double)(msgs_count)*100.0);
printf("%s %s %s bw:%.3g%% count:%.3g%%\n", np->addr, np->ip, np->type, bw_dev/bw*100.0, (double)(np->msgs)/(double)(msgs_count)*100.0);
}
printf("\n");
......@@ -136,7 +140,6 @@ void print_report(int s) {
}
int main(int argc, char **argv) {
xAAL_businfo_t bus;
int opt;
......@@ -147,8 +150,9 @@ int main(int argc, char **argv) {
const char *version, *source, *msgType, *devType, *action,
*cipher, *signature;
time_t timestamp;
ssize_t nread;
char *ip;
seen_dev_t *seen_dev;
size_t sz;
/* Parse cmdline arguments */
while ((opt = getopt(argc, argv, "a:p:h:")) != -1) {
......@@ -193,22 +197,22 @@ int main(int argc, char **argv) {
for (;;) {
/* Recive a message */
if (!xAAL_read_bus(&bus, &jmsg, &version, &source, &jtargets, &msgType, &devType,
&action, &cipher, &signature, &timestamp))
&action, &cipher, &signature, &timestamp, &nread, &ip))
continue;
sz = strlen(json_object_get_string(jmsg));
if (bytes_count > (ULLONG_MAX-sz)) {
if (bytes_count > (ULLONG_MAX-nread)) {
init_data();
continue;
}
bytes_count += sz;
bytes_count += nread;
msgs_count++;
seen_dev = append_dev(seen_devs, source, devType);
seen_dev->bytes += sz;
seen_dev->bytes += nread;
seen_dev->msgs++;
if ( (seen_dev->ip == NULL) && (ip) )
seen_dev->ip = strdup(ip);
print_report(SIGUSR1);
......
../libxaal/xaal.h
\ No newline at end of file
/*
* Modified version of the xAAL library
* xAAL_read_bus() is modified to return actual message size and sender's ip
*/
/* libxaal
* A minimal xAAL library
*
* (c) 2014 Christophe Lohr <christophe.lohr@telecom-bretagne.eu>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBXAAL
#define LIBXAAL
#include <stdio.h>
#include <stdbool.h>
#include <netdb.h>
#include <time.h>
#include <json-c/json.h>
#define xAAL_LIB_VERSION "0.5"
#define xAAL_BUF_SIZE 65536 /* Adjust it to your needs and capabilities */
#define xAAL_VERSION "0.4"
extern FILE *xAAL_error_log;
/*
* Data structures
*/
typedef struct {
int sfd;
struct sockaddr_storage addr;
socklen_t addrlen;
int hops;
} xAAL_businfo_t;
typedef struct {
char addr[37];
char *devType;
unsigned alivemax;
char *vendorId;
char *productId;
struct json_object *hwId;
char *version;
char *parent;
char **childrens;
char *url;
char *info;
char **unsupportedAttributes;
char **unsupportedMethods;
char **unsupportedNotifications;
} xAAL_devinfo_t;
/*
* Helpers for data structures
*/
/* Retrieve an item within a null-terminated list of strings */
/* May be used on unsupported{Attributes,Methods,Notifications} */
char **xAAL_list_get_item(char **list, char *item);
/* Build a json arry from a null-terminated vector of strings */
struct json_object *xAAL_vector2array(char **items);
/* Build a null-terminated vector of strings from a json arry */
char **xAAL_array2vector(struct json_object *jarray);
/* Build a json array from a (va_) list of strings */
struct json_object *xAAL_list2array(const char *st0, ...);
/*
* Helpers for accessing the bus
*/
/* Join the xAAL bus
Return 'true' if everything was ok, and 'false' otherwise. */
bool xAAL_join_bus(const char *addr,
const char *port,
int hops,
int mcast_loop,
xAAL_businfo_t *bus);
/* Manage received message */
/* Read a message from the bus, parse it thanks to the json-c library,
return the json object of the message,
return parameters of the header.
Note: do not forget to do a json_object_put(jmsg) after using jmsg
and its content in order to free memory.
Return 'true' if everything was ok, and 'false' otherwise. */
bool xAAL_read_bus(const xAAL_businfo_t *bus,
struct json_object **jmsg,
const char **version,
const char **source,
struct json_object **jtargets,
const char **msgType,
const char **devType,
const char **action,
const char **cipher,
const char **signature,
time_t *timestamp,
ssize_t *nread, char **ip);
/* Test if a given address belong to the jtargets list (or boradcast) */
bool xAAL_targets_match(struct json_object *jtargets,
const char *addr);
/* Send a message on the bus */
/* Helps devices to write a message on the bus.
It build the header, add the provided jbody if any, an send it.
Targets is a json array of uuid strings (addresses).
Return true if success */
bool xAAL_write_bus(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *msgType,
const char *action,
struct json_object *jbody,
struct json_object *jtargets);
/* Send a message on the bus */
/* Helps devices to write a message on the bus.
It build the header, add the provided jbody if any, an send it.
Targets is a vector of uuid strings (addresses) terminated by NULL.
(see xAAL_write_busl() for passing targets as a list)
Return true if success */
#define xAAL_write_busv(bus, device, msgType, action, jbody, targets) xAAL_write_bus(bus, device, msgType, action, jbody, xAAL_vector2array(targets))
/* Send a message on the bus */
/* Helps devices to write a message on the bus.
It build the header, add the provided jbody if any, an send it.
Targets is a list of uuid strings (addresses) terminated by NULL.
(see xAAL_write_busv() for passing targets as a vector)
Return true if success */
#define xAAL_write_busl(bus, device, msgType, action, jbody, ...) xAAL_write_bus(bus, device, msgType, action, jbody, xAAL_list2array(__VA_ARGS__))
/*
* Helpers for handling usual messages
*/
/* Send alive messages */
/* Return true if success */
bool xAAL_notify_alive(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device);
/* xAAL_reply_getDescription */
/* Return true if success */
bool xAAL_reply_getDescription(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *target);
/* xAAL_reply_getCiphers */
/* Return true if success */
bool xAAL_reply_getCiphers(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *target);
/* xAAL_reply_setCiphers */
/* We actually to not manage cipher change... */
/* Return true if success */
bool xAAL_reply_setCiphers(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *target);
/* xAAL_reply_getBusConfig */
/* Return true if success */
bool xAAL_reply_getBusConfig(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *target);
/* xAAL_reply_setBusConfig */
/* We actually to not manage bus change... */
/* Return true if success */
bool xAAL_reply_setBusConfig(const xAAL_businfo_t *bus,
const xAAL_devinfo_t *device,
const char *target);
/* Get timeout value within an alive notify */
/* Return 0 if there is no timeout indication or timeout+now otherwise */
time_t xAAL_read_aliveTimeout(struct json_object *jmsg);
/* Test if requested devTypes of an isAlive match a given one */
/* i.e., <prefix>.<suffix> or <prefix>.any or any.any */
bool xAAL_isAliveDevType_match(struct json_object *jmsg,
char *devType);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment