/** * Extracts context information from ARP packets. * * @param eth input Ethernet frame that is thought to be ARP * @param inPort in port * @param actions actions to take * @return MessageContext object if the packet was a valid ARP packet, * otherwise null */ private static NeighbourMessageContext createArpContext(Ethernet eth, ConnectPoint inPort, NeighbourMessageActions actions) { if (eth.getEtherType() != Ethernet.TYPE_ARP) { return null; } ARP arp = (ARP) eth.getPayload(); IpAddress target = Ip4Address.valueOf(arp.getTargetProtocolAddress()); IpAddress sender = Ip4Address.valueOf(arp.getSenderProtocolAddress()); NeighbourMessageType type; if (arp.getOpCode() == ARP.OP_REQUEST) { type = NeighbourMessageType.REQUEST; } else if (arp.getOpCode() == ARP.OP_REPLY) { type = NeighbourMessageType.REPLY; } else { return null; } return new DefaultNeighbourMessageContext(actions, eth, inPort, NeighbourProtocol.ARP, type, target, sender); }
@Override public void process(PacketContext context) { InboundPacket pkt = context.inPacket(); ConnectPoint connectPoint = pkt.receivedFrom(); DeviceId deviceId = connectPoint.deviceId(); Ethernet ethPkt = pkt.parsed(); if (ethPkt == null) { return; } if (ethPkt.getEtherType() == Ethernet.TYPE_ARP) { ARP arpPacket = (ARP) ethPkt.getPayload(); if ((arpPacket.getOpCode() == ARP.OP_REQUEST)) { arprequestProcess(arpPacket, deviceId); } else if (arpPacket.getOpCode() == ARP.OP_REPLY) { arpresponceProcess(arpPacket, deviceId); } } else if (ethPkt.getEtherType() == Ethernet.TYPE_IPV4) { if (ethPkt.getDestinationMAC().isMulticast()) { return; } IPv4 ip = (IPv4) ethPkt.getPayload(); upStreamPacketProcessor(ip, deviceId); } else { return; } }
ARP arp = (ARP) ethRequest.getPayload(); if (arp.getOpCode() != ARP.OP_REQUEST) { return;