+ private static Attributes nextHopToAttribute(final Attributes attrs, final MpReachNlri mpReach) {
+ if (attrs.getCNextHop() == null && mpReach.getCNextHop() != null) {
+ final AttributesBuilder attributesBuilder = new AttributesBuilder(attrs);
+ attributesBuilder.setCNextHop(mpReach.getCNextHop());
+ return attributesBuilder.build();
+ }
+ return attrs;
+ }
+
+ /**
+ * Creates MPReach for the prefixes to be handled in the same way as linkstate routes
+ *
+ * @param message Update message containing prefixes in NLRI
+ * @return MpReachNlri with prefixes from the nlri field
+ */
+ private static MpReachNlri prefixesToMpReach(final Update message) {
+ final List<Ipv4Prefixes> prefixes = new ArrayList<>();
+ for (final Ipv4Prefix p : message.getNlri().getNlri()) {
+ prefixes.add(new Ipv4PrefixesBuilder().setPrefix(p).build());
+ }
+ final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(
+ UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(
+ new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(
+ new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build());
+ if (message.getAttributes() != null) {
+ b.setCNextHop(message.getAttributes().getCNextHop());
+ }
+ return b.build();
+ }
+
+ /**
+ * Create MPUnreach for the prefixes to be handled in the same way as linkstate routes
+ *
+ * @param message Update message containing withdrawn routes
+ * @param isAnyNlriAnnounced
+ * @return MpUnreachNlri with prefixes from the withdrawn routes field
+ */
+ private static MpUnreachNlri prefixesToMpUnreach(final Update message, final boolean isAnyNlriAnnounced) {
+ final List<Ipv4Prefixes> prefixes = new ArrayList<>();
+ for (final Ipv4Prefix p : message.getWithdrawnRoutes().getWithdrawnRoutes()) {
+ boolean nlriAnounced = false;
+ if(isAnyNlriAnnounced) {
+ nlriAnounced = message.getNlri().getNlri().contains(p);
+ }
+
+ if(!nlriAnounced) {
+ prefixes.add(new Ipv4PrefixesBuilder().setPrefix(p).build());
+ }
+ }
+ return new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setWithdrawnRoutes(
+ new WithdrawnRoutesBuilder().setDestinationType(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4(
+ new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build()).build();
+ }
+