2 * Copyright (c) 2021 Orange. 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.server.provider;
10 import static com.google.common.base.Preconditions.checkArgument;
12 import com.google.common.base.MoreObjects;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.ConcurrentMap;
15 import org.opendaylight.mdsal.binding.api.TransactionChain;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.server.rev220321.PathType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.server.rev220321.pcc.configured.lsp.ConfiguredLsp;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.server.rev220321.pcc.configured.lsp.ConfiguredLspKey;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
21 import org.opendaylight.yangtools.yang.binding.CodeHelpers;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class ManagedTeNode {
26 private enum NodeState {
32 private static final Logger LOG = LoggerFactory.getLogger(ManagedTeNode.class);
34 private final ConcurrentMap<ConfiguredLspKey, ManagedTePath> mngPaths = new ConcurrentHashMap<>();
35 private final TransactionChain chain;
36 private final NodeId id;
37 private NodeState state;
39 public ManagedTeNode(final NodeId id, final TransactionChain chain) {
42 state = NodeState.Enabled;
45 public ManagedTeNode(final NodeId id, final TransactionChain chain, final NodeState state) {
51 public NodeState getState() {
55 public NodeId getId() {
59 public ConcurrentMap<ConfiguredLspKey, ManagedTePath> getTePaths() {
63 public WriteTransaction getTransaction() {
64 return chain.newWriteOnlyTransaction();
67 public boolean isSync() {
68 return state == NodeState.Sync;
72 state = NodeState.Sync;
76 * Disable this Managed TE Node and removed associated Managed Node from the Data Store. TE Path which are not
77 * delegated are removed from the path list other ones are mark as disabled.
79 public void disable() {
80 /* Remove associated TE Paths that are not managed by the PCE i.e. TE Path which are not delegated */
81 for (ManagedTePath mngPath: mngPaths.values()) {
82 final ConfiguredLsp lsp = mngPath.getLsp();
83 if (mngPath.getType() == PathType.Stateless || mngPath.getType() == PathType.Pcc) {
84 mngPaths.remove(lsp.key());
90 state = NodeState.Disabled;
91 LOG.debug("Managed TE Node {} has been disabled. Keep configuration {}", id, this);
94 public void addManagedTePath(final ManagedTePath mngPath) {
95 mngPaths.put(mngPath.getLsp().key(), mngPath);
98 public ManagedTePath removeManagedTePath(final ConfiguredLspKey key) {
99 checkArgument(key != null, "Provided Configured LSP Key is a null object");
101 /* Get corresponding Managed TE Path */
102 final ManagedTePath mngPath = mngPaths.remove(key);
103 if (mngPath == null) {
107 /* Remove corresponding Managed Path from the Data Store */
108 mngPath.removeFromDataStore();
113 public ManagedTePath getManagedTePath(final ConfiguredLspKey key) {
114 checkArgument(key != null, "Provided Configured LSP Key is a null object");
116 return mngPaths.get(key);
120 public String toString() {
121 final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper("ManagedTeNode");
122 CodeHelpers.appendValue(helper, "NodeId", id);
123 CodeHelpers.appendValue(helper, "NodeState", state);
124 CodeHelpers.appendValue(helper, "ManagedTePaths", mngPaths);
125 return helper.toString();