blob: 7921099d7b0ec349c1e90c16b616f2c9746b23c2 [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore.topology;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -07002
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.hamcrest.Matchers.anyOf;
4import static org.hamcrest.Matchers.equalTo;
5import static org.hamcrest.Matchers.hasItem;
6import static org.hamcrest.Matchers.hasKey;
7import static org.hamcrest.Matchers.is;
8import static org.junit.Assert.assertArrayEquals;
9import static org.junit.Assert.assertEquals;
10import static org.junit.Assert.assertNotEquals;
11import static org.junit.Assert.assertThat;
12import static org.junit.Assert.fail;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070013
14import java.util.ArrayList;
15import java.util.Arrays;
16import java.util.HashMap;
17import java.util.List;
18import java.util.Map;
19import java.util.TreeMap;
20
Jonathan Hart6df90172014-04-03 10:13:11 -070021import net.onrc.onos.core.datastore.DataStoreClient;
22import net.onrc.onos.core.datastore.IKVClient;
23import net.onrc.onos.core.datastore.IKVTable;
24import net.onrc.onos.core.datastore.ObjectDoesntExistException;
25import net.onrc.onos.core.datastore.ObjectExistsException;
26import net.onrc.onos.core.datastore.WrongVersionException;
Jonathan Hart6df90172014-04-03 10:13:11 -070027import net.onrc.onos.core.datastore.utils.ByteArrayComparator;
28import net.onrc.onos.core.datastore.utils.KVObject;
29import net.onrc.onos.core.datastore.utils.KVObject.WriteOp;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070030
31import org.junit.After;
32import org.junit.Before;
33import org.junit.Test;
34
35public class KVTopologyTest {
36
Yuta HIGUCHIceb21b62014-04-17 15:46:05 -070037 static {
38 // configuration to quickly fall back to instance mode for faster test run
39 System.setProperty("net.onrc.onos.core.datastore.hazelcast.client.attemptLimit", "0");
40 }
41
Ray Milkey7531a342014-04-11 15:08:12 -070042 static final long VERSION_NONEXISTENT = DataStoreClient.getClient().getVersionNonexistant();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070043
Ray Milkey269ffb92014-04-03 14:43:30 -070044 private static final byte[] DEVICE2_MAC_SW2P2 = new byte[]{6, 5, 4, 3, 2, 1, 0};
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070045
46 private static final Long SW2_PORTNO2 = 2L;
47
48 private static final Long SW2_PORTNO1 = 1L;
49
50 private static final Long DPID2 = 0x2L;
51
Ray Milkey269ffb92014-04-03 14:43:30 -070052 private static final byte[] DEVICE1_MAC_SW1P1 = new byte[]{0, 1, 2, 3, 4, 5, 6};
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070053
54 private static final Long SW1_PORTNO2 = 2L;
55
56 private static final Long SW1_PORTNO1 = 1L;
57
58 private static final Long DPID1 = 0x1L;
59
60 @Before
61 @After
62 public void wipeTopology() throws Exception {
Ray Milkey269ffb92014-04-03 14:43:30 -070063 IKVTable switchTable = DataStoreClient.getClient().getTable(KVSwitch.GLOBAL_SWITCH_TABLE_NAME);
64 DataStoreClient.getClient().dropTable(switchTable);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 IKVTable portTable = DataStoreClient.getClient().getTable(KVPort.GLOBAL_PORT_TABLE_NAME);
67 DataStoreClient.getClient().dropTable(portTable);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070068
Ray Milkey269ffb92014-04-03 14:43:30 -070069 IKVTable linkTable = DataStoreClient.getClient().getTable(KVLink.GLOBAL_LINK_TABLE_NAME);
70 DataStoreClient.getClient().dropTable(linkTable);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070071
Ray Milkey269ffb92014-04-03 14:43:30 -070072 IKVTable deviceTable = DataStoreClient.getClient().getTable(KVDevice.GLOBAL_DEVICE_TABLE_NAME);
73 DataStoreClient.getClient().dropTable(deviceTable);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070074 }
75
76 @Test
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070077 public void basicSwitchTest() {
Ray Milkey269ffb92014-04-03 14:43:30 -070078 // create switch 0x1
79 try {
80 KVSwitch sw = new KVSwitch(DPID1);
81 sw.setStatus(KVSwitch.STATUS.ACTIVE);
82 sw.create();
83 assertNotEquals(VERSION_NONEXISTENT, sw.getVersion());
84 assertEquals(DPID1, sw.getDpid());
85 assertEquals(KVSwitch.STATUS.ACTIVE, sw.getStatus());
86 } catch (ObjectExistsException e) {
87 e.printStackTrace();
88 fail("Create Switch Failed " + e);
89 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070090
Ray Milkey269ffb92014-04-03 14:43:30 -070091 // read switch 0x1
92 KVSwitch swRead = new KVSwitch(DPID1);
93 try {
94 swRead.read();
95 assertNotEquals(VERSION_NONEXISTENT, swRead.getVersion());
96 assertEquals(DPID1, swRead.getDpid());
97 assertEquals(KVSwitch.STATUS.ACTIVE, swRead.getStatus());
98 } catch (ObjectDoesntExistException e) {
99 e.printStackTrace();
100 fail("Reading Switch Failed " + e);
101 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700102
Ray Milkey269ffb92014-04-03 14:43:30 -0700103 // and update 0x1
104 swRead.setStatus(KVSwitch.STATUS.INACTIVE);
105 try {
106 swRead.update();
107 assertNotEquals(VERSION_NONEXISTENT, swRead.getVersion());
108 assertEquals(DPID1, swRead.getDpid());
109 assertEquals(KVSwitch.STATUS.INACTIVE, swRead.getStatus());
110 } catch (ObjectDoesntExistException | WrongVersionException e) {
111 e.printStackTrace();
112 fail("Updating Switch Failed " + e);
113 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700114
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 // read 0x1 again and delete
116 KVSwitch swRead2 = new KVSwitch(DPID1);
117 try {
118 swRead2.read();
119 assertNotEquals(VERSION_NONEXISTENT, swRead2.getVersion());
120 assertEquals(DPID1, swRead2.getDpid());
121 assertEquals(KVSwitch.STATUS.INACTIVE, swRead2.getStatus());
122 } catch (ObjectDoesntExistException e) {
123 e.printStackTrace();
124 fail("Reading Switch Again Failed " + e);
125 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700126
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 try {
128 swRead2.delete();
129 assertNotEquals(VERSION_NONEXISTENT, swRead2.getVersion());
130 } catch (ObjectDoesntExistException | WrongVersionException e) {
131 e.printStackTrace();
132 fail("Deleting Switch Failed " + e);
133 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700134
Ray Milkey269ffb92014-04-03 14:43:30 -0700135 // make sure 0x1 is deleted
136 KVObject swRead3 = new KVSwitch(DPID1);
137 try {
138 swRead3.read();
139 fail(swRead3 + " was supposed to be deleted, but read succeed");
140 } catch (ObjectDoesntExistException e) {
141 System.out.println("-- " + swRead3 + " not found as expected--");
142 e.printStackTrace(System.out);
143 System.out.println("---------------------------------------");
144 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700145 }
146
147 @Test
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700148 public void topologySetupAndTeardown() {
149 topologySetup();
150 topologyWalk();
151 topologyDelete();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700152 }
153
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700154 private static void topologySetup() {
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700155
Ray Milkey269ffb92014-04-03 14:43:30 -0700156 // d1 - s1p1 - s1 - s1p2 - s2p1 - s2 - s2p2
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700157
Ray Milkey269ffb92014-04-03 14:43:30 -0700158 KVSwitch sw1 = new KVSwitch(DPID1);
159 sw1.setStatus(KVSwitch.STATUS.ACTIVE);
160 try {
161 sw1.create();
162 assertNotEquals(VERSION_NONEXISTENT, sw1.getVersion());
163 assertEquals(DPID1, sw1.getDpid());
164 assertEquals(KVSwitch.STATUS.ACTIVE, sw1.getStatus());
165 } catch (ObjectExistsException e) {
166 e.printStackTrace();
167 fail("Switch creation failed " + e);
168 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700169
Ray Milkey269ffb92014-04-03 14:43:30 -0700170 KVPort sw1p1 = new KVPort(DPID1, SW1_PORTNO1);
171 sw1p1.setStatus(KVPort.STATUS.ACTIVE);
172 KVPort sw1p2 = new KVPort(DPID1, SW1_PORTNO2);
173 sw1p2.setStatus(KVPort.STATUS.ACTIVE);
174 try {
175 sw1p1.create();
176 assertNotEquals(VERSION_NONEXISTENT, sw1p1.getVersion());
177 assertEquals(DPID1, sw1p1.getDpid());
178 assertEquals(SW1_PORTNO1, sw1p1.getNumber());
179 assertEquals(KVPort.STATUS.ACTIVE, sw1p1.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700180
Ray Milkey269ffb92014-04-03 14:43:30 -0700181 sw1p2.create();
182 assertNotEquals(VERSION_NONEXISTENT, sw1p2.getVersion());
183 assertEquals(DPID1, sw1p2.getDpid());
184 assertEquals(SW1_PORTNO2, sw1p2.getNumber());
185 assertEquals(KVPort.STATUS.ACTIVE, sw1p2.getStatus());
186 } catch (ObjectExistsException e) {
187 e.printStackTrace();
188 fail("Port creation failed " + e);
189 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700190
Ray Milkey269ffb92014-04-03 14:43:30 -0700191 try {
192 sw1.update();
193 assertNotEquals(VERSION_NONEXISTENT, sw1.getVersion());
194 assertEquals(DPID1, sw1.getDpid());
195 assertEquals(KVSwitch.STATUS.ACTIVE, sw1.getStatus());
196 } catch (ObjectDoesntExistException | WrongVersionException e) {
197 e.printStackTrace();
198 fail("Switch update failed " + e);
199 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700200
Ray Milkey269ffb92014-04-03 14:43:30 -0700201 KVDevice d1 = new KVDevice(DEVICE1_MAC_SW1P1);
202 d1.addPortId(sw1p1.getId());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700203
Ray Milkey269ffb92014-04-03 14:43:30 -0700204 try {
205 d1.create();
206 assertNotEquals(VERSION_NONEXISTENT, d1.getVersion());
207 assertEquals(1, d1.getAllPortIds().size());
208 assertArrayEquals(sw1p1.getId(), d1.getAllPortIds().iterator().next());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700209
Ray Milkey269ffb92014-04-03 14:43:30 -0700210 try {
211 sw1p1.update();
212 assertNotEquals(VERSION_NONEXISTENT, sw1p1.getVersion());
213 assertEquals(DPID1, sw1p1.getDpid());
214 assertEquals(SW1_PORTNO1, sw1p1.getNumber());
215 assertEquals(KVPort.STATUS.ACTIVE, sw1p1.getStatus());
216 } catch (ObjectDoesntExistException | WrongVersionException e) {
217 e.printStackTrace();
218 fail("Link update failed " + e);
219 }
220 } catch (ObjectExistsException e) {
221 e.printStackTrace();
222 fail("Device creation failed " + e);
223 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700224
Ray Milkey269ffb92014-04-03 14:43:30 -0700225 KVSwitch sw2 = new KVSwitch(DPID2);
226 sw2.setStatus(KVSwitch.STATUS.ACTIVE);
227 KVPort sw2p1 = new KVPort(DPID2, SW2_PORTNO1);
228 sw2p1.setStatus(KVPort.STATUS.ACTIVE);
229 KVPort sw2p2 = new KVPort(DPID2, SW2_PORTNO2);
230 sw2p2.setStatus(KVPort.STATUS.ACTIVE);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700231
Ray Milkey269ffb92014-04-03 14:43:30 -0700232 KVDevice d2 = new KVDevice(DEVICE2_MAC_SW2P2);
233 d2.addPortId(sw2p2.getId());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700234
Ray Milkey269ffb92014-04-03 14:43:30 -0700235 IKVClient client = DataStoreClient.getClient();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700236
Ray Milkey269ffb92014-04-03 14:43:30 -0700237 List<WriteOp> groupOp = Arrays.asList(
238 sw2.createOp(client), sw2p1.createOp(client),
239 sw2p2.createOp(client), d2.createOp(client));
240 boolean failed = KVObject.multiWrite(groupOp);
241 if (failed) {
242 for (WriteOp op : groupOp) {
243 System.err.println(op);
244 }
245 fail("Some of Switch/Port/Device creation failed");
246 } else {
247 assertNotEquals(VERSION_NONEXISTENT, sw2.getVersion());
248 assertEquals(DPID2, sw2.getDpid());
249 assertEquals(KVSwitch.STATUS.ACTIVE, sw2.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700250
Ray Milkey269ffb92014-04-03 14:43:30 -0700251 assertNotEquals(VERSION_NONEXISTENT, sw2p1.getVersion());
252 assertEquals(DPID2, sw2p1.getDpid());
253 assertEquals(SW2_PORTNO1, sw2p1.getNumber());
254 assertEquals(KVPort.STATUS.ACTIVE, sw2p1.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700255
Ray Milkey269ffb92014-04-03 14:43:30 -0700256 assertNotEquals(VERSION_NONEXISTENT, sw2p2.getVersion());
257 assertEquals(DPID2, sw2p2.getDpid());
258 assertEquals(SW2_PORTNO2, sw2p2.getNumber());
259 assertEquals(KVPort.STATUS.ACTIVE, sw2p2.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700260
Ray Milkey269ffb92014-04-03 14:43:30 -0700261 assertNotEquals(VERSION_NONEXISTENT, d2.getVersion());
262 assertEquals(1, d2.getAllPortIds().size());
263 assertArrayEquals(sw2p2.getId(), d2.getAllPortIds().iterator().next());
264 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700265
Ray Milkey269ffb92014-04-03 14:43:30 -0700266 KVLink l1 = new KVLink(DPID1, SW1_PORTNO2, DPID2, SW2_PORTNO1);
267 l1.setStatus(KVLink.STATUS.ACTIVE);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700268
Ray Milkey269ffb92014-04-03 14:43:30 -0700269 try {
270 l1.create();
271 assertNotEquals(VERSION_NONEXISTENT, l1.getVersion());
272 assertEquals(KVLink.STATUS.ACTIVE, l1.getStatus());
273 assertArrayEquals(sw1.getId(), l1.getSrc().getSwitchID());
274 assertArrayEquals(sw1p2.getId(), l1.getSrc().getPortID());
275 assertArrayEquals(sw2.getId(), l1.getDst().getSwitchID());
276 assertArrayEquals(sw2p1.getId(), l1.getDst().getPortID());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700277
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 try {
279 sw1p2.update();
280 assertNotEquals(VERSION_NONEXISTENT, sw1p2.getVersion());
281 assertEquals(DPID1, sw1p2.getDpid());
282 assertEquals(SW1_PORTNO2, sw1p2.getNumber());
283 assertEquals(KVPort.STATUS.ACTIVE, sw1p2.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700284
Ray Milkey269ffb92014-04-03 14:43:30 -0700285 sw2p1.update();
286 assertNotEquals(VERSION_NONEXISTENT, sw2p1.getVersion());
287 assertEquals(DPID2, sw2p1.getDpid());
288 assertEquals(SW2_PORTNO1, sw2p1.getNumber());
289 assertEquals(KVPort.STATUS.ACTIVE, sw2p1.getStatus());
290 } catch (ObjectDoesntExistException | WrongVersionException e) {
291 e.printStackTrace();
292 fail("Port update failed " + e);
293 }
294 } catch (ObjectExistsException e) {
295 e.printStackTrace();
296 fail("Link creation failed " + e);
297 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700298 }
299
300
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700301 private static void topologyWalk() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700302 Iterable<KVSwitch> swIt = KVSwitch.getAllSwitches();
303 List<Long> switchesExpected = new ArrayList<>(Arrays.asList(DPID1, DPID2));
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700304
Ray Milkey269ffb92014-04-03 14:43:30 -0700305 System.out.println("Enumerating Switches start");
306 for (KVSwitch sw : swIt) {
307 System.out.println(sw + " @ " + sw.getVersion());
308 assertNotEquals(VERSION_NONEXISTENT, sw.getVersion());
309 assertEquals(KVSwitch.STATUS.ACTIVE, sw.getStatus());
310 assertThat(sw.getDpid(), is(anyOf(equalTo(DPID1), equalTo(DPID2))));
311 assertThat(switchesExpected, hasItem(sw.getDpid()));
312 switchesExpected.remove(sw.getDpid());
313 }
314 System.out.println("Enumerating Switches end");
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700315
Ray Milkey269ffb92014-04-03 14:43:30 -0700316 KVSwitch sw1 = new KVSwitch(DPID1);
317 try {
318 sw1.read();
319 assertNotEquals(VERSION_NONEXISTENT, sw1.getVersion());
320 assertEquals(DPID1, sw1.getDpid());
321 assertEquals(KVSwitch.STATUS.ACTIVE, sw1.getStatus());
322 } catch (ObjectDoesntExistException e) {
323 e.printStackTrace();
324 fail("Reading switch failed " + e);
325 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700326
Ray Milkey269ffb92014-04-03 14:43:30 -0700327 KVSwitch sw2 = new KVSwitch(DPID2);
328 if (KVObject.multiRead(Arrays.asList(sw2))) {
329 fail("Failed to read switch " + sw2);
330 } else {
331 assertNotEquals(VERSION_NONEXISTENT, sw2.getVersion());
332 assertEquals(DPID2, sw2.getDpid());
333 assertEquals(KVSwitch.STATUS.ACTIVE, sw2.getStatus());
334 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700335
336
Ray Milkey269ffb92014-04-03 14:43:30 -0700337 // DPID -> [port_no]
338 @SuppressWarnings("serial")
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700339 Map<Long, List<Long>> expectedPorts = new HashMap<Long, List<Long>>() { {
Ray Milkey269ffb92014-04-03 14:43:30 -0700340 put(DPID1, new ArrayList<>(Arrays.asList(SW1_PORTNO1, SW1_PORTNO2)));
341 put(DPID2, new ArrayList<>(Arrays.asList(SW2_PORTNO1, SW2_PORTNO2)));
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700342 } };
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700343
Ray Milkey269ffb92014-04-03 14:43:30 -0700344 for (KVPort port : KVPort.getAllPorts()) {
345 System.out.println(port + " @ " + port.getVersion());
346 assertNotEquals(VERSION_NONEXISTENT, port.getVersion());
347 assertEquals(KVPort.STATUS.ACTIVE, port.getStatus());
348 assertThat(port.getDpid(), is(anyOf(equalTo(DPID1), equalTo(DPID2))));
349 assertThat(port.getNumber(), is(anyOf(equalTo(SW1_PORTNO1), equalTo(SW1_PORTNO2))));
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700350
Ray Milkey269ffb92014-04-03 14:43:30 -0700351 assertThat(expectedPorts, hasKey(port.getDpid()));
352 assertThat(expectedPorts.get(port.getDpid()), hasItem(port.getNumber()));
353 expectedPorts.get(port.getDpid()).remove(port.getNumber());
354 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700355
Ray Milkey269ffb92014-04-03 14:43:30 -0700356 // DeviceID -> PortID
357 @SuppressWarnings("serial")
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700358 Map<byte[], byte[]> expectedDevice = new TreeMap<byte[], byte[]>(ByteArrayComparator.BYTEARRAY_COMPARATOR) { {
Ray Milkey269ffb92014-04-03 14:43:30 -0700359 put(DEVICE1_MAC_SW1P1, KVPort.getPortID(DPID1, SW1_PORTNO1));
360 put(DEVICE2_MAC_SW2P2, KVPort.getPortID(DPID2, SW2_PORTNO2));
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700361 } };
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700362
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 for (KVDevice device : KVDevice.getAllDevices()) {
364 System.out.println(device + " @ " + device.getVersion());
365 assertNotEquals(VERSION_NONEXISTENT, device.getVersion());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700366
Ray Milkey269ffb92014-04-03 14:43:30 -0700367 assertThat(expectedDevice, hasKey(device.getMac()));
368 assertThat(device.getAllPortIds(), hasItem(expectedDevice.get(device.getMac())));
369 expectedDevice.remove(device.getMac());
370 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700371
Ray Milkey269ffb92014-04-03 14:43:30 -0700372 for (KVLink link : KVLink.getAllLinks()) {
373 System.out.println(link + " @ " + link.getVersion());
374 assertNotEquals(VERSION_NONEXISTENT, link.getVersion());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700375
Ray Milkey269ffb92014-04-03 14:43:30 -0700376 // there is currently only 1 link SW1P2->SW2P1
377 assertEquals(DPID1, link.getSrc().dpid);
378 assertEquals(SW1_PORTNO2, link.getSrc().number);
379 assertEquals(DPID2, link.getDst().dpid);
380 assertEquals(SW2_PORTNO1, link.getDst().number);
381 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700382
383 }
384
385
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700386 private static void topologyDelete() {
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700387
Ray Milkey269ffb92014-04-03 14:43:30 -0700388 for (KVSwitch sw : KVSwitch.getAllSwitches()) {
389 try {
390 sw.read();
391 sw.delete();
392 assertNotEquals(VERSION_NONEXISTENT, sw.getVersion());
393 } catch (ObjectDoesntExistException | WrongVersionException e) {
394 e.printStackTrace();
395 fail("Delete Switch Failed " + e);
396 }
397 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700398
Ray Milkey269ffb92014-04-03 14:43:30 -0700399 for (KVPort p : KVPort.getAllPorts()) {
400 try {
401 p.read();
402 p.delete();
403 assertNotEquals(VERSION_NONEXISTENT, p.getVersion());
404 } catch (ObjectDoesntExistException | WrongVersionException e) {
405 e.printStackTrace();
406 fail("Delete Port Failed " + e);
407 }
408 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700409
Ray Milkey269ffb92014-04-03 14:43:30 -0700410 for (KVDevice d : KVDevice.getAllDevices()) {
411 d.forceDelete();
412 assertNotEquals(VERSION_NONEXISTENT, d.getVersion());
413 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700414
Ray Milkey269ffb92014-04-03 14:43:30 -0700415 for (KVLink l : KVLink.getAllLinks()) {
416 try {
417 l.read();
418 l.delete();
419 assertNotEquals(VERSION_NONEXISTENT, l.getVersion());
420 } catch (ObjectDoesntExistException | WrongVersionException e) {
421 e.printStackTrace();
422 fail("Delete Link Failed " + e);
423 }
424 }
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700425 }
426
427 public static void main(final String[] argv) {
428
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -0700429 topologySetup();
430 topologyWalk();
431 topologyDelete();
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700432
Ray Milkey269ffb92014-04-03 14:43:30 -0700433 System.exit(0);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -0700434 }
435
436}