2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateMessage;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
22 public final class BgpPeerUtil {
24 private BgpPeerUtil() {
25 throw new UnsupportedOperationException();
29 * Creates UPDATE message that contains EOR marker for specified address family.
31 * @param key of family for which we need EOR
32 * @return UPDATE message with EOR marker
34 public static Update createEndOfRib(final TablesKey key) {
35 return key.getAfi() == Ipv4AddressFamily.class && key.getSafi() == UnicastSubsequentAddressFamily.class
36 ? new UpdateBuilder().build() :
38 .setAttributes(new AttributesBuilder()
39 .addAugmentation(Attributes2.class, new Attributes2Builder()
40 .setMpUnreachNlri(new MpUnreachNlriBuilder()
42 .setSafi(key.getSafi())
43 .build()).build()).build()).build();
47 * Verify presence of EOR marker in UPDATE message.
49 * @param msg UPDATE message to be checked
50 * @return True if message contains EOR marker, otherwise return False
52 public static boolean isEndOfRib(final UpdateMessage msg) {
53 if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
54 if (msg.getAttributes() != null) {
55 final Attributes2 pa = msg.getAttributes().augmentation(Attributes2.class);
56 if (pa != null && msg.getAttributes().augmentation(Attributes1.class) == null) {
57 //only MP_UNREACH_NLRI allowed in EOR
58 if (pa.getMpUnreachNlri() != null && pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
59 // EOR message contains only MPUnreach attribute and no NLRI
64 // true for empty IPv4 Unicast