/** * Create an {@link UdpMatchBuilder} instance. * * @param umatch An {@link UdpMatchBuilder} instance. * {@code null} must be specified on the first call. * @return If {@code umatch} is {@code null}, this method creates a new * {@link UdpMatchBuilder} instance and returns it. * Otherwise a {@link UdpMatchBuilder} instance passed to * {@code umatch} is returned. */ private UdpMatchBuilder create(UdpMatchBuilder umatch) { return (umatch == null) ? new UdpMatchBuilder() : umatch; }
private Layer4Match resolveL4Match(Map<String, ParameterValue> params) { Long ipProto = IpProtoClassifier.getIpProtoValue(params); if (ipProto == null) { throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + " is missing."); } if (IpProtoClassifierDefinition.UDP_VALUE.equals(ipProto)) { return new UdpMatchBuilder().build(); } else if (IpProtoClassifierDefinition.TCP_VALUE.equals(ipProto)) { return new TcpMatchBuilder().build(); } else if (IpProtoClassifierDefinition.SCTP_VALUE.equals(ipProto)) { return new SctpMatchBuilder().build(); } throw new IllegalArgumentException("Parameter " + IpProtoClassifierDefinition.PROTO_PARAM + ": value " + ipProto + " is " + Classifier.MSG_NOT_SUPPORTED); }
private Set<UdpMatch> createUdpMatches(UdpMatch udpMatch, Set<Long> sPorts, Set<Long> dPorts) { Set<UdpMatch> udpMatches = new HashSet<>(); if (!sPorts.isEmpty() && dPorts.isEmpty()) { for (Long srcPort : sPorts) { equalOrNotSetValidation(udpMatch.getUdpSourcePort(), srcPort.longValue()); udpMatches .add(new UdpMatchBuilder(udpMatch).setUdpSourcePort(new PortNumber(srcPort.intValue())).build()); } } else if (sPorts.isEmpty() && !dPorts.isEmpty()) { for (Long dstPort : dPorts) { equalOrNotSetValidation(udpMatch.getUdpDestinationPort(), dstPort.longValue()); udpMatches.add(new UdpMatchBuilder(udpMatch).setUdpDestinationPort(new PortNumber(dstPort.intValue())) .build()); } } else if (!sPorts.isEmpty() && !dPorts.isEmpty()) { for (Long srcPort : sPorts) { for (Long dstPort : dPorts) { equalOrNotSetValidation(udpMatch.getUdpSourcePort(), srcPort.longValue()); equalOrNotSetValidation(udpMatch.getUdpDestinationPort(), dstPort.longValue()); udpMatches.add(new UdpMatchBuilder(udpMatch).setUdpSourcePort(new PortNumber(srcPort.intValue())) .setUdpDestinationPort(new PortNumber(dstPort.intValue())) .build()); } } } return udpMatches; }
public static void addMatchDstUdpPort(MatchBuilder match, int portNum) { PortNumber port = new PortNumber(portNum); UdpMatchBuilder udpMatch = new UdpMatchBuilder(); udpMatch.setUdpDestinationPort(port); match.setLayer4Match(udpMatch.build()); }
public static void addMatchSrcUdpPort(MatchBuilder match, int portNum) { PortNumber port = new PortNumber(portNum); UdpMatchBuilder udpMatch = new UdpMatchBuilder(); udpMatch.setUdpSourcePort(port); match.setLayer4Match(udpMatch.build()); }
private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) { UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder(); Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC); Integer destinationPort = transportPort(sourceMatch, MatchType.TP_DST); if (sourcePort != null) { udpMatchBuilder.setUdpSourcePort(new PortNumber(sourcePort)); } if (destinationPort != null) { udpMatchBuilder.setUdpDestinationPort(new PortNumber( destinationPort)); } if(sourcePort != null || destinationPort != null) { return udpMatchBuilder.build(); } return null; }
/** * Create Set Destination UDP Port Instruction * * @param ib Map InstructionBuilder without any instructions * @param udpport Integer representing a destination UDP port * @return ib Map InstructionBuilder with instructions */ public static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) { List<Action> actionList = new ArrayList<>(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); // Build the Destination TCP Port PortNumber udpdstport = new PortNumber(udpport); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpDestinationPort(udpdstport); setFieldBuilder.setLayer4Match(udpmatch.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); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
final UdpMatchBuilder udpmatch = new UdpMatchBuilder(); final UdpMatchBuilder udpmatch1 = new UdpMatchBuilder(); udpmatch.setUdpDestinationPort(udpdstport); udpmatch1.setUdpSourcePort(udpsrcport);
/** * Create Set Source UDP Port Instruction * * @param ib Map InstructionBuilder without any instructions * @param udpport Integer representing a source UDP port * @return ib Map InstructionBuilder with instructions */ public static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) { List<Action> actionList = Lists.newArrayList(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); // Build the Destination TCP Port PortNumber udpsrcport = new PortNumber(udpport); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(udpsrcport); setFieldBuilder.setLayer4Match(udpmatch.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); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
/** * Create Set Source UDP Port Instruction * * @param ib Map InstructionBuilder without any instructions * @param udpport Integer representing a source UDP port * @return ib Map InstructionBuilder with instructions */ public static InstructionBuilder createSetSrcUDPPort(InstructionBuilder ib, PortNumber udpport) { List<Action> actionList = new ArrayList<>(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); // Build the Destination TCP Port PortNumber udpsrcport = new PortNumber(udpport); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(udpsrcport); setFieldBuilder.setLayer4Match(udpmatch.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); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
/** * Create Set Destination UDP Port Instruction * * @param ib Map InstructionBuilder without any instructions * @param udpport Integer representing a destination UDP port * @return ib Map InstructionBuilder with instructions */ public static InstructionBuilder createSetDstUDPPort(InstructionBuilder ib, PortNumber udpport) { List<Action> actionList = Lists.newArrayList(); ActionBuilder ab = new ActionBuilder(); SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); // Build the Destination TCP Port PortNumber udpdstport = new PortNumber(udpport); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpDestinationPort(udpdstport); setFieldBuilder.setLayer4Match(udpmatch.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); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); return ib; }
/** * Create Source UDP Port Match * * @param matchBuilder MatchBuilder Object without a match yet * @param udpport Integer representing a source UDP port * @return matchBuilder Map MatchBuilder Object with a match */ public static MatchBuilder createSetSrcUdpMatch(MatchBuilder matchBuilder, PortNumber udpport) { EthernetMatchBuilder ethType = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(IPV4_LONG)); ethType.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethType.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol((short) 17); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(udpport); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Create Destination UDP Port Match * * @param matchBuilder MatchBuilder Object without a match yet * @param udpDstPort Integer representing a destination UDP port * @return matchBuilder Map MatchBuilder Object with a match */ public static MatchBuilder createSetDstUdpMatch(MatchBuilder matchBuilder, PortNumber udpDstPort) { EthernetMatchBuilder ethType = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(IPV4_LONG)); ethType.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethType.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol((short) 17); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpDestinationPort(udpDstPort); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Create Destination UDP Port Match * * @param matchBuilder MatchBuilder Object without a match yet * @param udpDstPort Integer representing a destination UDP port * @return matchBuilder Map MatchBuilder Object with a match */ public static MatchBuilder createSetDstUdpMatch(MatchBuilder matchBuilder, PortNumber udpDstPort) { EthernetMatchBuilder ethType = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(IPV4_LONG)); ethType.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethType.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol((short) 17); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpDestinationPort(udpDstPort); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Create Source UDP Port Match * * @param matchBuilder @param matchbuilder MatchBuilder Object without a match yet * @param udpport Integer representing a source UDP port * @return matchBuilder Map MatchBuilder Object with a match */ public static MatchBuilder createSetSrcUdpMatch(MatchBuilder matchBuilder, PortNumber udpport) { EthernetMatchBuilder ethType = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(IPV4_LONG)); ethType.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethType.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol((short) 17); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(udpport); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Create a DHCP match with port provided. * * @param matchBuilder the match builder * @param srcPort the source port * @param dstPort the destination port * @return the DHCP match */ public static MatchBuilder createDhcpMatch(MatchBuilder matchBuilder, int srcPort, int dstPort) { EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(0x0800L)); ethernetMatch.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol(UDP_SHORT); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(new PortNumber(srcPort)); udpmatch.setUdpDestinationPort(new PortNumber(dstPort)); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Create a DHCP match with port provided. * * @param matchBuilder the match builder * @param srcPort the source port * @param dstPort the destination port * @return the DHCP match */ public static MatchBuilder createDhcpv6Match(MatchBuilder matchBuilder, int srcPort, int dstPort) { EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(0x86DDL)); ethernetMatch.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol(UDP_SHORT); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(new PortNumber(srcPort)); udpmatch.setUdpDestinationPort(new PortNumber(dstPort)); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * @return */ private static MatchBuilder createL4UDPMatch() { final MatchBuilder match = new MatchBuilder(); final EthernetMatchBuilder eth = new EthernetMatchBuilder(); final EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(0x0800L)); eth.setEthernetType(ethTypeBuilder.build()); match.setEthernetMatch(eth.build()); final IpMatchBuilder ipmatch = new IpMatchBuilder(); // ipv4 version ipmatch.setIpProtocol((short) 17); match.setIpMatch(ipmatch.build()); final PortNumber srcport = new PortNumber(1325); final PortNumber dstport = new PortNumber(42); final UdpMatchBuilder udpmatch = new UdpMatchBuilder(); // udp match udpmatch.setUdpDestinationPort(dstport); udpmatch.setUdpSourcePort(srcport); match.setLayer4Match(udpmatch.build()); return match; }
/** * Creates DHCP server packet match with DHCP mac address and port. * * @param matchBuilder the matchbuilder * @param dhcpServerMac MAc address of the DHCP server of the subnet * @param srcPort the source port * @param dstPort the destination port * @return the DHCP server match */ public static MatchBuilder createDhcpServerMatch(MatchBuilder matchBuilder, String dhcpServerMac, int srcPort, int dstPort) { EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(0x0800L)); ethernetMatch.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder(); ethSourceBuilder.setAddress(new MacAddress(dhcpServerMac)); ethernetMatch.setEthernetSource(ethSourceBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol(UDP_SHORT); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(new PortNumber(srcPort)); udpmatch.setUdpDestinationPort(new PortNumber(dstPort)); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }
/** * Creates DHCPv6 server packet match with DHCP mac address and port. * * @param matchBuilder the matchbuilder * @param dhcpServerMac MAc address of the DHCP server of the subnet * @param srcPort the source port * @param dstPort the destination port * @return the DHCP server match */ public static MatchBuilder createDhcpv6ServerMatch(MatchBuilder matchBuilder, String dhcpServerMac, int srcPort, int dstPort) { EthernetMatchBuilder ethernetMatch = new EthernetMatchBuilder(); EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder(); ethTypeBuilder.setType(new EtherType(0x86DDL)); ethernetMatch.setEthernetType(ethTypeBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); EthernetSourceBuilder ethSourceBuilder = new EthernetSourceBuilder(); ethSourceBuilder.setAddress(new MacAddress(dhcpServerMac)); ethernetMatch.setEthernetSource(ethSourceBuilder.build()); matchBuilder.setEthernetMatch(ethernetMatch.build()); IpMatchBuilder ipmatch = new IpMatchBuilder(); ipmatch.setIpProtocol(UDP_SHORT); matchBuilder.setIpMatch(ipmatch.build()); UdpMatchBuilder udpmatch = new UdpMatchBuilder(); udpmatch.setUdpSourcePort(new PortNumber(srcPort)); udpmatch.setUdpDestinationPort(new PortNumber(dstPort)); matchBuilder.setLayer4Match(udpmatch.build()); return matchBuilder; }