@Override @Nonnull public AclLineMatchExpr toAclLineMatchExpr(Map<String, ObjectGroup> objectGroups) { return new MatchHeaderSpace( HeaderSpace.builder() .setDscps(_dscps) .setDstPorts(_dstPortRanges) .setEcns(_ecns) .setIcmpCodes( _icmpCode != null ? ImmutableSet.of(new SubRange(_icmpCode)) : ImmutableSet.of()) .setIcmpTypes( _icmpType != null ? ImmutableSet.of(new SubRange(_icmpType)) : ImmutableSet.of()) .setIpProtocols( _protocol != IpProtocol.IP ? ImmutableSet.of(_protocol) : ImmutableSet.of()) .setSrcPorts(_srcPortRanges) .setStates(_states) .setTcpFlags(_tcpFlags) .build()); }
@Override @Nonnull public AclLineMatchExpr toAclLineMatchExpr(Map<String, ObjectGroup> objectGroups) { return new MatchHeaderSpace(HeaderSpace.builder().setDscps(_dscps).setEcns(_ecns).build()); } }
public Builder toBuilder() { return builder() .setDscps(_dscps) .setDstIps(_dstIps) .setDstPorts(_dstPorts)
public static Optional<HeaderSpace> intersect(HeaderSpace h1, HeaderSpace h2) { checkArgument(isUnconstrained(h1.getSrcOrDstIps())); checkArgument(isUnconstrained(h2.getSrcOrDstIps())); checkArgument(isUnconstrained(h1.getSrcOrDstPorts())); checkArgument(isUnconstrained(h2.getSrcOrDstPorts())); checkArgument(isUnconstrained(h1.getSrcOrDstProtocols())); checkArgument(isUnconstrained(h2.getSrcOrDstProtocols())); try { return Optional.of( HeaderSpace.builder() .setDscps(intersectSimpleSets(h1.getDscps(), h2.getDscps())) .setDstIps(intersection(h1.getDstIps(), h2.getDstIps())) .setDstPorts(intersectSubRangeSets(h1.getDstPorts(), h2.getDstPorts())) .setDstProtocols(intersectSimpleSets(h1.getDstProtocols(), h2.getDstProtocols())) .setIpProtocols(intersectSimpleSets(h1.getIpProtocols(), h2.getIpProtocols())) .setIcmpCodes(intersectSubRangeSets(h1.getIcmpCodes(), h2.getIcmpCodes())) .setIcmpTypes(intersectSubRangeSets(h1.getIcmpTypes(), h2.getIcmpTypes())) .setNotDstIps(AclIpSpace.union(h1.getNotDstIps(), h2.getNotDstIps())) .setNotDstPorts(Sets.union(h1.getNotDstPorts(), h2.getNotDstPorts())) .setNotSrcIps(AclIpSpace.union(h1.getNotSrcIps(), h2.getNotSrcIps())) .setNotSrcPorts(Sets.union(h1.getNotSrcPorts(), h2.getNotSrcPorts())) .setSrcIps(AclIpSpace.intersection(h1.getSrcIps(), h2.getSrcIps())) .setSrcOrDstPorts(intersectSubRangeSets(h1.getSrcOrDstPorts(), h2.getSrcOrDstPorts())) .setSrcPorts(intersectSubRangeSets(h1.getSrcPorts(), h2.getSrcPorts())) .setTcpFlags(intersectTcpFlagMatchConditions(h1.getTcpFlags(), h2.getTcpFlags())) .build()); } catch (NoIntersection e) { return Optional.empty(); } }
/** * Convert packet header constraints to a {@link HeaderSpace.Builder} * * <p><b>Does not resolve/set source and destination IPs</b> */ public static HeaderSpace.Builder toHeaderSpaceBuilder(PacketHeaderConstraints phc) { // Note: headerspace builder does not accept nulls, so we have to convert nulls to empty sets HeaderSpace.Builder builder = HeaderSpace.builder() .setIpProtocols(firstNonNull(phc.resolveIpProtocols(), ImmutableSortedSet.of())) .setSrcPorts(extractSubranges(phc.getSrcPorts())) .setDstPorts(extractSubranges(phc.resolveDstPorts())) .setIcmpCodes(extractSubranges(phc.getIcmpCodes())) .setIcmpTypes(extractSubranges(phc.getIcmpTypes())) .setDstProtocols(firstNonNull(phc.getApplications(), ImmutableSortedSet.of())) .setFragmentOffsets(extractSubranges(phc.getFragmentOffsets())) .setPacketLengths(extractSubranges(phc.getPacketLengths())) .setTcpFlags(firstNonNull(phc.getTcpFlags(), ImmutableSet.of())) .setStates(firstNonNull(phc.getFlowStates(), ImmutableSortedSet.of())); if (phc.getDscps() != null) { builder.setDscps(phc.getDscps().enumerate()); } if (phc.getEcns() != null) { builder.setEcns(ImmutableSortedSet.copyOf(phc.getEcns().enumerate())); } return builder; }
@Test public void test_dscps() { HeaderSpace headerSpace = HeaderSpace.builder() .setDscps(ImmutableSet.of(1, 2, 3)) .setNotDscps(ImmutableSet.of(3, 4, 5)) .build(); BDD bdd = _toBDD.toBDD(headerSpace); BDDInteger dscp = _pkt.getDscp(); BDD dscpBDD = dscp.value(1).or(dscp.value(2)); assertThat(bdd, equalTo(dscpBDD)); }