@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(); }
/** * Set ARP_THA Instructions * @param ib Map InstructionBuilder * @param macdst the macdst * @return instructionbuilder with new attributes */ public static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) { List<Action> actionList = Lists.newArrayList(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); ArpMatchBuilder arpmatch = new ArpMatchBuilder(); ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder(); arpdst.setAddress(macdst); setFieldBuilder.setLayer3Match(arpmatch.build()); ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build()); ab.setOrder(0); ab.setKey(new ActionKey(0)); actionList.add(ab.build()); ApplyActionsBuilder aab = new ApplyActionsBuilder(); aab.setAction(actionList); // Wrap our Apply Action in an Instruction ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
/** * Set ARP_THA Instructions * @param ib Map InstructionBuilder * @param macdst the macdst * @return instructionbuilder with new attributes */ public static InstructionBuilder createDstArpMacInstructions(InstructionBuilder ib, MacAddress macdst) { List<Action> actionList = new ArrayList<>(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); ArpMatchBuilder arpmatch = new ArpMatchBuilder(); ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder(); arpdst.setAddress(macdst); setFieldBuilder.setLayer3Match(arpmatch.build()); ab.setAction(new SetFieldCaseBuilder().setSetField(setFieldBuilder.build()).build()); ab.setOrder(0); ab.setKey(new ActionKey(0)); actionList.add(ab.build()); ApplyActionsBuilder aab = new ApplyActionsBuilder(); aab.setAction(actionList); // Wrap our Apply Action in an Instruction ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
/** * 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; }
} else if (field.equals(ArpTha.class)) { ArpThaCase arpThaCase = ((ArpThaCase) entry.getMatchEntryValue()); ArpTargetHardwareAddressBuilder arpTha = new ArpTargetHardwareAddressBuilder(); arpTha.setAddress(arpThaCase.getArpTha().getMacAddress()); if (entry.isHasMask()) {
private static Layer3Match setLayer3MatchAsArp(final Match sourceMatch, final Inet4Address inetSourceAddress, final Inet4Address inetDestAddress) { String inetSourceAddressStr = InetAddresses .toAddrString(inetSourceAddress); Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(inetSourceAddressStr + "/32"); String inetDestAddressValue = InetAddresses .toAddrString(inetDestAddress); Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(inetDestAddressValue + "/32"); ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder(); arpMatchBuilder.setArpSourceTransportAddress(ipv4SourcePrefix); arpMatchBuilder.setArpTargetTransportAddress(ipv4DestPrefix); ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder(); arpSourceHardwareAddressBuilder .setAddress(ethernetSourceAddress(sourceMatch)); arpMatchBuilder .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder .build()); ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder(); arpTargetHardwareAddressBuilder .setAddress(ethernetDestAddress(sourceMatch)); arpMatchBuilder .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder .build()); return arpMatchBuilder.build(); }
final ArpSourceHardwareAddressBuilder arpsrc = new ArpSourceHardwareAddressBuilder(); arpsrc.setAddress(macsrc); final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder(); arpdst.setAddress(macdest); arpmatch.setArpOp(2);
arpsrc.setAddress(macsrc); arpsrc.setMask(new MacAddress("ff:ff:ff:00:00:00")); final ArpTargetHardwareAddressBuilder arpdst = new ArpTargetHardwareAddressBuilder(); arpdst.setAddress(macdest); arpdst.setMask(new MacAddress("ff:ff:00:00:00:00"));