2 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.bgp;
19 import com.google.common.collect.ImmutableSet;
20 import com.google.inject.Inject;
21 import com.google.inject.name.Named;
22 import io.fd.honeycomb.translate.util.write.BindingBrokerWriter;
23 import io.fd.honeycomb.translate.write.WriterFactory;
24 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 * {@link WriterFactory} for BGP Application RIB write integration with HC writer registry.
32 * Uses BindingBrokerWriter to write routes via dedicated broker that, unlike
33 * {@link io.fd.honeycomb.data.impl.DataBroker DataBroker}, supports tx chains and DOMDataChangeListener registration
34 * extensively used by ODL's bgp.
36 * As a bonus BGP routes persisted and available for read via RESTCONF/NETCONF.
38 final class ApplicationRibWriterFactory implements WriterFactory {
41 @Named(BgpModule.HONEYCOMB_BGP)
42 private DataBroker dataBroker;
44 private static final InstanceIdentifier<ApplicationRib> AR_IID =
45 InstanceIdentifier.create(ApplicationRib.class);
46 private static final InstanceIdentifier<Tables> TABLES_IID = AR_IID.child(Tables.class);
49 // TODO (HONEYCOMB-359):
50 // BGP models are huge, we need some kind of wildcarded subtree writer, that works for whole subtree.
51 // 1) we can either move checking handledTypes to writers (getHandledTypes, isAffected, writer.getHandedTypes, ...)
52 // but then precondition check in flatWriterRegistry might be slower (we need to check if we have all writers
53 // in order to avoid unnecessary reverts).
55 // 2) alternative is to compute all child nodes during initialization (might introduce some footprint penalty).
57 public void init(final ModifiableWriterRegistryBuilder registry) {
58 registry.subtreeAdd(ImmutableSet.of(TABLES_IID), new BindingBrokerWriter<>(InstanceIdentifier.create(ApplicationRib.class), dataBroker)