blob: 2505c90226621703892e3456803bee074e9c89f1 [file] [log] [blame]
tejeshwer degala3fe1ed52016-04-22 17:04:01 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.isis.controller.impl.lsdb;
17
18import com.google.common.base.MoreObjects;
19import org.onosproject.isis.controller.IsisLspBin;
20import org.onosproject.isis.controller.LspWrapper;
21
22import java.util.Map;
23import java.util.concurrent.ConcurrentHashMap;
24
25/**
26 * Representation of LSP bin, where an LSP is stored for Aging.
27 * A bin is identified by a bin number and can have one or more LSPs
28 * store in a particular bin location
29 */
30public class DefaultIsisLspBin implements IsisLspBin {
31 private int binNumber;
32 private Map<String, LspWrapper> listOfLsp = new ConcurrentHashMap<>();
33
34 /**
35 * Creates ISIS LSP bin instance.
36 *
37 * @param binNumber bin number
38 */
39 public DefaultIsisLspBin(int binNumber) {
40 this.binNumber = binNumber;
41 }
42
43 /**
44 * Adds the LSP to wrapper.
45 *
46 * @param lspKey key to add the LSP
47 * @param lspWrapper LSP wrapper instance
48 */
49 public void addIsisLsp(String lspKey, LspWrapper lspWrapper) {
50 if (!listOfLsp.containsKey(lspKey)) {
51 listOfLsp.put(lspKey, lspWrapper);
52 lspWrapper.setBinNumber(this.binNumber);
53 }
54 }
55
56 /**
57 * Returns the LSP wrapper.
58 *
59 * @param lspKey LSP key
60 * @return LSP wrapper
61 */
62 public LspWrapper isisLsp(String lspKey) {
63 return listOfLsp.get(lspKey);
64 }
65
66 /**
67 * Removes ISIS LSP from database.
68 *
69 * @param lspKey LSP key
70 * @param lspWrapper LSP wrapper instance
71 */
72 public void removeIsisLsp(String lspKey, LspWrapper lspWrapper) {
73 if (listOfLsp.containsKey(lspKey)) {
74 listOfLsp.remove(lspKey);
75 }
76 }
77
78 /**
79 * Returns all LSP wrappers.
80 *
81 * @return all LSP wrappers
82 */
83 public Map<String, LspWrapper> listOfLsp() {
84 return listOfLsp;
85 }
86
87 /**
88 * Returns the bin number.
89 *
90 * @return the bin number
91 */
92 public int binNumber() {
93 return binNumber;
94 }
95
96 @Override
97 public String toString() {
98 return MoreObjects.toStringHelper(getClass())
99 .omitNullValues()
100 .add("binNumber", binNumber)
101 .add("listOfLsp", listOfLsp)
102 .toString();
103 }
104}