Search in sources :

Example 1 with DpnVpninterfacesList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList in project netvirt by opendaylight.

the class VpnInterfaceManager method removeFromNeutronRouterDpnsMap.

protected void removeFromNeutronRouterDpnsMap(String routerName, String vpnInterfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
    if (dpId.equals(BigInteger.ZERO)) {
        LOG.error("removeFromNeutronRouterDpnsMap: Could not retrieve dp id for interface {} to handle router {}" + " dissociation model", vpnInterfaceName, routerName);
        return;
    }
    InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
    Optional<DpnVpninterfacesList> optionalRouterDpnList = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
    if (optionalRouterDpnList.isPresent()) {
        List<RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
        RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(vpnInterfaceName)).setInterface(vpnInterfaceName).build();
        if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
            if (routerInterfaces.isEmpty()) {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
            } else {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(RouterInterfaces.class, new RouterInterfacesKey(vpnInterfaceName)));
            }
        }
    }
}
Also used : RouterInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder) RouterInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey)

Example 2 with DpnVpninterfacesList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList in project netvirt by opendaylight.

the class NatUtil method addToNeutronRouterDpnsMap.

public static void addToNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
    if (dpId.equals(BigInteger.ZERO)) {
        LOG.warn("addToNeutronRouterDpnsMap : Could not retrieve dp id for interface {} " + "to handle router {} association model", interfaceName, routerName);
        return;
    }
    LOG.debug("addToNeutronRouterDpnsMap : Adding the Router {} and DPN {} for the Interface {} in the " + "ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
    InstanceIdentifier<DpnVpninterfacesList> dpnVpnInterfacesListIdentifier = getRouterDpnId(routerName, dpId);
    Optional<DpnVpninterfacesList> optionalDpnVpninterfacesList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier);
    org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(interfaceName)).setInterface(interfaceName).build();
    if (optionalDpnVpninterfacesList.isPresent()) {
        LOG.debug("addToNeutronRouterDpnsMap : RouterDpnList already present for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
        writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, dpnVpnInterfacesListIdentifier.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class, new RouterInterfacesKey(interfaceName)), routerInterface, true);
    } else {
        LOG.debug("addToNeutronRouterDpnsMap : Building new RouterDpnList for the Router {} and DPN {} for the " + "Interface {} in the ODL-L3VPN : NeutronRouterDpn map", routerName, dpId, interfaceName);
        RouterDpnListBuilder routerDpnListBuilder = new RouterDpnListBuilder();
        routerDpnListBuilder.setRouterId(routerName);
        DpnVpninterfacesListBuilder dpnVpnList = new DpnVpninterfacesListBuilder().setDpnId(dpId);
        List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces = new ArrayList<>();
        routerInterfaces.add(routerInterface);
        dpnVpnList.setRouterInterfaces(routerInterfaces);
        routerDpnListBuilder.setDpnVpninterfacesList(Collections.singletonList(dpnVpnList.build()));
        writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, getRouterId(routerName), routerDpnListBuilder.build(), true);
    }
}
Also used : ArrayList(java.util.ArrayList) RouterInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder) RouterDpnListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListBuilder) DpnVpninterfacesListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListBuilder) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey)

Example 3 with DpnVpninterfacesList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList in project netvirt by opendaylight.

the class NatUtil method removeFromNeutronRouterDpnsMap.

public static void removeFromNeutronRouterDpnsMap(DataBroker broker, String routerName, String interfaceName, BigInteger dpId, WriteTransaction writeOperTxn) {
    if (dpId.equals(BigInteger.ZERO)) {
        LOG.error("removeFromNeutronRouterDpnsMap : Could not retrieve dp id for interface {} to handle router {} " + "dissociation model", interfaceName, routerName);
        return;
    }
    InstanceIdentifier<DpnVpninterfacesList> routerDpnListIdentifier = getRouterDpnId(routerName, dpId);
    Optional<DpnVpninterfacesList> optionalRouterDpnList = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(broker, LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
    if (optionalRouterDpnList.isPresent()) {
        List<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces> routerInterfaces = optionalRouterDpnList.get().getRouterInterfaces();
        org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces routerInterface = new RouterInterfacesBuilder().setKey(new RouterInterfacesKey(interfaceName)).setInterface(interfaceName).build();
        if (routerInterfaces != null && routerInterfaces.remove(routerInterface)) {
            if (routerInterfaces.isEmpty()) {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier);
            } else {
                writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, routerDpnListIdentifier.child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces.class, new RouterInterfacesKey(interfaceName)));
            }
        }
    }
}
Also used : DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey) RouterInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder)

Example 4 with DpnVpninterfacesList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList in project netvirt by opendaylight.

the class NatUtil method getDpnsForRouter.

@Nonnull
public static List<BigInteger> getDpnsForRouter(DataBroker dataBroker, String routerUuid) {
    InstanceIdentifier id = InstanceIdentifier.builder(NeutronRouterDpns.class).child(RouterDpnList.class, new RouterDpnListKey(routerUuid)).build();
    Optional<RouterDpnList> routerDpnListData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    List<BigInteger> dpns = new ArrayList<>();
    if (routerDpnListData.isPresent()) {
        List<DpnVpninterfacesList> dpnVpninterfacesList = routerDpnListData.get().getDpnVpninterfacesList();
        for (DpnVpninterfacesList dpnVpnInterface : dpnVpninterfacesList) {
            dpns.add(dpnVpnInterface.getDpnId());
        }
    }
    return dpns;
}
Also used : RouterDpnListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListKey) ArrayList(java.util.ArrayList) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) BigInteger(java.math.BigInteger) DpnVpninterfacesList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList) Nonnull(javax.annotation.Nonnull)

Example 5 with DpnVpninterfacesList

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList in project netvirt by opendaylight.

the class RouterDpnChangeListener method add.

@Override
protected void add(final InstanceIdentifier<DpnVpninterfacesList> identifier, final DpnVpninterfacesList dpnInfo) {
    LOG.trace("add : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
    final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
    BigInteger dpnId = dpnInfo.getDpnId();
    // check router is associated to external network
    InstanceIdentifier<Routers> id = NatUtil.buildRouterIdentifier(routerUuid);
    Optional<Routers> routerData = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (routerData.isPresent()) {
        Routers router = routerData.get();
        Uuid networkId = router.getNetworkId();
        if (networkId != null) {
            if (natMode == NatMode.Conntrack) {
                BigInteger naptSwitch = NatUtil.getPrimaryNaptfromRouterName(dataBroker, router.getRouterName());
                if (naptSwitch == null || naptSwitch.equals(BigInteger.ZERO)) {
                    LOG.warn("add : NAPT switch is not selected.");
                    return;
                }
                // If it is for NAPT switch skip as the flows would be already programmed.
                if (naptSwitch.equals(dpnId)) {
                    LOG.debug("Skipping the notification recived for NAPT switch {}", routerUuid);
                    return;
                }
                natServiceManager.notify(router, naptSwitch, dpnId, SnatServiceManager.Action.SNAT_ROUTER_ENBL);
            } else {
                coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
                    WriteTransaction writeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    LOG.debug("add : Router {} is associated with ext nw {}", routerUuid, networkId);
                    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
                    Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (routerId == NatConstants.INVALID_ID) {
                        LOG.error("add : Invalid routerId returned for routerName {}", routerUuid);
                        writeFlowInvTx.cancel();
                        removeFlowInvTx.cancel();
                        return futures;
                    }
                    extNetGroupInstaller.installExtNetGroupEntries(networkId, dpnId);
                    Long vpnId;
                    if (vpnName == null) {
                        LOG.debug("add : Internal vpn associated to router {}", routerUuid);
                        vpnId = routerId;
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Install default entry in FIB to SNAT table
                        LOG.info("add : Installing default route in FIB on dpn {} for router {} with vpn {}", dpnId, routerUuid, vpnId);
                        installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
                        snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, writeFlowInvTx);
                    } else {
                        LOG.debug("add : External BGP vpn associated to router {}", routerUuid);
                        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("add : Invalid vpnId returned for routerName {}", routerUuid);
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("add : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Install default entry in FIB to SNAT table
                        LOG.debug("add : Installing default route in FIB on dpn {} for routerId {} with " + "vpnId {}...", dpnId, routerUuid, vpnId);
                        installDefaultNatRouteForRouterExternalSubnets(dpnId, NatUtil.getExternalSubnetIdsFromExternalIps(router.getExternalIps()));
                        snatDefaultRouteProgrammer.installDefNATRouteInDPN(dpnId, vpnId, routerId, writeFlowInvTx);
                    }
                    if (router.isEnableSnat()) {
                        LOG.info("add : SNAT enabled for router {}", routerUuid);
                        ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerUuid, networkId);
                        if (extNwProvType == null) {
                            LOG.error("add : External Network Provider Type missing");
                            writeFlowInvTx.cancel();
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        handleSNATForDPN(dpnId, routerUuid, routerId, vpnId, writeFlowInvTx, removeFlowInvTx, extNwProvType);
                    } else {
                        LOG.info("add : SNAT is not enabled for router {} to handle addDPN event {}", routerUuid, dpnId);
                    }
                    futures.add(NatUtil.waitForTransactionToComplete(writeFlowInvTx));
                    futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
                    return futures;
                }, NatConstants.NAT_DJC_MAX_RETRIES);
            }
        // end of controller based SNAT
        }
    } else {
        LOG.debug("add : Router {} is not associated with External network", routerUuid);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ProviderTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes) ArrayList(java.util.ArrayList) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RouterDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList)

Aggregations

DpnVpninterfacesList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesList)9 BigInteger (java.math.BigInteger)7 RouterInterfacesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesBuilder)6 RouterInterfacesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfacesKey)6 ArrayList (java.util.ArrayList)5 RouterDpnList (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnList)5 RouterInterfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.dpn.vpninterfaces.list.RouterInterfaces)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Nonnull (javax.annotation.Nonnull)2 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)2 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)2 RouterDpnListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListBuilder)2 RouterDpnListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.RouterDpnListKey)2 DpnVpninterfacesListBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.neutron.router.dpns.router.dpn.list.DpnVpninterfacesListBuilder)2 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 HashSet (java.util.HashSet)1 NeutronRouterDpns (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.NeutronRouterDpns)1 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)1