+ this.prefixesSentCounter.increment();
+ if (!this.mpSupport) {
+ return buildUpdate(Collections.singleton(route), Collections.emptyList(), routeAttributes(route));
+ }
+ return this.support.buildUpdate(Collections.singleton(route), Collections.emptyList(), routeAttributes(route));
+ }
+
+ private Update buildUpdate(
+ @Nonnull final Collection<MapEntryNode> advertised,
+ @Nonnull final Collection<MapEntryNode> withdrawn,
+ @Nonnull final Attributes attr) {
+ final UpdateBuilder ub = new UpdateBuilder().setWithdrawnRoutes(extractWithdrawnRoutes(withdrawn))
+ .setNlri(extractNlris(advertised));
+ ub.setAttributes(attr);
+ return ub.build();
+ }
+
+ private List<Nlri> extractNlris(final Collection<MapEntryNode> routes) {
+ return routes.stream().map(ipv4Route -> new NlriBuilder().setPrefix(new Ipv4Prefix(extractPrefix(ipv4Route)))
+ .setPathId(extractPathId(ipv4Route)).build()).collect(Collectors.toList());
+ }
+
+ private List<WithdrawnRoutes> extractWithdrawnRoutes(final Collection<MapEntryNode> routes) {
+ return routes.stream().map(ipv4Route -> new WithdrawnRoutesBuilder()
+ .setPrefix(new Ipv4Prefix(extractPrefix(ipv4Route))).setPathId(extractPathId(ipv4Route)).build())
+ .collect(Collectors.toList());
+ }
+
+ private String extractPrefix(final MapEntryNode ipv4Route) {
+ return (String) ipv4Route.getChild(this.routeKeyPrefixLeaf).get().getValue();
+ }
+
+ private PathId extractPathId(final MapEntryNode ipv4Route) {
+ final Optional<DataContainerChild<? extends PathArgument, ?>> pathId = ipv4Route
+ .getChild(this.routeKeyPathIdLeaf);
+ return pathId.isPresent() ? new PathId((Long) pathId.get().getValue()) : null;
+ }
+
+ public void close() {
+ this.registerDataTreeChangeListener.close();
+ }
+
+ boolean isMpSupported() {
+ return this.mpSupport;
+ }
+
+ @Override
+ public long getPrefixesSentCount() {
+ return this.prefixesSentCounter.longValue();