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.netvirt.openstack.netvirt.impl;
10 import java.math.BigInteger;
11 import java.security.InvalidParameterException;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.List;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.netvirt.openstack.netvirt.NetworkHandler;
21 import org.opendaylight.netvirt.openstack.netvirt.api.OvsdbTables;
22 import org.opendaylight.netvirt.openstack.netvirt.ClusterAwareMdsalUtils;
23 import org.opendaylight.netvirt.openstack.netvirt.MdsalHelper;
24 import org.opendaylight.netvirt.openstack.netvirt.api.Southbound;
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.opendaylight.params.xml.ns.yang.ovsdb.rev150105.*;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIds;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.InterfaceTypeEntry;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchOtherConfigs;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.InterfaceExternalIds;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortExternalIds;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.PortOtherConfigs;
45 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
48 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
49 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
50 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
51 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
53 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
58 import com.google.common.collect.ImmutableBiMap;
61 * Utility class to wrap mdsal transactions.
63 * @author Sam Hague (shague@redhat.com)
65 public class SouthboundImpl implements Southbound {
66 private static final Logger LOG = LoggerFactory.getLogger(SouthboundImpl.class);
67 private final DataBroker databroker;
68 private static final String PATCH_PORT_TYPE = "patch";
69 private final ClusterAwareMdsalUtils mdsalUtils;
72 * Class constructor setting the data broker.
74 * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
76 public SouthboundImpl(DataBroker dataBroker) {
77 this.databroker = dataBroker;
78 mdsalUtils = new ClusterAwareMdsalUtils(dataBroker);
81 public DataBroker getDatabroker() {
85 public ConnectionInfo getConnectionInfo(Node ovsdbNode) {
86 ConnectionInfo connectionInfo = null;
87 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractOvsdbNode(ovsdbNode);
88 if (ovsdbNodeAugmentation != null) {
89 connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
91 return connectionInfo;
94 public OvsdbNodeAugmentation extractOvsdbNode(Node node) {
95 return node.getAugmentation(OvsdbNodeAugmentation.class);
98 public NodeId extractBridgeOvsdbNodeId(Node bridgeNode) {
99 NodeId ovsdbNodeId = null;
100 OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
101 if (bridgeAugmentation != null) {
102 @SuppressWarnings("unchecked")
103 InstanceIdentifier<Node> ovsdbNodeIid =
104 (InstanceIdentifier<Node>) (bridgeAugmentation.getManagedBy().getValue());
105 ovsdbNodeId = InstanceIdentifier.keyOf(ovsdbNodeIid).getNodeId();
110 public List<Node> readOvsdbTopologyNodes() {
111 List<Node> ovsdbNodes = new ArrayList<>();
112 InstanceIdentifier<Topology> topologyInstanceIdentifier = MdsalHelper.createInstanceIdentifier();
113 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyInstanceIdentifier);
114 if (topology != null && topology.getNode() != null) {
115 for (Node node : topology.getNode()) {
116 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
117 if (ovsdbNodeAugmentation != null) {
118 ovsdbNodes.add(node);
125 public List<Node> readOvsdbTopologyBridgeNodes() {
126 List<Node> ovsdbNodes = new ArrayList<>();
127 InstanceIdentifier<Topology> topologyInstanceIdentifier = MdsalHelper.createInstanceIdentifier();
128 Topology topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, topologyInstanceIdentifier);
129 if (topology != null && topology.getNode() != null) {
130 for (Node node : topology.getNode()) {
131 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
132 if (ovsdbBridgeAugmentation != null) {
133 ovsdbNodes.add(node);
140 public Node readOvsdbNode(Node bridgeNode) {
141 Node ovsdbNode = null;
142 OvsdbBridgeAugmentation bridgeAugmentation = extractBridgeAugmentation(bridgeNode);
143 if (bridgeAugmentation != null) {
144 InstanceIdentifier<Node> ovsdbNodeIid =
145 (InstanceIdentifier<Node>) bridgeAugmentation.getManagedBy().getValue();
146 ovsdbNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, ovsdbNodeIid);
148 LOG.debug("readOvsdbNode: Provided node is not a bridge node : {}",bridgeNode);
153 public String getOvsdbNodeUUID(Node node) {
154 String nodeUUID = null;
155 OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class);
156 if (ovsdbNodeAugmentation != null) {
157 // TODO replace with proper uuid and not the system-id
158 nodeUUID = getOsdbNodeExternalIdsValue(ovsdbNodeAugmentation, "system-id");
163 public String getOsdbNodeExternalIdsValue(OvsdbNodeAugmentation ovsdbNodeAugmentation, String key) {
165 List<OpenvswitchExternalIds> pairs = ovsdbNodeAugmentation.getOpenvswitchExternalIds();
166 if (pairs != null && !pairs.isEmpty()) {
167 for (OpenvswitchExternalIds pair : pairs) {
168 if (pair.getExternalIdKey().equals(key)) {
169 value = pair.getExternalIdValue();
177 public boolean addBridge(Node ovsdbNode, String bridgeName, List<String> controllersStr,
178 final Class<? extends DatapathTypeBase> dpType) {
179 return addBridge(ovsdbNode, bridgeName, controllersStr, dpType, null);
182 public boolean addBridge(Node ovsdbNode, String bridgeName, List<String> controllersStr,
183 final Class<? extends DatapathTypeBase> dpType, String mac) {
186 LOG.info("addBridge: node: {}, bridgeName: {}, controller(s): {}", ovsdbNode, bridgeName, controllersStr);
187 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
188 if (connectionInfo != null) {
189 NodeBuilder bridgeNodeBuilder = new NodeBuilder();
190 InstanceIdentifier<Node> bridgeIid =
191 MdsalHelper.createInstanceIdentifier(ovsdbNode.getKey(), bridgeName);
192 NodeId bridgeNodeId = MdsalHelper.createManagedNodeId(bridgeIid);
193 bridgeNodeBuilder.setNodeId(bridgeNodeId);
194 OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder = new OvsdbBridgeAugmentationBuilder();
195 ovsdbBridgeAugmentationBuilder.setControllerEntry(createControllerEntries(controllersStr));
196 ovsdbBridgeAugmentationBuilder.setBridgeName(new OvsdbBridgeName(bridgeName));
197 ovsdbBridgeAugmentationBuilder.setProtocolEntry(createMdsalProtocols());
198 ovsdbBridgeAugmentationBuilder.setFailMode(
199 MdsalHelper.OVSDB_FAIL_MODE_MAP.inverse().get("secure"));
200 BridgeOtherConfigsBuilder bridgeOtherConfigsBuilder = new BridgeOtherConfigsBuilder();
201 bridgeOtherConfigsBuilder.setBridgeOtherConfigKey(MdsalHelper.DISABLE_IN_BAND);
202 bridgeOtherConfigsBuilder.setBridgeOtherConfigValue("true");
203 List<BridgeOtherConfigs> bridgeOtherConfigsList = new ArrayList<>();
204 bridgeOtherConfigsList.add(bridgeOtherConfigsBuilder.build());
206 BridgeOtherConfigsBuilder macOtherConfigBuilder = new BridgeOtherConfigsBuilder();
207 macOtherConfigBuilder.setBridgeOtherConfigKey("hwaddr");
208 macOtherConfigBuilder.setBridgeOtherConfigValue(mac);
209 bridgeOtherConfigsList.add(macOtherConfigBuilder.build());
211 ovsdbBridgeAugmentationBuilder.setBridgeOtherConfigs(bridgeOtherConfigsList);
212 setManagedByForBridge(ovsdbBridgeAugmentationBuilder, ovsdbNode.getKey());
213 if (dpType != null) {
214 ovsdbBridgeAugmentationBuilder.setDatapathType(dpType);
216 if (isOvsdbNodeDpdk(ovsdbNode)) {
217 ovsdbBridgeAugmentationBuilder.setDatapathType(DatapathTypeNetdev.class);
219 bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
221 Node node = bridgeNodeBuilder.build();
222 result = mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, bridgeIid, node);
223 LOG.info("addBridge: result: {}", result);
225 throw new InvalidParameterException("Could not find ConnectionInfo");
230 public boolean deleteBridge(Node ovsdbNode) {
231 InstanceIdentifier<Node> bridgeIid =
232 MdsalHelper.createInstanceIdentifier(ovsdbNode.getNodeId());
234 boolean result = mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, bridgeIid);
235 LOG.info("deleteBridge node: {}, bridgeName: {} result : {}", ovsdbNode, ovsdbNode.getNodeId(),result);
239 public OvsdbBridgeAugmentation readBridge(Node node, String name) {
240 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
241 ConnectionInfo connectionInfo = getConnectionInfo(node);
242 if (connectionInfo != null) {
243 InstanceIdentifier<Node> bridgeIid =
244 MdsalHelper.createInstanceIdentifier(node.getKey(), name);
245 Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
246 if (bridgeNode != null) {
247 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
250 return ovsdbBridgeAugmentation;
253 public Node readBridgeNode(Node node, String name) {
254 Node ovsdbNode = node;
255 if (extractNodeAugmentation(ovsdbNode) == null) {
256 ovsdbNode = readOvsdbNode(node);
257 if (ovsdbNode == null) {
261 Node bridgeNode = null;
262 ConnectionInfo connectionInfo = getConnectionInfo(ovsdbNode);
263 if (connectionInfo != null) {
264 InstanceIdentifier<Node> bridgeIid =
265 MdsalHelper.createInstanceIdentifier(node.getKey(), name);
266 bridgeNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
271 public Node getBridgeNode(Node node, String bridgeName) {
272 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
273 if (bridge != null && bridge.getBridgeName().getValue().equals(bridgeName)) {
276 return readBridgeNode(node, bridgeName);
280 public String getBridgeUuid(Node node, String name) {
282 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = readBridge(node, name);
283 if (ovsdbBridgeAugmentation != null) {
284 uuid = ovsdbBridgeAugmentation.getBridgeUuid().getValue();
289 private void setManagedByForBridge(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
290 NodeKey ovsdbNodeKey) {
291 InstanceIdentifier<Node> connectionNodePath = MdsalHelper.createInstanceIdentifier(ovsdbNodeKey.getNodeId());
292 ovsdbBridgeAugmentationBuilder.setManagedBy(new OvsdbNodeRef(connectionNodePath));
295 private List<ControllerEntry> createControllerEntries(List<String> controllersStr) {
296 List<ControllerEntry> controllerEntries = new ArrayList<>();
297 if (controllersStr != null) {
298 for (String controllerStr : controllersStr) {
299 ControllerEntryBuilder controllerEntryBuilder = new ControllerEntryBuilder();
300 controllerEntryBuilder.setTarget(new Uri(controllerStr));
301 controllerEntries.add(controllerEntryBuilder.build());
304 return controllerEntries;
307 private List<ProtocolEntry> createMdsalProtocols() {
308 List<ProtocolEntry> protocolList = new ArrayList<>();
309 ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
310 MdsalHelper.OVSDB_PROTOCOL_MAP.inverse();
311 protocolList.add(new ProtocolEntryBuilder().
312 setProtocol(mapper.get("OpenFlow13")).build());
316 public long getDataPathId(Node node) {
318 String datapathId = getDatapathId(node);
319 if (datapathId != null) {
320 dpid = new BigInteger(datapathId.replaceAll(":", ""), 16).longValue();
325 public String getDatapathId(Node node) {
326 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
327 return getDatapathId(ovsdbBridgeAugmentation);
330 public String getDatapathId(OvsdbBridgeAugmentation ovsdbBridgeAugmentation) {
331 String datapathId = null;
332 if (ovsdbBridgeAugmentation != null && ovsdbBridgeAugmentation.getDatapathId() != null) {
333 datapathId = ovsdbBridgeAugmentation.getDatapathId().getValue();
338 public OvsdbBridgeAugmentation getBridge(Node node, String name) {
339 OvsdbBridgeAugmentation bridge = node.getAugmentation(OvsdbBridgeAugmentation.class);
340 if ((bridge != null) && (!bridge.getBridgeName().getValue().equals(name))) {
346 public OvsdbBridgeAugmentation getBridge(Node node) {
347 return node.getAugmentation(OvsdbBridgeAugmentation.class);
350 public String getBridgeName(Node node) {
351 String bridgeName = null;
352 OvsdbBridgeAugmentation bridge = getBridge(node);
353 if (bridge != null) {
354 bridgeName = bridge.getBridgeName().getValue();
359 public String extractBridgeName(Node node) {
360 return node.getAugmentation(OvsdbBridgeAugmentation.class).getBridgeName().getValue();
363 public OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
367 return node.getAugmentation(OvsdbBridgeAugmentation.class);
370 public List<Node> getAllBridgesOnOvsdbNode(Node node) {
371 List<Node> nodes = new ArrayList<>();
372 List<ManagedNodeEntry> managedNodes = node.getAugmentation(OvsdbNodeAugmentation.class).getManagedNodeEntry();
373 for (ManagedNodeEntry managedNode : managedNodes) {
374 InstanceIdentifier<?> bridgeIid = managedNode.getBridgeRef().getValue();
375 Node bridgeNode = (Node) mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeIid);
376 if (bridgeNode != null) {
377 nodes.add(bridgeNode);
383 public boolean isBridgeOnOvsdbNode(Node ovsdbNode, String bridgeName) {
384 boolean found = false;
385 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractNodeAugmentation(ovsdbNode);
386 if (ovsdbNodeAugmentation != null) {
387 List<ManagedNodeEntry> managedNodes = ovsdbNodeAugmentation.getManagedNodeEntry();
388 if (managedNodes != null) {
389 for (ManagedNodeEntry managedNode : managedNodes) {
390 InstanceIdentifier<?> bridgeIid = managedNode.getBridgeRef().getValue();
391 if (bridgeIid.toString().contains(bridgeName)) {
401 public boolean isOvsdbNodeDpdk(Node ovsdbNode) {
402 boolean found = false;
403 OvsdbNodeAugmentation ovsdbNodeAugmentation = extractNodeAugmentation(ovsdbNode);
404 if (ovsdbNodeAugmentation != null) {
405 List<InterfaceTypeEntry> ifTypes = ovsdbNodeAugmentation.getInterfaceTypeEntry();
406 if (ifTypes != null) {
407 for (InterfaceTypeEntry ifType : ifTypes) {
408 if (ifType.getInterfaceType().equals(InterfaceTypeDpdk.class)) {
418 public OvsdbNodeAugmentation extractNodeAugmentation(Node node) {
419 return node.getAugmentation(OvsdbNodeAugmentation.class);
423 * Method read ports from bridge node. Method will check if the provided node
424 * has the ports details, if not, it will read from Operational data store.
425 * @param node Target bridge to getch termination points from.
426 * @return List of termination points on the given bridge
428 public List<OvsdbTerminationPointAugmentation> getTerminationPointsOfBridge(Node node) {
429 List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations(node);
430 if(tpAugmentations.isEmpty()){
431 tpAugmentations = readTerminationPointAugmentations(node);
433 return tpAugmentations;
436 public OvsdbTerminationPointAugmentation getTerminationPointOfBridge(Node node, String portName) {
437 OvsdbTerminationPointAugmentation tpAugmentation = extractTerminationPointAugmentation(node,portName);
438 if(tpAugmentation == null){
439 List<OvsdbTerminationPointAugmentation> tpAugmentations = readTerminationPointAugmentations(node);
440 if(tpAugmentations != null){
441 for(OvsdbTerminationPointAugmentation ovsdbTpAugmentation : tpAugmentations){
442 if(ovsdbTpAugmentation.getName().equals(portName)){
443 return ovsdbTpAugmentation;
448 return tpAugmentation;
451 public OvsdbTerminationPointAugmentation extractTerminationPointAugmentation(Node bridgeNode, String portName) {
452 if (bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class) != null) {
453 List<OvsdbTerminationPointAugmentation> tpAugmentations = extractTerminationPointAugmentations(bridgeNode);
454 for (OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation : tpAugmentations) {
455 if (ovsdbTerminationPointAugmentation.getName().equals(portName)) {
456 return ovsdbTerminationPointAugmentation;
463 public List<TerminationPoint> extractTerminationPoints(Node node) {
464 List<TerminationPoint> terminationPoints = new ArrayList<>();
465 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = node.getAugmentation(OvsdbBridgeAugmentation.class);
466 if (ovsdbBridgeAugmentation != null) {
467 terminationPoints.addAll(node.getTerminationPoint());
469 return terminationPoints;
472 public List<OvsdbTerminationPointAugmentation> extractTerminationPointAugmentations( Node node ) {
473 List<OvsdbTerminationPointAugmentation> tpAugmentations = new ArrayList<>();
475 LOG.error("extractTerminationPointAugmentations: Node value is null");
476 return Collections.<OvsdbTerminationPointAugmentation>emptyList();
478 List<TerminationPoint> terminationPoints = node.getTerminationPoint();
479 if(terminationPoints != null && !terminationPoints.isEmpty()){
480 for(TerminationPoint tp : terminationPoints){
481 OvsdbTerminationPointAugmentation ovsdbTerminationPointAugmentation =
482 tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
483 if (ovsdbTerminationPointAugmentation != null) {
484 tpAugmentations.add(ovsdbTerminationPointAugmentation);
488 return tpAugmentations;
491 public List<OvsdbTerminationPointAugmentation> readTerminationPointAugmentations(Node node) {
493 LOG.error("readTerminationPointAugmentations: Node value is null");
494 return Collections.<OvsdbTerminationPointAugmentation>emptyList();
496 InstanceIdentifier<Node> bridgeNodeIid = MdsalHelper.createInstanceIdentifier(node.getNodeId());
497 Node operNode = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, bridgeNodeIid);
498 if(operNode != null){
499 return extractTerminationPointAugmentations(operNode);
501 return new ArrayList<>();
504 public String getInterfaceExternalIdsValue(
505 OvsdbTerminationPointAugmentation terminationPointAugmentation, String key) {
507 List<InterfaceExternalIds> pairs = terminationPointAugmentation.getInterfaceExternalIds();
508 if (pairs != null && !pairs.isEmpty()) {
509 for (InterfaceExternalIds pair : pairs) {
510 if (pair.getExternalIdKey().equals(key)) {
511 value = pair.getExternalIdValue();
519 public Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type) {
520 InstanceIdentifier<TerminationPoint> tpIid =
521 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
522 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder =
523 new OvsdbTerminationPointAugmentationBuilder();
525 tpAugmentationBuilder.setName(portName);
527 tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
529 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
530 tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
531 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
532 return mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build());
535 public Boolean deleteTerminationPoint(Node bridgeNode, String portName) {
536 InstanceIdentifier<TerminationPoint> tpIid =
537 MdsalHelper.createTerminationPointInstanceIdentifier(bridgeNode, portName);
538 return mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, tpIid);
541 public Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName,
542 String type, Map<String, String> options) {
543 InstanceIdentifier<TerminationPoint> tpIid = MdsalHelper.createTerminationPointInstanceIdentifier(
544 bridgeNode, portName);
545 OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder();
547 tpAugmentationBuilder.setName(portName);
549 tpAugmentationBuilder.setInterfaceType(MdsalHelper.OVSDB_INTERFACE_TYPE_MAP.get(type));
552 List<Options> optionsList = new ArrayList<>();
553 for (Map.Entry<String, String> entry : options.entrySet()) {
554 OptionsBuilder optionsBuilder = new OptionsBuilder();
555 optionsBuilder.setKey(new OptionsKey(entry.getKey()));
556 optionsBuilder.setOption(entry.getKey());
557 optionsBuilder.setValue(entry.getValue());
558 optionsList.add(optionsBuilder.build());
560 tpAugmentationBuilder.setOptions(optionsList);
562 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
563 tpBuilder.setKey(InstanceIdentifier.keyOf(tpIid));
564 tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build());
565 /* TODO SB_MIGRATION should this be merge or mdsalUtils.put */
566 return mdsalUtils.put(LogicalDatastoreType.CONFIGURATION, tpIid, tpBuilder.build());
569 public TerminationPoint readTerminationPoint(Node bridgeNode, String bridgeName, String portName) {
570 InstanceIdentifier<TerminationPoint> tpIid = MdsalHelper.createTerminationPointInstanceIdentifier(
571 bridgeNode, portName);
572 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, tpIid);
575 public Boolean addTunnelTerminationPoint(Node bridgeNode, String bridgeName, String portName, String type,
576 Map<String, String> options) {
577 return addTerminationPoint(bridgeNode, bridgeName, portName, type, options);
580 public Boolean isTunnelTerminationPointExist(Node bridgeNode, String bridgeName, String portName){
581 return readTerminationPoint(bridgeNode, bridgeName, portName) != null;
584 public Boolean addPatchTerminationPoint(Node node, String bridgeName, String portName, String peerPortName) {
585 Map<String, String> option = new HashMap<>();
586 option.put("peer", peerPortName);
587 return addTerminationPoint(node, bridgeName, portName, PATCH_PORT_TYPE, option);
590 public String getExternalId(Node node, OvsdbTables table, String key) {
593 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
594 if (bridge != null && bridge.getBridgeExternalIds() != null) {
595 for (BridgeExternalIds bridgeExternaIds :bridge.getBridgeExternalIds()) {
596 if (bridgeExternaIds.getBridgeExternalIdKey().equals(key)) {
597 return bridgeExternaIds.getBridgeExternalIdValue();
603 LOG.warn("getExternalId: There is no external_id for OvsdbTables: ", table);
606 OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
607 if (ovsdbNode == null) {
608 Node nodeFromReadOvsdbNode = readOvsdbNode(node);
609 if (nodeFromReadOvsdbNode != null) {
610 ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
613 if (ovsdbNode != null && ovsdbNode.getOpenvswitchExternalIds() != null) {
614 for (OpenvswitchExternalIds openvswitchExternalIds : ovsdbNode.getOpenvswitchExternalIds()) {
615 if (openvswitchExternalIds.getExternalIdKey().equals(key)) {
616 return openvswitchExternalIds.getExternalIdValue();
622 List <OvsdbTerminationPointAugmentation> ports = extractTerminationPointAugmentations(node);
623 for (OvsdbTerminationPointAugmentation port : ports) {
624 if (port != null && port.getPortExternalIds() != null) {
625 for (PortExternalIds portExternalIds :port.getPortExternalIds()) {
626 if (portExternalIds.getExternalIdKey().equals(key)) {
627 return portExternalIds.getExternalIdValue();
634 LOG.debug("getExternalId: Couldn't find the specified OvsdbTable: ", table);
640 public String getOtherConfig(Node node, OvsdbTables table, String key) {
643 OvsdbBridgeAugmentation bridge = extractBridgeAugmentation(node);
644 if (bridge != null && bridge.getBridgeOtherConfigs() != null) {
645 for (BridgeOtherConfigs bridgeOtherConfigs : bridge.getBridgeOtherConfigs()) {
646 if (bridgeOtherConfigs.getBridgeOtherConfigKey().equals(key)) {
647 return bridgeOtherConfigs.getBridgeOtherConfigValue();
653 LOG.warn("getOtherConfig: There is no other_config for OvsdbTables: ", table);
657 OvsdbNodeAugmentation ovsdbNode = extractNodeAugmentation(node);
658 if (ovsdbNode == null) {
659 Node nodeFromReadOvsdbNode = readOvsdbNode(node);
660 if (nodeFromReadOvsdbNode != null) {
661 ovsdbNode = extractNodeAugmentation(nodeFromReadOvsdbNode);
664 if (ovsdbNode != null && ovsdbNode.getOpenvswitchOtherConfigs() != null) {
665 for (OpenvswitchOtherConfigs openvswitchOtherConfigs : ovsdbNode.getOpenvswitchOtherConfigs()) {
666 if (openvswitchOtherConfigs.getOtherConfigKey().equals(key)) {
667 return openvswitchOtherConfigs.getOtherConfigValue();
673 List <OvsdbTerminationPointAugmentation> ports = extractTerminationPointAugmentations(node);
674 for (OvsdbTerminationPointAugmentation port : ports) {
675 if (port != null && port.getPortOtherConfigs() != null) {
676 for (PortOtherConfigs portOtherConfigs : port.getPortOtherConfigs()) {
677 if (portOtherConfigs.getOtherConfigKey().equals(key)) {
678 return portOtherConfigs.getOtherConfigValue();
685 LOG.debug("getOtherConfig: Couldn't find the specified OvsdbTable: ", table);
691 public boolean addVlanToTp(long vlan) {
695 public boolean isTunnel(OvsdbTerminationPointAugmentation port) {
696 LOG.trace("SouthboundImpl#isTunnel: Interface : {}", port);
698 if(port.getInterfaceType() == null){
699 LOG.warn("No type found for the interface : {}", port);
702 return MdsalHelper.createOvsdbInterfaceType(
703 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_VXLAN)
704 || MdsalHelper.createOvsdbInterfaceType(
705 port.getInterfaceType()).equals(NetworkHandler.NETWORK_TYPE_GRE);
708 public String getOptionsValue(List<Options> options, String key) {
710 for (Options option : options) {
711 if (option.getOption().equals(key)) {
712 value = option.getValue();
718 public Topology getOvsdbTopology() {
719 InstanceIdentifier<Topology> path = InstanceIdentifier
720 .create(NetworkTopology.class)
721 .child(Topology.class, new TopologyKey(MdsalHelper.OVSDB_TOPOLOGY_ID));
723 return mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path);
726 public Long getOFPort(OvsdbTerminationPointAugmentation port) {
728 if (port.getOfport() != null) {
729 ofPort = port.getOfport();
734 public Long getOFPort(Node bridgeNode, String portName) {
736 OvsdbTerminationPointAugmentation port = extractTerminationPointAugmentation(bridgeNode, portName);
738 ofPort = getOFPort(port);
740 TerminationPoint tp = readTerminationPoint(bridgeNode, null, portName);
742 port = tp.getAugmentation(OvsdbTerminationPointAugmentation.class);
744 ofPort = getOFPort(port);
750 public OvsdbBridgeAugmentation getBridgeFromConfig(Node node, String bridge) {
751 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = null;
752 InstanceIdentifier<Node> bridgeIid =
753 MdsalHelper.createInstanceIdentifier(node.getKey(), bridge);
754 Node bridgeNode = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, bridgeIid);
755 if (bridgeNode != null) {
756 ovsdbBridgeAugmentation = bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
758 return ovsdbBridgeAugmentation;