Commit 5116cd33 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add the long desired halt/swap event directives. You can now put this

in your NS file:

	$ns at 2000.0 "$ns halt"
or
	$ns at 2000.0 "$ns swapout"

The first causes the experiment to terminate, the later causes it to
swap out. I know some wiseass is going to ask for a swapin event!
You can also send these events from tevc:

	tevc -e testbed/stopme now ns halt
or
	tevc -e testbed/stopme now ns swapout

Does it need to be said that this is insecure? That we could get swap
wars going on as people try to get nodes for their experiments by
swapping out someone else? Well, if that happens we will apply the big
hammer and squash their nuts.

Details: I added an SIMULATOR "agent", and HALT/SWAPOUT event types in
the usual places. In the event scheduler, SIMULATOR events are treated
specially (not actually sent anywhere), but handled internally. Very
convenient, cause the scheduler runs as the person who swapped the
experiment in, and so I just run either swapexp or endexp, right from
the scheduler. At some point we need to give the permission issue some
thought.
parent 56a3ea2a
......@@ -32,6 +32,7 @@
static void enqueue(event_handle_t handle,
event_notification_t notification, void *data);
static void dequeue(event_handle_t handle);
static int handle_simevent(event_handle_t handle, sched_event_t *eventp);
static char *progname;
static char *pid, *eid;
......@@ -298,10 +299,19 @@ dequeue(event_handle_t handle)
if (debug > 1)
gettimeofday(&now, NULL);
if (event_notify(handle, next_event.notification) == 0) {
ERROR("could not fire event\n");
return;
}
/*
* Sim events are special right now since we handle them here.
*/
if (next_event.simevent) {
if (! handle_simevent(handle, &next_event))
goto bad;
}
else {
if (event_notify(handle, next_event.notification) == 0) {
ERROR("could not fire event\n");
return;
}
}
if (debug > 1) {
info("Fire: note:%p at:%ld:%d now:%ld:%d\n",
......@@ -310,6 +320,7 @@ dequeue(event_handle_t handle)
now.tv_sec,
now.tv_usec);
}
bad:
event_notification_free(handle, next_event.notification);
}
}
......@@ -501,6 +512,8 @@ get_static_events(event_handle_t handle)
}
event.time.tv_sec = time.tv_sec;
event.time.tv_usec = time.tv_usec;
event.simevent = !strcmp(OBJTYPE,
TBDB_OBJECTTYPE_SIMULATOR);
sched_event_enqueue(event);
nrows--;
}
......@@ -520,6 +533,7 @@ get_static_events(event_handle_t handle)
error("could not allocate notification");
return 0;
}
event.simevent = 0;
event.notification = notification;
event.time.tv_sec = now.tv_sec;
event.time.tv_usec = now.tv_usec;
......@@ -550,3 +564,50 @@ quit(int sig)
/* cleanup() will be called from atexit() */
exit(0);
}
static int
handle_simevent(event_handle_t handle, sched_event_t *eventp)
{
char evtype[TBDB_FLEN_EVEVENTTYPE];
int rcode;
char cmd[BUFSIZ];
if (! event_notification_get_eventtype(handle,
eventp->notification,
evtype, sizeof(evtype))) {
error("could not get event type from notification %p\n",
eventp->notification);
return 0;
}
/*
* All we know about is the "SWAPOUT" and "HALT" event!
*/
if (strcmp(evtype, TBDB_EVENTTYPE_HALT) &&
strcmp(evtype, TBDB_EVENTTYPE_SWAPOUT)) {
error("cannot handle SIMULATOR event %s.\n", evtype);
return 0;
}
/*
* We are lucky! The event scheduler runs as the user! But just in
* case, check our uid to make sure we are not root.
*/
if (!getuid() || !geteuid()) {
error("Cannot run SIMULATOR %s as root.\n", evtype);
return 0;
}
/*
* Run the command. Redirect the output so we can see it.
*/
if (!strcmp(evtype, TBDB_EVENTTYPE_SWAPOUT)) {
sprintf(cmd, "swapexp -s out %s %s", pid, eid);
}
else if (!strcmp(evtype, TBDB_EVENTTYPE_HALT)) {
sprintf(cmd, "endexp %s %s", pid, eid);
}
rcode = system(cmd);
/* Should not return, but ... */
return (rcode == 0);
}
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2002 University of Utah and the Flux Group.
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -28,6 +28,7 @@
typedef struct sched_event {
event_notification_t notification; /* event notification */
struct timeval time; /* event firing time */
int simevent; /* A simulator event, dummy */
} sched_event_t;
/*
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2002 University of Utah and the Flux Group.
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -19,6 +19,7 @@ char *tbdb_objecttypes[] = {
TBDB_OBJECTTYPE_TIME,
TBDB_OBJECTTYPE_PROGRAM,
TBDB_OBJECTTYPE_FRISBEE,
TBDB_OBJECTTYPE_SIMULATOR,
0,
};
......@@ -33,6 +34,8 @@ char *tbdb_eventtypes[] = {
TBDB_EVENTTYPE_MODIFY,
TBDB_EVENTTYPE_SET,
TBDB_EVENTTYPE_RESET,
TBDB_EVENTTYPE_HALT,
TBDB_EVENTTYPE_SWAPOUT,
TBDB_NODESTATE_ISUP,
TBDB_NODESTATE_REBOOTED,
TBDB_NODESTATE_REBOOTING,
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2002 University of Utah and the Flux Group.
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -32,6 +32,7 @@
#define TBDB_OBJECTTYPE_TIME "TIME"
#define TBDB_OBJECTTYPE_PROGRAM "PROGRAM"
#define TBDB_OBJECTTYPE_FRISBEE "FRISBEE"
#define TBDB_OBJECTTYPE_SIMULATOR "SIMULATOR"
#define TBDB_EVENTTYPE_START "START"
#define TBDB_EVENTTYPE_STOP "STOP"
......@@ -43,6 +44,8 @@
#define TBDB_EVENTTYPE_MODIFY "MODIFY"
#define TBDB_EVENTTYPE_SET "SET"
#define TBDB_EVENTTYPE_RESET "RESET"
#define TBDB_EVENTTYPE_HALT "HALT"
#define TBDB_EVENTTYPE_SWAPOUT "SWAPOUT"
#define TBDB_NODESTATE_ISUP "ISUP"
#define TBDB_NODESTATE_REBOOTED "REBOOTED"
......
......@@ -122,6 +122,9 @@ REPLACE INTO event_eventtypes VALUES (6,'MODIFY');
REPLACE INTO event_eventtypes VALUES (7,'SET');
REPLACE INTO event_eventtypes VALUES (8,'TIME');
REPLACE INTO event_eventtypes VALUES (9,'RESET');
REPLACE INTO event_eventtypes VALUES (10,'KILL');
REPLACE INTO event_eventtypes VALUES (11,'HALT');
REPLACE INTO event_eventtypes VALUES (12,'SWAPOUT');
--
-- Dumping data for table 'event_objecttypes'
......@@ -134,6 +137,7 @@ REPLACE INTO event_objecttypes VALUES (2,'TRAFGEN');
REPLACE INTO event_objecttypes VALUES (3,'TIME');
REPLACE INTO event_objecttypes VALUES (4,'PROGRAM');
REPLACE INTO event_objecttypes VALUES (5,'FRISBEE');
REPLACE INTO event_objecttypes VALUES (6,'SIMULATOR');
--
-- Dumping data for table 'exported_tables'
......
......@@ -62,7 +62,7 @@ use libtestbed;
$| = 1;
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin:$TB/bin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $evsched = "$TB/sbin/event-sched";
......
......@@ -321,7 +321,12 @@ Simulator instproc run {} {
sql exec $DB "update experiments set forcelinkdelays=$forcelinkdelays,uselinkdelays=$uselinkdelays,usewatunnels=$usewatunnels,uselatestwadata=$uselatestwadata,wa_delay_solverweight=$wa_delay_solverweight,wa_bw_solverweight=$wa_bw_solverweight,wa_plr_solverweight=$wa_plr_solverweight where pid='$pid' and eid='$eid'"
sql endquery $DB
# This could probably be elsewhere.
sql exec $DB "insert into virt_agents (pid,eid,vnode,vname,objecttype) values ('$pid','$eid','*','$self','$objtypes(SIMULATOR)')";
sql endquery $DB
foreach event $event_list {
sql exec $DB "insert into eventlist (pid,eid,time,vnode,vname,objecttype,eventtype,arguments,atstring) values (\"$pid\",\"$eid\",[lindex $event 0],\"[lindex $event 1]\",\"[lindex $event 2]\",$objtypes([lindex $event 3]),$eventtypes([lindex $event 4]),\"[lindex $event 5]\",\"[lindex $event 6]\")"
}
......@@ -602,18 +607,29 @@ Simulator instproc at {time eventstring} {
set okargs 1
}
"Simulator" {
set vnode "*"
set vname $self
switch -- $cmd {
"bandwidth" {
set otype LINK
set etype MODIFY
set vnode {}
set vname {}
}
"halt" {
set otype SIMULATOR
set etype HALT
}
"swapout" {
set otype SIMULATOR
set etype SWAPOUT
}
unknown {
punsup "at $time $event"
return
}
}
set vnode {}
set vname {}
set okargs 1
}
unknown {
......
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