BUG-6317 Do not withdraw route when best path has changed
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / controller / config / yang / bgp / rib / impl / BGPPSMImplModule.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.controller.config.yang.bgp.rib.impl;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.config.api.DependencyResolver;
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
13 import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
14 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPBestPathSelection;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
18 import org.opendaylight.yangtools.yang.binding.DataContainer;
19
20 public final class BGPPSMImplModule extends AbstractBGPPSMImplModule {
21     public BGPPSMImplModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver) {
22         super(identifier, dependencyResolver);
23     }
24
25     public BGPPSMImplModule(ModuleIdentifier identifier, DependencyResolver dependencyResolver, BGPPSMImplModule oldModule, AutoCloseable oldInstance) {
26         super(identifier, dependencyResolver, oldModule, oldInstance);
27     }
28
29     private static final class AutoCloseableBestPathSelectionStrategy implements BGPBestPathSelection {
30
31         private final BgpTableType pathFamilyDependency;
32         private final PathSelectionMode strategyFactory;
33
34         AutoCloseableBestPathSelectionStrategy(final BgpTableType pathFamilyDependency, final PathSelectionMode strategyFactory) {
35             this.pathFamilyDependency = Preconditions.checkNotNull(pathFamilyDependency);
36             this.strategyFactory = Preconditions.checkNotNull(strategyFactory);
37         }
38
39         @Override
40         public void close() throws Exception {
41             this.strategyFactory.close();
42         }
43
44         @Override
45         public Class<? extends AddressFamily> getAfi() {
46             return this.pathFamilyDependency.getAfi();
47         }
48
49         @Override
50         public Class<? extends SubsequentAddressFamily> getSafi() {
51             return this.pathFamilyDependency.getSafi();
52         }
53
54         @Override
55         public Class<? extends DataContainer> getImplementedInterface() {
56             return BGPBestPathSelection.class;
57         }
58
59         @Override
60         public PathSelectionMode getStrategy() {
61             return this.strategyFactory;
62         }
63     }
64
65     @Override
66     public void customValidation() {
67     }
68
69     @Override
70     public java.lang.AutoCloseable createInstance() {
71         return new AutoCloseableBestPathSelectionStrategy(getPathAddressFamilyDependency(), getPathSelectionModeDependency());
72     }
73 }