@Nonnull @JsonIgnore public LocationSpecifier getStartLocationSpecifier() { return LocationSpecifierFactory.load(LOCATION_SPECIFIER_FACTORY) .buildLocationSpecifier(_startLocation); } }
static LocationSpecifierFactory load(String name) { for (LocationSpecifierFactory factory : ServiceLoader.load(LocationSpecifierFactory.class)) { if (factory.getName().equals(name)) { return factory; } } throw new BatfishException("Could not find a LocationSpecifierFactory with name " + name); }
@Test public void testAllInterfacesLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load(new AllInterfacesLocationSpecifierFactory().getName()), instanceOf(AllInterfacesLocationSpecifierFactory.class)); assertThat( new AllInterfacesLocationSpecifierFactory().getName(), equalTo(AllInterfacesLocationSpecifierFactory.NAME)); assertThat( new AllInterfacesLocationSpecifierFactory().buildLocationSpecifier(null), is(AllInterfacesLocationSpecifier.INSTANCE)); }
@Test public void testAllInterfaceLinksLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load(new AllInterfaceLinksLocationSpecifierFactory().getName()), instanceOf(AllInterfaceLinksLocationSpecifierFactory.class)); assertThat( new AllInterfaceLinksLocationSpecifierFactory().getName(), equalTo(AllInterfaceLinksLocationSpecifierFactory.NAME)); assertThat( new AllInterfaceLinksLocationSpecifierFactory().buildLocationSpecifier(null), is(AllInterfaceLinksLocationSpecifier.INSTANCE)); }
@Test public void testNodeRoleRegexInterfaceLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new NodeRoleRegexInterfaceLocationSpecifierFactory().getName()), instanceOf(NodeRoleRegexInterfaceLocationSpecifierFactory.class)); assertThat( new NodeRoleRegexInterfaceLocationSpecifierFactory() .buildLocationSpecifierTyped("roleDimension:" + PATTERN_SRC), equalTo(new NodeRoleRegexInterfaceLocationSpecifier("roleDimension", PATTERN))); }
@JsonIgnore public LocationSpecifier getLocationSpecifier() { checkNotNull(_locationSpecifierFactory, PROP_LOCATION_SPECIFIER_FACTORY + " is null"); return LocationSpecifierFactory.load(_locationSpecifierFactory) .buildLocationSpecifier(_locationSpecifierInput); }
@Test public void testNodeRoleRegexInterfaceLinkLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new NodeRoleRegexInterfaceLinkLocationSpecifierFactory().getName()), instanceOf(NodeRoleRegexInterfaceLinkLocationSpecifierFactory.class)); assertThat( new NodeRoleRegexInterfaceLinkLocationSpecifierFactory() .buildLocationSpecifierTyped("roleDimension:" + PATTERN_SRC), equalTo(new NodeRoleRegexInterfaceLinkLocationSpecifier("roleDimension", PATTERN))); }
@VisibleForTesting static IpSpaceAssignment initSourceIpAssignment( String sourceLocation, String sourceIps, SpecifierContext specifierContext) { /* construct specifiers */ LocationSpecifier sourceLocationSpecifier = LocationSpecifierFactory.load(SRC_LOCATION_SPECIFIER_FACTORY) .buildLocationSpecifier(sourceLocation); IpSpaceSpecifier sourceIpSpaceSpecifier = IpSpaceSpecifierFactory.load(IP_SPECIFIER_FACTORY).buildIpSpaceSpecifier(sourceIps); /* resolve specifiers */ Set<Location> sourceLocations = sourceLocationSpecifier.resolve(specifierContext); return sourceIpSpaceSpecifier.resolve(sourceLocations, specifierContext); }
@Test public void testVrfNameRegexInterfaceLinkLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new VrfNameRegexInterfaceLinkLocationSpecifierFactory().getName()), instanceOf(VrfNameRegexInterfaceLinkLocationSpecifierFactory.class)); assertThat( new VrfNameRegexInterfaceLinkLocationSpecifierFactory().getName(), equalTo(VrfNameRegexInterfaceLinkLocationSpecifierFactory.NAME)); assertThat( new VrfNameRegexInterfaceLinkLocationSpecifierFactory().buildLocationSpecifier(PATTERN_SRC), equalTo(new VrfNameRegexInterfaceLinkLocationSpecifier(PATTERN))); }
/** Generate a set of flows to do traceroute */ @VisibleForTesting Set<Flow> getFlows(String tag) { Set<Location> srcLocations = LocationSpecifierFactory.load(SRC_LOCATION_SPECIFIER_FACTORY) .buildLocationSpecifier(_sourceLocationStr) .resolve(_specifierContext); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); // Perform cross-product of all locations to flows for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = headerConstraintsToFlow(_packetHeaderConstraints, srcLocation); setSourceLocation(flowBuilder, srcLocation); flowBuilder.setTag(tag); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { // Try to ignore silently if possible allProblems.add(e.getMessage()); } } Set<Flow> flows = setBuilder.build(); checkArgument( !flows.isEmpty(), "Could not construct a flow for traceroute. Found issues: %s", String.join(",", allProblems.build())); return flows; }
@Test public void testNameRegexInterfaceLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load(new NameRegexInterfaceLocationSpecifierFactory().getName()), instanceOf(NameRegexInterfaceLocationSpecifierFactory.class)); assertThat( new NameRegexInterfaceLocationSpecifierFactory().getName(), equalTo(NameRegexInterfaceLocationSpecifierFactory.NAME)); assertThat( new NameRegexInterfaceLocationSpecifierFactory().buildLocationSpecifier(PATTERN_SRC), equalTo(new NameRegexInterfaceLocationSpecifier(PATTERN))); }
@Test public void testDescriptionRegexInterfaceLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new DescriptionRegexInterfaceLocationSpecifierFactory().getName()), instanceOf(DescriptionRegexInterfaceLocationSpecifierFactory.class)); assertThat( new DescriptionRegexInterfaceLocationSpecifierFactory().getName(), equalTo(DescriptionRegexInterfaceLocationSpecifierFactory.NAME)); assertThat( new DescriptionRegexInterfaceLocationSpecifierFactory().buildLocationSpecifier(PATTERN_SRC), equalTo(new DescriptionRegexInterfaceLocationSpecifier(PATTERN))); }
@Test public void testNodeNameRegexInterfaceLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new NodeNameRegexInterfaceLocationSpecifierFactory().getName()), instanceOf(NodeNameRegexInterfaceLocationSpecifierFactory.class)); assertThat( new NodeNameRegexInterfaceLocationSpecifierFactory().getName(), equalTo(NodeNameRegexInterfaceLocationSpecifierFactory.NAME)); assertThat( new NodeNameRegexInterfaceLocationSpecifierFactory().buildLocationSpecifier(PATTERN_SRC), equalTo(new NodeNameRegexInterfaceLocationSpecifier(PATTERN))); }
@Test public void testDescriptionRegexInterfaceLinkLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new DescriptionRegexInterfaceLinkLocationSpecifierFactory().getName()), instanceOf(DescriptionRegexInterfaceLinkLocationSpecifierFactory.class)); assertThat( new DescriptionRegexInterfaceLinkLocationSpecifierFactory().getName(), equalTo(DescriptionRegexInterfaceLinkLocationSpecifierFactory.NAME)); assertThat( new DescriptionRegexInterfaceLinkLocationSpecifierFactory() .buildLocationSpecifier(PATTERN_SRC), equalTo(new DescriptionRegexInterfaceLinkLocationSpecifier(PATTERN))); }
@Test public void testNodeNameRegexInterfaceLinkLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new NodeNameRegexInterfaceLinkLocationSpecifierFactory().getName()), instanceOf(NodeNameRegexInterfaceLinkLocationSpecifierFactory.class)); assertThat( new NodeNameRegexInterfaceLinkLocationSpecifierFactory().getName(), equalTo(NodeNameRegexInterfaceLinkLocationSpecifierFactory.NAME)); assertThat( new NodeNameRegexInterfaceLinkLocationSpecifierFactory() .buildLocationSpecifier(PATTERN_SRC), equalTo(new NodeNameRegexInterfaceLinkLocationSpecifier(PATTERN))); }
@Test public void testVrfNameRegexInterfaceLocationSpecifierFactory() { assertThat( LocationSpecifierFactory.load( new VrfNameRegexInterfaceLocationSpecifierFactory().getName()), instanceOf(VrfNameRegexInterfaceLocationSpecifierFactory.class)); assertThat( new VrfNameRegexInterfaceLocationSpecifierFactory().getName(), equalTo(VrfNameRegexInterfaceLocationSpecifierFactory.NAME)); assertThat( new VrfNameRegexInterfaceLocationSpecifierFactory().buildLocationSpecifier(PATTERN_SRC), equalTo(new VrfNameRegexInterfaceLocationSpecifier(PATTERN))); } }