Search in sources :

Example 16 with PacketReceived

use of org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived in project genius by opendaylight.

the class AlivenessProtocolHandlerARP method handlePacketIn.

@Override
public String handlePacketIn(ARP packet, PacketReceived packetReceived) {
    short tableId = packetReceived.getTableId().getValue();
    int arpType = packet.getOpCode();
    if (LOG.isTraceEnabled()) {
        LOG.trace("packet: {}, tableId {}, arpType {}", packetReceived, tableId, arpType);
    }
    if (arpType == ARP.REPLY) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("packet: {}", packetReceived);
        }
        BigInteger metadata = packetReceived.getMatch().getMetadata().getMetadata();
        int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
        String interfaceName = null;
        try {
            GetInterfaceFromIfIndexInput input = new GetInterfaceFromIfIndexInputBuilder().setIfIndex(portTag).build();
            Future<RpcResult<GetInterfaceFromIfIndexOutput>> output = interfaceManager.getInterfaceFromIfIndex(input);
            RpcResult<GetInterfaceFromIfIndexOutput> result = output.get();
            if (result.isSuccessful()) {
                GetInterfaceFromIfIndexOutput ifIndexOutput = result.getResult();
                interfaceName = ifIndexOutput.getInterfaceName();
            } else {
                LOG.warn("RPC call to get interface name for if index {} failed with errors {}", portTag, result.getErrors());
                return null;
            }
        } catch (InterruptedException | ExecutionException e) {
            LOG.warn("Error retrieving interface Name for tag {}", portTag, e);
        }
        if (!Strings.isNullOrEmpty(interfaceName)) {
            String sourceIp = NWUtil.toStringIpAddress(packet.getSenderProtocolAddress());
            String targetIp = NWUtil.toStringIpAddress(packet.getTargetProtocolAddress());
            return getMonitoringKey(interfaceName, targetIp, sourceIp);
        } else {
            LOG.debug("No interface associated with tag {} to interpret the received ARP Reply", portTag);
        }
    }
    return null;
}
Also used : GetInterfaceFromIfIndexInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetInterfaceFromIfIndexInput) GetInterfaceFromIfIndexInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetInterfaceFromIfIndexInputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) BigInteger(java.math.BigInteger) ExecutionException(java.util.concurrent.ExecutionException) GetInterfaceFromIfIndexOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetInterfaceFromIfIndexOutput)

Aggregations

BigInteger (java.math.BigInteger)5 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)5 PacketReceived (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived)5 Ethernet (org.opendaylight.genius.mdsalutil.packet.Ethernet)4 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)4 PacketReceivedBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder)4 ExecutionException (java.util.concurrent.ExecutionException)3 Test (org.junit.Test)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 UnknownHostException (java.net.UnknownHostException)2 InterfaceInfo (org.opendaylight.genius.interfacemanager.globals.InterfaceInfo)2 Packet (org.opendaylight.openflowplugin.libraries.liblldp.Packet)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)2 PhysAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)2 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)2 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)2 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)2 TableId (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId)2 Optional (com.google.common.base.Optional)1