Search in sources :

Example 1 with ARP

use of org.opendaylight.genius.mdsalutil.packet.ARP in project netvirt by opendaylight.

the class ElanUtils method getSourceIpAddress.

public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
    Optional<IpAddress> srcIpAddress = Optional.absent();
    if (ethernet.getPayload() == null) {
        return srcIpAddress;
    }
    byte[] ipAddrBytes = null;
    if (ethernet.getPayload() instanceof IPv4) {
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
    } else if (ethernet.getPayload() instanceof ARP) {
        ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
    }
    if (ipAddrBytes != null) {
        String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
        return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
    }
    return srcIpAddress;
}
Also used : IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 2 with ARP

use of org.opendaylight.genius.mdsalutil.packet.ARP in project genius by opendaylight.

the class ArpPacketUtil method createARPPacket.

private static ARP createARPPacket(short opCode, byte[] senderMacAddress, byte[] senderIP, byte[] targetMacAddress, byte[] targetIP) {
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolType(EtherTypes.IPv4.shortValue());
    arp.setHardwareAddressLength((byte) 6);
    arp.setProtocolAddressLength((byte) 4);
    arp.setOpCode(opCode);
    arp.setSenderHardwareAddress(senderMacAddress);
    arp.setSenderProtocolAddress(senderIP);
    arp.setTargetHardwareAddress(targetMacAddress);
    arp.setTargetProtocolAddress(targetIP);
    return arp;
}
Also used : ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 3 with ARP

use of org.opendaylight.genius.mdsalutil.packet.ARP in project genius by opendaylight.

the class ArpUtilImpl method onPacketReceived.

@Override
public void onPacketReceived(PacketReceived packetReceived) {
    Class<? extends PacketInReason> pktInReason = packetReceived.getPacketInReason();
    LOG.trace("Packet Received {}", packetReceived);
    if (pktInReason == SendToController.class) {
        try {
            int tableId = packetReceived.getTableId().getValue();
            byte[] data = packetReceived.getPayload();
            Ethernet ethernet = new Ethernet();
            ethernet.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
            if (ethernet.getEtherType() != ArpConstants.ETH_TYPE_ARP) {
                return;
            }
            Packet pkt = ethernet.getPayload();
            ARP arp = (ARP) pkt;
            InetAddress srcInetAddr = InetAddress.getByAddress(arp.getSenderProtocolAddress());
            InetAddress dstInetAddr = InetAddress.getByAddress(arp.getTargetProtocolAddress());
            byte[] srcMac = ethernet.getSourceMACAddress();
            byte[] dstMac = ethernet.getDestinationMACAddress();
            Metadata metadata = packetReceived.getMatch().getMetadata();
            String interfaceName = getInterfaceName(metadata);
            checkAndFireMacChangedNotification(interfaceName, srcInetAddr, srcMac);
            macsDB.put(interfaceName + "-" + srcInetAddr.getHostAddress(), NWUtil.toStringMacAddress(srcMac));
            if (arp.getOpCode() == ArpConstants.ARP_REQUEST_OP) {
                fireArpReqRecvdNotification(interfaceName, srcInetAddr, srcMac, dstInetAddr, tableId, metadata.getMetadata());
            } else {
                fireArpRespRecvdNotification(interfaceName, srcInetAddr, srcMac, tableId, metadata.getMetadata(), dstInetAddr, dstMac);
            }
            if (macAddrs.get(srcInetAddr.getHostAddress()) != null) {
                threadPool.execute(new MacResponderTask(arp));
            }
        } catch (PacketException | UnknownHostException | InterruptedException | ExecutionException e) {
            LOG.trace("Failed to decode packet", e);
        }
    }
}
Also used : Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) UnknownHostException(java.net.UnknownHostException) Metadata(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) ExecutionException(java.util.concurrent.ExecutionException) InetAddress(java.net.InetAddress) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 4 with ARP

use of org.opendaylight.genius.mdsalutil.packet.ARP in project netvirt by opendaylight.

the class ArpUtils method createARPPacket.

private static byte[] createARPPacket(short opCode, byte[] senderMacAddress, byte[] senderIP, byte[] targetMacAddress, byte[] targetIP) {
    ARP arp = new ARP();
    byte[] rawArpPkt = null;
    try {
        arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
        arp.setProtocolType(EtherTypes.IPv4.shortValue());
        arp.setHardwareAddressLength((byte) 6);
        arp.setProtocolAddressLength((byte) 4);
        arp.setOpCode(opCode);
        arp.setSenderHardwareAddress(senderMacAddress);
        arp.setSenderProtocolAddress(senderIP);
        arp.setTargetHardwareAddress(targetMacAddress);
        arp.setTargetProtocolAddress(targetIP);
        rawArpPkt = arp.serialize();
    } catch (PacketException ex) {
        LOG.error("VPNUtil:  Serialized ARP packet with senderIp {} targetIP {} exception ", senderIP, targetIP, ex);
    }
    return rawArpPkt;
}
Also used : PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 5 with ARP

use of org.opendaylight.genius.mdsalutil.packet.ARP in project genius by opendaylight.

the class ArpPacketUtil method getPayload.

static byte[] getPayload(short opCode, byte[] senderMacAddress, byte[] senderIP, byte[] targetMacAddress, byte[] targetIP) throws PacketException {
    ARP arp = createARPPacket(opCode, senderMacAddress, senderIP, targetMacAddress, targetIP);
    Ethernet ethernet = createEthernetPacket(senderMacAddress, targetMacAddress, arp);
    return ethernet.serialize();
}
Also used : Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Aggregations

ARP (org.opendaylight.genius.mdsalutil.packet.ARP)5 Ethernet (org.opendaylight.genius.mdsalutil.packet.Ethernet)2 PacketException (org.opendaylight.openflowplugin.libraries.liblldp.PacketException)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 IPv4 (org.opendaylight.genius.mdsalutil.packet.IPv4)1 Packet (org.opendaylight.openflowplugin.libraries.liblldp.Packet)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 Metadata (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata)1