14c6173394929a5bb96557fb4ca86281e0a50e40
[netvirt.git] / openstack / net-virt-sfc / it / src / test / java / org / opendaylight / netvirt / openstack / netvirt / sfc / it / NetvirtSfcIT.java
1 /*
2  * Copyright © 2015 Red Hat, Inc. 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
9 package org.opendaylight.netvirt.openstack.netvirt.sfc.it;
10
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
16 import static org.ops4j.pax.exam.CoreOptions.composite;
17 import static org.ops4j.pax.exam.CoreOptions.maven;
18 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
19 import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperties;
20 import static org.ops4j.pax.exam.CoreOptions.vmOption;
21 import static org.ops4j.pax.exam.CoreOptions.when;
22 import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
23 import static org.ops4j.pax.exam.MavenUtils.asInProject;
24 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
25 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
26 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
27
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Properties;
34 import java.util.concurrent.atomic.AtomicBoolean;
35
36 import org.junit.After;
37 import org.junit.Assert;
38 import org.junit.Before;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
43 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
44 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
45 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
46 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.AclUtils;
47 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.ClassifierUtils;
48 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.RenderedServicePathUtils;
49 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.ServiceFunctionChainUtils;
50 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.ServiceFunctionPathUtils;
51 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.ServiceFunctionUtils;
52 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.SfcConfigUtils;
53 import org.opendaylight.netvirt.openstack.netvirt.api.Southbound;
54 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.PipelineOrchestrator;
55 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
56 import org.opendaylight.netvirt.openstack.netvirt.sfc.NshUtils;
57 import org.opendaylight.netvirt.openstack.netvirt.sfc.SfcUtils;
58 import org.opendaylight.netvirt.openstack.netvirt.sfc.standalone.openflow13.SfcClassifier;
59 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.NetvirtConfigUtils;
60 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.ServiceFunctionForwarderUtils;
61 import org.opendaylight.netvirt.openstack.netvirt.sfc.it.utils.NetvirtSfcUtils;
62 import org.opendaylight.netvirt.openstack.netvirt.sfc.workaround.services.FlowNames;
63 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
64 import org.opendaylight.netvirt.utils.it.utils.ItUtils;
65 import org.opendaylight.netvirt.utils.mdsal.openflow.FlowUtils;
66 import org.opendaylight.netvirt.utils.mdsal.utils.MdsalUtils;
67 import org.opendaylight.netvirt.utils.servicehelper.ServiceHelper;
68 import org.opendaylight.netvirt.utils.it.utils.NodeInfo;
69 import org.opendaylight.ovsdb.utils.mdsal.utils.NotifyingDataChangeListener;
70 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
71 import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI;
72 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.RspName;
73 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.common.rev151017.SftType;
74 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.CreateRenderedPathInputBuilder;
75 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.RenderedServicePaths;
76 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
77 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePathKey;
78 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.rendered.service.path.RenderedServicePathHop;
79 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctions;
80 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctionsBuilder;
81 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
82 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChains;
84 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChainsBuilder;
85 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
86 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChainBuilder;
87 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
88 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionBuilder;
89 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwarders;
90 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwardersBuilder;
91 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
92 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarderBuilder;
93 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPaths;
94 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPathsBuilder;
95 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
96 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathBuilder;
97 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfig;
98 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.sfc.of.renderer.rev151123.SfcOfRendererConfigBuilder;
99 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
100 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessListsBuilder;
101 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.AclBuilder;
102 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.AccessListEntriesBuilder;
103 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.AceBuilder;
104 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.ActionsBuilder;
105 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.MatchesBuilder;
106 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
107 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
108 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.providers.config.rev160109.NetvirtProvidersConfig;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.providers.config.rev160109.NetvirtProvidersConfigBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.Classifiers;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.ClassifiersBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.ClassifierBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.SffsBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.sffs.SffBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.Sfc;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.SfcBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
124 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
125 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
126 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
127 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
128 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
129 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
130 import org.opendaylight.yangtools.concepts.Builder;
131 import org.opendaylight.yangtools.yang.binding.DataObject;
132 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
133 import org.ops4j.pax.exam.Configuration;
134 import org.ops4j.pax.exam.Option;
135 import org.ops4j.pax.exam.junit.PaxExam;
136 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
137 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
138 import org.ops4j.pax.exam.options.MavenUrlReference;
139 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
140 import org.ops4j.pax.exam.spi.reactors.PerClass;
141 import org.slf4j.Logger;
142 import org.slf4j.LoggerFactory;
143
144 import com.google.common.collect.Maps;
145
146 @RunWith(PaxExam.class)
147 @ExamReactorStrategy(PerClass.class)
148 public class NetvirtSfcIT extends AbstractMdsalTestBase {
149     private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcIT.class);
150     private static AclUtils aclUtils = new AclUtils();
151     private static ClassifierUtils classifierUtils = new ClassifierUtils();
152     private static NetvirtSfcUtils netvirtSfcUtils = new NetvirtSfcUtils();
153     private static ServiceFunctionUtils serviceFunctionUtils = new ServiceFunctionUtils();
154     private static ServiceFunctionForwarderUtils serviceFunctionForwarderUtils = new ServiceFunctionForwarderUtils();
155     private static ServiceFunctionChainUtils serviceFunctionChainUtils = new ServiceFunctionChainUtils();
156     private static ServiceFunctionPathUtils serviceFunctionPathUtils = new ServiceFunctionPathUtils();
157     private static RenderedServicePathUtils renderedServicePathUtils = new RenderedServicePathUtils();
158     private static SfcConfigUtils sfcConfigUtils = new SfcConfigUtils();
159     private static NetvirtConfigUtils netvirtConfigUtils = new NetvirtConfigUtils();
160     private static MdsalUtils mdsalUtils;
161     private static AtomicBoolean setup = new AtomicBoolean(false);
162     private static SouthboundUtils southboundUtils;
163     private static SfcUtils sfcUtils;
164     private static String addressStr;
165     private static String portStr;
166     private static String connectionType;
167     private static String controllerStr;
168     private static boolean ovsdb_wait = false;
169     private static String userSpaceEnabled = "no";
170     private static PipelineOrchestrator pipelineOrchestrator;
171     private static Southbound southbound;
172     private static DataBroker dataBroker;
173     private static ItUtils itUtils;
174     public static final String CONTROLLER_IPADDRESS = "ovsdb.controller.address";
175     public static final String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
176     public static final String SERVER_PORT = "ovsdbserver.port";
177     public static final String CONNECTION_TYPE = "ovsdbserver.connection";
178     public static final String CONNECTION_TYPE_ACTIVE = "active";
179     public static final String CONNECTION_TYPE_PASSIVE = "passive";
180     public static final String DEFAULT_SERVER_PORT = "6640";
181     public static final String USERSPACE_ENABLED = "ovsdb.userspace.enabled";
182     public static final String INTEGRATION_BRIDGE_NAME = "br-int";
183     private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
184     private static final String OVSDB_TRACE = "ovsdb.trace";
185     private static final String OVSDB_WAIT = "ovsdb.wait";
186     private static final String SF1NAME = "firewall-72";
187     private static final String SF2NAME = "dpi-72";
188     private static final String SF1IP = "10.2.1.1";//"192.168.50.70";//"192.168.120.31";
189     private static final String SF2IP = "10.2.1.2";
190     private static final String SF1DPLNAME = "sf1";
191     private static final String SF2DPLNAME = "sf2";
192     // Use 192.168.50.70 when running against vagrant vm for workaround testing, eg. netvirtsfc-env.
193     // Use 192.168.1.129 (or whatever address is dhcp'ed) for tacker-vm.
194     // "192.168.50.70"; "127.0.0.1"; "192.168.1.129";
195     private static final String SFF1IP = "192.168.50.70";
196     private static final String SFF2IP = "127.0.0.1";
197     private static final String SFF1NAME = "sff1";
198     private static final String SFF2NAME = "sff2";
199     private static final String SFFDPL1NAME = "vxgpe";
200     private static final String SFFDPL2NAME = "vxgpe";
201     private static final String SN1NAME = "ovsdb1";
202     private static final String SN2NAME = "ovsdb2";
203     private static final String BRIDGE1NAME= "br-int";
204     private static final String BRIDGE2NAME= "br-int";
205     private static final String ACLNAME= "httpAcl";
206     private static final String RULENAME= "httpRule";
207     private static final String SFCNAME = "SFC";
208     private static final String SFCPATH = "SFC-Path";
209     private static final String RSPNAME = SFCPATH + "_rsp";
210     private static final String SFCSF1NAME = "firewall-abstract";
211     private static final SftType SFCSF1TYPE = new SftType("firewall");
212     private static final int GPEUDPPORT = 6633;
213
214     @Override
215     public String getModuleName() {
216         return "netvirt-sfc-impl";
217     }
218
219     @Override
220     public String getInstanceName() {
221         return "netvirt-sfc-impl";
222     }
223
224     @Override
225     public MavenUrlReference getFeatureRepo() {
226         return maven()
227                 .groupId("org.opendaylight.netvirt")
228                 .artifactId("openstack.net-virt-sfc-features")
229                 .classifier("features")
230                 .type("xml")
231                 .versionAsInProject();
232     }
233
234     @Override
235     public String getFeatureName() {
236         return "odl-ovsdb-sfc-test";
237     }
238
239     @Configuration
240     @Override
241     public Option[] config() {
242         Option[] parentOptions = super.config();
243         Option[] propertiesOptions = getPropertiesOptions();
244         Option[] otherOptions = getOtherOptions();
245         Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
246         System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
247         System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
248         System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
249                 otherOptions.length);
250         return options;
251     }
252
253     private Option[] getOtherOptions() {
254         return new Option[] {
255                 wrappedBundle(
256                         mavenBundle("org.opendaylight.netvirt", "utils.mdsal-openflow")
257                                 .version(asInProject())
258                                 .type("jar")),
259                 configureConsole().startLocalConsole(),
260                 //vmOption("-verbose:class"),
261                 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
262                 keepRuntimeFolder()
263         };
264     }
265
266     public Option[] getPropertiesOptions() {
267         return new Option[] {
268                 propagateSystemProperties(SERVER_IPADDRESS, SERVER_PORT, CONNECTION_TYPE,
269                         CONTROLLER_IPADDRESS, OVSDB_TRACE, OVSDB_WAIT, USERSPACE_ENABLED),
270         };
271     }
272
273     @Override
274     public Option getLoggingOption() {
275         return composite(
276                 when(Boolean.getBoolean(OVSDB_TRACE)).useOptions(
277                         editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
278                                 "log4j.logger.org.opendaylight.ovsdb",
279                                 LogLevelOption.LogLevel.TRACE.name())),
280                 //editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
281                 //        "log4j.logger.org.opendaylight.ovsdb",
282                 //        LogLevelOption.LogLevel.TRACE.name()),
283                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
284                         "log4j.logger.org.opendaylight.ovsdb.library",
285                         LogLevel.INFO.name()),
286                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
287                         logConfiguration(NetvirtSfcIT.class),
288                         LogLevel.INFO.name()),
289                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
290                         "log4j.logger.org.opendaylight.netvirt.openstack.netvirt.sfc",
291                         LogLevel.TRACE.name()),
292                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
293                         "log4j.logger.org.opendaylight.netvirt.openstack.netvirt.providers.openflow13",
294                         LogLevel.TRACE.name()),
295                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
296                         "log4j.logger.org.opendaylight.sfc",
297                         LogLevel.TRACE.name()),
298                 super.getLoggingOption());
299     }
300
301     protected String usage() {
302         return "Integration Test needs a valid connection configuration as follows :\n"
303                 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
304                 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
305     }
306
307     private void getProperties() {
308         Properties props = System.getProperties();
309         addressStr = props.getProperty(SERVER_IPADDRESS);
310         portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
311         connectionType = props.getProperty(CONNECTION_TYPE, "active");
312         controllerStr = props.getProperty(CONTROLLER_IPADDRESS, "0.0.0.0");
313         userSpaceEnabled = props.getProperty(USERSPACE_ENABLED, "no");
314         LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}, controller ip: {}, " +
315                         "userspace.enabled: {}",
316                 connectionType, addressStr, portStr, controllerStr, userSpaceEnabled);
317         if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
318             if (addressStr == null) {
319                 fail(usage());
320             }
321         }
322         LOG.info("getProperties {}: {}", OVSDB_TRACE, props.getProperty(OVSDB_TRACE));
323         LOG.info("getProperties {}: {}", OVSDB_WAIT, props.getProperty(OVSDB_WAIT));
324         if (props.getProperty(OVSDB_WAIT) != null && props.getProperty(OVSDB_WAIT).equals("true")) {
325             ovsdb_wait = true;
326         }
327     }
328
329     @Before
330     @Override
331     public void setup() {
332         if (setup.get()) {
333             LOG.info("Skipping setUp, already initialized");
334             return;
335         }
336
337         try {
338             Thread.sleep(1000);
339             super.setup();
340         } catch (Exception e) {
341             LOG.warn("Failed to setup test", e);
342             fail("Failed to setup test: " + e);
343         }
344
345         getProperties();
346
347         dataBroker = getDatabroker(getProviderContext());
348         itUtils = new ItUtils(dataBroker);
349         mdsalUtils = new MdsalUtils(dataBroker);
350         org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils sbMdsalUtils =
351                 new org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils(dataBroker);
352         assertNotNull("mdsalUtils should not be null", mdsalUtils);
353         southboundUtils = new SouthboundUtils(sbMdsalUtils);
354         sfcUtils = new SfcUtils(mdsalUtils);
355         assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
356         southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
357         assertNotNull("southbound should not be null", southbound);
358         pipelineOrchestrator =
359                 (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this);
360         assertNotNull("pipelineOrchestrator should not be null", pipelineOrchestrator);
361
362         setup.set(true);
363     }
364
365     @After
366     public void teardown() {
367         closeWaitFors();
368     }
369
370     private ProviderContext getProviderContext() {
371         ProviderContext providerContext = null;
372         for (int i=0; i < 60; i++) {
373             providerContext = getSession();
374             if (providerContext != null) {
375                 break;
376             } else {
377                 try {
378                     Thread.sleep(1000);
379                 } catch (InterruptedException e) {
380                     LOG.warn("Interrupted while waiting for provider context", e);
381                 }
382             }
383         }
384         assertNotNull("providercontext should not be null", providerContext);
385         /* One more second to let the provider finish initialization */
386         try {
387             Thread.sleep(1000);
388         } catch (InterruptedException e) {
389             LOG.warn("Interrupted while waiting for other provider", e);
390         }
391         return providerContext;
392     }
393
394     private DataBroker getDatabroker(ProviderContext providerContext) {
395         DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
396         assertNotNull("dataBroker should not be null", dataBroker);
397         return dataBroker;
398     }
399
400     private Boolean getNetvirtTopology() {
401         LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
402         Boolean found = false;
403         final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
404         InstanceIdentifier<Topology> path =
405                 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
406         for (int i = 0; i < 60; i++) {
407             Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
408             if (topology != null) {
409                 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
410                 found = true;
411                 break;
412             } else {
413                 LOG.info("getNetvirtTopology: still looking ({})...", i);
414                 try {
415                     Thread.sleep(1000);
416                 } catch (InterruptedException e) {
417                     LOG.warn("Interrupted while waiting for {}", NETVIRT_TOPOLOGY_ID, e);
418                 }
419             }
420         }
421         return found;
422     }
423
424     private AccessListsBuilder accessListsBuilder() {
425         return accessListsBuilder(false);
426     }
427
428     private AccessListsBuilder accessListsBuilder(boolean renderRsp) {
429         String ruleName = RULENAME;
430         String sfcName = SFCNAME;
431         MatchesBuilder matchesBuilder = aclUtils.matchesBuilder(new MatchesBuilder(), 80);
432         LOG.info("Matches: {}", matchesBuilder.build());
433         ActionsBuilder actionsBuilder = aclUtils.actionsBuilder(new ActionsBuilder(), sfcName, renderRsp);
434         AceBuilder accessListEntryBuilder =
435                 aclUtils.aceBuilder(new AceBuilder(), ruleName, matchesBuilder, actionsBuilder);
436         AccessListEntriesBuilder accessListEntriesBuilder =
437                 aclUtils.accessListEntriesBuidler(new AccessListEntriesBuilder(), accessListEntryBuilder);
438         AclBuilder accessListBuilder =
439                 aclUtils.aclBuilder(new AclBuilder(), ACLNAME, accessListEntriesBuilder);
440         AccessListsBuilder accessListsBuilder =
441                 aclUtils.accesslistsbuilder(new AccessListsBuilder(), accessListBuilder);
442         LOG.info("AccessLists: {}", accessListsBuilder.build());
443         return accessListsBuilder;
444     }
445
446     @Test
447     public void testAccessLists() throws InterruptedException {
448         testModel(accessListsBuilder(), AccessLists.class, 0);
449     }
450
451     private ClassifiersBuilder classifiersBuilder() {
452         SffBuilder sffBuilder = classifierUtils.sffBuilder(new SffBuilder(), SFF1NAME);
453         SffsBuilder sffsBuilder = classifierUtils.sffsBuilder(new SffsBuilder(), sffBuilder);
454         ClassifierBuilder classifierBuilder = classifierUtils.classifierBuilder(new ClassifierBuilder(),
455                 "classifierName", ACLNAME, sffsBuilder);
456         ClassifiersBuilder classifiersBuilder = classifierUtils.classifiersBuilder(new ClassifiersBuilder(),
457                 classifierBuilder);
458         LOG.info("Classifiers: {}", classifiersBuilder.build());
459         return classifiersBuilder;
460     }
461
462     @Test
463     public void testClassifiers() throws InterruptedException {
464         testModel(classifiersBuilder(), Classifiers.class, 0);
465     }
466
467     private SfcBuilder netvirtSfcBuilder() {
468         return netvirtSfcUtils.sfcBuilder(new SfcBuilder(), "sfc");
469     }
470
471     @Test
472     public void testNetvirtSfcModel() throws InterruptedException {
473         testModel(netvirtSfcBuilder(), Sfc.class, 0);
474     }
475
476     private <T extends DataObject> void testModelPut(Builder<T> builder, Class<T> clazz) {
477         InstanceIdentifier<T> path = InstanceIdentifier.create(clazz);
478         assertTrue(mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, path, builder.build()));
479         T result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
480         assertNotNull(clazz.getSimpleName() + " should not be null", result);
481     }
482
483     private <T extends DataObject> void testModelDelete(Builder<T> builder, Class<T> clazz)
484             throws InterruptedException {
485         InstanceIdentifier<T> path = InstanceIdentifier.create(clazz);
486         assertTrue("Failed to remove " + clazz.getSimpleName(),
487                 mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, path));
488         T result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
489         assertNull(clazz.getSimpleName() + " should be null", result);
490     }
491
492     private <T extends DataObject> void testModel(Builder<T> builder, Class<T> clazz, long wait)
493             throws InterruptedException {
494         testModelPut(builder, clazz);
495         Thread.sleep(wait);
496         testModelDelete(builder, clazz);
497     }
498
499     private <T extends DataObject> void testModel(Builder<T> builder, Class<T> clazz)
500             throws InterruptedException {
501         testModelPut(builder, clazz);
502         Thread.sleep(1000);
503         testModelDelete(builder, clazz);
504     }
505
506     private ServiceFunctionsBuilder serviceFunctionsBuilder() {
507         String sf1Name = SF1NAME;
508         String sf1Ip = SF1IP;
509         String sff1Name = SFF1NAME;
510         String sf1DplName = SF1DPLNAME;
511         int port = GPEUDPPORT;
512
513         ServiceFunctionBuilder serviceFunctionBuilder =
514                 serviceFunctionUtils.serviceFunctionBuilder(sf1Ip, port, sf1DplName, sff1Name, sf1Name);
515         List<ServiceFunction> serviceFunctionList = serviceFunctionUtils.list(
516                 new ArrayList<ServiceFunction>(), serviceFunctionBuilder);
517
518         ServiceFunctionsBuilder serviceFunctionsBuilder =
519                 serviceFunctionUtils.serviceFunctionsBuilder(new ServiceFunctionsBuilder(),
520                         serviceFunctionList);
521         LOG.info("ServiceFunctions: {}", serviceFunctionsBuilder.build());
522         return serviceFunctionsBuilder;
523     }
524
525     private ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder() {
526         return serviceFunctionForwardersBuilder(null);
527     }
528
529     private ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder(OvsdbNodeRef ovsdbNodeRef) {
530         String sf1Name = SF1NAME;
531         String sf1Ip = SF1IP;
532         String sf1DplName = SF1DPLNAME;
533         String sff1Ip = SFF1IP;
534         String sff1Name = SFF1NAME;
535         String sffDpl1Name = SFFDPL1NAME;
536         String sn1Name = SN1NAME;
537         String bridge1Name= BRIDGE1NAME;
538         int port = GPEUDPPORT;
539
540         ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder =
541                 serviceFunctionForwarderUtils.serviceFunctionForwarderBuilder(
542                         sff1Name, sff1Ip, port, sffDpl1Name, sf1Ip, sn1Name, bridge1Name, sf1Name, sf1DplName,
543                         ovsdbNodeRef);
544         List<ServiceFunctionForwarder>  serviceFunctionForwarderList = serviceFunctionForwarderUtils.list(
545                 new ArrayList<ServiceFunctionForwarder>(), serviceFunctionForwarderBuilder);
546
547         ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder =
548                 serviceFunctionForwarderUtils.serviceFunctionForwardersBuilder(
549                         new ServiceFunctionForwardersBuilder(), serviceFunctionForwarderList);
550         LOG.info("ServiceFunctionForwarders: {}", serviceFunctionForwardersBuilder.build());
551         return serviceFunctionForwardersBuilder;
552     }
553
554     private ServiceFunctionChainsBuilder serviceFunctionChainsBuilder() {
555         String sf1Name = SFCSF1NAME;
556         SftType sfType = SFCSF1TYPE;
557         String sfcName = SFCNAME;
558
559         SfcServiceFunctionBuilder sfcServiceFunctionBuilder = serviceFunctionChainUtils.sfcServiceFunctionBuilder(
560                 new SfcServiceFunctionBuilder(), sf1Name, sfType);
561         List<SfcServiceFunction> sfcServiceFunctionList =
562                 serviceFunctionChainUtils.list(new ArrayList<SfcServiceFunction>(), sfcServiceFunctionBuilder);
563
564         ServiceFunctionChainBuilder serviceFunctionChainBuilder =
565                 serviceFunctionChainUtils.serviceFunctionChainBuilder(
566                         new ServiceFunctionChainBuilder(), sfcName, false, sfcServiceFunctionList);
567         ServiceFunctionChainsBuilder serviceFunctionChainsBuilder =
568                 serviceFunctionChainUtils.serviceFunctionChainsBuilder(
569                         new ServiceFunctionChainsBuilder(),
570                         serviceFunctionChainUtils.list(new ArrayList<ServiceFunctionChain>(),
571                                 serviceFunctionChainBuilder));
572         LOG.info("ServiceFunctionChains: {}", serviceFunctionChainBuilder.build());
573         return serviceFunctionChainsBuilder;
574     }
575
576     private ServiceFunctionPathsBuilder serviceFunctionPathsBuilder() {
577         String sfpName = SFCPATH;
578         String sfcName = SFCNAME;
579         short startingIndex = 255;
580
581         ServiceFunctionPathBuilder serviceFunctionPathBuilder =
582                 serviceFunctionPathUtils.serviceFunctionPathBuilder(
583                         new ServiceFunctionPathBuilder(), sfpName, sfcName, startingIndex, false);
584         ServiceFunctionPathsBuilder serviceFunctionPathsBuilder =
585                 serviceFunctionPathUtils.serviceFunctionPathsBuilder(
586                         serviceFunctionPathUtils.list(new ArrayList<ServiceFunctionPath>(),
587                                 serviceFunctionPathBuilder));
588         LOG.info("ServiceFunctionPaths: {}", serviceFunctionPathsBuilder.build());
589         return serviceFunctionPathsBuilder;
590     }
591
592     private SfcOfRendererConfigBuilder sfcOfRendererConfigBuilder(short tableOffset, short egressTable) {
593         SfcOfRendererConfigBuilder sfcOfRendererConfigBuilder =
594                 sfcConfigUtils.sfcOfRendererConfigBuilder(new SfcOfRendererConfigBuilder(), tableOffset, egressTable);
595         LOG.info("SfcOfRendererConfig: {}", sfcOfRendererConfigBuilder.build());
596         return sfcOfRendererConfigBuilder;
597     }
598
599     private NetvirtProvidersConfigBuilder netvirtProvidersConfigBuilder(short tableOffset) {
600         NetvirtProvidersConfigBuilder netvirtProvidersConfigBuilder =
601                 netvirtConfigUtils.netvirtProvidersConfigBuilder(new NetvirtProvidersConfigBuilder(), tableOffset);
602         LOG.info("NetvirtProvidersConfig: {}", netvirtProvidersConfigBuilder.build());
603         return netvirtProvidersConfigBuilder;
604     }
605
606     @Test
607     public void testSfcModel() throws InterruptedException {
608         int timeout = 1000;
609         testModel(serviceFunctionsBuilder(), ServiceFunctions.class, timeout);
610         testModel(serviceFunctionForwardersBuilder(), ServiceFunctionForwarders.class, timeout);
611         testModel(serviceFunctionChainsBuilder(), ServiceFunctionChains.class, timeout);
612         testModel(serviceFunctionPathsBuilder(), ServiceFunctionPaths.class, timeout);
613     }
614
615     @Test
616     public void testSfcModels() throws InterruptedException {
617         testModel(serviceFunctionsBuilder(), ServiceFunctions.class);
618         testModel(serviceFunctionForwardersBuilder(), ServiceFunctionForwarders.class);
619         testModel(serviceFunctionChainsBuilder(), ServiceFunctionChains.class);
620         testModel(serviceFunctionPathsBuilder(), ServiceFunctionPaths.class);
621
622         testModel(accessListsBuilder(), AccessLists.class);
623         testModel(classifiersBuilder(), Classifiers.class);
624     }
625
626     /**
627      * Test that the NetvirtSfc SfcClassifierService is added to the Netvirt pipeline. The test
628      * sets the table offset and verifies the correct flow is programmed with the offset.
629      */
630     @Test
631     public void testNetvirtSfcPipeline() throws InterruptedException {
632         short netvirtTableOffset = 1;
633         testModelPut(netvirtProvidersConfigBuilder(netvirtTableOffset), NetvirtProvidersConfig.class);
634
635         NodeInfo nodeInfo = itUtils.createNodeInfo(SouthboundUtils.getConnectionInfo(addressStr, portStr), waitList);
636         nodeInfo.connect();
637
638         String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(Service.SFC_CLASSIFIER);
639         verifyFlow(nodeInfo.datapathId, flowId, Service.SFC_CLASSIFIER);
640
641         nodeInfo.disconnect();
642     }
643
644     /**
645      * Test the full NetvirtSfc functionality by creating everything needed to realize a chain and
646      * then verify all flows have been created.
647      * NOTE: This test requires an OVS with the NSH v8 patch, otherwise it will fail miserably.
648      * @throws InterruptedException
649      */
650     @Test
651     public void testNetvirtSfcAll() throws Exception {
652         if (userSpaceEnabled.equals("yes")) {
653             LOG.info("testNetvirtSfcAll: skipping test because userSpaceEnabled {}", userSpaceEnabled);
654             return;
655         }
656
657         String sfpName = SFCPATH;
658         String sfcName = SFCNAME;
659         short startingIndex = 255;
660
661         short netvirtTableOffset = 1;
662         testModelPut(netvirtProvidersConfigBuilder(netvirtTableOffset), NetvirtProvidersConfig.class);
663         short sfcTableoffset = 150;
664         short egressTable = pipelineOrchestrator.getTable(Service.SFC_CLASSIFIER);
665         testModelPut(sfcOfRendererConfigBuilder(sfcTableoffset, egressTable), SfcOfRendererConfig.class);
666
667         NodeInfo nodeInfo = itUtils.createNodeInfo(SouthboundUtils.getConnectionInfo(addressStr, portStr), waitList);
668         nodeInfo.connect();
669
670         String flowId = "DEFAULT_PIPELINE_FLOW_" + pipelineOrchestrator.getTable(Service.SFC_CLASSIFIER);
671         verifyFlow(nodeInfo.datapathId, flowId, Service.SFC_CLASSIFIER);
672
673         Map<String, String> externalIds = Maps.newHashMap();
674         externalIds.put("attached-mac", "f6:00:00:0f:00:01");
675         southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, SF1DPLNAME, "internal", null, externalIds);
676         externalIds.clear();
677         externalIds.put("attached-mac", "f6:00:00:0c:00:01");
678         southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm1", "internal");
679         externalIds.clear();
680         externalIds.put("attached-mac", "f6:00:00:0c:00:02");
681         southboundUtils.addTerminationPoint(nodeInfo.bridgeNode, "vm2", "internal");
682
683         InstanceIdentifier<TerminationPoint> tpIid =
684                 southboundUtils.createTerminationPointInstanceIdentifier(nodeInfo.bridgeNode, SFFDPL1NAME);
685         final NotifyingDataChangeListener portOperationalListener =
686                 new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, tpIid, waitList);
687         portOperationalListener.registerDataChangeListener(dataBroker);
688
689         InstanceIdentifier<RenderedServicePath> rspIid = sfcUtils.getRspId(RSPNAME);
690         final NotifyingDataChangeListener rspOperationalListener =
691                 new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, rspIid, waitList);
692         rspOperationalListener.registerDataChangeListener(dataBroker);
693
694         OvsdbBridgeAugmentation bridgeAugmentation = southbound.extractBridgeAugmentation(nodeInfo.bridgeNode);
695         OvsdbNodeRef ovsdbNodeRef = null;
696         if (bridgeAugmentation != null) {
697             ovsdbNodeRef = bridgeAugmentation.getManagedBy();
698         }
699
700         testModelPut(serviceFunctionsBuilder(), ServiceFunctions.class);
701         testModelPut(serviceFunctionForwardersBuilder(ovsdbNodeRef), ServiceFunctionForwarders.class);
702         testModelPut(serviceFunctionChainsBuilder(), ServiceFunctionChains.class);
703         testModelPut(serviceFunctionPathsBuilder(), ServiceFunctionPaths.class);
704
705         testModelPut(accessListsBuilder(false), AccessLists.class);
706         testModelPut(classifiersBuilder(), Classifiers.class);
707         ServiceFunctionPathBuilder serviceFunctionPathBuilder =
708                 serviceFunctionPathUtils.serviceFunctionPathBuilder(
709                         new ServiceFunctionPathBuilder(), sfpName, sfcName, startingIndex, false);
710         SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPathBuilder.build(),
711                 renderedServicePathUtils.createRenderedPathInputBuilder(new CreateRenderedPathInputBuilder(),
712                         SFCPATH, RSPNAME).build());
713
714         portOperationalListener.waitForCreation();
715         long vxGpeOfPort = southbound.getOFPort(nodeInfo.bridgeNode, SFFDPL1NAME);
716         assertNotEquals("vxGpePort was not found", 0, vxGpeOfPort);
717
718         rspOperationalListener.waitForCreation();
719         RenderedServicePath rsp = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, rspIid);
720         assertNotNull("RSP was not found", rsp);
721
722         flowId = FlowNames.getSfcIngressClass(RULENAME, rsp.getPathId(), rsp.getStartingIndex());
723         verifyFlow(nodeInfo.datapathId, flowId, Service.SFC_CLASSIFIER);
724         RenderedServicePathHop lastHop = sfcUtils.getLastHop(rsp);
725         short lastServiceindex = (short)((lastHop.getServiceIndex()).intValue() - 1);
726         flowId = FlowNames.getSfcEgressClass(vxGpeOfPort, rsp.getPathId(), lastServiceindex);
727         verifyFlow(nodeInfo.datapathId, flowId, Service.SFC_CLASSIFIER);
728         flowId = FlowNames.getSfcEgressClassBypass(rsp.getPathId(), lastServiceindex, 1);
729         verifyFlow(nodeInfo.datapathId, flowId, Service.CLASSIFIER);
730         flowId = FlowNames.getArpResponder(SF1IP);
731         verifyFlow(nodeInfo.datapathId, flowId, Service.ARP_RESPONDER);
732         // Only verify these flows if NetVirt adds them and not SFC
733         //flowId = FlowNames.getSfEgress(GPEUDPPORT);
734         //verifyFlow(nodeInfo.datapathId, flowId, Service.SFC_CLASSIFIER);
735         //flowId = FlowNames.getSfIngress(GPEUDPPORT, SF1IP);
736         //verifyFlow(nodeInfo.datapathId, flowId, Service.CLASSIFIER.getTable());
737
738         LOG.info("check for flows!!!!!!!!!!!!!");
739         Thread.sleep(30000);
740         InstanceIdentifier<Flow> flowIid = createFlowIid(nodeInfo.datapathId, flowId,
741                 pipelineOrchestrator.getTable(Service.CLASSIFIER));
742
743         final NotifyingDataChangeListener flowConfigurationListener =
744                 new NotifyingDataChangeListener(LogicalDatastoreType.CONFIGURATION, flowIid, waitList);
745         flowConfigurationListener.registerDataChangeListener(dataBroker);
746         final NotifyingDataChangeListener flowOperationalListener =
747                 new NotifyingDataChangeListener(LogicalDatastoreType.OPERATIONAL, flowIid, waitList);
748         flowOperationalListener.registerDataChangeListener(dataBroker);
749
750         deleteRsp(RSPNAME);
751         rspOperationalListener.waitForDeletion();
752         rsp = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, rspIid);
753         assertNull("RSP should not be found", rsp);
754
755         flowConfigurationListener.waitForDeletion();
756         Flow flow = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, flowIid);
757         assertNull("Flow should not be found in CONFIGURATION " + flowIid, flow);
758
759         flowOperationalListener.waitForDeletion();
760         flow = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, flowIid);
761         assertNull("Flow should not be found in OPERATIONAL " + flowIid, flow);
762
763         nodeInfo.disconnect();
764     }
765
766     private void deleteRsp(String rspName) {
767         RenderedServicePathKey renderedServicePathKey =
768                 new RenderedServicePathKey(RspName.getDefaultInstance(rspName));
769         InstanceIdentifier<RenderedServicePath> path =
770                 InstanceIdentifier.create(RenderedServicePaths.class)
771                         .child(RenderedServicePath.class, renderedServicePathKey);
772         mdsalUtils.delete(LogicalDatastoreType.OPERATIONAL, path);
773     }
774
775     /**
776      * Test the standalone NetvirtSfc implementation
777      * NOTE: This test requires an OVS with the NSH v8 patch, otherwise it will fail miserably.
778      * @throws InterruptedException
779      */
780     @Ignore
781     @Test
782     public void testStandalone() throws InterruptedException {
783         String bridgeName = "sw1";
784         ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo(addressStr, portStr);
785         assertNotNull("connection failed", southboundUtils.connectOvsdbNode(connectionInfo));
786         Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
787         assertNotNull("node is not connected", ovsdbNode);
788
789         String controllerTarget = "tcp:192.168.50.1:6653";
790         List<ControllerEntry> setControllerEntry = southboundUtils.createControllerEntry(controllerTarget);
791         Assert.assertTrue(southboundUtils.addBridge(connectionInfo, null, bridgeName, null, true,
792                 SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null,
793                 setControllerEntry, null, "00:00:00:00:00:00:00:01"));
794         assertTrue("Controller " + SouthboundUtils.connectionInfoToString(connectionInfo)
795                 + " is not connected", itUtils.isControllerConnected(connectionInfo));
796
797         Node bridgeNode = southbound.getBridgeNode(ovsdbNode, bridgeName);
798         assertNotNull("bridge " + bridgeName + " was not found", bridgeNode);
799         long datapathId = southbound.getDataPathId(bridgeNode);
800         String datapathIdString = southbound.getDatapathId(bridgeNode);
801         LOG.info("testNetVirt: bridgeNode: {}, datapathId: {} - {}", bridgeNode, datapathIdString, datapathId);
802         assertNotEquals("datapathId was not found", datapathId, 0);
803
804         SfcClassifier sfcClassifier = new SfcClassifier(dataBroker, southbound, mdsalUtils);
805         //sfcClassifier.programLocalInPort(datapathId, "4096", (long)1, (short)0, (short)50, true);
806
807         NshUtils nshUtils = new NshUtils(new Ipv4Address("192.168.50.71"), new PortNumber(6633),
808                 (long)10, (short)255, (long)4096, (long)4096);
809         MatchesBuilder matchesBuilder = aclUtils.matchesBuilder(new MatchesBuilder(), 80);
810         sfcClassifier.programSfcClassiferFlows(datapathId, (short)0, "test", matchesBuilder.build(),
811                 nshUtils, (long)2, true);
812
813         //nshUtils = new NshUtils(null, null, (long)10, (short)253, 0, 0);
814         //sfcClassifier.programEgressSfcClassiferFlows(datapathId, (short)0, "test", null,
815         //        nshUtils, (long)2, (long)3, true);
816
817         //NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
818         //FlowBuilder flowBuilder = getLocalInPortFlow(datapathId, "4096", (long) 1,
819         //                                             pipelineOrchestrator.getTable(Service.CLASSIFIER));
820         //Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
821         //assertNotNull("Could not find flow in config", flow);
822         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
823         //assertNotNull("Could not find flow in operational", flow);
824
825         //MatchBuilder matchBuilder = sfcClassifier.buildMatch(matchesBuilder.build());
826         //NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
827         //FlowBuilder flowBuilder = getSfcClassifierFlow(datapathId,
828         //        pipelineOrchestrator.getTable(Service.CLASSIFIER), "test", null,
829         //        nshUtils, (long) 2, matchBuilder);
830         //Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
831         //assertNotNull("Could not find flow in config", flow);
832         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
833         //assertNotNull("Could not find flow in operational", flow);
834
835         //nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
836         //flowBuilder = getEgressSfcClassifierFlow(datapathId,
837                                                    //pipelineOrchestrator.getTable(Service.CLASSIFIER),
838                                                    //"test", nshUtils, (long) 2);
839         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
840         //assertNotNull("Could not find flow in config", flow);
841         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
842         //assertNotNull("Could not find flow in operational", flow);
843
844         LOG.info("***** Go look for flows *****");
845         Thread.sleep(30000);
846         assertTrue(southboundUtils.deleteBridge(connectionInfo, bridgeName));
847         Thread.sleep(1000);
848         assertTrue(southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME));
849         Thread.sleep(1000);
850         assertTrue(southboundUtils.disconnectOvsdbNode(connectionInfo));
851     }
852
853     private InstanceIdentifier<Flow> createFlowIid(long datapathId, String flowId, short table) {
854         org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
855                 FlowUtils.createNodeBuilder(datapathId);
856         FlowBuilder flowBuilder =
857                 FlowUtils.initFlowBuilder(new FlowBuilder(), flowId, table);
858         return FlowUtils.createFlowPath(flowBuilder, nodeBuilder);
859     }
860
861     private Flow getFlow (
862             FlowBuilder flowBuilder,
863             org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder,
864             LogicalDatastoreType store) throws InterruptedException {
865
866         Flow flow = null;
867         for (int i = 0; i < 10; i++) {
868             LOG.info("getFlow try {} from {}: looking for flow: {}, node: {}",
869                     i, store, flowBuilder.build(), nodeBuilder.build());
870             flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
871             if (flow != null) {
872                 LOG.info("getFlow try {} from {}: found flow: {}", i, store, flow);
873                 break;
874             }
875             Thread.sleep(1000);
876         }
877         return flow;
878     }
879
880     private void verifyFlow(long datapathId, String flowId, short table) throws InterruptedException {
881         org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder nodeBuilder =
882                 FlowUtils.createNodeBuilder(datapathId);
883         FlowBuilder flowBuilder =
884                 FlowUtils.initFlowBuilder(new FlowBuilder(), flowId, table);
885         Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
886         assertNotNull("Could not find flow in config: " + flowBuilder.build() + "--" + nodeBuilder.build(), flow);
887         flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
888         assertNotNull("Could not find flow in operational: " + flowBuilder.build() + "--" + nodeBuilder.build(),
889                 flow);
890     }
891
892     private void verifyFlow(long datapathId, String flowId, Service service) throws InterruptedException {
893         verifyFlow(datapathId, flowId, pipelineOrchestrator.getTable(service));
894     }
895
896     private void readwait() {
897         if (ovsdb_wait) {
898             LOG.warn("Waiting, kill with ps -ef | grep java, kill xxx... ");
899             try {
900                 System.in.read();
901             } catch (IOException e) {
902                 e.printStackTrace();
903             }
904         }
905     }
906
907     private List<NotifyingDataChangeListener> waitList = new ArrayList<>();
908
909     private void closeWaitFors() {
910         for (Iterator<NotifyingDataChangeListener> iterator = waitList.iterator(); iterator.hasNext();) {
911             NotifyingDataChangeListener listener = iterator.next();
912             iterator.remove();
913             try {
914                 listener.close();
915             } catch (Exception ex) {
916                 LOG.warn("Failed to close registration {}", listener, ex);
917             }
918         }
919         LOG.info("waitList size {}", waitList.size());
920     }
921
922 }