2014-06-05 09:35:32 +00:00
|
|
|
/** Nodes
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
|
|
|
* The S2SS server connects multiple nodes.
|
|
|
|
* There are multiple types of nodes:
|
|
|
|
* - simulators
|
|
|
|
* - servers
|
|
|
|
* - workstations
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
2014-06-28 06:40:52 +00:00
|
|
|
* @file
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NODE_H_
|
|
|
|
#define _NODE_H_
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2014-06-05 09:35:41 +00:00
|
|
|
#include <libconfig.h>
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-07-04 09:47:29 +00:00
|
|
|
#include "msg.h"
|
2014-06-25 01:53:48 +00:00
|
|
|
#include "tc.h"
|
|
|
|
|
2014-07-18 16:05:45 +00:00
|
|
|
/** Static node initialization */
|
|
|
|
#define NODE_INIT(n) { \
|
|
|
|
.sd = -1, \
|
|
|
|
.name = n \
|
|
|
|
}
|
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** The datastructure for a node.
|
|
|
|
*
|
|
|
|
* Every entity which exchanges messages is represented by a node.
|
|
|
|
*/
|
2014-06-05 09:34:29 +00:00
|
|
|
struct node
|
|
|
|
{
|
2014-06-05 09:35:41 +00:00
|
|
|
/** The socket descriptor */
|
2014-06-05 09:34:29 +00:00
|
|
|
int sd;
|
2014-06-05 09:34:35 +00:00
|
|
|
|
2014-07-04 09:44:12 +00:00
|
|
|
/** A short identifier of the node, only used for configuration and logging */
|
2014-06-25 01:53:44 +00:00
|
|
|
const char *name;
|
|
|
|
|
2014-06-05 09:35:41 +00:00
|
|
|
/** Local address of the socket */
|
2014-06-05 09:35:32 +00:00
|
|
|
struct sockaddr_in local;
|
2014-06-05 09:35:41 +00:00
|
|
|
/** Remote address of the socket */
|
2014-06-05 09:34:35 +00:00
|
|
|
struct sockaddr_in remote;
|
|
|
|
|
2014-06-25 01:53:46 +00:00
|
|
|
/** The egress interface */
|
|
|
|
struct interface *interface;
|
|
|
|
|
2014-06-25 01:53:48 +00:00
|
|
|
/** Network emulator settings */
|
|
|
|
struct netem *netem;
|
|
|
|
|
2014-06-25 01:53:37 +00:00
|
|
|
/** Socket mark for netem, routing and filtering */
|
2014-06-05 09:35:39 +00:00
|
|
|
int mark;
|
2014-06-05 09:34:35 +00:00
|
|
|
|
2014-06-05 09:35:41 +00:00
|
|
|
/** A pointer to the libconfig object which instantiated this node */
|
|
|
|
config_setting_t *cfg;
|
2014-06-10 18:47:25 +00:00
|
|
|
|
|
|
|
/** Linked list pointer */
|
|
|
|
struct node *next;
|
2014-06-05 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
2014-06-25 01:53:44 +00:00
|
|
|
/** Connect and bind the UDP socket of this node.
|
2014-06-05 09:34:56 +00:00
|
|
|
*
|
|
|
|
* @param n A pointer to the node structure
|
|
|
|
* @return
|
|
|
|
* - 0 on success
|
|
|
|
* - otherwise on error occured
|
|
|
|
*/
|
|
|
|
int node_connect(struct node *n);
|
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Disconnect the UDP socket of this node.
|
2014-06-05 09:34:56 +00:00
|
|
|
*
|
|
|
|
* @param n A pointer to the node structure
|
|
|
|
* @return
|
|
|
|
* - 0 on success
|
|
|
|
* - otherwise on error occured
|
|
|
|
*/
|
|
|
|
int node_disconnect(struct node *n);
|
2014-06-05 09:34:29 +00:00
|
|
|
|
2014-06-05 09:35:32 +00:00
|
|
|
/** Search list of nodes for a name.
|
2014-06-05 09:34:29 +00:00
|
|
|
*
|
2014-06-05 09:34:56 +00:00
|
|
|
* @param str The name of the wanted node
|
2014-06-10 18:47:25 +00:00
|
|
|
* @param nodes A linked list of all nodes
|
2014-06-05 09:34:56 +00:00
|
|
|
* @return A pointer to the node or NULL if not found
|
2014-06-05 09:34:29 +00:00
|
|
|
*/
|
2014-06-10 18:47:25 +00:00
|
|
|
struct node* node_lookup_name(const char *str, struct node *nodes);
|
2014-06-05 09:34:29 +00:00
|
|
|
|
|
|
|
#endif /* _NODE_H_ */
|