@Override public Optional<MatchBuilder> process(@Nonnull ArpThaCase source, MatchResponseConvertorData data, ConvertorExecutor convertorExecutor) { final MatchBuilder matchBuilder = data.getMatchBuilder(); final ArpMatchBuilder arpMatchBuilder = data.getArpMatchBuilder(); ArpTha arpTha = source.getArpTha(); MacAddress macAddress = arpTha.getMacAddress(); if (macAddress != null) { ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder(); arpTargetHardwareAddressBuilder.setAddress(macAddress); byte[] mask = arpTha.getMask(); if (mask != null) { arpTargetHardwareAddressBuilder.setMask(new MacAddress(ByteBufUtils .macAddressToString(mask))); } arpMatchBuilder.setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder.build()); matchBuilder.setLayer3Match(arpMatchBuilder.build()); } return Optional.of(matchBuilder); } }
/** * Creates {@link ArpMatch} containing Reply ARP operation, THA and TPA for the given target * address and SPA for the given sender protocol address */ public static ArpMatch createArpMatch(ArpMessageAddress targetAddress, Ipv4Address senderProtocolAddress) { return new ArpMatchBuilder().setArpOp(ArpOperation.REPLY.intValue()) .setArpTargetHardwareAddress( new ArpTargetHardwareAddressBuilder().setAddress(targetAddress.getHardwareAddress()).build()) .setArpTargetTransportAddress(new Ipv4Prefix(targetAddress.getProtocolAddress().getValue() + HOST_MASK)) .setArpSourceTransportAddress(new Ipv4Prefix(senderProtocolAddress.getValue() + HOST_MASK)) .build(); }
/** * Builds the arp match with src and destintion mac address. * @param matchBuilder the match builder * @param srcMac the src mac address , will not be added to match if null. * @param dstMac the destination mac address, will not be added to match if null. * @return the match builder with the matches */ public static MatchBuilder addArpMacMatch(MatchBuilder matchBuilder, String srcMac, String dstMac) { ArpMatchBuilder arpMatch = new ArpMatchBuilder(); if (null != srcMac) { ArpSourceHardwareAddressBuilder arpSrc = new ArpSourceHardwareAddressBuilder(); arpSrc.setAddress(new MacAddress(srcMac)); arpMatch.setArpSourceHardwareAddress(arpSrc.build()); } if (null != dstMac) { ArpTargetHardwareAddressBuilder arpDst = new ArpTargetHardwareAddressBuilder(); arpDst.setAddress(new MacAddress(dstMac)); arpMatch.setArpTargetHardwareAddress(arpDst.build()); } matchBuilder.setLayer3Match(arpMatch.build()); return matchBuilder; }
arpTha.setMask(new MacAddress(ByteUtil.bytesToHexstring(arpThaCase.getArpTha().getMask(), ":"))); arpMatch.setArpTargetHardwareAddress(arpTha.build());
arpmatch.setArpOp(2); arpmatch1.setArpSourceHardwareAddress(arpsrc.build()); arpmatch2.setArpTargetHardwareAddress(arpdst.build()); arpmatch3.setArpSourceTransportAddress(srciparp); arpmatch4.setArpTargetTransportAddress(dstiparp);
arpmatch.setArpOp(2); arpmatch.setArpSourceHardwareAddress(arpsrc.build()); arpmatch.setArpTargetHardwareAddress(arpdst.build()); arpmatch.setArpSourceTransportAddress(srcip); arpmatch.setArpTargetTransportAddress(dstip);