@Test public void constructorExplicitName() { InterfacesSpecifier specifier = new InterfacesSpecifier("name:Loopback.*"); assertThat(specifier.getType(), equalTo(Type.NAME)); assertThat(specifier.getRegex().pattern(), equalTo(Pattern.compile("Loopback.*").pattern())); }
question.getInterfacesSpecifier().matches(iface) && (!question.getEnabledIpsOnly() || iface.getActive()))
public static LocationSpecifier from(@Nonnull InterfacesSpecifier ingressInterfaces) { switch (ingressInterfaces.getType()) { case DESC: return new DescriptionRegexInterfaceLocationSpecifier(ingressInterfaces.getRegex()); case NAME: return new NameRegexInterfaceLocationSpecifier(ingressInterfaces.getRegex()); case VRF: return new VrfNameRegexInterfaceLocationSpecifier(ingressInterfaces.getRegex()); default: throw new BatfishException( "Unexcepted InterfacesSpecifier type: " + ingressInterfaces.getType()); } }
@Test public void matchesName() { InterfacesSpecifier specifier = new InterfacesSpecifier("name:Loopback.*"); Interface loopbackInterface = new Interface("Loopback0"); Interface nonLoopbackInterface = new Interface("Ethetnet0/0"); assertThat(specifier.matches(loopbackInterface), equalTo(true)); assertThat(specifier.matches(nonLoopbackInterface), equalTo(false)); }
private boolean isFilterOnInterface( Configuration c, Function<Interface, IpAccessList> filterGetter, IpAccessList filter) { InterfacesSpecifier interfaceSpecifiers = new InterfacesSpecifier(_regex); return c.getAllInterfaces().values().stream() .filter(interfaceSpecifiers::matches) .map(filterGetter) .anyMatch(o -> o == filter); }
@Test public void matchesCaseInsensitive() { Interface iface = Interface.builder() .setName("Loopback0") .setOwner(new Configuration("c", ConfigurationFormat.CISCO_IOS)) .setVrf(new Vrf("vrfA")) .build(); iface.setDescription("secrets are never secrets for long"); assertTrue(new InterfacesSpecifier("name:LoopBAck.*").matches(iface)); assertTrue(new InterfacesSpecifier("desc:SECrets.*").matches(iface)); assertTrue(new InterfacesSpecifier("type:Loopback").matches(iface)); assertTrue(new InterfacesSpecifier("vrf:vrfa").matches(iface)); }
return new ShorthandInterfaceSpecifier(new InterfacesSpecifier(str));
@Test public void constructorImplicitName() { InterfacesSpecifier specifier = new InterfacesSpecifier("Loopback.*"); assertThat(specifier.getType(), equalTo(Type.NAME)); assertThat(specifier.getRegex().pattern(), equalTo(Pattern.compile("Loopback.*").pattern())); }
@Test public void matchesDesc() { InterfacesSpecifier specifier = new InterfacesSpecifier("desc:secret.*"); Interface secretInterface = new Interface("Loopback0"); secretInterface.setDescription("secrets are never secrets for long"); Interface nonSecretInterface = new Interface("Ethetnet0/0"); nonSecretInterface.setDescription("this interface couldn't keep its secret"); assertThat(specifier.matches(secretInterface), equalTo(true)); assertThat(specifier.matches(nonSecretInterface), equalTo(false)); }
@Test public void testShorthand() { assertThat( new FlexibleInterfaceSpecifierFactory().buildInterfaceSpecifier("name:.*"), equalTo(new ShorthandInterfaceSpecifier(new InterfacesSpecifier("name:.*")))); }
if (!interfacesSpecifier.matches(iface) || (excludeShutInterfaces && !iface.getActive())) { continue;
@Test public void constructorRole() { InterfacesSpecifier specifier = new InterfacesSpecifier("desc:secret.*"); assertThat(specifier.getType(), equalTo(Type.DESC)); assertThat(specifier.getRegex().pattern(), equalTo(Pattern.compile("secret.*").pattern())); }
@Test public void matchesType() { InterfacesSpecifier specifier = new InterfacesSpecifier("type:physical"); Configuration c = new Configuration("c", ConfigurationFormat.CISCO_IOS); Interface ifaceLoopback = Interface.builder().setName("Loopback0").setOwner(c).build(); Interface ifacePhysical = Interface.builder().setName("GigabitEthernet0").setOwner(c).build(); assertThat(specifier.matches(ifaceLoopback), equalTo(false)); assertThat(specifier.matches(ifacePhysical), equalTo(true)); }
private @Nonnull Multiset<Row> getRows(String property) { InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property); return InterfacePropertiesAnswerer.getProperties( propertySpecifier, ImmutableMap.of(HOSTNAME, _c), ImmutableSet.of(HOSTNAME), new InterfacesSpecifier(INTERFACE_NAME), new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier), (String) null) .toColumnMap()); }
String interfaceName = e2.getKey(); Interface iface = e2.getValue(); if (question.getInterfacesSpecifier().matches(iface)) { if (iface.getSwitchport()) {
@Test public void matchesVrf() { InterfacesSpecifier specifier = new InterfacesSpecifier("vrf:vrf1"); Interface vrf1Iface = Interface.builder().setName("iface").setVrf(new Vrf("vrf1")).build(); Interface vrf2Iface = Interface.builder().setName("iface").setVrf(new Vrf("vrf2")).build(); assertThat(specifier.matches(vrf1Iface), equalTo(true)); assertThat(specifier.matches(vrf2Iface), equalTo(false)); } }
@Test public void resolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface11 = Interface.builder().setName("iface11").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface12").setOwner(node1).build(); Interface iface2 = Interface.builder().setName("iface2").setOwner(node2).build(); node1.setInterfaces(ImmutableSortedMap.of("iface11", iface11, "iface12", iface12)); node2.setInterfaces(ImmutableSortedMap.of("iface2", iface2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of("node1", node1, "node2", node2)) .build(); assertThat( new ShorthandInterfaceSpecifier(new InterfacesSpecifier("iface11")) .resolve(ImmutableSet.of("node1"), ctxt), equalTo(ImmutableSet.of(iface11))); } }
@Test public void testToReachabilityParameters_ingressNodes_ingressInterface() { NodesSpecifier nodesSpecifier = new NodesSpecifier("nodes"); InterfacesSpecifier interfacesSpecifier = new InterfacesSpecifier("interfaces"); ReachabilitySettings settings = ReachabilitySettings.builder() .setActions(ImmutableList.of()) .setHeaderSpace(HeaderSpace.builder().build()) .setIngressNodes(nodesSpecifier) .setIngressInterfaces(interfacesSpecifier) .build(); ReachabilityParameters params = settings.toReachabilityParameters(); assertThat( params.getSourceLocationSpecifier(), equalTo( new IntersectionLocationSpecifier( LocationSpecifiers.from(interfacesSpecifier), LocationSpecifiers.from(nodesSpecifier)))); } }
ImmutableMap.of("node1", conf1), ImmutableSet.of("node1"), new InterfacesSpecifier("iface1"), new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier),