@Test public void testToHeaderSpace() { IpSpace baseIpSpace = IpWildcard.parse(BASE_IP_PREFIX).toIpSpace(); FwFromSourcePrefixList fwFrom = new FwFromSourcePrefixList(BASE_PREFIX_LIST_NAME); assertEquals( fwFrom.toHeaderspace(_jc, _c, _w), HeaderSpace.builder().setSrcIps(baseIpSpace).build()); }
@VisibleForTesting HeaderSpace toHeaderspace(JuniperConfiguration jc, Configuration c, Warnings w) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_name); if (pl == null) { w.redFlag("Reference to undefined source-prefix-list: \"" + _name + "\""); return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } if (pl.getIpv6()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } RouteFilterList prefixList = c.getRouteFilterLists().get(_name); if (prefixList.getLines().isEmpty()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } return HeaderSpace.builder() .setSrcIps( AclIpSpace.union( prefixList.getMatchingIps().stream() .map(IpWildcard::toIpSpace) .collect(ImmutableList.toImmutableList()))) .build(); }
FwFromSourcePrefixList implements FwFrom { @VisibleForTesting HeaderSpace toHeaderspace(JuniperConfiguration jc, Configuration c, Warnings w) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_name); if (pl == null) { w.redFlag("Reference to undefined source-prefix-list: \"" + _name + "\""); return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } if (pl.getIpv6()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } RouteFilterList prefixList = c.getRouteFilterLists().get(_name); if (prefixList.getLines().isEmpty()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } return HeaderSpace.builder() .setSrcIps( AclIpSpace.union( prefixList.getMatchingIps().stream() .map(IpWildcard::toIpSpace) .collect(ImmutableList.toImmutableList()))) .build(); } }
FwFromSourcePrefixList implements FwFrom { @VisibleForTesting HeaderSpace toHeaderspace(JuniperConfiguration jc, Configuration c, Warnings w) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_name); if (pl == null) { w.redFlag("Reference to undefined source-prefix-list: \"" + _name + "\""); return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } if (pl.getIpv6()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } RouteFilterList prefixList = c.getRouteFilterLists().get(_name); if (prefixList.getLines().isEmpty()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } return HeaderSpace.builder() .setSrcIps( AclIpSpace.union( prefixList.getMatchingIps().stream() .map(IpWildcard::toIpSpace) .collect(ImmutableList.toImmutableList()))) .build(); } FwFromSourcePrefixList(String name); }
FwFromSourcePrefixList implements FwFrom { @VisibleForTesting HeaderSpace toHeaderspace(JuniperConfiguration jc, Configuration c, Warnings w) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_name); if (pl == null) { w.redFlag("Reference to undefined source-prefix-list: \"" + _name + "\""); return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } if (pl.getIpv6()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } RouteFilterList prefixList = c.getRouteFilterLists().get(_name); if (prefixList.getLines().isEmpty()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } return HeaderSpace.builder() .setSrcIps( AclIpSpace.union( prefixList.getMatchingIps().stream() .map(IpWildcard::toIpSpace) .collect(ImmutableList.toImmutableList()))) .build(); } FwFromSourcePrefixList(String name); @Override Field getField(); @Override AclLineMatchExpr toAclLineMatchExpr(JuniperConfiguration jc, Configuration c, Warnings w); }
FwFromSourcePrefixList implements FwFrom { @VisibleForTesting HeaderSpace toHeaderspace(JuniperConfiguration jc, Configuration c, Warnings w) { PrefixList pl = jc.getMasterLogicalSystem().getPrefixLists().get(_name); if (pl == null) { w.redFlag("Reference to undefined source-prefix-list: \"" + _name + "\""); return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } if (pl.getIpv6()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } RouteFilterList prefixList = c.getRouteFilterLists().get(_name); if (prefixList.getLines().isEmpty()) { return HeaderSpace.builder().setSrcIps(EmptyIpSpace.INSTANCE).build(); } return HeaderSpace.builder() .setSrcIps( AclIpSpace.union( prefixList.getMatchingIps().stream() .map(IpWildcard::toIpSpace) .collect(ImmutableList.toImmutableList()))) .build(); } FwFromSourcePrefixList(String name); @Override Field getField(); @Override AclLineMatchExpr toAclLineMatchExpr(JuniperConfiguration jc, Configuration c, Warnings w);  }