2 * Copyright (c) 2013 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 java.util.concurrent.Future;
12 import javax.annotation.concurrent.ThreadSafe;
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
17 import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.Update;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130918.update.PathAttributes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes1;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.PathAttributes2;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpReachNlri;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130918.update.path.attributes.MpUnreachNlri;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.google.common.base.Objects;
30 import com.google.common.base.Objects.ToStringHelper;
31 import com.google.common.base.Preconditions;
35 private static final Logger logger = LoggerFactory.getLogger(RIBImpl.class);
36 private final DataProviderService dps;
37 private final RIBTables tables;
39 RIBImpl(final DataProviderService dps) {
40 this.dps = Preconditions.checkNotNull(dps);
41 this.tables = new RIBTables(BGPObjectComparator.INSTANCE, AdjRIBsInFactoryRegistryImpl.INSTANCE);
44 synchronized void updateTables(final BGPPeer peer, final Update message) {
45 final DataModificationTransaction trans = this.dps.beginTransaction();
47 // FIXME: detect and handle end-of-RIB markers
49 // remove(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
50 // trans, peer, message.getWithdrawnRoutes().getWithdrawnRoutes().iterator());
52 final PathAttributes attrs = message.getPathAttributes();
53 final PathAttributes2 mpu = attrs.getAugmentation(PathAttributes2.class);
55 final MpUnreachNlri nlri = mpu.getMpUnreachNlri();
57 final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
59 ari.removeRoutes(trans, peer, nlri);
61 logger.debug("Not removing objects from unhandled NLRI {}", nlri);
65 // add(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
66 // trans, peer, message.getNlri().getNlri().iterator(), attrs);
68 final PathAttributes1 mpr = message.getPathAttributes().getAugmentation(PathAttributes1.class);
70 final MpReachNlri nlri = mpr.getMpReachNlri();
72 final AdjRIBsIn ari = this.tables.getOrCreate(new TablesKey(nlri.getAfi(), nlri.getSafi()));
74 ari.addRoutes(trans, peer, nlri, attrs);
76 logger.debug("Not adding objects from unhandled NLRI {}", nlri);
80 // FIXME: we need to attach to this future for failures
81 final Future<RpcResult<TransactionStatus>> f = trans.commit();
84 synchronized void clearTable(final BGPPeer peer, final TablesKey key) {
85 final AdjRIBsIn ari = this.tables.get(key);
87 final DataModificationTransaction trans = this.dps.beginTransaction();
88 ari.clear(trans, peer);
90 // FIXME: we need to attach to this future for failures
91 final Future<RpcResult<TransactionStatus>> f = trans.commit();
96 public String toString() {
97 return addToStringAttributes(Objects.toStringHelper(this)).toString();
100 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
101 return toStringHelper;