Merge "Add ovsdb/netvirt ui to vpnservice netvirt code."
[netvirt.git] / vpnservice / it / src / test / java / org / opendaylight / netvirt / it / NetvirtIT.java
index d140ea02f66593b73c2327621c2577324f0af8a4..66cd0cc560bc46e95559610ca450ad5553078d38 100644 (file)
@@ -22,14 +22,16 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRunti
 
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicBoolean;
+import javax.inject.Inject;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
+import org.opendaylight.netvirt.it.NetvirtITConstants.DefaultFlow;
+import org.opendaylight.netvirt.utils.netvirt.it.utils.FlowITUtil;
 import org.opendaylight.netvirt.utils.netvirt.it.utils.NetITUtil;
-import org.opendaylight.netvirt.vpnmanager.VpnserviceProvider;
 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.DockerOvs;
 import org.opendaylight.ovsdb.utils.ovsdb.it.utils.NodeInfo;
@@ -49,6 +51,7 @@ import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,13 +69,15 @@ public class NetvirtIT extends AbstractMdsalTestBase {
     private static OvsdbItUtils itUtils;
     private static MdsalUtils mdsalUtils = null;
     private static SouthboundUtils southboundUtils;
+    private static FlowITUtil flowITUtil;
     private static String addressStr;
     private static String portStr;
     private static String connectionType;
     private static String controllerStr;
     private static AtomicBoolean setup = new AtomicBoolean(false);
-    private static DataBroker dataBroker = null;
     private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
+    @Inject @Filter(timeout=60000)
+    private static DataBroker dataBroker = null;
 
     @Override
     public String getModuleName() {
@@ -167,16 +172,13 @@ public class NetvirtIT extends AbstractMdsalTestBase {
         Thread.sleep(10*1000);
         getProperties();
 
-        // get the dataBroker
-        dataBroker = VpnserviceProvider.getDataBroker();
         assertNotNull("dataBroker should not be null", dataBroker);
         itUtils = new OvsdbItUtils(dataBroker);
         mdsalUtils = new MdsalUtils(dataBroker);
         assertNotNull("mdsalUtils should not be null", mdsalUtils);
         southboundUtils = new SouthboundUtils(mdsalUtils);
         assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, this.getNetvirtTopology());
-
-//      TODO: need to implement new pipelineOrchestrator for the vpnservice pipeline
+        flowITUtil = new FlowITUtil(dataBroker);
 
         setup.set(true);
     }
@@ -219,6 +221,17 @@ public class NetvirtIT extends AbstractMdsalTestBase {
         return found;
     }
 
+    private void validateDefaultFlows(long datapathId, int timeout){
+        LOG.info("Validating default flows");
+        for (DefaultFlow defaultFlow : DefaultFlow.values()){
+            try {
+                flowITUtil.verifyFlowByFields(datapathId, defaultFlow.getFlowId(), defaultFlow.getTableId(), timeout);
+            } catch (Exception e){
+                LOG.error("Failed to verify flow id : {}", defaultFlow.getFlowId());
+                fail();
+            }
+        }
+    }
 
     /**
      * Test for basic southbound events to netvirt.
@@ -239,6 +252,9 @@ public class NetvirtIT extends AbstractMdsalTestBase {
             NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
             nodeInfo.connect();
 
+            //validate default flows
+            validateDefaultFlows(nodeInfo.datapathId, 60*1000);
+
             LOG.info("testNetVirt: should be connected: {}", nodeInfo.ovsdbNode.getNodeId());
 
             southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, NetvirtITConstants.PORT_NAME,
@@ -271,8 +287,8 @@ public class NetvirtIT extends AbstractMdsalTestBase {
             NodeInfo nodeInfo = itUtils.createNodeInfo(connectionInfo, null);
             nodeInfo.connect();
 
-            // waiting for the default flows to be installed before adding the ports
-            Thread.sleep(20*100);
+            //validate default flows
+            validateDefaultFlows(nodeInfo.datapathId, 60*1000);
 
             //create the neutron objects
             NetITUtil net = new NetITUtil(ovs, southboundUtils, mdsalUtils);
@@ -280,8 +296,6 @@ public class NetvirtIT extends AbstractMdsalTestBase {
             String port1 = net.createPort(nodeInfo.bridgeNode);
             String port2 = net.createPort(nodeInfo.bridgeNode);
 
-//          TODO - need to add pipeline validation
-
             Thread.sleep(1000);
 
             //ovs interface configuration for running the ping test