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.impl;
10 import java.math.BigInteger;
11 import java.security.InvalidParameterException;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.ovsdb.openstack.netvirt.MdsalHelper;
20 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
21 import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
23 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.InterfaceTypeEntry;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigs;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
53 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 import com.google.common.collect.ImmutableBiMap;
60 * Utility class to wrap mdsal transactions.
62 * @author Sam Hague (shague@redhat.com)
64 public class SouthboundImpl implements Southbound {
65 private static final Logger LOG = LoggerFactory.getLogger(SouthboundImpl.class);
66 private final DataBroker databroker;
67 private static final String PATCH_PORT_TYPE = "patch";
68 private final MdsalUtils mdsalUtils;
71 * Class constructor setting the data broker.
73 * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
75 public SouthboundImpl(DataBroker dataBroker) {
76 this.databroker = dataBroker;
77 mdsalUtils = new MdsalUtils(dataBroker);
80 public DataBroker getDatabroker() {
84 public ConnectionInfo getConnectionInfo(Node ovsdbNode) {
85 ConnectionInfo connectionInfo = null;
86 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode);
87 if (ovsdbNodeAugmentation != null) {
88 connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
90 return connectionInfo;
93 public OvsdbNodeAugmentation extractOvsdbNode(Node node) {
94 return node.getAugmentation(OvsdbNodeAugmentation.class);
97 public NodeId extractBridgeOvsdbNodeId(Node bridgeNode) {
98 NodeId ovsdbNodeId = null;
99 OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
100 if (bridgeAugmentation != null) {
101 @SuppressWarnings("unchecked")
102 InstanceIdentifier<Node> ovsdbNodeIid =
103 (InstanceIdentifier<Node>) (bridgeAugmentation.getManagedBy().getValue());
104 ovsdbNodeId = InstanceIdentifier.keyOf(ovsdbNodeIid).getNodeId();
109 public List<Node> readOvsdbTopologyNodes() {
110 List<Node> ovsdbNodes = new ArrayList<>();
111 InstanceIdentifier<Topology> topologyInstanceIdentifier = MdsalHelper.createInstanceIdentifier();
112 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyInstanceIdentifier);
113 if (topology != null && topology.getNode() != null) {
114 for (Node node : topology.getNode()) {
115 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
116 if (ovsdbNodeAugmentation != null) {
117 ovsdbNodes.add(node);
124 public List<Node> readOvsdbTopologyBridgeNodes() {
125 List<Node> ovsdbNodes = new ArrayList<>();
126 InstanceIdentifier<Topology> topologyInstanceIdentifier = MdsalHelper.createInstanceIdentifier();
127 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyInstanceIdentifier);
128 if (topology != null && topology.getNode() != null) {
129 for (Node node : topology.getNode()) {
130 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
131 if (ovsdbBridgeAugmentation != null) {
132 ovsdbNodes.add(node);
139 public Node readOvsdbNode(Node bridgeNode) {
140 Node ovsdbNode = null;
141 OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
142 if (bridgeAugmentation != null) {
143 InstanceIdentifier<Node> ovsdbNodeIid =
144 (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
145 ovsdbNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbNodeIid);
147 LOG.debug("readOvsdbNode: Provided node is not a bridge node : {}",bridgeNode);
152 public String getOvsdbNodeUUID(Node node) {
153 String nodeUUID = null;
154 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
155 if (ovsdbNodeAugmentation != null) {
156 // TODO replace with proper uuid and not the system-id
157 nodeUUID = getOsdbNodeExternalIdsValue(ovsdbNodeAugmentation, "system-id");
162 public String getOsdbNodeExternalIdsValue(OvsdbNodeAugmentation ovsdbNodeAugmentation, String key) {
164 List<OpenvswitchExternalIds> pairs = ovsdbNodeAugmentation.getOpenvswitchExternalIds();
165 if (pairs != null && !pairs.isEmpty()) {
166 for (OpenvswitchExternalIds pair : pairs) {
167 if (pair.getExternalIdKey().equals(key)) {
168 value = pair.getExternalIdValue();
176 public boolean addBridge(Node ovsdbNode, String bridgeName, List<String> controllersStr,
177 final Class<? extends DatapathTypeBase> dpType) {
180 LOG.info("addBridge: node: {}, bridgeName: {}, controller(s): {}", ovsdbNode, bridgeName, controllersStr);
181 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
182 if (connectionInfo != null) {
183 NodeBuilder bridgeNodeBuilder = new NodeBuilder();
184 InstanceIdentifier<Node> bridgeIid =
185 MdsalHelper.createInstanceIdentifier(ovsdbNode.getKey(), bridgeName);
186 NodeId bridgeNodeId = MdsalHelper.createManagedNodeId(bridgeIid);
187 bridgeNodeBuilder.setNodeId(bridgeNodeId);
188 OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
189 ovsdbBridgeAugmentationBuilder.setControllerEntry(createControllerEntries(controllersStr));
190 ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
191 ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
192 ovsdbBridgeAugmentationBuilder.setFailMode(
193 MdsalHelper.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
194 BridgeOtherConfigsBuilder bridgeOtherConfigsBuilder = new BridgeOtherConfigsBuilder();
195 bridgeOtherConfigsBuilder.setBridgeOtherConfigKey(MdsalHelper.DISABLE_IN_BAND);
196 bridgeOtherConfigsBuilder.setBridgeOtherConfigValue("true");
197 bridgeOtherConfigsBuilder.setBridgeOtherConfigKey(MdsalHelper.DISABLE_IN_BAND);
198 List<BridgeOtherConfigs> bridgeOtherConfigsList = new ArrayList<>();
199 bridgeOtherConfigsList.add(bridgeOtherConfigsBuilder.build());
200 ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(bridgeOtherConfigsList);
201 setManagedByForBridge(ovsdbBridgeAugmentationBuilder, ovsdbNode.getKey());
202 if (dpType != null) {
203 ovsdbBridgeAugmentationBuilder.setDatapathType(dpType);
205 if (isOvsdbNodeDpdk(ovsdbNode)) {
206 ovsdbBridgeAugmentationBuilder.setDatapathType(DatapathTypeNetdev.class);
208 bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
210 result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, bridgeIid, bridgeNodeBuilder.build());
211 LOG.info("addBridge: result: {}", result);
213 throw new InvalidParameterException("Could not find ConnectionInfo");
218 public boolean deleteBridge(Node ovsdbNode) {
219 InstanceIdentifier<Node> bridgeIid =
220 MdsalHelper.createInstanceIdentifier(ovsdbNode.getNodeId());
222 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, bridgeIid);
223 LOG.info("deleteBridge node: {}, bridgeName: {} result : {}", ovsdbNode, ovsdbNode.getNodeId(),result);
227 public OvsdbBridgeAugmentation readBridge(Node node, String name) {
228 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
229 ConnectionInfo connectionInfo = getConnectionInfo(node);
230 if (connectionInfo != null) {
231 InstanceIdentifier<Node> bridgeIid =
232 MdsalHelper.createInstanceIdentifier(node.getKey(), name);
233 Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
234 if (bridgeNode != null) {
235 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
238 return ovsdbBridgeAugmentation;
241 public Node readBridgeNode(Node node, String name) {
242 Node ovsdbNode = node;
243 if (extractNodeAugmentation(ovsdbNode) == null) {
244 ovsdbNode = readOvsdbNode(node);
246 Node bridgeNode = null;
247 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
248 if (connectionInfo != null) {
249 InstanceIdentifier<Node> bridgeIid =
250 MdsalHelper.createInstanceIdentifier(node.getKey(), name);
251 bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
256 public Node getBridgeNode(Node node, String bridgeName) {
257 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
258 if (bridge != null && bridge.getBridgeName().getValue().equals(bridgeName)) {
261 return readBridgeNode(node, bridgeName);
265 public String getBridgeUuid(Node node, String name) {
267 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = readBridge(node, name);
268 if (ovsdbBridgeAugmentation != null) {
269 uuid = ovsdbBridgeAugmentation.getBridgeUuid().getValue();
274 private void setManagedByForBridge(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
275 NodeKey ovsdbNodeKey) {
276 InstanceIdentifier<Node> connectionNodePath = MdsalHelper.createInstanceIdentifier(ovsdbNodeKey.getNodeId());
277 ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
280 private List<ControllerEntry> createControllerEntries(List<String> controllersStr) {
281 List<ControllerEntry> controllerEntries = new ArrayList<>();
282 if (controllersStr != null) {
283 for (String controllerStr : controllersStr) {
284 ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
285 controllerEntryBuilder.setTarget(new Uri(controllerStr));
286 controllerEntries.add(controllerEntryBuilder.build());
289 return controllerEntries;
292 private List<ProtocolEntry> createMdsalProtocols() {
293 List<ProtocolEntry> protocolList = new ArrayList<>();
294 ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
295 MdsalHelper.OVSDB_PROTOCOL_MAP.inverse();
296 protocolList.add(new ProtocolEntryBuilder().
297 setProtocol(mapper.get("OpenFlow13")).build());
301 public long getDataPathId(Node node) {
303 String datapathId = getDatapathId(node);
304 if (datapathId != null) {
305 dpid = new BigInteger(datapathId.replaceAll(":", ""), 16).longValue();
310 public String getDatapathId(Node node) {
311 String datapathId = null;
312 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
313 if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
314 datapathId = node.getAugmentation(OvsdbBridgeAugmentation.class).getDatapathId().getValue();
319 public String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
320 String datapathId = null;
321 if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
322 datapathId = ovsdbBridgeAugmentation.getDatapathId().getValue();
327 public OvsdbBridgeAugmentation getBridge(Node node, String name) {
328 OvsdbBridgeAugmentation bridge = node.getAugmentation(OvsdbBridgeAugmentation.class);
329 if ((bridge != null) && (!bridge.getBridgeName().getValue().equals(name))) {
335 public OvsdbBridgeAugmentation getBridge(Node node) {
336 return node.getAugmentation(OvsdbBridgeAugmentation.class);
339 public String getBridgeName(Node node) {
340 String bridgeName = null;
341 OvsdbBridgeAugmentation bridge = getBridge(node);
342 if (bridge != null) {
343 bridgeName = bridge.getBridgeName().getValue();
348 public String extractBridgeName(Node node) {
349 return node.getAugmentation(OvsdbBridgeAugmentation.class).getBridgeName().getValue();
352 public OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
356 return node.getAugmentation(OvsdbBridgeAugmentation.class);
359 public List<Node> getAllBridgesOnOvsdbNode(Node node) {
360 List<Node> nodes = new ArrayList<>();
361 List<ManagedNodeEntry> managedNodes = node.getAugmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
362 for (ManagedNodeEntry managedNode : managedNodes) {
363 InstanceIdentifier<?> bridgeIid = managedNode.getBridgeRef().getValue();
364 Node bridgeNode = (Node) mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
365 if (bridgeNode != null) {
366 nodes.add(bridgeNode);
372 public boolean isBridgeOnOvsdbNode(Node ovsdbNode, String bridgeName) {
373 boolean found = false;
374 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractNodeAugmentation(ovsdbNode);
375 if (ovsdbNodeAugmentation != null) {
376 List<ManagedNodeEntry> managedNodes = ovsdbNodeAugmentation.getManagedNodeEntry();
377 if (managedNodes != null) {
378 for (ManagedNodeEntry managedNode : managedNodes) {
379 InstanceIdentifier<?> bridgeIid = managedNode.getBridgeRef().getValue();
380 if (bridgeIid.toString().contains(bridgeName)) {
390 public boolean isOvsdbNodeDpdk(Node ovsdbNode) {
391 boolean found = false;
392 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractNodeAugmentation(ovsdbNode);
393 if (ovsdbNodeAugmentation != null) {
394 List<InterfaceTypeEntry> ifTypes = ovsdbNodeAugmentation.getInterfaceTypeEntry();
395 if (ifTypes != null) {
396 for (InterfaceTypeEntry ifType : ifTypes) {
397 if (ifType.getInterfaceType().equals(InterfaceTypeDpdk.class)) {
407 public OvsdbNodeAugmentation extractNodeAugmentation(Node node) {
408 return node.getAugmentation(OvsdbNodeAugmentation.class);
412 * Method read ports from bridge node. Method will check if the provided node
413 * has the ports details, if not, it will read from Operational data store.
414 * @param node Target bridge to getch termination points from.
415 * @return List of termination points on the given bridge
417 public List<OvsdbTerminationPointAugmentation> getTerminationPointsOfBridge(Node node) {
418 List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations(node);
419 if(tpAugmentations.isEmpty()){
420 tpAugmentations = readTerminationPointAugmentations(node);
422 return tpAugmentations;
425 public OvsdbTerminationPointAugmentation getTerminationPointOfBridge(Node node, String portName) {
426 OvsdbTerminationPointAugmentation tpAugmentation = extractTerminationPointAugmentation(node,portName);
427 if(tpAugmentation == null){
428 List<OvsdbTerminationPointAugmentation> tpAugmentations = readTerminationPointAugmentations(node);
429 if(tpAugmentations != null){
430 for(OvsdbTerminationPointAugmentation ovsdbTpAugmentation : tpAugmentations){
431 if(ovsdbTpAugmentation.getName().equals(portName)){
432 return ovsdbTpAugmentation;
437 return tpAugmentation;
440 public OvsdbTerminationPointAugmentation extractTerminationPointAugmentation(Node bridgeNode, String portName) {
441 if (bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class) != null) {
442 List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations(bridgeNode);
443 for (OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation : tpAugmentations) {
444 if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
445 return ovsdbTerminationPointAugmentation;
452 public List<TerminationPoint> extractTerminationPoints(Node node) {
453 List<TerminationPoint> terminationPoints = new ArrayList<>();
454 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
455 if (ovsdbBridgeAugmentation != null) {
456 terminationPoints.addAll(node.getTerminationPoint());
458 return terminationPoints;
461 public List<OvsdbTerminationPointAugmentation> extractTerminationPointAugmentations( Node node ) {
462 List<OvsdbTerminationPointAugmentation> tpAugmentations = new ArrayList<>();
463 List<TerminationPoint> terminationPoints = node.getTerminationPoint();
464 if(terminationPoints != null && !terminationPoints.isEmpty()){
465 for(TerminationPoint tp : terminationPoints){
466 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
467 tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
468 if (ovsdbTerminationPointAugmentation != null) {
469 tpAugmentations.add(ovsdbTerminationPointAugmentation);
473 return tpAugmentations;
476 public List<OvsdbTerminationPointAugmentation> readTerminationPointAugmentations(Node node) {
477 InstanceIdentifier<Node> bridgeNodeIid = MdsalHelper.createInstanceIdentifier(node.getNodeId());
478 Node operNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeNodeIid);
479 if(operNode != null){
480 return extractTerminationPointAugmentations(operNode);
482 return new ArrayList<>();
485 public String getInterfaceExternalIdsValue(
486 OvsdbTerminationPointAugmentation terminationPointAugmentation, String key) {
488 List<InterfaceExternalIds> pairs = terminationPointAugmentation.getInterfaceExternalIds();
489 if (pairs != null && !pairs.isEmpty()) {
490 for (InterfaceExternalIds pair : pairs) {
491 if (pair.getExternalIdKey().equals(key)) {
492 value = pair.getExternalIdValue();
500 public Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type) {
501 InstanceIdentifier<TerminationPoint> tpIid =
502 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
503 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
504 new OvsdbTerminationPointAugmentationBuilder();
506 tpAugmentationBuilder.setName(portName);
508 tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
510 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
511 tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
512 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
513 return mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build());
516 public Boolean deleteTerminationPoint(Node bridgeNode, String portName) {
517 InstanceIdentifier<TerminationPoint> tpIid =
518 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
519 return mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, tpIid);
522 public Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName,
523 String type, Map<String, String> options) {
524 InstanceIdentifier<TerminationPoint> tpIid = MdsalHelper.createTerminationPointInstanceIdentifier(
525 bridgeNode, portName);
526 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
528 tpAugmentationBuilder.setName(portName);
530 tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
533 List<Options> optionsList = new ArrayList<>();
534 for (Map.Entry<String, String> entry : options.entrySet()) {
535 OptionsBuilder optionsBuilder = new OptionsBuilder();
536 optionsBuilder.setKey(new OptionsKey(entry.getKey()));
537 optionsBuilder.setOption(entry.getKey());
538 optionsBuilder.setValue(entry.getValue());
539 optionsList.add(optionsBuilder.build());
541 tpAugmentationBuilder.setOptions(optionsList);
543 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
544 tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
545 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
546 /* TODO SB_MIGRATION should this be merge or mdsalUtils.put */
547 return mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build());
550 public TerminationPoint readTerminationPoint(Node bridgeNode, String bridgeName, String portName) {
551 InstanceIdentifier<TerminationPoint> tpIid = MdsalHelper.createTerminationPointInstanceIdentifier(
552 bridgeNode, portName);
553 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, tpIid);
556 public Boolean addTunnelTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type,
557 Map<String, String> options) {
558 return addTerminationPoint(bridgeNode, bridgeName, portName, type, options);
561 public Boolean isTunnelTerminationPointExist(Node bridgeNode, String bridgeName, String portName){
562 return readTerminationPoint(bridgeNode, bridgeName, portName) != null;
565 public Boolean addPatchTerminationPoint(Node node, String bridgeName, String portName, String peerPortName) {
566 Map<String, String> option = new HashMap<>();
567 option.put("peer", peerPortName);
568 return addTerminationPoint(node, bridgeName, portName, PATCH_PORT_TYPE, option);
571 public String getExternalId(Node node, OvsdbTables table, String key) {
574 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
575 if (bridge != null && bridge.getBridgeExternalIds() != null) {
576 for (BridgeExternalIds bridgeExternaIds :bridge.getBridgeExternalIds()) {
577 if (bridgeExternaIds.getBridgeExternalIdKey().equals(key)) {
578 return bridgeExternaIds.getBridgeExternalIdValue();
584 LOG.warn("getExternalId: There is no external_id for OvsdbTables: ", table);
587 OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
588 if (ovsdbNode == null) {
589 Node nodeFromReadOvsdbNode = readOvsdbNode(node);
590 ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
592 if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
593 for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds()) {
594 if (openvswitchExternalIds.getExternalIdKey().equals(key)) {
595 return openvswitchExternalIds.getExternalIdValue();
601 List <OvsdbTerminationPointAugmentation> ports = extractTerminationPointAugmentations(node);
602 for (OvsdbTerminationPointAugmentation port : ports) {
603 if (port != null && port.getPortExternalIds() != null) {
604 for (PortExternalIds portExternalIds :port.getPortExternalIds()) {
605 if (portExternalIds.getExternalIdKey().equals(key)) {
606 return portExternalIds.getExternalIdValue();
613 LOG.debug("getExternalId: Couldn't find the specified OvsdbTable: ", table);
619 public String getOtherConfig(Node node, OvsdbTables table, String key) {
622 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
623 if (bridge != null && bridge.getBridgeOtherConfigs() != null) {
624 for (BridgeOtherConfigs bridgeOtherConfigs : bridge.getBridgeOtherConfigs()) {
625 if (bridgeOtherConfigs.getBridgeOtherConfigKey().equals(key)) {
626 return bridgeOtherConfigs.getBridgeOtherConfigValue();
632 LOG.warn("getOtherConfig: There is no other_config for OvsdbTables: ", table);
636 OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
637 if (ovsdbNode == null) {
638 Node nodeFromReadOvsdbNode = readOvsdbNode(node);
639 ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
641 if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
642 for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {
643 if (openvswitchOtherConfigs.getOtherConfigKey().equals(key)) {
644 return openvswitchOtherConfigs.getOtherConfigValue();
650 List <OvsdbTerminationPointAugmentation> ports = extractTerminationPointAugmentations(node);
651 for (OvsdbTerminationPointAugmentation port : ports) {
652 if (port != null && port.getPortOtherConfigs() != null) {
653 for (PortOtherConfigs portOtherConfigs : port.getPortOtherConfigs()) {
654 if (portOtherConfigs.getOtherConfigKey().equals(key)) {
655 return portOtherConfigs.getOtherConfigValue();
662 LOG.debug("getOtherConfig: Couldn't find the specified OvsdbTable: ", table);
668 public boolean addVlanToTp(long vlan) {
672 public boolean isTunnel(OvsdbTerminationPointAugmentation port) {
673 LOG.trace("SouthboundImpl#isTunnel: Interface : {}", port);
675 if(port.getInterfaceType() == null){
676 LOG.warn("No type found for the interface : {}", port);
679 return MdsalHelper.createOvsdbInterfaceType(
680 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_VXLAN)
681 || MdsalHelper.createOvsdbInterfaceType(
682 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_GRE);
685 public String getOptionsValue(List<Options> options, String key) {
687 for (Options option : options) {
688 if (option.getOption().equals(key)) {
689 value = option.getValue();
695 public Topology getOvsdbTopology() {
696 InstanceIdentifier<Topology> path = InstanceIdentifier
697 .create(NetworkTopology.class)
698 .child(Topology.class, new TopologyKey(MdsalHelper.OVSDB_TOPOLOGY_ID));
700 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
703 public Long getOFPort(OvsdbTerminationPointAugmentation port) {
705 if (port.getOfport() != null) {
706 ofPort = port.getOfport();
711 public Long getOFPort(Node bridgeNode, String portName) {
713 OvsdbTerminationPointAugmentation port = extractTerminationPointAugmentation(bridgeNode, portName);
715 ofPort = getOFPort(port);
717 TerminationPoint tp = readTerminationPoint(bridgeNode, null, portName);
719 port = tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
721 ofPort = getOFPort(port);
727 public OvsdbBridgeAugmentation getBridgeFromConfig(Node node, String bridge) {
728 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
729 InstanceIdentifier<Node> bridgeIid =
730 MdsalHelper.createInstanceIdentifier(node.getKey(), bridge);
731 Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, bridgeIid);
732 if (bridgeNode != null) {
733 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
735 return ovsdbBridgeAugmentation;