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 static java.util.Objects.requireNonNull;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateMessage;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
24 public final class BgpPeerUtil {
25 private BgpPeerUtil() {
30 * Creates UPDATE message that contains EOR marker for specified address family.
32 * @param key of family for which we need EOR
33 * @return UPDATE message with EOR marker
35 public static Update createEndOfRib(final TablesKey key) {
36 return key.getAfi() == Ipv4AddressFamily.class && key.getSafi() == UnicastSubsequentAddressFamily.class
37 ? new UpdateBuilder().build() : new UpdateBuilder()
38 .setAttributes(new AttributesBuilder()
39 .addAugmentation(new Attributes2Builder()
40 .setMpUnreachNlri(new MpUnreachNlriBuilder()
42 .setSafi(key.getSafi())
50 * Verify presence of EOR marker in UPDATE message.
52 * @param msg UPDATE message to be checked
53 * @return True if message contains EOR marker, otherwise return False
55 public static boolean isEndOfRib(final UpdateMessage msg) {
56 if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
57 if (msg.getAttributes() != null) {
58 final Attributes2 pa = msg.getAttributes().augmentation(Attributes2.class);
59 if (pa != null && msg.getAttributes().augmentation(Attributes1.class) == null) {
60 //only MP_UNREACH_NLRI allowed in EOR
61 if (pa.getMpUnreachNlri() != null && pa.getMpUnreachNlri().getWithdrawnRoutes() == null) {
62 // EOR message contains only MPUnreach attribute and no NLRI
67 // true for empty IPv4 Unicast
75 * DTO for transferring LLGR advertizements.
77 * @deprecated This class is deprecated for refactoring.
79 // FIXME: there should be no need for this class, as we should be able to efficiently translate TableKey classes
80 // and rely on yang-parser-api.
82 public static final class LlGracefulRestartDTO {
84 private final TablesKey tableKey;
85 private final int staleTime;
86 private final boolean forwardingFlag;
88 public LlGracefulRestartDTO(final TablesKey tableKey, final int staleTime, final boolean forwardingFlag) {
89 this.tableKey = requireNonNull(tableKey);
90 this.staleTime = staleTime;
91 this.forwardingFlag = forwardingFlag;
94 public TablesKey getTableKey() {
98 public int getStaleTime() {
102 public boolean isForwarding() {
103 return forwardingFlag;