- Implemented ordering checks. Need some test to validate this though.

This commit is contained in:
ccremers 2004-08-27 19:06:15 +00:00
parent 957b920b98
commit 4f534410bd
3 changed files with 166 additions and 78 deletions

View File

@ -4,12 +4,14 @@
#include "list.h" #include "list.h"
#include "role.h" #include "role.h"
#include "label.h"
#include "system.h" #include "system.h"
#include "binding.h" #include "binding.h"
#include "warshall.h" #include "warshall.h"
#include "memory.h" #include "memory.h"
#include "debug.h" #include "debug.h"
#include "term.h" #include "term.h"
#include "termmap.h"
static System sys; static System sys;
static int *graph; static int *graph;
@ -342,6 +344,58 @@ goal_unbind (const Binding b)
} }
} }
//! Determine whether some label set is ordered w.r.t. send/read order.
/**
* Assumes all these labels exist in the system, within length etc, and that the run mappings are valid.
*/
int
labels_ordered (Termmap runs, Termlist labels)
{
goal_graph_create ();
while (labels != NULL)
{
// Given this label, and the mapping of runs, we want to know if the order is okay. Thus, we need to know sendrole and readrole
Labelinfo linfo;
int send_run, send_ev, read_run, read_ev;
int get_index (const int run)
{
Roledef rd;
int i;
i = 0;
rd = sys->runs[run].start;
while (rd != NULL && !isTermEqual (rd->label, labels->term))
{
rd = rd->next;
i++;
}
#ifdef DEBUG
if (rd == NULL)
error
("Could not locate send or read for label, after niagree holds, to test for order.");
#endif
return i;
}
linfo = label_find (sys->labellist, labels->term);
send_run = termmapGet (runs, linfo->sendrole);
read_run = termmapGet (runs, linfo->readrole);
send_ev = get_index (send_run);
read_ev = get_index (read_run);
if (graph[graph_nodes (nodes, send_run, send_ev, read_run, read_ev)] ==
0)
{
// Not ordered; false
return 0;
}
// Proceed
labels = labels->next;
}
return 1;
}
//! Prune invalid state w.r.t. <=C minimal requirement //! Prune invalid state w.r.t. <=C minimal requirement
/** /**
* Intuition says this can be done a lot more efficient. Luckily this is the prototype. * Intuition says this can be done a lot more efficient. Luckily this is the prototype.

View File

@ -2,6 +2,7 @@
#define BINDINGS #define BINDINGS
#include "term.h" #include "term.h"
#include "termmap.h"
#include "system.h" #include "system.h"
/* /*
@ -41,6 +42,7 @@ void goal_add (Term term, const int run, const int ev, const int level);
void goal_remove_last (); void goal_remove_last ();
int goal_bind (const Binding b, const int run, const int ev); int goal_bind (const Binding b, const int run, const int ev);
void goal_unbind (const Binding b); void goal_unbind (const Binding b);
int labels_ordered (Termmap runs, Termlist labels);
int bindings_c_minimal (); int bindings_c_minimal ();

View File

@ -4,6 +4,7 @@
#include "label.h" #include "label.h"
#include "error.h" #include "error.h"
#include "debug.h" #include "debug.h"
#include "binding.h"
#define MATCH_NONE 0 #define MATCH_NONE 0
#define MATCH_ORDER 1 #define MATCH_ORDER 1
@ -475,7 +476,8 @@ check_claim_niagree (const System sys, const int i)
//! Check generic agree claim for a given set of runs, arachne style //! Check generic agree claim for a given set of runs, arachne style
int arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs) int
arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs)
{ {
Termlist labels; Termlist labels;
int flag; int flag;
@ -499,48 +501,48 @@ int arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs
Labelinfo linfo; Labelinfo linfo;
Roledef get_label_event (const Term role, const Term label) Roledef get_label_event (const Term role, const Term label)
{ {
Roledef rd, rd_res; Roledef rd, rd_res;
int i; int i;
int run; int run;
run = termmapGet (runs, role); run = termmapGet (runs, role);
#ifdef DEBUG #ifdef DEBUG
if (run < 0 || run >= sys->maxruns ) if (run < 0 || run >= sys->maxruns)
{ {
globalError++; globalError++;
eprintf ("Run mapping %i out of bounds for role ", run); eprintf ("Run mapping %i out of bounds for role ", run);
termPrint (role); termPrint (role);
eprintf (" and label "); eprintf (" and label ");
termPrint (label); termPrint (label);
eprintf ("\n"); eprintf ("\n");
eprintf ("This label has sendrole "); eprintf ("This label has sendrole ");
termPrint (linfo->sendrole); termPrint (linfo->sendrole);
eprintf (" and readrole "); eprintf (" and readrole ");
termPrint (linfo->readrole); termPrint (linfo->readrole);
eprintf ("\n"); eprintf ("\n");
globalError--; globalError--;
error ("Run mapping is out of bounds."); error ("Run mapping is out of bounds.");
} }
#endif #endif
rd = sys->runs[run].start; rd = sys->runs[run].start;
rd_res = NULL; rd_res = NULL;
i = 0; i = 0;
while (i < sys->runs[run].step && rd != NULL) while (i < sys->runs[run].step && rd != NULL)
{ {
if (isTermEqual (rd->label, label)) if (isTermEqual (rd->label, label))
{ {
rd_res = rd; rd_res = rd;
rd = NULL; rd = NULL;
} }
else else
{ {
rd = rd->next; rd = rd->next;
} }
i++; i++;
} }
return rd_res; return rd_res;
} }
// Main // Main
linfo = label_find (sys->labellist, labels->term); linfo = label_find (sys->labellist, labels->term);
@ -567,12 +569,14 @@ int arachne_runs_agree (const System sys, const Claimlist cl, const Termmap runs
return flag; return flag;
} }
//! Check arachne agreement claim //! Check arachne authentications claim
/** /**
* Per default, occurs in run 0, but for generality we have left the run parameter in. * Per default, occurs in run 0, but for generality we have left the run parameter in.
*@returns 1 if the claim is true, 0 if it is not. *@returns 1 if the claim is true, 0 if it is not.
*/ */
int arachne_claim_niagree (const System sys, const int claim_run, const int claim_index) int
arachne_claim_authentications (const System sys, const int claim_run,
const int claim_index, const int require_order)
{ {
Claimlist cl; Claimlist cl;
Roledef rd; Roledef rd;
@ -580,38 +584,57 @@ int arachne_claim_niagree (const System sys, const int claim_run, const int clai
int flag; int flag;
int fill_roles (Termlist roles_tofill) int fill_roles (Termlist roles_tofill)
{ {
if (roles_tofill == NULL) if (roles_tofill == NULL)
{ {
// All roles have been chosen // All roles have been chosen
return arachne_runs_agree (sys, cl, runs_involved); if (arachne_runs_agree (sys, cl, runs_involved))
} {
else // niagree holds
{ if (!require_order)
// Choose a run for this role, if possible {
// Note that any will do return 1;
int run, flag; }
else
{
// Stronger claim: nisynch. Test for ordering as well.
return labels_ordered (runs_involved, cl->prec);
}
}
else
{
// niagree does not hold
return 0;
}
}
else
{
// Choose a run for this role, if possible
// Note that any will do
int run, flag;
run = 0; run = 0;
flag = 0; flag = 0;
while (run < sys->maxruns) while (run < sys->maxruns)
{ {
// Has to be from the right protocol // Has to be from the right protocol
if (sys->runs[run].protocol == cl->protocol) if (sys->runs[run].protocol == cl->protocol)
{ {
// Has to be the right name // Has to be the right name
if (isTermEqual (sys->runs[run].role->nameterm, roles_tofill->term)) if (isTermEqual
{ (sys->runs[run].role->nameterm, roles_tofill->term))
// Choose, iterate {
runs_involved = termmapSet (runs_involved, roles_tofill->term, run); // Choose, iterate
flag = flag || fill_roles (roles_tofill->next); runs_involved =
} termmapSet (runs_involved, roles_tofill->term, run);
} flag = flag || fill_roles (roles_tofill->next);
run++; }
} }
return flag; run++;
} }
} return flag;
}
}
#ifdef DEBUG #ifdef DEBUG
if (DEBUGL (5)) if (DEBUGL (5))
@ -623,7 +646,7 @@ int arachne_claim_niagree (const System sys, const int claim_run, const int clai
rd = roledef_shift (sys->runs[claim_run].start, claim_index); rd = roledef_shift (sys->runs[claim_run].start, claim_index);
#ifdef DEBUG #ifdef DEBUG
if (rd == NULL) if (rd == NULL)
error ("Retrieving claim info for NULL node??"); error ("Retrieving claim info for NULL node??");
#endif #endif
cl = rd->claiminfo; cl = rd->claiminfo;
@ -634,9 +657,18 @@ int arachne_claim_niagree (const System sys, const int claim_run, const int clai
return flag; return flag;
} }
//! Test nisynch //! Test niagree
int arachne_claim_nisynch (const System sys, const int claim_run, const int claim_index) int
arachne_claim_niagree (const System sys, const int claim_run,
const int claim_index)
{ {
//!@todo For now, only agreement claim return arachne_claim_authentications (sys, claim_run, claim_index, 0);
return arachne_claim_niagree (sys, claim_run, claim_index); }
//! Test nisynch
int
arachne_claim_nisynch (const System sys, const int claim_run,
const int claim_index)
{
return arachne_claim_authentications (sys, claim_run, claim_index, 1);
} }