Search in sources :

Example 1 with RoaPrefixAssertion

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();
    }
}
Also used : RoaPrefixAssertion(net.ripe.rpki.validator3.domain.RoaPrefixAssertion)

Example 2 with RoaPrefixAssertion

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)));
}
Also used : RoaPrefixAssertion(net.ripe.rpki.validator3.domain.RoaPrefixAssertion) Link(org.springframework.hateoas.Link) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with RoaPrefixAssertion

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());
}
Also used : RoaPrefixAssertion(net.ripe.rpki.validator3.domain.RoaPrefixAssertion) Paging(net.ripe.rpki.validator3.api.Paging) Links(org.springframework.hateoas.Links) SearchTerm(net.ripe.rpki.validator3.api.SearchTerm) Sorting(net.ripe.rpki.validator3.api.Sorting) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with RoaPrefixAssertion

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());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BgpPreviewController(net.ripe.rpki.validator3.api.bgp.BgpPreviewController) Asn(net.ripe.ipresource.Asn)

Example 5 with RoaPrefixAssertion

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);
}
Also used : Arrays(java.util.Arrays) IgnoreFilter(net.ripe.rpki.validator3.domain.IgnoreFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Scheduled(org.springframework.scheduling.annotation.Scheduled) ArrayList(java.util.ArrayList) Sorting(net.ripe.rpki.validator3.api.Sorting) Value(org.springframework.beans.factory.annotation.Value) Asn(net.ripe.ipresource.Asn) Paging(net.ripe.rpki.validator3.api.Paging) ImmutableList(com.google.common.collect.ImmutableList) IpResourceIntervalStrategy(net.ripe.ipresource.etree.IpResourceIntervalStrategy) RoaPrefixAssertion(net.ripe.rpki.validator3.domain.RoaPrefixAssertion) Pair(org.apache.commons.lang3.tuple.Pair) IgnoreFilterService(net.ripe.rpki.validator3.api.ignorefilters.IgnoreFilterService) Service(org.springframework.stereotype.Service) Map(java.util.Map) RoaPrefixDefinition(net.ripe.rpki.validator3.domain.RoaPrefixDefinition) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) IntervalMap(net.ripe.ipresource.etree.IntervalMap) RoaPrefixAssertionsService(net.ripe.rpki.validator3.api.roaprefixassertions.RoaPrefixAssertionsService) ValidatedRpkiObjects(net.ripe.rpki.validator3.domain.ValidatedRpkiObjects) Predicate(java.util.function.Predicate) IpRange(net.ripe.ipresource.IpRange) Collection(java.util.Collection) NestedIntervalMap(net.ripe.ipresource.etree.NestedIntervalMap) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) SearchTerm(net.ripe.rpki.validator3.api.SearchTerm) Optional(java.util.Optional) IgnoreFiltersPredicate(net.ripe.rpki.validator3.domain.IgnoreFiltersPredicate) Comparator(java.util.Comparator) Collections(java.util.Collections) Asn(net.ripe.ipresource.Asn)

Aggregations

RoaPrefixAssertion (net.ripe.rpki.validator3.domain.RoaPrefixAssertion)4 ImmutableList (com.google.common.collect.ImmutableList)2 Asn (net.ripe.ipresource.Asn)2 Paging (net.ripe.rpki.validator3.api.Paging)2 SearchTerm (net.ripe.rpki.validator3.api.SearchTerm)2 Sorting (net.ripe.rpki.validator3.api.Sorting)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 TreeMap (java.util.TreeMap)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1