X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=vpnservice.git;a=blobdiff_plain;f=interfacemgr%2Finterfacemgr-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Finterfacemgr%2Frenderer%2Fhwvtep%2Fconfighelpers%2FHwVTEPInterfaceConfigAddHelper.java;fp=interfacemgr%2Finterfacemgr-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Finterfacemgr%2Frenderer%2Fhwvtep%2Fconfighelpers%2FHwVTEPInterfaceConfigAddHelper.java;h=202b6b59a34f3cbf2e408bad7fe9cc28f8a010d3;hp=a069302a1b4725f13a736effcd26c40f8c55bc04;hb=8025297a9d760ee5add270ad673d4adc5b41d79f;hpb=769edd5c7e8cfa0a13a2f8e442270978f649b83f;ds=sidebyside diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/hwvtep/confighelpers/HwVTEPInterfaceConfigAddHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/hwvtep/confighelpers/HwVTEPInterfaceConfigAddHelper.java index a069302a..202b6b59 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/hwvtep/confighelpers/HwVTEPInterfaceConfigAddHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/hwvtep/confighelpers/HwVTEPInterfaceConfigAddHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -10,24 +10,108 @@ package org.opendaylight.vpnservice.interfacemgr.renderer.hwvtep.confighelpers; import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; +import org.opendaylight.vpnservice.interfacemgr.renderer.hwvtep.utilities.SouthboundUtils; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.EncapsulationTypeVxlanOverIpv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalLocatorAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; import java.util.ArrayList; import java.util.List; public class HwVTEPInterfaceConfigAddHelper { private static final Logger LOG = LoggerFactory.getLogger(HwVTEPInterfaceConfigAddHelper.class); - public static List> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs, - Interface interfaceNew) { + public static List> addConfiguration(DataBroker dataBroker, InstanceIdentifier physicalSwitchNodeId, + InstanceIdentifier globalNodeId, + Interface interfaceNew, IfTunnel ifTunnel) { List> futures = new ArrayList>(); - LOG.debug("adding hwvtep configuration for {}", interfaceNew.getName()); + LOG.info("adding hwvtep configuration for {}", interfaceNew.getName()); - // TODO create hwvtep through ovsdb plugin + // create hwvtep through ovsdb plugin + WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + InterfaceMetaUtils.createTunnelToInterfaceMap(interfaceNew.getName(), physicalSwitchNodeId, transaction, ifTunnel); + if(globalNodeId != null) { + addTerminationPoints(transaction, futures, globalNodeId,ifTunnel); + SouthboundUtils.addStateEntry(interfaceNew, interfaceNew.getAugmentation(IfTunnel.class), transaction); + }else{ + LOG.debug("specified physical switch is not connected {}", physicalSwitchNodeId); + } + futures.add(transaction.submit()); return futures; } + + /* + * For each hwvtep configuration, we need to configure Physical LocatorTable of hwvtep schema with + * destination IP and tunnel-type. The configuration needs to be done for both local endpoint as well as remote endpoint + */ + public static void addTerminationPoints(WriteTransaction transaction, + List> futures, + InstanceIdentifier globalNodeId, + IfTunnel ifTunnel) { + //InstanceIdentifier localTEP = + // createLocalPhysicalLocatorEntryIfNotPresent(futures, dataBroker,transaction, ifTunnel, globalNodeId); + createRemotePhysicalLocatorEntry(transaction, futures, globalNodeId, ifTunnel.getTunnelDestination()); + //InstanceIdentifier tunnelsInstanceIdentifier = createTunnelTableEntry(transaction, physicalSwitchNodeId, localTEP, remoteTEP); + } + + private static InstanceIdentifier createRemotePhysicalLocatorEntry(WriteTransaction transaction, List> futures, + InstanceIdentifier nodeIid, IpAddress destIPAddress){ + String remoteIp = destIPAddress.getIpv4Address().getValue(); + LOG.debug("creating remote physical locator entry {}", remoteIp); + TerminationPointKey tpKey = SouthboundUtils.getTerminationPointKey(remoteIp); + InstanceIdentifier tpPath = + SouthboundUtils.createInstanceIdentifier(nodeIid, tpKey); + createPhysicalLocatorEntry(transaction, futures, tpPath, tpKey, destIPAddress); + return tpPath; + } + + + private static InstanceIdentifier createLocalPhysicalLocatorEntryIfNotPresent(List> futures, + DataBroker dataBroker, + WriteTransaction transaction, + IfTunnel ifTunnel, + InstanceIdentifier nodeIid){ + String localIp = ifTunnel.getTunnelSource().getIpv4Address().getValue(); + LOG.debug("creating local physical locator entry {}", localIp); + TerminationPointKey tpKey = SouthboundUtils.getTerminationPointKey(localIp); + InstanceIdentifier tpPath = + SouthboundUtils.createInstanceIdentifier(nodeIid, tpKey); + // if local tep is not present, create it + TerminationPoint terminationPoint = SouthboundUtils.getTEPFromConfigDS(tpPath, dataBroker); + if(terminationPoint == null) { + createPhysicalLocatorEntry(transaction, futures, tpPath, tpKey, ifTunnel.getTunnelSource()); + } + return tpPath; + } + + /* + * This method writes the termination end point details to the topology Config DS + */ + private static void createPhysicalLocatorEntry(WriteTransaction transaction, List> futures, + InstanceIdentifier tpPath, TerminationPointKey terminationPointKey, + IpAddress destIPAddress){ + TerminationPointBuilder tpBuilder = new TerminationPointBuilder(); + HwvtepPhysicalLocatorAugmentationBuilder tpAugmentationBuilder = + new HwvtepPhysicalLocatorAugmentationBuilder(); + tpBuilder.setKey(terminationPointKey); + tpBuilder.setTpId(terminationPointKey.getTpId()); + tpAugmentationBuilder.setEncapsulationType(EncapsulationTypeVxlanOverIpv4.class); + SouthboundUtils.setDstIp(tpAugmentationBuilder, destIPAddress); + tpBuilder.addAugmentation(HwvtepPhysicalLocatorAugmentation.class, tpAugmentationBuilder.build()); + LOG.debug("creating physical locator entry for {}", terminationPointKey); + transaction.put(LogicalDatastoreType.CONFIGURATION, + tpPath, tpBuilder.build(), true); + } }