2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.bgpcep.pcep.topology.provider;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.checkerframework.checker.lock.qual.GuardedBy;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
17 import org.opendaylight.mdsal.binding.api.DataListener;
18 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
19 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
23 import org.opendaylight.yangtools.concepts.Registration;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * This class tracks the configuration content of a particular topology instance and propagates updates towards its
30 * associated {@link PCEPTopologyProvider}.
32 final class PCEPTopologyInstance implements DataListener<Topology> {
33 private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyInstance.class);
35 private final @NonNull TopologyKey topology;
38 private PCEPTopologyProvider provider;
40 private Registration reg;
42 PCEPTopologyInstance(final TopologyKey topology, final PCEPTopologyProviderDependencies dependencies,
43 final InstructionScheduler scheduler) {
44 this.topology = requireNonNull(topology);
46 final var instanceIdentifier = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, topology);
48 provider = new PCEPTopologyProvider(instanceIdentifier, dependencies, scheduler);
50 reg = dependencies.getDataBroker().registerDataListener(
51 DataTreeIdentifier.of(LogicalDatastoreType.CONFIGURATION, instanceIdentifier), this);
52 LOG.info("Topology instance for {} initialized", topologyId());
55 synchronized ListenableFuture<?> terminate() {
56 verifyNotNull(reg, "Topology %s instance %s already terminating", topologyId(), this);
60 final var ret = provider.stop();
66 public synchronized void dataChangedTo(final Topology data) {
68 // We have been shut down, do not process any more updates
73 LOG.trace("Updating topology {} configuration to {}", topologyId(), data);
74 provider.updateConfiguration(PCEPTopologyConfiguration.of(data));
76 LOG.info("Topology {} configuration disappeared, ignoring update in anticipation of shutdown",
81 private String topologyId() {
82 return TopologyUtils.friendlyId(topology);