+ private final class BGPPeerModuleTracker implements BGPConfigModuleTracker {
+
+ private final BGPOpenconfigMapper<BGPPeerInstanceConfiguration> neighborProvider;
+ private final BGPPeerInstanceConfiguration bgpPeerInstanceConfiguration;
+
+ public BGPPeerModuleTracker(final Optional<BGPOpenConfigProvider> openconfigProvider) {
+ if (openconfigProvider.isPresent()) {
+ this.neighborProvider = openconfigProvider.get().getOpenConfigMapper(BGPPeerInstanceConfiguration.class);
+ } else {
+ this.neighborProvider = null;
+ }
+ final InstanceConfigurationIdentifier identifier = new InstanceConfigurationIdentifier(getIdentifier().getInstanceName());
+ this.bgpPeerInstanceConfiguration = new BGPPeerInstanceConfiguration(identifier, Rev130715Util.getIpvAddress(getNormalizedHost()),
+ Rev130715Util.getPort(getPort().getValue()), getHoldtimer(), getPeerRole(), getInitiateConnection(),
+ getAdvertizedTableDependency(), Rev130715Util.getASNumber(getAsOrDefault(getRibDependency()).getValue()),
+ getOptionaPassword(getPassword()), getAddPathDependency());
+ }
+
+ @Override
+ public void onInstanceCreate() {
+ if (this.neighborProvider != null) {
+ this.neighborProvider.writeConfiguration(this.bgpPeerInstanceConfiguration);
+ }
+ }
+
+ @Override
+ public void onInstanceClose() {
+ if (this.neighborProvider != null) {
+ this.neighborProvider.removeConfiguration(this.bgpPeerInstanceConfiguration);
+ }
+ }
+
+ }
+
+ private Optional<Rfc2385Key> getOptionaPassword(final Rfc2385Key password) {
+ return password != null && ! password.getValue().isEmpty() ? Optional.of(password) : Optional.<Rfc2385Key>absent();
+ }
+