Search in sources :

Example 6 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received 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 7 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received 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 8 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received 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)

Example 9 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class ArpMonitoringHandler method remove.

@Override
protected void remove(InstanceIdentifier<LearntVpnVipToPort> key, LearntVpnVipToPort value) {
    runOnlyInOwnerNode("ArpMonitoringHandler: remove event", () -> {
        try {
            InetAddress srcInetAddr = InetAddress.getByName(value.getPortFixedip());
            if (value.getMacAddress() == null) {
                LOG.warn("The mac address received is null for LearntVpnVipToPort {}, ignoring the DTCN", value);
                return;
            }
            String vpnName = value.getVpnName();
            String learntIp = srcInetAddr.getHostAddress();
            LearntVpnVipToPort vpnVipToPort = VpnUtil.getLearntVpnVipToPort(dataBroker, vpnName, learntIp);
            if (vpnVipToPort != null && !vpnVipToPort.getCreationTime().equals(value.getCreationTime())) {
                LOG.warn("The MIP {} over vpn {} has been learnt again and processed. " + "Ignoring this remove event.", learntIp, vpnName);
                return;
            }
            MacAddress srcMacAddress = MacAddress.getDefaultInstance(value.getMacAddress());
            String interfaceName = value.getPortName();
            MacEntry macEntry = new MacEntry(vpnName, srcMacAddress, srcInetAddr, interfaceName, value.getCreationTime());
            jobCoordinator.enqueueJob(buildJobKey(srcInetAddr.toString(), vpnName), new ArpMonitorStopTask(macEntry, dataBroker, alivenessManager));
        } catch (UnknownHostException e) {
            LOG.error("Error in deserializing packet {} with exception", value, e);
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) InetAddress(java.net.InetAddress)

Example 10 with Received

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180321.network.instances.network.instance.protocols.protocol.bgp.neighbors.neighbor.state.messages.Received in project netvirt by opendaylight.

the class DpnInVpnChangeListener method onRemoveDpnEvent.

@Override
public void onRemoveDpnEvent(RemoveDpnEvent notification) {
    RemoveEventData eventData = notification.getRemoveEventData();
    final String rd = eventData.getRd();
    final String vpnName = eventData.getVpnName();
    BigInteger dpnId = eventData.getDpnId();
    LOG.trace("Remove Dpn Event notification received for rd {} VpnName {} DpnId {}", rd, vpnName, dpnId);
    synchronized (vpnName.intern()) {
        InstanceIdentifier<VpnInstanceOpDataEntry> id = VpnUtil.getVpnInstanceOpDataIdentifier(rd);
        Optional<VpnInstanceOpDataEntry> vpnOpValue = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
        if (vpnOpValue.isPresent()) {
            VpnInstanceOpDataEntry vpnInstOpData = vpnOpValue.get();
            List<VpnToDpnList> vpnToDpnList = vpnInstOpData.getVpnToDpnList();
            boolean flushDpnsOnVpn = true;
            for (VpnToDpnList dpn : vpnToDpnList) {
                if (dpn.getDpnState() == VpnToDpnList.DpnState.Active) {
                    flushDpnsOnVpn = false;
                    break;
                }
            }
            if (flushDpnsOnVpn) {
                WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
                deleteDpn(vpnToDpnList, rd, writeTxn);
                try {
                    writeTxn.submit().get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error removing dpnToVpnList for vpn {} ", vpnName);
                    throw new RuntimeException(e.getMessage(), e);
                }
            }
        }
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) RemoveEventData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.remove.dpn.event.RemoveEventData) VpnToDpnList(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.VpnToDpnList) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BigInteger (java.math.BigInteger)26 ArrayList (java.util.ArrayList)20 ExecutionException (java.util.concurrent.ExecutionException)16 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)13 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)13 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 List (java.util.List)10 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)9 UnknownHostException (java.net.UnknownHostException)8 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)8 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)8 Optional (com.google.common.base.Optional)7 Test (org.junit.Test)7 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)7 Collections (java.util.Collections)6 TunnelTypeVxlan (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan)6 FutureCallback (com.google.common.util.concurrent.FutureCallback)5 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)5 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)5