Search in sources :

Example 36 with VrfEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry in project netvirt by opendaylight.

the class VPNServiceChainHandlerTest method testProgramVpnToScfWithIfacesNotBound.

@Test
public void testProgramVpnToScfWithIfacesNotBound() throws Exception {
    // ///////////////////
    // Basic stubbing //
    // ///////////////////
    String ifaceName = "eth0";
    stubGetRouteDistinguisher(VPN_NAME, RD);
    stubGetVpnInstance(RD, "1.2.3.4", ifaceName);
    VrfEntry vrfEntry = FibHelper.getVrfEntryBuilder("11.12.13.14", 2000L, DC_GW_IP, RouteOrigin.STATIC, null).build();
    stubGetVrfEntries(RD, Collections.singletonList(vrfEntry));
    stubReadVpnToDpnList(RD, DPN_ID, Collections.singletonList(ifaceName));
    stubScfIsNotBoundOnIface(SCF_TAG, ifaceName);
    // ///////
    // SUT //
    // ///////
    short tableId = 10;
    vpnsch.programVpnToScfPipeline(VPN_NAME, tableId, SCF_TAG, LPORT_TAG, NwConstants.ADD_FLOW);
    // //////////
    // Verify //
    // //////////
    ArgumentCaptor<FlowEntity> argumentCaptor = ArgumentCaptor.forClass(FlowEntity.class);
    verify(ifaceMgr).bindService(eq(ifaceName), eq(ServiceModeIngress.class), anyObject());
    verify(mdsalMgr, times(2)).installFlow(argumentCaptor.capture());
    List<FlowEntity> installedFlowsCaptured = argumentCaptor.getAllValues();
    assert installedFlowsCaptured.size() == 2;
    RoutePaths routePath = vrfEntry.getRoutePaths().get(0);
    FlowEntity expectedLFibFlowEntity = VpnServiceChainUtils.buildLFibVpnPseudoPortFlow(DPN_ID, routePath.getLabel(), routePath.getNexthopAddress(), LPORT_TAG);
    assert new FlowEntityMatcher(expectedLFibFlowEntity).matches(installedFlowsCaptured.get(0));
    FlowEntity expectedLPortDispatcher = VpnServiceChainUtils.buildLportFlowDispForVpnToScf(DPN_ID, LPORT_TAG, SCF_TAG, tableId);
    assert new FlowEntityMatcher(expectedLPortDispatcher).matches(installedFlowsCaptured.get(1));
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) FlowEntityMatcher(org.opendaylight.netvirt.cloudservicechain.matchers.FlowEntityMatcher) RoutePaths(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) ServiceModeIngress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeIngress) Test(org.junit.Test)

Example 37 with VrfEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry in project netvirt by opendaylight.

the class VPNServiceChainHandler method programVpnToScfPipeline.

/**
 * Programs the necessary flows in LFIB and LPortDispatcher table so that
 * the packets coming from a given VPN are delivered to a given
 * ServiceChain Pipeline.
 *
 * @param vpnName Name of the VPN. Typically the UUID
 * @param tableId Table to which the LPortDispatcher table sends the packet
 *                 to (Uplink or Downlink Subsc table)
 * @param scfTag Scf tag to the SCF to which the Vpn is linked to.
 * @param lportTag VpnPseudo Port lportTag
 * @param addOrRemove States if the VPN2SCF Pipeline must be installed or
 *        removed
 */
public void programVpnToScfPipeline(String vpnName, short tableId, long scfTag, int lportTag, int addOrRemove) {
    // This entries must be created in the DPN where the CGNAT is installed. Since it is not possible
    // to know where CGNAT is located, this entries are installed in all the VPN footprint.
    // LFIB:
    // - Match: cgnatLabel   Instr: lportTag=vpnPseudoPortTag + SI=SCF  +  GOTO 17
    // LportDisp:
    // - Match: vpnPseudoPortTag + SI==SCF   Instr:  scfTag  +  GOTO 70
    LOG.info("programVpnToScfPipeline ({}) : Parameters VpnName:{} tableId:{} scftag:{}  lportTag:{}", addOrRemove == NwConstants.ADD_FLOW ? "Creation" : "Removal", vpnName, tableId, scfTag, lportTag);
    String rd = VpnServiceChainUtils.getVpnRd(dataBroker, vpnName);
    LOG.debug("Router distinguisher (rd):{}", rd);
    if (rd == null || rd.isEmpty()) {
        LOG.warn("programVpnToScfPipeline: Could not find Router-distinguisher for VPN {}. No further actions", vpnName);
        return;
    }
    VpnInstanceOpDataEntry vpnInstance = getVpnInstance(rd);
    if (vpnInstance == null) {
        LOG.warn("Could not find a suitable VpnInstance for Route-Distinguisher={}", rd);
        return;
    }
    // Find out the set of DPNs for the given VPN ID
    Collection<VpnToDpnList> vpnToDpnList = vpnInstance.getVpnToDpnList();
    List<VrfEntry> vrfEntries = VpnServiceChainUtils.getAllVrfEntries(dataBroker, rd);
    if (vrfEntries != null) {
        if (addOrRemove == NwConstants.ADD_FLOW) {
            AddVpnPseudoPortDataJob updateVpnToPseudoPortTask = new AddVpnPseudoPortDataJob(dataBroker, rd, lportTag, tableId, (int) scfTag);
            jobCoordinator.enqueueJob(updateVpnToPseudoPortTask.getDsJobCoordinatorKey(), updateVpnToPseudoPortTask);
        } else {
            RemoveVpnPseudoPortDataJob removeVpnPseudoPortDataTask = new RemoveVpnPseudoPortDataJob(dataBroker, rd);
            jobCoordinator.enqueueJob(removeVpnPseudoPortDataTask.getDsJobCoordinatorKey(), removeVpnPseudoPortDataTask);
        }
        for (VpnToDpnList dpnInVpn : vpnToDpnList) {
            BigInteger dpnId = dpnInVpn.getDpnId();
            programVpnToScfPipelineOnDpn(dpnId, vrfEntries, tableId, (int) scfTag, lportTag, addOrRemove);
            if (dpnInVpn.getVpnInterfaces() != null) {
                long vpnId = vpnInstance.getVpnId();
                Flow flow = VpnServiceChainUtils.buildLPortDispFromScfToL3VpnFlow(vpnId, dpnId, lportTag, NwConstants.ADD_FLOW);
                if (addOrRemove == NwConstants.ADD_FLOW) {
                    mdsalManager.installFlow(dpnId, flow);
                } else {
                    mdsalManager.removeFlow(dpnId, flow);
                }
                dpnInVpn.getVpnInterfaces().forEach(vpnIf -> {
                    if (addOrRemove == NwConstants.ADD_FLOW) {
                        bindScfOnVpnInterface(vpnIf.getInterfaceName(), (int) scfTag);
                    } else {
                        unbindScfOnVpnInterface(vpnIf.getInterfaceName());
                    }
                });
            }
        }
    }
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) BigInteger(java.math.BigInteger) AddVpnPseudoPortDataJob(org.opendaylight.netvirt.cloudservicechain.jobs.AddVpnPseudoPortDataJob) RemoveVpnPseudoPortDataJob(org.opendaylight.netvirt.cloudservicechain.jobs.RemoveVpnPseudoPortDataJob) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 38 with VrfEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry in project netvirt by opendaylight.

the class VPNServiceChainHandler method removeVpnPseudoPortFlows.

/**
 * Removes all Flows in LFIB and LPortDispatcher that are related to this VpnPseudoLPort.
 *
 * @param vpnInstanceName vpn Instance name
 * @param vpnPseudoLportTag vpnPseudoLPort tag
 */
public void removeVpnPseudoPortFlows(String vpnInstanceName, int vpnPseudoLportTag) {
    // At VpnPseudoPort removal time the current Vpn footprint could not be enough, so let's try to
    // remove all possible entries in all DPNs.
    // TODO: Study how this could be enhanced. It could be done at ServiceChain removal, but that
    // could imply check all ServiceChains ending in all DPNs in Vpn footprint to decide that if the entries
    // can be removed, and that sounds even costlier than this.
    String rd = VpnServiceChainUtils.getVpnRd(dataBroker, vpnInstanceName);
    List<VrfEntry> vrfEntries = null;
    if (rd != null) {
        vrfEntries = VpnServiceChainUtils.getAllVrfEntries(dataBroker, rd);
    }
    boolean cleanLFib = vrfEntries != null && !vrfEntries.isEmpty();
    List<BigInteger> operativeDPNs = NWUtil.getOperativeDPNs(dataBroker);
    for (BigInteger dpnId : operativeDPNs) {
        if (cleanLFib) {
            VpnServiceChainUtils.programLFibEntriesForSCF(mdsalManager, dpnId, vrfEntries, vpnPseudoLportTag, NwConstants.DEL_FLOW);
        }
        String vpnToScfflowRef = VpnServiceChainUtils.getL3VpnToScfLportDispatcherFlowRef(vpnPseudoLportTag);
        Flow vpnToScfFlow = new FlowBuilder().setTableId(NwConstants.LPORT_DISPATCHER_TABLE).setId(new FlowId(vpnToScfflowRef)).build();
        mdsalManager.removeFlow(dpnId, vpnToScfFlow);
        String scfToVpnFlowRef = VpnServiceChainUtils.getScfToL3VpnLportDispatcherFlowRef(vpnPseudoLportTag);
        Flow scfToVpnFlow = new FlowBuilder().setTableId(NwConstants.LPORT_DISPATCHER_TABLE).setId(new FlowId(scfToVpnFlowRef)).build();
        mdsalManager.removeFlow(dpnId, scfToVpnFlow);
    }
    if (rd != null) {
        RemoveVpnPseudoPortDataJob removeVpnPseudoPortDataTask = new RemoveVpnPseudoPortDataJob(dataBroker, rd);
        jobCoordinator.enqueueJob(removeVpnPseudoPortDataTask.getDsJobCoordinatorKey(), removeVpnPseudoPortDataTask);
    }
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) BigInteger(java.math.BigInteger) RemoveVpnPseudoPortDataJob(org.opendaylight.netvirt.cloudservicechain.jobs.RemoveVpnPseudoPortDataJob) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 39 with VrfEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry in project netvirt by opendaylight.

the class VpnInterfaceManager method processVpnInterfaceAdjacencies.

@SuppressWarnings("checkstyle:IllegalCatch")
protected void processVpnInterfaceAdjacencies(BigInteger dpnId, final int lportTag, String vpnName, String primaryRd, String interfaceName, final long vpnId, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn, Interface interfaceState) {
    InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
    // Read NextHops
    InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
    Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
    if (!adjacencies.isPresent()) {
        addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null, /*adjacencies*/
        lportTag, null, /*gwMac*/
        writeOperTxn);
        return;
    }
    // Get the rd of the vpn instance
    String nextHopIp = null;
    try {
        nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
    } catch (Exception e) {
        LOG.error("processVpnInterfaceAdjacencies: Unable to retrieve endpoint ip address for " + "dpnId {} for vpnInterface {} vpnName {}", dpnId, interfaceName, vpnName);
    }
    List<String> nhList = new ArrayList<>();
    if (nextHopIp != null) {
        nhList.add(nextHopIp);
        LOG.debug("processVpnInterfaceAdjacencies: NextHop for interface {} on dpn {} in vpn {} is {}", interfaceName, dpnId, vpnName, nhList);
    }
    Optional<String> gwMac = Optional.absent();
    String vpnInterfaceSubnetGwMacAddress = null;
    VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
    Long l3vni = vpnInstanceOpData.getL3vni();
    boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
    VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
    VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
    List<Adjacency> nextHops = adjacencies.get().getAdjacency();
    List<Adjacency> value = new ArrayList<>();
    for (Adjacency nextHop : nextHops) {
        String rd = primaryRd;
        String nexthopIpValue = nextHop.getIpAddress().split("/")[0];
        if (vpnInstanceOpData.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPNInternet && NWUtil.isIpv4Address(nexthopIpValue)) {
            String prefix = nextHop.getIpAddress() == null ? "null" : VpnUtil.getIpPrefix(nextHop.getIpAddress());
            LOG.debug("processVpnInterfaceAdjacencies: UnsupportedOperation : Not Adding prefix {} to interface {}" + " as InternetVpn has an IPV4 address {}", prefix, interfaceName, vpnName);
            continue;
        }
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            Prefixes.PrefixCue prefixCue = nextHop.isPhysNetworkFunc() ? Prefixes.PrefixCue.PhysNetFunc : Prefixes.PrefixCue.None;
            LOG.debug("processVpnInterfaceAdjacencies: Adding prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), prefix), VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, nextHop.getSubnetId(), prefixCue), true);
            final Uuid subnetId = nextHop.getSubnetId();
            String gatewayIp = nextHop.getSubnetGatewayIp();
            if (gatewayIp == null) {
                Optional<String> gatewayIpOptional = VpnUtil.getVpnSubnetGatewayIp(dataBroker, subnetId);
                if (gatewayIpOptional.isPresent()) {
                    gatewayIp = gatewayIpOptional.get();
                }
            }
            if (gatewayIp != null) {
                gwMac = getMacAddressForSubnetIp(vpnName, interfaceName, gatewayIp);
                if (gwMac.isPresent()) {
                    // A valid mac-address is available for this subnet-gateway-ip
                    // Use this for programming ARP_RESPONDER table here.  And save this
                    // info into vpnInterface operational, so it can used in VrfEntryProcessor
                    // to populate L3_GW_MAC_TABLE there.
                    arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    vpnInterfaceSubnetGwMacAddress = gwMac.get();
                } else {
                    // A valid mac-address is not available for this subnet-gateway-ip
                    // Use the connected-mac-address to configure ARP_RESPONDER Table.
                    // Save this connected-mac-address as gateway-mac-address for the
                    // VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
                    gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
                    if (gwMac.isPresent()) {
                        VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
                        arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    } else {
                        LOG.error("processVpnInterfaceAdjacencies: Gateway MAC for subnet ID {} could not be " + "obtained, cannot create ARP responder flow for interface name {}, vpnName {}, " + "gwIp {}", subnetId, interfaceName, vpnName, gatewayIp);
                    }
                }
            } else {
                LOG.warn("processVpnInterfaceAdjacencies: Gateway IP for subnet ID {} could not be obtained, " + "cannot create ARP responder flow for interface name {}, vpnName {}", subnetId, interfaceName, vpnName);
                gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
        } else {
            // Extra route adjacency
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
            synchronized (vpnPrefixKey.intern()) {
                java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
                if (rdToAllocate.isPresent()) {
                    rd = rdToAllocate.get();
                    LOG.info("processVpnInterfaceAdjacencies: The rd {} is allocated for the extraroute {}", rd, prefix);
                } else {
                    LOG.error("processVpnInterfaceAdjacencies: No rds to allocate extraroute {}", prefix);
                    continue;
                }
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} and nextHopList {} as extra-route for vpn{}" + " interface {} on dpn {}", nextHop.getIpAddress(), nextHop.getNextHopIpList(), vpnName, interfaceName, dpnId);
        }
        // Please note that primary adjacency will use a subnet-gateway-mac-address that
        // can be different from the gateway-mac-address within the VRFEntry as the
        // gateway-mac-address is a superset.
        RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
        L3vpnInput input = new L3vpnInput().setNextHop(nextHop).setRd(rd).setVpnName(vpnName).setInterfaceName(interfaceName).setNextHopIp(nextHopIp).setPrimaryRd(primaryRd).setSubnetGatewayMacAddress(vpnInterfaceSubnetGwMacAddress).setRouteOrigin(origin);
        Adjacency operationalAdjacency = null;
        try {
            operationalAdjacency = registeredPopulator.createOperationalAdjacency(input);
        } catch (NullPointerException e) {
            LOG.error("processVpnInterfaceAdjacencies: failed to create operational adjacency: input: {}, {}", input, e.getMessage());
            return;
        }
        if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
            vpnManager.addExtraRoute(vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), rd, vpnName, l3vni, origin, interfaceName, operationalAdjacency, encapType, writeConfigTxn);
        }
        value.add(operationalAdjacency);
    }
    AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
    addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, aug, lportTag, gwMac.isPresent() ? gwMac.get() : null, writeOperTxn);
    L3vpnInput input = new L3vpnInput().setNextHopIp(nextHopIp).setL3vni(l3vni).setPrimaryRd(primaryRd).setGatewayMac(gwMac.orNull()).setInterfaceName(interfaceName).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType);
    for (Adjacency nextHop : aug.getAdjacency()) {
        // Adjacencies other than primary Adjacencies are handled in the addExtraRoute call above.
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
            input.setNextHop(nextHop).setRd(nextHop.getVrfId()).setRouteOrigin(origin);
            registeredPopulator.populateFib(input, writeConfigTxn);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) ExecutionException(java.util.concurrent.ExecutionException) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 40 with VrfEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry in project netvirt by opendaylight.

the class VpnInterfaceManager method processVpnInterfaceUp.

// "Unconditional wait" and "Wait not in loop" wrt the VpnNotifyTask below - suppressing the FB violation -
// see comments below.
@SuppressFBWarnings({ "UW_UNCOND_WAIT", "WA_NOT_IN_LOOP" })
protected void processVpnInterfaceUp(final BigInteger dpId, VpnInterface vpnInterface, final String primaryRd, final int lportTag, boolean isInterfaceUp, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn, WriteTransaction writeInvTxn, Interface interfaceState, final String vpnName) {
    final String interfaceName = vpnInterface.getName();
    Optional<VpnInterfaceOpDataEntry> optOpVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, interfaceName, vpnName);
    VpnInterfaceOpDataEntry opVpnInterface = optOpVpnInterface.isPresent() ? optOpVpnInterface.get() : null;
    boolean isBgpVpnInternetVpn = VpnUtil.isBgpVpnInternet(dataBroker, vpnName);
    if (!isInterfaceUp) {
        LOG.info("processVpnInterfaceUp: Binding vpn service to interface {} onto dpn {} for vpn {}", interfaceName, dpId, vpnName);
        long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
        if (vpnId == VpnConstants.INVALID_ID) {
            LOG.warn("processVpnInterfaceUp: VpnInstance to VPNId mapping not available for VpnName {}" + " processing vpninterface {} on dpn {}, bailing out now.", vpnName, interfaceName, dpId);
            return;
        }
        boolean waitForVpnInterfaceOpRemoval = false;
        if (opVpnInterface != null && !opVpnInterface.isScheduledForRemove()) {
            String opVpnName = opVpnInterface.getVpnInstanceName();
            String primaryInterfaceIp = null;
            if (opVpnName.equals(vpnName)) {
                // Please check if the primary VRF Entry does not exist for VPNInterface
                // If so, we have to process ADD, as this might be a DPN Restart with Remove and Add triggered
                // back to back
                // However, if the primary VRF Entry for this VPNInterface exists, please continue bailing out !
                List<Adjacency> adjs = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, interfaceName);
                if (adjs == null) {
                    LOG.error("processVpnInterfaceUp: VPN Interface {} on dpn {} for vpn {} failed as adjacencies" + " for this vpn interface could not be obtained", interfaceName, dpId, vpnName);
                    return;
                }
                for (Adjacency adj : adjs) {
                    if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                        primaryInterfaceIp = adj.getIpAddress();
                        break;
                    }
                }
                if (primaryInterfaceIp == null) {
                    LOG.error("processVpnInterfaceUp: VPN Interface {} addition on dpn {} for vpn {} failed" + " as primary adjacency for this vpn interface could not be obtained", interfaceName, dpId, vpnName);
                    return;
                }
                // Get the rd of the vpn instance
                VrfEntry vrf = VpnUtil.getVrfEntry(dataBroker, primaryRd, primaryInterfaceIp);
                if (vrf != null) {
                    LOG.error("processVpnInterfaceUp: VPN Interface {} on dpn {} for vpn {} already provisioned ," + " bailing out from here.", interfaceName, dpId, vpnName);
                    return;
                }
                waitForVpnInterfaceOpRemoval = true;
            } else {
                LOG.error("processVpnInterfaceUp: vpn interface {} to go to configured vpn {} on dpn {}," + " but in operational vpn {}", interfaceName, vpnName, dpId, opVpnName);
            }
        }
        if (!waitForVpnInterfaceOpRemoval) {
            // Add the VPNInterface and quit
            vpnFootprintService.updateVpnToDpnMapping(dpId, vpnName, primaryRd, interfaceName, null, /*ipAddressSourceValuePair*/
            true);
            processVpnInterfaceAdjacencies(dpId, lportTag, vpnName, primaryRd, interfaceName, vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState);
            if (!isBgpVpnInternetVpn) {
                VpnUtil.bindService(vpnName, interfaceName, dataBroker, false, /*isTunnelInterface*/
                jobCoordinator);
            }
            LOG.info("processVpnInterfaceUp: Plumbed vpn interface {} onto dpn {} for vpn {}", interfaceName, dpId, vpnName);
            if (interfaceManager.isExternalInterface(interfaceName)) {
                processExternalVpnInterface(interfaceName, vpnName, vpnId, dpId, lportTag, writeInvTxn, NwConstants.ADD_FLOW);
            }
            return;
        }
        // FIB didn't get a chance yet to clean up this VPNInterface
        // Let us give it a chance here !
        LOG.info("processVpnInterfaceUp: Trying to add VPN Interface {} on dpn {} for vpn {}," + " but waiting for FIB to clean up! ", interfaceName, dpId, vpnName);
        try {
            Runnable notifyTask = new VpnNotifyTask();
            synchronized (notifyTask) {
                // Per FB's "Unconditional wait" violation, the code should really verify that the condition it
                // intends to wait for is not already satisfied before calling wait. However the VpnNotifyTask is
                // published here while holding the lock on it so this path will hit the wait before notify can be
                // invoked.
                vpnIntfMap.put(interfaceName, notifyTask);
                try {
                    notifyTask.wait(VpnConstants.MAX_WAIT_TIME_IN_MILLISECONDS);
                } catch (InterruptedException e) {
                // Ignored
                }
            }
        } finally {
            vpnIntfMap.remove(interfaceName);
        }
        if (opVpnInterface != null) {
            LOG.warn("processVpnInterfaceUp: VPN Interface {} removal on dpn {} for vpn {}" + " by FIB did not complete on time," + " bailing addition ...", interfaceName, dpId, vpnName);
            VpnUtil.unsetScheduledToRemoveForVpnInterface(txRunner, interfaceName);
            return;
        }
        // VPNInterface got removed, proceed with Add
        LOG.info("processVpnInterfaceUp: Continuing to plumb vpn interface {} onto dpn {} for vpn {}", interfaceName, dpId, vpnName);
        vpnFootprintService.updateVpnToDpnMapping(dpId, vpnName, primaryRd, interfaceName, null, /*ipAddressSourceValuePair*/
        true);
        processVpnInterfaceAdjacencies(dpId, lportTag, vpnName, primaryRd, interfaceName, vpnId, writeConfigTxn, writeOperTxn, writeInvTxn, interfaceState);
        if (!isBgpVpnInternetVpn) {
            VpnUtil.bindService(vpnName, interfaceName, dataBroker, false, /*isTunnelInterface*/
            jobCoordinator);
        }
        LOG.info("processVpnInterfaceUp: Plumbed vpn interface {} onto dpn {} for vpn {} after waiting for" + " FIB to clean up", interfaceName, dpId, vpnName);
        if (interfaceManager.isExternalInterface(interfaceName)) {
            processExternalVpnInterface(interfaceName, vpnName, vpnId, dpId, lportTag, writeInvTxn, NwConstants.ADD_FLOW);
        }
    } else {
        // Interface is retained in the DPN, but its Link Up.
        // Advertise prefixes again for this interface to BGP
        InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(vpnInterface.getName());
        InstanceIdentifier<VpnInterfaceOpDataEntry> vpnInterfaceOpIdentifier = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
        advertiseAdjacenciesForVpnToBgp(primaryRd, dpId, vpnInterfaceOpIdentifier, vpnName, interfaceName);
        // Perform similar operation as interface add event for extraroutes.
        InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
        Optional<Adjacencies> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
        if (!optAdjacencies.isPresent()) {
            LOG.trace("No config adjacencies present for vpninterface {}", vpnInterface);
            return;
        }
        List<Adjacency> adjacencies = optAdjacencies.get().getAdjacency();
        for (Adjacency adjacency : adjacencies) {
            if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                continue;
            }
            // if BGPVPN Internet, filter only IPv6 Adjacencies
            if (isBgpVpnInternetVpn && !VpnUtil.isAdjacencyEligibleToVpnInternet(dataBroker, adjacency)) {
                continue;
            }
            addNewAdjToVpnInterface(vpnInterfaceOpIdentifier, primaryRd, adjacency, dpId, writeOperTxn, writeConfigTxn);
        }
    }
}
Also used : Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)48 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)39 BigInteger (java.math.BigInteger)34 ArrayList (java.util.ArrayList)33 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)26 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)23 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)22 VrfEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey)22 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)19 RoutePaths (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentrybase.RoutePaths)17 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)17 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)16 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)15 ExecutionException (java.util.concurrent.ExecutionException)14 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)14 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)14 RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)12 Optional (com.google.common.base.Optional)11 Collections (java.util.Collections)11 List (java.util.List)11