blob: de1986232f17cddd730e2fe326c7202c2690f1a7 [file] [log] [blame]
chidambar babu344dc812016-05-02 19:13:10 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
chidambar babu344dc812016-05-02 19:13:10 +05303 *
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 org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.isis.controller.IsisLsdb;
22import org.onosproject.isis.controller.IsisLsdbAge;
23import org.onosproject.isis.controller.IsisPduType;
24import org.onosproject.isis.controller.LspWrapper;
sunish vk4b5ce002016-05-09 20:18:35 +053025import org.onosproject.isis.controller.impl.DefaultIsisInterface;
26import org.onosproject.isis.io.isispacket.IsisHeader;
27import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas;
28import org.onosproject.isis.io.isispacket.pdu.LsPdu;
chidambar babu344dc812016-05-02 19:13:10 +053029import org.onosproject.isis.io.util.IsisConstants;
30
sunish vk4b5ce002016-05-09 20:18:35 +053031import java.util.List;
chidambar babu344dc812016-05-02 19:13:10 +053032import java.util.Map;
33import java.util.concurrent.ConcurrentHashMap;
34
35import static org.hamcrest.CoreMatchers.*;
36import static org.junit.Assert.assertThat;
37
38/**
39 * Unit test case for DefaultIsisLsdb.
40 */
41public class DefaultIsisLsdbTest {
42 private final int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
43 private final int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
44 private final String srcId = "1111.1111.1111";
chidambar babu344dc812016-05-02 19:13:10 +053045 private DefaultIsisLsdb defaultIsisLsdb;
46 private IsisLsdbAge lsdbAge = null;
chidambar babu344dc812016-05-02 19:13:10 +053047 private int resultInt;
48 private Map<String, LspWrapper> resultMap = new ConcurrentHashMap<>();
49 private IsisLsdb resultLsdb;
50 private LspWrapper resultLspWrapper;
sunish vk4b5ce002016-05-09 20:18:35 +053051 private List<LspWrapper> lspWrapperList;
52 private LsPdu lsPdu;
53 private IsisHeader isisHeader;
54 private DefaultIsisInterface defaultIsisInterface;
55 private String lspId = "1234.1234.1234.00-00";
56 private String result;
chidambar babu344dc812016-05-02 19:13:10 +053057
58 @Before
59 public void setUp() throws Exception {
sunish vk4b5ce002016-05-09 20:18:35 +053060 defaultIsisInterface = new DefaultIsisInterface();
61 isisHeader = new IsisHeader();
62 lsPdu = new LsPdu(isisHeader);
63 lsPdu.setLspId(lspId);
64 lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
65 lsPdu.setIsisPduType(IsisPduType.L1LSPDU.value());
chidambar babu344dc812016-05-02 19:13:10 +053066 defaultIsisLsdb = new DefaultIsisLsdb();
67 }
68
69 @After
70 public void tearDown() throws Exception {
71 defaultIsisLsdb = null;
72 }
73
74 /**
75 * Tests initializeDb() method.
76 */
77 @Test
78 public void testInitializeDb() throws Exception {
79 defaultIsisLsdb.initializeDb();
80 assertThat(lsdbAge, is(nullValue()));
81 }
82
83 /**
84 * Tests setL1LspSeqNo() method.
85 */
86 @Test
87 public void testSetL1LspSeqNo() throws Exception {
88 defaultIsisLsdb.setL1LspSeqNo(l1LspSeqNo);
89 assertThat(defaultIsisLsdb, is(notNullValue()));
90 }
91
92 /**
93 * Tests setL2LspSeqNo() method.
94 */
95 @Test
96 public void testSetL2LspSeqNo() throws Exception {
97 defaultIsisLsdb.setL2LspSeqNo(l2LspSeqNo);
98 assertThat(defaultIsisLsdb, is(notNullValue()));
99 }
100
101 /**
102 * Tests setL2LspSeqNo() method.
103 */
104 @Test
105 public void testLspKey() throws Exception {
106 defaultIsisLsdb.lspKey(srcId);
107 assertThat(defaultIsisLsdb, is(notNullValue()));
108 }
109
110 /**
111 * Tests setL2LspSeqNo() method.
112 */
113 @Test
114 public void testGetL1Db() throws Exception {
115 resultMap = defaultIsisLsdb.getL1Db();
116 assertThat(resultMap.isEmpty(), is(true));
117 }
118
119 /**
120 * Tests setL2LspSeqNo() method.
121 */
122 @Test
123 public void testGetL2Db() throws Exception {
124 resultMap = defaultIsisLsdb.getL2Db();
125 assertThat(resultMap.isEmpty(), is(true));
126 }
127
128 /**
129 * Tests setL2LspSeqNo() method.
130 */
131 @Test
132 public void testIsisLsdb() throws Exception {
133 resultLsdb = defaultIsisLsdb.isisLsdb();
134 assertThat(resultLsdb, is(notNullValue()));
135 }
136
137 /**
138 * Tests findLsp() method.
139 */
140 @Test
141 public void testFindLsp() throws Exception {
142 resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId);
143 assertThat(resultLspWrapper, is(nullValue()));
144 }
sunish vk4b5ce002016-05-09 20:18:35 +0530145
146 /**
147 * Tests allLspHeaders() method.
148 */
149 @Test
150 public void testAllLspHeaders() throws Exception {
151 defaultIsisLsdb.addLsp(lsPdu, false, defaultIsisInterface);
152 lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
153 assertThat(lspWrapperList, is(notNullValue()));
154
155 defaultIsisLsdb.addLsp(lsPdu, true, defaultIsisInterface);
156 lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
157 assertThat(lspWrapperList, is(notNullValue()));
158 }
159
160 /**
161 * Tests isNewerOrSameLsp() method.
162 */
163 @Test
164 public void testIsNewerOrSameLsp() throws Exception {
165 result = defaultIsisLsdb.isNewerOrSameLsp(lsPdu, lsPdu);
166 assertThat(result, is("same"));
167 }
168
169 /**
170 * Tests lsSequenceNumber() method.
171 */
172 @Test
173 public void testLsSequenceNumber() throws Exception {
174 resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1LSPDU);
175 assertThat(resultInt, is(1));
176
177 resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L2LSPDU);
178 assertThat(resultInt, is(1));
179
180 resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1CSNP);
181 assertThat(resultInt, is(1));
182 }
183
184 /**
185 * Tests deleteLsp() method.
186 */
187 @Test
188 public void testdeleteLsp() throws Exception {
189 defaultIsisLsdb.deleteLsp(lsPdu);
190 assertThat(defaultIsisLsdb, is(notNullValue()));
191
192 lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
193 defaultIsisLsdb.deleteLsp(lsPdu);
194 assertThat(defaultIsisLsdb, is(notNullValue()));
195
196 lsPdu.setIsisPduType(IsisPduType.L1CSNP.value());
197 defaultIsisLsdb.deleteLsp(lsPdu);
198 assertThat(defaultIsisLsdb, is(notNullValue()));
199 }
chidambar babu344dc812016-05-02 19:13:10 +0530200}
201