Search in sources :

Example 1 with InterVpnLinkKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey 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 2 with InterVpnLinkKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey in project netvirt by opendaylight.

the class InterVpnLinkListener method remove.

@Override
protected void remove(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink del) {
    LOG.debug("Reacting to InterVpnLink {} removal", del.getName());
    // Remove learnt routes
    // Remove entries in the LPortDispatcher table
    // Remove the corresponding entries in InterVpnLinkState
    // For each endpoint, remove all routes that have been learnt by intervpnLink
    String vpn1Uuid = del.getFirstEndpoint().getVpnUuid().getValue();
    String rd1 = VpnUtil.getVpnRd(dataBroker, vpn1Uuid);
    LOG.debug("Removing leaked routes in VPN {}  rd={}", vpn1Uuid, rd1);
    VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd1, RouteOrigin.INTERVPN);
    List<VrfEntry> vrfEntriesSecondEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd1, del.getSecondEndpoint().getIpAddress().getValue());
    String vpn2Uuid = del.getSecondEndpoint().getVpnUuid().getValue();
    String rd2 = VpnUtil.getVpnRd(dataBroker, vpn2Uuid);
    LOG.debug("Removing leaked routes in VPN {}  rd={}", vpn2Uuid, rd2);
    VpnUtil.removeVrfEntriesByOrigin(dataBroker, rd2, RouteOrigin.INTERVPN);
    List<VrfEntry> vrfEntriesFirstEndpoint = VpnUtil.findVrfEntriesByNexthop(dataBroker, rd2, del.getFirstEndpoint().getIpAddress().getValue());
    Optional<InterVpnLinkState> optIVpnLinkState = InterVpnLinkUtil.getInterVpnLinkState(dataBroker, del.getName());
    if (optIVpnLinkState.isPresent()) {
        InterVpnLinkState interVpnLinkState = optIVpnLinkState.get();
        boolean isVpnFirstEndPoint = true;
        if (interVpnLinkState.getFirstEndpointState() != null) {
            Long firstEndpointLportTag = interVpnLinkState.getFirstEndpointState().getLportTag();
            removeVpnLinkEndpointFlows(del, vpn2Uuid, rd1, interVpnLinkState.getSecondEndpointState().getDpId(), firstEndpointLportTag.intValue(), del.getFirstEndpoint().getIpAddress().getValue(), vrfEntriesSecondEndpoint, isVpnFirstEndPoint);
        } else {
            LOG.info("Could not get first endpoint state attributes for InterVpnLink {}", del.getName());
        }
        isVpnFirstEndPoint = false;
        if (interVpnLinkState.getSecondEndpointState() != null) {
            Long secondEndpointLportTag = interVpnLinkState.getSecondEndpointState().getLportTag();
            removeVpnLinkEndpointFlows(del, vpn1Uuid, rd2, interVpnLinkState.getFirstEndpointState().getDpId(), secondEndpointLportTag.intValue(), del.getSecondEndpoint().getIpAddress().getValue(), vrfEntriesFirstEndpoint, isVpnFirstEndPoint);
        } else {
            LOG.info("Could not get second endpoint state attributes for InterVpnLink {}", del.getName());
        }
    }
    VpnUtil.removeVrfEntries(dataBroker, rd1, vrfEntriesSecondEndpoint);
    VpnUtil.removeVrfEntries(dataBroker, rd2, vrfEntriesFirstEndpoint);
    VpnUtil.withdrawRoutes(bgpManager, rd1, vrfEntriesSecondEndpoint);
    VpnUtil.withdrawRoutes(bgpManager, rd2, vrfEntriesFirstEndpoint);
    // Release idManager with LPortTag associated to endpoints
    LOG.debug("Releasing InterVpnLink {} endpoints LportTags", del.getName());
    InterVpnLinkKey key = del.getKey();
    Uuid firstEndpointVpnUuid = del.getFirstEndpoint().getVpnUuid();
    Uuid secondEndpointVpnUuid = del.getSecondEndpoint().getVpnUuid();
    releaseVpnLinkLPortTag(key.getName() + firstEndpointVpnUuid.getValue());
    releaseVpnLinkLPortTag(key.getName() + secondEndpointVpnUuid.getValue());
    // Routes with nextHop pointing to an end-point of the inter-vpn-link are populated into FIB table.
    // The action in that case is a nx_resubmit to LPortDispatcher table. This is done in FibManager.
    // At this point. we need to check if is there any entry in FIB table pointing to LPortDispatcher table.
    // Remove it in that case.
    // Removing the InterVpnLinkState
    InstanceIdentifier<InterVpnLinkState> interVpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(del.getName());
    VpnUtil.delete(dataBroker, LogicalDatastoreType.CONFIGURATION, interVpnLinkStateIid);
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) InterVpnLinkKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 InterVpnLinkState (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState)2 InterVpnLinkKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey)2 BigInteger (java.math.BigInteger)1 InterVpnLinkDataComposite (org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)1 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)1 InterVpnLinkStateBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder)1 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)1 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)1 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)1 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)1