Fixed few things:
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / MdsalUtils.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.ovsdb.openstack.netvirt;
9
10 import com.google.common.base.Optional;
11 import com.google.common.collect.ImmutableBiMap;
12 import com.google.common.util.concurrent.CheckedFuture;
13
14 import java.math.BigInteger;
15 import java.security.InvalidParameterException;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
22 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
25 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
26 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
27 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
28 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeInternal;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
58 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
61
62 /**
63  * Utility class to wrap mdsal transactions.
64  *
65  * @author Sam Hague (shague@redhat.com)
66  */
67 public class MdsalUtils {
68     private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
69     private static DataBroker databroker = null;
70     private static final int OVSDB_UPDATE_TIMEOUT = 500;
71
72     /**
73      * Class constructor setting the data broker.
74      *
75      * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
76      */
77     public MdsalUtils(DataBroker dataBroker) {
78         this.databroker = dataBroker;
79     }
80
81     /**
82      * Executes delete as a blocking transaction.
83      *
84      * @param store {@link LogicalDatastoreType} which should be modified
85      * @param path {@link InstanceIdentifier} to read from
86      * @param <D> the data object type
87      * @return the result of the request
88      */
89     public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
90             final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
91         boolean result = false;
92         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
93         transaction.delete(store, path);
94         CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
95         try {
96             future.checkedGet();
97             result = true;
98         } catch (TransactionCommitFailedException e) {
99             LOG.warn("Failed to delete {} ", path, e);
100         }
101         return result;
102     }
103
104     /**
105      * Executes merge as a blocking transaction.
106      *
107      * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
108      * @param path {@link InstanceIdentifier} for path to read
109      * @param <D> the data object type
110      * @return the result of the request
111      */
112     public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
113             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
114         boolean result = false;
115         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
116         transaction.merge(logicalDatastoreType, path, data, true);
117         CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
118         try {
119             future.checkedGet();
120             result = true;
121         } catch (TransactionCommitFailedException e) {
122             LOG.warn("Failed to merge {} ", path, e);
123         }
124         return result;
125     }
126
127     /**
128      * Executes put as a blocking transaction.
129      *
130      * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
131      * @param path {@link InstanceIdentifier} for path to read
132      * @param <D> the data object type
133      * @return the result of the request
134      */
135     public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
136             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
137         boolean result = false;
138         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
139         transaction.put(logicalDatastoreType, path, data, true);
140         CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
141         try {
142             future.checkedGet();
143             result = true;
144         } catch (TransactionCommitFailedException e) {
145             LOG.warn("Failed to put {} ", path, e);
146         }
147         return result;
148     }
149
150     /**
151      * Executes read as a blocking transaction.
152      *
153      * @param store {@link LogicalDatastoreType} to read
154      * @param path {@link InstanceIdentifier} for path to read
155      * @param <D> the data object type
156      * @return the result as the data object requested
157      */
158     public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
159             final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
160         D result = null;
161         final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
162         Optional<D> optionalDataObject;
163         CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
164         try {
165             optionalDataObject = future.checkedGet();
166             if (optionalDataObject.isPresent()) {
167                 result = optionalDataObject.get();
168             } else {
169                 LOG.debug("{}: Failed to read {}",
170                         Thread.currentThread().getStackTrace()[1], path);
171             }
172         } catch (ReadFailedException e) {
173             LOG.warn("Failed to read {} ", path, e);
174         }
175         transaction.close();
176         return result;
177     }
178
179     public static ConnectionInfo getConnectionInfo(Node node) {
180         ConnectionInfo connectionInfo = null;
181         OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
182         if (ovsdbNodeAugmentation != null) {
183             connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
184         }
185         return connectionInfo;
186     }
187
188     public static String getOvsdbNodeUUID(Node node) {
189         String nodeUUID = null;
190         OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
191         if (ovsdbNodeAugmentation != null) {
192             // TODO replace with proper uuid and not the system-id
193             nodeUUID = getOsdbNodeExternalIdsValue(ovsdbNodeAugmentation, "system-id");
194         }
195         return nodeUUID;
196     }
197
198     public static String getOsdbNodeExternalIdsValue(OvsdbNodeAugmentation ovsdbNodeAugmentation, String key) {
199         String value = null;
200         List<OpenvswitchExternalIds> pairs = ovsdbNodeAugmentation.getOpenvswitchExternalIds();
201         for (OpenvswitchExternalIds pair : pairs) {
202             if (pair.getKey().equals(key)) {
203                 value = pair.getExternalIdValue();
204             }
205         }
206         return value;
207     }
208
209     public static boolean addBridge(Node ovsdbNode, String bridgeName, String target)
210             throws InterruptedException, InvalidParameterException {
211         boolean result = false;
212
213         LOG.info("Add Bridge: node: {}, bridgeName: {}, target: {}", ovsdbNode, bridgeName, target);
214         ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
215         if (connectionInfo != null) {
216             NodeBuilder bridgeNodeBuilder = new NodeBuilder();
217             InstanceIdentifier<Node> bridgeIid =
218                     SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
219             NodeId bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
220             bridgeNodeBuilder.setNodeId(bridgeNodeId);
221             OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
222             ovsdbBridgeAugmentationBuilder.setControllerEntry(createControllerEntries(target));
223             ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
224             ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
225             ovsdbBridgeAugmentationBuilder.setFailMode(
226                     SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
227             setManagedByForBridge(ovsdbBridgeAugmentationBuilder, connectionInfo);
228             bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
229
230             result = put(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build());
231             LOG.info("addBridge: result: {}", result);
232         } else {
233             throw new InvalidParameterException("Could not find ConnectionInfo");
234         }
235         return result;
236     }
237
238     public static boolean deleteBridge(Node ovsdbNode) {
239         boolean result = false;
240         InstanceIdentifier<Node> bridgeIid =
241                 SouthboundMapper.createInstanceIdentifier(ovsdbNode.getNodeId());
242
243         result = delete(LogicalDatastoreType.CONFIGURATION, bridgeIid);
244         LOG.info("Delete bridge node: {}, bridgeName: {} result : {}", ovsdbNode, ovsdbNode.getNodeId(),result);
245         return result;
246     }
247
248     public static OvsdbBridgeAugmentation readBridge(Node node, String name) {
249         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
250         ConnectionInfo connectionInfo = getConnectionInfo(node);
251         if (connectionInfo != null) {
252             InstanceIdentifier<Node> bridgeIid =
253                     SouthboundMapper.createInstanceIdentifier(connectionInfo,
254                             new OvsdbBridgeName(name));
255             Node bridgeNode = read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
256             if (bridgeNode != null) {
257                 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
258             }
259         }
260         return ovsdbBridgeAugmentation;
261     }
262
263     public static Uuid getBridgeUuid(Node node, String name) {
264         Uuid uuid = null;
265         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = readBridge(node, name);
266         if (ovsdbBridgeAugmentation != null) {
267             uuid = ovsdbBridgeAugmentation.getBridgeUuid();
268         }
269         return uuid;
270     }
271
272     private static void setManagedByForBridge(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
273                                      ConnectionInfo connectionInfo) {
274         InstanceIdentifier<Node> connectionNodePath = SouthboundMapper.createInstanceIdentifier(connectionInfo);
275         ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
276     }
277
278     private static void setControllerForBridge(Node ovsdbNode, String bridgeName, String targetString) {
279         ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
280         if (connectionInfo != null) {
281             for (ControllerEntry controllerEntry: createControllerEntries(targetString)) {
282                 InstanceIdentifier<ControllerEntry> iid =
283                         SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName))
284                                 .augmentation(OvsdbBridgeAugmentation.class)
285                                 .child(ControllerEntry.class, controllerEntry.getKey());
286
287                 boolean result = put(LogicalDatastoreType.CONFIGURATION, iid, controllerEntry);
288                 LOG.info("addController: result: {}", result);
289             }
290         }
291     }
292
293     private static List<ControllerEntry> createControllerEntries(String targetString) {
294         List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
295         ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
296         controllerEntryBuilder.setTarget(new Uri(targetString));
297         controllerEntries.add(controllerEntryBuilder.build());
298         return controllerEntries;
299     }
300
301     private static List<ProtocolEntry> createMdsalProtocols() {
302         List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
303         ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
304                 SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
305         protocolList.add(new ProtocolEntryBuilder().
306                 setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build());
307         return protocolList;
308     }
309
310     public static long getDataPathId(Node node) {
311         long dpid = 0L;
312         String datapathId = getDatapathId(node);
313         if (datapathId != null) {
314             dpid = new BigInteger(datapathId.replaceAll(":", ""), 16).longValue();
315         }
316         return dpid;
317     }
318
319     public static String getDatapathId(Node node) {
320         String datapathId = null;
321         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
322         if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
323             datapathId = node.getAugmentation(OvsdbBridgeAugmentation.class).getDatapathId().getValue();
324         }
325         return datapathId;
326     }
327
328     public static String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
329         String datapathId = null;
330         if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
331             datapathId = ovsdbBridgeAugmentation.getDatapathId().getValue();
332         }
333         return datapathId;
334     }
335
336     public static OvsdbBridgeAugmentation getBridge(Node node, String name) {
337         OvsdbBridgeAugmentation bridge = node.getAugmentation(OvsdbBridgeAugmentation.class);
338         if (bridge != null) {
339             if (!bridge.getBridgeName().equals(name)) {
340                 bridge = null;
341             }
342         }
343         return bridge;
344     }
345
346     public static String extractBridgeName(Node node) {
347         return (node.getAugmentation(OvsdbBridgeAugmentation.class).getBridgeName().getValue());
348     }
349
350     public static OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
351         return node.getAugmentation(OvsdbBridgeAugmentation.class);
352     }
353
354     public static List<Node> getAllBridgesOnOvsdbNode(Node node) {
355         return null;
356     }
357
358     /**
359      * Method read ports from bridge node. Method will check if the provided node
360      * has the ports details, if not, it will read from Operational data store.
361      * @param node
362      * @return
363      */
364     public static List<OvsdbTerminationPointAugmentation> getTerminationPointsOfBridge(Node node) {
365         List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations( node);
366         if(tpAugmentations.isEmpty()){
367             tpAugmentations = readTerminationPointAugmentationFromDataStore(node);
368         }
369         return tpAugmentations;
370     }
371
372     public static OvsdbTerminationPointAugmentation extractTerminationPointAugmentation(Node bridgeNode, String portName) {
373         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
374         if (ovsdbBridgeAugmentation != null) {
375             List<TerminationPoint> terminationPoints = bridgeNode.getTerminationPoint();
376             for(TerminationPoint terminationPoint : terminationPoints) {
377                 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
378                         terminationPoint.getAugmentation( OvsdbTerminationPointAugmentation.class);
379                 if (ovsdbTerminationPointAugmentation != null
380                         && ovsdbTerminationPointAugmentation.getName().equals(portName)) {
381                     return ovsdbTerminationPointAugmentation;
382                 }
383             }
384         }
385         return null;
386     }
387
388     public static List<TerminationPoint> extractTerminationPoints(Node node) {
389         List<TerminationPoint> terminationPoints = new ArrayList<TerminationPoint>();
390         OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
391         if (ovsdbBridgeAugmentation != null) {
392             terminationPoints.addAll(node.getTerminationPoint());
393         }
394         return terminationPoints;
395     }
396
397     public static List<OvsdbTerminationPointAugmentation> extractTerminationPointAugmentations( Node node ) {
398         List<OvsdbTerminationPointAugmentation> tpAugmentations = new ArrayList<OvsdbTerminationPointAugmentation>();
399         List<TerminationPoint> terminationPoints = node.getTerminationPoint();
400         if(terminationPoints != null && !terminationPoints.isEmpty()){
401             for(TerminationPoint tp : terminationPoints){
402                 tpAugmentations.add(tp.getAugmentation(OvsdbTerminationPointAugmentation.class));
403             }
404         }
405         return tpAugmentations;
406     }
407
408     public static List<OvsdbTerminationPointAugmentation> readTerminationPointAugmentationFromDataStore( Node node ) {
409         InstanceIdentifier<Node> bridgeNodeIid = SouthboundMapper.createInstanceIdentifier(node.getNodeId());
410         Node operNode = read(LogicalDatastoreType.OPERATIONAL, bridgeNodeIid);
411         if(operNode != null){
412             return extractTerminationPointAugmentations(operNode);
413         }
414         return new ArrayList<OvsdbTerminationPointAugmentation>();
415     }
416
417     public static String getInterfaceExternalIdsValue(
418             OvsdbTerminationPointAugmentation terminationPointAugmentation,String key) {
419         String value = null;
420         List<InterfaceExternalIds> pairs = terminationPointAugmentation.getInterfaceExternalIds();
421         if (pairs != null) {
422             for (InterfaceExternalIds pair : pairs) {
423                 if (pair.getKey().equals(key)) {
424                     value = pair.getExternalIdValue();
425                 }
426             }
427         }
428         return value;
429     }
430
431     public static Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName) {
432         InstanceIdentifier<TerminationPoint> tpIid =
433                 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
434         OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
435                 new OvsdbTerminationPointAugmentationBuilder();
436
437         tpAugmentationBuilder.setName(portName);
438         tpAugmentationBuilder.setInterfaceType(InterfaceTypeInternal.class);
439         TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
440         tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
441         return put(LogicalDatastoreType.CONFIGURATION,tpIid,tpBuilder.build());
442     }
443
444     public static Boolean deleteTerminationPoint(Node bridgeNode, String portName) {
445         InstanceIdentifier<TerminationPoint> tpIid =
446                 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
447         return delete(LogicalDatastoreType.CONFIGURATION,tpIid);
448     }
449
450     public static Boolean addTunnelTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type,
451                                         Map<String, String> options) {
452         InstanceIdentifier<TerminationPoint> tpIid =
453                 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
454         OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
455                 new OvsdbTerminationPointAugmentationBuilder();
456
457         tpAugmentationBuilder.setName(portName);
458         tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
459
460         List<Options> optionsList = new ArrayList<Options>();
461         for(Map.Entry<String,String> entry : options.entrySet()){
462             OptionsBuilder optionsBuilder = new OptionsBuilder();
463             optionsBuilder.setKey(new OptionsKey(entry.getKey()));
464             optionsBuilder.setOption(entry.getKey());
465             optionsBuilder.setValue(entry.getValue());
466             optionsList.add(optionsBuilder.build());
467         }
468         tpAugmentationBuilder.setOptions(optionsList);
469
470         TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
471         tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
472         return put(LogicalDatastoreType.CONFIGURATION,tpIid,tpBuilder.build());
473     }
474
475     public static Boolean addPatchTerminationPoint(Node node, String bridgeName, String portName, String peerPortName) {
476         return false;
477     }
478
479     public static String getExternalId(Node node, OvsdbTables table, String key) {
480         return null;
481     }
482
483     public static String getOtherConfig(Node node, OvsdbTables table, String key) {
484         return null;
485     }
486
487     public static boolean addVlanToTp(long vlan) {
488         return false;
489     }
490
491     public static boolean isTunnel(OvsdbTerminationPointAugmentation port) {
492         return SouthboundMapper.createOvsdbInterfaceType(
493                 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_VXLAN)
494                 || SouthboundMapper.createOvsdbInterfaceType(
495                 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_GRE);
496     }
497
498     public static String getOptionsValue(List<Options> options, String key) {
499         String value = null;
500         for (Options option : options) {
501             if (option.getKey().equals(key)) {
502                 value = option.getValue();
503             }
504         }
505         return value;
506     }
507
508     private static Topology getOvsdbTopology() {
509         InstanceIdentifier<Topology> path = InstanceIdentifier
510                 .create(NetworkTopology.class)
511                 .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
512
513         Topology topology = read(LogicalDatastoreType.OPERATIONAL, path);
514         return topology;
515     }
516
517 }