2 * Copyright (c) 2015 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.ovsdb.openstack.netvirt;
10 import java.math.BigInteger;
11 import java.security.InvalidParameterException;
12 import java.util.ArrayList;
13 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
23 import org.opendaylight.ovsdb.southbound.SouthboundConstants;
24 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeInternal;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentationBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeRef;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentation;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbTerminationPointAugmentationBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigs;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
54 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
55 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
56 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
57 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
59 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
60 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory;
63 import com.google.common.base.Optional;
64 import com.google.common.collect.ImmutableBiMap;
65 import com.google.common.util.concurrent.CheckedFuture;
68 * Utility class to wrap mdsal transactions.
70 * @author Sam Hague (shague@redhat.com)
72 public class MdsalUtils {
73 private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
74 private static DataBroker databroker = null;
75 private static final int OVSDB_UPDATE_TIMEOUT = 500;
78 * Class constructor setting the data broker.
80 * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
82 public MdsalUtils(DataBroker dataBroker) {
83 this.databroker = dataBroker;
87 * Executes delete as a blocking transaction.
89 * @param store {@link LogicalDatastoreType} which should be modified
90 * @param path {@link InstanceIdentifier} to read from
91 * @param <D> the data object type
92 * @return the result of the request
94 public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
95 final LogicalDatastoreType store, final InstanceIdentifier<D> path) {
96 boolean result = false;
97 final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
98 transaction.delete(store, path);
99 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
103 } catch (TransactionCommitFailedException e) {
104 LOG.warn("Failed to delete {} ", path, e);
110 * Executes merge as a blocking transaction.
112 * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
113 * @param path {@link InstanceIdentifier} for path to read
114 * @param <D> the data object type
115 * @return the result of the request
117 public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
118 final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data) {
119 boolean result = false;
120 final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
121 transaction.merge(logicalDatastoreType, path, data, true);
122 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
126 } catch (TransactionCommitFailedException e) {
127 LOG.warn("Failed to merge {} ", path, e);
133 * Executes put as a blocking transaction.
135 * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
136 * @param path {@link InstanceIdentifier} for path to read
137 * @param <D> the data object type
138 * @return the result of the request
140 public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
141 final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data) {
142 boolean result = false;
143 final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
144 transaction.put(logicalDatastoreType, path, data, true);
145 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
149 } catch (TransactionCommitFailedException e) {
150 LOG.warn("Failed to put {} ", path, e);
156 * Executes read as a blocking transaction.
158 * @param store {@link LogicalDatastoreType} to read
159 * @param path {@link InstanceIdentifier} for path to read
160 * @param <D> the data object type
161 * @return the result as the data object requested
163 public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
164 final LogicalDatastoreType store, final InstanceIdentifier<D> path) {
166 final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
167 Optional<D> optionalDataObject;
168 CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
170 optionalDataObject = future.checkedGet();
171 if (optionalDataObject.isPresent()) {
172 result = optionalDataObject.get();
174 LOG.debug("{}: Failed to read {}",
175 Thread.currentThread().getStackTrace()[1], path);
177 } catch (ReadFailedException e) {
178 LOG.warn("Failed to read {} ", path, e);
184 public static ConnectionInfo getConnectionInfo(Node node) {
185 ConnectionInfo connectionInfo = null;
186 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
187 if (ovsdbNodeAugmentation != null) {
188 connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
190 return connectionInfo;
193 public static String getOvsdbNodeUUID(Node node) {
194 String nodeUUID = null;
195 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
196 if (ovsdbNodeAugmentation != null) {
197 // TODO replace with proper uuid and not the system-id
198 nodeUUID = getOsdbNodeExternalIdsValue(ovsdbNodeAugmentation, "system-id");
203 public static String getOsdbNodeExternalIdsValue(OvsdbNodeAugmentation ovsdbNodeAugmentation, String key) {
205 List<OpenvswitchExternalIds> pairs = ovsdbNodeAugmentation.getOpenvswitchExternalIds();
206 for (OpenvswitchExternalIds pair : pairs) {
207 if (pair.getKey().equals(key)) {
208 value = pair.getExternalIdValue();
214 public static boolean addBridge(Node ovsdbNode, String bridgeName, String target)
215 throws InterruptedException, InvalidParameterException {
216 boolean result = false;
218 LOG.info("addBridge: node: {}, bridgeName: {}, target: {}", ovsdbNode, bridgeName, target);
219 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
220 if (connectionInfo != null) {
221 NodeBuilder bridgeNodeBuilder = new NodeBuilder();
222 InstanceIdentifier<Node> bridgeIid =
223 SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName));
224 NodeId bridgeNodeId = SouthboundMapper.createManagedNodeId(bridgeIid);
225 bridgeNodeBuilder.setNodeId(bridgeNodeId);
226 OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
227 //ovsdbBridgeAugmentationBuilder.setControllerEntry(setControllerEntries(target));
228 ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
229 ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
230 ovsdbBridgeAugmentationBuilder.setFailMode(
231 SouthboundConstants.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
232 setManagedByForBridge(ovsdbBridgeAugmentationBuilder, connectionInfo);
233 bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
235 result = merge(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build());
236 LOG.info("addBridge: result: {}", result);
237 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
238 setControllerForBridge(ovsdbNode, bridgeName, target);
239 Thread.sleep(OVSDB_UPDATE_TIMEOUT);
241 throw new InvalidParameterException("Could not find ConnectionInfo");
246 public static OvsdbBridgeAugmentation readBridge(Node node, String name) {
247 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
248 ConnectionInfo connectionInfo = getConnectionInfo(node);
249 if (connectionInfo != null) {
250 InstanceIdentifier<Node> bridgeIid =
251 SouthboundMapper.createInstanceIdentifier(connectionInfo,
252 new OvsdbBridgeName(name));
253 Node bridgeNode = read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
254 if (bridgeNode != null) {
255 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
258 return ovsdbBridgeAugmentation;
261 public static Uuid getBridgeUuid(Node node, String name) {
263 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = readBridge(node, name);
264 if (ovsdbBridgeAugmentation != null) {
265 uuid = ovsdbBridgeAugmentation.getBridgeUuid();
270 private static void setManagedByForBridge(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
271 ConnectionInfo connectionInfo) {
272 InstanceIdentifier<Node> connectionNodePath = SouthboundMapper.createInstanceIdentifier(connectionInfo);
273 ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
276 private static void setControllerForBridge(Node ovsdbNode, String bridgeName, String targetString) {
277 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
278 if (connectionInfo != null) {
279 for (ControllerEntry controllerEntry: createControllerEntries(targetString)) {
280 InstanceIdentifier<ControllerEntry> iid =
281 SouthboundMapper.createInstanceIdentifier(connectionInfo, new OvsdbBridgeName(bridgeName))
282 .augmentation(OvsdbBridgeAugmentation.class)
283 .child(ControllerEntry.class, controllerEntry.getKey());
285 boolean result = put(LogicalDatastoreType.CONFIGURATION, iid, controllerEntry);
286 LOG.info("addController: result: {}", result);
291 private static List<ControllerEntry> createControllerEntries(String targetString) {
292 List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
293 ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
294 controllerEntryBuilder.setTarget(new Uri(targetString));
295 controllerEntries.add(controllerEntryBuilder.build());
296 return controllerEntries;
299 private static List<ProtocolEntry> createMdsalProtocols() {
300 List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
301 ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
302 SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
303 protocolList.add(new ProtocolEntryBuilder().
304 setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get("OpenFlow13")).build());
308 public static long getDataPathId(Node node) {
310 String datapathId = getDatapathId(node);
311 if (datapathId != null) {
312 dpid = new BigInteger(datapathId.replaceAll(":", ""), 16).longValue();
317 public static String getDatapathId(Node node) {
318 String datapathId = null;
319 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
320 if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
321 datapathId = node.getAugmentation(OvsdbBridgeAugmentation.class).getDatapathId().getValue();
326 public static String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
327 String datapathId = null;
328 if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
329 datapathId = ovsdbBridgeAugmentation.getDatapathId().getValue();
334 public static OvsdbBridgeAugmentation getBridge(Node node, String name) {
335 OvsdbBridgeAugmentation bridge = node.getAugmentation(OvsdbBridgeAugmentation.class);
336 if (bridge != null) {
337 if (!bridge.getBridgeName().equals(name)) {
344 public static String extractBridgeName(Node node) {
345 return (node.getAugmentation(OvsdbBridgeAugmentation.class).getBridgeName().getValue());
348 public static OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
349 return node.getAugmentation(OvsdbBridgeAugmentation.class);
352 public static List<Node> getAllBridgesOnOvsdbNode(Node node) {
356 public static OvsdbNodeAugmentation extractOvsdbNodeAugmentation(Node node) {
357 return node.getAugmentation(OvsdbNodeAugmentation.class);
361 * Method read ports from bridge node. Method will check if the provided node
362 * has the ports details, if not, it will read from Operational data store.
366 public static List<OvsdbTerminationPointAugmentation> getTerminationPointsOfBridge(Node node) {
367 List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations( node);
368 if(tpAugmentations.isEmpty()){
369 tpAugmentations = readTerminationPointAugmentationFromDataStore(node);
371 return tpAugmentations;
374 public static OvsdbTerminationPointAugmentation extractTerminationPointAugmentation(Node bridgeNode, String portName) {
375 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
376 if (ovsdbBridgeAugmentation != null) {
377 List<TerminationPoint> terminationPoints = bridgeNode.getTerminationPoint();
378 for(TerminationPoint terminationPoint : terminationPoints) {
379 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
380 terminationPoint.getAugmentation( OvsdbTerminationPointAugmentation.class);
381 if (ovsdbTerminationPointAugmentation != null
382 && ovsdbTerminationPointAugmentation.getName().equals(portName)) {
383 return ovsdbTerminationPointAugmentation;
390 public static List<TerminationPoint> extractTerminationPoints(Node node) {
391 List<TerminationPoint> terminationPoints = new ArrayList<TerminationPoint>();
392 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
393 if (ovsdbBridgeAugmentation != null) {
394 terminationPoints.addAll(node.getTerminationPoint());
396 return terminationPoints;
399 public static List<OvsdbTerminationPointAugmentation> extractTerminationPointAugmentations( Node node ) {
400 List<OvsdbTerminationPointAugmentation> tpAugmentations = new ArrayList<OvsdbTerminationPointAugmentation>();
401 List<TerminationPoint> terminationPoints = node.getTerminationPoint();
402 if(terminationPoints != null && !terminationPoints.isEmpty()){
403 for(TerminationPoint tp : terminationPoints){
404 tpAugmentations.add(tp.getAugmentation(OvsdbTerminationPointAugmentation.class));
407 return tpAugmentations;
410 public static List<OvsdbTerminationPointAugmentation> readTerminationPointAugmentationFromDataStore( Node node ) {
411 InstanceIdentifier<Node> bridgeNodeIid = SouthboundMapper.createInstanceIdentifier(node.getNodeId());
412 Node operNode = read(LogicalDatastoreType.OPERATIONAL, bridgeNodeIid);
413 if(operNode != null){
414 return extractTerminationPointAugmentations(operNode);
416 return new ArrayList<OvsdbTerminationPointAugmentation>();
419 public static String getInterfaceExternalIdsValue(
420 OvsdbTerminationPointAugmentation terminationPointAugmentation,String key) {
422 List<InterfaceExternalIds> pairs = terminationPointAugmentation.getInterfaceExternalIds();
424 for (InterfaceExternalIds pair : pairs) {
425 if (pair.getKey().equals(key)) {
426 value = pair.getExternalIdValue();
433 public static Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName) {
434 InstanceIdentifier<TerminationPoint> tpIid =
435 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
436 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
437 new OvsdbTerminationPointAugmentationBuilder();
439 tpAugmentationBuilder.setName(portName);
440 tpAugmentationBuilder.setInterfaceType(InterfaceTypeInternal.class);
441 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
442 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
443 return put(LogicalDatastoreType.CONFIGURATION,tpIid,tpBuilder.build());
446 public static Boolean deleteTerminationPoint(Node bridgeNode, String portName) {
447 InstanceIdentifier<TerminationPoint> tpIid =
448 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
449 return delete(LogicalDatastoreType.CONFIGURATION,tpIid);
452 public static Boolean addTunnelTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type,
453 Map<String, String> options) {
454 InstanceIdentifier<TerminationPoint> tpIid =
455 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
456 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
457 new OvsdbTerminationPointAugmentationBuilder();
459 tpAugmentationBuilder.setName(portName);
460 tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
462 List<Options> optionsList = new ArrayList<Options>();
463 for(Map.Entry<String,String> entry : options.entrySet()){
464 OptionsBuilder optionsBuilder = new OptionsBuilder();
465 optionsBuilder.setKey(new OptionsKey(entry.getKey()));
466 optionsBuilder.setOption(entry.getKey());
467 optionsBuilder.setValue(entry.getValue());
468 optionsList.add(optionsBuilder.build());
470 tpAugmentationBuilder.setOptions(optionsList);
472 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
473 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
474 return put(LogicalDatastoreType.CONFIGURATION,tpIid,tpBuilder.build());
477 public static Boolean addPatchTerminationPoint(Node node, String bridgeName, String portName, String peerPortName) {
481 public static String getExternalId(Node node, OvsdbTables table, String key) {
484 for (BridgeExternalIds bridgeExternaIds :extractBridgeAugmentation(node).getBridgeExternalIds()) {
485 if (bridgeExternaIds.getBridgeExternalIdKey().equals(key)) {
486 return bridgeExternaIds.getBridgeExternalIdValue();
490 LOG.debug("There is no external_id for OvsdbTables: ", table);
493 for ( OpenvswitchExternalIds openvswitchExternalIds :extractOvsdbNodeAugmentation(node).getOpenvswitchExternalIds()) {
494 if (openvswitchExternalIds.getExternalIdKey().equals(key)) {
495 return openvswitchExternalIds.getExternalIdValue();
499 for (OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation :extractTerminationPointAugmentations(node)) {
500 for (PortExternalIds portExternalIds :ovsdbTerminationPointAugmentation.getPortExternalIds()) {
501 if (portExternalIds.getExternalIdKey().equals(key)) {
502 return portExternalIds.getExternalIdValue();
507 LOG.debug("Couldn't find the specified OvsdbTables: ", table);
512 public static String getOtherConfig(Node node, OvsdbTables table, String key) {
515 for (BridgeOtherConfigs bridgeOtherConfigs :extractBridgeAugmentation(node).getBridgeOtherConfigs()) {
516 if (bridgeOtherConfigs.getBridgeOtherConfigKey().equals(key)) {
517 return bridgeOtherConfigs.getBridgeOtherConfigValue();
521 LOG.debug("There is no other_config for OvsdbTables: ", table);
524 for ( OpenvswitchOtherConfigs openvswitchOtherConfigs :extractOvsdbNodeAugmentation(node).getOpenvswitchOtherConfigs()) {
525 if (openvswitchOtherConfigs.getOtherConfigKey().equals(key)) {
526 return openvswitchOtherConfigs.getOtherConfigValue();
530 for (OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation :extractTerminationPointAugmentations(node)) {
531 for (PortOtherConfigs portOtherConfigs :ovsdbTerminationPointAugmentation.getPortOtherConfigs()) {
532 if (portOtherConfigs.getOtherConfigKey().equals(key)) {
533 return portOtherConfigs.getOtherConfigValue();
538 LOG.debug("Couldn't find the specified OvsdbTables: ", table);
543 public static boolean addVlanToTp(long vlan) {
547 public static boolean isTunnel(OvsdbTerminationPointAugmentation port) {
548 return SouthboundMapper.createOvsdbInterfaceType(
549 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_VXLAN)
550 || SouthboundMapper.createOvsdbInterfaceType(
551 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_GRE);
554 public static String getOptionsValue(List<Options> options, String key) {
556 for (Options option : options) {
557 if (option.getKey().equals(key)) {
558 value = option.getValue();
564 private static Topology getOvsdbTopology() {
565 InstanceIdentifier<Topology> path = InstanceIdentifier
566 .create(NetworkTopology.class)
567 .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
569 Topology topology = read(LogicalDatastoreType.OPERATIONAL, path);