Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions bayonet.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import file=std.file;
import lexer, parser, expression, declaration, error, util;
import scope_, semantic_;

enum OutputType { PSI, PRISM, PRISM_DET }

string getActualPath(string path){
// TODO: search path
auto ext = path.extension;
Expand All @@ -16,12 +18,12 @@ string readCode(File f){
auto app=mallocAppender!(char[])();
foreach(r;f.byChunk(1024)){app.put(cast(char[])r);}
app.put("\0\0\0\0"); // insert 4 padding zero bytes
return cast(string)app.data;
return cast(string)app.data;
}
string readCode(string path){ return readCode(File(path)); }


int run(string path){
int run(string path, OutputType ot){
path = getActualPath(path);
auto ext = path.extension;
if(ext != ".bayonet"){
Expand All @@ -41,8 +43,18 @@ int run(string path){
program=semantic(src,program,new TopScope(err));
//writeln(program);
if(!err.nerrors){
import translate_;
writeln(translate(program,new Builder()));
if(ot==OutputType.PSI){
import translate_;
writeln(translate(program,new Builder()));
}else if(ot==OutputType.PRISM){
import translate_prism;
writeln(translate(program,new Builder()));
}else if(ot==OutputType.PRISM_DET){
import translate_prism_deterministic;
writeln(translate(program,new Builder()));
}else{
assert(0);
}
}
return !!err.nerrors;
}
Expand All @@ -56,8 +68,26 @@ int main(string[] args){
}
args.popFront();
args.sort!((a,b)=>a.startsWith("--")>b.startsWith("--"));
OutputType ot = OutputType.PSI;
bool otSet = false;
foreach(x;args){
if(auto r=run(x)) return r;
if(x=="--psi" || x=="--prism" || x=="--prism-det"){
if(otSet){
stderr.writeln("error: output type already set");
return 1;
}
if(x=="--psi")
ot = OutputType.PSI;
else if(x=="--prism")
ot = OutputType.PRISM;
else if(x=="--prism-det")
ot = OutputType.PRISM_DET;
else
assert(0);
otSet = true;
continue;
}
if(auto r=run(x,ot)) return r;
}
return 0;
}
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ else
fi

# debug build
$DMD -g -debug bayonet.d declaration.d error.d expression.d lexer.d parser.d scope_.d semantic_.d terminal.d translate_.d util.d -ofbayonet
$DMD -g -debug bayonet.d declaration.d error.d expression.d lexer.d parser.d scope_.d semantic_.d terminal.d translate_.d translate_prism.d translate_prism_deterministic.d util.d -ofbayonet

$DMD -g -debug maketable.d -ofmaketable
101 changes: 101 additions & 0 deletions keyur/congestion-10.bayonet
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
parameters{ NUM_PACKETS(3), COST_01(1), COST_02(2), COST_03(3), COST_12(1), COST_23(1) }

queue_capacity 2;

query probability(pkt_count@H1 < NUM_PACKETS);

packet_fields{}


num_steps 54 ;
topology {
nodes { H0, H1, S0, S1, S2, S3, S4, S5, S6, S7 }
links {
(H0,pt1) <-> (S0,pt1),

(S0,pt2) <-> (S1,pt1),
(S0,pt3) <-> (S2,pt1),
(S0,pt4) <-> (S3,pt4),
(S1,pt2) <-> (S3,pt1),
(S2,pt2) <-> (S3,pt2),

(S3,pt3) <-> (S4,pt1),

(S4,pt2) <-> (S5,pt1),
(S4,pt3) <-> (S6,pt1),
(S4,pt4) <-> (S7,pt4),
(S5,pt2) <-> (S7,pt1),
(S6,pt2) <-> (S7,pt2),

(S7,pt3) <-> (H1,pt1)
}
}
programs { H0 -> h0, H1 -> h1, S0 -> s0, S1 -> s1, S2 -> s2, S3 -> s3, S4 -> s0, S5 -> s1, S6 -> s2, S7 -> s3 }


def h0(pkt, port) state pkt_count(0){
new;
if pkt_count < NUM_PACKETS{
pkt_count = pkt_count + 1;
fwd(1);
}else { drop; drop; }
}

def h1(pkt, port) state pkt_count(0){
pkt_count = pkt_count + 1;
drop;
}

def s0(pkt, port)
state
route1(0), route2(0), route3(0),
shortest1(0), shortest2(0), shortest3(0),
nshortest(0), which(0)
{
if port == 1{
route1 = COST_01 + COST_12 + COST_23;
route2 = COST_03;
route3 = COST_02 + COST_23;
shortest1=0; shortest2=0; shortest3=0;
if (route1 <= route2 && route2 <= route3) { shortest1 = 1; }
if (route2 <= route1 && route2 <= route3) { shortest2 = 1; }
if (route3 <= route1 && route3 <= route2) { shortest3 = 1; }
nshortest = shortest1 + shortest2 + shortest3;
if (nshortest==1) {
which = 1;
} else if (nshortest==2) {
which = uniformInt(1,2);
} else {
which = uniformInt(1,3);
}
if which == shortest1 { fwd(2); }
else if which == shortest1+shortest2 { fwd(3); }
else { fwd(4); }
}
}

def s1(pkt,port){
if port == 1{
fwd(2);
}
}
def s2(pkt,port){
if port == 1{
fwd(2);
}
}
def s3(pkt,port){
if port == 1 || port == 2 || port == 4{
fwd(3);
}
}

def scheduler() state num_actions(0){
actions := ([]: (R x R)[]);
for i in [0..k){
if (Q_in@i).size() > 0 { actions ~= [(RunSw,i)]; }
if (Q_out@i).size() > 0 { actions ~= [(FwdQ,i)]; }
}
num_actions += 1;
return actions[uniformInt(0,actions.length-1)];
}
Loading