2 * Copyright (c) 2015 - 2017 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md;
12 import java.util.Map.Entry;
13 import java.util.Optional;
14 import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance;
17 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
18 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
19 import org.opendaylight.ovsdb.lib.message.TableUpdates;
20 import org.opendaylight.ovsdb.lib.notation.UUID;
21 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
22 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentationBuilder;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 public class HwvtepPhysicalLocatorUpdateCommand extends AbstractTransactionCommand {
35 private final Map<UUID, PhysicalLocator> updatedPLocRows;
36 private final Map<UUID, PhysicalLocator> oldPLocRows;
38 public HwvtepPhysicalLocatorUpdateCommand(HwvtepConnectionInstance key, TableUpdates updates,
39 DatabaseSchema dbSchema) {
40 super(key, updates, dbSchema);
41 updatedPLocRows = TyperUtils.extractRowsUpdated(PhysicalLocator.class, getUpdates(), getDbSchema());
42 oldPLocRows = TyperUtils.extractRowsOld(PhysicalLocator.class, getUpdates(), getDbSchema());
46 public void execute(ReadWriteTransaction transaction) {
47 final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
48 if (updatedPLocRows.isEmpty()) {
51 Optional<Node> node = HwvtepSouthboundUtil.readNode(transaction, connectionIId);
52 if (node.isPresent()) {
53 updateTerminationPoints(transaction, node.get());
57 private void updateTerminationPoints(ReadWriteTransaction transaction, Node node) {
58 for (Entry<UUID, PhysicalLocator> locUpdate : updatedPLocRows.entrySet()) {
59 PhysicalLocator locator = locUpdate.getValue();
60 InstanceIdentifier<Node> nodeIid = HwvtepSouthboundMapper.createInstanceIdentifier(node.getNodeId());
61 TerminationPointKey tpKey = HwvtepSouthboundMapper.getTerminationPointKey(locator);
62 if (nodeIid != null && tpKey != null) {
63 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
64 tpBuilder.withKey(tpKey);
65 tpBuilder.setTpId(tpKey.getTpId());
66 InstanceIdentifier<TerminationPoint> tpPath =
67 HwvtepSouthboundMapper.createInstanceIdentifier(nodeIid, locator);
68 HwvtepPhysicalLocatorAugmentationBuilder tpAugmentationBuilder =
69 new HwvtepPhysicalLocatorAugmentationBuilder();
70 tpAugmentationBuilder.setPhysicalLocatorUuid(new Uuid(locator.getUuid().toString()));
71 setEncapsType(tpAugmentationBuilder, locator);
72 setDstIp(tpAugmentationBuilder, locator);
73 tpBuilder.addAugmentation(tpAugmentationBuilder.build());
74 if (oldPLocRows.containsKey(locUpdate.getKey())) {
75 transaction.merge(LogicalDatastoreType.OPERATIONAL,
76 tpPath, tpBuilder.build());
78 transaction.put(LogicalDatastoreType.OPERATIONAL,
79 tpPath, tpBuilder.build());
81 addToUpdateTx(TerminationPoint.class, tpPath, locator.getUuid(), locator);
86 private static void setEncapsType(HwvtepPhysicalLocatorAugmentationBuilder tpAugmentationBuilder,
87 PhysicalLocator locator) {
88 String encapsType = locator.getEncapsulationTypeColumn().getData();
89 if (HwvtepSouthboundMapper.createEncapsulationType(encapsType) != null) {
90 tpAugmentationBuilder.setEncapsulationType(HwvtepSouthboundMapper.createEncapsulationType(encapsType));
94 private static void setDstIp(HwvtepPhysicalLocatorAugmentationBuilder tpAugmentationBuilder,
95 PhysicalLocator locator) {
96 tpAugmentationBuilder.setDstIp(IpAddressBuilder.getDefaultInstance(locator.getDstIpColumn().getData()));