16 package org.openkilda.pce.provider;
25 import org.junit.AfterClass;
26 import org.junit.Assert;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.neo4j.driver.v1.AuthTokens;
30 import org.neo4j.driver.v1.GraphDatabase;
31 import org.neo4j.graphdb.GraphDatabaseService;
32 import org.neo4j.graphdb.Label;
33 import org.neo4j.graphdb.Node;
34 import org.neo4j.graphdb.Relationship;
35 import org.neo4j.graphdb.RelationshipType;
36 import org.neo4j.graphdb.Transaction;
37 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
38 import org.neo4j.io.fs.FileUtils;
39 import org.neo4j.kernel.configuration.BoltConnector;
42 import java.util.List;
47 AuthTokens.basic(
"neo4j",
"neo4j")));
48 private static GraphDatabaseService graphDb;
50 private static final File databaseDirectory =
new File(
"target/neo4j-test-db");
54 FileUtils.deleteRecursively(databaseDirectory);
57 BoltConnector bolt =
new BoltConnector(
"0");
58 graphDb =
new GraphDatabaseFactory()
59 .newEmbeddedDatabaseBuilder(databaseDirectory)
60 .setConfig(bolt.type,
"BOLT")
61 .setConfig(bolt.enabled,
"true")
62 .setConfig(bolt.listen_address,
"localhost:7878")
74 try (Transaction tx = graphDb.beginTx()) {
75 Node node1 = graphDb.createNode(Label.label(
"switch"));
76 node1.setProperty(
"name",
"00:01");
77 Node node2 = graphDb.createNode(Label.label(
"switch"));
78 node2.setProperty(
"name",
"00:02");
79 Relationship rel1 = node1.createRelationshipTo(node2, RelationshipType.withName(
"flow"));
80 rel1.setProperty(
"flowid",
"f1");
81 rel1.setProperty(
"cookie", 3);
82 rel1.setProperty(
"meter_id", 2);
83 rel1.setProperty(
"transit_vlan", 1);
84 rel1.setProperty(
"src_switch",
"00:01");
85 rel1.setProperty(
"dst_switch",
"00:02");
86 rel1.setProperty(
"src_port", 1);
87 rel1.setProperty(
"dst_port", 2);
88 rel1.setProperty(
"src_vlan", 5);
89 rel1.setProperty(
"dst_vlan", 5);
90 rel1.setProperty(
"path",
"\"{\"path\": [], \"latency_ns\": 0, \"timestamp\": 1522528031909}\"");
91 rel1.setProperty(
"bandwidth", 200);
92 rel1.setProperty(
"ignore_bandwidth",
true);
93 rel1.setProperty(
"description",
"description");
94 rel1.setProperty(
"last_updated",
"last_updated");
98 List<Flow> flows = target.getAllFlows();
99 Flow flow = flows.get(0);
100 Assert.assertEquals(3, flow.getCookie());
101 Assert.assertEquals(
"f1", flow.getFlowId());
102 Assert.assertEquals(
true, flow.isIgnoreBandwidth());
108 try (Transaction tx = graphDb.beginTx()) {
109 Node node1 = graphDb.createNode(Label.label(
"switch"));
110 node1.setProperty(
"name",
"00:01");
111 Node node2 = graphDb.createNode(Label.label(
"switch"));
112 node2.setProperty(
"name",
"00:02");
113 Relationship rel1 = node1.createRelationshipTo(node2, RelationshipType.withName(
"isl"));
114 rel1.setProperty(
"src_switch",
"00:01");
115 rel1.setProperty(
"src_port", 1);
116 rel1.setProperty(
"dst_switch",
"00:02");
117 rel1.setProperty(
"dst_port", 2);
118 rel1.setProperty(
"speed", 200);
119 rel1.setProperty(
"max_bandwidth", 300);
120 rel1.setProperty(
"latency", 400);
121 rel1.setProperty(
"available_bandwidth", 500);
122 rel1.setProperty(
"status",
"active");
124 Relationship rel2 = node2.createRelationshipTo(node1, RelationshipType.withName(
"isl"));
125 rel2.setProperty(
"src_switch",
"00:02");
126 rel2.setProperty(
"src_port", 3);
127 rel2.setProperty(
"dst_switch",
"00:01");
128 rel2.setProperty(
"dst_port", 4);
129 rel2.setProperty(
"speed", 600);
130 rel2.setProperty(
"max_bandwidth", 700);
131 rel2.setProperty(
"latency", 800);
132 rel2.setProperty(
"available_bandwidth", 900);
133 rel2.setProperty(
"status",
"inactive");
138 List<IslInfoData> isls = target.getIsls();
140 Assert.assertEquals(200, isl.getSpeed());
141 Assert.assertEquals(
new SwitchId(
"00:01"), isl.
getPath().get(0).getSwitchId());
152 try (Transaction tx = graphDb.beginTx()) {
153 Node node1 = graphDb.createNode(Label.label(
"switch"));
154 node1.setProperty(
"name",
"00:01");
155 node1.setProperty(
"address",
"1");
156 node1.setProperty(
"hostname",
"2");
157 node1.setProperty(
"description",
"3");
158 node1.setProperty(
"controller",
"4");
159 node1.setProperty(
"state",
"active");
161 Node node2 = graphDb.createNode(Label.label(
"switch"));
162 node2.setProperty(
"name",
"00:02");
163 node2.setProperty(
"address",
"5");
164 node2.setProperty(
"hostname",
"6");
165 node2.setProperty(
"description",
"7");
166 node2.setProperty(
"controller",
"8");
167 node2.setProperty(
"state",
"inactive");
172 List<SwitchInfoData> switches = target.getSwitches();
static void tearDownOnce()
List< PathNode > getPath()