2 * Copyright (c) 2016, 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
8 package org.opendaylight.genius.interfacemanager.renderer.hwvtep.confighelpers;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
12 import static org.opendaylight.mdsal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.opendaylight.genius.infra.Datastore.Configuration;
18 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
19 import org.opendaylight.genius.infra.TypedWriteTransaction;
20 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
21 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeVxlanOverIpv4;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentationBuilder;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public final class HwVTEPInterfaceConfigAddHelper {
37 private static final Logger LOG = LoggerFactory.getLogger(HwVTEPInterfaceConfigAddHelper.class);
39 private HwVTEPInterfaceConfigAddHelper() {
43 public static List<ListenableFuture<Void>> addConfiguration(ManagedNewTransactionRunner txRunner,
44 InstanceIdentifier<Node> physicalSwitchNodeId, InstanceIdentifier<Node> globalNodeId,
45 Interface interfaceNew, IfTunnel ifTunnel) {
46 LOG.info("adding hwvtep configuration for {}", interfaceNew.getName());
48 // create hwvtep through ovsdb plugin
49 List<ListenableFuture<Void>> futures = new ArrayList<>();
50 // Topology config shard
51 if (globalNodeId != null) {
52 futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
53 tx -> addTerminationPoints(tx, globalNodeId, ifTunnel)));
55 // Default operational shard
56 // TODO Move this to another listener, reacing to the config write above
57 futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
58 InterfaceMetaUtils.createTunnelToInterfaceMap(interfaceNew.getName(), physicalSwitchNodeId,
60 if (globalNodeId != null) {
61 SouthboundUtils.addStateEntry(interfaceNew, interfaceNew.augmentation(IfTunnel.class), tx);
68 * For each hwvtep configuration, we need to configure Physical LocatorTable
69 * of hwvtep schema with destination IP and tunnel-type. The configuration
70 * needs to be done for both local endpoint as well as remote endpoint
72 public static void addTerminationPoints(TypedWriteTransaction<Configuration> transaction,
73 InstanceIdentifier<Node> globalNodeId, IfTunnel ifTunnel) {
74 // InstanceIdentifier<TerminationPoint> localTEP =
75 // createLocalPhysicalLocatorEntryIfNotPresent(futures,
76 // dataBroker,transaction, ifTunnel, globalNodeId);
77 createRemotePhysicalLocatorEntry(transaction, globalNodeId, ifTunnel.getTunnelDestination());
78 // InstanceIdentifier<Tunnels> tunnelsInstanceIdentifier =
79 // createTunnelTableEntry(transaction, physicalSwitchNodeId, localTEP,
83 private static InstanceIdentifier<TerminationPoint> createRemotePhysicalLocatorEntry(
84 TypedWriteTransaction<Configuration> transaction,
85 InstanceIdentifier<Node> nodeIid, IpAddress destIPAddress) {
86 String remoteIp = destIPAddress.getIpv4Address().getValue();
87 LOG.debug("creating remote physical locator entry {}", remoteIp);
88 TerminationPointKey tpKey = SouthboundUtils.getTerminationPointKey(remoteIp);
89 InstanceIdentifier<TerminationPoint> tpPath = SouthboundUtils.createInstanceIdentifier(nodeIid, tpKey);
90 createPhysicalLocatorEntry(transaction, tpPath, tpKey, destIPAddress);
95 * This method writes the termination end point details to the topology
98 private static void createPhysicalLocatorEntry(TypedWriteTransaction<Configuration> transaction,
99 InstanceIdentifier<TerminationPoint> tpPath, TerminationPointKey terminationPointKey,
100 IpAddress destIPAddress) {
101 TerminationPointBuilder tpBuilder = new TerminationPointBuilder();
102 HwvtepPhysicalLocatorAugmentationBuilder tpAugmentationBuilder = new HwvtepPhysicalLocatorAugmentationBuilder();
103 tpBuilder.withKey(terminationPointKey);
104 tpBuilder.setTpId(terminationPointKey.getTpId());
105 tpAugmentationBuilder.setEncapsulationType(EncapsulationTypeVxlanOverIpv4.class);
106 SouthboundUtils.setDstIp(tpAugmentationBuilder, destIPAddress);
107 tpBuilder.addAugmentation(HwvtepPhysicalLocatorAugmentation.class, tpAugmentationBuilder.build());
108 LOG.debug("creating physical locator entry for {}", terminationPointKey);
109 transaction.put(tpPath, tpBuilder.build(), CREATE_MISSING_PARENTS);