diff --git a/include/cfg.h b/include/cfg.h index 5d2776865..343399451 100644 --- a/include/cfg.h +++ b/include/cfg.h @@ -2,7 +2,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file cfg.h + * @file */ #ifndef _CFG_H_ @@ -37,10 +37,12 @@ struct settings { /** Parse configuration file and store settings in supplied struct settings. * - * @param cfg A libconfig object - * @param set The global configuration structure (also contains the config filename) - * @param nodes A pointer to a linked list of nodes which should be parsed - * @param paths A pointer to a linked list of paths which should be parsed + * @param filename The path to the configration file (relative or absolute) + * @param cfg A initialized libconfig object + * @param set The global configuration structure + * @param nodes A linked list of nodes which should be parsed + * @param paths A linked list of paths which should be parsed + * @param interfaces A linked list of interfaces which should be parsed * @return * - 0 on success * - otherwise an error occured diff --git a/include/config.h b/include/config.h index c121d5958..536b2c62d 100644 --- a/include/config.h +++ b/include/config.h @@ -4,7 +4,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file config.h + * @file */ #ifndef _CONFIG_H_ @@ -19,9 +19,6 @@ /** Maximum number of registrable hook functions per path */ #define MAX_HOOKS 5 -/** Size of the stack which gets prefaulted during initialization */ -#define MAX_SAFE_STACK (16*1024) /* 16 KiB */ - /** Socket priority */ #define SOCKET_PRIO 7 diff --git a/include/if.h b/include/if.h index 009153a27..d2c4cc1ce 100644 --- a/include/if.h +++ b/include/if.h @@ -2,7 +2,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file if.h + * @file */ #ifndef _IF_H_ @@ -11,8 +11,8 @@ #include #include -#define IF_NAME_MAX IFNAMSIZ -#define IF_IRQ_MAX 3 +#define IF_NAME_MAX IFNAMSIZ /**< Maximum length of an interface name */ +#define IF_IRQ_MAX 3 /**< Maxmimal number of IRQs of an interface */ /** Interface data structure */ struct interface { diff --git a/include/msg.h b/include/msg.h index e2344fe17..e6d6a9215 100644 --- a/include/msg.h +++ b/include/msg.h @@ -2,7 +2,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file msg.h + * @file */ #ifndef _MSG_H_ diff --git a/include/node.h b/include/node.h index 0f5c00192..a0848ea94 100644 --- a/include/node.h +++ b/include/node.h @@ -8,7 +8,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file node.h + * @file */ #ifndef _NODE_H_ diff --git a/include/path.h b/include/path.h index f4024cb01..8eb2d0041 100644 --- a/include/path.h +++ b/include/path.h @@ -2,7 +2,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file path.h + * @file */ #ifndef _PATH_H_ @@ -47,9 +47,13 @@ struct path unsigned int duplicated; /** Last known message number */ unsigned int sequence; + /** Counter for received messages with invalid device id or data */ + unsigned int invalid; - /** The thread ids for this path */ - pthread_t tid, tid2; + /** The thread id for this path */ + pthread_t tid; + /** A second thread id for fixed rate sending thread */ + phtread_t tid2; /** A pointer to the libconfig object which instantiated this path */ config_setting_t *cfg; diff --git a/include/tc.h b/include/tc.h index 0acb6c4dc..b987fd8e1 100644 --- a/include/tc.h +++ b/include/tc.h @@ -1,8 +1,13 @@ -/** - * Setup interface queuing desciplines for network emulation +/** Setup interface queuing desciplines for network emulation + * + * We use the firewall mark to apply individual netem qdiscs + * per node. Every node uses an own BSD socket. + * By using so SO_MARK socket option (see socket(7)) + * we can classify traffic originating from a node seperately. * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC + * @file */ #ifndef _TC_H_ @@ -10,25 +15,38 @@ #include -/* Some helper for TC handles */ +/** A type alias for TC handles. + * + * TC handles are used to construct a tree + * of classes, qdiscs and filters. + */ typedef uint32_t tc_hdl_t; +/** Concatenate 16 bit minor and majar parts to a 32 bit tc handle */ #define TC_HDL(maj, min) ((maj & 0xFFFF) << 16 | (min & 0xFFFF)) +/** Get the major part of a tc handle */ #define TC_HDL_MAJ(h) ((h >> 16) & 0xFFFF) +/** Get the minor part of a tc handle */ #define TC_HDL_MIN(h) ((h >> 0) & 0xFFFF) +/** The root handle */ #define TC_HDL_ROOT (0xFFFFFFFFU) /* Bitfield for valid fields in struct netem */ -#define TC_NETEM_LIMIT (1 << 0) -#define TC_NETEM_DELAY (1 << 1) -#define TC_NETEM_JITTER (1 << 2) -#define TC_NETEM_DISTR (1 << 3) -#define TC_NETEM_LOSS (1 << 4) -#define TC_NETEM_CORRUPT (1 << 5) -#define TC_NETEM_DUPL (1 << 6) +#define TC_NETEM_LIMIT (1 << 0) /**< netem::limit is valid @see netem::valid */ +#define TC_NETEM_DELAY (1 << 1) /**< netem::delay is valid @see netem::valid */ +#define TC_NETEM_JITTER (1 << 2) /**< netem::jitter is valid @see netem::valid */ +#define TC_NETEM_DISTR (1 << 3) /**< netem::distribution is valid @see netem::valid */ +#define TC_NETEM_LOSS (1 << 4) /**< netem::loss is valid @see netem::valid */ +#define TC_NETEM_CORRUPT (1 << 5) /**< netem::corrupt is valid @see netem::valid */ +#define TC_NETEM_DUPL (1 << 6) /**< netem::duplicate is valid @see netem::valid */ struct interface; +/** Netem configuration settings + * + * This struct is used to pass the netem configuration + * from config_parse_netem() to tc_netem() + */ struct netem { /** Which fields of this struct contain valid data (TC_NETEM_*). */ char valid; @@ -52,15 +70,17 @@ struct netem { /** Remove all queuing disciplines and filters * * @param i The interface + * @return + * - 0 on success + * - otherwise an error occured */ int tc_reset(struct interface *i); /** Create a prio queueing discipline * * @param i The interface - * @param parent - * @param handle - * @param bands + * @param handle The handle for the new qdisc + * @param bands The number of classes for this new qdisc * @return * - 0 on success * - otherwise an error occured @@ -70,11 +90,23 @@ int tc_prio(struct interface *i, tc_hdl_t handle, int bands); /** Add a new network emulator discipline * * @param i The interface - * @param parent Make this + * @param parent Make this qdisc a child of + * @param em The netem settings + * @return + * - 0 on success + * - otherwise an error occured */ int tc_netem(struct interface *i, tc_hdl_t parent, struct netem *em); -/** Add a new fwmark filter */ +/** Add a new filter based on the netfilter mark + * + * @param i The interface + * @param flowid The destination class for matched traffic + * @param mark The netfilter firewall mark (sometime called 'fwmark') + * @return + * - 0 on success + * - otherwise an error occured +*/ int tc_mark(struct interface *i, tc_hdl_t flowid, int mark); #endif /* _TC_H_ */ diff --git a/include/utils.h b/include/utils.h index babe38bce..9b30d055f 100644 --- a/include/utils.h +++ b/include/utils.h @@ -2,7 +2,7 @@ * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC - * @file utils.h + * @file */ #ifndef _UTILS_H_ @@ -16,13 +16,13 @@ #include /* Some color escape codes for pretty log messages */ -#define RED(str) "\x1B[31m" str "\x1B[0m" -#define GRN(str) "\x1B[32m" str "\x1B[0m" -#define YEL(str) "\x1B[33m" str "\x1B[0m" -#define BLU(str) "\x1B[34m" str "\x1B[0m" -#define MAG(str) "\x1B[35m" str "\x1B[0m" -#define CYN(str) "\x1B[36m" str "\x1B[0m" -#define WHT(str) "\x1B[37m" str "\x1B[0m" +#define RED(str) "\x1B[31m" str "\x1B[0m" /**< Print str in red */ +#define GRN(str) "\x1B[32m" str "\x1B[0m" /**< Print str in green */ +#define YEL(str) "\x1B[33m" str "\x1B[0m" /**< Print str in yellow */ +#define BLU(str) "\x1B[34m" str "\x1B[0m" /**< Print str in blue */ +#define MAG(str) "\x1B[35m" str "\x1B[0m" /**< Print str in magenta */ +#define CYN(str) "\x1B[36m" str "\x1B[0m" /**< Print str in cyan */ +#define WHT(str) "\x1B[37m" str "\x1B[0m" /**< Print str in white */ /** The log level which is passed as first argument to print() */ enum log_level { DEBUG, INFO, WARN, ERROR }; diff --git a/src/cfg.c b/src/cfg.c index 15b5ed364..140ef01e8 100644 --- a/src/cfg.c +++ b/src/cfg.c @@ -1,5 +1,4 @@ -/** - * Configuration parser +/** Configuration parser * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/if.c b/src/if.c index 503fa7528..b93c8719e 100644 --- a/src/if.c +++ b/src/if.c @@ -1,5 +1,4 @@ -/** - * Interface related functions +/** Interface related functions * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/msg.c b/src/msg.c index 5995e762e..81f39aa46 100644 --- a/src/msg.c +++ b/src/msg.c @@ -1,5 +1,4 @@ -/** - * Message related functions +/** Message related functions * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/node.c b/src/node.c index e6aa3aa82..391483b15 100644 --- a/src/node.c +++ b/src/node.c @@ -1,5 +1,4 @@ -/** - * Nodes +/** Nodes * * The S2SS server connects multiple nodes. * There are multiple types of nodes: diff --git a/src/path.c b/src/path.c index ebeaa143c..67f4515f3 100644 --- a/src/path.c +++ b/src/path.c @@ -1,5 +1,4 @@ -/** - * Message paths +/** Message paths * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/random.c b/src/random.c index a2725c8ac..c98282bf5 100644 --- a/src/random.c +++ b/src/random.c @@ -1,5 +1,4 @@ -/** - * Generate random packages on stdout +/** Generate random packages on stdout * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/receive.c b/src/receive.c index 06239e9a9..402778129 100644 --- a/src/receive.c +++ b/src/receive.c @@ -1,5 +1,4 @@ -/** - * Receive messages from server snd print them on stdout +/** Receive messages from server snd print them on stdout * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/send.c b/src/send.c index 9bf5aefbf..94b900221 100644 --- a/src/send.c +++ b/src/send.c @@ -1,5 +1,4 @@ -/** - * Send messages from stdin to server +/** Send messages from stdin to server * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/server.c b/src/server.c index 66ad3b44e..ad0acf72b 100644 --- a/src/server.c +++ b/src/server.c @@ -1,5 +1,4 @@ -/** - * Main routine +/** Main routine * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/tc.c b/src/tc.c index 5fd78a90e..cec7696ff 100644 --- a/src/tc.c +++ b/src/tc.c @@ -1,5 +1,6 @@ -/** - * Traffic control: setup interface queuing desciplines +/** Traffic control: setup interface queuing desciplines + * + * S2SS uses these functions to setup the network emulation feature. * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/test.c b/src/test.c index 675cda4e0..b1bd3518c 100644 --- a/src/test.c +++ b/src/test.c @@ -1,5 +1,4 @@ -/** - * Some basic tests +/** Some basic tests * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC diff --git a/src/utils.c b/src/utils.c index 380e855d7..ad48c10d3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,5 +1,4 @@ -/** - * Some helper functions +/** Some helper functions * * @author Steffen Vogel * @copyright 2014, Institute for Automation of Complex Power Systems, EONERC