HONEYCOMB-359 - Wildcarded writers
[honeycomb.git] / infra / northbound / bgp / src / main / java / io / fd / honeycomb / infra / bgp / neighbors / BgpPeerWriterFactory.java
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.infra.bgp.neighbors;
18
19 import com.google.inject.Inject;
20 import io.fd.honeycomb.infra.bgp.BgpConfiguration;
21 import io.fd.honeycomb.translate.impl.write.GenericListWriter;
22 import io.fd.honeycomb.translate.write.WriterFactory;
23 import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
24 import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
25 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
26 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
27 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
28 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
29 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
30 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
31 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
32 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
33 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Protocol1;
35 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36
37 import javax.annotation.Nonnull;
38
39 /**
40  * Initializes writer for Bgp Neighbors ({@link Neighbor} node) and all its parents required by HC infra.
41  */
42 public final class BgpPeerWriterFactory implements WriterFactory {
43     private static final InstanceIdentifier<NetworkInstance> NETWORK_INSTANCE_ID =
44             InstanceIdentifier.create(NetworkInstances.class)
45                     .child(NetworkInstance.class);
46
47     private static final InstanceIdentifier<Protocol> PROTOCOL_ID =
48             NETWORK_INSTANCE_ID.child(Protocols.class).child(Protocol.class);
49
50     private static final InstanceIdentifier<Neighbor> NEIGHBOR_ID =
51             PROTOCOL_ID.augmentation(Protocol1.class).child(Bgp.class).child(Neighbors.class).child(Neighbor.class);
52
53     @Inject
54     private BgpConfiguration configuration;
55     @Inject
56     private RIB globalRib;
57     @Inject
58     private BGPTableTypeRegistryConsumer tableTypeRegistry;
59     @Inject
60     private BGPPeerRegistry peerRegistry;
61
62     @Override
63     public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
64         // NetworkInstances
65         //  NetworkInstance =
66         registry.add(new GenericListWriter<>(NETWORK_INSTANCE_ID,
67                 new NetworkInstanceCustomizer(configuration.bgpNetworkInstanceName)));
68
69         //   Protocols
70         //    Protocol =
71         registry.add(
72                 new GenericListWriter<>(PROTOCOL_ID, new ProtocolCustomizer(configuration.bgpProtocolInstanceName.get())));
73
74         //     Protocol1 augmentation (from bgp-openconfig-extensions)
75         //      Bgp
76         //       Neighbors
77         //        Neighbor=
78         registry.wildcardedSubtreeAdd(new GenericListWriter<>(NEIGHBOR_ID, new NeighborCustomizer(globalRib, peerRegistry, tableTypeRegistry)));
79     }
80 }
81