2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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 com.google.common.base.Preconditions;
11 import org.opendaylight.protocol.bgp.rib.impl.spi.AbstractImportPolicy;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Invoked on routes which we get from our normal home AS peers.
23 class FromInternalImportPolicy extends AbstractImportPolicy {
24 private static final Logger LOG = LoggerFactory.getLogger(FromInternalImportPolicy.class);
25 private final ClusterIdentifier clusterIdentifier;
26 private final Ipv4Address bgpIdentifier;
28 FromInternalImportPolicy(final Ipv4Address bgpIdentifier, final ClusterIdentifier clusterIdentifier) {
29 this.bgpIdentifier = Preconditions.checkNotNull(bgpIdentifier);
30 this.clusterIdentifier = Preconditions.checkNotNull(clusterIdentifier);
34 public ContainerNode effectiveAttributes(final ContainerNode attributes) {
35 final AttributeOperations oper = AttributeOperations.getInstance(attributes);
38 * This is an implementation of https://tools.ietf.org/html/rfc4456#section-8
40 * We first check the ORIGINATOR_ID, if present. If it matches our BGP identifier,
41 * we filter the route.
43 final Object originatorId = oper.getOriginatorId(attributes);
44 if (this.bgpIdentifier.getValue().equals(originatorId)) {
45 LOG.debug("Filtering route with our ORIGINATOR_ID {}", this.bgpIdentifier);
50 * Second we check CLUSTER_LIST, if present. If it contains our CLUSTER_ID, we issue
51 * a warning and ignore the route.
53 final LeafSetNode<?> clusterList = oper.getClusterList(attributes);
54 if (clusterList != null) {
55 for (final LeafSetEntryNode<?> node : clusterList.getValue()) {
56 if (this.clusterIdentifier.getValue().equals(node.getValue())) {
57 LOG.info("Received a route with our CLUSTER_ID {} in CLUSTER_LIST {}, filtering it", this.clusterIdentifier.getValue(), clusterList);