Commit e3ddfecf authored by Leigh B. Stoller's avatar Leigh B. Stoller

Some additions in support of event scheduler code.

A couple of temporary routines to check for valid events; needs to
moved into the scheduler.
parent e58a3fa7
......@@ -11,7 +11,7 @@ include $(TESTBED_SRCDIR)/GNUmakerules
SYSTEM := $(shell uname -s)
OBJS = log.o
OBJS = log.o tbdefs.o
ifneq ($(SYSTEM),Linux)
OBJS += tbdb.o
endif
......@@ -22,7 +22,8 @@ libtb.a: $(OBJS)
$(RANLIB) $@
log.o: log.h
tbdb.o: tbdb.h log.h
tbdb.o: tbdb.h log.h tbdefs.h
tbdefs.o: tbdefs.h
install:
......
......@@ -116,6 +116,38 @@ mydb_iptonodeid(char *ipaddr, char *bufp)
return 1;
}
/*
* Map node ID to IP (control net interface).
*/
int
mydb_nodeidtoip(char *nodeid, char *bufp)
{
MYSQL_RES *res;
MYSQL_ROW row;
res = mydb_query("select IP from nodes as n "
"left join node_types as nt on n.type=nt.type "
"left join interfaces as i on "
" i.node_id=n.node_id and i.iface=nt.control_iface "
"where n.node_id='%s'", 1, nodeid);
if (!res) {
error("nodeidtoip: DB Error: %s", nodeid);
return 0;
}
if (! (int)mysql_num_rows(res)) {
error("nodeidtoip: No such nodeid: %s", nodeid);
mysql_free_result(res);
return 0;
}
row = mysql_fetch_row(res);
mysql_free_result(res);
strcpy(bufp, row[0]);
return 1;
}
/*
* Set the node event status.
*/
......
......@@ -14,6 +14,7 @@ int dbinit(void);
* TB functions.
*/
int mydb_iptonodeid(char *ipaddr, char *bufp);
int mydb_nodeidtoip(char *nodeid, char *bufp);
int mydb_setnodeeventstate(char *nodeid, char *eventtype);
int mydb_checkexptnodeeventstate(char *pid, char *eid,char *ev,int *count);
int mydb_seteventschedulerpid(char *pid, char *eid, int processid);
......
/*
*
*/
#include "tbdefs.h"
char *tbdb_objecttypes[] = {
TBDB_OBJECTTYPE_TESTBED,
TBDB_OBJECTTYPE_LINK,
TBDB_OBJECTTYPE_TRAFGEN,
TBDB_OBJECTTYPE_TIME,
0,
};
char *tbdb_eventtypes[] = {
TBDB_EVENTTYPE_START,
TBDB_EVENTTYPE_STOP,
TBDB_EVENTTYPE_ISUP,
TBDB_EVENTTYPE_REBOOT,
TBDB_EVENTTYPE_UP,
TBDB_EVENTTYPE_DOWN,
TBDB_EVENTTYPE_MODIFY,
TBDB_EVENTTYPE_SET,
0,
};
/*
* Check that events are legal.
*/
int
tbdb_validobjecttype(char *foo)
{
char **bp = tbdb_objecttypes;
while (*bp) {
if (!strcmp(*bp, foo))
return 1;
bp++;
}
return 0;
}
int
tbdb_valideventtype(char *foo)
{
char **bp = tbdb_eventtypes;
while (*bp) {
if (!strcmp(*bp, foo))
return 1;
bp++;
}
return 0;
}
......@@ -2,6 +2,10 @@
* Various constants that are reflected in the DB!
*/
#define TBDB_FLEN_NODEID 64
#define TBDB_FLEN_VNAME 32
#define TBDB_FLEN_EID 32
#define TBDB_FLEN_PID 12
#define TBDB_FLEN_GID 16
#define TBDB_FLEN_EVOBJTYPE 128
#define TBDB_FLEN_EVOBJNAME 128
#define TBDB_FLEN_EVEVENTTYPE 128
......@@ -23,3 +27,8 @@
#define TBDB_EVENTTYPE_MODIFY "MODIFY"
#define TBDB_EVENTTYPE_SET "SET"
/*
* Protos.
*/
int tbdb_validobjecttype(char *foo);
int tbdb_valideventtype(char *foo);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment