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 {
27 private enum NodeState {
33 private final NodeId id;
34 private NodeState state;
35 private ConcurrentMap<ConfiguredLspKey, ManagedTePath> mngPaths =
36 new ConcurrentHashMap<ConfiguredLspKey, ManagedTePath>();
37 private final TransactionChain chain;
38 private static final Logger LOG = LoggerFactory.getLogger(ManagedTeNode.class);
40 public ManagedTeNode(final NodeId id, final TransactionChain chain) {
43 this.state = NodeState.Enabled;
46 public ManagedTeNode(final NodeId id, TransactionChain chain, final NodeState state) {
52 public NodeState getState() {
56 public NodeId getId() {
60 public ConcurrentMap<ConfiguredLspKey, ManagedTePath> getTePaths() {
64 public WriteTransaction getTransaction() {
65 return chain.newWriteOnlyTransaction();
68 public boolean isSync() {
69 return state == NodeState.Sync;
73 state = NodeState.Sync;
77 * Disable this Managed TE Node and removed associated Managed Node from the Data Store. TE Path which are not
78 * delegated are removed from the path list other ones are mark as disabled.
80 public void disable() {
81 /* Remove associated TE Paths that are not managed by the PCE i.e. TE Path which are not delegated */
82 for (ManagedTePath mngPath: mngPaths.values()) {
83 final ConfiguredLsp lsp = mngPath.getLsp();
84 if (mngPath.getType() == PathType.Stateless || mngPath.getType() == PathType.Pcc) {
85 mngPaths.remove(lsp.key());
91 state = NodeState.Disabled;
92 LOG.debug("Managed TE Node {} has been disabled. Keep configuration {}", id, this);
95 public void addManagedTePath(final ManagedTePath mngPath) {
96 mngPaths.put(mngPath.getLsp().key(), mngPath);
99 public ManagedTePath removeManagedTePath(final ConfiguredLspKey key) {
100 checkArgument(key != null, "Provided Configured LSP Key is a null object");
102 /* Get corresponding Managed TE Path */
103 final ManagedTePath mngPath = mngPaths.remove(key);
104 if (mngPath == null) {
108 /* Remove corresponding Managed Path from the Data Store */
109 mngPath.removeFromDataStore();
114 public ManagedTePath getManagedTePath(final ConfiguredLspKey key) {
115 checkArgument(key != null, "Provided Configured LSP Key is a null object");
117 return mngPaths.get(key);
121 public String toString() {
122 final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper("ManagedTeNode");
123 CodeHelpers.appendValue(helper, "NodeId", id);
124 CodeHelpers.appendValue(helper, "NodeState", state);
125 CodeHelpers.appendValue(helper, "ManagedTePaths", mngPaths);
126 return helper.toString();