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