Search in sources :

Example 6 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkCacheImpl method addInterVpnLinkToCaches.

@Override
public void addInterVpnLinkToCaches(InterVpnLink interVpnLink) {
    String ivlName = interVpnLink.getName();
    LOG.debug("Adding InterVpnLink {} with vpn1=[id={} endpoint={}] and vpn2=[id={}  endpoint={}] ]", ivlName, interVpnLink.getFirstEndpoint().getVpnUuid(), interVpnLink.getFirstEndpoint().getIpAddress(), interVpnLink.getSecondEndpoint().getVpnUuid(), interVpnLink.getSecondEndpoint().getIpAddress());
    InterVpnLinkDataComposite interVpnLinkDataComposite = getInterVpnLinkByName(ivlName).orNull();
    if (interVpnLinkDataComposite != null) {
        interVpnLinkDataComposite.setInterVpnLinkConfig(interVpnLink);
    } else {
        interVpnLinkDataComposite = new InterVpnLinkDataComposite(interVpnLink);
        addToIVpnLinkNameCache(interVpnLinkDataComposite);
    }
    addToEndpointCache(interVpnLinkDataComposite);
    addToVpnUuidCache(interVpnLinkDataComposite);
}
Also used : InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 7 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkCacheImpl method addInterVpnLinkStateToCaches.

@Override
public void addInterVpnLinkStateToCaches(InterVpnLinkState interVpnLinkState) {
    String ivlName = interVpnLinkState.getInterVpnLinkName();
    LOG.debug("Adding InterVpnLinkState {} with vpn1=[{}]  and vpn2=[{}]", ivlName, interVpnLinkState.getFirstEndpointState(), interVpnLinkState.getSecondEndpointState());
    InterVpnLinkDataComposite ivl = getInterVpnLinkByName(ivlName).orNull();
    if (ivl != null) {
        ivl.setInterVpnLinkState(interVpnLinkState);
    } else {
        ivl = new InterVpnLinkDataComposite(interVpnLinkState);
        addToIVpnLinkNameCache(ivl);
    }
    addToEndpointCache(ivl);
    addToVpnUuidCache(ivl);
}
Also used : InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 8 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkListener method add.

@Override
protected void add(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink add) {
    String ivpnLinkName = add.getName();
    LOG.debug("Reacting to IVpnLink {} creation. Vpn1=[name={}  EndpointIp={}]  Vpn2=[name={} endpointIP={}]", ivpnLinkName, add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(), add.getSecondEndpoint().getVpnUuid(), add.getSecondEndpoint().getIpAddress());
    // Create VpnLink state
    InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLinkName);
    InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkState);
    InterVpnLinkKey key = add.getKey();
    Uuid vpn1Uuid = add.getFirstEndpoint().getVpnUuid();
    String vpn1Name = vpn1Uuid.getValue();
    Uuid vpn2Uuid = add.getSecondEndpoint().getVpnUuid();
    String vpn2Name = vpn2Uuid.getValue();
    String vpn1PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
    String vpn2PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
    if (!VpnUtil.isVpnPendingDelete(dataBroker, vpn1PrimaryRd) && !VpnUtil.isVpnPendingDelete(dataBroker, vpn2PrimaryRd)) {
        if (VpnUtil.getVpnInstance(this.dataBroker, vpn1Name) == null) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 1st endpoint Vpn " + vpn1Name;
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        if (!checkVpnAvailability(key, vpn1Name)) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn1Name + " is already associated to an inter-vpn-link ";
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        // Second VPN
        if (VpnUtil.getVpnInstance(this.dataBroker, vpn2Name) == null) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 2nd endpoint Vpn " + vpn2Name;
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        if (!checkVpnAvailability(key, vpn2Name)) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn2Name + " is already associated with an inter-vpn-link";
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        interVpnLinkCache.addInterVpnLinkToCaches(add);
        // Wait for VPN Operational data ready
        long vpn1Id = VpnUtil.getVpnId(dataBroker, vpn1Name);
        if (vpn1Id == VpnConstants.INVALID_ID) {
            boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn1Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
            if (!vpn1Ready) {
                String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn1Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                return;
            }
        }
        long vpn2Id = VpnUtil.getVpnId(dataBroker, vpn2Name);
        if (vpn2Id == VpnConstants.INVALID_ID) {
            boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn2Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
            if (!vpn1Ready) {
                String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn2Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                return;
            }
        }
        List<BigInteger> firstDpnList = ivpnLinkLocator.selectSuitableDpns(add);
        if (firstDpnList != null && !firstDpnList.isEmpty()) {
            List<BigInteger> secondDpnList = firstDpnList;
            Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
            Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
            FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setDpId(firstDpnList).setLportTag(firstVpnLportTag).build();
            SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setDpId(secondDpnList).setLportTag(secondVpnLportTag).build();
            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Active, firstEndPointState, secondEndPointState, interVpnLinkCache);
            // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, firstDpnList, vpn2Name, secondVpnLportTag);
            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, secondDpnList, vpn1Name, firstVpnLportTag);
            // Update the VPN -> DPNs Map.
            // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2.
            // Why? because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how
            // to reach to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these
            // DPNs even if Vpn2 is not physically present there.
            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn2Name, vpn2PrimaryRd, firstDpnList);
            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn1Name, vpn1PrimaryRd, secondDpnList);
            // Program static routes if needed
            Optional<InterVpnLinkDataComposite> interVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
            ivpnLinkService.handleStaticRoutes(interVpnLink.get());
            // Now, if the corresponding flags are activated, there will be some routes exchange
            ivpnLinkService.exchangeRoutes(interVpnLink.get());
        } else {
            // If there is no connection to DPNs, the InterVpnLink is created and the InterVpnLinkState is also
            // created with the corresponding LPortTags but no DPN is assigned since there is no DPN operative.
            Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
            Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
            FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setLportTag(firstVpnLportTag).setDpId(Collections.emptyList()).build();
            SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setLportTag(secondVpnLportTag).setDpId(Collections.emptyList()).build();
            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Error, firstEndPointState, secondEndPointState, interVpnLinkCache);
        }
    }
}
Also used : InterVpnLinkKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey) FirstEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointState) InterVpnLinkStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder) FirstEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SecondEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder) BigInteger(java.math.BigInteger) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState) SecondEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 9 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkLocator method findDpnsWithSimilarIVpnLinks.

/*
     * Given an InterVpnLink, this method finds those DPNs where there is an
     * InterVpnLink of the same group. Two InterVpnLinks are in the same group
     * if they link 2 L3VPNs that are from the same group, and 2 L3VPNs are in
     * the same group if their iRTs match.
     *
     * @param interVpnLink InterVpnLink to be checked
     * @return the list of dpnIds where the specified InterVpnLink should not
     *     be installed
     */
private List<BigInteger> findDpnsWithSimilarIVpnLinks(InterVpnLink interVpnLink, List<InterVpnLinkDataComposite> allInterVpnLinks) {
    List<InterVpnLinkDataComposite> sameGroupInterVpnLinks = findInterVpnLinksSameGroup(interVpnLink, allInterVpnLinks);
    Set<BigInteger> resultDpns = new HashSet<>();
    for (InterVpnLinkDataComposite ivl : sameGroupInterVpnLinks) {
        resultDpns.addAll(ivl.getFirstEndpointDpns());
        resultDpns.addAll(ivl.getSecondEndpointDpns());
    }
    return new ArrayList<>(resultDpns);
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) HashSet(java.util.HashSet)

Example 10 with InterVpnLinkDataComposite

use of org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite in project netvirt by opendaylight.

the class InterVpnLinkLocatorTest method setUp.

@Before
public void setUp() throws Exception {
    dataBroker = getDataBroker();
    // Creating both empty containers: InterVpnLinks and InterVpnLinkStates
    WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(InterVpnLinks.class).build(), new InterVpnLinksBuilder().setInterVpnLink(Collections.emptyList()).build(), true);
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(InterVpnLinkStates.class).build(), new InterVpnLinkStatesBuilder().setInterVpnLinkState(Collections.emptyList()).build(), true);
    writeTx.submit().checkedGet();
    interVpnLinkCache = new InterVpnLinkCacheImpl(dataBroker);
    interVpnLinkCache.initialFeed();
    // Prepare
    populateL3Vpns(dataBroker, L3VpnTestCatalog.ALL_VPNS);
    InterVpnLinkTestCatalog.populateIvpnLinks(dataBroker, ALL_IVPN_LINKS);
    for (InterVpnLinkDataComposite ivl : ALL_IVPN_LINKS) {
        interVpnLinkCache.addInterVpnLinkToCaches(ivl.getInterVpnLinkConfig());
        interVpnLinkCache.addInterVpnLinkStateToCaches(ivl.getInterVpnLinkState());
    }
    // SUT
    sut = new InterVpnLinkLocator(dataBroker, interVpnLinkCache);
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) InterVpnLinksBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinksBuilder) InterVpnLinkStatesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.InterVpnLinkStatesBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Before(org.junit.Before)

Aggregations

InterVpnLinkDataComposite (org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)20 BigInteger (java.math.BigInteger)9 ArrayList (java.util.ArrayList)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)5 List (java.util.List)3 PostConstruct (javax.annotation.PostConstruct)3 Inject (javax.inject.Inject)3 Singleton (javax.inject.Singleton)3 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)3 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)3 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)3 Optional (com.google.common.base.Optional)2 Preconditions (com.google.common.base.Preconditions)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2