1 /*******************************************************************************
2 * Copyright (c) 2017 Politecnico di Torino and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Apache License, Version 2.0
6 * which accompanies this distribution, and is available at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *******************************************************************************/
10 package it.polito.escape.verify.test;
12 import java.sql.Timestamp;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
18 import com.fasterxml.jackson.databind.JsonNode;
19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.fasterxml.jackson.databind.node.ArrayNode;
21 import com.fasterxml.jackson.databind.node.ObjectNode;
23 import it.polito.escape.verify.client.VerifyClient;
24 import it.polito.escape.verify.client.VerifyClientException;
25 import it.polito.escape.verify.model.Configuration;
26 import it.polito.escape.verify.model.Graph;
27 import it.polito.escape.verify.model.Neighbour;
28 import it.polito.escape.verify.model.Node;
29 import it.polito.escape.verify.model.Verification;
31 public class Scalability {
33 private VerifyClient client = new VerifyClient("http://localhost:8080/verify/api");
35 public static void main(String[] args) throws VerifyClientException {
36 Scalability s = new Scalability();
38 reachabilityTest(s, 10);
40 isolationTest(s,1500);
44 private static void reachabilityTest(Scalability s, int n) throws VerifyClientException {
45 System.out.printf("Reachability test with N=" + n + ": ");
47 Graph graph = generateNatScenario(n);
48 Graph createdGraph = s.client.createGraph(graph).readEntity(Graph.class);
49 Verification result = s.client.getReachability(createdGraph.getId(), "client", "server");
50 System.out.println("Test returned " + result.getResult());
51 System.out.printf("Finished reachability test with N=" + n + ": ");
56 private static void isolationTest(Scalability s, int n) throws VerifyClientException {
57 System.out.printf("Isolation test with N=" + n + ": ");
59 Graph graph = generateNatScenario(n);
60 Graph createdGraph = s.client.createGraph(graph).readEntity(Graph.class);
61 Verification result = s.client.getIsolation(createdGraph.getId(), "client", "server", "firewall");
62 System.out.println("Test returned " + result.getResult());
63 System.out.printf("Finished isolation test with N=" + n + ": ");
68 private static void traversalTest(Scalability s, int n) throws VerifyClientException {
69 System.out.printf("Traversal test with N=" + n + ": ");
71 Graph graph = generateNatScenario(n);
72 Graph createdGraph = s.client.createGraph(graph).readEntity(Graph.class);
73 Verification result = s.client.getTraversal(createdGraph.getId(), "client", "server", "firewall");
74 System.out.println("Test returned " + result.getResult());
75 // System.out.println("Result explanation: " + result.getComment());
76 System.out.printf("Finished traversal test with N=" + n + ": ");
81 private static void printTimestamp() {
82 java.util.Date date= new java.util.Date();
83 System.out.println(new Timestamp(date.getTime()));
86 private static Graph generateNatScenario(int n) {
87 List<Node> nodes = new ArrayList<Node>();
89 Node client = new Node();
90 client.setName("client");
91 client.setFunctional_type("endhost");
92 ArrayNode clientConfigArray = new ObjectMapper().createArrayNode();
93 JsonNode clientConfig = new ObjectMapper().createObjectNode();
94 ((ObjectNode)clientConfig).put("url", "www.facebook.com");
95 ((ObjectNode)clientConfig).put("body", "word");
96 ((ObjectNode)clientConfig).put("destination","server");
97 ((ObjectNode)clientConfig).put("protocol", "HTTP_REQUEST");
98 clientConfigArray.add(clientConfig);
99 client.setConfiguration(new Configuration(client.getName(),"", clientConfigArray));
101 Map<Long, Neighbour> clientNeighbours = new HashMap<Long, Neighbour>();
102 clientNeighbours.put(1L, new Neighbour(1L, "nat1"));
103 client.setNeighbours(clientNeighbours );
107 for(int i=0; i< n;i++){
108 Node nat = new Node();
110 nat.setName("nat" + (i+1));
111 nat.setFunctional_type("nat");
112 ArrayNode configArray = new ObjectMapper().createArrayNode();
114 Map<Long, Neighbour> natNeighbours = new HashMap<Long, Neighbour>();
116 //set left neighbour for each node except the first
117 if(nat.getId() != 1){
118 natNeighbours.put(1L, new Neighbour(1L, "nat" + i));
119 configArray.add("client");
120 for (int j=1; j <= i; j++){
121 configArray.add("nat" + j);
124 //first nat: set only client as neighbour and natted node
126 natNeighbours.put(1L, new Neighbour(1L, "client"));
127 configArray.add("client");
129 //set right neighbour for each node except the last
130 if(nat.getId() != n){
131 natNeighbours.put(2L, new Neighbour(1L, "nat" + (i+2)));
133 //last nat: set server as neighbour
135 natNeighbours.put(2L, new Neighbour(1L, "server"));
138 nat.setNeighbours(natNeighbours);
139 nat.setConfiguration(new Configuration(nat.getName(),"", configArray));
145 Node server = new Node();
146 server.setName("server");
147 server.setFunctional_type("webserver");
148 ArrayNode serverConfigArray = new ObjectMapper().createArrayNode();
149 server.setConfiguration(new Configuration(server.getName(),"", serverConfigArray));
151 Map<Long, Neighbour> serverNeighbours = new HashMap<Long, Neighbour>();
152 serverNeighbours.put(1L, new Neighbour(1L, "nat" + (n)));
153 server.setNeighbours(serverNeighbours );
159 Graph g = new Graph();
160 Map<Long, Node> graphNodes = new HashMap<Long, Node>();
162 for (Node node : nodes){
163 graphNodes.put(index, node);
166 g.setNodes(graphNodes);
171 private static Graph generateFirewallScenario(int n) {
172 List<Node> nodes = new ArrayList<Node>();
174 Node client = new Node();
175 client.setName("client");
176 client.setFunctional_type("endhost");
177 ArrayNode clientConfigArray = new ObjectMapper().createArrayNode();
178 JsonNode clientConfig = new ObjectMapper().createObjectNode();
179 ((ObjectNode)clientConfig).put("url", "www.facebook.com");
180 ((ObjectNode)clientConfig).put("body", "word");
181 ((ObjectNode)clientConfig).put("destination","server");
182 ((ObjectNode)clientConfig).put("protocol", "HTTP_REQUEST");
183 clientConfigArray.add(clientConfig);
184 client.setConfiguration(new Configuration(client.getName(),"", clientConfigArray));
186 Map<Long, Neighbour> clientNeighbours = new HashMap<Long, Neighbour>();
187 clientNeighbours.put(1L, new Neighbour(1L, "firewall1"));
188 client.setNeighbours(clientNeighbours );
192 for(int i=0; i< n;i++){
193 Node firewall = new Node();
195 firewall.setName("firewall" + (i+1));
196 firewall.setFunctional_type("firewall");
197 ArrayNode configArray = new ObjectMapper().createArrayNode();
199 Map<Long, Neighbour> natNeighbours = new HashMap<Long, Neighbour>();
201 //set left neighbour for each node except the first
202 if(firewall.getId() != 1){
203 natNeighbours.put(1L, new Neighbour(1L, "firewall" + i));
205 //first firewall: set only client as neighbour and natted node
207 natNeighbours.put(1L, new Neighbour(1L, "client"));
209 //set right neighbour for each node except the last
210 if(firewall.getId() != n){
211 natNeighbours.put(2L, new Neighbour(1L, "firewall" + (i+2)));
213 //last firewall: set server as neighbour
215 natNeighbours.put(2L, new Neighbour(1L, "server"));
218 firewall.setNeighbours(natNeighbours);
219 firewall.setConfiguration(new Configuration(firewall.getName(),"", configArray));
225 Node server = new Node();
226 server.setName("server");
227 server.setFunctional_type("webserver");
228 ArrayNode serverConfigArray = new ObjectMapper().createArrayNode();
229 server.setConfiguration(new Configuration(server.getName(),"", serverConfigArray));
231 Map<Long, Neighbour> serverNeighbours = new HashMap<Long, Neighbour>();
232 serverNeighbours.put(1L, new Neighbour(1L, "firewall" + (n)));
233 server.setNeighbours(serverNeighbours );
239 Graph g = new Graph();
240 Map<Long, Node> graphNodes = new HashMap<Long, Node>();
242 for (Node node : nodes){
243 graphNodes.put(index, node);
246 g.setNodes(graphNodes);
251 private static Graph generateScenario(int n) {
252 List<Node> nodes = new ArrayList<Node>();
254 Node firewall = new Node();
255 firewall.setName("firewall");
256 firewall.setFunctional_type("firewall");
257 ArrayNode firewallConfigArray = new ObjectMapper().createArrayNode();
258 Map<Long, Neighbour> firewallNeighbours = new HashMap<Long, Neighbour>();
260 for (int i=0; i < n; i++){
262 JsonNode firewallEntry = new ObjectMapper().createObjectNode();
263 ((ObjectNode) firewallEntry).put("server", "client" + (i+1));
264 firewallConfigArray.add(firewallEntry);
266 firewallNeighbours.put(new Long(i+1), new Neighbour(new Long(i+1), "client" + (i+1)));
269 firewallNeighbours.put(new Long(n+1), new Neighbour(new Long(n+1), "server"));
271 firewall.setConfiguration(new Configuration(firewall.getName(),"", firewallConfigArray));
274 firewall.setNeighbours(firewallNeighbours );
278 for(int i=0; i< n;i++){
279 Node client = new Node();
281 client.setName("client" + (i+1));
282 client.setFunctional_type("endhost");
283 ArrayNode clientConfigArray = new ObjectMapper().createArrayNode();
284 JsonNode clientConfig = new ObjectMapper().createObjectNode();
285 ((ObjectNode)clientConfig).put("url", "www.facebook.com");
286 ((ObjectNode)clientConfig).put("body", "word");
287 ((ObjectNode)clientConfig).put("destination","server");
288 ((ObjectNode)clientConfig).put("protocol", "HTTP_REQUEST");
289 clientConfigArray.add(clientConfig);
291 Map<Long, Neighbour> clientNeighbours = new HashMap<Long, Neighbour>();
293 clientNeighbours.put(1L, new Neighbour(1L, "firewall"));
295 client.setNeighbours(clientNeighbours);
296 client.setConfiguration(new Configuration(client.getName(),"", clientConfigArray));
302 Node server = new Node();
303 server.setName("server");
304 server.setFunctional_type("webserver");
305 ArrayNode serverConfigArray = new ObjectMapper().createArrayNode();
306 server.setConfiguration(new Configuration(server.getName(),"", serverConfigArray));
308 Map<Long, Neighbour> serverNeighbours = new HashMap<Long, Neighbour>();
309 serverNeighbours.put(1L, new Neighbour(1L, "firewall"));
310 server.setNeighbours(serverNeighbours );
316 Graph g = new Graph();
317 Map<Long, Node> graphNodes = new HashMap<Long, Node>();
319 for (Node node : nodes){
320 graphNodes.put(index, node);
323 g.setNodes(graphNodes);
328 private static Graph generateDpiScenario(int n) {
329 List<Node> nodes = new ArrayList<Node>();
331 Node client = new Node();
332 client.setName("client");
333 client.setFunctional_type("endhost");
334 ArrayNode clientConfigArray = new ObjectMapper().createArrayNode();
335 JsonNode clientConfig = new ObjectMapper().createObjectNode();
336 ((ObjectNode)clientConfig).put("url", "www.facebook.com");
337 ((ObjectNode)clientConfig).put("body", "word");
338 ((ObjectNode)clientConfig).put("destination","server");
339 ((ObjectNode)clientConfig).put("protocol", "HTTP_REQUEST");
340 clientConfigArray.add(clientConfig);
341 client.setConfiguration(new Configuration(client.getName(),"", clientConfigArray));
343 Map<Long, Neighbour> clientNeighbours = new HashMap<Long, Neighbour>();
344 clientNeighbours.put(1L, new Neighbour(1L, "dpi1"));
345 client.setNeighbours(clientNeighbours );
349 for(int i=0; i< n;i++){
350 Node dpi = new Node();
352 dpi.setName("dpi" + (i+1));
353 dpi.setFunctional_type("dpi");
354 ArrayNode configArray = new ObjectMapper().createArrayNode();
355 configArray.add("drug");
357 Map<Long, Neighbour> natNeighbours = new HashMap<Long, Neighbour>();
359 //set left neighbour for each node except the first
360 if(dpi.getId() != 1){
361 natNeighbours.put(1L, new Neighbour(1L, "dpi" + i));
363 //first firewall: set only client as neighbour and natted node
365 natNeighbours.put(1L, new Neighbour(1L, "client"));
367 //set right neighbour for each node except the last
368 if(dpi.getId() != n){
369 natNeighbours.put(2L, new Neighbour(1L, "dpi" + (i+2)));
371 //last firewall: set server as neighbour
373 natNeighbours.put(2L, new Neighbour(1L, "server"));
376 dpi.setNeighbours(natNeighbours);
377 dpi.setConfiguration(new Configuration(dpi.getName(),"", configArray));
383 Node server = new Node();
384 server.setName("server");
385 server.setFunctional_type("webserver");
386 ArrayNode serverConfigArray = new ObjectMapper().createArrayNode();
387 server.setConfiguration(new Configuration(server.getName(),"", serverConfigArray));
389 Map<Long, Neighbour> serverNeighbours = new HashMap<Long, Neighbour>();
390 serverNeighbours.put(1L, new Neighbour(1L, "dpi" + (n)));
391 server.setNeighbours(serverNeighbours );
397 Graph g = new Graph();
398 Map<Long, Node> graphNodes = new HashMap<Long, Node>();
400 for (Node node : nodes){
401 graphNodes.put(index, node);
404 g.setNodes(graphNodes);