Bug 8055: remove all unused imports
[ovsdb.git] / hwvtepsouthbound / hwvtepsouthbound-it / src / test / java / org / opendaylight / ovsdb / hwvtepsouthbound / it / HwvtepSouthboundIT.java
1 /*
2  * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.ovsdb.hwvtepsouthbound.it;
9
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12 import static org.ops4j.pax.exam.CoreOptions.composite;
13 import static org.ops4j.pax.exam.CoreOptions.maven;
14 import static org.ops4j.pax.exam.CoreOptions.vmOption;
15 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
16 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
17
18 import java.lang.annotation.Annotation;
19 import java.lang.reflect.Method;
20 import java.net.InetAddress;
21 import java.net.UnknownHostException;
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Properties;
26 import java.util.Set;
27
28 import javax.annotation.Nullable;
29 import javax.inject.Inject;
30
31 import org.junit.After;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
38 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
39 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
40 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
41 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
42 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
43 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
44 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
45 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
46 import org.opendaylight.ovsdb.utils.hwvtepsouthbound.utils.HwvtepSouthboundUtils;
47 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalRef;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentationBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfoBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.ManagementIps;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelIps;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
65 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
66 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
67 import org.ops4j.pax.exam.Configuration;
68 import org.ops4j.pax.exam.Option;
69 import org.ops4j.pax.exam.junit.PaxExam;
70 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
71 import org.ops4j.pax.exam.options.MavenUrlReference;
72 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
73 import org.ops4j.pax.exam.spi.reactors.PerClass;
74 import org.ops4j.pax.exam.util.Filter;
75 import org.osgi.framework.BundleContext;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
78
79 @RunWith(PaxExam.class)
80 @ExamReactorStrategy(PerClass.class)
81 public class HwvtepSouthboundIT extends AbstractMdsalTestBase {
82     private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundIT.class);
83
84     //Constants
85
86     public static final String ORG_OPS4J_PAX_LOGGING_CFG = "etc/org.ops4j.pax.logging.cfg";
87     public static final String CUSTOM_PROPERTIES = "etc/custom.properties";
88     public static final String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
89     public static final String DEFAULT_SERVER_IPADDRESS = "127.0.0.1";
90     public static final String SERVER_PORT = "ovsdbserver.port";
91     public static final String DEFAULT_SERVER_PORT = "6640";
92     public static final String CONNECTION_TYPE = "ovsdbserver.connection";
93     public static final String CONNECTION_TYPE_ACTIVE = "active";
94     public static final String CONNECTION_TYPE_PASSIVE = "passive";
95     public static final int CONNECTION_INIT_TIMEOUT = 10000;
96     public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
97     private static final String PS_NAME = "ps0";
98
99     private static final int OVSDB_UPDATE_TIMEOUT = 1000;
100     private static final int OVSDB_ROUNDTRIP_TIMEOUT = 10000;
101
102     private static MdsalUtils mdsalUtils = null;
103     private static boolean setup = false;
104     private static int testMethodsRemaining;
105     private static String addressStr;
106     private static int portNumber;
107     private static String connectionType;
108     private static Node hwvtepNode;
109     @Inject @Filter(timeout=60000)
110     private static DataBroker dataBroker = null;
111     @Inject
112     private BundleContext bundleContext;
113
114     private static final NotifyingDataChangeListener OPERATIONAL_LISTENER =
115             new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL);
116
117     private static class NotifyingDataChangeListener implements DataTreeChangeListener<Node> {
118         private final LogicalDatastoreType type;
119         private final Set<InstanceIdentifier<Node>> createdNodes = new HashSet<>();
120         private final Set<InstanceIdentifier<Node>> removedNodes = new HashSet<>();
121         private final Set<InstanceIdentifier<Node>> updatedNodes = new HashSet<>();
122
123         private NotifyingDataChangeListener(LogicalDatastoreType type) {
124             this.type = type;
125         }
126
127         @Override
128         public void onDataTreeChanged(Collection<DataTreeModification<Node>> changes) {
129             for (DataTreeModification<Node> change : changes) {
130                 final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
131                 final DataObjectModification<Node> mod = change.getRootNode();
132                     switch (mod.getModificationType()) {
133                     case DELETE:
134                         removedNodes.add(key);
135                         break;
136                     case SUBTREE_MODIFIED:
137                         updatedNodes.add(key);
138                         break;
139                     case WRITE:
140                         if (mod.getDataBefore() == null) {
141                             LOG.trace("Data added: {}", mod.getDataAfter());
142                             createdNodes.add(key);
143                         } else {
144                             updatedNodes.add(key);
145                         }
146                         break;
147                     default:
148                         throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
149                     }
150             }
151         }
152
153         public boolean isCreated(InstanceIdentifier<Node> iid) {
154             return createdNodes.remove(iid);
155         }
156
157         public boolean isRemoved(InstanceIdentifier<Node> iid) {
158             return removedNodes.remove(iid);
159         }
160
161         public boolean isUpdated(InstanceIdentifier<Node> iid) {
162             return updatedNodes.remove(iid);
163         }
164     }
165
166     @Configuration
167     public Option[] config() {
168         Option[] options = super.config();
169         Option[] propertyOptions = getPropertiesOptions();
170         Option[] otherOptions = getOtherOptions();
171         Option[] combinedOptions = new Option[options.length + propertyOptions.length + otherOptions.length];
172         System.arraycopy(options, 0, combinedOptions, 0, options.length);
173         System.arraycopy(propertyOptions, 0, combinedOptions, options.length, propertyOptions.length);
174         System.arraycopy(otherOptions, 0, combinedOptions, options.length + propertyOptions.length,
175                 otherOptions.length);
176         return combinedOptions;
177     }
178
179     private Option[] getOtherOptions() {
180         return new Option[] {
181                 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
182                 keepRuntimeFolder()
183         };
184     }
185
186     @Override
187     public String getKarafDistro() {
188         return maven()
189                 .groupId("org.opendaylight.ovsdb")
190                 .artifactId("hwvtepsouthbound-karaf")
191                 .versionAsInProject()
192                 .type("zip")
193                 .getURL();
194     }
195
196     @Override
197     public MavenUrlReference getFeatureRepo() {
198         return maven()
199                 .groupId("org.opendaylight.ovsdb")
200                 .artifactId("hwvtepsouthbound-features")
201                 .classifier("features")
202                 .type("xml")
203                 .versionAsInProject();
204     }
205
206     @Override
207     public String getFeatureName() {
208         return "odl-ovsdb-hwvtepsouthbound-test";
209     }
210
211     protected String usage() {
212         return "Integration Test needs a valid connection configuration as follows :\n"
213                 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
214                 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
215     }
216
217     @Override
218     public Option getLoggingOption() {
219         Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
220                 logConfiguration(HwvtepSouthboundIT.class),
221                 LogLevel.INFO.name());
222         option = composite(option, super.getLoggingOption());
223         return option;
224     }
225
226     private Option[] getPropertiesOptions() {
227         Properties props = new Properties(System.getProperties());
228         String addressStr = props.getProperty(SERVER_IPADDRESS, DEFAULT_SERVER_IPADDRESS);
229         String portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
230         String connectionType = props.getProperty(CONNECTION_TYPE, CONNECTION_TYPE_ACTIVE);
231
232         LOG.info("getPropertiesOptions: Using the following properties: mode= {}, ip:port= {}:{}",
233                 connectionType, addressStr, portStr);
234
235         return new Option[] {
236                 editConfigurationFilePut(CUSTOM_PROPERTIES, SERVER_IPADDRESS, addressStr),
237                 editConfigurationFilePut(CUSTOM_PROPERTIES, SERVER_PORT, portStr),
238                 editConfigurationFilePut(CUSTOM_PROPERTIES, CONNECTION_TYPE, connectionType),
239         };
240     }
241
242     @Before
243     @Override
244     public void setup() throws InterruptedException {
245         if (setup) {
246             LOG.info("Skipping setup, already initialized");
247             return;
248         }
249
250         try {
251             super.setup();
252         } catch (Exception e) {
253             LOG.warn("Failed to setup test", e);
254             fail("Failed to setup test: " + e);
255         }
256
257         addressStr = bundleContext.getProperty(SERVER_IPADDRESS);
258         String portStr = bundleContext.getProperty(SERVER_PORT);
259         try {
260             portNumber = Integer.parseInt(portStr);
261         } catch (NumberFormatException e) {
262             fail("Invalid port number " + portStr + System.lineSeparator() + usage() + e);
263         }
264
265         connectionType = bundleContext.getProperty(CONNECTION_TYPE);
266
267         LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}",
268                 connectionType, addressStr, portNumber);
269         if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
270             if (addressStr == null) {
271                 fail(usage());
272             }
273         }
274
275         mdsalUtils = new MdsalUtils(dataBroker);
276         assertTrue("Did not find " + HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue(), getHwvtepTopology());
277         final ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
278         final InstanceIdentifier<Node> iid = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo);
279         final DataTreeIdentifier<Node> treeId =
280                         new DataTreeIdentifier<Node>(LogicalDatastoreType.OPERATIONAL, iid);
281
282         dataBroker.registerDataTreeChangeListener(treeId, OPERATIONAL_LISTENER);
283
284         hwvtepNode = connectHwvtepNode(connectionInfo);
285         // Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is
286         // useless with pax-exam)
287         for (Method method : getClass().getMethods()) {
288             boolean testMethod = false;
289             boolean ignoreMethod = false;
290             for (Annotation annotation : method.getAnnotations()) {
291                 if (Test.class.equals(annotation.annotationType())) {
292                     testMethod = true;
293                 }
294                 if (Ignore.class.equals(annotation.annotationType())) {
295                     ignoreMethod = true;
296                 }
297             }
298             if (testMethod && !ignoreMethod) {
299                 testMethodsRemaining++;
300             }
301         }
302         LOG.info("{} test methods to run", testMethodsRemaining);
303
304         setup = true;
305     }
306
307     private Boolean getHwvtepTopology() {
308         LOG.info("getHwvtepTopology: looking for {}...", HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
309         Boolean found = false;
310         final TopologyId topologyId = HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID;
311         InstanceIdentifier<Topology> path =
312                 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
313         for (int i = 0; i < 60; i++) {
314             Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
315             if (topology != null) {
316                 LOG.info("getHwvtepTopology: found {}...", HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
317                 found = true;
318                 break;
319             } else {
320                 LOG.info("getHwvtepTopology: still looking ({})...", i);
321                 try {
322                     Thread.sleep(1000);
323                 } catch (InterruptedException e) {
324                     LOG.warn("Interrupted while waiting for {}",
325                             HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue(), e);
326                 }
327             }
328         }
329         return found;
330     }
331
332     private Node connectHwvtepNode(ConnectionInfo connectionInfo) throws InterruptedException {
333         final InstanceIdentifier<Node> iid = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo);
334         Assert.assertTrue(mdsalUtils.put(LogicalDatastoreType.CONFIGURATION,
335                         iid, HwvtepSouthboundUtils.createNode(connectionInfo)));
336         waitForOperationalCreation(iid);
337         Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid);
338         Assert.assertNotNull(node);
339         LOG.info("Connected to {}", HwvtepSouthboundUtils.connectionInfoToString(connectionInfo));
340         return node;
341     }
342
343     private static void disconnectHwvtepNode(final ConnectionInfo connectionInfo) throws InterruptedException {
344         final InstanceIdentifier<Node> iid = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo);
345         Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
346         waitForOperationalDeletion(iid);
347         Node node = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, iid);
348         Assert.assertNull(node);
349         LOG.info("Disconnected from {}", HwvtepSouthboundUtils.connectionInfoToString(connectionInfo));
350     }
351
352     private void waitForOperationalCreation(InstanceIdentifier<Node> iid) throws InterruptedException {
353         synchronized (OPERATIONAL_LISTENER) {
354             long _start = System.currentTimeMillis();
355             LOG.info("Waiting for OPERATIONAL DataChanged creation on {}", iid);
356             while (!OPERATIONAL_LISTENER.isCreated(
357                     iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
358                 OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
359             }
360             LOG.info("Woke up, waited {} for creation of {}", (System.currentTimeMillis() - _start), iid);
361         }
362     }
363
364     private static void waitForOperationalDeletion(InstanceIdentifier<Node> iid) throws InterruptedException {
365         synchronized (OPERATIONAL_LISTENER) {
366             long _start = System.currentTimeMillis();
367             LOG.info("Waiting for OPERATIONAL DataChanged deletion on {}", iid);
368             while (!OPERATIONAL_LISTENER.isRemoved(
369                     iid) && (System.currentTimeMillis() - _start) < OVSDB_ROUNDTRIP_TIMEOUT) {
370                 OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
371             }
372             LOG.info("Woke up, waited {} for deletion of {}", (System.currentTimeMillis() - _start), iid);
373         }
374     }
375
376     private ConnectionInfo getConnectionInfo(String addressStr, int portNumber) {
377         InetAddress inetAddress = null;
378         try {
379             inetAddress = InetAddress.getByName(addressStr);
380         } catch (UnknownHostException e) {
381             fail("Could not resolve " + addressStr + ": " + e);
382         }
383
384         IpAddress address = HwvtepSouthboundMapper.createIpAddress(inetAddress);
385         PortNumber port = new PortNumber(portNumber);
386
387         final ConnectionInfo connectionInfo = new ConnectionInfoBuilder()
388                 .setRemoteIp(address)
389                 .setRemotePort(port)
390                 .build();
391         LOG.info("connectionInfo: {}", connectionInfo);
392         return connectionInfo;
393     }
394
395     private static class TestPhysicalSwitch implements AutoCloseable {
396         private final ConnectionInfo connectionInfo;
397         private final String psName;
398
399
400         public TestPhysicalSwitch(final ConnectionInfo connectionInfo, String psName) {
401             this(connectionInfo, psName, null, null, null, true, null, null, null);
402         }
403
404         public TestPhysicalSwitch (final ConnectionInfo connectionInfo, final String name,
405                         @Nullable InstanceIdentifier<Node> psIid, @Nullable NodeId psNodeId,
406                         @Nullable final String description, final boolean setManagedBy,
407                         @Nullable final List<ManagementIps> managementIps,
408                         @Nullable final List<TunnelIps> tunnelIps,
409                         @Nullable final List<Tunnels> tunnels) {
410             this.connectionInfo = connectionInfo;
411             this.psName = name;
412             NodeBuilder psNodeBuilder = new NodeBuilder();
413             if(psIid == null) {
414                 psIid = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo, new HwvtepNodeName(psName));
415             }
416             if(psNodeId == null) {
417                 psNodeId = HwvtepSouthboundMapper.createManagedNodeId(psIid);
418             }
419             psNodeBuilder.setNodeId(psNodeId);
420             PhysicalSwitchAugmentationBuilder psAugBuilder = new PhysicalSwitchAugmentationBuilder();
421             psAugBuilder.setHwvtepNodeName(new HwvtepNodeName(psName));
422             if(description != null) {
423                 psAugBuilder.setHwvtepNodeDescription(description);
424             }
425             if(setManagedBy) {
426                 InstanceIdentifier<Node> nodePath = HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo);
427                 psAugBuilder.setManagedBy(new HwvtepGlobalRef(nodePath));
428             }
429             psAugBuilder.setManagementIps(managementIps);
430             psAugBuilder.setTunnelIps(tunnelIps);
431             psAugBuilder.setTunnels(tunnels);
432             psNodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, psAugBuilder.build());
433             LOG.debug("Built with intent to store PhysicalSwitch data {}", psAugBuilder.toString());
434             Assert.assertTrue(
435                             mdsalUtils.merge(LogicalDatastoreType.CONFIGURATION, psIid, psNodeBuilder.build()));
436                     try {
437                         Thread.sleep(OVSDB_UPDATE_TIMEOUT);
438                     } catch (InterruptedException e) {
439                         LOG.warn("Sleep interrupted while waiting for bridge creation (bridge {})", psName, e);
440                     }
441         }
442
443         @Override
444         public void close() {
445             final InstanceIdentifier<Node> iid =
446                             HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo, new HwvtepNodeName(psName));
447             Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
448             try {
449                 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
450             } catch (InterruptedException e) {
451                 LOG.warn("Sleep interrupted while waiting for bridge deletion (bridge {})", psName, e);
452             }
453         }
454     }
455
456     @After
457     public void teardown() {
458         testMethodsRemaining--;
459         LOG.info("{} test methods remaining", testMethodsRemaining);
460     }
461
462     @Test
463     public void testhwvtepsouthboundFeatureLoad() {
464         Assert.assertTrue(true);
465     }
466
467     @Test
468     public void testNetworkTopology() throws InterruptedException {
469         NetworkTopology networkTopology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION,
470                 InstanceIdentifier.create(NetworkTopology.class));
471         Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.CONFIGURATION,
472                 networkTopology);
473
474         networkTopology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL,
475                 InstanceIdentifier.create(NetworkTopology.class));
476         Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.OPERATIONAL,
477                 networkTopology);
478     }
479
480     @Test
481     public void testHwvtepTopology() throws InterruptedException {
482         InstanceIdentifier<Topology> path = InstanceIdentifier
483                 .create(NetworkTopology.class)
484                 .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID));
485
486         Topology topology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
487         Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.CONFIGURATION,
488                 topology);
489
490         topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
491
492         Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.OPERATIONAL,
493                 topology);
494     }
495
496     @Test
497     public void testAddDeleteHwvtepNode() throws InterruptedException {
498         ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
499         // At this point we're connected, disconnect and reconnect (the connection will be removed at the very end)
500         disconnectHwvtepNode(connectionInfo);
501         connectHwvtepNode(connectionInfo);
502     }
503
504     @Test
505     public void testAddDeletePhysicalSwitch() throws InterruptedException {
506         ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber);
507
508         try (TestPhysicalSwitch testPSwitch = new TestPhysicalSwitch(connectionInfo, PS_NAME)) {
509             PhysicalSwitchAugmentation pSwitch = getPhysicalSwitch(connectionInfo);
510             Assert.assertNotNull(pSwitch);
511             LOG.info("PhysicalSwitch: {}", pSwitch);
512         }
513     }
514
515     private PhysicalSwitchAugmentation getPhysicalSwitch(ConnectionInfo connectionInfo) {
516         return getPhysicalSwitch(connectionInfo, PS_NAME);
517     }
518
519     private PhysicalSwitchAugmentation getPhysicalSwitch(ConnectionInfo connectionInfo, String psName) {
520         return getPhysicalSwitch(connectionInfo, psName, LogicalDatastoreType.OPERATIONAL);
521     }
522
523     private PhysicalSwitchAugmentation getPhysicalSwitch(ConnectionInfo connectionInfo, String psName,
524                     LogicalDatastoreType dataStore) {
525         Node psNode = getPhysicalSwitchNode(connectionInfo, psName, dataStore);
526         Assert.assertNotNull(psNode);
527         PhysicalSwitchAugmentation psAugmentation = psNode.getAugmentation(PhysicalSwitchAugmentation.class);
528         Assert.assertNotNull(psAugmentation);
529         return psAugmentation;
530     }
531
532     private Node getPhysicalSwitchNode(ConnectionInfo connectionInfo, String psName, LogicalDatastoreType dataStore) {
533         InstanceIdentifier<Node> psIid =
534                         HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo, new HwvtepNodeName(psName));
535                 return mdsalUtils.read(dataStore, psIid);
536     }
537
538 }