Search in sources :

Example 6 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 SubnetOpDpnManager method removeInterfaceFromDpn.

public boolean removeInterfaceFromDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
    boolean dpnRemoved = false;
    try {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (!optionalSubDpn.isPresent()) {
            LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}" + " not available in datastore", intfName, subnetId.getValue(), dpnId);
            return false;
        }
        SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
        List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
        VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
        vpnIntfList.remove(vpnIntfs);
        if (vpnIntfList.isEmpty()) {
            // Remove the DPN as well
            removeDpnFromSubnet(subnetId, dpnId);
            dpnRemoved = true;
        } else {
            subDpnBuilder.setVpnInterfaces(vpnIntfList);
            SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build());
        }
        LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}", intfName, subnetId.getValue(), dpnId);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}" + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
        return false;
    }
    return dpnRemoved;
}
Also used : SubnetToDpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces) VpnInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)

Example 7 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 SubnetOpDpnManager method addInterfaceToDpn.

public SubnetToDpn addInterfaceToDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
    SubnetToDpn subDpn = null;
    try {
        // Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
        // Please use a synchronize block here as we donot need a cluster-wide lock
        InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
        Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
        if (!optionalSubDpn.isPresent()) {
            // Create a new DPN Entry
            subDpn = addDpnToSubnet(subnetId, dpnId);
        } else {
            subDpn = optionalSubDpn.get();
        }
        SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
        List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
        VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
        vpnIntfList.add(vpnIntfs);
        subDpnBuilder.setVpnInterfaces(vpnIntfList);
        subDpn = subDpnBuilder.build();
        SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
        LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
    } catch (TransactionCommitFailedException ex) {
        LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
        return null;
    }
    return subDpn;
}
Also used : SubnetToDpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder) VpnInterfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces) VpnInterfacesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) VpnInterfacesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder) SubnetToDpnKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)

Example 8 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 add.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
    LOG.trace("{} add: Received interface {} up event", LOGGING_PREFIX, intrf);
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.trace("SubnetRouteInterfaceListener add: Received interface {} up event", intrf);
            if (intrf.getOperStatus().equals(Interface.OperStatus.Up)) {
                List<Uuid> subnetIdList = getSubnetId(intrf);
                if (subnetIdList.isEmpty()) {
                    LOG.trace("SubnetRouteInterfaceListener add: Port {} doesn't exist in configDS", intrf.getName());
                    return;
                }
                for (Uuid subnetId : subnetIdList) {
                    jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                        String interfaceName = intrf.getName();
                        BigInteger dpnId = BigInteger.ZERO;
                        LOG.info("{} add: Received port UP event for interface {} subnetId {}", LOGGING_PREFIX, interfaceName, subnetId);
                        try {
                            dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
                        } catch (Exception e) {
                            LOG.error("{} add: Unable to obtain dpnId for interface {} in subnet {}," + " subnetroute inclusion for this interface failed", LOGGING_PREFIX, interfaceName, subnetId, e);
                        }
                        InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                        Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                        List<ListenableFuture<Void>> futures = new ArrayList<>();
                        if (!cfgVpnInterface.isPresent()) {
                            return futures;
                        }
                        vpnSubnetRouteHandler.onInterfaceUp(dpnId, intrf.getName(), subnetId);
                        return futures;
                    });
                }
            }
        }
        LOG.info("{} add: Processed interface {} up event", LOGGING_PREFIX, intrf.getName());
    } catch (Exception e) {
        LOG.error("{} add: Exception observed in handling addition for VPN Interface {}.", LOGGING_PREFIX, intrf.getName(), e);
    }
}
Also used : 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) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 9 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 remove.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
    try {
        if (L2vlan.class.equals(intrf.getType())) {
            LOG.trace("SubnetRouteInterfaceListener remove: Received interface {} down event", intrf);
            List<Uuid> subnetIdList = getSubnetId(intrf);
            if (subnetIdList.isEmpty()) {
                LOG.trace("SubnetRouteInterfaceListener remove: Port {} doesn't exist in configDS", intrf.getName());
                return;
            }
            for (Uuid subnetId : subnetIdList) {
                jobCoordinator.enqueueJob("SUBNETROUTE-" + subnetId, () -> {
                    String interfaceName = intrf.getName();
                    BigInteger dpnId = BigInteger.ZERO;
                    LOG.info("{} remove: Received port DOWN event for interface {} in subnet {} ", LOGGING_PREFIX, interfaceName, subnetId);
                    try {
                        dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
                    } catch (Exception e) {
                        LOG.error("{} remove: Unable to retrieve dpnId for interface {} in subnet {}. " + "Fetching from vpn interface itself", LOGGING_PREFIX, intrf.getName(), subnetId, e);
                    }
                    InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
                    Optional<VpnInterface> cfgVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
                    List<ListenableFuture<Void>> futures = new ArrayList<>();
                    if (!cfgVpnInterface.isPresent()) {
                        return futures;
                    }
                    boolean interfaceDownEligible = 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)) {
                                interfaceDownEligible = true;
                                break;
                            }
                        }
                    }
                    if (interfaceDownEligible) {
                        vpnSubnetRouteHandler.onInterfaceDown(dpnId, intrf.getName(), subnetId);
                    }
                    return futures;
                });
            }
        }
        LOG.info("{} remove: Processed interface {} down event in ", LOGGING_PREFIX, intrf.getName());
    } catch (Exception e) {
        LOG.error("{} remove: Exception observed in handling deletion of VPN Interface {}.", LOGGING_PREFIX, intrf.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) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Example 10 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 onPacketReceived.

@Override
public void onPacketReceived(PacketReceived notification) {
    short tableId = notification.getTableId().getValue();
    LOG.trace("{} onPacketReceived: Packet punted from table {}", LOGGING_PREFIX, tableId);
    byte[] data = notification.getPayload();
    if (notification.getMatch() == null || notification.getMatch().getMetadata() == null) {
        LOG.error("{} onPacketReceived: Received from table {} where the match or metadata are null", LOGGING_PREFIX, tableId);
        return;
    }
    BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
    Ethernet res = new Ethernet();
    if (tableId == NwConstants.L3_SUBNET_ROUTE_TABLE) {
        LOG.trace("{} onPacketReceived: Some packet received as {}", LOGGING_PREFIX, notification);
        try {
            res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.error("{} onPacketReceived: Failed to decode Packet ", LOGGING_PREFIX, e);
            VpnManagerCounters.subnet_route_packet_failed.inc();
            return;
        }
        try {
            Packet pkt = res.getPayload();
            if (pkt instanceof IPv4) {
                IPv4 ipv4 = (IPv4) pkt;
                byte[] srcIp = Ints.toByteArray(ipv4.getSourceAddress());
                byte[] dstIp = Ints.toByteArray(ipv4.getDestinationAddress());
                String dstIpStr = NWUtil.toStringIpAddress(dstIp);
                String srcIpStr = NWUtil.toStringIpAddress(srcIp);
                // It is an ARP request on a configured VPN. So we must
                // attempt to respond.
                long vpnId = MetaDataUtil.getVpnIdFromMetadata(metadata);
                LOG.info("{} onPacketReceived: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and vpnId {}", LOGGING_PREFIX, srcIpStr, dstIpStr, vpnId);
                Optional<VpnIds> vpnIdsOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId));
                if (!vpnIdsOptional.isPresent()) {
                    // Donot trigger subnetroute logic for packets from
                    // unknown VPNs
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: Ignoring IPv4 packet with destination Ip {} and source Ip {}" + " as it came on unknown VPN with ID {}", LOGGING_PREFIX, dstIpStr, srcIpStr, vpnId);
                    return;
                }
                String vpnIdVpnInstanceName = vpnIdsOptional.get().getVpnInstanceName();
                if (VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source IP {} vpnId {} " + "is a valid Neutron port,ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (VpnUtil.getLearntVpnVipToPort(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
                    VpnManagerCounters.subnet_route_packet_ignored.inc();
                    LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source Ip {} vpnId {}" + " is an already discovered IPAddress, ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
                if (elanTag == 0L) {
                    VpnManagerCounters.subnet_route_packet_failed.inc();
                    LOG.error("{} onPacketReceived: elanTag value from metadata found to be 0, for IPv4 " + " Packet received with Target IP {} src Ip {} vpnId {}", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
                    return;
                }
                if (!vpnIdsOptional.get().isExternalVpn()) {
                    handleInternalVpnSubnetRoutePacket(metadata, dstIp, srcIpStr, dstIpStr, ipv4.getDestinationAddress(), vpnIdVpnInstanceName, elanTag);
                    return;
                }
                byte[] srcMac = res.getSourceMACAddress();
                handleBgpVpnSubnetRoute(ipv4, srcMac, dstIp, dstIpStr, srcIpStr, elanTag);
            }
        } catch (UnknownHostException | InterruptedException | ExecutionException ex) {
            // Failed to handle packet
            VpnManagerCounters.subnet_route_packet_failed.inc();
            LOG.error("{} onPacketReceived: Failed to handle subnetroute packet.", LOGGING_PREFIX, ex);
        }
        return;
    }
// All Arp responses learning for invisble IPs is handled by
// ArpNotificationHandler
}
Also used : Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) UnknownHostException(java.net.UnknownHostException) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) BigInteger(java.math.BigInteger) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) ExecutionException(java.util.concurrent.ExecutionException)

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