@VisibleForTesting static void setSrcPort(PacketHeaderConstraints constraints, Flow.Builder builder) { IntegerSpace srcPorts = constraints.getSrcPorts(); checkArgument( srcPorts == null || srcPorts.isSingleton(), "Cannot construct flow with multiple source ports"); if (srcPorts != null) { builder.setSrcPort(srcPorts.singletonValue()); } }
fb.setSrcIp(srcAddress); fb.setDstIp(dstAddress); fb.setSrcPort(NamedPort.EPHEMERAL_LOWEST.number()); fb.setDstPort(NamedPort.BGP.number()); Flow forwardFlow = fb.build(); fb.setSrcIp(forwardFlow.getDstIp()); fb.setDstIp(forwardFlow.getSrcIp()); fb.setSrcPort(forwardFlow.getDstPort()); fb.setDstPort(forwardFlow.getSrcPort()); Flow backwardFlow = fb.build();
/** * Creates a return {@link Flow} for the input {@param forwardFlow}. Swaps the source/destination * IPs/ports, and sets the ingress node/vrf/interface. */ static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .build(); }
b.setSrcIp(srcIp); b.setDstIp(dstIp); b.setSrcPort(srcPort); b.setDstPort(dstPort); b.setIpProtocol(ipProtocol);
/** * Generate a flow builder given some set of packet header constraints. * * @param constraints {@link PacketHeaderConstraints} * @throws IllegalArgumentException if the {@code constraints} cannot be resolved to a single * value. */ private Flow.Builder headerConstraintsToFlow( PacketHeaderConstraints constraints, Location srcLocation) throws IllegalArgumentException { Flow.Builder builder = PacketHeaderConstraintsUtil.toFlow(constraints); // Extract and source IP from header constraints, setSrcIp(constraints, srcLocation, builder); setDstIp(constraints, builder); // Set defaults for protocol, and ports and packet lengths: if (builder.getIpProtocol() == null || builder.getIpProtocol() == IpProtocol.IP) { builder.setIpProtocol(IpProtocol.UDP); } if (builder.getDstPort() == 0) { builder.setDstPort(TRACEROUTE_PORT); } if (builder.getSrcPort() == 0) { builder.setSrcPort(NamedPort.EPHEMERAL_LOWEST.number()); } return builder; }
public Flow.Builder getFlowFromAssignment(BDD satAssignment) { checkArgument(isAssignment(satAssignment)); Flow.Builder fb = Flow.builder(); fb.setDstIp(Ip.create(_dstIp.satAssignmentToLong(satAssignment))); fb.setSrcIp(Ip.create(_srcIp.satAssignmentToLong(satAssignment))); fb.setDstPort(_dstPort.satAssignmentToLong(satAssignment).intValue()); fb.setSrcPort(_srcPort.satAssignmentToLong(satAssignment).intValue()); fb.setIpProtocol( IpProtocol.fromNumber(_ipProtocol.satAssignmentToLong(satAssignment).intValue())); fb.setIcmpCode(_icmpCode.satAssignmentToLong(satAssignment).intValue()); fb.setIcmpType(_icmpType.satAssignmentToLong(satAssignment).intValue()); fb.setTcpFlagsAck(_tcpAck.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsCwr(_tcpCwr.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsEce(_tcpEce.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsFin(_tcpFin.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsPsh(_tcpPsh.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsRst(_tcpRst.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsSyn(_tcpSyn.and(satAssignment).isZero() ? 0 : 1); fb.setTcpFlagsUrg(_tcpUrg.and(satAssignment).isZero() ? 0 : 1); fb.setDscp(_dscp.satAssignmentToLong(satAssignment).intValue()); fb.setEcn(_ecn.satAssignmentToLong(satAssignment).intValue()); fb.setFragmentOffset(_fragmentOffset.satAssignmentToLong(satAssignment).intValue()); fb.setState(FlowState.fromNum(_state.satAssignmentToLong(satAssignment).intValue())); return fb; }
/** * Generate a flow builder given some set of packet header constraints. * * @param constraints {@link PacketHeaderConstraints} * @throws IllegalArgumentException if the {@code constraints} cannot be resolved to a single * value. */ private Flow.Builder headerConstraintsToFlow( PacketHeaderConstraints constraints, Location srcLocation) throws IllegalArgumentException { Flow.Builder builder = PacketHeaderConstraintsUtil.toFlow(constraints); setSrcIp(constraints, srcLocation, builder); setDstIp(constraints, builder); // Set defaults for protocol, and ports and packet lengths: if (builder.getIpProtocol() == null || builder.getIpProtocol() == IpProtocol.IP) { builder.setIpProtocol(IpProtocol.TCP); } if (builder.getDstPort() == 0) { builder.setDstPort(NamedPort.HTTP.number()); } if (builder.getSrcPort() == 0) { builder.setSrcPort(NamedPort.EPHEMERAL_LOWEST.number()); } return builder; }