Search in sources :

Example 16 with L3vpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.

the class VpnInterfaceOpListener method postProcessVpnInterfaceRemoval.

private void postProcessVpnInterfaceRemoval(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, VpnInterfaceOpDataEntry del, WriteTransaction writeOperTxn) {
    final VpnInterfaceOpDataEntryKey key = identifier.firstKeyOf(VpnInterfaceOpDataEntry.class, VpnInterfaceOpDataEntryKey.class);
    String interfaceName = key.getName();
    String vpnName = del.getVpnInstanceName();
    LOG.info("postProcessVpnInterfaceRemoval: interface name {} vpnName {} dpn {}", interfaceName, vpnName, del.getDpnId());
    // decrement the vpn interface count in Vpn Instance Op Data
    Optional<VpnInstance> vpnInstance = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnOperDsUtils.getVpnInstanceToVpnIdIdentifier(vpnName));
    if (vpnInstance.isPresent()) {
        String rd = null;
        rd = vpnInstance.get().getVrfId();
        VpnInstanceOpDataEntry vpnInstOp = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
        AdjacenciesOp adjs = del.getAugmentation(AdjacenciesOp.class);
        List<Adjacency> adjList = adjs != null ? adjs.getAdjacency() : null;
        if (vpnInstOp != null && adjList != null && adjList.size() > 0) {
            /*
                 * When a VPN Interface is removed by FibManager (aka VrfEntryListener and its cohorts),
                 * one adjacency for that VPN Interface will be hanging around along with that
                 * VPN Interface.   That adjacency could be primary (or) non-primary.
                 * If its a primary adjacency, then a prefix-to-interface entry will be available for the
                 * same.  If its a non-primary adjacency, then a prefix-to-interface entry will not be
                 * available for the same, instead we will have vpn-to-extraroutes filled in for them.
                 *
                 * Here we try to remove prefix-to-interface entry for pending adjacency in the deleted
                 * vpnInterface.   More importantly, we also update the vpnInstanceOpData by removing this
                 * vpnInterface from it.
                 */
            List<Prefixes> prefixToInterface = new ArrayList<>();
            for (Adjacency adjacency : adjs.getAdjacency()) {
                List<Prefixes> prefixToInterfaceLocal = new ArrayList<>();
                Optional<Prefixes> prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(adjacency.getIpAddress())));
                if (prefix.isPresent()) {
                    prefixToInterfaceLocal.add(prefix.get());
                }
                if (prefixToInterfaceLocal.isEmpty()) {
                    for (String nh : adjacency.getNextHopIpList()) {
                        prefix = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), VpnUtil.getIpPrefix(nh)));
                        if (prefix.isPresent()) {
                            prefixToInterfaceLocal.add(prefix.get());
                        }
                    }
                }
                if (!prefixToInterfaceLocal.isEmpty()) {
                    prefixToInterface.addAll(prefixToInterfaceLocal);
                }
            }
            /*
                 * In VPN Migration scenarios, there is a race condition where we use the new DPNID
                 * for the migrated VM instead of old DPNID because when we read prefix-to-interface to cleanup
                 * old DPNID, we actually get the new DPNID.
                 *
                 * More dangerously, we tend to alter the new prefix-to-interface which should be retained intac
                 * for the migration to succeed in L3VPN.  As a workaround, here we are going to use the dpnId in
                 * the deleted vpnInterface itself instead of tinkering with the prefix-to-interface.  Further we
                 * will tinker prefix-to-interface only when are damn sure if its value matches our
                 * deleted vpnInterface.
                 *
                 */
            for (Prefixes pref : prefixToInterface) {
                if (isMatchedPrefixToInterface(pref, del)) {
                    if (writeOperTxn != null) {
                        writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()));
                    } else {
                        VpnUtil.delete(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(vpnInstOp.getVpnId(), pref.getIpAddress()), VpnUtil.DEFAULT_CALLBACK);
                    }
                }
            }
        }
        if (del.getDpnId() != null) {
            vpnFootprintService.updateVpnToDpnMapping(del.getDpnId(), del.getVpnInstanceName(), rd, interfaceName, null, /*ipAddressSourceValuePair*/
            false);
        }
        LOG.info("postProcessVpnInterfaceRemoval: Removed vpn operational data and updated vpn footprint" + " for interface {} on dpn {} vpn {}", interfaceName, del.getDpnId(), vpnName);
    } else {
        LOG.error("postProcessVpnInterfaceRemoval: rd not retrievable as vpninstancetovpnid for vpn {} is absent," + " trying rd as {}. interface {} dpn {}", vpnName, vpnName, interfaceName, del.getDpnId());
    }
    notifyTaskIfRequired(interfaceName);
}
Also used : VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) VpnInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.to.vpn.id.VpnInstance) ArrayList(java.util.ArrayList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)

Example 17 with L3vpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.

the class IVpnLinkServiceImpl method handleStaticRoutes.

@Override
public void handleStaticRoutes(InterVpnLinkDataComposite ivpnLink) {
    /*
         * Checks if there are any static routes pointing to any of both
         * InterVpnLink's endpoints. Goes through all routers checking if they have
         * a route whose nexthop is an InterVpnLink endpoint
         */
    // Map that corresponds a routerId with the L3VPN that it's been assigned to.
    Map<String, String> routerXL3VpnMap = buildRouterXL3VPNMap();
    // Retrieving all Routers
    InstanceIdentifier<Routers> routersIid = InstanceIdentifier.builder(Neutron.class).child(Routers.class).build();
    Optional<Routers> routerOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIid);
    if (!routerOpData.isPresent()) {
        return;
    }
    List<Router> routers = routerOpData.get().getRouter();
    for (Router router : routers) {
        String vpnId = routerXL3VpnMap.get(router.getUuid().getValue());
        if (vpnId == null) {
            LOG.warn("Could not find suitable VPN for router {}", router.getUuid());
            // with next router
            continue;
        }
        List<Routes> routerRoutes = router.getRoutes();
        if (routerRoutes != null) {
            for (Routes route : routerRoutes) {
                handleStaticRoute(vpnId, route, ivpnLink);
            }
        }
    }
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)

Example 18 with L3vpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.

the class VpnToElanFallbackNodeListener method add.

@Override
protected void add(InstanceIdentifier<Node> identifier, Node add) {
    BigInteger dpnId = getDpnIdFromNodeId(add.getNodeId());
    if (dpnId == null) {
        return;
    }
    LOG.debug("Installing L3VPN to ELAN default Fallback flow in LPortDispatcher table on Dpn {}", add.getNodeId());
    List<MatchInfo> matches = Collections.singletonList(new MatchMetadata(MetaDataUtil.getServiceIndexMetaData(ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)), MetaDataUtil.METADATA_MASK_SERVICE_INDEX));
    BigInteger metadataToWrite = MetaDataUtil.getServiceIndexMetaData(ServiceIndex.getIndex(NwConstants.ELAN_SERVICE_NAME, NwConstants.ELAN_SERVICE_INDEX));
    int instructionKey = 0;
    List<Instruction> instructions = Arrays.asList(MDSALUtil.buildAndGetWriteMetadaInstruction(metadataToWrite, MetaDataUtil.METADATA_MASK_SERVICE_INDEX, ++instructionKey), MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_INTERFACE_TABLE, ++instructionKey));
    Flow flow = MDSALUtil.buildFlowNew(NwConstants.LPORT_DISPATCHER_TABLE, L3_TO_L2_DEFAULT_FLOW_REF, NwConstants.TABLE_MISS_PRIORITY, L3_TO_L2_DEFAULT_FLOW_REF, 0, 0, CloudServiceChainConstants.COOKIE_L3_BASE, matches, instructions);
    mdsalMgr.installFlow(dpnId, flow);
}
Also used : MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) BigInteger(java.math.BigInteger) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 19 with L3vpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.

the class VpnToElanFallbackNodeListener method remove.

@Override
protected void remove(InstanceIdentifier<Node> identifier, Node del) {
    BigInteger dpnId = getDpnIdFromNodeId(del.getNodeId());
    if (dpnId == null) {
        return;
    }
    LOG.debug("Removing L3VPN to ELAN default Fallback flow in LPortDispatcher table from Dpn {}", del.getNodeId());
    Flow flowToRemove = new FlowBuilder().setFlowName(L3_TO_L2_DEFAULT_FLOW_REF).setId(new FlowId(L3_TO_L2_DEFAULT_FLOW_REF)).setTableId(NwConstants.LPORT_DISPATCHER_TABLE).build();
    mdsalMgr.removeFlow(dpnId, flowToRemove);
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) BigInteger(java.math.BigInteger) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 20 with L3vpn

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn in project netvirt by opendaylight.

the class VpnServiceChainUtils method programLPortDispatcherFlowForScfToVpn.

/**
 * Installs/removes a flow in LPortDispatcher table that is in charge of
 * handling packets that falls back from SCF Pipeline to L3Vpn.
 *
 * @param mdsalManager  MDSAL Util API accessor
 * @param vpnId Dataplane identifier of the VPN, the Vrf Tag.
 * @param dpId The DPN where the flow must be installed/removed
 * @param vpnPseudoLportTag Dataplane identifier for the VpnPseudoPort
 * @param addOrRemove States if the flow must be created or removed
 */
public static void programLPortDispatcherFlowForScfToVpn(IMdsalApiManager mdsalManager, long vpnId, BigInteger dpId, Integer vpnPseudoLportTag, int addOrRemove) {
    LOG.trace("programLPortDispatcherFlowForScfToVpn: vpnId={} dpId={}, vpnPseudoLportTag={} addOrRemove={}", vpnId, dpId, vpnPseudoLportTag, addOrRemove);
    Flow flow = buildLPortDispFromScfToL3VpnFlow(vpnId, dpId, vpnPseudoLportTag, addOrRemove);
    if (addOrRemove == NwConstants.ADD_FLOW) {
        mdsalManager.installFlow(dpId, flow);
    } else {
        mdsalManager.removeFlow(dpId, flow);
    }
}
Also used : Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Aggregations

ArrayList (java.util.ArrayList)11 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)7 BigInteger (java.math.BigInteger)6 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)4 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)4 VpnInstance (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance)3 ExecutionException (java.util.concurrent.ExecutionException)2 RouteDistinguisherUtil.extractRouteDistinguisher (org.opendaylight.bgp.concepts.RouteDistinguisherUtil.extractRouteDistinguisher)2 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)2 BitArray (org.opendaylight.protocol.util.BitArray)2 VpnTarget (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.af.config.vpntargets.VpnTarget)2 VpnInstanceKey (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey)2 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)2 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)2 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)2 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)2 DpnRoutersList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.DpnRoutersList)2 RoutersList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.dpn.routers.dpn.routers.list.RoutersList)2 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)2