Partially implemented config file parser. Validates, but does not populate NetworkSetup object yet.
This commit is contained in:
parent
f119717b5e
commit
6fa948cd74
16 changed files with 323 additions and 81 deletions
12
configure.in
12
configure.in
|
@ -46,6 +46,7 @@ AM_CONDITIONAL(HAVE_CHECK, test x$have_check = xtrue)
|
|||
#fi
|
||||
|
||||
AC_CHECK_LIB([m], [sqrt])
|
||||
AC_CHECK_LIB([db], [db_open])
|
||||
AC_CHECK_LIB([pthread], [pthread_create])
|
||||
|
||||
# Checks for header files.
|
||||
|
@ -59,14 +60,19 @@ AC_C_CONST
|
|||
AC_TYPE_PID_T
|
||||
AC_TYPE_SIZE_T
|
||||
AC_HEADER_TIME
|
||||
AC_STRUCT_TM
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_ERROR_AT_LINE
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_REALLOC
|
||||
AC_FUNC_STAT
|
||||
AC_CHECK_FUNCS([bzero fdatasync getcwd gettimeofday inet_ntoa memmove memset mkdir socket sqrt strchr strdup strerror strrchr strstr strtoul])
|
||||
AC_CHECK_FUNCS([bzero fdatasync getcwd gettimeofday inet_ntoa localtime_r memmove memset mkdir socket sqrt strchr strdup strerror strrchr strstr strtoul])
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
benchmarks/Makefile
|
||||
benchmarks/berkeleyDB/Makefile
|
||||
libdfa/Makefile
|
||||
lladd/Makefile
|
||||
pbl/Makefile
|
||||
|
@ -78,8 +84,8 @@ AC_CONFIG_FILES([Makefile
|
|||
src/libdfa/Makefile
|
||||
src/lladd/Makefile
|
||||
src/pbl/Makefile
|
||||
src/timing/Makefile
|
||||
src/pobj/Makefile
|
||||
src/timing/Makefile
|
||||
test/2pc/Makefile
|
||||
test/Makefile
|
||||
test/cht/Makefile
|
||||
|
@ -90,7 +96,5 @@ AC_CONFIG_FILES([Makefile
|
|||
test/monotree/Makefile
|
||||
test/pobj/Makefile
|
||||
utilities/Makefile
|
||||
benchmarks/Makefile
|
||||
benchmarks/berkeleyDB/Makefile
|
||||
])
|
||||
AC_OUTPUT
|
||||
|
|
|
@ -54,8 +54,6 @@ terms specified in this license.
|
|||
*/
|
||||
#define DFA_MACHINE_COUNT 100
|
||||
|
||||
|
||||
/** TODO: Add transitions and states to dfaSet? */
|
||||
typedef struct dfaSet {
|
||||
/* MonoTree monoTree; */
|
||||
smash_t * smash;
|
||||
|
|
|
@ -44,7 +44,7 @@ terms specified in this license.
|
|||
#define _MESSAGES_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <libdfa/networksetup.h>
|
||||
typedef unsigned long state_machine_id;
|
||||
|
||||
/* Maximum size of a message payload, in bytes. Should be a multiple of the system word length.*/
|
||||
|
@ -86,29 +86,6 @@ typedef struct message {
|
|||
char payload[MAX_PAYLOAD];
|
||||
} Message;
|
||||
|
||||
/**
|
||||
This struct contains the state for the messages (networking) layer.
|
||||
Currently, everything here can be derived at startup, so this won't
|
||||
need to be in transactional storage, with some luck. */
|
||||
typedef struct networkSetup {
|
||||
unsigned short localport;
|
||||
char * localhost;
|
||||
int socket;
|
||||
/**
|
||||
Same format as argv for main(). If a message is addressed to
|
||||
"broadcast", then the message will be sent to each
|
||||
"address:port" pair in this string. If you want to use proper
|
||||
IP broadcast, then this list can simply contain one entry that
|
||||
contains a subnet broadcast address like "1.2.3.0:1234".
|
||||
|
||||
It would be best to set this value to NULL and
|
||||
broadcast_list_count to zero if you don't plan to use broadcast.
|
||||
*/
|
||||
char *** broadcast_lists;
|
||||
int broadcast_lists_count;
|
||||
int *broadcast_list_host_count;
|
||||
} NetworkSetup;
|
||||
|
||||
int init_network(NetworkSetup *ns, unsigned short portnum);
|
||||
|
||||
int init_network_broadcast(NetworkSetup * ns, unsigned short portnum, char * localhost, char *** broadcast_lists,
|
||||
|
|
36
libdfa/networksetup.h
Normal file
36
libdfa/networksetup.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef __NETWORKSETUP_H
|
||||
#define __NETWORKSETUP_H
|
||||
/**
|
||||
This struct contains the state for the messages (networking) layer.
|
||||
Currently, everything here can be derived at startup, so this won't
|
||||
need to be in transactional storage, with some luck. */
|
||||
typedef struct networkSetup {
|
||||
unsigned short localport;
|
||||
char * localhost;
|
||||
int socket;
|
||||
/**
|
||||
Same format as argv for main(). If a message is addressed to
|
||||
"broadcast", then the message will be sent to each
|
||||
"address:port" pair in this string. If you want to use proper
|
||||
IP broadcast, then this list can simply contain one entry that
|
||||
contains a subnet broadcast address like "1.2.3.0:1234".
|
||||
|
||||
It would be best to set this value to NULL and
|
||||
broadcast_list_count to zero if you don't plan to use broadcast.
|
||||
*/
|
||||
char *** broadcast_lists;
|
||||
int broadcast_lists_count;
|
||||
int *broadcast_list_host_count;
|
||||
} NetworkSetup;
|
||||
|
||||
/** This site is the coordinator. */
|
||||
#define COORDINATOR -1
|
||||
/** Obtain the hostnumber from the config file. */
|
||||
#define DEFAULT_HOST -2
|
||||
/** Parses the network configuration file.
|
||||
@param The name of the config file.
|
||||
@param hostnumber COORDINATOR, or which subordinate this host is (zero indexed)
|
||||
@return an initialized NetworkSetup struct.
|
||||
*/
|
||||
NetworkSetup * readNetworkConfig(char * name, int hostnumber);
|
||||
#endif // __NETWORKSETUP_H
|
7
libdfa/networksetup.sample
Normal file
7
libdfa/networksetup.sample
Normal file
|
@ -0,0 +1,7 @@
|
|||
coordinator = 127.0.0.1:20000
|
||||
subordinates = {
|
||||
127.0.0.1:20001,
|
||||
127.0.0.1:20002,
|
||||
127.0.0.1:20003,
|
||||
127.0.0.1:20004
|
||||
}
|
50
lladd.pws
50
lladd.pws
|
@ -11,14 +11,14 @@ filter.file.ignore.hidden=0
|
|||
filter.dir.ignore.hidden=0
|
||||
|
||||
[filenumbers]
|
||||
0=135
|
||||
0=1
|
||||
1=1
|
||||
2=1
|
||||
3=113
|
||||
4=51
|
||||
5=439
|
||||
6=545
|
||||
7=122
|
||||
2=12
|
||||
3=2
|
||||
4=50
|
||||
5=3
|
||||
6=25
|
||||
7=24
|
||||
8=30
|
||||
9=1
|
||||
10=67
|
||||
|
@ -51,15 +51,14 @@ filter.dir.ignore.hidden=0
|
|||
17=
|
||||
|
||||
[filelist]
|
||||
0=/home/sears/lladd/lladd/constants.h
|
||||
1=/home/sears/lladd/lladd/operations.h
|
||||
2=/home/sears/lladd/src/lladd/page.c
|
||||
3=/home/sears/lladd/src/lladd/operations/set.c
|
||||
4=/home/sears/lladd/src/lladd/operations/arrayList.c
|
||||
5=/home/sears/lladd/test/lladd/check_page.c
|
||||
6=/home/sears/lladd/test/lladd/check_operations.c
|
||||
7=/home/sears/lladd/src/lladd/operations/alloc.c
|
||||
8=/home/sears/lladd/lladd/operations/alloc.h
|
||||
0=/home/sears/lladd/libdfa/messages.h
|
||||
1=/home/sears/lladd/test/dfa/Makefile.am
|
||||
2=/home/sears/lladd/test/lladd/Makefile.am
|
||||
3=/home/sears/lladd/test/lladd/check_blobRecovery.c
|
||||
4=/home/sears/lladd/test/dfa/check_networksetup.c
|
||||
5=/home/sears/lladd/libdfa/networksetup.sample
|
||||
6=/home/sears/lladd/src/libdfa/networksetup.c
|
||||
7=/home/sears/lladd/libdfa/networksetup.h
|
||||
|
||||
[Project Tree]
|
||||
0=0
|
||||
|
@ -74,14 +73,17 @@ filter.dir.ignore.hidden=0
|
|||
|
||||
[File Tree]
|
||||
0=0
|
||||
1=0:6
|
||||
2=0:6:2
|
||||
3=0:9
|
||||
4=0:9:4
|
||||
5=0:9:4:3
|
||||
6=0:9:4:4
|
||||
7=0:10
|
||||
8=0:10:5
|
||||
1=0:5
|
||||
2=0:6
|
||||
3=0:6:2
|
||||
4=0:9
|
||||
5=0:10
|
||||
6=0:10:0
|
||||
7=0:10:2
|
||||
8=0:10:3
|
||||
9=0:11
|
||||
10=0:11:4
|
||||
11=0:11:5
|
||||
|
||||
[executer args]
|
||||
0=check_linearHash
|
||||
|
|
|
@ -101,19 +101,20 @@ static unsigned char * responseType(Message *m) {
|
|||
}
|
||||
|
||||
/** TODO: Endianness. (ICK) */
|
||||
//state_name request_type =*(requestType(m)); \sdsd
|
||||
//state_name response_type =*(responseType(m)); \sd
|
||||
//TwoPCMachineState * machine_state_2pc = (TwoPCMachineState*) &(stateMachine->app_state); \sd
|
||||
|
||||
#define setup_vars \
|
||||
state_name request_type =*(requestType(m)); \
|
||||
state_name response_type =*(responseType(m)); \
|
||||
TwoPCMachineState * machine_state_2pc = (TwoPCMachineState*) &(stateMachine->app_state); \
|
||||
TwoPCAppState * app_state_2pc = ((TwoPCAppState*)(((DfaSet*)dfaSet)->app_setup)); \
|
||||
CHTAppState * app_state_cht = app_state_2pc->app_state; \
|
||||
jbHashTable_t * xid_ht = app_state_cht->xid_ht; \
|
||||
jbHashTable_t * ht_ht = app_state_cht->ht_ht; \
|
||||
int ht_xid = app_state_cht->ht_xid; \
|
||||
int xid; \
|
||||
int xid_exists = (-1 != jbHtLookup(ht_xid, xid_ht, &(stateMachine->machine_id), sizeof(state_machine_id), &xid)); \
|
||||
int xid_exists = (-1 != jbHtLookup(ht_xid, xid_ht,(byte*) &(stateMachine->machine_id), sizeof(state_machine_id), (byte*)&xid)); \
|
||||
jbHashTable_t ht; \
|
||||
int ht_exists = (-1 != jbHtLookup(ht_xid, ht_ht, &(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), &ht))
|
||||
int ht_exists = (-1 != jbHtLookup(ht_xid, ht_ht, (byte*)&(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t),(byte*) &ht))
|
||||
|
||||
|
||||
|
||||
|
@ -321,6 +322,16 @@ state_name init_xact_cht(void * dfaSet, StateMachine * stateMachine, Message * m
|
|||
return 1;
|
||||
}
|
||||
|
||||
int xid_exists(int ht_xid, jbHashTable_t * xid_ht, StateMachine * stateMachine) {
|
||||
int xid;
|
||||
if (-1 == jbHtLookup(ht_xid, xid_ht, (byte*)&(stateMachine->machine_id), sizeof(state_machine_id), (byte*)&xid)) {
|
||||
return 0;
|
||||
} else {
|
||||
assert(xid);
|
||||
return xid;
|
||||
}
|
||||
}
|
||||
|
||||
callback_fcn abort_cht;
|
||||
|
||||
/* Begins new transaction, does the work the transaction requests, stores the message, and returns the corresponding error code. */
|
||||
|
@ -329,6 +340,8 @@ state_name veto_or_prepare_cht(void * dfaSet, StateMachine * stateMachine, Messa
|
|||
state_name ret;
|
||||
setup_vars;
|
||||
|
||||
// int xid_exists = (-1 != jbHtLookup(ht_xid, app_state_cht->xid_ht, &(stateMachine->machine_id), sizeof(state_machine_id, &xid));
|
||||
|
||||
if(xid_exists) { printf("Warning: Stale xid found!\n"); }
|
||||
assert(!xid_exists);
|
||||
printf("requestType: %d, responseType: %d key: %d from %s:%ld\n", *requestType(m), *responseType(m), *(int*)getKeyAddr(m), m->initiator, m->initiator_machine_id);
|
||||
|
@ -339,7 +352,7 @@ state_name veto_or_prepare_cht(void * dfaSet, StateMachine * stateMachine, Messa
|
|||
|
||||
printf("Tbegin failed; %d\n", xid);
|
||||
|
||||
} else if(jbHtInsert(ht_xid, xid_ht, &(stateMachine->machine_id), sizeof(state_machine_id), &xid, sizeof(int)) == -1) {
|
||||
} else if(jbHtInsert(ht_xid, xid_ht, (byte*)&(stateMachine->machine_id), sizeof(state_machine_id), (byte*)&xid, sizeof(int)) == -1) {
|
||||
|
||||
printf("jbHtInsert failed.\n");
|
||||
|
||||
|
@ -373,7 +386,7 @@ state_name abort_cht(void * dfaSet, StateMachine * stateMachine, Message * m, ch
|
|||
|
||||
printf("Aborting!!\n");
|
||||
|
||||
if(response_type == AWAIT_COMMIT_POINT || response_type == AWAIT_RESULT) {
|
||||
if(*responseType(m) == AWAIT_COMMIT_POINT || *responseType(m) == AWAIT_RESULT) {
|
||||
state_machine_id tmp = m->from_machine_id;
|
||||
|
||||
/* TODO: Could the chages to from_machine_id be moved into libdfa (it does this anyway, but it does it too late.) */
|
||||
|
@ -387,7 +400,7 @@ state_name abort_cht(void * dfaSet, StateMachine * stateMachine, Message * m, ch
|
|||
assert(xid_exists);
|
||||
|
||||
Tabort(xid); // !!!!
|
||||
jbHtRemove(ht_xid, xid_ht, &(stateMachine->machine_id), sizeof(state_machine_id), &xid);
|
||||
jbHtRemove(ht_xid, xid_ht, (byte*)&(stateMachine->machine_id), sizeof(state_machine_id), (byte*)&xid);
|
||||
Tcommit(app_state_cht->ht_xid);
|
||||
app_state_cht->ht_xid = Tbegin();
|
||||
return 1;
|
||||
|
@ -402,13 +415,13 @@ state_name do_work(void * dfaSet, StateMachine * stateMachine, Message * m, char
|
|||
|
||||
/* printf("ht_ht = %x, ht = %x\n", ht_ht, ht); */
|
||||
|
||||
switch(request_type)
|
||||
switch(*requestType(m))
|
||||
{
|
||||
case CREATE:
|
||||
{
|
||||
jbHashTable_t * new = jbHtCreate(ht_xid, 79);
|
||||
if(new != NULL) {
|
||||
ret = (jbHtInsert(ht_xid, ht_ht, &(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), new, sizeof(jbHashTable_t)) >= 0);
|
||||
ret = (jbHtInsert(ht_xid, ht_ht, (byte*)&(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), (byte*)new, sizeof(jbHashTable_t)) >= 0);
|
||||
} else {
|
||||
ret = 0;
|
||||
}
|
||||
|
@ -427,7 +440,7 @@ state_name do_work(void * dfaSet, StateMachine * stateMachine, Message * m, char
|
|||
if(!ht_exists) { printf ("Hash table %d doesn't exist!\n", (__header_ptr(m)->hashTable).id); fflush(NULL); ret = 0; } else {
|
||||
ret = (jbHtInsert(xid, &ht, getKeyAddr(m), getKeyLength(m), getValAddr(m), getValLength(m)) >= 0);
|
||||
printf("Insert: %d ht=%d (key length %d) %d -> %s\n", ret, (__header_ptr(m)->hashTable).id, getKeyLength(m), *(int*)getKeyAddr(m), getValAddr(m));
|
||||
(jbHtInsert(ht_xid, ht_ht, &(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), &ht, sizeof(jbHashTable_t)));
|
||||
(jbHtInsert(ht_xid, ht_ht, (byte*)&(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), (byte*)&ht, sizeof(jbHashTable_t)));
|
||||
|
||||
}
|
||||
} break;
|
||||
|
@ -444,7 +457,7 @@ state_name do_work(void * dfaSet, StateMachine * stateMachine, Message * m, char
|
|||
{
|
||||
if(!ht_exists) { printf ("Hash table doesn't exist!\n"); fflush(NULL); ret = 0; } else {
|
||||
ret = (jbHtRemove(xid, &ht, getKeyAddr(m), getKeyLength(m), getValAddr(m)) >= 0);
|
||||
(jbHtInsert(ht_xid, ht_ht, &(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), &ht, sizeof(jbHashTable_t)));
|
||||
(jbHtInsert(ht_xid, ht_ht, (byte*)&(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), (byte*)&ht, sizeof(jbHashTable_t)));
|
||||
}
|
||||
} break;
|
||||
|
||||
|
@ -452,7 +465,7 @@ state_name do_work(void * dfaSet, StateMachine * stateMachine, Message * m, char
|
|||
{
|
||||
if(!ht_exists) { printf ("Hash table doesn't exist!\n"); fflush(NULL); ret = 0; } else {
|
||||
jbHtRemove(xid, ht_ht, getKeyAddr(m), getKeyLength(m), NULL);
|
||||
(jbHtInsert(ht_xid, ht_ht, &(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), &ht, sizeof(jbHashTable_t)));
|
||||
(jbHtInsert(ht_xid, ht_ht, (byte*)&(__header_ptr(m)->hashTable), sizeof(clusterHashTable_t), (byte*)&ht, sizeof(jbHashTable_t)));
|
||||
/* ret = (jbHtDelete(xid, &ht) >= 0); */ /* Don't need this--jbHtDelete just frees the (stack!) pointer. */
|
||||
Tcommit(app_state_cht->ht_xid);
|
||||
app_state_cht->ht_xid = Tbegin();
|
||||
|
@ -497,7 +510,7 @@ state_name do_work(void * dfaSet, StateMachine * stateMachine, Message * m, char
|
|||
*/
|
||||
default:
|
||||
{
|
||||
printf("Unknown request type: %d\n", request_type);
|
||||
printf("Unknown request type: %d\n", *requestType(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,12 +523,12 @@ state_name commit_cht(void * dfaSet, StateMachine * stateMachine, Message * m, c
|
|||
|
||||
assert(xid_exists);
|
||||
Tcommit(xid);
|
||||
jbHtRemove(ht_xid, xid_ht, &(stateMachine->machine_id), sizeof(state_machine_id), &xid);
|
||||
jbHtRemove(ht_xid, xid_ht, (byte*)&(stateMachine->machine_id), sizeof(state_machine_id), (byte*)&xid);
|
||||
Tcommit(app_state_cht->ht_xid);
|
||||
app_state_cht->ht_xid = Tbegin();
|
||||
/* }*/
|
||||
|
||||
if(response_type == AWAIT_RESULT) {
|
||||
if(*responseType(m) == AWAIT_RESULT) {
|
||||
printf("commit_cht responding on an AWAIT_RESULT request.\n");
|
||||
assert(0);
|
||||
/* respond_once(&((DfaSet*)dfaSet)->networkSetup, SUBORDINATE_ACKING_2PC, m, __header_ptr(m)->initiator); */
|
||||
|
@ -526,13 +539,13 @@ state_name commit_cht(void * dfaSet, StateMachine * stateMachine, Message * m, c
|
|||
|
||||
state_name tally_cht(void * dfaSet, StateMachine * stateMachine, Message * m, char * from) {
|
||||
|
||||
setup_vars;
|
||||
// setup_vars;
|
||||
|
||||
/* TODO: Make sure this is after tally forces the log. Also, need to
|
||||
make sure that it increments the (currently unimplemented)
|
||||
sequence number before flushing... */
|
||||
|
||||
if(response_type == AWAIT_COMMIT_POINT && stateMachine->current_state==COORDINATOR_START_2PC) {
|
||||
if(*responseType(m) == AWAIT_COMMIT_POINT && stateMachine->current_state==COORDINATOR_START_2PC) {
|
||||
state_machine_id tmp = m->from_machine_id;
|
||||
|
||||
/* TODO: Could the chages to from_machine_id be moved into libdfa (it does this anyway, but it does it too late.) */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#LDADD=$(top_builddir)/build/transactional.a $(top_builddir)/build/libpbl.a
|
||||
lib_LIBRARIES=libdfa.a librw.a
|
||||
libdfa_a_SOURCES=libdfa.c monotree.c smash.c callbacks.c messages.c
|
||||
libdfa_a_SOURCES=libdfa.c monotree.c smash.c callbacks.c messages.c networksetup.c
|
||||
librw_a_SOURCES=rw.c
|
||||
AM_CFLAGS= -g -Wall -pedantic -std=gnu99
|
||||
|
|
|
@ -95,17 +95,17 @@ short parse_port(const char * address) {
|
|||
port_s = strtok_r(addr_copy, ":", &strtok_buf);
|
||||
|
||||
if(port_s == NULL) {
|
||||
printf("Invalid address (%s) passed into parse_port", address);
|
||||
assert(0);
|
||||
return -1;
|
||||
// printf("Invalid address (%s) passed into parse_port", address);
|
||||
// assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
port_s = strtok_r(NULL, ":", &strtok_buf);
|
||||
|
||||
if(port_s == NULL) {
|
||||
printf("Invalid address (%s) passed into parse_port", address);
|
||||
assert(0);
|
||||
return -1;
|
||||
// printf("Invalid address (%s) passed into parse_port", address);
|
||||
// assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
port = atoi(port_s);
|
||||
|
|
76
src/libdfa/networksetup.c
Normal file
76
src/libdfa/networksetup.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#include <libdfa/networksetup.h>
|
||||
#include <confuse.h>
|
||||
#include <stdlib.h>
|
||||
#include <libdfa/messages.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/** @todo could validate ip addresses a bit better. Currently, validate_host_port will accept 999.999.999.999:1
|
||||
*/
|
||||
int validate_host_port(cfg_t *cfg, cfg_opt_t *opt) {
|
||||
char * hostport = cfg_opt_getnstr(opt, cfg_opt_size(opt) - 1);
|
||||
if(strlen(hostport) > MAX_ADDRESS_LENGTH-1) {
|
||||
cfg_error(cfg, "string option %s ('%s') too long.\n\tMust be less than %d characters in section '%s'",
|
||||
opt->name, hostport, MAX_ADDRESS_LENGTH, cfg->name);
|
||||
return -1;
|
||||
}
|
||||
char * addr = parse_addr(hostport);
|
||||
if(addr == NULL) {
|
||||
cfg_error(cfg, "Error parsing address portion of string option %s ('%s'). should be of form nnn.nnn.nnn.nnn:mmmmm where n and m are intergers in section '%s'",
|
||||
opt->name, hostport, cfg->name);
|
||||
return -1;
|
||||
}
|
||||
int i;
|
||||
for(i = 0; i < strlen(addr); i++) {
|
||||
if((addr[i] < '0' || addr[i] > '9') && addr[i] != '.') {
|
||||
cfg_error(cfg, "Error parsing address from option %s ('%s'), should be IP address in section '%s'",
|
||||
opt->name, addr, cfg->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
free(addr);
|
||||
long int port = parse_port(hostport);
|
||||
|
||||
if(port < 1 || port > 65535)
|
||||
{
|
||||
cfg_error(cfg, "port number must be between 1 and 65535 in option %s ('%s') section '%s'",
|
||||
opt->name, hostport, cfg->name);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
cfg_opt_t opts[] = {
|
||||
CFG_STR("coordinator", "127.0.0.1:10000", CFGF_NONE),
|
||||
CFG_STR_LIST("subordinates",
|
||||
"{127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003}", CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
NetworkSetup * readNetworkConfig(char * name, int hostnumber) {
|
||||
|
||||
cfg_t *cfg;
|
||||
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
cfg_set_validate_func(cfg, "coordinator", validate_host_port);
|
||||
cfg_set_validate_func(cfg, "subordinates", validate_host_port);
|
||||
if(cfg_parse(cfg, name) == CFG_PARSE_ERROR) {
|
||||
fprintf(stderr, "Configuration file parse error.\n");
|
||||
fflush(NULL);
|
||||
return NULL;
|
||||
}
|
||||
printf("coordinator: %s\n", cfg_getstr(cfg, "coordinator"));
|
||||
printf("subordinate count: %d\n", cfg_size(cfg, "subordinates"));
|
||||
int i;
|
||||
for(i = 0; i < cfg_size(cfg, "subordinates"); i++) {
|
||||
printf("\t%s\n", cfg_getnstr(cfg, "subordinates", i));
|
||||
}
|
||||
|
||||
if(hostnumber == COORDINATOR) {
|
||||
printf("I am coordinator\n");
|
||||
} else {
|
||||
printf("I am subordinate # %d\n", hostnumber);
|
||||
}
|
||||
|
||||
cfg_free(cfg);
|
||||
return NULL;
|
||||
}
|
|
@ -1,3 +1,12 @@
|
|||
LDADD=$(top_builddir)/src/libdfa/libdfa.a $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a
|
||||
LDADD= @CHECK_LIBS@ $(top_builddir)/src/libdfa/libdfa.a $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a -lconfuse
|
||||
bin_PROGRAMS=ping_pong_dfa fork_bomb star
|
||||
AM_FLAGS= -g -Wall -pedantic -std=c99
|
||||
if HAVE_CHECK
|
||||
TESTS = check_networksetup
|
||||
else
|
||||
TESTS =
|
||||
endif
|
||||
noinst_PROGRAMS = $(TESTS)
|
||||
#LDADD = @CHECK_LIBS@ $(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/pbl/libpbl.a $(top_builddir)/src/libdfa/librw.a #-lefence
|
||||
CLEANFILES = check_networksetup.log
|
||||
#AM_CFLAGS= -g -Wall -pedantic -std=gnu99
|
||||
|
|
89
test/dfa/check_networksetup.c
Normal file
89
test/dfa/check_networksetup.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*---
|
||||
This software is copyrighted by the Regents of the University of
|
||||
California, and other parties. The following terms apply to all files
|
||||
associated with the software unless explicitly disclaimed in
|
||||
individual files.
|
||||
|
||||
The authors hereby grant permission to use, copy, modify, distribute,
|
||||
and license this software and its documentation for any purpose,
|
||||
provided that existing copyright notices are retained in all copies
|
||||
and that this notice is included verbatim in any distributions. No
|
||||
written agreement, license, or royalty fee is required for any of the
|
||||
authorized uses. Modifications to this software may be copyrighted by
|
||||
their authors and need not follow the licensing terms described here,
|
||||
provided that the new terms are clearly indicated on the first page of
|
||||
each file where they apply.
|
||||
|
||||
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
||||
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
||||
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
|
||||
NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND
|
||||
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
|
||||
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||
|
||||
GOVERNMENT USE: If you are acquiring this software on behalf of the
|
||||
U.S. government, the Government shall have only "Restricted Rights" in
|
||||
the software and related documentation as defined in the Federal
|
||||
Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you are
|
||||
acquiring the software on behalf of the Department of Defense, the
|
||||
software shall be classified as "Commercial Computer Software" and the
|
||||
Government shall have only "Restricted Rights" as defined in Clause
|
||||
252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
|
||||
authors grant the U.S. Government and others acting in its behalf
|
||||
permission to use and distribute the software in accordance with the
|
||||
terms specified in this license.
|
||||
---*/
|
||||
#include <config.h>
|
||||
#include <check.h>
|
||||
/*#include <assert.h> */
|
||||
|
||||
//#include <lladd/transactional.h>
|
||||
//#include "../../src/lladd/logger/logWriter.h"
|
||||
#include "../check_includes.h"
|
||||
#include <assert.h>
|
||||
#include <libdfa/networksetup.h>
|
||||
#define LOG_NAME "check_networksetup.log"
|
||||
|
||||
/**
|
||||
@test
|
||||
*/
|
||||
START_TEST (networksetup_check) {
|
||||
readNetworkConfig("../../libdfa/networksetup.sample", COORDINATOR);
|
||||
}
|
||||
END_TEST
|
||||
/**
|
||||
@test
|
||||
*/
|
||||
START_TEST (networksetup_check_error) {
|
||||
assert(!readNetworkConfig("networksetup.bad", COORDINATOR));
|
||||
assert(!readNetworkConfig("networksetup.bad2", COORDINATOR));
|
||||
assert(!readNetworkConfig("networksetup.bad3", COORDINATOR));
|
||||
assert(!readNetworkConfig("networksetup.bad4", COORDINATOR));
|
||||
}
|
||||
END_TEST
|
||||
/**
|
||||
Add suite declarations here
|
||||
*/
|
||||
Suite * check_suite(void) {
|
||||
Suite *s = suite_create("networksetup_suite");
|
||||
/* Begin a new test */
|
||||
TCase *tc = tcase_create("networksetup");
|
||||
/* void * foobar; */ /* used to supress warnings. */
|
||||
/* Sub tests are added, one per line, here */
|
||||
|
||||
tcase_add_test(tc, networksetup_check);
|
||||
tcase_add_test(tc, networksetup_check_error);
|
||||
/* --------------------------------------------- */
|
||||
// tcase_add_checked_fixture(tc, setup, teardown);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
#include "../check_setup.h"
|
7
test/dfa/networksetup.bad
Normal file
7
test/dfa/networksetup.bad
Normal file
|
@ -0,0 +1,7 @@
|
|||
coordinator = 127.0.0.1:20000
|
||||
subordinates = {
|
||||
127.0.0.1:abcd,
|
||||
127.0.0.1:20002,
|
||||
127.0.0.1:20003,
|
||||
127.0.0.1:20004
|
||||
}
|
7
test/dfa/networksetup.bad2
Normal file
7
test/dfa/networksetup.bad2
Normal file
|
@ -0,0 +1,7 @@
|
|||
coordinator = 127.0.0.1:20000
|
||||
subordinates = {
|
||||
127.0.0.1:abcdThisOptionIsReallyLong,
|
||||
127.0.0.1:20002,
|
||||
127.0.0.1:20003,
|
||||
127.0.0.1:20004
|
||||
}
|
7
test/dfa/networksetup.bad3
Normal file
7
test/dfa/networksetup.bad3
Normal file
|
@ -0,0 +1,7 @@
|
|||
coordinator = 127.0.0.1:20000
|
||||
subordinates = {
|
||||
127.0.0.1,
|
||||
127.0.0.1:20002,
|
||||
127.0.0.1:20003,
|
||||
127.0.0.1:20004
|
||||
}
|
10
test/dfa/networksetup.bad4
Normal file
10
test/dfa/networksetup.bad4
Normal file
|
@ -0,0 +1,10 @@
|
|||
coordinator = 127.0.0.1:20000
|
||||
|
||||
## The library currently doesn't handle hostnames, so this should fail to validate.
|
||||
|
||||
subordinates = {
|
||||
hedora.ath.cx:20001,
|
||||
127.0.0.1:20002,
|
||||
127.0.0.1:20003,
|
||||
127.0.0.1:20004
|
||||
}
|
Loading…
Reference in a new issue