Merge "Patch Set 1: Add postman collection for HwvtepSouthbound"
[netvirt.git] / openstack / net-virt-sfc / it / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / sfc / 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.ovsdb.openstack.netvirt.sfc;
10
11 import static org.junit.Assert.assertEquals;
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 com.google.common.collect.Maps;
29 import java.io.IOException;
30 import java.math.BigInteger;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Properties;
35 import java.util.concurrent.atomic.AtomicBoolean;
36 import org.junit.Assert;
37 import org.junit.Before;
38 import org.junit.Ignore;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
42 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
43 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
44 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
45 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
46 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
47 import org.opendaylight.ovsdb.openstack.netvirt.sfc.standalone.openflow13.SfcClassifier;
48 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.AclUtils;
49 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.ClassifierUtils;
50 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.ServiceFunctionChainUtils;
51 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.ServiceFunctionPathUtils;
52 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.SfcUtils;
53 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.ServiceFunctionForwarderUtils;
54 import org.opendaylight.ovsdb.openstack.netvirt.sfc.utils.ServiceFunctionUtils;
55 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
56 import org.opendaylight.ovsdb.southbound.SouthboundUtil;
57 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
58 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
59 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
60 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
61 import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils;
62 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctions;
63 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.ServiceFunctionsBuilder;
64 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
65 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunctionBuilder;
66 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChains;
67 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.ServiceFunctionChainsBuilder;
68 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
69 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChainBuilder;
70 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
71 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunctionBuilder;
72 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwarders;
73 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.ServiceFunctionForwardersBuilder;
74 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
75 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarderBuilder;
76 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPaths;
77 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.ServiceFunctionPathsBuilder;
78 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPath;
79 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfp.rev140701.service.function.paths.ServiceFunctionPathBuilder;
80 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.Firewall;
81 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
82 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessListsBuilder;
83 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.AclBuilder;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.AccessListEntriesBuilder;
85 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.AceBuilder;
86 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;
87 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.acl.access.list.entries.ace.Matches;
88 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;
89 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
90 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
91 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.Classifiers;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.ClassifiersBuilder;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.ClassifierBuilder;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.SffsBuilder;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.sffs.SffBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.Sfc;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.rev150105.SfcBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
108 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
109 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
110 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
111 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
112 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
113 import org.opendaylight.yangtools.concepts.Builder;
114 import org.opendaylight.yangtools.yang.binding.DataObject;
115 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
116
117 import org.ops4j.pax.exam.Configuration;
118 import org.ops4j.pax.exam.Option;
119 import org.ops4j.pax.exam.junit.PaxExam;
120 import org.ops4j.pax.exam.karaf.options.LogLevelOption;
121 import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
122 import org.ops4j.pax.exam.options.MavenUrlReference;
123 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
124 import org.ops4j.pax.exam.spi.reactors.PerClass;
125 import org.slf4j.Logger;
126 import org.slf4j.LoggerFactory;
127
128 @RunWith(PaxExam.class)
129 @ExamReactorStrategy(PerClass.class)
130 public class NetvirtSfcIT extends AbstractMdsalTestBase {
131     private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcIT.class);
132     private static AclUtils aclUtils = new AclUtils();
133     private static ClassifierUtils classifierUtils = new ClassifierUtils();
134     private static SfcUtils sfcUtils = new SfcUtils();
135     private static ServiceFunctionUtils serviceFunctionUtils = new ServiceFunctionUtils();
136     private static ServiceFunctionForwarderUtils serviceFunctionForwarderUtils = new ServiceFunctionForwarderUtils();
137     private static ServiceFunctionChainUtils serviceFunctionChainUtils = new ServiceFunctionChainUtils();
138     private static ServiceFunctionPathUtils serviceFunctionPathUtils = new ServiceFunctionPathUtils();
139     private static MdsalUtils mdsalUtils;
140     private static AtomicBoolean setup = new AtomicBoolean(false);
141     private static SouthboundUtils southboundUtils;
142     private static String addressStr;
143     private static String portStr;
144     private static String connectionType;
145     private static Southbound southbound;
146     private static DataBroker dataBroker;
147     public static final String CONTROLLER_IPADDRESS = "ovsdb.controller.address";
148     public static final String SERVER_IPADDRESS = "ovsdbserver.ipaddress";
149     public static final String SERVER_PORT = "ovsdbserver.port";
150     public static final String CONNECTION_TYPE = "ovsdbserver.connection";
151     public static final String CONNECTION_TYPE_ACTIVE = "active";
152     public static final String CONNECTION_TYPE_PASSIVE = "passive";
153     public static final String DEFAULT_SERVER_PORT = "6640";
154     public static final String INTEGRATION_BRIDGE_NAME = "br-int";
155     private static final String NETVIRT_TOPOLOGY_ID = "netvirt:1";
156     private static final String OVSDB_TRACE = "ovsdb.trace";
157     private static final String SF1NAME = "firewall-72";
158     private static final String SF2NAME = "dpi-72";
159     private static final String SF1IP = "10.2.1.1";//"192.168.50.70";//"192.168.120.31";
160     private static final String SF2IP = "10.2.1.2";
161     private static final String SF1DPLNAME = "sf1";
162     private static final String SF2DPLNAME = "sf2";
163     private static final String SFF1IP = "127.0.0.1";
164     private static final String SFF2IP = "127.0.0.1";
165     private static final String SFF1NAME = "SFF1";
166     private static final String SFF2NAME = "SFF2";
167     private static final String SFFDPL1NAME = "vxgpe";
168     private static final String SFFDPL2NAME = "vxgpe";
169     private static final String SN1NAME = "OVSDB1";
170     private static final String SN2NAME = "OVSDB2";
171     private static final String BRIDGE1NAME= "br-int";
172     private static final String BRIDGE2NAME= "br-int";
173     private static final String ACLNAME= "httpAcl";
174     private static final String SFCNAME = "SFC";
175     private static final int GPEPORT = 6633;
176
177     @Override
178     public String getModuleName() {
179         return "netvirt-sfc";
180     }
181
182     @Override
183     public String getInstanceName() {
184         return "netvirt-sfc-default";
185     }
186
187     @Override
188     public MavenUrlReference getFeatureRepo() {
189         return maven()
190                 .groupId("org.opendaylight.ovsdb")
191                 .artifactId("openstack.net-virt-sfc-features-test")
192                 .classifier("features")
193                 .type("xml")
194                 .versionAsInProject();
195     }
196
197     @Override
198     public String getFeatureName() {
199         return "odl-ovsdb-sfc-test";
200     }
201
202     @Configuration
203     @Override
204     public Option[] config() {
205         Option[] parentOptions = super.config();
206         Option[] propertiesOptions = getPropertiesOptions();
207         Option[] otherOptions = getOtherOptions();
208         Option[] options = new Option[parentOptions.length + propertiesOptions.length + otherOptions.length];
209         System.arraycopy(parentOptions, 0, options, 0, parentOptions.length);
210         System.arraycopy(propertiesOptions, 0, options, parentOptions.length, propertiesOptions.length);
211         System.arraycopy(otherOptions, 0, options, parentOptions.length + propertiesOptions.length,
212                 otherOptions.length);
213         return options;
214     }
215
216     private Option[] getOtherOptions() {
217         return new Option[] {
218                 wrappedBundle(
219                         mavenBundle("org.opendaylight.ovsdb", "utils.mdsal-openflow")
220                                 .version(asInProject())
221                                 .type("jar")),
222                 configureConsole().startLocalConsole(),
223                 vmOption("-javaagent:../jars/org.jacoco.agent.jar=destfile=../../jacoco-it.exec"),
224                         keepRuntimeFolder()
225         };
226     }
227
228     public Option[] getPropertiesOptions() {
229         return new Option[] {
230                 propagateSystemProperties(SERVER_IPADDRESS, SERVER_PORT, CONNECTION_TYPE,
231                         CONTROLLER_IPADDRESS, OVSDB_TRACE),
232         };
233     }
234
235     @Override
236     public Option getLoggingOption() {
237         return composite(
238                 when(Boolean.getBoolean(OVSDB_TRACE)).useOptions(
239                         editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
240                                 "log4j.logger.org.opendaylight.ovsdb",
241                                 LogLevelOption.LogLevel.TRACE.name())),
242                 //editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
243                 //        "log4j.logger.org.opendaylight.ovsdb",
244                 //        LogLevelOption.LogLevel.TRACE.name()),
245                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
246                         logConfiguration(NetvirtSfcIT.class),
247                         LogLevel.INFO.name()),
248                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
249                         "log4j.logger.org.opendaylight.ovsdb.openstack.netvirt.sfc",
250                         LogLevel.TRACE.name()),
251                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
252                         "log4j.logger.org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13",
253                         LogLevel.TRACE.name()),
254                 editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG,
255                         "log4j.logger.org.opendaylight.sfc",
256                         LogLevel.TRACE.name()),
257                 super.getLoggingOption());
258     }
259
260     protected String usage() {
261         return "Integration Test needs a valid connection configuration as follows :\n"
262                 + "active connection : mvn -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=yyyy verify\n"
263                 + "passive connection : mvn -Dovsdbserver.connection=passive verify\n";
264     }
265
266     private void getProperties() {
267         Properties props = System.getProperties();
268         addressStr = props.getProperty(SERVER_IPADDRESS);
269         portStr = props.getProperty(SERVER_PORT, DEFAULT_SERVER_PORT);
270         connectionType = props.getProperty(CONNECTION_TYPE, "active");
271         LOG.info("setUp: Using the following properties: mode= {}, ip:port= {}:{}",
272                 connectionType, addressStr, portStr);
273         if (connectionType.equalsIgnoreCase(CONNECTION_TYPE_ACTIVE)) {
274             if (addressStr == null) {
275                 fail(usage());
276             }
277         }
278         LOG.info("getProperties {}: {}", OVSDB_TRACE, props.getProperty(OVSDB_TRACE));
279     }
280
281     @Before
282     @Override
283     public void setup() {
284         if (setup.get()) {
285             LOG.info("Skipping setUp, already initialized");
286             return;
287         }
288
289         try {
290             Thread.sleep(1000);
291             super.setup();
292         } catch (Exception e) {
293             e.printStackTrace();
294         }
295
296         getProperties();
297
298         dataBroker = getDatabroker(getProviderContext());
299         mdsalUtils = new MdsalUtils(dataBroker);
300         assertNotNull("mdsalUtils should not be null", mdsalUtils);
301         southboundUtils = new SouthboundUtils(mdsalUtils);
302         assertTrue("Did not find " + NETVIRT_TOPOLOGY_ID, getNetvirtTopology());
303         southbound = (Southbound) ServiceHelper.getGlobalInstance(Southbound.class, this);
304         assertNotNull("southbound should not be null", southbound);
305         setup.set(true);
306     }
307
308     private ProviderContext getProviderContext() {
309         ProviderContext providerContext = null;
310         for (int i=0; i < 60; i++) {
311             providerContext = getSession();
312             if (providerContext != null) {
313                 break;
314             } else {
315                 try {
316                     Thread.sleep(1000);
317                 } catch (InterruptedException e) {
318                     e.printStackTrace();
319                 }
320             }
321         }
322         assertNotNull("providercontext should not be null", providerContext);
323         /* One more second to let the provider finish initialization */
324         try {
325             Thread.sleep(1000);
326         } catch (InterruptedException e) {
327             e.printStackTrace();
328         }
329         return providerContext;
330     }
331
332     private DataBroker getDatabroker(ProviderContext providerContext) {
333         DataBroker dataBroker = providerContext.getSALService(DataBroker.class);
334         assertNotNull("dataBroker should not be null", dataBroker);
335         return dataBroker;
336     }
337
338     private Boolean getNetvirtTopology() {
339         LOG.info("getNetvirtTopology: looking for {}...", NETVIRT_TOPOLOGY_ID);
340         Boolean found = false;
341         final TopologyId topologyId = new TopologyId(new Uri(NETVIRT_TOPOLOGY_ID));
342         InstanceIdentifier<Topology> path =
343                 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, new TopologyKey(topologyId));
344         for (int i = 0; i < 60; i++) {
345             Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
346             if (topology != null) {
347                 LOG.info("getNetvirtTopology: found {}...", NETVIRT_TOPOLOGY_ID);
348                 found = true;
349                 break;
350             } else {
351                 LOG.info("getNetvirtTopology: still looking ({})...", i);
352                 try {
353                     Thread.sleep(1000);
354                 } catch (InterruptedException e) {
355                     e.printStackTrace();
356                 }
357             }
358         }
359         return found;
360     }
361
362     @Test
363     public void testNetvirtSfcFeatureLoad() {
364         assertTrue(true);
365     }
366
367     private AccessListsBuilder accessListsBuilder() {
368         MatchesBuilder matchesBuilder = aclUtils.matchesBuilder(new MatchesBuilder(), 80);
369         LOG.info("Matches: {}", matchesBuilder.build());
370         //ActionsBuilder actionsBuilder = aclUtils.actionsBuilder(new ActionsBuilder(), Boolean.TRUE);
371         ActionsBuilder actionsBuilder = aclUtils.actionsBuilder(new ActionsBuilder(), SFCNAME);
372         AceBuilder accessListEntryBuilder =
373                 aclUtils.aceBuilder(new AceBuilder(), "httpRule", matchesBuilder, actionsBuilder);
374         AccessListEntriesBuilder accessListEntriesBuilder =
375                 aclUtils.accessListEntriesBuidler(new AccessListEntriesBuilder(), accessListEntryBuilder);
376         AclBuilder accessListBuilder =
377                 aclUtils.aclBuilder(new AclBuilder(), ACLNAME, accessListEntriesBuilder);
378         AccessListsBuilder accessListsBuilder =
379                 aclUtils.accesslistsbuilder(new AccessListsBuilder(), accessListBuilder);
380         LOG.info("AccessLists: {}", accessListsBuilder.build());
381         return accessListsBuilder;
382     }
383
384     @Test
385     public void testAccessLists() throws InterruptedException {
386         testModel(accessListsBuilder(), AccessLists.class, 0);
387     }
388
389     private ClassifiersBuilder classifiersBuilder() {
390         SffBuilder sffBuilder = classifierUtils.sffBuilder(new SffBuilder(), SFF1NAME);
391         SffsBuilder sffsBuilder = classifierUtils.sffsBuilder(new SffsBuilder(), sffBuilder);
392         ClassifierBuilder classifierBuilder = classifierUtils.classifierBuilder(new ClassifierBuilder(),
393                 "classifierName", ACLNAME, sffsBuilder);
394         ClassifiersBuilder classifiersBuilder = classifierUtils.ClassifiersBuilder(new ClassifiersBuilder(),
395                 classifierBuilder);
396         LOG.info("Classifiers: {}", classifiersBuilder.build());
397         return classifiersBuilder;
398     }
399
400     @Test
401     public void testClassifiers() throws InterruptedException {
402         testModel(classifiersBuilder(), Classifiers.class, 0);
403     }
404
405     private SfcBuilder netvirtSfcBuilder() {
406         return sfcUtils.sfcBuilder(new SfcBuilder(), "sfc");
407     }
408
409     @Test
410     public void testNetvirtSfcModel() throws InterruptedException {
411         testModel(netvirtSfcBuilder(), Sfc.class, 0);
412     }
413
414     private <T extends DataObject> void testModelPut(Builder<T> builder, Class<T> clazz) {
415         InstanceIdentifier<T> path = InstanceIdentifier.create(clazz);
416         assertTrue(mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, path, builder.build()));
417         T result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
418         assertNotNull(clazz.getSimpleName() + " should not be null", result);
419     }
420
421     private <T extends DataObject> void testModelDelete(Builder<T> builder, Class<T> clazz)
422             throws InterruptedException {
423         InstanceIdentifier<T> path = InstanceIdentifier.create(clazz);
424         assertTrue("Failed to remove " + clazz.getSimpleName(),
425                 mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, path));
426         T result = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path);
427         assertNull(clazz.getSimpleName() + " should be null", result);
428     }
429
430     private <T extends DataObject> void testModel(Builder<T> builder, Class<T> clazz, long wait)
431             throws InterruptedException {
432         testModelPut(builder, clazz);
433         Thread.sleep(wait);
434         testModelDelete(builder, clazz);
435     }
436
437     private ServiceFunctionsBuilder serviceFunctionsBuilder() {
438         String sf1Name = SF1NAME;
439         String sf1Ip = SF1IP;
440         String sff1Ip = SF1IP;
441         String sff1Name = SFF1NAME;
442         String sf1DplName = SF1DPLNAME;
443         String sn1Name = SN1NAME;
444         String bridge1Name= BRIDGE1NAME;
445         String sf2Name = SF2NAME;
446         String sf2Ip = SF2IP;
447         String sff2Ip = SF2IP;
448         String sff2Name = SFF2NAME;
449         String sf2DplName = SF2DPLNAME;
450         String sn2Name = SN2NAME;
451         String bridge2Name= BRIDGE2NAME;
452         int port = GPEPORT;
453
454         ServiceFunctionBuilder serviceFunctionBuilder =
455                 serviceFunctionUtils.serviceFunctionBuilder(sf1Ip, port, sf1DplName, sff1Name, sf1Name);
456         List<ServiceFunction> serviceFunctionList = serviceFunctionUtils.list(
457                 new ArrayList<ServiceFunction>(), serviceFunctionBuilder);
458
459         //serviceFunctionBuilder =
460         //        serviceFunctionUtils.serviceFunctionBuilder(sf2Ip, port, sffDpl2Name, sff2Name, sf2Name);
461         //serviceFunctionList = serviceFunctionUtils.list(
462         //        serviceFunctionList, serviceFunctionBuilder);
463
464         ServiceFunctionsBuilder serviceFunctionsBuilder =
465                 serviceFunctionUtils.serviceFunctionsBuilder(new ServiceFunctionsBuilder(),
466                         serviceFunctionList);
467         LOG.info("ServiceFunctions: {}", serviceFunctionsBuilder.build());
468         return serviceFunctionsBuilder;
469     }
470
471     private ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder() {
472         String sf1Name = SF1NAME;
473         String sf1Ip = SF1IP;
474         String sff1Ip = SFF1IP;
475         String sff1Name = SFF1NAME;
476         String sffDpl1Name = SFFDPL1NAME;
477         String sn1Name = SN1NAME;
478         String bridge1Name= BRIDGE1NAME;
479         String sf2Name = SF2NAME;
480         String sf2Ip = SF2IP;
481         String sff2Ip = SFF2IP;
482         String sff2Name = SFF2NAME;
483         String sffDpl2Name = SFFDPL2NAME;
484         String sn2Name = SN2NAME;
485         String bridge2Name= BRIDGE2NAME;
486         String aclName = ACLNAME;
487         int port = GPEPORT;
488
489         ServiceFunctionForwarderBuilder serviceFunctionForwarderBuilder =
490                 serviceFunctionForwarderUtils.serviceFunctionForwarderBuilder(
491                         sff1Name, sff1Ip, port, sffDpl1Name, sf1Name, sf1Ip, sn1Name, bridge1Name, Firewall.class);
492         List<ServiceFunctionForwarder>  serviceFunctionForwarderList = serviceFunctionForwarderUtils.list(
493                 new ArrayList<ServiceFunctionForwarder>(), serviceFunctionForwarderBuilder);
494
495         //serviceFunctionForwarderBuilder =
496         //        serviceFunctionForwarderUtils.serviceFunctionForwarderBuilder(
497         //                sff2Name, sff2Ip, port, sffDpl2Name, sf2Name, sff2Ip, sn2Name, bridge2Name, Dpi.class);
498         //serviceFunctionForwarderList = serviceFunctionForwarderUtils.list(
499         //        serviceFunctionForwarderList, serviceFunctionForwarderBuilder);
500
501         ServiceFunctionForwardersBuilder serviceFunctionForwardersBuilder =
502                 serviceFunctionForwarderUtils.serviceFunctionForwardersBuilder(
503                         new ServiceFunctionForwardersBuilder(), serviceFunctionForwarderList);
504         LOG.info("ServiceFunctionForwarders: {}", serviceFunctionForwardersBuilder.build());
505         return serviceFunctionForwardersBuilder;
506     }
507
508     private ServiceFunctionChainsBuilder serviceFunctionChainsBuilder() {
509         String sf1Name = "firewall-abstract1";
510         String sf2Name = "dpi-abstract1";
511         String sfcName = SFCNAME;
512
513         SfcServiceFunctionBuilder sfcServiceFunctionBuilder = serviceFunctionChainUtils.sfcServiceFunctionBuilder(
514                 new SfcServiceFunctionBuilder(), sf1Name, Firewall.class);
515         List<SfcServiceFunction> sfcServiceFunctionList =
516                 serviceFunctionChainUtils.list(new ArrayList<SfcServiceFunction>(), sfcServiceFunctionBuilder);
517
518         //sfcServiceFunctionBuilder = serviceFunctionChainUtils.sfcServiceFunctionBuilder(
519         //        sfcServiceFunctionBuilder, sf2Name, Dpi.class);
520         //sfcServiceFunctionList = serviceFunctionChainUtils.list(sfcServiceFunctionList, sfcServiceFunctionBuilder);
521
522         ServiceFunctionChainBuilder serviceFunctionChainBuilder =
523                 serviceFunctionChainUtils.serviceFunctionChainBuilder(
524                         new ServiceFunctionChainBuilder(), sfcName, false, sfcServiceFunctionList);
525         ServiceFunctionChainsBuilder serviceFunctionChainsBuilder =
526                 serviceFunctionChainUtils.serviceFunctionChainsBuilder(
527                         new ServiceFunctionChainsBuilder(),
528                         serviceFunctionChainUtils.list(new ArrayList<ServiceFunctionChain>(),
529                                 serviceFunctionChainBuilder));
530         LOG.info("ServiceFunctionChains: {}", serviceFunctionChainBuilder.build());
531         return serviceFunctionChainsBuilder;
532     }
533
534     private ServiceFunctionPathsBuilder serviceFunctionPathsBuilder() {
535         String sfpName = "SFC-Path";
536         String sfcName = "SFC";
537         short startingIndex = 255;
538
539         ServiceFunctionPathBuilder serviceFunctionPathBuilder =
540                 serviceFunctionPathUtils.serviceFunctionPathBuilder(
541                         new ServiceFunctionPathBuilder(), sfpName, sfcName, startingIndex, false);
542         ServiceFunctionPathsBuilder serviceFunctionPathsBuilder =
543                 serviceFunctionPathUtils.serviceFunctionPathsBuilder(
544                         serviceFunctionPathUtils.list(new ArrayList<ServiceFunctionPath>(),
545                                 serviceFunctionPathBuilder));
546         LOG.info("ServiceFunctionPaths: {}", serviceFunctionPathsBuilder.build());
547         return serviceFunctionPathsBuilder;
548     }
549
550     @Test
551     public void testSfcModel() throws InterruptedException {
552         testModel(serviceFunctionsBuilder(), ServiceFunctions.class, 3000);
553         testModel(serviceFunctionForwardersBuilder(), ServiceFunctionForwarders.class, 3000);
554         testModel(serviceFunctionChainsBuilder(), ServiceFunctionChains.class, 3000);
555         testModel(serviceFunctionPathsBuilder(), ServiceFunctionPaths.class, 3000);
556     }
557
558     @Test
559     public void testSfcModels() throws InterruptedException {
560         String bridgeName = INTEGRATION_BRIDGE_NAME;
561         ConnectionInfo connectionInfo = southboundUtils.getConnectionInfo(addressStr, portStr);
562         assertNotNull("connection failed", southboundUtils.connectOvsdbNode(connectionInfo));
563         Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
564         assertNotNull("node is not connected", ovsdbNode);
565
566         Thread.sleep(5000);
567         Node bridgeNode = southbound.getBridgeNode(ovsdbNode, bridgeName);
568         assertNotNull("bridge " + bridgeName + " was not found", bridgeNode);
569         long datapathId = southbound.getDataPathId(bridgeNode);
570
571         Map<String, String> externalIds = Maps.newHashMap();
572         externalIds.put("attached-mac", "f6:00:00:0f:00:01");
573         southboundUtils.addTerminationPoint(bridgeNode, null, SF1DPLNAME, "internal", null, externalIds);
574         southboundUtils.addTerminationPoint(bridgeNode, null, "vm1", "internal");
575         southboundUtils.addTerminationPoint(bridgeNode, null, "vm2", "internal");
576         Map<String, String> options = Maps.newHashMap();
577         options.put("key", "flow");
578         options.put("remote_ip", "192.168.120.32");
579         southboundUtils.addTerminationPoint(bridgeNode, null, "vx", "vxlan", options, null);
580         Thread.sleep(1000);
581
582         testModelPut(serviceFunctionsBuilder(), ServiceFunctions.class);
583         testModelPut(serviceFunctionForwardersBuilder(), ServiceFunctionForwarders.class);
584         testModelPut(serviceFunctionChainsBuilder(), ServiceFunctionChains.class);
585         testModelPut(serviceFunctionPathsBuilder(), ServiceFunctionPaths.class);
586
587         Thread.sleep(5000);
588
589         testModelPut(accessListsBuilder(), AccessLists.class);
590         testModelPut(classifiersBuilder(), Classifiers.class);
591
592         Thread.sleep(10000);
593
594         ISfcClassifierService sfcClassifierService = (ISfcClassifierService) ServiceHelper.getGlobalInstance(ISfcClassifierService.class, this);
595         LOG.info("SfcClassifierService: {}", sfcClassifierService);
596         readwait();
597         //sfcClassifierService.programIngressClassifier(datapathId);
598
599         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
600         FlowBuilder flowBuilder = getSfcIngressClassifierFlowBuilder();
601         Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
602         assertNotNull("Could not find flow in config", flow);
603         flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
604         assertNotNull("Could not find flow in operational", flow);
605
606         assertTrue(southboundUtils.deleteBridge(connectionInfo, bridgeName));
607         Thread.sleep(1000);
608         assertTrue(southboundUtils.disconnectOvsdbNode(connectionInfo));
609     }
610
611     /*
612      * Connect to an ovsdb node. Netvirt should add br-int, add the controller address
613      * and program the pipeline flows.
614      */
615     @Test
616     public void testNetvirtSfc() throws InterruptedException {
617         String bridgeName = INTEGRATION_BRIDGE_NAME;
618         ConnectionInfo connectionInfo = southboundUtils.getConnectionInfo(addressStr, portStr);
619         assertNotNull("connection failed", southboundUtils.connectOvsdbNode(connectionInfo));
620         Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
621         assertNotNull("node is not connected", ovsdbNode);
622         ControllerEntry controllerEntry;
623         // Loop 10s checking if the controller was added
624         for (int i = 0; i < 10; i++) {
625             ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
626             assertNotNull("ovsdb node not found", ovsdbNode);
627             String controllerTarget = SouthboundUtil.getControllerTarget(ovsdbNode);
628             assertNotNull("Failed to get controller target", controllerTarget);
629             OvsdbBridgeAugmentation bridge = southboundUtils.getBridge(connectionInfo, bridgeName);
630             if (bridge != null) {
631                 assertNotNull("Failed to read bridge", bridge);
632                 assertNotNull("Failed to extract controllerEntry", bridge.getControllerEntry());
633                 controllerEntry = bridge.getControllerEntry().iterator().next();
634                 assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
635                 if (controllerEntry.isIsConnected()) {
636                     Assert.assertTrue("switch is not connected to the controller", controllerEntry.isIsConnected());
637                     break;
638                 }
639             }
640             Thread.sleep(1000);
641         }
642
643         Node bridgeNode = southbound.getBridgeNode(ovsdbNode, bridgeName);
644         assertNotNull("bridge " + bridgeName + " was not found", bridgeNode);
645         long datapathId = southbound.getDataPathId(bridgeNode);
646
647         //Thread.sleep(10000);
648
649         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
650         FlowBuilder flowBuilder = FlowUtils.getPipelineFlow(Service.SFC_CLASSIFIER.getTable(), (short)0);
651         Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
652         assertNotNull("Could not find flow in config", flow);
653         flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
654         assertNotNull("Could not find flow in operational", flow);
655
656         assertTrue(southboundUtils.deleteBridge(connectionInfo, bridgeName));
657         Thread.sleep(1000);
658         assertTrue(southboundUtils.disconnectOvsdbNode(connectionInfo));
659     }
660
661     @Ignore
662     @Test
663     public void testStandalone() throws InterruptedException {
664         String bridgeName = "sw1";
665         ConnectionInfo connectionInfo = southboundUtils.getConnectionInfo(addressStr, portStr);
666         assertNotNull("connection failed", southboundUtils.connectOvsdbNode(connectionInfo));
667         Node ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
668         assertNotNull("node is not connected", ovsdbNode);
669         String controllerTarget = "tcp:192.168.50.1:6653";
670         List<ControllerEntry> setControllerEntry = southboundUtils.createControllerEntry(controllerTarget);
671         Assert.assertTrue(southboundUtils.addBridge(connectionInfo, null, bridgeName, null, true,
672                 SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"), true, null, null,
673                 setControllerEntry, null, "00:00:00:00:00:00:00:01"));
674         // Loop 10s checking if the controller was added
675         for (int i = 0; i < 10; i++) {
676             ovsdbNode = southboundUtils.getOvsdbNode(connectionInfo);
677             assertNotNull("ovsdb node not found", ovsdbNode);
678             assertNotNull("Failed to get controller target", controllerTarget);
679             OvsdbBridgeAugmentation bridge = southboundUtils.getBridge(connectionInfo, bridgeName);
680             assertNotNull(bridge);
681             assertNotNull(bridge.getControllerEntry());
682             ControllerEntry controllerEntry = bridge.getControllerEntry().iterator().next();
683             assertEquals(controllerTarget, controllerEntry.getTarget().getValue());
684             if (controllerEntry.isIsConnected()) {
685                 Assert.assertTrue(controllerEntry.isIsConnected());
686                 break;
687             }
688             Thread.sleep(1000);
689         }
690
691         Node bridgeNode = southbound.getBridgeNode(ovsdbNode, bridgeName);
692         assertNotNull("bridge " + bridgeName + " was not found", bridgeNode);
693         long datapathId = southbound.getDataPathId(bridgeNode);
694
695         SfcClassifier sfcClassifier = new SfcClassifier(dataBroker, southbound, mdsalUtils);
696         //sfcClassifier.programLocalInPort(datapathId, "4096", (long)1, (short)0, (short)50, true);
697
698         NshUtils nshUtils = new NshUtils(new Ipv4Address("192.168.50.71"), new PortNumber(6633),
699                 (long)10, (short)255, (long)4096, (long)4096);
700         MatchesBuilder matchesBuilder = aclUtils.matchesBuilder(new MatchesBuilder(), 80);
701         sfcClassifier.programSfcClassiferFlows(datapathId, (short)0, "test", matchesBuilder.build(),
702                 nshUtils, (long)2, true);
703
704         nshUtils = new NshUtils(null, null, (long)10, (short)253, 0, 0);
705         //sfcClassifier.programEgressSfcClassiferFlows(datapathId, (short)0, "test", null,
706         //        nshUtils, (long)2, (long)3, true);
707
708         //try {
709         //    System.in.read();
710         //} catch (IOException e) {
711         //    e.printStackTrace();
712         //}
713
714         //NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
715         //FlowBuilder flowBuilder = getLocalInPortFlow(datapathId, "4096", (long) 1, (short) 0);
716         //Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
717         //assertNotNull("Could not find flow in config", flow);
718         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
719         //assertNotNull("Could not find flow in operational", flow);
720
721         MatchBuilder matchBuilder = sfcClassifier.buildMatch(matchesBuilder.build());
722         NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
723         FlowBuilder flowBuilder = getSfcClassifierFlow(datapathId, (short) 0, "test", null,
724                 nshUtils, (long) 2, matchBuilder);
725         Flow flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
726         assertNotNull("Could not find flow in config", flow);
727         flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
728         assertNotNull("Could not find flow in operational", flow);
729
730         //nodeBuilder = FlowUtils.createNodeBuilder(datapathId);
731         //flowBuilder = getEgressSfcClassifierFlow(datapathId, (short) 0, "test", nshUtils, (long) 2);
732         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.CONFIGURATION);
733         //assertNotNull("Could not find flow in config", flow);
734         //flow = getFlow(flowBuilder, nodeBuilder, LogicalDatastoreType.OPERATIONAL);
735         //assertNotNull("Could not find flow in operational", flow);
736
737         LOG.info("***** Go look for flows *****");
738         Thread.sleep(30000);
739         assertTrue(southboundUtils.deleteBridge(connectionInfo, bridgeName));
740         Thread.sleep(1000);
741         assertTrue(southboundUtils.deleteBridge(connectionInfo, INTEGRATION_BRIDGE_NAME));
742         Thread.sleep(1000);
743         assertTrue(southboundUtils.disconnectOvsdbNode(connectionInfo));
744     }
745
746     private FlowBuilder getLocalInPortFlow(long dpidLong, String segmentationId, long inPort, short writeTable) {
747         MatchBuilder matchBuilder = new MatchBuilder();
748
749         FlowBuilder flowBuilder = new FlowBuilder();
750
751         flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, inPort).build());
752         String flowId = "sfcIngress_" + segmentationId + "_" + inPort;
753         flowBuilder.setId(new FlowId(flowId));
754         FlowKey key = new FlowKey(new FlowId(flowId));
755         flowBuilder.setStrict(true);
756         flowBuilder.setBarrier(false);
757         flowBuilder.setTableId(writeTable);
758         flowBuilder.setKey(key);
759         flowBuilder.setFlowName(flowId);
760         flowBuilder.setHardTimeout(0);
761         flowBuilder.setIdleTimeout(0);
762         return flowBuilder;
763     }
764
765     public FlowBuilder getSfcClassifierFlow(long dpidLong, short writeTable, String ruleName, Matches match,
766                                              NshUtils nshHeader, long tunnelOfPort, MatchBuilder matchBuilder) {
767         FlowBuilder flowBuilder = new FlowBuilder();
768
769         flowBuilder.setMatch(matchBuilder.build());
770
771         String flowId = "sfcClass_" + ruleName + "_" + nshHeader.getNshNsp();
772         flowBuilder.setId(new FlowId(flowId));
773         FlowKey key = new FlowKey(new FlowId(flowId));
774         flowBuilder.setBarrier(true);
775         flowBuilder.setTableId(writeTable);
776         flowBuilder.setKey(key);
777         flowBuilder.setFlowName(flowId);
778         flowBuilder.setHardTimeout(0);
779         flowBuilder.setIdleTimeout(0);
780         return flowBuilder;
781     }
782
783     private FlowBuilder getEgressSfcClassifierFlow(long dpidLong, short writeTable, String ruleName,
784                                                    NshUtils nshHeader, long tunnelOfPort) {
785         FlowBuilder flowBuilder = new FlowBuilder();
786
787         MatchBuilder matchBuilder = new MatchBuilder();
788         flowBuilder.setMatch(MatchUtils.createInPortMatch(matchBuilder, dpidLong, tunnelOfPort).build());
789         flowBuilder.setMatch(
790                 MatchUtils.createTunnelIDMatch(matchBuilder, BigInteger.valueOf(nshHeader.getNshNsp())).build());
791         flowBuilder.setMatch(MatchUtils.addNxNspMatch(matchBuilder, nshHeader.getNshNsp()).build());
792         flowBuilder.setMatch(MatchUtils.addNxNsiMatch(matchBuilder, nshHeader.getNshNsi()).build());
793
794         String flowId = "egressSfcClass_" + ruleName + "_" + nshHeader.getNshNsp() + "_" + nshHeader.getNshNsi();
795         flowBuilder.setId(new FlowId(flowId));
796         FlowKey key = new FlowKey(new FlowId(flowId));
797         flowBuilder.setStrict(true);
798         flowBuilder.setBarrier(false);
799         flowBuilder.setTableId(writeTable);
800         flowBuilder.setKey(key);
801         flowBuilder.setFlowName(flowId);
802         flowBuilder.setHardTimeout(0);
803         flowBuilder.setIdleTimeout(0);
804         return flowBuilder;
805     }
806
807     private FlowBuilder getSfcIngressClassifierFlowBuilder() {
808         FlowBuilder flowBuilder = new FlowBuilder();
809         String flowId = "sfcClass_" + "httpRule";
810         flowBuilder.setId(new FlowId(flowId));
811         FlowKey key = new FlowKey(new FlowId(flowId));
812         flowBuilder.setKey(key);
813         flowBuilder.setFlowName(flowId);
814         flowBuilder.setTableId((short)10);
815         return flowBuilder;
816     }
817
818     private Flow getFlow (FlowBuilder flowBuilder, NodeBuilder nodeBuilder, LogicalDatastoreType store)
819             throws InterruptedException {
820         Flow flow = null;
821         for (int i = 0; i < 10; i++) {
822             flow = FlowUtils.getFlow(flowBuilder, nodeBuilder, dataBroker.newReadOnlyTransaction(), store);
823             if (flow != null) {
824                 LOG.info("getFlow: flow: {}: {}", store, flow);
825                 break;
826             }
827             Thread.sleep(1000);
828         }
829         return flow;
830     }
831
832     private void readwait() {
833         try {
834             System.in.read();
835         } catch (IOException e) {
836             e.printStackTrace();
837         }
838     }
839 }