use of net.ripe.rpki.validator3.domain.RoaPrefixAssertion in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsService method remove.
public void remove(long roaPrefixAssertionId) {
RoaPrefixAssertion entity = roaPrefixAssertions.get(roaPrefixAssertionId);
if (entity != null) {
roaPrefixAssertions.remove(entity);
notifyListeners();
}
}
use of net.ripe.rpki.validator3.domain.RoaPrefixAssertion in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsController method add.
@PostMapping(consumes = { Api.API_MIME_TYPE, "application/json" })
public ResponseEntity<ApiResponse<RoaPrefixAssertionResource>> add(@RequestBody @Valid ApiCommand<AddRoaPrefixAssertion> command) {
final long id = roaPrefixAssertionsService.execute(command.getData());
final RoaPrefixAssertion ignoreFilter = roaPrefixAssertions.get(id);
final Link selfRel = linkTo(methodOn(RoaPrefixAssertionsController.class).get(id)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(ApiResponse.data(toResource(ignoreFilter)));
}
use of net.ripe.rpki.validator3.domain.RoaPrefixAssertion in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsController method list.
@GetMapping
public ResponseEntity<ApiResponse<Stream<RoaPrefixAssertionResource>>> list(@RequestParam(name = "startFrom", defaultValue = "0") int startFrom, @RequestParam(name = "pageSize", defaultValue = "20") int pageSize, @RequestParam(name = "search", defaultValue = "", required = false) String searchString, @RequestParam(name = "sortBy", defaultValue = "prefix") String sortBy, @RequestParam(name = "sortDirection", defaultValue = "asc") String sortDirection) {
final SearchTerm searchTerm = StringUtils.isNotBlank(searchString) ? new SearchTerm(searchString) : null;
final Sorting sorting = Sorting.parse(sortBy, sortDirection);
final Paging paging = Paging.of(startFrom, pageSize);
final List<RoaPrefixAssertion> matching = roaPrefixAssertions.find(searchTerm, sorting, paging).collect(Collectors.toList());
int totalSize = (int) roaPrefixAssertions.count(searchTerm);
final Links links = Paging.links(startFrom, pageSize, totalSize, (sf, ps) -> methodOn(RoaPrefixAssertionsController.class).list(sf, ps, searchString, sortBy, sortDirection));
return ResponseEntity.ok(ApiResponse.<Stream<RoaPrefixAssertionResource>>builder().links(links).metadata(Metadata.of(totalSize)).data(matching.stream().map(this::toResource)).build());
}
use of net.ripe.rpki.validator3.domain.RoaPrefixAssertion in project rpki-validator-3 by RIPE-NCC.
the class RoaPrefixAssertionsController method toResource.
private RoaPrefixAssertionResource toResource(RoaPrefixAssertion assertion) {
Asn asn = new Asn(assertion.getAsn());
List<BgpPreviewService.BgpPreviewEntry> affected = bgpPreviewService.findAffected(asn, IpRange.parse(assertion.getPrefix()), assertion.getMaximumLength());
ImmutableList.Builder<BgpPreviewController.BgpPreview> validated = ImmutableList.builder();
ImmutableList.Builder<BgpPreviewController.BgpPreview> invalidated = ImmutableList.builder();
affected.forEach(x -> {
BgpPreviewController.BgpPreview entry = BgpPreviewController.BgpPreview.of(x.getOrigin().toString(), x.getPrefix().toString(), x.getValidity().toString());
if (x.getValidity() == BgpPreviewService.Validity.VALID && x.getOrigin().equals(asn)) {
validated.add(entry);
} else if (x.getValidity() != BgpPreviewService.Validity.VALID) {
invalidated.add(entry);
}
});
return RoaPrefixAssertionResource.of(assertion.getId(), assertion.getAsn(), assertion.getPrefix(), assertion.getMaximumLength(), assertion.getComment(), validated.build(), invalidated.build());
}
use of net.ripe.rpki.validator3.domain.RoaPrefixAssertion in project rpki-validator-3 by RIPE-NCC.
the class BgpPreviewService method updateRoaPrefixAssertions.
private synchronized void updateRoaPrefixAssertions(Collection<RoaPrefixAssertion> assertions) {
this.roaPrefixAssertions = ImmutableList.copyOf(assertions.stream().map(p -> RoaPrefix.of(null, null, p.getId(), p.getComment(), new Asn(p.getAsn()), IpRange.parse(p.getPrefix()), p.getMaximumLength(), p.getMaximumLength() == null ? IpRange.parse(p.getPrefix()).getPrefixLength() : p.getMaximumLength())).collect(Collectors.toList()));
this.roaPrefixes = recalculateRoaPrefixes(this.validatedRoaPrefixes, this.ignoreFilters, this.roaPrefixAssertions);
this.bgpPreviewEntries = validateBgpRisEntries(this.bgpPreviewEntries, this.roaPrefixes);
}
Aggregations