Search in sources :

Example 96 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.

// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
    ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
    if (elanInfo == null) {
        LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
        return null;
    }
    Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
    if (!optionalNetworkMap.isPresent()) {
        LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
        return null;
    }
    List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
    LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
    for (Uuid subnetId : subnetList) {
        String vpnName = null;
        Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
        if (sn != null && sn.getVpnId() != null) {
            vpnName = sn.getVpnId().getValue();
        }
        if (vpnName == null) {
            continue;
        }
        Optional<SubnetOpDataEntry> optionalSubs;
        optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
        if (!optionalSubs.isPresent()) {
            continue;
        }
        SubnetOpDataEntry subOpEntry = optionalSubs.get();
        if (subOpEntry.getNhDpnId() != null) {
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
            boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
            if (match) {
                return subOpEntry;
            }
        }
    }
    return null;
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 97 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class SubnetmapChangeListener method update.

@Override
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void update(InstanceIdentifier<Subnetmap> identifier, Subnetmap subnetmapOriginal, Subnetmap subnetmapUpdate) {
    LOG.debug("SubnetMapChangeListener update method - key {}, original {}, update {}", identifier, subnetmapOriginal, subnetmapUpdate);
    Uuid subnetId = subnetmapUpdate.getId();
    Network network = VpnUtil.getNeutronNetwork(dataBroker, subnetmapUpdate.getNetworkId());
    if (network == null) {
        LOG.error("SubnetMapChangeListener:update: network was not found for subnetId {}", subnetId.getValue());
        return;
    }
    if (VpnUtil.getIsExternal(network)) {
        LOG.debug("SubnetMapChangeListener:update: provider subnetwork {} is handling in " + "ExternalSubnetVpnInstanceListener", subnetId.getValue());
        return;
    }
    String elanInstanceName = subnetmapUpdate.getNetworkId().getValue();
    long elanTag = getElanTag(elanInstanceName);
    if (elanTag == 0L) {
        LOG.error("SubnetMapChangeListener:update: unable to fetch elantag from ElanInstance {} for subnetId {}", elanInstanceName, subnetId);
        return;
    }
    // update on BGPVPN or InternalVPN change
    Uuid vpnIdOld = subnetmapOriginal.getVpnId();
    Uuid vpnIdNew = subnetmapUpdate.getVpnId();
    if (!Objects.equals(vpnIdOld, vpnIdNew)) {
        LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in VPN", subnetmapUpdate.getId().getValue());
        updateSubnetmapOpDataEntry(subnetmapOriginal.getVpnId(), subnetmapUpdate.getVpnId(), subnetmapUpdate, subnetmapOriginal, elanTag);
    }
    // update on Internet VPN Id change
    Uuid inetVpnIdOld = subnetmapOriginal.getInternetVpnId();
    Uuid inetVpnIdNew = subnetmapUpdate.getInternetVpnId();
    if (!Objects.equals(inetVpnIdOld, inetVpnIdNew)) {
        LOG.info("SubnetMapChangeListener:update: update subnetOpDataEntry for subnet {} imported in InternetVPN", subnetmapUpdate.getId().getValue());
        updateSubnetmapOpDataEntry(inetVpnIdOld, inetVpnIdNew, subnetmapUpdate, subnetmapOriginal, elanTag);
    }
    // update on PortList change
    List<Uuid> oldPortList;
    List<Uuid> newPortList;
    newPortList = subnetmapUpdate.getPortList() != null ? subnetmapUpdate.getPortList() : new ArrayList<>();
    oldPortList = subnetmapOriginal.getPortList() != null ? subnetmapOriginal.getPortList() : new ArrayList<>();
    if (newPortList.size() == oldPortList.size()) {
        return;
    }
    LOG.info("SubnetMapChangeListener:update: update port list for subnet {}", subnetmapUpdate.getId().getValue());
    if (newPortList.size() > oldPortList.size()) {
        for (Uuid portId : newPortList) {
            if (!oldPortList.contains(portId)) {
                vpnSubnetRouteHandler.onPortAddedToSubnet(subnetmapUpdate, portId);
                return;
            }
        }
    } else {
        for (Uuid portId : oldPortList) {
            if (!newPortList.contains(portId)) {
                vpnSubnetRouteHandler.onPortRemovedFromSubnet(subnetmapUpdate, portId);
                return;
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) ArrayList(java.util.ArrayList)

Example 98 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class NatUtil method getNetworkVpnIdFromRouterId.

public static Long getNetworkVpnIdFromRouterId(DataBroker broker, long routerId) {
    // Get the external network ID from the ExternalRouter model
    Uuid networkId = NatUtil.getNetworkIdFromRouterId(broker, routerId);
    if (networkId == null) {
        LOG.error("getNetworkVpnIdFromRouterId : networkId is null");
        return NatConstants.INVALID_ID;
    }
    // Get the VPN ID from the ExternalNetworks model
    Uuid vpnUuid = NatUtil.getVpnIdfromNetworkId(broker, networkId);
    if (vpnUuid == null) {
        LOG.error("getNetworkVpnIdFromRouterId : vpnUuid is null");
        return NatConstants.INVALID_ID;
    }
    Long vpnId = NatUtil.getVpnId(broker, vpnUuid.getValue());
    return vpnId;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 99 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class NatUtil method checkForRoutersWithSameExtNetAndNaptSwitch.

public static boolean checkForRoutersWithSameExtNetAndNaptSwitch(DataBroker broker, Uuid networkId, String routerName, BigInteger dpnId) {
    InstanceIdentifier<Networks> id = buildNetworkIdentifier(networkId);
    Optional<Networks> networkData = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, id);
    if (networkData != null && networkData.isPresent()) {
        List<Uuid> routerUuidList = networkData.get().getRouterIds();
        if (routerUuidList != null && !routerUuidList.isEmpty()) {
            for (Uuid routerUuid : routerUuidList) {
                String sharedRouterName = routerUuid.getValue();
                if (!routerName.equals(sharedRouterName)) {
                    BigInteger swtichDpnId = NatUtil.getPrimaryNaptfromRouterName(broker, sharedRouterName);
                    if (swtichDpnId == null) {
                        continue;
                    } else if (swtichDpnId.equals(dpnId)) {
                        LOG.debug("checkForRoutersWithSameExtNetAndNaptSwitch: external-network {} is " + "associated with other active router {} on NAPT switch {}", networkId, sharedRouterName, swtichDpnId);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) BigInteger(java.math.BigInteger)

Example 100 with Network

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network in project netvirt by opendaylight.

the class RouterDpnChangeListener method remove.

@Override
protected void remove(InstanceIdentifier<DpnVpninterfacesList> identifier, DpnVpninterfacesList dpnInfo) {
    LOG.trace("remove : key: {}, value: {}", dpnInfo.getKey(), dpnInfo);
    final String routerUuid = identifier.firstKeyOf(RouterDpnList.class).getRouterId();
    Long routerId = NatUtil.getVpnId(dataBroker, routerUuid);
    if (routerId == NatConstants.INVALID_ID) {
        LOG.error("REMOVE: Invalid routId returned for routerName {}", routerUuid);
        return;
    }
    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("remove : 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_DISBL);
            } else {
                coordinator.enqueueJob(NatConstants.NAT_DJC_PREFIX + dpnInfo.getKey(), () -> {
                    WriteTransaction removeFlowInvTx = dataBroker.newWriteOnlyTransaction();
                    LOG.debug("remove : Router {} is associated with ext nw {}", routerUuid, networkId);
                    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerUuid);
                    Long vpnId;
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (vpnName == null) {
                        LOG.debug("remove : Internal vpn associated to router {}", routerUuid);
                        vpnId = routerId;
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Remove default entry in FIB
                        LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
                        snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, removeFlowInvTx);
                    } else {
                        LOG.debug("remove : External vpn associated to router {}", routerUuid);
                        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
                        if (vpnId == NatConstants.INVALID_ID) {
                            LOG.error("remove : Invalid vpnId returned for routerName {}", routerUuid);
                            removeFlowInvTx.cancel();
                            return futures;
                        }
                        LOG.debug("remove : Retrieved vpnId {} for router {}", vpnId, routerUuid);
                        // Remove default entry in FIB
                        LOG.debug("remove : Removing default route in FIB on dpn {} for vpn {} ...", dpnId, vpnName);
                        snatDefaultRouteProgrammer.removeDefNATRouteInDPN(dpnId, vpnId, routerId, removeFlowInvTx);
                    }
                    if (router.isEnableSnat()) {
                        LOG.info("remove : SNAT enabled for router {}", routerUuid);
                        removeSNATFromDPN(dpnId, routerUuid, routerId, vpnId, networkId, removeFlowInvTx);
                    } else {
                        LOG.info("remove : SNAT is not enabled for router {} to handle removeDPN event {}", routerUuid, dpnId);
                    }
                    futures.add(NatUtil.waitForTransactionToComplete(removeFlowInvTx));
                    return futures;
                }, NatConstants.NAT_DJC_MAX_RETRIES);
            }
        // end of controller based SNAT
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ArrayList(java.util.ArrayList) 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

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)93 ArrayList (java.util.ArrayList)46 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)33 BigInteger (java.math.BigInteger)31 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)31 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)26 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)19 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)19 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)17 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)15 ElanInstance (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)12 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)11 ExecutionException (java.util.concurrent.ExecutionException)10 ExternalNetworks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks)10 Networks (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks)10 QosPolicy (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.rev160613.qos.attributes.qos.policies.QosPolicy)10 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)9 HashSet (java.util.HashSet)8 Nonnull (javax.annotation.Nonnull)8