From a42de79292d9541db7865b54e93be2d0b6e6a094 Mon Sep 17 00:00:00 2001 From: "serena.spinoso" Date: Thu, 7 Sep 2017 10:22:39 +0200 Subject: update verigraph JIRA: PARSER-154 code optimizations about graph manipulation and formula generation. Change-Id: Idebef19b128281aa2bc40d1aeab6e208c7ddd93d Signed-off-by: serena.spinoso --- .../service/src/mcnet/netobjs/PolitoCache.java | 177 --------------------- 1 file changed, 177 deletions(-) delete mode 100644 verigraph/service/src/mcnet/netobjs/PolitoCache.java (limited to 'verigraph/service/src/mcnet/netobjs/PolitoCache.java') diff --git a/verigraph/service/src/mcnet/netobjs/PolitoCache.java b/verigraph/service/src/mcnet/netobjs/PolitoCache.java deleted file mode 100644 index 948915c..0000000 --- a/verigraph/service/src/mcnet/netobjs/PolitoCache.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017 Politecnico di Torino and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Apache License, Version 2.0 - * which accompanies this distribution, and is available at - * http://www.apache.org/licenses/LICENSE-2.0 - *******************************************************************************/ - -package mcnet.netobjs; - - -import java.util.ArrayList; -import java.util.List; - -import com.microsoft.z3.BoolExpr; -import com.microsoft.z3.Context; -import com.microsoft.z3.DatatypeExpr; -import com.microsoft.z3.Expr; -import com.microsoft.z3.FuncDecl; -import com.microsoft.z3.IntExpr; -import com.microsoft.z3.Solver; -import com.microsoft.z3.Sort; - -import mcnet.components.NetContext; -import mcnet.components.Network; -import mcnet.components.NetworkObject; -/**Cache Model - * - */ -public class PolitoCache extends NetworkObject{ - - List constraints; - Context ctx; - DatatypeExpr politoCache; - Network net; - NetContext nctx; - FuncDecl isInBlacklist; - - public PolitoCache(Context ctx, Object[]... args) { - super(ctx, args); - } - - @Override - protected void init(Context ctx, Object[]... args) { - this.ctx = ctx; - isEndHost=false; - constraints = new ArrayList(); - z3Node = ((NetworkObject)args[0][0]).getZ3Node(); - politoCache = z3Node; - net = (Network)args[0][1]; - nctx = (NetContext)args[0][2]; - //net.saneSend(this); - } - - @Override - public DatatypeExpr getZ3Node() { - return politoCache; - } - - @Override - protected void addConstraints(Solver solver) { - BoolExpr[] constr = new BoolExpr[constraints.size()]; - solver.add(constraints.toArray(constr)); - } - - public void installCache (NetworkObject[] internalNodes){ - Expr n_0 = ctx.mkConst("politoCache_"+politoCache+"_n_0", nctx.node); - Expr n_1 = ctx.mkConst("politoCache_"+politoCache+"_n_1", nctx.node); - Expr n_2 = ctx.mkConst("politoCache_"+politoCache+"_n_2", nctx.node); - Expr p_0 = ctx.mkConst("politoCache_"+politoCache+"_p_0", nctx.packet); - Expr p_1 = ctx.mkConst("politoCache_"+politoCache+"_p_1", nctx.packet); - Expr p_2 = ctx.mkConst("politoCache_"+politoCache+"_p_2", nctx.packet); - - IntExpr t_0 = ctx.mkIntConst("politoCache_"+politoCache+"_t_0"); - IntExpr t_1 = ctx.mkIntConst("politoCache_"+politoCache+"_t_1"); - IntExpr t_2 = ctx.mkIntConst("politoCache_"+politoCache+"_t_2"); - - Expr a_0 = ctx.mkConst(politoCache+"politoCache_a_0", nctx.node); - IntExpr u_0 = ctx.mkIntConst("politoCache_"+politoCache+"_u_0"); - - FuncDecl isInternalNode = ctx.mkFuncDecl(politoCache+"_isInternalNode", nctx.node, ctx.mkBoolSort()); - FuncDecl isInCache = ctx.mkFuncDecl(politoCache+"_isInCache", new Sort[]{ctx.mkIntSort(),ctx.mkIntSort()}, ctx.mkBoolSort()); - - assert(internalNodes.length!=0); //No internal nodes => Should never happen - - //Modeling the behavior of the isInternalNode() and isInCache() functions - BoolExpr[] internalNodesConstraint = new BoolExpr[internalNodes.length]; - for(int w=0;w - // (exist t_1,n_1 : - // (t_1 < t_0 && recv(n_1, politoCache, p, t_1) && - // p.proto == HTTP_REQ && !isInCache(p.url,t_0)) - constraints.add( - ctx.mkForall(new Expr[]{n_0,p_0, t_0}, - ctx.mkImplies( - ctx.mkAnd((BoolExpr)nctx.send.apply(politoCache,n_0,p_0,t_0),ctx.mkNot((BoolExpr)isInternalNode.apply(n_0))), - ctx.mkAnd(ctx.mkExists(new Expr[]{t_1, n_1}, - ctx.mkAnd( - ctx.mkLt(t_1, t_0), - (BoolExpr)isInternalNode.apply(n_1), - (BoolExpr)nctx.recv.apply(n_1, politoCache, p_0, t_1)),1,null,null,null,null), - ctx.mkEq(nctx.pf.get("proto").apply(p_0), ctx.mkInt(nctx.HTTP_REQUEST)), - ctx.mkNot((BoolExpr)isInCache.apply(nctx.pf.get("url").apply(p_0), t_0)))),1,null,null,null,null)); - - //Constraint4 send(politoCache, n_0, p, t_0) && isInternalNode(n_0) -> - // (exist p_1,t_1 : - // (t_1 < t_0 && recv(n_0, politoCache, p_1, t_1) && - // p_1.proto == HTTP_REQ && p.proto == HTTP_RESP && - // p_1.url == p.url && p.src == p_1.dest && p.dest==p_1.src - // && isInCache(p.url,t_0)) - constraints.add( - ctx.mkForall(new Expr[]{n_0,p_0, t_0}, - ctx.mkImplies( - ctx.mkAnd((BoolExpr)nctx.send.apply(politoCache,n_0,p_0,t_0),(BoolExpr)isInternalNode.apply(n_0)), - ctx.mkAnd(ctx.mkExists(new Expr[]{p_1, t_1}, - ctx.mkAnd( - ctx.mkLt(t_1, t_0), - (BoolExpr)nctx.recv.apply(n_0, politoCache, p_1, t_1), - ctx.mkEq(nctx.pf.get("proto").apply(p_1), ctx.mkInt(nctx.HTTP_REQUEST)), - ctx.mkEq(nctx.pf.get("url").apply(p_1), nctx.pf.get("url").apply(p_0))),1,null,null,null,null), - ctx.mkEq(nctx.pf.get("proto").apply(p_0), ctx.mkInt(nctx.HTTP_RESPONSE)), - ctx.mkEq(nctx.pf.get("src").apply(p_0), nctx.pf.get("dest").apply(p_1)), - ctx.mkEq(nctx.pf.get("dest").apply(p_0), nctx.pf.get("src").apply(p_1)), - (BoolExpr)isInCache.apply(nctx.pf.get("url").apply(p_0), t_0))),1,null,null,null,null)); - } -} \ No newline at end of file -- cgit 1.2.3-korg