Committed by
Thomas Vachuska
ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests
Change-Id: I18972a0712fbd63798f92da7b4c48381b4a38519
Showing
3 changed files
with
2075 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2016 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 | + */ | ||
16 | +package org.onosproject.ospf.controller.impl; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
21 | +import org.jboss.netty.buffer.HeapChannelBufferFactory; | ||
22 | +import org.jboss.netty.channel.Channel; | ||
23 | +import org.jboss.netty.channel.ChannelConfig; | ||
24 | +import org.jboss.netty.channel.ChannelFuture; | ||
25 | +import org.jboss.netty.channel.ChannelHandlerContext; | ||
26 | +import org.jboss.netty.channel.ChannelStateEvent; | ||
27 | +import org.jboss.netty.channel.ExceptionEvent; | ||
28 | +import org.jboss.netty.channel.MessageEvent; | ||
29 | +import org.junit.After; | ||
30 | +import org.junit.Before; | ||
31 | +import org.junit.Test; | ||
32 | +import org.onlab.packet.Ip4Address; | ||
33 | +import org.onosproject.ospf.controller.OspfAreaAddressRange; | ||
34 | +import org.onosproject.ospf.controller.OspfInterface; | ||
35 | +import org.onosproject.ospf.controller.OspfNbr; | ||
36 | +import org.onosproject.ospf.controller.OspfNeighborState; | ||
37 | +import org.onosproject.ospf.controller.TopologyForDeviceAndLink; | ||
38 | +import org.onosproject.ospf.controller.area.OspfAreaAddressRangeImpl; | ||
39 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
40 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
41 | +import org.onosproject.ospf.controller.util.OspfEligibleRouter; | ||
42 | +import org.onosproject.ospf.exceptions.OspfParseException; | ||
43 | +import org.onosproject.ospf.protocol.lsa.LsaHeader; | ||
44 | +import org.onosproject.ospf.protocol.lsa.TlvHeader; | ||
45 | +import org.onosproject.ospf.protocol.lsa.tlvtypes.RouterTlv; | ||
46 | +import org.onosproject.ospf.protocol.lsa.types.RouterLsa; | ||
47 | +import org.onosproject.ospf.protocol.ospfpacket.OspfMessage; | ||
48 | +import org.onosproject.ospf.protocol.ospfpacket.subtype.LsRequestPacket; | ||
49 | +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; | ||
50 | +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; | ||
51 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge; | ||
52 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest; | ||
53 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate; | ||
54 | +import org.onosproject.ospf.protocol.util.ChecksumCalculator; | ||
55 | +import org.onosproject.ospf.protocol.util.OspfInterfaceState; | ||
56 | + | ||
57 | +import java.net.SocketAddress; | ||
58 | +import java.net.UnknownHostException; | ||
59 | +import java.util.ArrayList; | ||
60 | +import java.util.HashMap; | ||
61 | +import java.util.List; | ||
62 | + | ||
63 | +import static org.hamcrest.CoreMatchers.is; | ||
64 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
65 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
66 | + | ||
67 | + | ||
68 | +/** | ||
69 | + * Unit test class for OspfInterfaceChannelHandler. | ||
70 | + */ | ||
71 | +public class OspfInterfaceChannelHandlerTest { | ||
72 | + | ||
73 | + private List<OspfAreaAddressRange> addressRanges; | ||
74 | + private List<OspfInterface> ospfInterfaces; | ||
75 | + private Controller controller; | ||
76 | + private OspfAreaImpl ospfArea; | ||
77 | + private OspfInterfaceImpl ospfInterface; | ||
78 | + private OspfInterfaceChannelHandler ospfInterfaceChannelHandler; | ||
79 | + private HashMap<String, OspfNbr> ospfNbrHashMap; | ||
80 | + private OspfNbrImpl ospfNbr; | ||
81 | + private Channel channel; | ||
82 | + private ChannelHandlerContext channelHandlerContext; | ||
83 | + private ChannelStateEvent channelStateEvent; | ||
84 | + private HelloPacket helloPacket; | ||
85 | + private DdPacket ddPacket; | ||
86 | + private ChecksumCalculator checksumCalculator; | ||
87 | + private byte[] byteArray; | ||
88 | + private byte[] checkArray; | ||
89 | + private ChannelBuffer buf; | ||
90 | + private OspfEligibleRouter ospfEligibleRouter; | ||
91 | + private LsUpdate lsUpdate; | ||
92 | + private LsAcknowledge lsAck; | ||
93 | + private LsRequest lsRequest; | ||
94 | + private TopologyForDeviceAndLink topologyForDeviceAndLink; | ||
95 | + | ||
96 | + @Before | ||
97 | + public void setUp() throws Exception { | ||
98 | + addressRanges = new ArrayList(); | ||
99 | + ospfInterfaces = new ArrayList<>(); | ||
100 | + ospfArea = createOspfArea(); | ||
101 | + ospfInterface = createOspfInterface(); | ||
102 | + ospfNbrHashMap = new HashMap(); | ||
103 | + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); | ||
104 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
105 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
106 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
107 | + ospfInterface) | ||
108 | + , topologyForDeviceAndLink); | ||
109 | + ospfNbr.setNeighborId(Ip4Address.valueOf("10.10.10.10")); | ||
110 | + ospfNbr.setRouterPriority(0); | ||
111 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
112 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
113 | + controller = new Controller(); | ||
114 | + ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(); | ||
115 | + ospfInterfaceChannelHandler = new OspfInterfaceChannelHandler(controller, ospfArea, | ||
116 | + ospfInterface); | ||
117 | + } | ||
118 | + | ||
119 | + @After | ||
120 | + public void tearDown() throws Exception { | ||
121 | + ospfInterfaceChannelHandler = null; | ||
122 | + addressRanges = null; | ||
123 | + ospfInterfaces = null; | ||
124 | + controller = null; | ||
125 | + ospfArea = null; | ||
126 | + ospfInterfaceChannelHandler = null; | ||
127 | + ospfInterface = null; | ||
128 | + ospfNbrHashMap = null; | ||
129 | + channel = null; | ||
130 | + channelHandlerContext = null; | ||
131 | + channelStateEvent = null; | ||
132 | + helloPacket = null; | ||
133 | + ddPacket = null; | ||
134 | + checksumCalculator = null; | ||
135 | + byteArray = null; | ||
136 | + checkArray = null; | ||
137 | + ospfEligibleRouter = null; | ||
138 | + lsUpdate = null; | ||
139 | + lsAck = null; | ||
140 | + lsRequest = null; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Tests interfaceUp() method. | ||
145 | + */ | ||
146 | + @Test | ||
147 | + public void testInterfaceUp() throws Exception { | ||
148 | + ospfInterface.setInterfaceType(2); | ||
149 | + ospfInterface.setRouterPriority(0); | ||
150 | + ospfInterfaceChannelHandler.interfaceUp(); | ||
151 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Tests interfaceUp() method. | ||
156 | + */ | ||
157 | + @Test | ||
158 | + public void testInterfaceUp1() throws Exception { | ||
159 | + | ||
160 | + ospfInterface.setInterfaceType(2); | ||
161 | + ospfInterface.setRouterPriority(0); | ||
162 | + ospfInterfaceChannelHandler.interfaceUp(); | ||
163 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests interfaceUp() method. | ||
168 | + */ | ||
169 | + @Test | ||
170 | + public void testInterfaceUp2() throws Exception { | ||
171 | + ospfInterface.setInterfaceType(1); | ||
172 | + ospfInterface.setRouterPriority(1); | ||
173 | + ospfInterfaceChannelHandler.interfaceUp(); | ||
174 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * Tests interfaceUp() method. | ||
179 | + */ | ||
180 | + @Test | ||
181 | + public void testInterfaceUp3() throws Exception { | ||
182 | + ospfInterface.setInterfaceType(2); | ||
183 | + ospfInterface.setRouterPriority(1); | ||
184 | + ospfInterfaceChannelHandler.interfaceUp(); | ||
185 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Tests backupSeen() method. | ||
190 | + */ | ||
191 | + @Test | ||
192 | + public void testBackupSeen() throws Exception { | ||
193 | + channel = EasyMock.createMock(Channel.class); | ||
194 | + ospfInterface.setState(OspfInterfaceState.WAITING); | ||
195 | + ospfInterfaceChannelHandler.backupSeen(channel); | ||
196 | + assertThat(ospfInterface.dr(), is(notNullValue())); | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Tests waitTimer() method. | ||
201 | + */ | ||
202 | + @Test | ||
203 | + public void testWaitTimer() throws Exception { | ||
204 | + channel = EasyMock.createMock(Channel.class); | ||
205 | + ospfInterface.setState(OspfInterfaceState.WAITING); | ||
206 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10")); | ||
207 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
208 | + ospfInterfaceChannelHandler.waitTimer(channel); | ||
209 | + assertThat(ospfInterface.dr(), is(notNullValue())); | ||
210 | + } | ||
211 | + | ||
212 | + /** | ||
213 | + * Tests neighborChange() method. | ||
214 | + */ | ||
215 | + @Test | ||
216 | + public void testNeighborChange() throws Exception { | ||
217 | + ospfNbrHashMap = new HashMap(); | ||
218 | + ospfNbr = new OspfNbrImpl(new OspfAreaImpl(), new OspfInterfaceImpl(), | ||
219 | + Ip4Address.valueOf("1.1.1.1"), Ip4Address.valueOf("2.2.2.2"), 2, | ||
220 | + new OspfInterfaceChannelHandler(new Controller(), | ||
221 | + new OspfAreaImpl(), | ||
222 | + new OspfInterfaceImpl()) | ||
223 | + , topologyForDeviceAndLink); | ||
224 | + ospfNbr.setNeighborId(Ip4Address.valueOf("111.111.111.111")); | ||
225 | + ospfNbrHashMap.put("111.111.111.111", ospfNbr); | ||
226 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
227 | + ospfInterface.setListOfNeighbors(ospfNbrHashMap); | ||
228 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10")); | ||
229 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
230 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.10")); | ||
231 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
232 | + channel = EasyMock.createMock(Channel.class); | ||
233 | + ospfInterface.setState(OspfInterfaceState.DR); | ||
234 | + ospfInterfaceChannelHandler.waitTimer(channel); | ||
235 | + assertThat(ospfInterface.dr(), is(Ip4Address.valueOf("0.0.0.0"))); | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Tests interfaceDown() method. | ||
240 | + */ | ||
241 | + @Test(expected = Exception.class) | ||
242 | + public void testInterfaceDown() throws Exception { | ||
243 | + ospfInterfaceChannelHandler.interfaceDown(); | ||
244 | + assertThat(ospfInterface.state(), is(OspfInterfaceState.DOWN)); | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Tests channelConnected() method. | ||
249 | + */ | ||
250 | + @Test(expected = Exception.class) | ||
251 | + public void testChannelConnected() throws Exception { | ||
252 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
253 | + channelStateEvent = EasyMock.createMock(ChannelStateEvent.class); | ||
254 | + ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent); | ||
255 | + assertThat(ospfInterface.state(), is(notNullValue())); | ||
256 | + } | ||
257 | + | ||
258 | + /** | ||
259 | + * Tests exceptionCaught() method. | ||
260 | + */ | ||
261 | + @Test(expected = Exception.class) | ||
262 | + public void testExceptionCaught() throws Exception { | ||
263 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
264 | + ExceptionEvent exception = EasyMock.createMock(ExceptionEvent.class); | ||
265 | + ospfInterfaceChannelHandler.exceptionCaught(channelHandlerContext, exception); | ||
266 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
267 | + } | ||
268 | + | ||
269 | + /** | ||
270 | + * Tests channelDisconnected() method. | ||
271 | + */ | ||
272 | + @Test(expected = Exception.class) | ||
273 | + public void testChannelDisconnected() throws Exception { | ||
274 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
275 | + channelStateEvent = EasyMock.createMock(ChannelStateEvent.class); | ||
276 | + | ||
277 | + ospfInterfaceChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent); | ||
278 | + | ||
279 | + assertThat(ospfInterface.state(), is(notNullValue())); | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * Tests messageReceived() method. | ||
284 | + */ | ||
285 | + @Test | ||
286 | + public void testMessageReceived() throws Exception { | ||
287 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
288 | + ospfInterface.setInterfaceType(2); | ||
289 | + ospfArea.setAreaId(Ip4Address.valueOf("13.13.13.13")); | ||
290 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
291 | + MessageEvent messageEvent = new MessageEvent() { | ||
292 | + @Override | ||
293 | + public Object getMessage() { | ||
294 | + helloPacket = new HelloPacket(); | ||
295 | + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
296 | + helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
297 | + helloPacket.setOspfVer(2); | ||
298 | + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
299 | + helloPacket.setOptions(2); | ||
300 | + helloPacket.setAreaId(Ip4Address.valueOf("5.5.5.5")); | ||
301 | + helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3")); | ||
302 | + helloPacket.setOspftype(1); | ||
303 | + helloPacket.setAuthType(0); | ||
304 | + helloPacket.setAuthentication(0); | ||
305 | + checksumCalculator = new ChecksumCalculator(); | ||
306 | + byteArray = helloPacket.asBytes(); | ||
307 | + helloPacket.setOspfPacLength(byteArray.length); | ||
308 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
309 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
310 | + helloPacket.setChecksum(buf.readUnsignedShort()); | ||
311 | + List<HelloPacket> messPackets = new ArrayList<>(); | ||
312 | + messPackets.add(helloPacket); | ||
313 | + return messPackets; | ||
314 | + } | ||
315 | + | ||
316 | + @Override | ||
317 | + public SocketAddress getRemoteAddress() { | ||
318 | + return null; | ||
319 | + } | ||
320 | + | ||
321 | + @Override | ||
322 | + public Channel getChannel() { | ||
323 | + return null; | ||
324 | + } | ||
325 | + | ||
326 | + @Override | ||
327 | + public ChannelFuture getFuture() { | ||
328 | + return null; | ||
329 | + } | ||
330 | + }; | ||
331 | + ospfInterfaceChannelHandler.messageReceived(channelHandlerContext, messageEvent); | ||
332 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
333 | + } | ||
334 | + | ||
335 | + /** | ||
336 | + * Tests processOSPFMessage() method. | ||
337 | + */ | ||
338 | + @Test | ||
339 | + public void testProcessOSPFMessage() throws Exception { | ||
340 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
341 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("225.225.225.225")); | ||
342 | + ospfInterface.setInterfaceType(2); | ||
343 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
344 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
345 | + OspfMessage message; | ||
346 | + helloPacket = new HelloPacket(); | ||
347 | + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
348 | + helloPacket.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
349 | + helloPacket.setOspfVer(2); | ||
350 | + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
351 | + helloPacket.setOptions(2); | ||
352 | + helloPacket.setNetworkMask(Ip4Address.valueOf("3.3.3.3")); | ||
353 | + helloPacket.setOspftype(1); | ||
354 | + helloPacket.setAuthType(0); | ||
355 | + helloPacket.setHelloInterval(60); | ||
356 | + helloPacket.setRouterDeadInterval(60); | ||
357 | + helloPacket.setAuthentication(0); | ||
358 | + checksumCalculator = new ChecksumCalculator(); | ||
359 | + byteArray = helloPacket.asBytes(); | ||
360 | + helloPacket.setOspfPacLength(byteArray.length); | ||
361 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
362 | + checkArray[0] = -53; | ||
363 | + checkArray[1] = 37; | ||
364 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
365 | + helloPacket.setChecksum(buf.readUnsignedShort()); | ||
366 | + message = helloPacket; | ||
367 | + ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext); | ||
368 | + ddPacket = new DdPacket(); | ||
369 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
370 | + ddPacket.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
371 | + ddPacket.setOspfVer(2); | ||
372 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
373 | + ddPacket.setOptions(2); | ||
374 | + ddPacket.setOspftype(2); | ||
375 | + ddPacket.setAuthType(0); | ||
376 | + ddPacket.setAuthentication(0); | ||
377 | + checksumCalculator = new ChecksumCalculator(); | ||
378 | + byteArray = ddPacket.asBytes(); | ||
379 | + ddPacket.setOspfPacLength(byteArray.length); | ||
380 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
381 | + checkArray[0] = -49; | ||
382 | + checkArray[1] = -79; | ||
383 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
384 | + ddPacket.setChecksum(buf.readUnsignedShort()); | ||
385 | + message = ddPacket; | ||
386 | + ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext); | ||
387 | + lsRequest = new LsRequest(); | ||
388 | + lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
389 | + lsRequest.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
390 | + lsRequest.setOspfVer(2); | ||
391 | + lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
392 | + lsRequest.setOspftype(3); | ||
393 | + lsRequest.setAuthType(0); | ||
394 | + lsRequest.setAuthentication(0); | ||
395 | + checksumCalculator = new ChecksumCalculator(); | ||
396 | + byteArray = lsRequest.asBytes(); | ||
397 | + lsRequest.setOspfPacLength(byteArray.length); | ||
398 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
399 | + checkArray[0] = -33; | ||
400 | + checkArray[1] = -58; | ||
401 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
402 | + lsRequest.setChecksum(buf.readUnsignedShort()); | ||
403 | + message = lsRequest; | ||
404 | + ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext); | ||
405 | + lsUpdate = new LsUpdate(); | ||
406 | + lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
407 | + lsUpdate.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
408 | + lsUpdate.setOspfVer(2); | ||
409 | + lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
410 | + lsUpdate.setOspftype(4); | ||
411 | + lsUpdate.setAuthType(0); | ||
412 | + lsUpdate.setAuthentication(0); | ||
413 | + checksumCalculator = new ChecksumCalculator(); | ||
414 | + byteArray = lsUpdate.asBytes(); | ||
415 | + lsUpdate.setOspfPacLength(byteArray.length); | ||
416 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
417 | + checkArray[0] = -47; | ||
418 | + checkArray[1] = -77; | ||
419 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
420 | + lsUpdate.setChecksum(buf.readUnsignedShort()); | ||
421 | + message = lsUpdate; | ||
422 | + ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext); | ||
423 | + lsAck = new LsAcknowledge(); | ||
424 | + lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
425 | + lsAck.setRouterId(Ip4Address.valueOf("10.10.10.10")); | ||
426 | + lsAck.setOspfVer(2); | ||
427 | + lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
428 | + lsAck.setOspftype(5); | ||
429 | + lsAck.setAuthType(0); | ||
430 | + lsAck.setAuthentication(0); | ||
431 | + checksumCalculator = new ChecksumCalculator(); | ||
432 | + byteArray = lsAck.asBytes(); | ||
433 | + lsAck.setOspfPacLength(byteArray.length); | ||
434 | + checkArray = checksumCalculator.calculateOspfCheckSum(byteArray, 12, 13); | ||
435 | + checkArray[0] = -47; | ||
436 | + checkArray[1] = -74; | ||
437 | + buf = ChannelBuffers.copiedBuffer(checkArray); | ||
438 | + lsAck.setChecksum(buf.readUnsignedShort()); | ||
439 | + message = lsAck; | ||
440 | + ospfInterfaceChannelHandler.processOSPFMessage(message, channelHandlerContext); | ||
441 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
442 | + | ||
443 | + } | ||
444 | + | ||
445 | + /** | ||
446 | + * Tests processHelloMessage() method. | ||
447 | + */ | ||
448 | + @Test | ||
449 | + public void testProcessHelloMessage() throws Exception { | ||
450 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
451 | + ospfInterface.setInterfaceType(1); | ||
452 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244")); | ||
453 | + ospfInterface.setHelloIntervalTime(10); | ||
454 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
455 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
456 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
457 | + OspfMessage message; | ||
458 | + helloPacket = new HelloPacket(); | ||
459 | + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
460 | + helloPacket.setOspfVer(2); | ||
461 | + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
462 | + helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244")); | ||
463 | + helloPacket.setHelloInterval(10); | ||
464 | + helloPacket.setRouterDeadInterval(10); | ||
465 | + helloPacket.setDr(Ip4Address.valueOf("10.10.10.10")); | ||
466 | + helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11")); | ||
467 | + helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111")); | ||
468 | + message = helloPacket; | ||
469 | + ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext); | ||
470 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
471 | + } | ||
472 | + | ||
473 | + /** | ||
474 | + * Tests processHelloMessage() method. | ||
475 | + */ | ||
476 | + @Test | ||
477 | + public void testProcessHelloMessage1() throws Exception { | ||
478 | + ospfInterface.setInterfaceType(2); | ||
479 | + ospfInterface.setRouterPriority(1); | ||
480 | + ospfInterfaceChannelHandler.interfaceUp(); | ||
481 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
482 | + ospfInterface.setState(OspfInterfaceState.WAITING); | ||
483 | + ospfInterface.setInterfaceType(2); | ||
484 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244")); | ||
485 | + ospfInterface.setHelloIntervalTime(10); | ||
486 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
487 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
488 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
489 | + OspfMessage message; | ||
490 | + helloPacket = new HelloPacket(); | ||
491 | + helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
492 | + helloPacket.setOspfVer(2); | ||
493 | + helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
494 | + helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244")); | ||
495 | + helloPacket.setHelloInterval(10); | ||
496 | + helloPacket.setRouterDeadInterval(10); | ||
497 | + helloPacket.setDr(Ip4Address.valueOf("10.10.10.10")); | ||
498 | + helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11")); | ||
499 | + helloPacket.setRouterId(Ip4Address.valueOf("2.2.2.2")); | ||
500 | + message = helloPacket; | ||
501 | + ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext); | ||
502 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
503 | + ospfNbrHashMap = new HashMap(); | ||
504 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
505 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
506 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
507 | + ospfInterface) | ||
508 | + , topologyForDeviceAndLink); | ||
509 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
510 | + ospfNbr.setRouterPriority(0); | ||
511 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
512 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
513 | + ospfInterfaceChannelHandler.processHelloMessage(message, channelHandlerContext); | ||
514 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
515 | + } | ||
516 | + | ||
517 | + /** | ||
518 | + * Tests processDdMessage() method. | ||
519 | + */ | ||
520 | + @Test | ||
521 | + public void testProcessDdMessage() throws Exception { | ||
522 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
523 | + ospfInterface.setInterfaceType(2); | ||
524 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
525 | + ospfInterface.setHelloIntervalTime(10); | ||
526 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
527 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
528 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
529 | + OspfMessage message; | ||
530 | + ddPacket = new DdPacket(); | ||
531 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
532 | + ddPacket.setOspfVer(2); | ||
533 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
534 | + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2")); | ||
535 | + ddPacket.setIsOpaqueCapable(true); | ||
536 | + ddPacket.setIsMore(1); | ||
537 | + ddPacket.setIsInitialize(1); | ||
538 | + ddPacket.setIsMaster(1); | ||
539 | + ddPacket.setSequenceNo(123); | ||
540 | + message = ddPacket; | ||
541 | + ospfNbrHashMap = new HashMap(); | ||
542 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
543 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
544 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
545 | + ospfInterface) | ||
546 | + , topologyForDeviceAndLink); | ||
547 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
548 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
549 | + ospfNbr.setState(OspfNeighborState.EXSTART); | ||
550 | + ospfNbr.setRouterPriority(0); | ||
551 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
552 | + ospfNbr.setDdSeqNum(123); | ||
553 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
554 | + ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext); | ||
555 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
556 | + } | ||
557 | + | ||
558 | + /** | ||
559 | + * Tests processDdMessage() method. | ||
560 | + */ | ||
561 | + @Test(expected = Exception.class) | ||
562 | + public void testProcessDdMessage3() throws Exception { | ||
563 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
564 | + ospfInterface.setInterfaceType(2); | ||
565 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
566 | + ospfInterface.setHelloIntervalTime(10); | ||
567 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
568 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
569 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
570 | + OspfMessage message; | ||
571 | + ddPacket = new DdPacket(); | ||
572 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
573 | + ddPacket.setOspfVer(2); | ||
574 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
575 | + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2")); | ||
576 | + ddPacket.setIsOpaqueCapable(true); | ||
577 | + ddPacket.setIsMore(1); | ||
578 | + ddPacket.setIsInitialize(1); | ||
579 | + ddPacket.setIsMaster(1); | ||
580 | + ddPacket.setSequenceNo(123); | ||
581 | + message = ddPacket; | ||
582 | + ospfNbrHashMap = new HashMap(); | ||
583 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
584 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
585 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
586 | + ospfInterface) | ||
587 | + , topologyForDeviceAndLink); | ||
588 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
589 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
590 | + ospfNbr.setState(OspfNeighborState.EXSTART); | ||
591 | + ospfNbr.setRouterPriority(0); | ||
592 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
593 | + ospfNbr.setDdSeqNum(123); | ||
594 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
595 | + ddPacket.setIsMore(1); | ||
596 | + ddPacket.setIsInitialize(0); | ||
597 | + ddPacket.setIsMaster(0); | ||
598 | + ddPacket.setSequenceNo(123); | ||
599 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
600 | + ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext); | ||
601 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
602 | + } | ||
603 | + | ||
604 | + /** | ||
605 | + * Tests processDdMessage() method. | ||
606 | + */ | ||
607 | + @Test(expected = Exception.class) | ||
608 | + public void testProcessDdMessage1() throws Exception { | ||
609 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
610 | + ospfInterface.setInterfaceType(2); | ||
611 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
612 | + ospfInterface.setHelloIntervalTime(10); | ||
613 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
614 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
615 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
616 | + OspfMessage message; | ||
617 | + ddPacket = new DdPacket(); | ||
618 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
619 | + ddPacket.setOspfVer(2); | ||
620 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
621 | + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2")); | ||
622 | + ddPacket.setIsOpaqueCapable(true); | ||
623 | + ddPacket.setIsMore(1); | ||
624 | + ddPacket.setIsInitialize(1); | ||
625 | + ddPacket.setIsMaster(1); | ||
626 | + ddPacket.setSequenceNo(123); | ||
627 | + message = ddPacket; | ||
628 | + ospfNbrHashMap = new HashMap(); | ||
629 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
630 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
631 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
632 | + ospfInterface) | ||
633 | + , topologyForDeviceAndLink); | ||
634 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
635 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
636 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
637 | + ospfNbr.setRouterPriority(0); | ||
638 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
639 | + ospfNbr.setDdSeqNum(123); | ||
640 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
641 | + ddPacket.setIsMore(1); | ||
642 | + ddPacket.setIsInitialize(0); | ||
643 | + ddPacket.setIsMaster(0); | ||
644 | + ddPacket.setSequenceNo(123); | ||
645 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
646 | + ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext); | ||
647 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
648 | + | ||
649 | + } | ||
650 | + | ||
651 | + /** | ||
652 | + * Tests processDdMessage() method. | ||
653 | + */ | ||
654 | + @Test(expected = Exception.class) | ||
655 | + public void testProcessDdMessage2() throws Exception { | ||
656 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
657 | + ospfInterface.setInterfaceType(2); | ||
658 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
659 | + ospfInterface.setHelloIntervalTime(10); | ||
660 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
661 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
662 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
663 | + OspfMessage message; | ||
664 | + ddPacket = new DdPacket(); | ||
665 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
666 | + ddPacket.setOspfVer(2); | ||
667 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
668 | + ddPacket.setRouterId(Ip4Address.valueOf("2.2.2.2")); | ||
669 | + ddPacket.setIsOpaqueCapable(true); | ||
670 | + ddPacket.setIsMore(1); | ||
671 | + ddPacket.setIsInitialize(1); | ||
672 | + ddPacket.setIsMaster(1); | ||
673 | + ddPacket.setSequenceNo(123); | ||
674 | + message = ddPacket; | ||
675 | + ospfNbrHashMap = new HashMap(); | ||
676 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.10.10.10"), | ||
677 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
678 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
679 | + ospfInterface) | ||
680 | + , topologyForDeviceAndLink); | ||
681 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
682 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
683 | + ospfNbr.setState(OspfNeighborState.LOADING); | ||
684 | + ospfNbr.setRouterPriority(0); | ||
685 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
686 | + ospfNbr.setDdSeqNum(123); | ||
687 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
688 | + ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext); | ||
689 | + ddPacket.setIsMore(1); | ||
690 | + ddPacket.setIsInitialize(0); | ||
691 | + ddPacket.setIsMaster(0); | ||
692 | + ddPacket.setSequenceNo(123); | ||
693 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
694 | + ospfNbr.setState(OspfNeighborState.LOADING); | ||
695 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
696 | + | ||
697 | + ospfInterfaceChannelHandler.processDdMessage(message, channelHandlerContext); | ||
698 | + | ||
699 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
700 | + | ||
701 | + } | ||
702 | + | ||
703 | + /** | ||
704 | + * Tests processLsRequestMessage() method. | ||
705 | + */ | ||
706 | + @Test | ||
707 | + public void testProcessLSRequestMessage() throws Exception { | ||
708 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
709 | + ospfInterface.setInterfaceType(2); | ||
710 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
711 | + ospfInterface.setHelloIntervalTime(10); | ||
712 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
713 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
714 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
715 | + OspfMessage message; | ||
716 | + lsRequest = new LsRequest(); | ||
717 | + lsRequest.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
718 | + lsRequest.setOspfVer(2); | ||
719 | + lsRequest.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
720 | + lsRequest.setRouterId(Ip4Address.valueOf("10.226.165.100")); | ||
721 | + List<LsRequestPacket> lsRequests = new ArrayList(); | ||
722 | + LsRequestPacket lsRequestPacket = new LsRequestPacket(); | ||
723 | + lsRequestPacket.setLsType(3); | ||
724 | + lsRequestPacket.setLinkStateId("2.2.2.2"); | ||
725 | + lsRequestPacket.setOwnRouterId("2.2.2.2"); | ||
726 | + lsRequests.add(lsRequestPacket); | ||
727 | + lsRequests.add(lsRequestPacket); | ||
728 | + lsRequest.addLinkStateRequests(new LsRequestPacket()); | ||
729 | + lsRequest.addLinkStateRequests(new LsRequestPacket()); | ||
730 | + message = lsRequest; | ||
731 | + ospfNbrHashMap = new HashMap(); | ||
732 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
733 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
734 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
735 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
736 | + createOspfInterface1()) | ||
737 | + , topologyForDeviceAndLink); | ||
738 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
739 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
740 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
741 | + ospfNbr.setRouterPriority(0); | ||
742 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
743 | + ospfNbr.setDdSeqNum(123); | ||
744 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
745 | + ospfInterface.setListOfNeighbors(ospfNbrHashMap); | ||
746 | + ospfInterfaceChannelHandler.processLsRequestMessage(message, channelHandlerContext); | ||
747 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
748 | + | ||
749 | + } | ||
750 | + | ||
751 | + /** | ||
752 | + * Tests processLsUpdateMessage() method. | ||
753 | + */ | ||
754 | + @Test | ||
755 | + public void testProcessLSUpdateMessage() throws Exception { | ||
756 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
757 | + ospfInterface.setInterfaceType(2); | ||
758 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
759 | + ospfInterface.setHelloIntervalTime(10); | ||
760 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
761 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
762 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
763 | + OspfMessage message; | ||
764 | + lsUpdate = new LsUpdate(); | ||
765 | + lsUpdate.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
766 | + lsUpdate.setOspfVer(2); | ||
767 | + lsUpdate.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
768 | + lsUpdate.setRouterId(Ip4Address.valueOf("10.226.165.100")); | ||
769 | + RouterLsa routerLsa = new RouterLsa(); | ||
770 | + lsUpdate.addLsa(routerLsa); | ||
771 | + lsUpdate.setNumberOfLsa(1); | ||
772 | + message = lsUpdate; | ||
773 | + ospfNbrHashMap = new HashMap(); | ||
774 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
775 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
776 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
777 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
778 | + createOspfInterface1()) | ||
779 | + , topologyForDeviceAndLink); | ||
780 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
781 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
782 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
783 | + ospfNbr.setRouterPriority(0); | ||
784 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
785 | + ospfNbr.setDdSeqNum(123); | ||
786 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
787 | + ospfInterfaceChannelHandler.processLsUpdateMessage(message, channelHandlerContext); | ||
788 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
789 | + | ||
790 | + } | ||
791 | + | ||
792 | + @Test(expected = Exception.class) | ||
793 | + public void testProcessLSAckMessage() throws Exception { | ||
794 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
795 | + ospfInterface.setInterfaceType(2); | ||
796 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
797 | + ospfInterface.setHelloIntervalTime(10); | ||
798 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
799 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
800 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
801 | + OspfMessage message; | ||
802 | + lsAck = new LsAcknowledge(); | ||
803 | + lsAck.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
804 | + lsAck.setOspfVer(2); | ||
805 | + lsAck.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
806 | + LsaHeader lsaHeader = new LsaHeader(); | ||
807 | + lsAck.addLinkStateHeader(lsaHeader); | ||
808 | + message = lsAck; | ||
809 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
810 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
811 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
812 | + createOspfInterface()) | ||
813 | + , topologyForDeviceAndLink); | ||
814 | + ospfNbr.setLastDdPacket(createDdPacket()); | ||
815 | + ospfNbr.setNeighborId(Ip4Address.valueOf("2.2.2.2")); | ||
816 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
817 | + ospfNbr.setRouterPriority(0); | ||
818 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("13.13.13.13")); | ||
819 | + ospfNbr.setDdSeqNum(123); | ||
820 | + ospfInterfaceChannelHandler.processLsAckMessage(message, channelHandlerContext); | ||
821 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
822 | + | ||
823 | + } | ||
824 | + | ||
825 | + /** | ||
826 | + * Tests compareDdPackets() method. | ||
827 | + */ | ||
828 | + @Test | ||
829 | + public void testCompareDDPackets() throws Exception { | ||
830 | + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); | ||
831 | + ospfInterface.setInterfaceType(2); | ||
832 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
833 | + ospfInterface.setHelloIntervalTime(10); | ||
834 | + ospfInterface.setRouterDeadIntervalTime(10); | ||
835 | + ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
836 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
837 | + OspfMessage message; | ||
838 | + ddPacket = new DdPacket(); | ||
839 | + ddPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); | ||
840 | + ddPacket.setOspfVer(2); | ||
841 | + ddPacket.setIsInitialize(1); | ||
842 | + ddPacket.setIsMaster(1); | ||
843 | + ddPacket.setIsMore(1); | ||
844 | + ddPacket.setOptions(2); | ||
845 | + ddPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); | ||
846 | + assertThat(ospfInterfaceChannelHandler.compareDdPackets(ddPacket, ddPacket), is(true)); | ||
847 | + } | ||
848 | + | ||
849 | + @Test(expected = Exception.class) | ||
850 | + public void testCloseChannel() throws Exception { | ||
851 | + channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); | ||
852 | + | ||
853 | + ospfInterfaceChannelHandler.closeChannel(channelHandlerContext); | ||
854 | + | ||
855 | + assertThat(ospfInterface.dr(), is(notNullValue())); | ||
856 | + } | ||
857 | + | ||
858 | + /** | ||
859 | + * Tests electRouter() method. | ||
860 | + */ | ||
861 | + @Test | ||
862 | + public void testElectRouter() throws Exception { | ||
863 | + ospfInterface.setDr(Ip4Address.valueOf("3.3.3.3")); | ||
864 | + ospfInterface.setBdr(Ip4Address.valueOf("3.3.3.3")); | ||
865 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
866 | + ChannelConfig channelConfig = EasyMock.createMock(ChannelConfig.class); | ||
867 | + EasyMock.expect(channelConfig.getBufferFactory()).andReturn(new HeapChannelBufferFactory()); | ||
868 | + Channel channel = EasyMock.createMock(Channel.class); | ||
869 | + ospfInterfaceChannelHandler.electRouter(channel); | ||
870 | + assertThat(ospfInterface.dr(), is(notNullValue())); | ||
871 | + } | ||
872 | + | ||
873 | + /** | ||
874 | + * Tests electBdr() method. | ||
875 | + */ | ||
876 | + @Test | ||
877 | + public void testElectBdr() throws Exception { | ||
878 | + ospfEligibleRouter = new OspfEligibleRouter(); | ||
879 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
880 | + ospfEligibleRouter.setIsDr(true); | ||
881 | + ospfEligibleRouter.setRouterPriority(10); | ||
882 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
883 | + ospfEligibleRouter.setIsBdr(false); | ||
884 | + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter(); | ||
885 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
886 | + ospfEligibleRouter.setIsDr(true); | ||
887 | + ospfEligibleRouter.setRouterPriority(10); | ||
888 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
889 | + ospfEligibleRouter.setIsBdr(false); | ||
890 | + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter(); | ||
891 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
892 | + ospfEligibleRouter.setIsDr(true); | ||
893 | + ospfEligibleRouter.setRouterPriority(10); | ||
894 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
895 | + ospfEligibleRouter.setIsBdr(false); | ||
896 | + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>(); | ||
897 | + | ||
898 | + ospfEligibleRouters.add(ospfEligibleRouter); | ||
899 | + ospfEligibleRouters.add(ospfEligibleRouter1); | ||
900 | + ospfEligibleRouters.add(ospfEligibleRouter2); | ||
901 | + OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electBdr(ospfEligibleRouters); | ||
902 | + assertThat(ospfEligibleRouters.size(), is(3)); | ||
903 | + assertThat(eligibleRouter, is(notNullValue())); | ||
904 | + } | ||
905 | + | ||
906 | + /** | ||
907 | + * Tests electDr() method. | ||
908 | + */ | ||
909 | + @Test | ||
910 | + public void testElectDR() throws Exception { | ||
911 | + ospfEligibleRouter = new OspfEligibleRouter(); | ||
912 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
913 | + ospfEligibleRouter.setIsDr(true); | ||
914 | + ospfEligibleRouter.setRouterPriority(10); | ||
915 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
916 | + ospfEligibleRouter.setIsBdr(false); | ||
917 | + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter(); | ||
918 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
919 | + ospfEligibleRouter.setIsDr(true); | ||
920 | + ospfEligibleRouter.setRouterPriority(10); | ||
921 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
922 | + ospfEligibleRouter.setIsBdr(false); | ||
923 | + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter(); | ||
924 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
925 | + ospfEligibleRouter.setIsDr(true); | ||
926 | + ospfEligibleRouter.setRouterPriority(10); | ||
927 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
928 | + ospfEligibleRouter.setIsBdr(false); | ||
929 | + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>(); | ||
930 | + ospfEligibleRouters.add(ospfEligibleRouter); | ||
931 | + ospfEligibleRouters.add(ospfEligibleRouter1); | ||
932 | + ospfEligibleRouters.add(ospfEligibleRouter2); | ||
933 | + OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.electDr(ospfEligibleRouters, | ||
934 | + ospfEligibleRouter); | ||
935 | + assertThat(ospfEligibleRouters.size(), is(3)); | ||
936 | + assertThat(eligibleRouter, is(notNullValue())); | ||
937 | + } | ||
938 | + | ||
939 | + /** | ||
940 | + * Tests selectRouterBasedOnPriority() method. | ||
941 | + */ | ||
942 | + @Test | ||
943 | + public void testSelectRouterBasedOnPriority() throws Exception { | ||
944 | + ospfEligibleRouter = new OspfEligibleRouter(); | ||
945 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
946 | + ospfEligibleRouter.setIsDr(true); | ||
947 | + ospfEligibleRouter.setRouterPriority(10); | ||
948 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
949 | + ospfEligibleRouter.setIsBdr(false); | ||
950 | + OspfEligibleRouter ospfEligibleRouter1 = new OspfEligibleRouter(); | ||
951 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
952 | + ospfEligibleRouter.setIsDr(true); | ||
953 | + ospfEligibleRouter.setRouterPriority(11); | ||
954 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
955 | + ospfEligibleRouter.setIsBdr(false); | ||
956 | + OspfEligibleRouter ospfEligibleRouter2 = new OspfEligibleRouter(); | ||
957 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
958 | + ospfEligibleRouter.setIsDr(true); | ||
959 | + ospfEligibleRouter.setRouterPriority(12); | ||
960 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
961 | + ospfEligibleRouter.setIsBdr(false); | ||
962 | + List<OspfEligibleRouter> ospfEligibleRouters = new ArrayList<>(); | ||
963 | + ospfEligibleRouters.add(ospfEligibleRouter); | ||
964 | + ospfEligibleRouters.add(ospfEligibleRouter1); | ||
965 | + ospfEligibleRouters.add(ospfEligibleRouter2); | ||
966 | + OspfEligibleRouter eligibleRouter = ospfInterfaceChannelHandler.selectRouterBasedOnPriority( | ||
967 | + ospfEligibleRouters); | ||
968 | + assertThat(eligibleRouter, is(notNullValue())); | ||
969 | + } | ||
970 | + | ||
971 | + /** | ||
972 | + * Tests addDeviceInformation() method. | ||
973 | + */ | ||
974 | + @Test(expected = Exception.class) | ||
975 | + public void testAddDeviceInformation() throws Exception { | ||
976 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
977 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
978 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
979 | + createOspfInterface()) | ||
980 | + , topologyForDeviceAndLink); | ||
981 | + | ||
982 | + ospfInterfaceChannelHandler.addDeviceInformation(new OspfRouterImpl()); | ||
983 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
984 | + } | ||
985 | + | ||
986 | + /** | ||
987 | + * Tests removeDeviceInformation() method. | ||
988 | + */ | ||
989 | + @Test(expected = Exception.class) | ||
990 | + public void testRemoveDeviceInformation() throws Exception { | ||
991 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
992 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
993 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
994 | + createOspfInterface()) | ||
995 | + , topologyForDeviceAndLink); | ||
996 | + | ||
997 | + ospfInterfaceChannelHandler.removeDeviceInformation(new OspfRouterImpl()); | ||
998 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
999 | + } | ||
1000 | + | ||
1001 | + /** | ||
1002 | + * Tests addLinkInformation() method. | ||
1003 | + */ | ||
1004 | + @Test(expected = Exception.class) | ||
1005 | + public void testaddLinkInformation() throws Exception { | ||
1006 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
1007 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
1008 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
1009 | + createOspfInterface()) | ||
1010 | + , topologyForDeviceAndLink); | ||
1011 | + | ||
1012 | + List topTlv = new ArrayList(); | ||
1013 | + topTlv.add(new RouterTlv(new TlvHeader())); | ||
1014 | + ospfInterfaceChannelHandler.addLinkInformation(new OspfRouterImpl(), new OspfLinkTedImpl()); | ||
1015 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
1016 | + } | ||
1017 | + | ||
1018 | + /** | ||
1019 | + * Tests removeLinkInformation() method. | ||
1020 | + */ | ||
1021 | + @Test(expected = Exception.class) | ||
1022 | + public void testRemoveLinkInformation() throws Exception { | ||
1023 | + ospfNbr = new OspfNbrImpl(ospfArea, createOspfInterface(), Ip4Address.valueOf("10.10.10.10"), | ||
1024 | + Ip4Address.valueOf("10.226.165.100"), 2, | ||
1025 | + new OspfInterfaceChannelHandler(new Controller(), ospfArea, | ||
1026 | + createOspfInterface()) | ||
1027 | + , topologyForDeviceAndLink); | ||
1028 | + | ||
1029 | + ospfInterfaceChannelHandler.removeLinkInformation(ospfNbr); | ||
1030 | + assertThat(ospfInterfaceChannelHandler, is(notNullValue())); | ||
1031 | + } | ||
1032 | + | ||
1033 | + /** | ||
1034 | + * Utility for test method. | ||
1035 | + */ | ||
1036 | + private DdPacket createDdPacket() throws OspfParseException { | ||
1037 | + byte[] ddPacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, | ||
1038 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126}; | ||
1039 | + DdPacket ddPacket1 = new DdPacket(); | ||
1040 | + ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length); | ||
1041 | + buf.writeBytes(ddPacket); | ||
1042 | + ddPacket1.readFrom(buf); | ||
1043 | + return ddPacket1; | ||
1044 | + } | ||
1045 | + | ||
1046 | + /** | ||
1047 | + * Utility for test method. | ||
1048 | + */ | ||
1049 | + private OspfInterfaceImpl createOspfInterface() throws UnknownHostException { | ||
1050 | + ospfInterface = new OspfInterfaceImpl(); | ||
1051 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
1052 | + OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock( | ||
1053 | + OspfInterfaceChannelHandler.class); | ||
1054 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"), | ||
1055 | + Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler | ||
1056 | + , topologyForDeviceAndLink); | ||
1057 | + ospfNbr.setState(OspfNeighborState.EXSTART); | ||
1058 | + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100")); | ||
1059 | + this.ospfInterface = new OspfInterfaceImpl(); | ||
1060 | + this.ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164")); | ||
1061 | + this.ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
1062 | + this.ospfInterface.setAreaId(2); | ||
1063 | + this.ospfInterface.setAuthKey("authKey"); | ||
1064 | + this.ospfInterface.setAuthType("AuthReq"); | ||
1065 | + this.ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111")); | ||
1066 | + this.ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111")); | ||
1067 | + this.ospfInterface.setHelloIntervalTime(20); | ||
1068 | + this.ospfInterface.setInterfaceCost(10); | ||
1069 | + this.ospfInterface.setInterfaceType(2); | ||
1070 | + this.ospfInterface.setReTransmitInterval(2000); | ||
1071 | + this.ospfInterface.setMtu(6500); | ||
1072 | + this.ospfInterface.setPollInterval(1000); | ||
1073 | + this.ospfInterface.setRouterDeadIntervalTime(1000); | ||
1074 | + this.ospfInterface.setRouterPriority(1); | ||
1075 | + this.ospfInterface.setTransmitDelay(500); | ||
1076 | + this.ospfInterface.setInterfaceType(1); | ||
1077 | + this.ospfInterface.addNeighbouringRouter(ospfNbr); | ||
1078 | + return this.ospfInterface; | ||
1079 | + } | ||
1080 | + | ||
1081 | + /** | ||
1082 | + * Utility for test method. | ||
1083 | + */ | ||
1084 | + private OspfInterfaceImpl createOspfInterface1() throws UnknownHostException { | ||
1085 | + ospfInterface = new OspfInterfaceImpl(); | ||
1086 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
1087 | + OspfInterfaceChannelHandler ospfInterfaceChannelHandler = EasyMock.createMock( | ||
1088 | + OspfInterfaceChannelHandler.class); | ||
1089 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("10.226.165.164"), | ||
1090 | + Ip4Address.valueOf("1.1.1.1"), 2, ospfInterfaceChannelHandler | ||
1091 | + , topologyForDeviceAndLink); | ||
1092 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
1093 | + ospfNbr.setNeighborId(Ip4Address.valueOf("10.226.165.100")); | ||
1094 | + ospfInterface = new OspfInterfaceImpl(); | ||
1095 | + ospfInterface.setIpAddress(Ip4Address.valueOf("10.226.165.164")); | ||
1096 | + ospfInterface.setIpNetworkMask(Ip4Address.valueOf("255.255.255.255")); | ||
1097 | + ospfInterface.setAreaId(2); | ||
1098 | + ospfInterface.setAuthKey("authKey"); | ||
1099 | + ospfInterface.setAuthType("AuthReq"); | ||
1100 | + ospfInterface.setBdr(Ip4Address.valueOf("111.111.111.111")); | ||
1101 | + ospfInterface.setDr(Ip4Address.valueOf("111.111.111.111")); | ||
1102 | + ospfInterface.setHelloIntervalTime(20); | ||
1103 | + ospfInterface.setInterfaceCost(10); | ||
1104 | + ospfInterface.setInterfaceType(2); | ||
1105 | + ospfInterface.setReTransmitInterval(2000); | ||
1106 | + ospfInterface.setMtu(6500); | ||
1107 | + ospfInterface.setPollInterval(1000); | ||
1108 | + ospfInterface.setRouterDeadIntervalTime(1000); | ||
1109 | + ospfInterface.setRouterPriority(1); | ||
1110 | + ospfInterface.setTransmitDelay(500); | ||
1111 | + ospfInterface.setInterfaceType(1); | ||
1112 | + ospfInterface.addNeighbouringRouter(ospfNbr); | ||
1113 | + return ospfInterface; | ||
1114 | + } | ||
1115 | + | ||
1116 | + /** | ||
1117 | + * Utility for test method. | ||
1118 | + */ | ||
1119 | + private OspfAreaImpl createOspfArea() throws UnknownHostException { | ||
1120 | + OspfAreaAddressRangeImpl ospfAreaAddressRange; | ||
1121 | + ospfAreaAddressRange = createOspfAreaAddressRange(); | ||
1122 | + addressRanges.add(ospfAreaAddressRange); | ||
1123 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
1124 | + ospfArea.setStubCost(10); | ||
1125 | + ospfArea.setAreaId(Ip4Address.valueOf("10.226.165.164")); | ||
1126 | + ospfArea.setExternalRoutingCapability(true); | ||
1127 | + ospfArea.setTransitCapability(true); | ||
1128 | + ospfArea.setAddressRanges(addressRanges); | ||
1129 | + OspfInterfaceImpl ospfInterface = createOspfInterface(); | ||
1130 | + ospfInterfaces.add(ospfInterface); | ||
1131 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
1132 | + RouterLsa routerLsa = new RouterLsa(); | ||
1133 | + routerLsa.setLsType(1); | ||
1134 | + routerLsa.setLinkStateId("2.2.2.2"); | ||
1135 | + routerLsa.setAdvertisingRouter(Ip4Address.valueOf("2.2.2.2")); | ||
1136 | + try { | ||
1137 | + ospfArea.addLsa(routerLsa, false, ospfInterface); | ||
1138 | + } catch (Exception e) { | ||
1139 | + System.out.println("ospfAreaImpl createOspfArea"); | ||
1140 | + } | ||
1141 | + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); | ||
1142 | + | ||
1143 | + return ospfArea; | ||
1144 | + } | ||
1145 | + | ||
1146 | + /** | ||
1147 | + * Utility for test method. | ||
1148 | + */ | ||
1149 | + private OspfAreaAddressRangeImpl createOspfAreaAddressRange() { | ||
1150 | + OspfAreaAddressRangeImpl ospfAreaAddressRange = new OspfAreaAddressRangeImpl(); | ||
1151 | + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("10.226.165.164")); | ||
1152 | + ospfAreaAddressRange.setAdvertise(true); | ||
1153 | + ospfAreaAddressRange.setMask("mask"); | ||
1154 | + return ospfAreaAddressRange; | ||
1155 | + } | ||
1156 | + | ||
1157 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfNbrImplTest.java
0 → 100755
1 | +/* | ||
2 | + * Copyright 2016 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 | + */ | ||
16 | +package org.onosproject.ospf.controller.impl; | ||
17 | + | ||
18 | + | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.jboss.netty.channel.Channel; | ||
21 | +import org.junit.After; | ||
22 | +import org.junit.Assert; | ||
23 | +import org.junit.Before; | ||
24 | +import org.junit.Test; | ||
25 | +import org.onlab.packet.Ip4Address; | ||
26 | +import org.onosproject.ospf.controller.OspfInterface; | ||
27 | +import org.onosproject.ospf.controller.OspfLsa; | ||
28 | +import org.onosproject.ospf.controller.OspfLsaType; | ||
29 | +import org.onosproject.ospf.controller.OspfNeighborState; | ||
30 | +import org.onosproject.ospf.controller.TopologyForDeviceAndLink; | ||
31 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
32 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
33 | +import org.onosproject.ospf.controller.lsdb.LsaWrapperImpl; | ||
34 | +import org.onosproject.ospf.controller.lsdb.LsdbAgeImpl; | ||
35 | +import org.onosproject.ospf.protocol.lsa.LsaHeader; | ||
36 | + | ||
37 | +import org.onosproject.ospf.protocol.lsa.types.NetworkLsa; | ||
38 | +import org.onosproject.ospf.protocol.lsa.types.RouterLsa; | ||
39 | +import org.onosproject.ospf.protocol.ospfpacket.OspfMessage; | ||
40 | +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket; | ||
41 | +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket; | ||
42 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest; | ||
43 | +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate; | ||
44 | +import org.onosproject.ospf.protocol.util.ChecksumCalculator; | ||
45 | + | ||
46 | +import org.onosproject.ospf.protocol.util.OspfUtil; | ||
47 | + | ||
48 | +import java.net.SocketAddress; | ||
49 | +import java.util.ArrayList; | ||
50 | +import java.util.List; | ||
51 | + | ||
52 | +import static org.hamcrest.CoreMatchers.is; | ||
53 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
54 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
55 | + | ||
56 | +/** | ||
57 | + * Unit test class for OspfNbrImpl. | ||
58 | + */ | ||
59 | +public class OspfNbrImplTest { | ||
60 | + | ||
61 | + private OspfNbrImpl ospfNbr; | ||
62 | + private OspfInterfaceImpl ospfInterface; | ||
63 | + private OspfAreaImpl ospfArea; | ||
64 | + private OspfInterfaceImpl ospfInterface1; | ||
65 | + private OspfInterfaceImpl ospfInterface2; | ||
66 | + private List<OspfInterface> ospfInterfaces; | ||
67 | + private List<OspfLsa> ospfLsaList; | ||
68 | + private Channel channel; | ||
69 | + private Channel channel1; | ||
70 | + private Channel channel2; | ||
71 | + private OspfMessage ospfMessage; | ||
72 | + private TopologyForDeviceAndLink topologyForDeviceAndLink; | ||
73 | + | ||
74 | + @Before | ||
75 | + public void setUp() throws Exception { | ||
76 | + ospfInterface = new OspfInterfaceImpl(); | ||
77 | + ospfInterface.setInterfaceType(2); | ||
78 | + ospfInterface.setRouterDeadIntervalTime(30); | ||
79 | + ospfInterface.setReTransmitInterval(30); | ||
80 | + ospfInterface.setDr(Ip4Address.valueOf("1.1.1.1")); | ||
81 | + ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
82 | + ospfArea = new OspfAreaImpl(); | ||
83 | + ospfInterface1 = new OspfInterfaceImpl(); | ||
84 | + ospfInterface1.setInterfaceType(2); | ||
85 | + ospfInterface1.setRouterDeadIntervalTime(30); | ||
86 | + ospfInterface1.setReTransmitInterval(30); | ||
87 | + ospfInterface1.setDr(Ip4Address.valueOf("7.7.7.7")); | ||
88 | + ospfInterface1.setIpAddress(Ip4Address.valueOf("7.7.7.7")); | ||
89 | + ospfInterface2 = new OspfInterfaceImpl(); | ||
90 | + ospfInterface2.setInterfaceType(2); | ||
91 | + ospfInterface2.setRouterDeadIntervalTime(30); | ||
92 | + ospfInterface2.setReTransmitInterval(30); | ||
93 | + ospfInterface2.setDr(Ip4Address.valueOf("6.6.6.6")); | ||
94 | + ospfInterface2.setIpAddress(Ip4Address.valueOf("6.6.6.6")); | ||
95 | + ospfInterfaces = new ArrayList(); | ||
96 | + ospfInterfaces.add(ospfInterface); | ||
97 | + ospfInterfaces.add(ospfInterface1); | ||
98 | + ospfInterfaces.add(ospfInterface2); | ||
99 | + ospfArea.setInterfacesLst(ospfInterfaces); | ||
100 | + ospfArea.setRouterId(Ip4Address.valueOf("111.111.111.111")); | ||
101 | + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); | ||
102 | + ospfNbr = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"), | ||
103 | + Ip4Address.valueOf("2.2.2.2"), 2, | ||
104 | + new OspfInterfaceChannelHandler(new Controller(), | ||
105 | + ospfArea, ospfInterface) | ||
106 | + , topologyForDeviceAndLink); | ||
107 | + | ||
108 | + } | ||
109 | + | ||
110 | + @After | ||
111 | + public void tearDown() throws Exception { | ||
112 | + ospfNbr = null; | ||
113 | + ospfArea = null; | ||
114 | + ospfInterface = null; | ||
115 | + ospfLsaList = null; | ||
116 | + channel = null; | ||
117 | + channel1 = null; | ||
118 | + channel2 = null; | ||
119 | + ospfMessage = null; | ||
120 | + | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * Tests neighborIpAddr() method. | ||
125 | + */ | ||
126 | + @Test | ||
127 | + public void testNeighborIpAddr() throws Exception { | ||
128 | + assertThat(ospfNbr.neighborIpAddr(), is(notNullValue())); | ||
129 | + } | ||
130 | + | ||
131 | + /** | ||
132 | + * Tests isOpaqueCapable() getter method. | ||
133 | + */ | ||
134 | + @Test | ||
135 | + public void testIsOpaqueCapable() throws Exception { | ||
136 | + assertThat(ospfNbr.isOpaqueCapable(), is(false)); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Tests isOpaqueCapable() setter method. | ||
141 | + */ | ||
142 | + @Test | ||
143 | + public void testSetIsOpaqueCapable() throws Exception { | ||
144 | + ospfNbr.setIsOpaqueCapable(true); | ||
145 | + assertThat(ospfNbr.isOpaqueCapable(), is(true)); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Tests oneWayReceived() method. | ||
150 | + */ | ||
151 | + @Test | ||
152 | + public void testOneWayReceived() throws Exception { | ||
153 | + ospfMessage = new HelloPacket(); | ||
154 | + ospfNbr.setState(OspfNeighborState.ATTEMPT); | ||
155 | + channel = EasyMock.createMock(Channel.class); | ||
156 | + ospfNbr.oneWayReceived(ospfMessage, channel); | ||
157 | + channel1 = EasyMock.createMock(Channel.class); | ||
158 | + ospfNbr.setState(OspfNeighborState.DOWN); | ||
159 | + ospfNbr.oneWayReceived(ospfMessage, channel1); | ||
160 | + channel2 = EasyMock.createMock(Channel.class); | ||
161 | + ospfNbr.setState(OspfNeighborState.TWOWAY); | ||
162 | + ospfNbr.oneWayReceived(ospfMessage, channel2); | ||
163 | + assertThat(ospfNbr, is(notNullValue())); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests twoWayReceived() method. | ||
168 | + */ | ||
169 | + @Test(expected = Exception.class) | ||
170 | + public void testTwoWayReceived() throws Exception { | ||
171 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1")); | ||
172 | + ospfMessage = new HelloPacket(); | ||
173 | + ospfNbr.setState(OspfNeighborState.ATTEMPT); | ||
174 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2")); | ||
175 | + ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2")); | ||
176 | + channel = EasyMock.createMock(Channel.class); | ||
177 | + SocketAddress socketAddress = EasyMock.createMock(SocketAddress.class); | ||
178 | + channel.bind(socketAddress); | ||
179 | + ospfNbr.twoWayReceived(ospfMessage, channel); | ||
180 | + ospfInterface.setIpAddress(Ip4Address.valueOf("3.3.3.3")); | ||
181 | + channel1 = EasyMock.createMock(Channel.class); | ||
182 | + ospfNbr.twoWayReceived(ospfMessage, channel1); | ||
183 | + assertThat(ospfNbr, is(notNullValue())); | ||
184 | + } | ||
185 | + | ||
186 | + /** | ||
187 | + * Tests negotiationDone() method. | ||
188 | + */ | ||
189 | + @Test(expected = Exception.class) | ||
190 | + public void testNegotiationDone() throws Exception { | ||
191 | + ospfLsaList = new ArrayList(); | ||
192 | + ospfLsaList.add(new RouterLsa()); | ||
193 | + ospfMessage = new HelloPacket(); | ||
194 | + ospfNbr.setState(OspfNeighborState.EXSTART); | ||
195 | + channel = EasyMock.createMock(Channel.class); | ||
196 | + ospfNbr.negotiationDone(ospfMessage, true, ospfLsaList, channel); | ||
197 | + channel1 = EasyMock.createMock(Channel.class); | ||
198 | + ospfNbr.negotiationDone(ospfMessage, false, ospfLsaList, channel1); | ||
199 | + assertThat(ospfNbr, is(notNullValue())); | ||
200 | + } | ||
201 | + | ||
202 | + /** | ||
203 | + * Tests processLsas() method. | ||
204 | + */ | ||
205 | + @Test | ||
206 | + public void testProcessLsas() throws Exception { | ||
207 | + ospfLsaList = new ArrayList(); | ||
208 | + RouterLsa routerLsa = new RouterLsa(); | ||
209 | + routerLsa.setLsType(1); | ||
210 | + ospfLsaList.add(routerLsa); | ||
211 | + NetworkLsa networkLsa = new NetworkLsa(); | ||
212 | + routerLsa.setLsType(2); | ||
213 | + ospfLsaList.add(networkLsa); | ||
214 | + routerLsa.setLsType(3); | ||
215 | + ospfLsaList.add(routerLsa); | ||
216 | + ospfNbr.processLsas(ospfLsaList); | ||
217 | + assertThat(ospfNbr, is(notNullValue())); | ||
218 | + } | ||
219 | + | ||
220 | + /** | ||
221 | + * Tests seqNumMismatch() method. | ||
222 | + */ | ||
223 | + @Test | ||
224 | + public void testSeqNumMismatch() throws Exception { | ||
225 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
226 | + assertThat(ospfNbr.seqNumMismatch("samelsa"), is(notNullValue())); | ||
227 | + } | ||
228 | + | ||
229 | + /** | ||
230 | + * Tests badLSReq() method. | ||
231 | + */ | ||
232 | + @Test | ||
233 | + public void testBadLSReq() throws Exception { | ||
234 | + channel = EasyMock.createMock(Channel.class); | ||
235 | + ospfNbr.setState(OspfNeighborState.FULL); | ||
236 | + ospfNbr.badLSReq(channel); | ||
237 | + assertThat(ospfNbr, is(notNullValue())); | ||
238 | + } | ||
239 | + | ||
240 | + /** | ||
241 | + * Tests processDdPacket() method. | ||
242 | + */ | ||
243 | + @Test | ||
244 | + public void testProcessDdPacket() throws Exception { | ||
245 | + ospfArea.addLsa(new RouterLsa(), false, ospfInterface); | ||
246 | + ospfArea.addLsa(new RouterLsa(), ospfInterface); | ||
247 | + ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl()); | ||
248 | + channel = EasyMock.createMock(Channel.class); | ||
249 | + DdPacket ddPacket = new DdPacket(); | ||
250 | + ddPacket.addLsaHeader(new LsaHeader()); | ||
251 | + ospfNbr.processDdPacket(true, ddPacket, channel); | ||
252 | + channel1 = EasyMock.createMock(Channel.class); | ||
253 | + ddPacket.setIsMore(1); | ||
254 | + ospfNbr.processDdPacket(false, ddPacket, channel1); | ||
255 | + assertThat(ospfNbr, is(notNullValue())); | ||
256 | + } | ||
257 | + | ||
258 | + /** | ||
259 | + * Tests exchangeDone() method. | ||
260 | + */ | ||
261 | + @Test | ||
262 | + public void testExchangeDone() throws Exception { | ||
263 | + ospfMessage = new HelloPacket(); | ||
264 | + channel = EasyMock.createMock(Channel.class); | ||
265 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
266 | + ospfNbr.exchangeDone(ospfMessage, channel); | ||
267 | + assertThat(ospfNbr, is(notNullValue())); | ||
268 | + } | ||
269 | + | ||
270 | + /** | ||
271 | + * Tests exchangeDone() method. | ||
272 | + */ | ||
273 | + @Test | ||
274 | + public void testExchangeDone1() throws Exception { | ||
275 | + ospfMessage = new HelloPacket(); | ||
276 | + channel = EasyMock.createMock(Channel.class); | ||
277 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
278 | + ospfLsaList = new ArrayList(); | ||
279 | + RouterLsa routerLsa = new RouterLsa(); | ||
280 | + routerLsa.setLsType(1); | ||
281 | + ospfLsaList.add(routerLsa); | ||
282 | + NetworkLsa networkLsa = new NetworkLsa(); | ||
283 | + routerLsa.setLsType(2); | ||
284 | + ospfLsaList.add(networkLsa); | ||
285 | + routerLsa.setLsType(3); | ||
286 | + ospfLsaList.add(routerLsa); | ||
287 | + ospfNbr.processLsas(ospfLsaList); | ||
288 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
289 | + ospfNbr.exchangeDone(ospfMessage, channel); | ||
290 | + assertThat(ospfNbr, is(notNullValue())); | ||
291 | + } | ||
292 | + | ||
293 | + /** | ||
294 | + * Tests adjOk() method. | ||
295 | + */ | ||
296 | + @Test | ||
297 | + public void testAdjOk() throws Exception { | ||
298 | + channel = EasyMock.createMock(Channel.class); | ||
299 | + ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2")); | ||
300 | + ospfNbr.setState(OspfNeighborState.TWOWAY); | ||
301 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("2.2.2.2")); | ||
302 | + ospfNbr.adjOk(channel); | ||
303 | + Assert.assertNotNull(ospfNbr); | ||
304 | + } | ||
305 | + | ||
306 | + /** | ||
307 | + * Tests processLsUpdate() method. | ||
308 | + */ | ||
309 | + @Test | ||
310 | + public void testProcessLsUpdate() throws Exception { | ||
311 | + LsUpdate ospfMessage = new LsUpdate(); | ||
312 | + ospfMessage.setSourceIp(Ip4Address.valueOf("10.10.10.10")); | ||
313 | + ospfMessage.addLsa(new RouterLsa()); | ||
314 | + ospfMessage.addLsa(new NetworkLsa()); | ||
315 | + channel = EasyMock.createMock(Channel.class); | ||
316 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
317 | + ospfNbr.processLsUpdate(ospfMessage, channel); | ||
318 | + assertThat(ospfNbr, is(notNullValue())); | ||
319 | + } | ||
320 | + | ||
321 | + /** | ||
322 | + * Tests loadingDone() method. | ||
323 | + */ | ||
324 | + @Test | ||
325 | + public void testLoadingDone() throws Exception { | ||
326 | + ospfArea.addLsa(new RouterLsa(), false, ospfInterface); | ||
327 | + ospfArea.addLsa(new RouterLsa(), ospfInterface); | ||
328 | + ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl()); | ||
329 | + ospfNbr.loadingDone(); | ||
330 | + assertThat(ospfNbr, is(notNullValue())); | ||
331 | + } | ||
332 | + | ||
333 | + /** | ||
334 | + * Tests processReceivedLsa() method. | ||
335 | + */ | ||
336 | + @Test | ||
337 | + public void testProcessReceivedLsa() throws Exception { | ||
338 | + LsaWrapperImpl lsaWrapper = new LsaWrapperImpl(); | ||
339 | + LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); | ||
340 | + lsdbAge.ageLsaAndFlood(); | ||
341 | + lsaWrapper.setLsdbAge(lsdbAge); | ||
342 | + lsaWrapper.setLsaHeader(new NetworkLsa()); | ||
343 | + RouterLsa routerlsa = new RouterLsa(); | ||
344 | + routerlsa.setLsType(1); | ||
345 | + routerlsa.setOptions(2); | ||
346 | + routerlsa.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1")); | ||
347 | + routerlsa.setAge(100); | ||
348 | + routerlsa.setLinkStateId("2.2.2.2"); | ||
349 | + routerlsa.setLsSequenceNo(1010101); | ||
350 | + lsaWrapper.setLsaHeader(new RouterLsa()); | ||
351 | + ospfArea.addLsa(routerlsa, false, ospfInterface); | ||
352 | + | ||
353 | + lsaWrapper.addLsa(OspfLsaType.ROUTER, routerlsa); | ||
354 | + ospfArea.addLsa(routerlsa, ospfInterface); | ||
355 | + ospfArea.addLsaToMaxAgeBin("lsa", new LsaWrapperImpl()); | ||
356 | + byte[] res = routerlsa.asBytes(); | ||
357 | + routerlsa.setLsPacketLen(res.length); | ||
358 | + res = new ChecksumCalculator().calculateLsaChecksum(routerlsa.asBytes(), 16, 17); | ||
359 | + routerlsa.setLsCheckSum(OspfUtil.byteToInteger(res)); | ||
360 | + channel = EasyMock.createMock(Channel.class); | ||
361 | + lsdbAge.ageLsaAndFlood(); | ||
362 | + assertThat(ospfNbr.processReceivedLsa(lsaWrapper.lsaHeader(), true, channel, | ||
363 | + Ip4Address.valueOf("10.10.10.10")), is(true)); | ||
364 | + channel1 = EasyMock.createMock(Channel.class); | ||
365 | + assertThat(ospfNbr.processReceivedLsa(routerlsa, true, channel1, | ||
366 | + Ip4Address.valueOf("10.10.10.10")), is(true)); | ||
367 | + } | ||
368 | + | ||
369 | + /** | ||
370 | + * Tests isNullorLatest() method. | ||
371 | + */ | ||
372 | + @Test | ||
373 | + public void testIsNullorLatest() throws Exception { | ||
374 | + | ||
375 | + LsaWrapperImpl lsaWrapper = new LsaWrapperImpl(); | ||
376 | + LsdbAgeImpl lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); | ||
377 | + lsdbAge.ageLsaAndFlood(); | ||
378 | + lsaWrapper.setLsdbAge(lsdbAge); | ||
379 | + lsaWrapper.setLsaHeader(new LsaHeader()); | ||
380 | + lsaWrapper.addLsa(OspfLsaType.ROUTER, new RouterLsa()); | ||
381 | + assertThat(ospfNbr.isNullorLatest(lsaWrapper, new LsaHeader()), is(notNullValue())); | ||
382 | + } | ||
383 | + | ||
384 | + /** | ||
385 | + * Tests processSelfOriginatedLsa() method. | ||
386 | + */ | ||
387 | + @Test | ||
388 | + public void testProcessSelfOriginatedLsa() throws Exception { | ||
389 | + ospfNbr.processSelfOriginatedLsa(); | ||
390 | + assertThat(ospfNbr, is(notNullValue())); | ||
391 | + } | ||
392 | + | ||
393 | + /** | ||
394 | + * Tests sendLsa() method. | ||
395 | + */ | ||
396 | + @Test | ||
397 | + public void testSendLsa() throws Exception { | ||
398 | + channel = EasyMock.createMock(Channel.class); | ||
399 | + ospfNbr.sendLsa(new LsaHeader(), Ip4Address.valueOf("1.1.1.1"), channel); | ||
400 | + assertThat(ospfNbr, is(notNullValue())); | ||
401 | + } | ||
402 | + | ||
403 | + /** | ||
404 | + * Tests directAcknowledge() method. | ||
405 | + */ | ||
406 | + @Test | ||
407 | + public void testDirectAcknowledge() throws Exception { | ||
408 | + channel = EasyMock.createMock(Channel.class); | ||
409 | + ospfNbr.directAcknowledge(new LsaHeader(), channel, Ip4Address.valueOf("1.1.1.1")); | ||
410 | + assertThat(ospfNbr, is(notNullValue())); | ||
411 | + } | ||
412 | + | ||
413 | + /** | ||
414 | + * Tests neighborDown() method. | ||
415 | + */ | ||
416 | + @Test(expected = Exception.class) | ||
417 | + public void testNeighborDown() throws Exception { | ||
418 | + ospfNbr.neighborDown(); | ||
419 | + assertThat(ospfNbr, is(notNullValue())); | ||
420 | + } | ||
421 | + | ||
422 | + /** | ||
423 | + * Tests startFloodingTimer() method. | ||
424 | + */ | ||
425 | + @Test | ||
426 | + public void testStartFloodingTimer() throws Exception { | ||
427 | + channel = EasyMock.createMock(Channel.class); | ||
428 | + ospfNbr.startFloodingTimer(channel); | ||
429 | + assertThat(ospfNbr, is(notNullValue())); | ||
430 | + } | ||
431 | + | ||
432 | + /** | ||
433 | + * Tests lastDdPacket() getter method. | ||
434 | + */ | ||
435 | + @Test | ||
436 | + public void testGetLastDdPacket() throws Exception { | ||
437 | + ospfNbr.setLastDdPacket(new DdPacket()); | ||
438 | + assertThat(ospfNbr.lastDdPacket(), is(notNullValue())); | ||
439 | + } | ||
440 | + | ||
441 | + /** | ||
442 | + * Tests lastDdPacket() setter method. | ||
443 | + */ | ||
444 | + @Test | ||
445 | + public void testSetLastDdPacket() throws Exception { | ||
446 | + ospfNbr.setLastDdPacket(new DdPacket()); | ||
447 | + assertThat(ospfNbr.lastDdPacket(), is(notNullValue())); | ||
448 | + } | ||
449 | + | ||
450 | + /** | ||
451 | + * Tests neighborId() getter method. | ||
452 | + */ | ||
453 | + @Test | ||
454 | + public void testNeighborId() throws Exception { | ||
455 | + ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1")); | ||
456 | + assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
457 | + } | ||
458 | + | ||
459 | + /** | ||
460 | + * Tests neighborId() setter method. | ||
461 | + */ | ||
462 | + @Test | ||
463 | + public void testSetNeighborId() throws Exception { | ||
464 | + ospfNbr.setNeighborId(Ip4Address.valueOf("1.1.1.1")); | ||
465 | + assertThat(ospfNbr.neighborId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
466 | + } | ||
467 | + | ||
468 | + /** | ||
469 | + * Tests neighborDr() getter method. | ||
470 | + */ | ||
471 | + @Test | ||
472 | + public void testNeighborDr() throws Exception { | ||
473 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1")); | ||
474 | + assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
475 | + } | ||
476 | + | ||
477 | + /** | ||
478 | + * Tests neighborDr() setter method. | ||
479 | + */ | ||
480 | + @Test | ||
481 | + public void testSetNeighborDr() throws Exception { | ||
482 | + ospfNbr.setNeighborDr(Ip4Address.valueOf("1.1.1.1")); | ||
483 | + assertThat(ospfNbr.neighborDr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
484 | + } | ||
485 | + | ||
486 | + /** | ||
487 | + * Tests neighborBdr() getter method. | ||
488 | + */ | ||
489 | + @Test | ||
490 | + public void testNeighborBdr() throws Exception { | ||
491 | + ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1")); | ||
492 | + assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
493 | + } | ||
494 | + | ||
495 | + /** | ||
496 | + * Tests neighborBdr() setter method. | ||
497 | + */ | ||
498 | + @Test | ||
499 | + public void testSetNeighborBdr() throws Exception { | ||
500 | + ospfNbr.setNeighborBdr(Ip4Address.valueOf("1.1.1.1")); | ||
501 | + assertThat(ospfNbr.neighborBdr(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
502 | + } | ||
503 | + | ||
504 | + /** | ||
505 | + * Tests routerPriority() getter method. | ||
506 | + */ | ||
507 | + @Test | ||
508 | + public void testRouterPriority() throws Exception { | ||
509 | + ospfNbr.setRouterPriority(1); | ||
510 | + assertThat(ospfNbr.routerPriority(), is(1)); | ||
511 | + } | ||
512 | + | ||
513 | + /** | ||
514 | + * Tests routerPriority() setter method. | ||
515 | + */ | ||
516 | + @Test | ||
517 | + public void testSetRouterPriority() throws Exception { | ||
518 | + ospfNbr.setRouterPriority(1); | ||
519 | + assertThat(ospfNbr.routerPriority(), is(1)); | ||
520 | + } | ||
521 | + | ||
522 | + /** | ||
523 | + * Tests options() getter method. | ||
524 | + */ | ||
525 | + @Test | ||
526 | + public void testGetOptions() throws Exception { | ||
527 | + ospfNbr.setOptions(1); | ||
528 | + assertThat(ospfNbr.options(), is(1)); | ||
529 | + } | ||
530 | + | ||
531 | + /** | ||
532 | + * Tests options() setter method. | ||
533 | + */ | ||
534 | + @Test | ||
535 | + public void testSetOptions() throws Exception { | ||
536 | + ospfNbr.setOptions(1); | ||
537 | + assertThat(ospfNbr.options(), is(1)); | ||
538 | + } | ||
539 | + | ||
540 | + /** | ||
541 | + * Tests ddSeqNum() getter method. | ||
542 | + */ | ||
543 | + @Test | ||
544 | + public void testGetDdSeqNum() throws Exception { | ||
545 | + ospfNbr.setDdSeqNum(1); | ||
546 | + assertThat(ospfNbr.ddSeqNum(), is(1L)); | ||
547 | + } | ||
548 | + | ||
549 | + /** | ||
550 | + * Tests ddSeqNum() setter method. | ||
551 | + */ | ||
552 | + @Test | ||
553 | + public void testSetDdSeqNum() throws Exception { | ||
554 | + ospfNbr.setDdSeqNum(1); | ||
555 | + assertThat(ospfNbr.ddSeqNum(), is(1L)); | ||
556 | + } | ||
557 | + | ||
558 | + /** | ||
559 | + * Tests isMaster() getter method. | ||
560 | + */ | ||
561 | + @Test | ||
562 | + public void testIsMaster() throws Exception { | ||
563 | + ospfNbr.setIsMaster(1); | ||
564 | + assertThat(ospfNbr.isMaster(), is(1)); | ||
565 | + } | ||
566 | + | ||
567 | + /** | ||
568 | + * Tests lastDdPacket() getter method. | ||
569 | + */ | ||
570 | + @Test | ||
571 | + public void testGetLastSentDdPacket() throws Exception { | ||
572 | + ospfNbr.setLastDdPacket(new DdPacket()); | ||
573 | + assertThat(ospfNbr.lastDdPacket(), is(notNullValue())); | ||
574 | + } | ||
575 | + | ||
576 | + /** | ||
577 | + * Tests lastDdPacket() setter method. | ||
578 | + */ | ||
579 | + @Test | ||
580 | + public void testSetLastSentDdPacket() throws Exception { | ||
581 | + ospfNbr.setLastDdPacket(new DdPacket()); | ||
582 | + assertThat(ospfNbr.lastDdPacket(), is(notNullValue())); | ||
583 | + } | ||
584 | + | ||
585 | + /** | ||
586 | + * Tests getLastSentLsrPacket() getter method. | ||
587 | + */ | ||
588 | + @Test | ||
589 | + public void testGetLastSentLsrPacket() throws Exception { | ||
590 | + ospfNbr.setLastSentLsrPacket(new LsRequest()); | ||
591 | + assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue())); | ||
592 | + } | ||
593 | + | ||
594 | + /** | ||
595 | + * Tests getLastSentLsrPacket() setter method. | ||
596 | + */ | ||
597 | + @Test | ||
598 | + public void testSetLastSentLsrPacket() throws Exception { | ||
599 | + ospfNbr.setLastSentLsrPacket(new LsRequest()); | ||
600 | + assertThat(ospfNbr.getLastSentLsrPacket(), is(notNullValue())); | ||
601 | + } | ||
602 | + | ||
603 | + /** | ||
604 | + * Tests getState() getter method. | ||
605 | + */ | ||
606 | + @Test | ||
607 | + public void testGetState() throws Exception { | ||
608 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
609 | + assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE)); | ||
610 | + } | ||
611 | + | ||
612 | + /** | ||
613 | + * Tests getState() setter method. | ||
614 | + */ | ||
615 | + @Test | ||
616 | + public void testSetState() throws Exception { | ||
617 | + ospfNbr.setState(OspfNeighborState.EXCHANGE); | ||
618 | + assertThat(ospfNbr.getState(), is(OspfNeighborState.EXCHANGE)); | ||
619 | + } | ||
620 | + | ||
621 | + /** | ||
622 | + * Tests isMaster() setter method. | ||
623 | + */ | ||
624 | + @Test | ||
625 | + public void testSetIsMaster() throws Exception { | ||
626 | + ospfNbr.setIsMaster(1); | ||
627 | + assertThat(ospfNbr.isMaster(), is(1)); | ||
628 | + } | ||
629 | + | ||
630 | + /** | ||
631 | + * Tests getLsReqList() method. | ||
632 | + */ | ||
633 | + @Test | ||
634 | + public void testGetLsReqList() throws Exception { | ||
635 | + assertThat(ospfNbr.getLsReqList(), is(notNullValue())); | ||
636 | + } | ||
637 | + | ||
638 | + /** | ||
639 | + * Tests getReTxList() method. | ||
640 | + */ | ||
641 | + @Test | ||
642 | + public void testGetReTxList() throws Exception { | ||
643 | + assertThat(ospfNbr.getReTxList(), is(notNullValue())); | ||
644 | + } | ||
645 | + | ||
646 | + /** | ||
647 | + * Tests getPendingReTxList() method. | ||
648 | + */ | ||
649 | + @Test | ||
650 | + public void testGetPendingReTxList() throws Exception { | ||
651 | + assertThat(ospfNbr.getPendingReTxList(), is(notNullValue())); | ||
652 | + } | ||
653 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | +* Copyright 2016 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 | +*/ | ||
16 | +package org.onosproject.ospf.controller.impl; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.jboss.netty.buffer.ChannelBuffers; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ip4Address; | ||
24 | +import org.onosproject.ospf.controller.DeviceInformation; | ||
25 | +import org.onosproject.ospf.controller.OspfLinkTed; | ||
26 | +import org.onosproject.ospf.controller.OspfLsa; | ||
27 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
28 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
29 | +import org.onosproject.ospf.protocol.lsa.OpaqueLsaHeader; | ||
30 | +import org.onosproject.ospf.protocol.lsa.TlvHeader; | ||
31 | +import org.onosproject.ospf.protocol.lsa.subtypes.OspfLsaLink; | ||
32 | +import org.onosproject.ospf.protocol.lsa.tlvtypes.LinkTlv; | ||
33 | +import org.onosproject.ospf.protocol.lsa.types.OpaqueLsa10; | ||
34 | +import org.onosproject.ospf.protocol.lsa.types.RouterLsa; | ||
35 | + | ||
36 | +import java.util.List; | ||
37 | +import java.util.Map; | ||
38 | + | ||
39 | +import static org.hamcrest.CoreMatchers.nullValue; | ||
40 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
41 | +import static org.hamcrest.Matchers.is; | ||
42 | +import static org.hamcrest.Matchers.notNullValue; | ||
43 | + | ||
44 | +/** | ||
45 | + * Unit test class for TopologyForDeviceAndLinkImpl. | ||
46 | + */ | ||
47 | +public class TopologyForDeviceAndLinkImplTest { | ||
48 | + private final byte[] packet = {0, 9, 0, 4, 0, 0, 0, 1, | ||
49 | + 0, 9, 0, 4, 0, 0, 0, 1, | ||
50 | + 0, 1, 0, 4, 0, 0, 0, 1, | ||
51 | + 0, 2, 0, 4, 0, 0, 0, 1, | ||
52 | + 0, 3, 0, 4, 0, 0, 0, 1, | ||
53 | + 0, 4, 0, 4, 0, 0, 0, 1, | ||
54 | + 0, 6, 0, 4, 0, 0, 0, 1, | ||
55 | + 0, 7, 0, 4, 0, 0, 0, 1, | ||
56 | + 0, 8, 0, 4, 0, 0, 0, 1, | ||
57 | + }; | ||
58 | + private TopologyForDeviceAndLinkImpl topologyForDeviceAndLink; | ||
59 | + private Map result; | ||
60 | + private LinkTlv linkTlv; | ||
61 | + private TlvHeader header; | ||
62 | + private ChannelBuffer channelBuffer; | ||
63 | + | ||
64 | + @Before | ||
65 | + public void setUp() throws Exception { | ||
66 | + topologyForDeviceAndLink = new TopologyForDeviceAndLinkImpl(); | ||
67 | + } | ||
68 | + | ||
69 | + @After | ||
70 | + public void tearDown() throws Exception { | ||
71 | + topologyForDeviceAndLink = null; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Tests deviceInformationMap() method. | ||
76 | + */ | ||
77 | + @Test | ||
78 | + public void testDeviceInformationMap() throws Exception { | ||
79 | + result = topologyForDeviceAndLink.deviceInformationMap(); | ||
80 | + assertThat(result.size(), is(0)); | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Tests setDeviceInformationMap() method. | ||
85 | + */ | ||
86 | + @Test | ||
87 | + public void testSetDeviceInformationMap() throws Exception { | ||
88 | + topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl()); | ||
89 | + result = topologyForDeviceAndLink.deviceInformationMap(); | ||
90 | + assertThat(result.size(), is(1)); | ||
91 | + } | ||
92 | + | ||
93 | + /** | ||
94 | + * Tests deviceInformation() method. | ||
95 | + */ | ||
96 | + @Test | ||
97 | + public void testDeviceInformation() throws Exception { | ||
98 | + topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl()); | ||
99 | + DeviceInformation deviceInformation = topologyForDeviceAndLink.deviceInformation("1.1.1.1"); | ||
100 | + assertThat(deviceInformation, is(notNullValue())); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Tests removeDeviceInformationMap() method. | ||
105 | + */ | ||
106 | + @Test | ||
107 | + public void testRemoveDeviceInformationMap() throws Exception { | ||
108 | + topologyForDeviceAndLink.setDeviceInformationMap("1.1.1.1", new DeviceInformationImpl()); | ||
109 | + topologyForDeviceAndLink.deviceInformation("1.1.1.1"); | ||
110 | + result = topologyForDeviceAndLink.deviceInformationMap(); | ||
111 | + topologyForDeviceAndLink.removeDeviceInformationMap("1.1.1.1"); | ||
112 | + assertThat(result.size(), is(0)); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Tests linkInformationMap() method. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testLinkInformationMap() throws Exception { | ||
120 | + result = topologyForDeviceAndLink.linkInformationMap(); | ||
121 | + assertThat(result.size(), is(0)); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Tests setLinkInformationMap() method. | ||
126 | + */ | ||
127 | + @Test | ||
128 | + public void testSetLinkInformationMap() throws Exception { | ||
129 | + topologyForDeviceAndLink.setLinkInformationMap("1.1.1.1", new LinkInformationImpl()); | ||
130 | + result = topologyForDeviceAndLink.linkInformationMap(); | ||
131 | + assertThat(result.size(), is(1)); | ||
132 | + } | ||
133 | + | ||
134 | + /** | ||
135 | + * Tests removeLinkInformationMap() method. | ||
136 | + */ | ||
137 | + @Test | ||
138 | + public void testRemoveLinkInformationMap() throws Exception { | ||
139 | + topologyForDeviceAndLink.setLinkInformationMap("1.1.1.1", new LinkInformationImpl()); | ||
140 | + topologyForDeviceAndLink.removeLinkInformationMap("1.1.1.1"); | ||
141 | + result = topologyForDeviceAndLink.linkInformationMap(); | ||
142 | + assertThat(result.size(), is(0)); | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Tests getOspfLinkTedHashMap() method. | ||
147 | + */ | ||
148 | + @Test | ||
149 | + public void testGetOspfLinkTedHashMap() throws Exception { | ||
150 | + OspfLinkTed ospfLinkTed = topologyForDeviceAndLink.getOspfLinkTedHashMap("1.1.1.1"); | ||
151 | + assertThat(ospfLinkTed, is(nullValue())); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Tests addLocalDevice() method. | ||
156 | + */ | ||
157 | + @Test | ||
158 | + public void testAddLocalDevice() throws Exception { | ||
159 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
160 | + ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5")); | ||
161 | + topologyForDeviceAndLink.addLocalDevice(createOspfLsa(), new OspfInterfaceImpl(), ospfArea); | ||
162 | + topologyForDeviceAndLink.addLocalDevice(createOspfLsa1(), new OspfInterfaceImpl(), ospfArea); | ||
163 | + assertThat(topologyForDeviceAndLink, is(notNullValue())); | ||
164 | + } | ||
165 | + | ||
166 | + /** | ||
167 | + * Tests addLocalLink() method. | ||
168 | + */ | ||
169 | + @Test | ||
170 | + public void testAddLocalLink() throws Exception { | ||
171 | + Ip4Address linkData = Ip4Address.valueOf("1.1.1.1"); | ||
172 | + Ip4Address linkSrc = Ip4Address.valueOf("2.2.2.2"); | ||
173 | + Ip4Address linkDest = Ip4Address.valueOf("3.3.3.3"); | ||
174 | + boolean opaqueEnabled = true; | ||
175 | + boolean linkSrcIdNotRouterId = true; | ||
176 | + topologyForDeviceAndLink.addLocalLink("10.10.10.10", linkData, linkSrc, | ||
177 | + linkDest, opaqueEnabled, linkSrcIdNotRouterId); | ||
178 | + assertThat(topologyForDeviceAndLink, is(notNullValue())); | ||
179 | + } | ||
180 | + | ||
181 | + /** | ||
182 | + * Tests removeLinks() method. | ||
183 | + */ | ||
184 | + @Test | ||
185 | + public void testRemoveLinks() throws Exception { | ||
186 | + Ip4Address linkData = Ip4Address.valueOf("1.1.1.1"); | ||
187 | + Ip4Address linkSrc = Ip4Address.valueOf("2.2.2.2"); | ||
188 | + Ip4Address linkDest = Ip4Address.valueOf("3.3.3.3"); | ||
189 | + boolean opaqueEnabled = true; | ||
190 | + boolean linkSrcIdNotRouterId = true; | ||
191 | + topologyForDeviceAndLink.addLocalLink("10.10.10.10", linkData, linkSrc, | ||
192 | + linkDest, opaqueEnabled, linkSrcIdNotRouterId); | ||
193 | + topologyForDeviceAndLink.removeLinks(Ip4Address.valueOf("10.10.10.10")); | ||
194 | + assertThat(topologyForDeviceAndLink, is(notNullValue())); | ||
195 | + } | ||
196 | + | ||
197 | + /** | ||
198 | + * Tests updateLinkInformation() method. | ||
199 | + */ | ||
200 | + @Test | ||
201 | + public void testUpdateLinkInformation() throws Exception { | ||
202 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
203 | + ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5")); | ||
204 | + topologyForDeviceAndLink.updateLinkInformation(createOspfLsa(), ospfArea); | ||
205 | + assertThat(topologyForDeviceAndLink, is(notNullValue())); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Tests getDeleteRouterInformation() method. | ||
210 | + */ | ||
211 | + @Test | ||
212 | + public void testGetDeleteRouterInformation() throws Exception { | ||
213 | + OspfAreaImpl ospfArea = new OspfAreaImpl(); | ||
214 | + ospfArea.setRouterId(Ip4Address.valueOf("5.5.5.5")); | ||
215 | + topologyForDeviceAndLink.updateLinkInformation(createOspfLsa(), ospfArea); | ||
216 | + List list = topologyForDeviceAndLink.getDeleteRouterInformation(createOspfLsa(), ospfArea); | ||
217 | + assertThat(list, is(notNullValue())); | ||
218 | + } | ||
219 | + | ||
220 | + /** | ||
221 | + * Utility for test methods. | ||
222 | + */ | ||
223 | + private OspfLsa createOspfLsa() { | ||
224 | + RouterLsa routerLsa = new RouterLsa(); | ||
225 | + routerLsa.setLsType(1); | ||
226 | + routerLsa.setAdvertisingRouter(Ip4Address.valueOf("6.6.6.6")); | ||
227 | + OspfLsaLink ospfLsaLink = new OspfLsaLink(); | ||
228 | + ospfLsaLink.setLinkData("192.168.7.77"); | ||
229 | + ospfLsaLink.setLinkId("9.9.9.9"); | ||
230 | + ospfLsaLink.setLinkType(1); | ||
231 | + OspfLsaLink ospfLsaLink0 = new OspfLsaLink(); | ||
232 | + ospfLsaLink0.setLinkData("7.7.7.7"); | ||
233 | + ospfLsaLink0.setLinkId("7.7.7.7"); | ||
234 | + ospfLsaLink0.setLinkType(2); | ||
235 | + OspfLsaLink ospfLsaLink120 = new OspfLsaLink(); | ||
236 | + ospfLsaLink120.setLinkData("192.168.7.77"); | ||
237 | + ospfLsaLink120.setLinkId("1.1.1.1"); | ||
238 | + ospfLsaLink120.setLinkType(1); | ||
239 | + OspfLsaLink lsaLink = new OspfLsaLink(); | ||
240 | + lsaLink.setLinkData("192.168.7.77"); | ||
241 | + lsaLink.setLinkId("14.14.14.14"); | ||
242 | + lsaLink.setLinkType(2); | ||
243 | + routerLsa.addRouterLink(lsaLink); | ||
244 | + routerLsa.addRouterLink(ospfLsaLink); | ||
245 | + routerLsa.addRouterLink(ospfLsaLink0); | ||
246 | + routerLsa.addRouterLink(ospfLsaLink120); | ||
247 | + return routerLsa; | ||
248 | + } | ||
249 | + | ||
250 | + /** | ||
251 | + * Utility for test methods. | ||
252 | + */ | ||
253 | + private OspfLsa createOspfLsa1() throws Exception { | ||
254 | + OpaqueLsa10 opaqueLsa10 = new OpaqueLsa10(new OpaqueLsaHeader()); | ||
255 | + opaqueLsa10.setLsType(10); | ||
256 | + header = new TlvHeader(); | ||
257 | + header.setTlvLength(8); | ||
258 | + header.setTlvType(9); | ||
259 | + linkTlv = new LinkTlv(header); | ||
260 | + channelBuffer = ChannelBuffers.copiedBuffer(packet); | ||
261 | + linkTlv.readFrom(channelBuffer); | ||
262 | + opaqueLsa10.addValue(linkTlv); | ||
263 | + return opaqueLsa10; | ||
264 | + } | ||
265 | +} |
-
Please register or login to post a comment