Bug-5023: Simplify client re-connection strategies
[bgpcep.git] / bgp / openconfig-impl / src / main / java / org / opendaylight / protocol / bgp / openconfig / impl / openconfig / BGPAppNeighborProviderImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.protocol.bgp.openconfig.impl.openconfig;
10
11 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
12 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
13 import org.opendaylight.protocol.bgp.openconfig.impl.util.OpenConfigUtil;
14 import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPAppPeerInstanceConfiguration;
15 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.Config1;
16 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.Config1Builder;
17 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
18 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
19 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborKey;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.rib.impl.rev160330.BgpApplicationPeer;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
24
25 final class BGPAppNeighborProviderImpl extends AbstractBGPNeighborProvider<BGPAppPeerInstanceConfiguration> {
26
27     public BGPAppNeighborProviderImpl(final BindingTransactionChain txChain, final BGPConfigStateStore stateHolders) {
28         super(txChain, stateHolders, Neighbor.class);
29     }
30
31     @Override
32     public ModuleKey createModuleKey(final String instanceName) {
33         return new ModuleKey(instanceName, BgpApplicationPeer.class);
34     }
35
36     @Override
37     public Neighbor apply(final BGPAppPeerInstanceConfiguration config) {
38         return toAppNeighbor(config);
39     }
40
41     @Override
42     public Class<BGPAppPeerInstanceConfiguration> getInstanceConfigurationType() {
43         return BGPAppPeerInstanceConfiguration.class;
44     }
45
46     private static Neighbor toAppNeighbor(final BGPAppPeerInstanceConfiguration config) {
47         final IpAddress ipAddress = new IpAddress(new Ipv4Address(config.getBgpId().getValue()));
48         return new NeighborBuilder()
49             .setNeighborAddress(ipAddress)
50             .setKey(new NeighborKey(ipAddress))
51             .setConfig(
52                     new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
53                     .addAugmentation(Config1.class, new Config1Builder().setPeerGroup(OpenConfigUtil.APPLICATION_PEER_GROUP_NAME).build())
54                     .build())
55             .build();
56     }
57 }