2004-05-15 13:33:01 +01:00
|
|
|
/**
|
2004-07-24 16:05:20 +01:00
|
|
|
* @file system.c
|
|
|
|
* \brief system related logic.
|
2004-05-15 13:33:01 +01:00
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <limits.h>
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "term.h"
|
|
|
|
#include "termlist.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "knowledge.h"
|
2004-07-24 16:08:35 +01:00
|
|
|
#include "system.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "memory.h"
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "constraint.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
#include "debug.h"
|
|
|
|
#include "output.h"
|
|
|
|
#include "tracebuf.h"
|
2004-07-24 20:07:29 +01:00
|
|
|
#include "role.h"
|
2005-06-02 13:14:28 +01:00
|
|
|
#include "mgu.h"
|
2005-06-07 16:02:27 +01:00
|
|
|
#include "switches.h"
|
|
|
|
#include "binding.h"
|
2005-06-16 15:10:07 +01:00
|
|
|
#include "specialterm.h"
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-15 13:33:01 +01:00
|
|
|
//! Global flag that signals LaTeX output.
|
|
|
|
/**
|
|
|
|
* True iff LaTeX output is desired.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
int globalLatex;
|
|
|
|
|
2004-08-27 11:08:03 +01:00
|
|
|
//! Global count of protocols
|
|
|
|
int protocolCount;
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Switch for indent or not.
|
2004-04-23 11:58:43 +01:00
|
|
|
static int indentState = 0;
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Current indent depth.
|
2004-04-23 11:58:43 +01:00
|
|
|
static int indentDepth = 0;
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Allocate memory the size of a run struct.
|
2004-04-23 11:58:43 +01:00
|
|
|
Run
|
|
|
|
makeRun ()
|
|
|
|
{
|
|
|
|
return (Run) memAlloc (sizeof (struct run));
|
|
|
|
}
|
|
|
|
|
2004-07-24 16:05:20 +01:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Initialise a system structure.
|
|
|
|
/**
|
|
|
|
*@return A system structure pointer with initial values.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
System
|
|
|
|
systemInit ()
|
|
|
|
{
|
|
|
|
System sys = (System) memAlloc (sizeof (struct system));
|
|
|
|
|
|
|
|
/* initially, no trace ofcourse */
|
|
|
|
sys->step = 0;
|
|
|
|
sys->shortestattack = INT_MAX;
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->attack = tracebufInit ();
|
2004-04-23 11:58:43 +01:00
|
|
|
sys->maxtracelength = INT_MAX;
|
|
|
|
|
|
|
|
/* init rundefs */
|
|
|
|
sys->maxruns = 0;
|
|
|
|
sys->runs = NULL;
|
|
|
|
/* no protocols yet */
|
2004-08-27 11:08:03 +01:00
|
|
|
protocolCount = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
sys->protocols = NULL;
|
|
|
|
sys->locals = NULL;
|
|
|
|
sys->variables = NULL;
|
|
|
|
sys->untrusted = NULL;
|
|
|
|
sys->secrets = NULL; // list of claimed secrets
|
2004-07-24 21:30:00 +01:00
|
|
|
sys->synchronising_labels = NULL;
|
2005-08-15 13:49:32 +01:00
|
|
|
sys->attack = NULL; // clash with prev. attack declaration TODO
|
2004-06-14 23:08:47 +01:00
|
|
|
/* no protocols => no protocol preprocessed */
|
2004-06-16 11:39:13 +01:00
|
|
|
sys->rolecount = 0;
|
|
|
|
sys->roleeventmax = 0;
|
2004-06-14 23:08:47 +01:00
|
|
|
sys->claimlist = NULL;
|
2004-08-27 12:52:43 +01:00
|
|
|
sys->labellist = NULL;
|
2005-06-07 14:40:56 +01:00
|
|
|
sys->attackid = 0; // First attack will have id 1, because the counter is increased before any attacks are displayed.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* matching CLP */
|
|
|
|
sys->constraints = NULL; // no initial constraints
|
|
|
|
|
2005-05-02 14:38:45 +01:00
|
|
|
/* Arachne assist */
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine == ARACHNE_ENGINE)
|
|
|
|
{
|
|
|
|
bindingInit (sys);
|
|
|
|
}
|
2005-05-02 14:38:45 +01:00
|
|
|
sys->bindings = NULL;
|
|
|
|
sys->current_claim = NULL;
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* reset global counters */
|
|
|
|
systemReset (sys);
|
|
|
|
|
|
|
|
return sys;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Reset a system state after some exploration.
|
|
|
|
/**
|
2004-06-13 21:58:54 +01:00
|
|
|
*@param sys A system structure pointer.
|
2004-05-15 15:47:19 +01:00
|
|
|
*@return Counter values have been reset.
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
systemReset (const System sys)
|
|
|
|
{
|
2004-06-14 23:08:47 +01:00
|
|
|
Claimlist cl;
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* some initial counters */
|
2004-07-21 15:26:28 +01:00
|
|
|
sys->states = statesIncrease (STATES0); //!< Initial state is not explored, so start counting at 1
|
2004-07-30 13:04:38 +01:00
|
|
|
sys->statesScenario = STATES0;
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->interval = sys->states; //!< To keep in line with the states
|
2004-07-21 11:35:39 +01:00
|
|
|
sys->claims = STATES0;
|
|
|
|
sys->failed = STATES0;
|
2004-07-28 12:39:08 +01:00
|
|
|
sys->countScenario = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
sys->explore = 1; // do explore the space
|
2004-06-14 23:08:47 +01:00
|
|
|
cl = sys->claimlist;
|
|
|
|
while (cl != NULL)
|
|
|
|
{
|
2004-07-21 15:26:28 +01:00
|
|
|
cl->count = STATES0;
|
|
|
|
cl->failed = STATES0;
|
2004-06-14 23:08:47 +01:00
|
|
|
cl = cl->next;
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
sys->knowPhase = 0; // knowledge transition id
|
|
|
|
|
|
|
|
termlistDestroy (sys->secrets); // remove old secrets list
|
|
|
|
sys->secrets = NULL; // list of claimed secrets
|
|
|
|
|
|
|
|
/* transfer switches */
|
2005-06-07 16:02:27 +01:00
|
|
|
sys->maxtracelength = switches.maxtracelength;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* POR init */
|
|
|
|
sys->PORphase = -1;
|
|
|
|
sys->PORdone = 1; // mark as 'something done' with previous reads
|
|
|
|
|
|
|
|
/* global latex switch: ugly, but otherwise I must carry it into every
|
|
|
|
* single subprocedure such as termPrint */
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
globalLatex = switches.latex;
|
2004-07-28 12:39:08 +01:00
|
|
|
|
2005-06-02 13:14:28 +01:00
|
|
|
/* propagate mgu_mode */
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
setMguMode (switches.match);
|
2004-07-28 12:39:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Initialize runtime system (according to cut traces, limited runs)
|
|
|
|
void
|
|
|
|
systemRuns (const System sys)
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
|
|
|
|
sys->lastChooseRun = -1;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = runPointerGet (sys, run);
|
2004-08-09 11:05:58 +01:00
|
|
|
if (rd != NULL && rd->internal && rd->type == READ)
|
2004-07-28 12:39:08 +01:00
|
|
|
{
|
|
|
|
/* increasing run traversal, so this yields max */
|
|
|
|
sys->lastChooseRun = run;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.scenario < 0)
|
2004-07-28 12:39:08 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
warning ("Last run with a choose: %i", sys->lastChooseRun);
|
2004-07-28 12:39:08 +01:00
|
|
|
}
|
|
|
|
#endif
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Delete a system structure and clear used memory for all buffers.
|
|
|
|
/**
|
|
|
|
* Is more thorough than systemDestroy().
|
|
|
|
*\sa systemDestroy()
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
systemDone (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int run;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* clear globals, which were defined in systemStart */
|
|
|
|
|
|
|
|
s = sys->maxtracelength + 1;
|
|
|
|
memFree (sys->traceEvent, s * sizeof (Roledef));
|
|
|
|
memFree (sys->traceRun, s * sizeof (int));
|
|
|
|
memFree (sys->traceKnow, s * sizeof (Knowledge));
|
2004-07-21 11:35:39 +01:00
|
|
|
memFree (sys->traceNode, s * sizeof (states_t));
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* clear roledefs */
|
2004-08-10 16:02:37 +01:00
|
|
|
while (sys->maxruns > 0)
|
|
|
|
{
|
|
|
|
roleInstanceDestroy (sys);
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* clear substructures */
|
|
|
|
termlistDestroy (sys->secrets);
|
|
|
|
|
|
|
|
/* clear main system */
|
|
|
|
systemDestroy (sys);
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print a short version of the number of states.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
statesPrintShort (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (sys->states);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print the number of states.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
statesPrint (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-07-30 13:04:38 +01:00
|
|
|
statesFormat (sys->states);
|
|
|
|
eprintf (" states traversed.\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
if (globalLatex)
|
2004-08-09 11:05:58 +01:00
|
|
|
eprintf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Destroy a system memory block and system::runs
|
|
|
|
/**
|
|
|
|
* Ignores any other substructes.
|
|
|
|
*\sa systemDone()
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
systemDestroy (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
memFree (sys->runs, sys->maxruns * sizeof (struct run));
|
|
|
|
memFree (sys, sizeof (struct system));
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Ensures that a run can be added to the system.
|
|
|
|
/**
|
|
|
|
* Allocates memory to allow a run to be added, if needed.
|
|
|
|
* This is meant to be used before using runPointerSet().
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
ensureValidRun (const System sys, int run)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int i, oldsize;
|
|
|
|
|
|
|
|
if (run < sys->maxruns)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* this amount of memory was not allocated yet */
|
|
|
|
/* (re)allocate space */
|
|
|
|
/* Note, this is never explicitly freed, because it is never
|
|
|
|
copied */
|
|
|
|
/* update size parameter */
|
|
|
|
oldsize = sys->maxruns;
|
|
|
|
sys->maxruns = run + 1;
|
2005-05-01 14:32:50 +01:00
|
|
|
sys->runs =
|
|
|
|
(Run) memRealloc (sys->runs, sizeof (struct run) * (sys->maxruns));
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* create runs, set the new pointer(s) to NULL */
|
|
|
|
for (i = oldsize; i < sys->maxruns; i++)
|
|
|
|
{
|
|
|
|
/* init run */
|
|
|
|
struct run myrun = sys->runs[i];
|
2004-12-08 19:30:26 +00:00
|
|
|
myrun.protocol = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
myrun.role = NULL;
|
|
|
|
myrun.agents = NULL;
|
2004-07-14 07:55:05 +01:00
|
|
|
myrun.step = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
myrun.index = NULL;
|
|
|
|
myrun.start = NULL;
|
2004-12-08 19:30:26 +00:00
|
|
|
|
|
|
|
myrun.locals = NULL;
|
|
|
|
myrun.artefacts = NULL;
|
|
|
|
myrun.substitutions = NULL;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine == POR_ENGINE)
|
2004-08-13 14:25:25 +01:00
|
|
|
{
|
|
|
|
myrun.know = knowledgeDuplicate (sys->know);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Arachne etc.
|
|
|
|
myrun.know = NULL;
|
|
|
|
}
|
2004-12-08 19:30:26 +00:00
|
|
|
|
|
|
|
myrun.prevSymmRun = -1;
|
|
|
|
myrun.firstNonAgentRead = -1;
|
|
|
|
myrun.firstReal = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print a run.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
runPrint (Roledef rd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
indent ();
|
|
|
|
i = 0;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("%i: ", i);
|
2004-04-23 11:58:43 +01:00
|
|
|
roledefPrint (rd);
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
i++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print all runs in the system structure.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
runsPrint (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
indent ();
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("[ Run definitions ]\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
for (i = 0; i < (sys->maxruns); i++)
|
|
|
|
{
|
|
|
|
indent ();
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("Run definition %i:\n", i);
|
2004-04-23 11:58:43 +01:00
|
|
|
runPrint (runPointerGet (sys, i));
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-31 15:31:06 +01:00
|
|
|
//! Determine whether a term is sent or claimed, but not read first in a roledef
|
2004-10-12 17:58:29 +01:00
|
|
|
/**
|
|
|
|
* @returns True iff the term occurs, and is sent/claimed first. If this returns true,
|
|
|
|
* we have to prefix a read.
|
|
|
|
*/
|
2004-09-20 13:40:01 +01:00
|
|
|
int
|
|
|
|
not_read_first (const Roledef rdstart, const Term t)
|
2004-08-31 15:31:06 +01:00
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = rdstart;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
if (termSubTerm (rd->message, t))
|
|
|
|
{
|
|
|
|
return (rd->type != READ);
|
|
|
|
}
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
2004-10-12 17:58:29 +01:00
|
|
|
/* this term is not read or sent explicitly, which is no problem */
|
|
|
|
/* So we signal we don't have to prefix a read */
|
2004-08-31 15:31:06 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Yield the agent name term in a role, for a run in the system.
|
|
|
|
/**
|
|
|
|
*@param sys The system.
|
|
|
|
*@param run The run in which we are interested.
|
|
|
|
*@param role The role of which we want to know the agent.
|
2004-04-23 11:58:43 +01:00
|
|
|
*/
|
|
|
|
Term
|
|
|
|
agentOfRunRole (const System sys, const int run, const Term role)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine != ARACHNE_ENGINE)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-02-21 15:12:59 +00:00
|
|
|
// Non-arachne
|
|
|
|
Termlist roles;
|
|
|
|
Termlist agents;
|
2005-05-01 14:32:50 +01:00
|
|
|
|
2005-02-21 15:12:59 +00:00
|
|
|
roles = sys->runs[run].protocol->rolenames;
|
|
|
|
agents = sys->runs[run].agents;
|
|
|
|
|
|
|
|
/* TODO stupid reversed order, lose that soon */
|
|
|
|
if (agents != NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-02-21 15:12:59 +00:00
|
|
|
agents = termlistForward (agents);
|
|
|
|
while (agents != NULL && roles != NULL)
|
2004-08-30 23:08:44 +01:00
|
|
|
{
|
2005-02-21 15:12:59 +00:00
|
|
|
if (isTermEqual (roles->term, role))
|
|
|
|
{
|
|
|
|
return agents->term;
|
|
|
|
}
|
|
|
|
agents = agents->prev;
|
|
|
|
roles = roles->next;
|
2004-08-30 23:08:44 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2005-02-21 15:12:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error
|
|
|
|
("Agent list for run %i is empty, so agentOfRunRole is not usable.",
|
|
|
|
run);
|
|
|
|
}
|
|
|
|
return NULL;
|
2004-08-30 23:08:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-21 15:12:59 +00:00
|
|
|
// Arachne engine
|
|
|
|
Termlist agents;
|
|
|
|
|
|
|
|
// Agent variables have the same symbol as the role names, so
|
|
|
|
// we can scan for this.
|
|
|
|
agents = sys->runs[run].agents;
|
|
|
|
while (agents != NULL)
|
|
|
|
{
|
|
|
|
Term agent;
|
|
|
|
|
|
|
|
agent = agents->term;
|
2005-05-01 14:32:50 +01:00
|
|
|
if (TermSymb (role) == TermSymb (agent))
|
2005-02-21 15:12:59 +00:00
|
|
|
{
|
|
|
|
return agent;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
agents = agents->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Yield the actor agent of a run in the system.
|
|
|
|
/**
|
|
|
|
*@param sys The system.
|
|
|
|
*@param run The run in which we are interested.
|
2004-04-23 11:58:43 +01:00
|
|
|
*/
|
|
|
|
Term
|
|
|
|
agentOfRun (const System sys, const int run)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
return agentOfRunRole (sys, run, sys->runs[run].role->nameterm);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-07-14 08:31:01 +01:00
|
|
|
/**
|
|
|
|
* A new run is created; now we want to know if it depends on any previous run.
|
|
|
|
* This occurs when there is a smaller runid with an identical protocol role, with the
|
|
|
|
* same agent pattern. However, there must be at least a variable in the pattern or no
|
|
|
|
* symmetry gains are to be made.
|
|
|
|
*
|
|
|
|
* Return -1 if there is no such symmetry.
|
|
|
|
*/
|
2004-08-09 11:05:58 +01:00
|
|
|
int
|
|
|
|
staticRunSymmetry (const System sys, const int rid)
|
2004-07-14 08:31:01 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
int ridSymm; // previous symmetrical run
|
|
|
|
Termlist agents; // list of agents for rid
|
|
|
|
Run runs; // shortcut usage
|
2004-07-14 08:31:01 +01:00
|
|
|
|
|
|
|
ridSymm = -1;
|
|
|
|
runs = sys->runs;
|
|
|
|
agents = runs[rid].agents;
|
|
|
|
while (agents != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
if (isTermVariable (agents->term))
|
|
|
|
ridSymm = rid - 1;
|
2004-07-14 08:31:01 +01:00
|
|
|
agents = agents->next;
|
|
|
|
}
|
|
|
|
/* there is no variable in this roledef, abort */
|
|
|
|
if (ridSymm == -1)
|
2004-08-09 11:05:58 +01:00
|
|
|
return -1;
|
2004-07-14 08:31:01 +01:00
|
|
|
|
|
|
|
agents = runs[rid].agents;
|
|
|
|
while (ridSymm >= 0)
|
|
|
|
{
|
|
|
|
/* compare protocol name, role name */
|
|
|
|
if (runs[ridSymm].protocol == runs[rid].protocol &&
|
2004-08-09 11:05:58 +01:00
|
|
|
runs[ridSymm].role == runs[rid].role)
|
2004-07-14 08:31:01 +01:00
|
|
|
{
|
|
|
|
/* same stuff */
|
|
|
|
int isEqual;
|
|
|
|
Termlist al, alSymm; // agent lists
|
|
|
|
|
|
|
|
isEqual = 1;
|
|
|
|
al = agents;
|
|
|
|
alSymm = runs[ridSymm].agents;
|
|
|
|
while (isEqual && al != NULL)
|
|
|
|
{
|
|
|
|
/* determine equality */
|
|
|
|
if (isTermVariable (al->term))
|
|
|
|
{
|
|
|
|
/* case 1: variable, should match type */
|
|
|
|
if (isTermVariable (alSymm->term))
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
if (!isTermlistEqual
|
|
|
|
(al->term->stype, alSymm->term->stype))
|
|
|
|
isEqual = 0;
|
2004-07-14 08:31:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isEqual = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* case 2: constant, should match */
|
|
|
|
if (!isTermEqual (al->term, alSymm->term))
|
2004-08-09 11:05:58 +01:00
|
|
|
isEqual = 0;
|
2004-07-14 08:31:01 +01:00
|
|
|
}
|
|
|
|
alSymm = alSymm->next;
|
|
|
|
al = al->next;
|
|
|
|
}
|
|
|
|
if (al == NULL && isEqual)
|
|
|
|
{
|
|
|
|
/* this candidate is allright */
|
2004-07-17 22:11:35 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-09 11:05:58 +01:00
|
|
|
warning ("Symmetry detection. #%i can depend on #%i.", rid,
|
|
|
|
ridSymm);
|
2004-07-17 22:11:35 +01:00
|
|
|
#endif
|
2004-07-14 08:31:01 +01:00
|
|
|
return ridSymm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ridSymm--;
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
return -1; // signal that no symmetrical run was found
|
2004-07-14 08:31:01 +01:00
|
|
|
}
|
|
|
|
|
2004-07-15 12:04:15 +01:00
|
|
|
//! Determine first read with variables besides agents
|
|
|
|
/**
|
|
|
|
*@todo For now, we assume it is simply the first read after the choose, if there is one.
|
|
|
|
*/
|
2004-08-09 11:05:58 +01:00
|
|
|
int
|
|
|
|
firstNonAgentRead (const System sys, int rid)
|
2004-07-15 12:04:15 +01:00
|
|
|
{
|
|
|
|
int step;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
if (sys->runs[rid].prevSymmRun == -1)
|
|
|
|
{
|
|
|
|
/* if there is no symmetrical run, then this doesn't apply at all */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
rd = sys->runs[rid].start;
|
|
|
|
step = 0;
|
|
|
|
while (rd != NULL && rd->internal && rd->type == READ) // assumes lazy LR eval
|
|
|
|
{
|
|
|
|
rd = rd->next;
|
|
|
|
step++;
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
if (rd != NULL && !rd->internal && rd->type == READ) // assumes lazy LR eval
|
2004-07-15 12:04:15 +01:00
|
|
|
{
|
2004-07-17 22:11:35 +01:00
|
|
|
#ifdef DEBUG
|
2004-08-09 11:05:58 +01:00
|
|
|
warning
|
|
|
|
("First read %i with dependency on symmetrical found in run %i.",
|
|
|
|
step, rid);
|
2004-07-17 22:11:35 +01:00
|
|
|
#endif
|
2004-07-15 12:04:15 +01:00
|
|
|
return step;
|
|
|
|
}
|
|
|
|
/* no such read */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-07-14 08:31:01 +01:00
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
/*************************************************
|
|
|
|
*
|
|
|
|
* Support code for roleInstance
|
|
|
|
*
|
|
|
|
*************************************************/
|
|
|
|
|
|
|
|
//! Prefix a read before a given run.
|
|
|
|
/**
|
|
|
|
* Maybe this simply needs integration in the role definitions. However, in practice it
|
|
|
|
* depends on the specific scenario. For Arachne it can thus depend on the roledef.
|
|
|
|
*
|
|
|
|
* Stores the (new) rd pointer in start and index
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
run_prefix_read (const System sys, const int run, Roledef rd,
|
|
|
|
const Term extterm)
|
|
|
|
{
|
|
|
|
/* prefix a read for such reads. TODO: this should also cover any external stuff */
|
|
|
|
if (extterm != NULL)
|
|
|
|
{
|
|
|
|
Roledef rdnew;
|
|
|
|
|
|
|
|
rdnew = roledefInit (READ, NULL, NULL, NULL, extterm, NULL);
|
|
|
|
/* this is an internal action! */
|
|
|
|
rdnew->internal = 1;
|
|
|
|
/* Store this new pointer */
|
|
|
|
rdnew->next = rd;
|
|
|
|
rd = rdnew;
|
|
|
|
/* mark the first real action */
|
|
|
|
sys->runs[run].firstReal++;
|
|
|
|
}
|
|
|
|
/* possibly shifted rd */
|
|
|
|
sys->runs[run].start = rd;
|
|
|
|
sys->runs[run].index = rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! Create a new local
|
|
|
|
/**
|
|
|
|
* Given a term, construct a new local term. Returns NULL if no such term was constructed.
|
|
|
|
*/
|
|
|
|
Term
|
|
|
|
create_new_local (const Term t, const int rid)
|
|
|
|
{
|
|
|
|
if (t != NULL && realTermLeaf (t))
|
|
|
|
{
|
|
|
|
Term newt;
|
|
|
|
|
2004-11-16 12:07:55 +00:00
|
|
|
newt = makeTermType (t->type, TermSymb (t), rid);
|
2004-09-20 13:40:01 +01:00
|
|
|
newt->stype = t->stype;
|
|
|
|
|
|
|
|
return newt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Localize run
|
|
|
|
/**
|
|
|
|
* Takes a run roledef list and substitutes fromlist into tolist terms.
|
|
|
|
* Furthermore, localizes all substitutions occurring in this, which termLocal
|
|
|
|
* does not. Any localized substitutions are stored as well in a list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
run_localize (const System sys, const int rid, Termlist fromlist,
|
|
|
|
Termlist tolist, Termlist substlist)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
rd = sys->runs[rid].start;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
2004-12-08 16:25:27 +00:00
|
|
|
rd->from = termLocal (rd->from, fromlist, tolist);
|
|
|
|
rd->to = termLocal (rd->to, fromlist, tolist);
|
|
|
|
rd->message = termLocal (rd->message, fromlist, tolist);
|
2004-09-20 13:40:01 +01:00
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
|
2004-12-08 16:25:27 +00:00
|
|
|
// Substlist is NULL currently? No usage of this last stuff now
|
|
|
|
// TODO
|
|
|
|
if (substlist != NULL)
|
|
|
|
{
|
|
|
|
error ("Substlist should be NULL in run_localize");
|
|
|
|
}
|
2004-09-20 13:40:01 +01:00
|
|
|
sys->runs[rid].substitutions = NULL;
|
|
|
|
while (substlist != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = substlist->term;
|
|
|
|
if (t->subst != NULL)
|
|
|
|
{
|
2004-12-08 16:25:27 +00:00
|
|
|
t->subst = termLocal (t->subst, fromlist, tolist);
|
2004-09-20 13:40:01 +01:00
|
|
|
sys->runs[rid].substitutions =
|
|
|
|
termlistAdd (sys->runs[rid].substitutions, t);
|
|
|
|
}
|
|
|
|
substlist = substlist->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Instantiate a role by making a new run for Arachne
|
2004-05-15 15:47:19 +01:00
|
|
|
/**
|
|
|
|
* This involves creation of a new run(id).
|
|
|
|
* Copy & subst of Roledef, Agent knowledge.
|
|
|
|
* Tolist might contain type constants.
|
2004-04-23 11:58:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2004-09-20 13:40:01 +01:00
|
|
|
roleInstanceArachne (const System sys, const Protocol protocol,
|
|
|
|
const Role role, const Termlist paramlist,
|
|
|
|
Termlist substlist)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int rid;
|
|
|
|
Run runs;
|
|
|
|
Roledef rd;
|
|
|
|
Termlist scanfrom, scanto;
|
2005-05-01 14:32:50 +01:00
|
|
|
Termlist fromlist = NULL; // deleted at the end
|
|
|
|
Termlist tolist = NULL; // -> .locals
|
|
|
|
Termlist artefacts = NULL; // -> .artefacts
|
|
|
|
Term extterm = NULL; // construction thing (will go to artefacts)
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* claim runid, allocate space */
|
|
|
|
rid = sys->maxruns;
|
2005-05-01 14:32:50 +01:00
|
|
|
ensureValidRun (sys, rid); // creates a new block
|
|
|
|
runs = sys->runs; // simple structure pointer transfer (shortcut)
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* duplicate roledef in buffer rd */
|
2004-12-08 16:41:43 +00:00
|
|
|
/* Notice that it is not stored (yet) in the run structure,
|
|
|
|
* and that termDuplicate is used internally
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
rd = roledefDuplicate (role->roledef);
|
|
|
|
|
2004-08-12 10:14:31 +01:00
|
|
|
/* set parameters */
|
2004-12-08 16:41:43 +00:00
|
|
|
/* generic setup of inherited stuff */
|
2004-08-12 10:14:31 +01:00
|
|
|
runs[rid].protocol = protocol;
|
|
|
|
runs[rid].role = role;
|
|
|
|
runs[rid].step = 0;
|
|
|
|
runs[rid].firstReal = 0;
|
|
|
|
|
2004-04-23 11:58:43 +01:00
|
|
|
/* scan for types in agent list */
|
|
|
|
/* scanners */
|
2004-09-20 13:40:01 +01:00
|
|
|
/**
|
|
|
|
* Because of pre-instantiation unification, some variables might already have been filled in.
|
|
|
|
* Ignore agent list; instead rely on role->variables.
|
|
|
|
*/
|
|
|
|
runs[rid].agents = NULL;
|
|
|
|
|
|
|
|
scanfrom = role->variables;
|
|
|
|
while (scanfrom != NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-09-20 13:40:01 +01:00
|
|
|
Term newt, oldt;
|
|
|
|
|
2004-12-08 16:41:43 +00:00
|
|
|
/* Some care has to be taken: after we use this instantiation, we might reset it.
|
|
|
|
* That is not strictly necessary: whoever set it first, is responsible for getting rid
|
|
|
|
* of it again.
|
|
|
|
*/
|
2004-09-20 13:40:01 +01:00
|
|
|
oldt = scanfrom->term;
|
2005-05-01 14:32:50 +01:00
|
|
|
newt = deVar (oldt);
|
2004-09-20 13:40:01 +01:00
|
|
|
if (realTermVariable (newt))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-12-08 16:41:43 +00:00
|
|
|
/* This is a variable of the role, that is not instantiated yet.
|
|
|
|
* Thus, it needs a local copy.
|
|
|
|
*/
|
2004-11-16 12:07:55 +00:00
|
|
|
newt = makeTermType (VARIABLE, TermSymb (newt), rid);
|
2004-09-20 13:40:01 +01:00
|
|
|
newt->stype = oldt->stype;
|
2004-12-09 15:45:14 +00:00
|
|
|
artefacts = termlistAddNew (artefacts, newt);
|
2004-09-20 13:40:01 +01:00
|
|
|
}
|
2004-12-08 19:30:26 +00:00
|
|
|
/* Now we add any role names to the agent list. Note that
|
|
|
|
* instantiations do not matter: because if the variable is
|
|
|
|
* instantiated, the rolename will be as well, and thus they will be
|
|
|
|
* equal anyway.
|
2004-12-08 16:41:43 +00:00
|
|
|
*/
|
2004-09-20 13:40:01 +01:00
|
|
|
if (inTermlist (protocol->rolenames, oldt))
|
|
|
|
{
|
2004-12-08 16:41:43 +00:00
|
|
|
/* Add the agent name or role variable... */
|
2004-10-28 13:33:57 +01:00
|
|
|
runs[rid].agents = termlistAppend (runs[rid].agents, newt);
|
2004-09-20 13:40:01 +01:00
|
|
|
|
|
|
|
if (isTermVariable (newt))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-12-29 16:05:32 +00:00
|
|
|
// It is a protocol role name
|
2005-05-01 14:32:50 +01:00
|
|
|
|
2004-12-29 16:05:32 +00:00
|
|
|
// Flag this
|
|
|
|
newt->roleVar = 1;
|
2005-01-14 18:18:40 +00:00
|
|
|
newt->stype = termlistAddNew (newt->stype, TERM_Agent);
|
2004-12-29 16:05:32 +00:00
|
|
|
|
|
|
|
// maybe add choose?
|
2004-09-20 13:40:01 +01:00
|
|
|
// Note that for anything but full type flaws, this is not an issue.
|
|
|
|
// In the POR reduction, force choose was the default. Here it is not.
|
2005-01-14 18:18:40 +00:00
|
|
|
/*
|
|
|
|
* [x]
|
|
|
|
* TODO currently disabled: something weird was goind on causing weird prunes,
|
|
|
|
* for match=2. Investigate later.
|
|
|
|
*/
|
2005-06-07 16:02:27 +01:00
|
|
|
if (0 && not_read_first (rd, oldt) && switches.match == 2)
|
2004-08-12 10:14:31 +01:00
|
|
|
{
|
|
|
|
/* this term is forced as a choose, or it does not occur in the (first) read event */
|
2004-08-31 15:31:06 +01:00
|
|
|
if (extterm == NULL)
|
|
|
|
{
|
2004-09-20 13:40:01 +01:00
|
|
|
extterm = newt;
|
2004-08-31 15:31:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-20 13:40:01 +01:00
|
|
|
extterm = makeTermTuple (newt, extterm);
|
2004-12-08 16:25:27 +00:00
|
|
|
// NOTE: don't these get double deleted? By roledefdestroy?
|
|
|
|
artefacts = termlistAddNew (artefacts, extterm);
|
2004-08-31 15:31:06 +01:00
|
|
|
}
|
2004-08-12 10:14:31 +01:00
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
2004-09-20 13:40:01 +01:00
|
|
|
fromlist = termlistAdd (fromlist, oldt);
|
|
|
|
tolist = termlistAdd (tolist, newt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
eprintf ("Created for run %i: ", rid);
|
|
|
|
termPrint (oldt);
|
|
|
|
eprintf (" -> ");
|
|
|
|
termPrint (newt);
|
|
|
|
eprintf ("\n");
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
scanfrom = scanfrom->next;
|
2004-07-15 14:32:09 +01:00
|
|
|
}
|
2004-08-12 10:14:31 +01:00
|
|
|
|
2004-12-08 19:30:26 +00:00
|
|
|
/* Now we prefix the read before rd, if extterm is not NULL. Even if
|
|
|
|
* extterm is NULL, rd is still set as the start and the index pointer of
|
|
|
|
* the run.
|
|
|
|
*/
|
2004-09-20 13:40:01 +01:00
|
|
|
run_prefix_read (sys, rid, rd, extterm);
|
2004-08-12 10:14:31 +01:00
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
/* duplicate all locals form this run */
|
|
|
|
scanto = role->locals;
|
|
|
|
while (scanto != NULL)
|
|
|
|
{
|
|
|
|
Term t = scanto->term;
|
|
|
|
if (!inTermlist (fromlist, t))
|
2004-08-12 10:14:31 +01:00
|
|
|
{
|
2004-09-20 13:40:01 +01:00
|
|
|
Term newt;
|
2004-08-12 10:14:31 +01:00
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
newt = create_new_local (t, rid);
|
|
|
|
if (newt != NULL)
|
2004-08-12 10:14:31 +01:00
|
|
|
{
|
2004-12-08 16:25:27 +00:00
|
|
|
artefacts = termlistAddNew (artefacts, newt);
|
2004-09-20 13:40:01 +01:00
|
|
|
if (realTermVariable (newt))
|
|
|
|
{
|
2004-12-09 15:45:14 +00:00
|
|
|
sys->variables = termlistAdd (sys->variables, newt);
|
2004-08-31 15:31:06 +01:00
|
|
|
}
|
2004-09-20 13:40:01 +01:00
|
|
|
fromlist = termlistAdd (fromlist, t);
|
|
|
|
tolist = termlistAdd (tolist, newt);
|
2004-08-15 17:08:53 +01:00
|
|
|
}
|
2004-08-12 10:14:31 +01:00
|
|
|
}
|
2004-09-20 13:40:01 +01:00
|
|
|
scanto = scanto->next;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
/* TODO this is not what we want yet, also local knowledge. The local
|
|
|
|
* knowledge (list?) also needs to be substituted on invocation. */
|
|
|
|
runs[rid].know = NULL;
|
2004-08-31 15:31:06 +01:00
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
/* now adjust the local run copy */
|
|
|
|
run_localize (sys, rid, fromlist, tolist, substlist);
|
|
|
|
|
|
|
|
termlistDelete (fromlist);
|
|
|
|
runs[rid].locals = tolist;
|
|
|
|
runs[rid].artefacts = artefacts;
|
|
|
|
|
|
|
|
/* erase any substitutions in the role definition, as they are now copied */
|
|
|
|
termlistSubstReset (role->variables);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! Instantiate a role by making a new run for the Modelchecker
|
|
|
|
/**
|
|
|
|
* This involves creation of a new run(id).
|
|
|
|
* Copy & subst of Roledef, Agent knowledge.
|
|
|
|
* Tolist might contain type constants.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
roleInstanceModelchecker (const System sys, const Protocol protocol,
|
|
|
|
const Role role, const Termlist paramlist,
|
|
|
|
Termlist substlist)
|
|
|
|
{
|
|
|
|
int rid;
|
|
|
|
Run runs;
|
|
|
|
Roledef rd;
|
|
|
|
Termlist scanfrom, scanto;
|
|
|
|
Termlist fromlist = NULL;
|
|
|
|
Termlist tolist = NULL;
|
|
|
|
Termlist artefacts = NULL;
|
|
|
|
Term extterm = NULL;
|
|
|
|
|
|
|
|
/* claim runid, allocate space */
|
|
|
|
rid = sys->maxruns;
|
|
|
|
ensureValidRun (sys, rid);
|
|
|
|
runs = sys->runs;
|
|
|
|
|
|
|
|
/* duplicate roledef in buffer rd */
|
|
|
|
rd = roledefDuplicate (role->roledef);
|
|
|
|
|
|
|
|
/* set parameters */
|
|
|
|
/* generic setup */
|
|
|
|
runs[rid].protocol = protocol;
|
|
|
|
runs[rid].role = role;
|
|
|
|
runs[rid].step = 0;
|
|
|
|
runs[rid].firstReal = 0;
|
|
|
|
|
|
|
|
/* scan for types in agent list */
|
|
|
|
/* scanners */
|
|
|
|
// Default engine adheres to scenario
|
|
|
|
scanfrom = protocol->rolenames;
|
|
|
|
scanto = paramlist;
|
|
|
|
while (scanfrom != NULL && scanto != NULL)
|
|
|
|
{
|
|
|
|
fromlist = termlistAdd (fromlist, scanfrom->term);
|
|
|
|
if (scanto->term->stype != NULL &&
|
|
|
|
inTermlist (scanto->term->stype, TERM_Type))
|
|
|
|
{
|
|
|
|
Term newvar;
|
|
|
|
|
|
|
|
/* There is a TYPE constant in the parameter list.
|
|
|
|
* Generate a new local variable for this run, with this type */
|
2004-11-16 12:07:55 +00:00
|
|
|
newvar = makeTermType (VARIABLE, TermSymb (scanfrom->term), rid);
|
2004-09-20 13:40:01 +01:00
|
|
|
artefacts = termlistAdd (artefacts, newvar);
|
|
|
|
sys->variables = termlistAdd (sys->variables, newvar);
|
|
|
|
newvar->stype = termlistAdd (NULL, scanto->term);
|
|
|
|
tolist = termlistAdd (tolist, newvar);
|
|
|
|
/* newvar is apparently new, but it might occur
|
|
|
|
* in the first event if it's a read, in which
|
|
|
|
* case we forget it */
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.forceChoose || not_read_first (rd, scanfrom->term))
|
2004-09-20 13:40:01 +01:00
|
|
|
{
|
|
|
|
/* this term is forced as a choose, or it does not occur in the (first) read event */
|
|
|
|
if (extterm == NULL)
|
|
|
|
{
|
|
|
|
extterm = newvar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
extterm = makeTermTuple (newvar, extterm);
|
|
|
|
artefacts = termlistAdd (artefacts, extterm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* not a type constant, add to list */
|
|
|
|
tolist = termlistAdd (tolist, scanto->term);
|
|
|
|
}
|
|
|
|
scanfrom = scanfrom->next;
|
|
|
|
scanto = scanto->next;
|
2004-08-31 15:31:06 +01:00
|
|
|
}
|
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
/* set agent list */
|
|
|
|
runs[rid].agents = termlistDuplicate (tolist);
|
|
|
|
|
|
|
|
run_prefix_read (sys, rid, rd, extterm);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* duplicate all locals form this run */
|
|
|
|
scanto = role->locals;
|
|
|
|
while (scanto != NULL)
|
|
|
|
{
|
|
|
|
Term t = scanto->term;
|
|
|
|
if (!inTermlist (fromlist, t))
|
|
|
|
{
|
2004-09-20 13:40:01 +01:00
|
|
|
Term newt;
|
|
|
|
|
|
|
|
newt = create_new_local (t, rid);
|
|
|
|
if (newt != NULL)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-10 16:02:37 +01:00
|
|
|
artefacts = termlistAdd (artefacts, newt);
|
2004-04-23 11:58:43 +01:00
|
|
|
if (realTermVariable (newt))
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
sys->variables = termlistAdd (sys->variables, newt);
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
fromlist = termlistAdd (fromlist, t);
|
|
|
|
tolist = termlistAdd (tolist, newt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scanto = scanto->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO this is not what we want yet, also local knowledge. The local
|
|
|
|
* knowledge (list?) also needs to be substituted on invocation. */
|
2004-09-20 13:40:01 +01:00
|
|
|
runs[rid].know = knowledgeDuplicate (sys->know);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* now adjust the local run copy */
|
2004-09-20 13:40:01 +01:00
|
|
|
run_localize (sys, rid, fromlist, tolist, substlist);
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
termlistDelete (fromlist);
|
2004-05-13 11:06:21 +01:00
|
|
|
runs[rid].locals = tolist;
|
2004-08-10 16:02:37 +01:00
|
|
|
runs[rid].artefacts = artefacts;
|
2004-07-14 08:31:01 +01:00
|
|
|
|
2004-08-12 10:28:50 +01:00
|
|
|
/* erase any substitutions in the role definition, as they are now copied */
|
|
|
|
termlistSubstReset (role->variables);
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine == POR_ENGINE)
|
2004-08-13 11:28:20 +01:00
|
|
|
{
|
|
|
|
/* Determine symmetric run */
|
|
|
|
runs[rid].prevSymmRun = staticRunSymmetry (sys, rid); // symmetry reduction static analysis
|
2004-07-15 12:04:15 +01:00
|
|
|
|
2004-08-13 11:28:20 +01:00
|
|
|
/* Determine first read with variables besides agents */
|
|
|
|
runs[rid].firstNonAgentRead = firstNonAgentRead (sys, rid); // symmetry reduction type II
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-09-20 13:40:01 +01:00
|
|
|
//! Instantiate a role by making a new run
|
|
|
|
/**
|
|
|
|
* Generic splitter. Splits into the arachne version, or the modelchecker version.
|
|
|
|
*
|
|
|
|
* This involves creation of a new run(id).
|
|
|
|
* Copy & subst of Roledef, Agent knowledge.
|
|
|
|
* Tolist might contain type constants.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
roleInstance (const System sys, const Protocol protocol, const Role role,
|
|
|
|
const Termlist paramlist, Termlist substlist)
|
|
|
|
{
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine == ARACHNE_ENGINE)
|
2004-09-20 13:40:01 +01:00
|
|
|
{
|
|
|
|
roleInstanceArachne (sys, protocol, role, paramlist, substlist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
roleInstanceModelchecker (sys, protocol, role, paramlist, substlist);
|
|
|
|
}
|
|
|
|
}
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-10 16:02:37 +01:00
|
|
|
//! Destroy roleInstance
|
|
|
|
/**
|
|
|
|
* Destroys the run with the highest index number
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
roleInstanceDestroy (const System sys)
|
|
|
|
{
|
2004-08-13 15:35:22 +01:00
|
|
|
if (sys->maxruns > 0)
|
2004-08-10 16:02:37 +01:00
|
|
|
{
|
2004-08-13 15:35:22 +01:00
|
|
|
int runid;
|
2004-08-10 16:02:37 +01:00
|
|
|
struct run myrun;
|
2004-08-15 20:58:26 +01:00
|
|
|
Termlist substlist;
|
2004-08-10 16:02:37 +01:00
|
|
|
|
2004-08-13 15:35:22 +01:00
|
|
|
runid = sys->maxruns - 1;
|
2004-08-10 16:02:37 +01:00
|
|
|
myrun = sys->runs[runid];
|
|
|
|
|
|
|
|
// Destroy roledef
|
|
|
|
roledefDestroy (myrun.start);
|
2004-08-12 10:14:31 +01:00
|
|
|
|
2004-08-10 16:02:37 +01:00
|
|
|
// Destroy artefacts
|
2005-10-08 20:53:10 +01:00
|
|
|
//
|
|
|
|
// sys->variables might contain locals from the run: remove them
|
|
|
|
{
|
|
|
|
Termlist tl;
|
|
|
|
|
|
|
|
tl = sys->variables;
|
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = tl->term;
|
|
|
|
if (realTermLeaf (t) && TermRunid (t) == runid)
|
|
|
|
{
|
|
|
|
Termlist tlnext;
|
|
|
|
|
|
|
|
tlnext = tl->next;
|
|
|
|
// remove from list; return pointer to head
|
|
|
|
sys->variables = termlistDelTerm (tl);
|
|
|
|
tl = tlnext;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// proceed
|
|
|
|
tl = tl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-10 16:02:37 +01:00
|
|
|
/*
|
|
|
|
* Arachne does real-time reduction of memory, POR does not
|
|
|
|
* Artefact removal can only be done if knowledge sets are empty, as with Arachne
|
|
|
|
*/
|
2005-06-07 16:02:27 +01:00
|
|
|
if (switches.engine == ARACHNE_ENGINE)
|
2004-08-10 16:02:37 +01:00
|
|
|
{
|
2004-08-12 10:14:31 +01:00
|
|
|
Termlist artefacts;
|
2004-08-10 16:02:37 +01:00
|
|
|
// Remove artefacts
|
2004-08-11 09:17:49 +01:00
|
|
|
artefacts = myrun.artefacts;
|
2004-08-10 16:02:37 +01:00
|
|
|
while (artefacts != NULL)
|
|
|
|
{
|
2004-08-11 09:17:49 +01:00
|
|
|
memFree (artefacts->term, sizeof (struct term));
|
2004-08-10 16:02:37 +01:00
|
|
|
artefacts = artefacts->next;
|
|
|
|
}
|
|
|
|
}
|
2004-08-15 20:58:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Undo the local copies of the substitutions. We cannot restore them however, so this might
|
|
|
|
* prove a problem. We assume that the substlist fixes this at roleInstance time; it should be exact.
|
|
|
|
*/
|
|
|
|
substlist = myrun.substitutions;
|
|
|
|
while (substlist != NULL)
|
|
|
|
{
|
|
|
|
Term t;
|
|
|
|
|
|
|
|
t = substlist->term;
|
|
|
|
if (t->subst != NULL)
|
|
|
|
{
|
|
|
|
termDelete (t->subst);
|
|
|
|
t->subst = NULL;
|
|
|
|
}
|
|
|
|
substlist = substlist->next;
|
|
|
|
}
|
2005-05-01 14:32:50 +01:00
|
|
|
termlistDelete (myrun.substitutions);
|
2004-12-08 16:25:27 +00:00
|
|
|
|
|
|
|
// remove lists
|
2004-08-12 10:14:31 +01:00
|
|
|
termlistDelete (myrun.artefacts);
|
|
|
|
termlistDelete (myrun.locals);
|
|
|
|
termlistDelete (myrun.agents);
|
2004-12-08 16:25:27 +00:00
|
|
|
|
2004-08-10 16:02:37 +01:00
|
|
|
// Destroy run struct allocation in array using realloc
|
|
|
|
// Reduce run count
|
2004-12-08 16:25:27 +00:00
|
|
|
sys->maxruns = sys->maxruns - 1;
|
2005-05-01 14:32:50 +01:00
|
|
|
sys->runs =
|
|
|
|
(Run) memRealloc (sys->runs, sizeof (struct run) * (sys->maxruns));
|
2004-08-10 16:02:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Initialise the second system phase.
|
|
|
|
/**
|
|
|
|
* Allocates memory for traces.
|
|
|
|
* The number of runs has to be known for this procedure.
|
|
|
|
*\sa systemInit()
|
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
void
|
2004-07-20 13:41:56 +01:00
|
|
|
systemStart (const System sys)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
int i, s;
|
|
|
|
Roledef rd;
|
|
|
|
|
|
|
|
s = 0;
|
|
|
|
for (i = 0; i < sys->maxruns; i++)
|
|
|
|
{
|
|
|
|
rd = runPointerGet (sys, i);
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
s++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the maximum trace length */
|
|
|
|
if (sys->maxtracelength > s)
|
|
|
|
sys->maxtracelength = s;
|
|
|
|
|
|
|
|
/* trace gets one added entry for buffer */
|
|
|
|
s = sys->maxtracelength + 1;
|
|
|
|
|
|
|
|
/* freed in systemDone */
|
|
|
|
sys->traceEvent = memAlloc (s * sizeof (Roledef));
|
|
|
|
sys->traceRun = memAlloc (s * sizeof (int));
|
|
|
|
sys->traceKnow = memAlloc (s * sizeof (Knowledge));
|
2004-07-21 11:35:39 +01:00
|
|
|
sys->traceNode = memAlloc (s * sizeof (states_t));
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
/* clear, for niceties */
|
|
|
|
for (i = 0; i < s; i++)
|
|
|
|
{
|
|
|
|
sys->traceEvent[i] = NULL;
|
|
|
|
sys->traceRun[i] = 0;
|
|
|
|
sys->traceKnow[i] = NULL;
|
2004-07-21 11:35:39 +01:00
|
|
|
sys->traceNode[i] = STATES0;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Activate indenting.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
indentActivate ()
|
|
|
|
{
|
|
|
|
indentState = 1;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Set indent depth.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
indentSet (int i)
|
|
|
|
{
|
|
|
|
if (indentState)
|
|
|
|
indentDepth = i;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print the prefix of a line suitable for the current indent level.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
indent ()
|
|
|
|
{
|
|
|
|
int i = indentDepth;
|
|
|
|
int j = 0;
|
|
|
|
while (i > 0)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("%i ", j);
|
2004-04-23 11:58:43 +01:00
|
|
|
i--;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Create an empty protocol structure with a name.
|
2004-04-23 11:58:43 +01:00
|
|
|
Protocol
|
|
|
|
protocolCreate (Term name)
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
p = memAlloc (sizeof (struct protocol));
|
|
|
|
p->nameterm = name;
|
|
|
|
p->roles = NULL;
|
2004-08-12 14:22:49 +01:00
|
|
|
p->rolenames = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
p->locals = NULL;
|
2004-08-12 14:22:49 +01:00
|
|
|
p->next = NULL;
|
2004-04-23 11:58:43 +01:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print all local terms in a term list.
|
2004-07-24 16:05:20 +01:00
|
|
|
//@todo What is this doing here? This should be in termlists.c!
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
locVarPrint (Termlist tl)
|
|
|
|
{
|
|
|
|
if (tl == NULL)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("No local terms.\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("Local terms: ");
|
|
|
|
eprintf ("[");
|
2004-04-23 11:58:43 +01:00
|
|
|
while (tl != NULL)
|
|
|
|
{
|
|
|
|
termPrint (tl->term);
|
|
|
|
if (tl->term->stype != NULL)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (":");
|
2004-04-23 11:58:43 +01:00
|
|
|
termlistPrint (tl->term->stype);
|
|
|
|
}
|
|
|
|
tl = tl->next;
|
|
|
|
if (tl != NULL)
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (",");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("]");
|
|
|
|
eprintf ("\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print a protocol.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
protocolPrint (Protocol p)
|
|
|
|
{
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
indent ();
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("[[Protocol : ");
|
2004-04-23 11:58:43 +01:00
|
|
|
termPrint (p->nameterm);
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (" (");
|
2004-04-23 11:58:43 +01:00
|
|
|
termlistPrint (p->rolenames);
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (")]]\n");
|
2004-04-23 11:58:43 +01:00
|
|
|
locVarPrint (p->locals);
|
|
|
|
rolesPrint (p->roles);
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Print a list of protocols.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
protocolsPrint (Protocol p)
|
|
|
|
{
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
protocolPrint (p);
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-01 14:25:54 +01:00
|
|
|
//! Determine whether an agent term is trusted
|
|
|
|
/**
|
|
|
|
* 1 (True) means trusted, 0 is untrusted
|
|
|
|
*/
|
2005-08-15 13:49:32 +01:00
|
|
|
int
|
2005-07-01 14:25:54 +01:00
|
|
|
isAgentTrusted (const System sys, Term agent)
|
|
|
|
{
|
|
|
|
agent = deVar (agent);
|
|
|
|
if (!realTermVariable (agent) && inTermlist (sys->untrusted, agent))
|
|
|
|
{
|
|
|
|
// Untrusted agent in the list
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Determine whether there is an untrusted agent.
|
|
|
|
/**
|
2005-07-01 14:25:54 +01:00
|
|
|
*@return True iff all agent in the list are trusted.
|
2004-05-15 15:47:19 +01:00
|
|
|
*/
|
2004-04-23 11:58:43 +01:00
|
|
|
int
|
2005-07-01 14:25:54 +01:00
|
|
|
isAgentlistTrusted (const System sys, Termlist agents)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
|
|
|
while (agents != NULL)
|
|
|
|
{
|
2005-07-01 14:25:54 +01:00
|
|
|
if (!isAgentTrusted (sys, agents->term))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-07-01 14:25:54 +01:00
|
|
|
return 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2005-07-01 14:25:54 +01:00
|
|
|
agents = agents->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Determine whether all agents of a run are trusted
|
|
|
|
/**
|
|
|
|
* Returns 0 (False) if they are not trusted, otherwise 1 (True)
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isRunTrusted (const System sys, const int run)
|
|
|
|
{
|
|
|
|
if (run >= 0 && run < sys->maxruns)
|
|
|
|
{
|
|
|
|
if (!isAgentlistTrusted (sys, sys->runs[run].agents))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2005-07-01 14:25:54 +01:00
|
|
|
return 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
2005-07-01 14:25:54 +01:00
|
|
|
return 1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Yield the maximum length of a trace by analysing the runs in the system.
|
2004-04-23 11:58:43 +01:00
|
|
|
int
|
|
|
|
getMaxTraceLength (const System sys)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int maxlen;
|
|
|
|
int run;
|
|
|
|
|
|
|
|
maxlen = 0;
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
rd = runPointerGet (sys, run);
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
rd = rd->next;
|
|
|
|
maxlen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return maxlen;
|
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Nicely format the role and agents we think we're talking to.
|
2004-04-23 11:58:43 +01:00
|
|
|
void
|
|
|
|
agentsOfRunPrint (const System sys, const int run)
|
|
|
|
{
|
|
|
|
Term role = sys->runs[run].role->nameterm;
|
|
|
|
Termlist roles = sys->runs[run].protocol->rolenames;
|
2004-10-28 13:33:57 +01:00
|
|
|
int notfirst;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
termPrint (role);
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (":");
|
|
|
|
termPrint (agentOfRunRole (sys, run, role));
|
|
|
|
eprintf (" (");
|
|
|
|
notfirst = 0;
|
2004-04-23 11:58:43 +01:00
|
|
|
while (roles != NULL)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
if (!isTermEqual (role, roles->term))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
if (notfirst)
|
2004-11-16 12:07:55 +00:00
|
|
|
eprintf (", ");
|
2004-10-28 13:33:57 +01:00
|
|
|
termPrint (roles->term);
|
|
|
|
eprintf (":");
|
|
|
|
termPrint (agentOfRunRole (sys, run, roles->term));
|
|
|
|
notfirst = 1;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-10-28 13:33:57 +01:00
|
|
|
roles = roles->next;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf (")");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Explain a violated claim at point i in the trace.
|
2004-04-23 11:58:43 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
violatedClaimPrint (const System sys, const int i)
|
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("Claim stuk");
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
|
2004-05-15 15:47:19 +01:00
|
|
|
//! Yield the real length of an attack.
|
|
|
|
/**
|
|
|
|
* AttackLength yields the real (user friendly) length of an attack by omitting
|
2004-04-23 11:58:43 +01:00
|
|
|
* the redundant events but also the choose events.
|
|
|
|
*/
|
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
int
|
|
|
|
attackLength (struct tracebuf *tb)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
int len, i;
|
2004-04-23 11:58:43 +01:00
|
|
|
|
2004-08-09 11:05:58 +01:00
|
|
|
len = 0;
|
|
|
|
i = 0;
|
|
|
|
while (i < tb->length)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
if (tb->status[i] != S_RED)
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
/* apparently not redundant */
|
|
|
|
if (!(tb->event[i]->type == READ && tb->event[i]->internal))
|
2004-04-23 11:58:43 +01:00
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
/* and no internal read, so it counts */
|
|
|
|
len++;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
i++;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
return len;
|
2004-04-23 11:58:43 +01:00
|
|
|
}
|
2004-06-16 11:39:13 +01:00
|
|
|
|
2004-07-26 13:43:19 +01:00
|
|
|
void
|
2005-06-07 16:02:27 +01:00
|
|
|
commandlinePrint (FILE * stream)
|
2004-07-26 13:43:19 +01:00
|
|
|
{
|
|
|
|
/* print command line */
|
|
|
|
int i;
|
|
|
|
|
2005-06-07 16:02:27 +01:00
|
|
|
for (i = 0; i < switches.argc; i++)
|
|
|
|
fprintf (stream, " %s", switches.argv[i]);
|
2004-07-26 13:43:19 +01:00
|
|
|
}
|
|
|
|
|
2004-06-16 11:39:13 +01:00
|
|
|
//! Get the number of roles in the system.
|
2004-08-09 11:05:58 +01:00
|
|
|
int
|
|
|
|
compute_rolecount (const System sys)
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
|
|
|
Protocol pr;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
pr = sys->protocols;
|
|
|
|
while (pr != NULL)
|
|
|
|
{
|
2004-08-09 11:05:58 +01:00
|
|
|
n = n + termlistLength (pr->rolenames);
|
2004-06-16 11:39:13 +01:00
|
|
|
pr = pr->next;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Compute the maximum number of events in a single role in the system.
|
2004-08-09 11:05:58 +01:00
|
|
|
int
|
|
|
|
compute_roleeventmax (const System sys)
|
2004-06-16 11:39:13 +01:00
|
|
|
{
|
|
|
|
Protocol pr;
|
|
|
|
int maxev;
|
|
|
|
|
|
|
|
maxev = 0;
|
|
|
|
pr = sys->protocols;
|
|
|
|
while (pr != NULL)
|
|
|
|
{
|
|
|
|
Role r;
|
|
|
|
|
|
|
|
r = pr->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
Roledef rd;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
rd = r->roledef;
|
|
|
|
n = 0;
|
|
|
|
while (rd != NULL)
|
|
|
|
{
|
|
|
|
n++;
|
|
|
|
rd = rd->next;
|
|
|
|
}
|
2004-08-09 11:05:58 +01:00
|
|
|
if (n > maxev)
|
|
|
|
maxev = n;
|
2004-06-16 11:39:13 +01:00
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
pr = pr->next;
|
|
|
|
}
|
|
|
|
return maxev;
|
|
|
|
}
|
2004-07-28 12:39:08 +01:00
|
|
|
|
|
|
|
//! Print the role, agents of a run
|
|
|
|
void
|
|
|
|
runInstancePrint (const System sys, const int run)
|
|
|
|
{
|
2004-07-29 12:15:07 +01:00
|
|
|
termPrint (sys->runs[run].role->nameterm);
|
2004-07-28 12:39:08 +01:00
|
|
|
termlistPrint (sys->runs[run].agents);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Print an instantiated scenario (chooses and such)
|
|
|
|
void
|
|
|
|
scenarioPrint (const System sys)
|
|
|
|
{
|
|
|
|
int run;
|
|
|
|
|
|
|
|
for (run = 0; run < sys->maxruns; run++)
|
|
|
|
{
|
|
|
|
runInstancePrint (sys, run);
|
2004-07-29 12:15:07 +01:00
|
|
|
if (run < sys->maxruns - 1)
|
2004-07-28 12:39:08 +01:00
|
|
|
{
|
2004-10-28 13:33:57 +01:00
|
|
|
eprintf ("\t");
|
2004-07-28 12:39:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-08-12 10:14:31 +01:00
|
|
|
|
|
|
|
//! Iterate over all roles (AND)
|
|
|
|
/**
|
|
|
|
* Function called gets (sys,protocol,role)
|
|
|
|
* If it returns 0, iteration aborts.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
system_iterate_roles (const System sys, int (*func) ())
|
|
|
|
{
|
|
|
|
Protocol p;
|
|
|
|
|
|
|
|
p = sys->protocols;
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
Role r;
|
|
|
|
|
|
|
|
r = p->roles;
|
|
|
|
while (r != NULL)
|
|
|
|
{
|
|
|
|
if (!func (sys, p, r))
|
|
|
|
return 0;
|
|
|
|
r = r->next;
|
|
|
|
}
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2005-07-01 14:25:54 +01:00
|
|
|
|
2005-08-15 13:49:32 +01:00
|
|
|
//! Determine whether we don't need any more attacks
|
|
|
|
/**
|
|
|
|
* Returns 1 (true) iff no more attacks are needed.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
enoughAttacks (const System sys)
|
|
|
|
{
|
|
|
|
if (switches.maxAttacks != 0)
|
|
|
|
{
|
|
|
|
if (sys->attackid >= switches.maxAttacks)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|