summaryrefslogtreecommitdiffstats
path: root/verigraph/service/src/mcnet/netobjs/PolitoMailClient.java
diff options
context:
space:
mode:
authorserena.spinoso <serena.spinoso@polito.it>2017-02-25 12:00:55 +0100
committerserena.spinoso <serena.spinoso@polito.it>2017-02-27 13:39:18 +0100
commit53d83244c1bf36af86e90ce5fe758a369f73563e (patch)
treef5780b3033763d6b3cd62c40f5d4a63dfac35f7a /verigraph/service/src/mcnet/netobjs/PolitoMailClient.java
parentf0108f26fb1f62fefbbc4d5484b87241d563737b (diff)
Add verigraph code base
JIRA: PARSER-111 Change-Id: Ie76e14fabbb6c388ebc89d9a15dd3021b25fa892 Signed-off-by: serena.spinoso <serena.spinoso@polito.it>
Diffstat (limited to 'verigraph/service/src/mcnet/netobjs/PolitoMailClient.java')
-rw-r--r--verigraph/service/src/mcnet/netobjs/PolitoMailClient.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/verigraph/service/src/mcnet/netobjs/PolitoMailClient.java b/verigraph/service/src/mcnet/netobjs/PolitoMailClient.java
new file mode 100644
index 0000000..6925258
--- /dev/null
+++ b/verigraph/service/src/mcnet/netobjs/PolitoMailClient.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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 mcnet.components.NetContext;
+import mcnet.components.Network;
+import mcnet.components.NetworkObject;
+/**
+ * MailClient objects
+ *
+ */
+public class PolitoMailClient extends NetworkObject{
+
+ List<BoolExpr> constraints;
+ Context ctx;
+ DatatypeExpr politoMailClient;
+ Network net;
+ NetContext nctx;
+ FuncDecl isInBlacklist;
+
+ public PolitoMailClient(Context ctx, Object[]... args) {
+ super(ctx, args);
+ }
+
+ @Override
+ protected void init(Context ctx, Object[]... args) {
+ this.ctx = ctx;
+ isEndHost=true;
+ constraints = new ArrayList<BoolExpr>();
+ z3Node = ((NetworkObject)args[0][0]).getZ3Node();
+ politoMailClient = z3Node;
+ net = (Network)args[0][1];
+ nctx = (NetContext)args[0][2];
+ DatatypeExpr ipServer = (DatatypeExpr) args[0][3];
+ mailClientRules(ipServer);
+ //net.saneSend(this);
+ }
+
+ @Override
+ public DatatypeExpr getZ3Node() {
+ return politoMailClient;
+ }
+
+ @Override
+ protected void addConstraints(Solver solver) {
+// System.out.println("[MailClient] Installing rules.");
+ BoolExpr[] constr = new BoolExpr[constraints.size()];
+ solver.add(constraints.toArray(constr));
+ }
+
+ private void mailClientRules (DatatypeExpr ipServer){
+ Expr n_0 = ctx.mkConst("PolitoMailClient_"+politoMailClient+"_n_0", nctx.node);
+ Expr p_0 = ctx.mkConst("PolitoMailClient_"+politoMailClient+"_p_0", nctx.packet);
+ IntExpr t_0 = ctx.mkIntConst("PolitoMailClient_"+politoMailClient+"_t_0");
+
+// Constraint1 send(politoMailClient, n_0, p, t_0) -> nodeHasAddr(politoMailClient,p.src)
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.send.apply(politoMailClient, n_0, p_0, t_0),
+ (BoolExpr)nctx.nodeHasAddr.apply(politoMailClient,nctx.pf.get("src").apply(p_0))),1,null,null,null,null));
+
+// Constraint2 send(politoMailClient, n_0, p, t_0) -> p.origin == politoMailClient
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.send.apply(politoMailClient, n_0, p_0, t_0),
+ ctx.mkEq(nctx.pf.get("origin").apply(p_0),politoMailClient)),1,null,null,null,null));
+
+// Constraint3 send(politoMailClient, n_0, p, t_0) -> p.orig_body == p.body
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.send.apply(politoMailClient, n_0, p_0, t_0),
+ ctx.mkEq(nctx.pf.get("orig_body").apply(p_0),nctx.pf.get("body").apply(p_0))),1,null,null,null,null));
+
+// Constraint4 recv(n_0, politoMailClient, p, t_0) -> nodeHasAddr(politoMailClient,p.dest)
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.recv.apply(n_0,politoMailClient, p_0, t_0),
+ (BoolExpr)nctx.nodeHasAddr.apply(politoMailClient,nctx.pf.get("dest").apply(p_0))),1,null,null,null,null));
+
+// Constraint5 This client is only able to produce POP3 requests
+// send(politoMailClient, n_0, p, t_0) -> p.proto == POP3_REQ
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.send.apply(politoMailClient, n_0, p_0, t_0),
+ ctx.mkEq(nctx.pf.get("proto").apply(p_0), ctx.mkInt(nctx.POP3_REQUEST))),1,null,null,null,null));
+
+// Constraint6 send(politoMailClient, n_0, p, t_0) -> p.dest == ip_mailServer
+ constraints.add( ctx.mkForall(new Expr[]{n_0, p_0, t_0},
+ ctx.mkImplies((BoolExpr)nctx.send.apply(politoMailClient, n_0, p_0, t_0),
+ ctx.mkEq(nctx.pf.get("dest").apply(p_0), ipServer)),1,null,null,null,null));
+ }
+}