/** * @return the opCode */ public ArpOpcode getOpCode() { return opCode; }
/** * @param opCode the opCode to set */ public ARP setOpCode(ArpOpcode opCode) { this.opCode = opCode; return this; }
@SuppressWarnings("unchecked") @Test public void iterateArpFields() { MacAddress macSrc = MacAddress.of("00:01:02:03:04:05"); MacAddress macDst = MacAddress.of("01:01:02:02:03:03"); IPv4Address ipSrc = IPv4Address.of("10.192.20.1"); IPv4Address ipDst = IPv4Address.of("10.192.20.2"); OFVersion version = factory.getVersion(); boolean supportsArpHardwareAddress = (version != OFVersion.OF_10) && (version != OFVersion.OF_11) && (version != OFVersion.OF_12); int matchFieldCount = 4; Match.Builder builder = factory.buildMatch(); builder.setExact(MatchField.ETH_TYPE, EthType.ARP) .setExact(MatchField.ARP_OP, ArpOpcode.REPLY) .setExact(MatchField.ARP_SPA, ipSrc) .setExact(MatchField.ARP_TPA, ipDst); if (supportsArpHardwareAddress) { builder.setExact(MatchField.ARP_SHA, macSrc); builder.setExact(MatchField.ARP_THA, macDst); matchFieldCount += 2; } Match match = builder.build(); assertThat(Iterables.size(match.getMatchFields()), is(matchFieldCount)); for (MatchField<?> matchField: match.getMatchFields()) { switch (matchField.id) { case ETH_TYPE: EthType ethType = match.get((MatchField<EthType>) matchField); assertThat(ethType, is(EthType.ARP)); break; case ARP_OP: ArpOpcode opcode = match.get((MatchField<ArpOpcode>) matchField); assertThat(opcode, is(ArpOpcode.REPLY)); break; case ARP_SHA: MacAddress mac = match.get((MatchField<MacAddress>) matchField); assertThat(mac, is(macSrc)); break; case ARP_THA: mac = match.get((MatchField<MacAddress>) matchField); assertThat(mac, is(macDst)); break; case ARP_SPA: IPv4Address ip = match.get((MatchField<IPv4Address>) matchField); assertThat(ip, is(ipSrc)); break; case ARP_TPA: ip = match.get((MatchField<IPv4Address>) matchField); assertThat(ip, is(ipDst)); break; default: fail("Unexpected match field returned from iterator"); } } }