Search in sources :

Example 96 with Subnet

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

the class SubnetRouteInterfaceStateChangeListener method getSubnetId.

@Nonnull
protected List<Uuid> getSubnetId(Interface intrf) {
    List<Uuid> listSubnetIds = new ArrayList<>();
    if (!NeutronUtils.isUuid(intrf.getName())) {
        LOG.debug("SubnetRouteInterfaceListener: Interface {} doesn't have valid uuid pattern", intrf.getName());
        return listSubnetIds;
    }
    PortOpDataEntry portOpEntry = subOpDpnManager.getPortOpDataEntry(intrf.getName());
    if (portOpEntry != null) {
        List<Uuid> subnet = portOpEntry.getSubnetIds();
        if (subnet != null) {
            return subnet;
        }
        return listSubnetIds;
    }
    LOG.trace("SubnetRouteInterfaceListener : Received Port {} event for {} that is not part of subnetRoute", intrf.getOperStatus(), intrf.getName());
    Port port = neutronVpnManager.getNeutronPort(intrf.getName());
    if (port == null) {
        return listSubnetIds;
    }
    List<FixedIps> portIps = port.getFixedIps();
    if (port.getFixedIps() != null) {
        for (FixedIps portIp : portIps) {
            listSubnetIds.add(portIp.getSubnetId());
        }
    }
    return listSubnetIds;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Nonnull(javax.annotation.Nonnull)

Example 97 with Subnet

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

the class SubnetRouteInterfaceStateChangeListener method update.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void update(InstanceIdentifier<Interface> identifier, Interface original, Interface update) {
    try {
        String interfaceName = update.getName();
        if (L2vlan.class.equals(update.getType())) {
            LOG.trace("{} update: Operation Interface update event - Old: {}, New: {}", LOGGING_PREFIX, original, update);
            List<Uuid> subnetIdList = getSubnetId(update);
            if (subnetIdList.isEmpty()) {
                LOG.error("SubnetRouteInterfaceListener update: Port {} doesn't exist in configDS", update.getName());
                return;
            }
            for (Uuid subnetId : subnetIdList) {
                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    BigInteger dpnId = BigInteger.ZERO;
                    try {
                        dpnId = InterfaceUtils.getDpIdFromInterface(update);
                    } catch (Exception e) {
                        LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet  {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, update.getName(), subnetId, e);
                    }
                    InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                    Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                    if (!cfgVpnInterface.isPresent()) {
                        return futures;
                    }
                    boolean interfaceChangeEligible = false;
                    for (VpnInstanceNames vpnInterfaceVpnInstance : cfgVpnInterface.get().getVpnInstanceNames()) {
                        String vpnName = vpnInterfaceVpnInstance.getVpnName();
                        InstanceIdentifier<VpnInterfaceOpDataEntry> idOper = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
                        Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, idOper);
                        if (optVpnInterface.isPresent()) {
                            BigInteger dpnIdLocal = dpnId;
                            if (dpnIdLocal.equals(BigInteger.ZERO)) {
                                dpnIdLocal = optVpnInterface.get().getDpnId();
                            }
                            if (!dpnIdLocal.equals(BigInteger.ZERO)) {
                                interfaceChangeEligible = true;
                                break;
                            }
                        }
                    }
                    if (interfaceChangeEligible) {
                        if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
                            LOG.info("{} update: Received port UP event for interface {} in subnet {}", LOGGING_PREFIX, update.getName(), subnetId);
                            vpnSubnetRouteHandler.onInterfaceUp(dpnId, update.getName(), subnetId);
                        } else if (update.getOperStatus().equals(Interface.OperStatus.Down) || update.getOperStatus().equals(Interface.OperStatus.Unknown)) {
                            /*
                                     * If the interface went down voluntarily (or) if the interface is not
                                     * reachable from control-path involuntarily, trigger subnetRoute election
                                     */
                            LOG.info("{} update: Received port {} event for interface {} in subnet {} ", LOGGING_PREFIX, update.getOperStatus().equals(Interface.OperStatus.Unknown) ? "UNKNOWN" : "DOWN", update.getName(), subnetId);
                            vpnSubnetRouteHandler.onInterfaceDown(dpnId, update.getName(), subnetId);
                        }
                    }
                    return futures;
                });
            }
        }
        LOG.info("{} update: Processed Interface {} update event", LOGGING_PREFIX, update.getName());
    } catch (Exception e) {
        LOG.error("{} update: Exception observed in handling deletion of VPNInterface {}", LOGGING_PREFIX, update.getName(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) 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) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BigInteger(java.math.BigInteger) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 98 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet 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 99 with Subnet

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

the class SubnetRoutePacketInHandler method handlePacketToInternalNetwork.

private void handlePacketToInternalNetwork(byte[] dstIp, String dstIpStr, int destinationAddress, long elanTag) throws UnknownHostException {
    SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, destinationAddress);
    if (targetSubnetForPacketOut == null) {
        LOG.debug("Couldn't find matching subnet for elan tag {} and destination ip {}", elanTag, dstIpStr);
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    Optional<Subnetmap> subnetMap = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildSubnetmapIdentifier(targetSubnetForPacketOut.getSubnetId()));
    if (!subnetMap.isPresent()) {
        LOG.debug("Couldn't find subnet map for subnet {}", targetSubnetForPacketOut.getSubnetId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceIp = subnetMap.get().getRouterInterfaceFixedIp();
    if (sourceIp == null) {
        LOG.debug("Subnet map {} doesn't have a router interface ip defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceMac = subnetMap.get().getRouterIntfMacAddress();
    if (sourceMac == null) {
        LOG.debug("Subnet map {} doesn't have a router interface mac address defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), sourceIp, sourceMac, dstIp, elanTag);
}
Also used : 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)

Example 100 with Subnet

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

the class SubnetRoutePacketInHandler method handleBgpVpnSubnetRoute.

private void handleBgpVpnSubnetRoute(IPv4 ipv4, byte[] srcMac, byte[] dstIp, String dstIpStr, String srcIpStr, long elanTag) throws UnknownHostException {
    LOG.info("{} handleBgpVpnSubnetRoute: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and elan Tag {}", LOGGING_PREFIX, srcIpStr, dstIpStr, elanTag);
    SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, ipv4.getDestinationAddress());
    if (targetSubnetForPacketOut != null) {
        // Handle subnet routes ip requests
        transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), srcIpStr, NWUtil.toStringMacAddress(srcMac), dstIp, elanTag);
    } else {
        VpnManagerCounters.subnet_route_packet_failed.inc();
        LOG.debug("{} handleBgpVpnSubnetRoute: Could not find target subnet for packet out {}", LOGGING_PREFIX, dstIpStr);
    }
}
Also used : SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)72 ArrayList (java.util.ArrayList)44 BigInteger (java.math.BigInteger)30 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)28 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)17 Subnet (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)15 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)13 List (java.util.List)12 ExecutionException (java.util.concurrent.ExecutionException)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)12 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 UnknownHostException (java.net.UnknownHostException)10 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)10 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)9 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)9 HashMap (java.util.HashMap)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)8