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