sunish vk
Committed by Gerrit Code Review

ONOS-4505: Bug Fixes

Change-Id: Ia030aa3aff9e2ad34a5e27fbe4ba088dda65bfa7
Showing 34 changed files with 1577 additions and 326 deletions
...@@ -195,13 +195,6 @@ public interface IsisInterface { ...@@ -195,13 +195,6 @@ public interface IsisInterface {
195 void setAreaLength(int areaLength); 195 void setAreaLength(int areaLength);
196 196
197 /** 197 /**
198 - * Sets link state packet ID.
199 - *
200 - * @param lspId link state packet ID
201 - */
202 - void setLspId(String lspId);
203 -
204 - /**
205 * Returns holding time. 198 * Returns holding time.
206 * 199 *
207 * @return holding time 200 * @return holding time
...@@ -251,6 +244,11 @@ public interface IsisInterface { ...@@ -251,6 +244,11 @@ public interface IsisInterface {
251 void startHelloSender(Channel channel); 244 void startHelloSender(Channel channel);
252 245
253 /** 246 /**
247 + * Stops the hello timer which sends hello packet every configured seconds.
248 + */
249 + void stopHelloSender();
250 +
251 + /**
254 * Processes an ISIS message which is received on this interface. 252 * Processes an ISIS message which is received on this interface.
255 * 253 *
256 * @param isisMessage ISIS message instance 254 * @param isisMessage ISIS message instance
...@@ -315,4 +313,9 @@ public interface IsisInterface { ...@@ -315,4 +313,9 @@ public interface IsisInterface {
315 * @param isisNeighbor ISIS neighbor instance 313 * @param isisNeighbor ISIS neighbor instance
316 */ 314 */
317 void removeNeighbor(IsisNeighbor isisNeighbor); 315 void removeNeighbor(IsisNeighbor isisNeighbor);
316 +
317 + /**
318 + * Removes all the neighbors.
319 + */
320 + void removeNeighbors();
318 } 321 }
......
...@@ -108,4 +108,18 @@ public interface IsisLsdb { ...@@ -108,4 +108,18 @@ public interface IsisLsdb {
108 * @return neighbor database information 108 * @return neighbor database information
109 */ 109 */
110 Map<String, LspWrapper> getL2Db(); 110 Map<String, LspWrapper> getL2Db();
111 +
112 + /**
113 + * Sets the level 1 link state sequence number.
114 + *
115 + * @param l1LspSeqNo link state sequence number
116 + */
117 + void setL1LspSeqNo(int l1LspSeqNo);
118 +
119 + /**
120 + * Sets the level 2 link state sequence number.
121 + *
122 + * @param l2LspSeqNo link state sequence number
123 + */
124 + void setL2LspSeqNo(int l2LspSeqNo);
111 } 125 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -108,4 +108,16 @@ public interface IsisNeighbor { ...@@ -108,4 +108,16 @@ public interface IsisNeighbor {
108 * Stops the inactivity timer. 108 * Stops the inactivity timer.
109 */ 109 */
110 void stopInactivityTimeCheck(); 110 void stopInactivityTimeCheck();
111 -} 111 +
112 + /**
113 + * Stops the holding time check timer.
114 + */
115 + void stopHoldingTimeCheck();
116 +
117 + /**
118 + * Returns router type.
119 + *
120 + * @return router type
121 + */
122 + IsisRouterType routerType();
123 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode;
19 import org.jboss.netty.bootstrap.ClientBootstrap; 19 import org.jboss.netty.bootstrap.ClientBootstrap;
20 import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor; 20 import org.jboss.netty.channel.AdaptiveReceiveBufferSizePredictor;
21 import org.jboss.netty.channel.ChannelFuture; 21 import org.jboss.netty.channel.ChannelFuture;
22 +import org.jboss.netty.channel.ChannelFutureListener;
22 import org.jboss.netty.channel.ChannelPipelineFactory; 23 import org.jboss.netty.channel.ChannelPipelineFactory;
23 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory; 24 import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
24 import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; 25 import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
...@@ -35,10 +36,14 @@ import org.slf4j.LoggerFactory; ...@@ -35,10 +36,14 @@ import org.slf4j.LoggerFactory;
35 36
36 import java.net.InetAddress; 37 import java.net.InetAddress;
37 import java.net.InetSocketAddress; 38 import java.net.InetSocketAddress;
39 +import java.net.NetworkInterface;
38 import java.net.UnknownHostException; 40 import java.net.UnknownHostException;
39 import java.util.ArrayList; 41 import java.util.ArrayList;
42 +import java.util.Enumeration;
40 import java.util.List; 43 import java.util.List;
41 import java.util.concurrent.Executors; 44 import java.util.concurrent.Executors;
45 +import java.util.concurrent.ScheduledExecutorService;
46 +import java.util.concurrent.TimeUnit;
42 47
43 import static org.onlab.util.Tools.groupedThreads; 48 import static org.onlab.util.Tools.groupedThreads;
44 49
...@@ -48,12 +53,17 @@ import static org.onlab.util.Tools.groupedThreads; ...@@ -48,12 +53,17 @@ import static org.onlab.util.Tools.groupedThreads;
48 public class Controller { 53 public class Controller {
49 protected static final int BUFFER_SIZE = 4 * 1024 * 1024; 54 protected static final int BUFFER_SIZE = 4 * 1024 * 1024;
50 private static final Logger log = LoggerFactory.getLogger(Controller.class); 55 private static final Logger log = LoggerFactory.getLogger(Controller.class);
56 + private static final int RETRY_INTERVAL = 4;
51 private final int peerWorkerThreads = 16; 57 private final int peerWorkerThreads = 16;
58 + byte[] configPacket = null;
52 private List<IsisProcess> processes = null; 59 private List<IsisProcess> processes = null;
53 private IsisChannelHandler isisChannelHandler; 60 private IsisChannelHandler isisChannelHandler;
54 private NioClientSocketChannelFactory peerExecFactory; 61 private NioClientSocketChannelFactory peerExecFactory;
55 private ClientBootstrap peerBootstrap = null; 62 private ClientBootstrap peerBootstrap = null;
56 private TpPort isisPort = TpPort.tpPort(IsisConstants.SPORT); 63 private TpPort isisPort = TpPort.tpPort(IsisConstants.SPORT);
64 + private ScheduledExecutorService connectExecutor = null;
65 + private int connectRetryCounter = 0;
66 + private int connectRetryTime;
57 67
58 /** 68 /**
59 * Deactivates ISIS controller. 69 * Deactivates ISIS controller.
...@@ -70,12 +80,11 @@ public class Controller { ...@@ -70,12 +80,11 @@ public class Controller {
70 */ 80 */
71 public void updateConfig(JsonNode jsonNode) throws Exception { 81 public void updateConfig(JsonNode jsonNode) throws Exception {
72 log.debug("Controller::UpdateConfig called"); 82 log.debug("Controller::UpdateConfig called");
73 - byte[] configPacket = new byte[IsisConstants.CONFIG_LENGTH]; 83 + configPacket = new byte[IsisConstants.CONFIG_LENGTH];
74 byte numberOfInterface = 0; // number of interfaces to configure 84 byte numberOfInterface = 0; // number of interfaces to configure
75 85
76 configPacket[0] = (byte) 0xFF; // its a conf packet - identifier 86 configPacket[0] = (byte) 0xFF; // its a conf packet - identifier
77 List<IsisProcess> isisProcesses = getConfig(jsonNode); 87 List<IsisProcess> isisProcesses = getConfig(jsonNode);
78 -
79 for (IsisProcess isisProcess : isisProcesses) { 88 for (IsisProcess isisProcess : isisProcesses) {
80 log.debug("IsisProcessDetails : " + isisProcess); 89 log.debug("IsisProcessDetails : " + isisProcess);
81 for (IsisInterface isisInterface : isisProcess.isisInterfaceList()) { 90 for (IsisInterface isisInterface : isisProcess.isisInterfaceList()) {
...@@ -100,16 +109,19 @@ public class Controller { ...@@ -100,16 +109,19 @@ public class Controller {
100 configPacket[1] = numberOfInterface; 109 configPacket[1] = numberOfInterface;
101 //First time configuration 110 //First time configuration
102 if (processes == null) { 111 if (processes == null) {
103 - processes = isisProcesses; 112 + if (isisProcesses.size() > 0) {
104 - //Initialize connection by creating a channel handler instance and sent the config packet); 113 + processes = isisProcesses;
105 - initConnection(); 114 + connectPeer();
106 - //Initializing the interface map in channel handler 115 + //Initializing the interface map in channel handler
107 - isisChannelHandler.initializeInterfaceMap(); 116 + if (isisChannelHandler != null) {
117 + isisChannelHandler.initializeInterfaceMap();
118 + }
119 + }
108 } else { 120 } else {
109 isisChannelHandler.updateInterfaceMap(isisProcesses); 121 isisChannelHandler.updateInterfaceMap(isisProcesses);
122 + //Send the config packet
123 + isisChannelHandler.sentConfigPacket(configPacket);
110 } 124 }
111 - //Send the config packet
112 - isisChannelHandler.sentConfigPacket(configPacket);
113 } 125 }
114 126
115 /** 127 /**
...@@ -182,10 +194,8 @@ public class Controller { ...@@ -182,10 +194,8 @@ public class Controller {
182 * @return list of processes configured 194 * @return list of processes configured
183 */ 195 */
184 private List<IsisProcess> getConfig(JsonNode json) throws Exception { 196 private List<IsisProcess> getConfig(JsonNode json) throws Exception {
185 -
186 List<IsisProcess> isisProcessesList = new ArrayList<>(); 197 List<IsisProcess> isisProcessesList = new ArrayList<>();
187 JsonNode jsonNodes = json; 198 JsonNode jsonNodes = json;
188 -
189 if (jsonNodes == null) { 199 if (jsonNodes == null) {
190 return isisProcessesList; 200 return isisProcessesList;
191 } 201 }
...@@ -193,49 +203,335 @@ public class Controller { ...@@ -193,49 +203,335 @@ public class Controller {
193 List<IsisInterface> interfaceList = new ArrayList<>(); 203 List<IsisInterface> interfaceList = new ArrayList<>();
194 for (JsonNode jsonNode1 : jsonNode.path(IsisConstants.INTERFACE)) { 204 for (JsonNode jsonNode1 : jsonNode.path(IsisConstants.INTERFACE)) {
195 IsisInterface isisInterface = new DefaultIsisInterface(); 205 IsisInterface isisInterface = new DefaultIsisInterface();
196 - isisInterface.setInterfaceIndex(jsonNode1.path(IsisConstants.INTERFACEINDEX).asInt()); 206 + String index = jsonNode1.path(IsisConstants.INTERFACEINDEX).asText();
197 - isisInterface.setInterfaceIpAddress(Ip4Address.valueOf(jsonNode1 207 + if (isPrimitive(index)) {
198 - .path(IsisConstants.INTERFACEIP) 208 + int input = Integer.parseInt(index);
199 - .asText())); 209 + if (input < 1 || input > 255) {
200 - try { 210 + log.debug("Wrong interface index: {}", index);
201 - isisInterface.setNetworkMask(InetAddress.getByName((jsonNode1 211 + continue;
202 - .path(IsisConstants.NETWORKMASK).asText())).getAddress()); 212 + }
203 - } catch (UnknownHostException e) { 213 + isisInterface.setInterfaceIndex(Integer.parseInt(index));
204 - log.debug("Error:: Parsing network mask"); 214 + } else {
205 - } 215 + log.debug("Wrong interface index {}", index);
206 - isisInterface.setInterfaceMacAddress(MacAddress.valueOf(jsonNode1 216 + continue;
207 - .path(IsisConstants.MACADDRESS) 217 + }
208 - .asText())); 218 + Ip4Address ipAddress = getInterfaceIp(isisInterface.interfaceIndex());
219 + if (ipAddress != null && !ipAddress.equals(IsisConstants.DEFAULTIP)) {
220 + isisInterface.setInterfaceIpAddress(ipAddress);
221 + } else {
222 + log.debug("Wrong interface index {}. No matching interface in system.", index);
223 + continue;
224 + }
225 + MacAddress macAddress = getInterfaceMac(isisInterface.interfaceIndex());
226 + if (macAddress != null) {
227 + isisInterface.setInterfaceMacAddress(macAddress);
228 + } else {
229 + log.debug("Wrong interface index {}. No matching interface in system.", index);
230 + continue;
231 + }
232 + String mask = getInterfaceMask(isisInterface.interfaceIndex());
233 + if (mask != null) {
234 + try {
235 + isisInterface.setNetworkMask(InetAddress.getByName(mask).getAddress());
236 + } catch (UnknownHostException e) {
237 + log.debug("Wrong interface index {}. Error while getting network mask.", index);
238 + }
239 + } else {
240 + log.debug("Wrong interface index {}. Error while getting network mask.", index);
241 + continue;
242 + }
209 isisInterface.setIntermediateSystemName(jsonNode1 243 isisInterface.setIntermediateSystemName(jsonNode1
210 .path(IsisConstants.INTERMEDIATESYSTEMNAME) 244 .path(IsisConstants.INTERMEDIATESYSTEMNAME)
211 .asText()); 245 .asText());
212 - isisInterface.setSystemId(jsonNode1.path(IsisConstants.SYSTEMID).asText()); 246 + String systemId = jsonNode1.path(IsisConstants.SYSTEMID).asText();
213 - isisInterface.setReservedPacketCircuitType(jsonNode1 247 + if (isValidSystemId(systemId)) {
214 - .path(IsisConstants.RESERVEDPACKETCIRCUITTYPE) 248 + isisInterface.setSystemId(systemId);
215 - .asInt()); 249 + } else {
216 - if (isisInterface.reservedPacketCircuitType() == IsisRouterType.L1.value()) { 250 + log.debug("Wrong systemId: {} for interface index {}.", systemId, index);
217 - isisInterface.setL1LanId(jsonNode1.path(IsisConstants.LANID).asText()); 251 + continue;
218 - } 252 + }
219 - isisInterface.setIdLength(jsonNode1.path(IsisConstants.IDLENGTH).asInt()); 253 + String circuitType = jsonNode1.path(IsisConstants.RESERVEDPACKETCIRCUITTYPE).asText();
220 - isisInterface.setMaxAreaAddresses(jsonNode1.path(IsisConstants.MAXAREAADDRESSES).asInt()); 254 + if (isPrimitive(circuitType)) {
221 - isisInterface.setNetworkType(IsisNetworkType.get(jsonNode1 255 + int input = Integer.parseInt(circuitType);
222 - .path(IsisConstants.NETWORKTYPE) 256 + if (input < 1 || input > 3) {
223 - .asInt())); 257 + log.debug("Wrong ReservedPacketCircuitType: {} for interface index {}.", circuitType, index);
224 - isisInterface.setAreaAddress(jsonNode1.path(IsisConstants.AREAADDRESS).asText()); 258 + continue;
225 - isisInterface.setAreaLength(jsonNode1.path(IsisConstants.AREALENGTH).asInt()); 259 + }
226 - isisInterface.setLspId(jsonNode1.path(IsisConstants.LSPID).asText()); 260 + isisInterface.setReservedPacketCircuitType(input);
227 - isisInterface.setCircuitId(jsonNode1.path(IsisConstants.CIRCUITID).asText()); 261 + } else {
228 - isisInterface.setHoldingTime(jsonNode1.path(IsisConstants.HOLDINGTIME).asInt()); 262 + log.debug("Wrong ReservedPacketCircuitType: {} for interface index {}.", circuitType, index);
229 - isisInterface.setPriority(jsonNode1.path(IsisConstants.PRIORITY).asInt()); 263 + continue;
230 - isisInterface.setHelloInterval(jsonNode1.path(IsisConstants.HELLOINTERVAL).asInt()); 264 + }
265 + String networkType = jsonNode1.path(IsisConstants.NETWORKTYPE).asText();
266 + if (isPrimitive(networkType)) {
267 + int input = Integer.parseInt(networkType);
268 + if (input < 1 || input > 2) {
269 + log.debug("Wrong networkType: {} for interface index {}.", networkType, index);
270 + continue;
271 + }
272 + isisInterface.setNetworkType(IsisNetworkType.get(input));
273 + } else {
274 + log.debug("Wrong networkType: {} for interface index {}.", networkType, index);
275 + continue;
276 + }
277 + String areaAddress = jsonNode1.path(IsisConstants.AREAADDRESS).asText();
278 + if (isPrimitive(areaAddress)) {
279 + if (areaAddress.length() > 7) {
280 + log.debug("Wrong areaAddress: {} for interface index {}.", areaAddress, index);
281 + continue;
282 + }
283 + isisInterface.setAreaAddress(areaAddress);
284 + } else {
285 + log.debug("Wrong areaAddress: {} for interface index {}.", areaAddress, index);
286 + continue;
287 + }
288 + String circuitId = jsonNode1.path(IsisConstants.CIRCUITID).asText();
289 + if (isPrimitive(circuitId)) {
290 + int input = Integer.parseInt(circuitId);
291 + if (input < 1) {
292 + log.debug("Wrong circuitId: {} for interface index {}.", circuitId, index);
293 + continue;
294 + }
295 + isisInterface.setCircuitId(circuitId);
296 + } else {
297 + log.debug("Wrong circuitId: {} for interface index {}.", circuitId, index);
298 + continue;
299 + }
300 + String holdingTime = jsonNode1.path(IsisConstants.HOLDINGTIME).asText();
301 + if (isPrimitive(holdingTime)) {
302 + int input = Integer.parseInt(holdingTime);
303 + if (input < 1 || input > 255) {
304 + log.debug("Wrong holdingTime: {} for interface index {}.", holdingTime, index);
305 + continue;
306 + }
307 + isisInterface.setHoldingTime(input);
308 + } else {
309 + log.debug("Wrong holdingTime: {} for interface index {}.", holdingTime, index);
310 + continue;
311 + }
312 + String helloInterval = jsonNode1.path(IsisConstants.HELLOINTERVAL).asText();
313 + if (isPrimitive(helloInterval)) {
314 + int interval = Integer.parseInt(helloInterval);
315 + if (interval > 0 && interval <= 255) {
316 + isisInterface.setHelloInterval(interval);
317 + } else {
318 + log.debug("Wrong hello interval: {} for interface index {}.", helloInterval, index);
319 + continue;
320 + }
321 + } else {
322 + log.debug("Wrong hello interval: {} for interface index {}.", helloInterval, index);
323 + continue;
324 + }
231 interfaceList.add(isisInterface); 325 interfaceList.add(isisInterface);
232 } 326 }
233 - IsisProcess process = new DefaultIsisProcess(); 327 + if (interfaceList.size() > 0) {
234 - process.setProcessId(jsonNode.path(IsisConstants.PROCESSESID).asText()); 328 + IsisProcess process = new DefaultIsisProcess();
235 - process.setIsisInterfaceList(interfaceList); 329 + process.setProcessId(jsonNode.path(IsisConstants.PROCESSESID).asText());
236 - isisProcessesList.add(process); 330 + process.setIsisInterfaceList(interfaceList);
331 + isisProcessesList.add(process);
332 + }
237 }); 333 });
238 334
239 return isisProcessesList; 335 return isisProcessesList;
240 } 336 }
337 +
338 + /**
339 + * Returns interface MAC by index.
340 + *
341 + * @param interfaceIndex interface index
342 + * @return interface IP by index
343 + */
344 + private MacAddress getInterfaceMac(int interfaceIndex) {
345 + MacAddress macAddress = null;
346 + try {
347 + NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
348 + macAddress = MacAddress.valueOf(networkInterface.getHardwareAddress());
349 + } catch (Exception e) {
350 + log.debug("Error while getting Interface IP by index");
351 + return macAddress;
352 + }
353 +
354 + return macAddress;
355 + }
356 +
357 + /**
358 + * Returns interface IP by index.
359 + *
360 + * @param interfaceIndex interface index
361 + * @return interface IP by index
362 + */
363 + private Ip4Address getInterfaceIp(int interfaceIndex) {
364 + Ip4Address ipAddress = null;
365 + try {
366 + NetworkInterface networkInterface = NetworkInterface.getByIndex(interfaceIndex);
367 + Enumeration ipAddresses = networkInterface.getInetAddresses();
368 + while (ipAddresses.hasMoreElements()) {
369 + InetAddress address = (InetAddress) ipAddresses.nextElement();
370 + if (!address.isLinkLocalAddress()) {
371 + ipAddress = Ip4Address.valueOf(address.getAddress());
372 + break;
373 + }
374 + }
375 + } catch (Exception e) {
376 + log.debug("Error while getting Interface IP by index");
377 + return IsisConstants.DEFAULTIP;
378 + }
379 + return ipAddress;
380 + }
381 +
382 + /**
383 + * Returns interface MAC by index.
384 + *
385 + * @param interfaceIndex interface index
386 + * @return interface IP by index
387 + */
388 + private String getInterfaceMask(int interfaceIndex) {
389 + String subnetMask = null;
390 + try {
391 + Ip4Address ipAddress = getInterfaceIp(interfaceIndex);
392 + NetworkInterface networkInterface = NetworkInterface.getByInetAddress(
393 + InetAddress.getByName(ipAddress.toString()));
394 + Enumeration ipAddresses = networkInterface.getInetAddresses();
395 + int index = 0;
396 + while (ipAddresses.hasMoreElements()) {
397 + InetAddress address = (InetAddress) ipAddresses.nextElement();
398 + if (!address.isLinkLocalAddress()) {
399 + break;
400 + }
401 + index++;
402 + }
403 + int prfLen = networkInterface.getInterfaceAddresses().get(index).getNetworkPrefixLength();
404 + int shft = 0xffffffff << (32 - prfLen);
405 + int oct1 = ((byte) ((shft & 0xff000000) >> 24)) & 0xff;
406 + int oct2 = ((byte) ((shft & 0x00ff0000) >> 16)) & 0xff;
407 + int oct3 = ((byte) ((shft & 0x0000ff00) >> 8)) & 0xff;
408 + int oct4 = ((byte) (shft & 0x000000ff)) & 0xff;
409 + subnetMask = oct1 + "." + oct2 + "." + oct3 + "." + oct4;
410 + } catch (Exception e) {
411 + log.debug("Error while getting Interface network mask by index");
412 + return subnetMask;
413 + }
414 + return subnetMask;
415 + }
416 +
417 + /**
418 + * Checks if primitive or not.
419 + *
420 + * @param value input value
421 + * @return true if number else false
422 + */
423 + private boolean isPrimitive(String value) {
424 + boolean status = true;
425 + value = value.trim();
426 + if (value.length() < 1) {
427 + return false;
428 + }
429 + for (int i = 0; i < value.length(); i++) {
430 + char c = value.charAt(i);
431 + if (!Character.isDigit(c)) {
432 + status = false;
433 + break;
434 + }
435 + }
436 +
437 + return status;
438 + }
439 +
440 + /**
441 + * Checks if system id is valid or not.
442 + *
443 + * @param value input value
444 + * @return true if valid else false
445 + */
446 + private boolean isValidSystemId(String value) {
447 + value = value.trim();
448 + boolean status = true;
449 + if (value.length() != 14) {
450 + return false;
451 + }
452 + for (int i = 0; i < value.length(); i++) {
453 + char c = value.charAt(i);
454 + if (!Character.isDigit(c)) {
455 + if (!((i == 4 || i == 9) && c == '.')) {
456 + status = false;
457 + break;
458 + }
459 + }
460 + }
461 +
462 + return status;
463 + }
464 +
465 + /**
466 + * Disconnects the executor.
467 + */
468 + public void disconnectExecutor() {
469 + if (connectExecutor != null) {
470 + connectExecutor.shutdown();
471 + connectExecutor = null;
472 + }
473 + }
474 +
475 + /**
476 + * Connects to peer.
477 + */
478 + public void connectPeer() {
479 + scheduleConnectionRetry(this.connectRetryTime);
480 + }
481 +
482 + /**
483 + * Retry connection with exponential back-off mechanism.
484 + *
485 + * @param retryDelay retry delay
486 + */
487 + private void scheduleConnectionRetry(long retryDelay) {
488 + if (this.connectExecutor == null) {
489 + this.connectExecutor = Executors.newSingleThreadScheduledExecutor();
490 + }
491 + this.connectExecutor.schedule(new ConnectionRetry(), retryDelay, TimeUnit.MINUTES);
492 + }
493 +
494 + /**
495 + * Implements ISIS connection and manages connection to peer with back-off mechanism in case of failure.
496 + */
497 + class ConnectionRetry implements Runnable {
498 + @Override
499 + public void run() {
500 + log.debug("Connect to peer {}", IsisConstants.SHOST);
501 + initConnection();
502 + InetSocketAddress connectToSocket = new InetSocketAddress(IsisConstants.SHOST, isisPort.toInt());
503 + try {
504 + peerBootstrap.connect(connectToSocket).addListener(new ChannelFutureListener() {
505 + @Override
506 + public void operationComplete(ChannelFuture future) throws Exception {
507 + if (!future.isSuccess()) {
508 + connectRetryCounter++;
509 + log.error("Connection failed, ConnectRetryCounter {} remote host {}", connectRetryCounter,
510 + IsisConstants.SHOST);
511 + /*
512 + * Reconnect to peer on failure is exponential till 4 mins, later on retry after every 4
513 + * mins.
514 + */
515 + if (connectRetryTime < RETRY_INTERVAL) {
516 + connectRetryTime = (connectRetryTime != 0) ? connectRetryTime * 2 : 1;
517 + }
518 + scheduleConnectionRetry(connectRetryTime);
519 + } else {
520 + connectRetryCounter++;
521 + log.info("Connected to remote host {}, Connect Counter {}", IsisConstants.SHOST,
522 + connectRetryCounter);
523 + disconnectExecutor();
524 + isisChannelHandler.initializeInterfaceMap();
525 + //Send the config packet
526 + isisChannelHandler.sentConfigPacket(configPacket);
527 + return;
528 + }
529 + }
530 + });
531 + } catch (Exception e) {
532 + log.info("Connect peer exception : " + e.toString());
533 + disconnectExecutor();
534 + }
535 + }
536 + }
241 } 537 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -69,15 +69,14 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -69,15 +69,14 @@ public class DefaultIsisInterface implements IsisInterface {
69 private MacAddress interfaceMacAddress; 69 private MacAddress interfaceMacAddress;
70 private String intermediateSystemName; 70 private String intermediateSystemName;
71 private String systemId; 71 private String systemId;
72 - private String l1LanId; 72 + private String l1LanId = IsisConstants.DEFAULTLANID;
73 - private String l2LanId; 73 + private String l2LanId = IsisConstants.DEFAULTLANID;
74 private int idLength; 74 private int idLength;
75 private int maxAreaAddresses; 75 private int maxAreaAddresses;
76 private int reservedPacketCircuitType; 76 private int reservedPacketCircuitType;
77 private IsisNetworkType networkType; 77 private IsisNetworkType networkType;
78 private String areaAddress; 78 private String areaAddress;
79 private int areaLength; 79 private int areaLength;
80 - private String lspId;
81 private int holdingTime; 80 private int holdingTime;
82 private int priority; 81 private int priority;
83 private String circuitId; 82 private String circuitId;
...@@ -114,10 +113,25 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -114,10 +113,25 @@ public class DefaultIsisInterface implements IsisInterface {
114 * @param isisNeighbor ISIS neighbor instance 113 * @param isisNeighbor ISIS neighbor instance
115 */ 114 */
116 public void removeNeighbor(IsisNeighbor isisNeighbor) { 115 public void removeNeighbor(IsisNeighbor isisNeighbor) {
116 + log.debug("Neighbor removed - {}", isisNeighbor.neighborMacAddress());
117 + isisNeighbor.stopHoldingTimeCheck();
118 + isisNeighbor.stopInactivityTimeCheck();
117 neighborList.remove(isisNeighbor.neighborMacAddress()); 119 neighborList.remove(isisNeighbor.neighborMacAddress());
118 } 120 }
119 121
120 /** 122 /**
123 + * Removes all the neighbors.
124 + */
125 + public void removeNeighbors() {
126 + Set<MacAddress> neighbors = neighbors();
127 + for (MacAddress mac : neighbors) {
128 + removeNeighbor(lookup(mac));
129 + log.debug("Neighbor removed - {}", mac);
130 + }
131 + neighborList.clear();
132 + }
133 +
134 + /**
121 * Returns the ISIS neighbor instance if exists. 135 * Returns the ISIS neighbor instance if exists.
122 * 136 *
123 * @param isisNeighborMac mac address of the neighbor router 137 * @param isisNeighborMac mac address of the neighbor router
...@@ -400,24 +414,6 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -400,24 +414,6 @@ public class DefaultIsisInterface implements IsisInterface {
400 } 414 }
401 415
402 /** 416 /**
403 - * Returns LSP ID.
404 - *
405 - * @return LSP ID
406 - */
407 - public String getLspId() {
408 - return lspId;
409 - }
410 -
411 - /**
412 - * Sets LSP ID.
413 - *
414 - * @param lspId link state packet ID
415 - */
416 - public void setLspId(String lspId) {
417 - this.lspId = lspId;
418 - }
419 -
420 - /**
421 * Returns holding time. 417 * Returns holding time.
422 * 418 *
423 * @return holding time 419 * @return holding time
...@@ -518,9 +514,21 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -518,9 +514,21 @@ public class DefaultIsisInterface implements IsisInterface {
518 */ 514 */
519 public void processIsisMessage(IsisMessage isisMessage, IsisLsdb isisLsdb, Channel channel) { 515 public void processIsisMessage(IsisMessage isisMessage, IsisLsdb isisLsdb, Channel channel) {
520 log.debug("IsisInterfaceImpl::processIsisMessage...!!!"); 516 log.debug("IsisInterfaceImpl::processIsisMessage...!!!");
521 - if (channel == null) { 517 + this.channel = channel;
522 - this.channel = channel; 518 +
519 + if (isisMessage.sourceMac().equals(interfaceMacAddress)) {
520 + log.debug("Received our own message {}...!!!", isisMessage.isisPduType());
521 + return;
522 + }
523 +
524 + if (isisMessage.isisPduType() == IsisPduType.P2PHELLOPDU && networkType.equals(IsisNetworkType.BROADCAST)) {
525 + return;
526 + } else if ((isisMessage.isisPduType() == IsisPduType.L1HELLOPDU ||
527 + isisMessage.isisPduType() == IsisPduType.L2HELLOPDU)
528 + && networkType.equals(IsisNetworkType.P2P)) {
529 + return;
523 } 530 }
531 +
524 if (this.isisLsdb == null) { 532 if (this.isisLsdb == null) {
525 this.isisLsdb = isisLsdb; 533 this.isisLsdb = isisLsdb;
526 } 534 }
...@@ -543,7 +551,7 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -543,7 +551,7 @@ public class DefaultIsisInterface implements IsisInterface {
543 break; 551 break;
544 case L1PSNP: 552 case L1PSNP:
545 case L2PSNP: 553 case L2PSNP:
546 - log.debug("Received a PSNP packet...!!!"); 554 + processPsnPduMessage(isisMessage, channel);
547 break; 555 break;
548 default: 556 default:
549 log.debug("Unknown packet to process...!!!"); 557 log.debug("Unknown packet to process...!!!");
...@@ -560,6 +568,13 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -560,6 +568,13 @@ public class DefaultIsisInterface implements IsisInterface {
560 public boolean validateHelloMessage(HelloPdu helloPdu) { 568 public boolean validateHelloMessage(HelloPdu helloPdu) {
561 boolean isValid = false; 569 boolean isValid = false;
562 570
571 + if ((helloPdu.circuitType() == IsisRouterType.L1.value() &&
572 + reservedPacketCircuitType == IsisRouterType.L2.value()) ||
573 + (helloPdu.circuitType() == IsisRouterType.L2.value() &&
574 + reservedPacketCircuitType == IsisRouterType.L1.value())) {
575 + return false;
576 + }
577 +
563 //Local InterfaceAddress TLV and compare with the IP Interface address and check if they are in same subnet 578 //Local InterfaceAddress TLV and compare with the IP Interface address and check if they are in same subnet
564 List<Ip4Address> interfaceIpAddresses = helloPdu.interfaceIpAddresses(); 579 List<Ip4Address> interfaceIpAddresses = helloPdu.interfaceIpAddresses();
565 Ip4Address neighborIp = (helloPdu.interfaceIpAddresses() != null) ? 580 Ip4Address neighborIp = (helloPdu.interfaceIpAddresses() != null) ?
...@@ -569,11 +584,16 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -569,11 +584,16 @@ public class DefaultIsisInterface implements IsisInterface {
569 } 584 }
570 585
571 //Verify if it's in same area, Areas which the router belongs to 586 //Verify if it's in same area, Areas which the router belongs to
572 - List<String> areas = helloPdu.areaAddress(); 587 + if (helloPdu.circuitType() == IsisRouterType.L1.value()) {
573 - for (String area : areas) { 588 + List<String> areas = helloPdu.areaAddress();
574 - if (areaAddress.equals(area)) { 589 + for (String area : areas) {
575 - isValid = true; 590 + if (areaAddress.equals(area)) {
591 + isValid = true;
592 + }
576 } 593 }
594 + } else if (helloPdu.circuitType() == IsisRouterType.L2.value() ||
595 + helloPdu.circuitType() == IsisRouterType.L1L2.value()) {
596 + isValid = true;
577 } 597 }
578 598
579 return isValid; 599 return isValid;
...@@ -585,6 +605,7 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -585,6 +605,7 @@ public class DefaultIsisInterface implements IsisInterface {
585 * @param neighborMac neighbor MAc address 605 * @param neighborMac neighbor MAc address
586 * @return true if neighbor exist else false 606 * @return true if neighbor exist else false
587 */ 607 */
608 +
588 private boolean isNeighborInList(MacAddress neighborMac) { 609 private boolean isNeighborInList(MacAddress neighborMac) {
589 return neighborList.containsKey(neighborMac); 610 return neighborList.containsKey(neighborMac);
590 } 611 }
...@@ -623,9 +644,8 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -623,9 +644,8 @@ public class DefaultIsisInterface implements IsisInterface {
623 log.debug("IsisInterfaceImpl::processHelloMessage::Interface Type {} ISISInterfaceState {} ", 644 log.debug("IsisInterfaceImpl::processHelloMessage::Interface Type {} ISISInterfaceState {} ",
624 networkType, interfaceState); 645 networkType, interfaceState);
625 646
626 - //If L1 Hello, validate the area, network and max address 647 + //If validate the area, network and max address
627 - if (IsisPduType.get(helloPacket.pduType()) == IsisPduType.L1HELLOPDU && 648 + if (!validateHelloMessage(helloPacket)) {
628 - !validateHelloMessage(helloPacket)) {
629 return; 649 return;
630 } 650 }
631 651
...@@ -637,6 +657,7 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -637,6 +657,7 @@ public class DefaultIsisInterface implements IsisInterface {
637 addNeighbouringRouter(neighbor); 657 addNeighbouringRouter(neighbor);
638 } 658 }
639 659
660 + neighbor.setHoldingTime(helloPacket.holdingTime());
640 neighbor.stopInactivityTimeCheck(); 661 neighbor.stopInactivityTimeCheck();
641 neighbor.startInactivityTimeCheck(); 662 neighbor.startInactivityTimeCheck();
642 663
...@@ -644,24 +665,29 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -644,24 +665,29 @@ public class DefaultIsisInterface implements IsisInterface {
644 String lanId = helloPacket.lanId(); 665 String lanId = helloPacket.lanId();
645 666
646 if (IsisPduType.L1HELLOPDU == helloPacket.isisPduType()) { 667 if (IsisPduType.L1HELLOPDU == helloPacket.isisPduType()) {
647 - buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel); 668 + buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel,
669 + IsisRouterType.get(helloPacket.circuitType()));
648 l1LanId = lanId; 670 l1LanId = lanId;
649 neighbor.setL1LanId(lanId); 671 neighbor.setL1LanId(lanId);
650 //if a change in lanid 672 //if a change in lanid
651 } else if (IsisPduType.L2HELLOPDU == helloPacket.isisPduType()) { 673 } else if (IsisPduType.L2HELLOPDU == helloPacket.isisPduType()) {
652 - buildUpdateAndSendSelfGeneratedLspIfDisChange(l1LanId, lanId, channel); 674 + buildUpdateAndSendSelfGeneratedLspIfDisChange(l2LanId, lanId, channel,
675 + IsisRouterType.get(helloPacket.circuitType()));
653 l2LanId = lanId; 676 l2LanId = lanId;
654 neighbor.setL2LanId(lanId); 677 neighbor.setL2LanId(lanId);
655 } 678 }
656 679
657 //Check in neighbors list our MAC address present 680 //Check in neighbors list our MAC address present
658 List<MacAddress> neighbors = helloPacket.neighborList(); 681 List<MacAddress> neighbors = helloPacket.neighborList();
659 - for (MacAddress macAddress : neighbors) { 682 + if (neighbors != null) {
660 - if (interfaceMacAddress.equals(macAddress)) { 683 + for (MacAddress macAddress : neighbors) {
661 - neighbor.setNeighborState(IsisInterfaceState.UP); 684 + if (interfaceMacAddress.equals(macAddress)) {
662 - //Build Self LSP add in LSDB and sent it. 685 + neighbor.setNeighborState(IsisInterfaceState.UP);
663 - buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); 686 + //Build Self LSP add in LSDB and sent it.
664 - break; 687 + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel,
688 + IsisRouterType.get(helloPacket.circuitType()));
689 + break;
690 + }
665 } 691 }
666 } 692 }
667 } 693 }
...@@ -671,7 +697,8 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -671,7 +697,8 @@ public class DefaultIsisInterface implements IsisInterface {
671 * 697 *
672 * @param channel netty channel instance 698 * @param channel netty channel instance
673 */ 699 */
674 - private void buildStoreAndSendSelfGeneratedLspIfNotExistInDb(Channel channel) { 700 + private void buildStoreAndSendSelfGeneratedLspIfNotExistInDb(Channel channel, IsisRouterType neighborRouterType) {
701 + this.channel = channel;
675 //Check our LSP is present in DB. else create a self LSP and store it and sent it 702 //Check our LSP is present in DB. else create a self LSP and store it and sent it
676 String lspKey = isisLsdb.lspKey(systemId); 703 String lspKey = isisLsdb.lspKey(systemId);
677 LspWrapper wrapper = null; 704 LspWrapper wrapper = null;
...@@ -690,18 +717,25 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -690,18 +717,25 @@ public class DefaultIsisInterface implements IsisInterface {
690 sendLsp(lsp, channel); 717 sendLsp(lsp, channel);
691 } 718 }
692 } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) { 719 } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) {
693 - wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey); 720 + if ((neighborRouterType == IsisRouterType.L1 || neighborRouterType == IsisRouterType.L1L2)) {
694 - if (wrapper == null) { 721 +
695 - LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); 722 + wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
696 - isisLsdb.addLsp(lsp, true, this); 723 + if (wrapper == null) {
697 - sendLsp(lsp, channel); 724 + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU,
725 + allConfiguredInterfaceIps);
726 + isisLsdb.addLsp(lsp, true, this);
727 + sendLsp(lsp, channel);
728 + }
698 } 729 }
699 730
700 - wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); 731 + if ((neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2)) {
701 - if (wrapper == null) { 732 + wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey);
702 - LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); 733 + if (wrapper == null) {
703 - isisLsdb.addLsp(lsp, true, this); 734 + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU,
704 - sendLsp(lsp, channel); 735 + allConfiguredInterfaceIps);
736 + isisLsdb.addLsp(lsp, true, this);
737 + sendLsp(lsp, channel);
738 + }
705 } 739 }
706 } 740 }
707 } 741 }
...@@ -714,29 +748,35 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -714,29 +748,35 @@ public class DefaultIsisInterface implements IsisInterface {
714 * @param channel netty channel instance 748 * @param channel netty channel instance
715 */ 749 */
716 private void buildUpdateAndSendSelfGeneratedLspIfDisChange(String previousLanId, 750 private void buildUpdateAndSendSelfGeneratedLspIfDisChange(String previousLanId,
717 - String latestLanId, Channel channel) { 751 + String latestLanId, Channel channel,
752 + IsisRouterType neighborRouterType) {
753 + this.channel = channel;
718 //If DIS change then build and sent LSP 754 //If DIS change then build and sent LSP
719 - if (previousLanId != null && !previousLanId.equals(IsisConstants.DEFAULTLANID) && 755 + if (!previousLanId.equals(latestLanId)) {
720 - !previousLanId.equals(latestLanId)) {
721 //Create a self LSP and Update it in DB and sent it 756 //Create a self LSP and Update it in DB and sent it
722 String lspKey = isisLsdb.lspKey(systemId); 757 String lspKey = isisLsdb.lspKey(systemId);
723 if (reservedPacketCircuitType == IsisRouterType.L1.value()) { 758 if (reservedPacketCircuitType == IsisRouterType.L1.value()) {
724 LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); 759 LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps);
725 isisLsdb.addLsp(lsp, true, this); 760 isisLsdb.addLsp(lsp, true, this);
726 sendLsp(lsp, channel); 761 sendLsp(lsp, channel);
727 - } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { 762 + } else if (reservedPacketCircuitType == IsisRouterType.L2.value() &&
763 + (neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2)) {
728 LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); 764 LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
729 isisLsdb.addLsp(lsp, true, this); 765 isisLsdb.addLsp(lsp, true, this);
730 sendLsp(lsp, channel); 766 sendLsp(lsp, channel);
731 } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) { 767 } else if (reservedPacketCircuitType == IsisRouterType.L1L2.value()) {
732 //L1 LSPDU 768 //L1 LSPDU
733 - LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps); 769 + if (neighborRouterType == IsisRouterType.L1 || neighborRouterType == IsisRouterType.L1L2) {
734 - isisLsdb.addLsp(lsp, true, this); 770 + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L1LSPDU, allConfiguredInterfaceIps);
735 - sendLsp(lsp, channel); 771 + isisLsdb.addLsp(lsp, true, this);
772 + sendLsp(lsp, channel);
773 + }
736 //L1 LSPDU 774 //L1 LSPDU
737 - lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps); 775 + if (neighborRouterType == IsisRouterType.L2 || neighborRouterType == IsisRouterType.L1L2) {
738 - isisLsdb.addLsp(lsp, true, this); 776 + LsPdu lsp = new LspGenerator().getLsp(this, lspKey, IsisPduType.L2LSPDU, allConfiguredInterfaceIps);
739 - sendLsp(lsp, channel); 777 + isisLsdb.addLsp(lsp, true, this);
778 + sendLsp(lsp, channel);
779 + }
740 } 780 }
741 } 781 }
742 782
...@@ -756,7 +796,9 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -756,7 +796,9 @@ public class DefaultIsisInterface implements IsisInterface {
756 lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION, 796 lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
757 IsisConstants.CHECKSUMPOSITION + 1); 797 IsisConstants.CHECKSUMPOSITION + 1);
758 //write to the channel 798 //write to the channel
759 - channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex)); 799 + if (channel != null && channel.isConnected() && channel.isOpen()) {
800 + channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex));
801 + }
760 } 802 }
761 803
762 /** 804 /**
...@@ -794,7 +836,7 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -794,7 +836,7 @@ public class DefaultIsisInterface implements IsisInterface {
794 addNeighbouringRouter(neighbor); 836 addNeighbouringRouter(neighbor);
795 } 837 }
796 neighbor.setNeighborState(IsisInterfaceState.DOWN); 838 neighbor.setNeighborState(IsisInterfaceState.DOWN);
797 - buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); 839 + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel, IsisRouterType.get(helloPacket.circuitType()));
798 } else if (stateTlv.adjacencyType() == IsisInterfaceState.DOWN.value()) { 840 } else if (stateTlv.adjacencyType() == IsisInterfaceState.DOWN.value()) {
799 neighbor = neighbouringRouter(isisMessage.sourceMac()); 841 neighbor = neighbouringRouter(isisMessage.sourceMac());
800 if (neighbor == null) { 842 if (neighbor == null) {
...@@ -805,6 +847,10 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -805,6 +847,10 @@ public class DefaultIsisInterface implements IsisInterface {
805 } else if (stateTlv.adjacencyType() == IsisInterfaceState.INITIAL.value()) { 847 } else if (stateTlv.adjacencyType() == IsisInterfaceState.INITIAL.value()) {
806 //Neighbor already present in the list 848 //Neighbor already present in the list
807 neighbor = neighbouringRouter(isisMessage.sourceMac()); 849 neighbor = neighbouringRouter(isisMessage.sourceMac());
850 + if (neighbor == null) {
851 + neighbor = new DefaultIsisNeighbor(helloPacket, this);
852 + addNeighbouringRouter(neighbor);
853 + }
808 neighbor.setNeighborState(IsisInterfaceState.INITIAL); 854 neighbor.setNeighborState(IsisInterfaceState.INITIAL);
809 neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId()); 855 neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId());
810 //interfaceState = IsisInterfaceState.UP; 856 //interfaceState = IsisInterfaceState.UP;
...@@ -813,9 +859,10 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -813,9 +859,10 @@ public class DefaultIsisInterface implements IsisInterface {
813 neighbor = neighbouringRouter(isisMessage.sourceMac()); 859 neighbor = neighbouringRouter(isisMessage.sourceMac());
814 neighbor.setNeighborState(IsisInterfaceState.UP); 860 neighbor.setNeighborState(IsisInterfaceState.UP);
815 neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId()); 861 neighbor.setLocalExtendedCircuitId(stateTlv.localCircuitId());
816 - buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel); 862 + buildStoreAndSendSelfGeneratedLspIfNotExistInDb(channel, IsisRouterType.get(helloPacket.circuitType()));
817 } 863 }
818 864
865 + neighbor.setHoldingTime(helloPacket.holdingTime());
819 neighbor.stopInactivityTimeCheck(); 866 neighbor.stopInactivityTimeCheck();
820 neighbor.startInactivityTimeCheck(); 867 neighbor.startInactivityTimeCheck();
821 } 868 }
...@@ -828,11 +875,36 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -828,11 +875,36 @@ public class DefaultIsisInterface implements IsisInterface {
828 */ 875 */
829 public void processLsPduMessage(IsisMessage isisMessage, Channel channel) { 876 public void processLsPduMessage(IsisMessage isisMessage, Channel channel) {
830 log.debug("Enters processLsPduMessage ...!!!"); 877 log.debug("Enters processLsPduMessage ...!!!");
878 + IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
879 + if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
880 + return;
881 + }
882 +
831 LsPdu lsPdu = (LsPdu) isisMessage; 883 LsPdu lsPdu = (LsPdu) isisMessage;
832 LspWrapper wrapper = isisLsdb.findLsp(lsPdu.isisPduType(), lsPdu.lspId()); 884 LspWrapper wrapper = isisLsdb.findLsp(lsPdu.isisPduType(), lsPdu.lspId());
833 if (wrapper == null || isisLsdb.isNewerOrSameLsp(lsPdu, wrapper.lsPdu()).equalsIgnoreCase("latest")) { 885 if (wrapper == null || isisLsdb.isNewerOrSameLsp(lsPdu, wrapper.lsPdu()).equalsIgnoreCase("latest")) {
834 - //not exist in the database or latest, then add it in database 886 + if (wrapper != null) { // verify if the LSA - is your own LSA - get system ID and compare LSP
835 - isisLsdb.addLsp(lsPdu, false, this); 887 + String lspKey = isisLsdb.lspKey(systemId);
888 + if (lsPdu.lspId().equals(lspKey)) {
889 + lsPdu.setSequenceNumber(lsPdu.sequenceNumber() + 1);
890 + if (lsPdu.pduType() == IsisPduType.L1LSPDU.value()) {
891 + // setting the ls sequence number
892 + isisLsdb.setL1LspSeqNo(lsPdu.sequenceNumber());
893 + } else if (lsPdu.pduType() == IsisPduType.L2LSPDU.value()) {
894 + // setting the ls sequence number
895 + isisLsdb.setL2LspSeqNo(lsPdu.sequenceNumber());
896 + }
897 + isisLsdb.addLsp(lsPdu, true, this);
898 + sendLsp(lsPdu, channel);
899 + } else {
900 + isisLsdb.addLsp(lsPdu, false, this);
901 + }
902 +
903 +
904 + } else {
905 + //not exist in the database or latest, then add it in database
906 + isisLsdb.addLsp(lsPdu, false, this);
907 + }
836 } 908 }
837 909
838 //If network type is P2P, acknowledge with a PSNP 910 //If network type is P2P, acknowledge with a PSNP
...@@ -865,135 +937,113 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -865,135 +937,113 @@ public class DefaultIsisInterface implements IsisInterface {
865 IsisConstants.RESERVEDPOSITION); 937 IsisConstants.RESERVEDPOSITION);
866 flagValue = false; 938 flagValue = false;
867 //write to the channel 939 //write to the channel
868 - channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex)); 940 + if (channel != null && channel.isConnected() && channel.isOpen()) {
941 + channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
942 + }
869 } 943 }
870 } 944 }
871 945
872 /** 946 /**
873 - * Processes CSN PDU message. 947 + * Processes PSN PDU message.
948 + * Checks for self originated LSP entries in PSNP message and sends the missing LSP.
874 * 949 *
875 - * @param isisMessage CSN PDU message instance 950 + * @param isisMessage PSN PDU message instance
876 * @param channel channel instance 951 * @param channel channel instance
877 */ 952 */
878 - public void processCsnPduMessage(IsisMessage isisMessage, Channel channel) { 953 + public void processPsnPduMessage(IsisMessage isisMessage, Channel channel) {
879 - log.debug("Enters processCsnPduMessage ...!!!"); 954 + log.debug("Enters processPsnPduMessage ...!!!");
880 - if (reservedPacketCircuitType == IsisRouterType.L1.value()) { 955 + //If adjacency not formed don't process.
881 - processOnL1CsnPdu(isisMessage, channel); 956 + IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
882 - } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) { 957 + if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
883 - processOnL2CsnPdu(isisMessage, channel); 958 + return;
884 } 959 }
885 - }
886 960
887 - /** 961 + Psnp psnPacket = (Psnp) isisMessage;
888 - * Process the isisMessage which belongs to L1 CSN PDU. 962 + List<IsisTlv> isisTlvs = psnPacket.getAllTlv();
889 - * checks the database for this LsPdu if it exists further check for sequence number 963 + Iterator iterator = isisTlvs.iterator();
890 - * sequence number is greater will send PsnPdu. 964 + while (iterator.hasNext()) {
891 - * 965 + IsisTlv isisTlv = (IsisTlv) iterator.next();
892 - * @param isisMessage CSN PDU message instance 966 + if (isisTlv instanceof LspEntriesTlv) {
893 - * @param channel netty channel instance 967 + LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv;
894 - */ 968 + List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry();
895 - private void processOnL1CsnPdu(IsisMessage isisMessage, Channel channel) { 969 + Iterator lspEntryListIterator = lspEntryList.iterator();
896 - Csnp csnPacket = (Csnp) isisMessage; 970 + while (lspEntryListIterator.hasNext()) {
897 - List<LspEntry> lspEntryRequestList = new ArrayList<>(); 971 + LspEntry lspEntry = (LspEntry) lspEntryListIterator.next();
898 - boolean selfOriginatedFound = false; 972 + String lspKey = lspEntry.lspId();
899 - if (IsisPduType.L1CSNP.equals(csnPacket.isisPduType())) { 973 + LspWrapper lspWrapper = isisLsdb.findLsp(psnPacket.isisPduType(), lspKey);
900 - List<IsisTlv> isisTlvs = csnPacket.getAllTlv(); 974 + if (lspWrapper != null) {
901 - Iterator iterator = isisTlvs.iterator(); 975 + if (lspWrapper.isSelfOriginated()) {
902 - while (iterator.hasNext()) { 976 + //Sent the LSP
903 - IsisTlv isisTlv = (IsisTlv) iterator.next(); 977 + sendLsp((LsPdu) lspWrapper.lsPdu(), channel);
904 - if (isisTlv instanceof LspEntriesTlv) {
905 - LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv;
906 - List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry();
907 - Iterator lspEntryListIterator = lspEntryList.iterator();
908 - while (lspEntryListIterator.hasNext()) {
909 - LspEntry lspEntry = (LspEntry) lspEntryListIterator.next();
910 - String lspKey = lspEntry.lspId();
911 - LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
912 - if (lspWrapper != null) {
913 - LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu();
914 - if (lspWrapper.isSelfOriginated()) {
915 - selfOriginatedFound = true;
916 - if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) {
917 - sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel);
918 - }
919 - } else {
920 - if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) {
921 - lspEntryRequestList.add(lspEntry);
922 - flagValue = true;
923 - }
924 - }
925 - } else {
926 - lspEntryRequestList.add(lspEntry);
927 - flagValue = true;
928 } 978 }
929 } 979 }
930 } 980 }
931 } 981 }
932 - if (flagValue) {
933 - sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel);
934 - }
935 -
936 - if (!selfOriginatedFound) {
937 - String lspKey = isisLsdb.lspKey(systemId);
938 - LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L1LSPDU, lspKey);
939 - sendLsp((LsPdu) wrapper.lsPdu(), channel);
940 - }
941 } 982 }
942 } 983 }
943 984
944 /** 985 /**
945 - * Process the isisMessage which belongs to L2 CSNP. 986 + * Processes CSN PDU message.
946 - * checks the database for this LsPdu if it exists further check for sequence number
947 - * sequence number is greater will send PsnPdu.
948 * 987 *
949 - * @param isisMessage received CSNP message 988 + * @param isisMessage CSN PDU message instance
950 - * @param channel netty channel instance 989 + * @param channel channel instance
951 */ 990 */
952 - private void processOnL2CsnPdu(IsisMessage isisMessage, Channel channel) { 991 + public void processCsnPduMessage(IsisMessage isisMessage, Channel channel) {
992 + log.debug("Enters processCsnPduMessage ...!!!");
993 + IsisNeighbor neighbor = neighbouringRouter(isisMessage.sourceMac());
994 + if (networkType == IsisNetworkType.BROADCAST && neighbor == null) {
995 + return;
996 + }
997 +
953 Csnp csnPacket = (Csnp) isisMessage; 998 Csnp csnPacket = (Csnp) isisMessage;
999 + IsisPduType psnPduType = (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) ?
1000 + IsisPduType.L2PSNP : IsisPduType.L1PSNP;
1001 + IsisPduType lsPduType = (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) ?
1002 + IsisPduType.L2LSPDU : IsisPduType.L1LSPDU;
1003 +
954 List<LspEntry> lspEntryRequestList = new ArrayList<>(); 1004 List<LspEntry> lspEntryRequestList = new ArrayList<>();
955 boolean selfOriginatedFound = false; 1005 boolean selfOriginatedFound = false;
956 - if (IsisPduType.L2CSNP.equals(csnPacket.isisPduType())) { 1006 + List<IsisTlv> isisTlvs = csnPacket.getAllTlv();
957 - List<IsisTlv> isisTlvs = csnPacket.getAllTlv(); 1007 + Iterator iterator = isisTlvs.iterator();
958 - Iterator iterator = isisTlvs.iterator(); 1008 + while (iterator.hasNext()) {
959 - while (iterator.hasNext()) { 1009 + IsisTlv isisTlv = (IsisTlv) iterator.next();
960 - IsisTlv isisTlv = (IsisTlv) iterator.next(); 1010 + if (isisTlv instanceof LspEntriesTlv) {
961 - if (isisTlv instanceof LspEntriesTlv) { 1011 + LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv;
962 - LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv; 1012 + List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry();
963 - List<LspEntry> lspEntryList = lspEntriesTlv.lspEntry(); 1013 + Iterator lspEntryListIterator = lspEntryList.iterator();
964 - Iterator lspEntryListIterator = lspEntryList.iterator(); 1014 + while (lspEntryListIterator.hasNext()) {
965 - while (lspEntryListIterator.hasNext()) { 1015 + LspEntry lspEntry = (LspEntry) lspEntryListIterator.next();
966 - LspEntry lspEntry = (LspEntry) lspEntryListIterator.next(); 1016 + String lspKey = lspEntry.lspId();
967 - String lspKey = lspEntry.lspId(); 1017 + LspWrapper lspWrapper = isisLsdb.findLsp(lsPduType, lspKey);
968 - LspWrapper lspWrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); 1018 + if (lspWrapper != null) {
969 - if (lspWrapper != null) { 1019 + LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu();
970 - LsPdu lsPdu = (LsPdu) lspWrapper.lsPdu(); 1020 + if (lspWrapper.isSelfOriginated()) {
971 - if (lspWrapper.isSelfOriginated()) { 1021 + selfOriginatedFound = true;
972 - selfOriginatedFound = true; 1022 + if (lspEntry.lspSequenceNumber() < lsPdu.sequenceNumber()) {
973 - if (lspEntry.lspSequenceNumber() > lsPdu.sequenceNumber()) { 1023 + sendLsp(lsPdu, channel);
974 - sendLsPduMessage(lspEntry.lspSequenceNumber(), csnPacket.isisPduType(), channel);
975 - }
976 - } else {
977 - if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) {
978 - lspEntryRequestList.add(lspEntry);
979 - flagValue = true;
980 - }
981 } 1024 }
982 } else { 1025 } else {
983 - lspEntryRequestList.add(lspEntry); 1026 + if (lsPdu.sequenceNumber() < lspEntry.lspSequenceNumber()) {
984 - flagValue = true; 1027 + lspEntryRequestList.add(lspEntry);
1028 + flagValue = true;
1029 + }
985 } 1030 }
1031 + } else {
1032 + lspEntryRequestList.add(lspEntry);
1033 + flagValue = true;
986 } 1034 }
987 } 1035 }
988 } 1036 }
989 - if (flagValue) { 1037 + }
990 - sendPsnPduMessage(lspEntryRequestList, csnPacket.isisPduType(), channel); 1038 + if (flagValue) {
991 - lspEntryRequestList.clear(); 1039 + sendPsnPduMessage(lspEntryRequestList, psnPduType, channel);
992 - } 1040 + lspEntryRequestList.clear();
1041 + }
993 1042
994 - if (!selfOriginatedFound) { 1043 + if (!selfOriginatedFound) {
995 - String lspKey = isisLsdb.lspKey(systemId); 1044 + String lspKey = isisLsdb.lspKey(systemId);
996 - LspWrapper wrapper = isisLsdb.findLsp(IsisPduType.L2LSPDU, lspKey); 1045 + LspWrapper wrapper = isisLsdb.findLsp(lsPduType, lspKey);
1046 + if (wrapper != null) {
997 sendLsp((LsPdu) wrapper.lsPdu(), channel); 1047 sendLsp((LsPdu) wrapper.lsPdu(), channel);
998 } 1048 }
999 } 1049 }
...@@ -1007,13 +1057,7 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -1007,13 +1057,7 @@ public class DefaultIsisInterface implements IsisInterface {
1007 * @param channel netty channel instance 1057 * @param channel netty channel instance
1008 */ 1058 */
1009 private void sendPsnPduMessage(List<LspEntry> lspEntryRequestList, IsisPduType isisPduType, Channel channel) { 1059 private void sendPsnPduMessage(List<LspEntry> lspEntryRequestList, IsisPduType isisPduType, Channel channel) {
1010 - IsisPduType psnpType = null; 1060 + IsisHeader isisHeader = new LspGenerator().getHeader(isisPduType);
1011 - if (isisPduType == IsisPduType.L1CSNP) {
1012 - psnpType = IsisPduType.L1PSNP;
1013 - } else if (reservedPacketCircuitType == IsisRouterType.L2.value()) {
1014 - psnpType = IsisPduType.L2PSNP;
1015 - }
1016 - IsisHeader isisHeader = new LspGenerator().getHeader(psnpType);
1017 Psnp psnp = new Psnp(isisHeader); 1061 Psnp psnp = new Psnp(isisHeader);
1018 psnp.setSourceId(lspKeyP2P(this.systemId)); 1062 psnp.setSourceId(lspKeyP2P(this.systemId));
1019 TlvHeader tlvHeader = new TlvHeader(); 1063 TlvHeader tlvHeader = new TlvHeader();
...@@ -1021,6 +1065,9 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -1021,6 +1065,9 @@ public class DefaultIsisInterface implements IsisInterface {
1021 tlvHeader.setTlvLength(0); 1065 tlvHeader.setTlvLength(0);
1022 LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader); 1066 LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
1023 for (LspEntry lspEntry : lspEntryRequestList) { 1067 for (LspEntry lspEntry : lspEntryRequestList) {
1068 + lspEntry.setLspChecksum(0);
1069 + lspEntry.setLspSequenceNumber(0);
1070 + lspEntry.setRemainingTime(0);
1024 lspEntriesTlv.addLspEntry(lspEntry); 1071 lspEntriesTlv.addLspEntry(lspEntry);
1025 } 1072 }
1026 psnp.addTlv(lspEntriesTlv); 1073 psnp.addTlv(lspEntriesTlv);
...@@ -1031,7 +1078,9 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -1031,7 +1078,9 @@ public class DefaultIsisInterface implements IsisInterface {
1031 IsisConstants.RESERVEDPOSITION); 1078 IsisConstants.RESERVEDPOSITION);
1032 flagValue = false; 1079 flagValue = false;
1033 //write to the channel 1080 //write to the channel
1034 - channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex)); 1081 + if (channel != null && channel.isConnected() && channel.isOpen()) {
1082 + channel.write(IsisUtil.framePacket(psnpBytes, interfaceIndex));
1083 + }
1035 } 1084 }
1036 1085
1037 /** 1086 /**
...@@ -1048,28 +1097,6 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -1048,28 +1097,6 @@ public class DefaultIsisInterface implements IsisInterface {
1048 } 1097 }
1049 1098
1050 /** 1099 /**
1051 - * Sends the link state PDU with latest self generated lsp entry.
1052 - *
1053 - * @param sequenceNumber sequence number of the self generated lsp
1054 - * @param isisPduType intermediate system type
1055 - * @param channel netty channel instance
1056 - */
1057 - private void sendLsPduMessage(int sequenceNumber, IsisPduType isisPduType, Channel channel) {
1058 - String lspKey = isisLsdb.lspKey(systemId);
1059 - LsPdu lsp = new LspGenerator().getLsp(this, lspKey, isisPduType, allConfiguredInterfaceIps);
1060 - lsp.setSequenceNumber(sequenceNumber);
1061 - byte[] lspBytes = lsp.asBytes();
1062 - lspBytes = IsisUtil.addLengthAndMarkItInReserved(lspBytes, IsisConstants.LENGTHPOSITION,
1063 - IsisConstants.LENGTHPOSITION + 1,
1064 - IsisConstants.RESERVEDPOSITION);
1065 - lspBytes = IsisUtil.addChecksum(lspBytes, IsisConstants.CHECKSUMPOSITION,
1066 - IsisConstants.CHECKSUMPOSITION + 1);
1067 - //write to the channel
1068 - channel.write(IsisUtil.framePacket(lspBytes, interfaceIndex));
1069 - }
1070 -
1071 -
1072 - /**
1073 * Starts the hello timer which sends hello packet every configured seconds. 1100 * Starts the hello timer which sends hello packet every configured seconds.
1074 * 1101 *
1075 * @param channel netty channel instance 1102 * @param channel netty channel instance
...@@ -1083,4 +1110,12 @@ public class DefaultIsisInterface implements IsisInterface { ...@@ -1083,4 +1110,12 @@ public class DefaultIsisInterface implements IsisInterface {
1083 exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0, 1110 exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0,
1084 helloInterval, TimeUnit.SECONDS); 1111 helloInterval, TimeUnit.SECONDS);
1085 } 1112 }
1113 +
1114 + /**
1115 + * Stops the hello timer which sends hello packet every configured seconds.
1116 + */
1117 + public void stopHelloSender() {
1118 + log.debug("IsisInterfaceImpl::stopHelloSender");
1119 + exServiceHello.shutdown();
1120 + }
1086 } 1121 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -88,6 +88,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -88,6 +88,7 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
88 } 88 }
89 this.isisInterface = isisInterface; 89 this.isisInterface = isisInterface;
90 startHoldingTimeCheck(); 90 startHoldingTimeCheck();
91 + log.debug("Neighbor added - {}", neighborMacAddress);
91 } 92 }
92 93
93 /** 94 /**
...@@ -387,6 +388,10 @@ public class DefaultIsisNeighbor implements IsisNeighbor { ...@@ -387,6 +388,10 @@ public class DefaultIsisNeighbor implements IsisNeighbor {
387 @Override 388 @Override
388 public void run() { 389 public void run() {
389 holdingTime--; 390 holdingTime--;
391 + if (holdingTime <= 0) {
392 + log.debug("Calling neighbor down. Holding time is 0.");
393 + neighborDown();
394 + }
390 } 395 }
391 } 396 }
392 } 397 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -94,13 +94,35 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler { ...@@ -94,13 +94,35 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
94 for (IsisInterface isisUpdatedInterface : isisUpdatedProcess.isisInterfaceList()) { 94 for (IsisInterface isisUpdatedInterface : isisUpdatedProcess.isisInterfaceList()) {
95 IsisInterface isisInterface = isisInterfaceMap.get(isisUpdatedInterface.interfaceIndex()); 95 IsisInterface isisInterface = isisInterfaceMap.get(isisUpdatedInterface.interfaceIndex());
96 if (isisInterface == null) { 96 if (isisInterface == null) {
97 - isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface); 97 + isisInterfaceMap.put(isisUpdatedInterface.interfaceIndex(), isisUpdatedInterface);
98 - interfaceIps.add(isisInterface.interfaceIpAddress()); 98 + interfaceIps.add(isisUpdatedInterface.interfaceIpAddress());
99 } else { 99 } else {
100 - isisInterface.setReservedPacketCircuitType(isisUpdatedInterface.reservedPacketCircuitType()); 100 + if (isisInterface.intermediateSystemName() != isisUpdatedInterface.intermediateSystemName()) {
101 - isisInterface.setNetworkType(isisUpdatedInterface.networkType()); 101 + isisInterface.setIntermediateSystemName(isisUpdatedInterface.intermediateSystemName());
102 - isisInterface.setHoldingTime(isisUpdatedInterface.holdingTime()); 102 + }
103 - isisInterface.setHelloInterval(isisUpdatedInterface.helloInterval()); 103 + if (isisInterface.reservedPacketCircuitType() != isisUpdatedInterface.reservedPacketCircuitType()) {
104 + isisInterface.setReservedPacketCircuitType(isisUpdatedInterface.reservedPacketCircuitType());
105 + isisInterface.removeNeighbors();
106 + }
107 + if (isisInterface.circuitId() != isisUpdatedInterface.circuitId()) {
108 + isisInterface.setCircuitId(isisUpdatedInterface.circuitId());
109 + }
110 + if (isisInterface.networkType() != isisUpdatedInterface.networkType()) {
111 + isisInterface.setNetworkType(isisUpdatedInterface.networkType());
112 + isisInterface.removeNeighbors();
113 + }
114 + if (isisInterface.areaAddress() != isisUpdatedInterface.areaAddress()) {
115 + isisInterface.setAreaAddress(isisUpdatedInterface.areaAddress());
116 + }
117 + if (isisInterface.holdingTime() != isisUpdatedInterface.holdingTime()) {
118 + isisInterface.setHoldingTime(isisUpdatedInterface.holdingTime());
119 + }
120 + if (isisInterface.helloInterval() != isisUpdatedInterface.helloInterval()) {
121 + isisInterface.setHelloInterval(isisUpdatedInterface.helloInterval());
122 + isisInterface.stopHelloSender();
123 + isisInterface.startHelloSender(channel);
124 + }
125 +
104 isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface); 126 isisInterfaceMap.put(isisInterface.interfaceIndex(), isisInterface);
105 } 127 }
106 } 128 }
...@@ -144,6 +166,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler { ...@@ -144,6 +166,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
144 @Override 166 @Override
145 public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) { 167 public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent evt) {
146 log.debug("IsisChannelHandler::channelDisconnected...!!!"); 168 log.debug("IsisChannelHandler::channelDisconnected...!!!");
169 + if (controller != null) {
170 + controller.connectPeer();
171 + }
147 } 172 }
148 173
149 @Override 174 @Override
...@@ -169,8 +194,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler { ...@@ -169,8 +194,9 @@ public class IsisChannelHandler extends IdleStateAwareChannelHandler {
169 } else if (e.getCause() instanceof RejectedExecutionException) { 194 } else if (e.getCause() instanceof RejectedExecutionException) {
170 log.warn("Could not process message: queue full"); 195 log.warn("Could not process message: queue full");
171 } else { 196 } else {
172 - log.error("Error while processing message from ISIS {}", 197 + log.error("Error while processing message from ISIS {}, {}",
173 - e.getChannel().getRemoteAddress()); 198 + e.getChannel().getRemoteAddress(), e.getCause().getMessage());
199 + e.getCause().printStackTrace();
174 } 200 }
175 } 201 }
176 202
......
...@@ -45,7 +45,7 @@ public class IsisHelloPduSender implements Runnable { ...@@ -45,7 +45,7 @@ public class IsisHelloPduSender implements Runnable {
45 45
46 @Override 46 @Override
47 public void run() { 47 public void run() {
48 - if (channel != null) { 48 + if (channel != null && channel.isConnected() && channel.isOpen()) {
49 try { 49 try {
50 byte[] helloPdu = null; 50 byte[] helloPdu = null;
51 byte[] interfaceIndex = {(byte) isisInterface.interfaceIndex()}; 51 byte[] interfaceIndex = {(byte) isisInterface.interfaceIndex()};
......
...@@ -44,7 +44,6 @@ public class IsisMessageDecoder extends FrameDecoder { ...@@ -44,7 +44,6 @@ public class IsisMessageDecoder extends FrameDecoder {
44 log.info("Channel is not connected."); 44 log.info("Channel is not connected.");
45 return null; 45 return null;
46 } 46 }
47 -
48 IsisMessageReader messageReader = new IsisMessageReader(); 47 IsisMessageReader messageReader = new IsisMessageReader();
49 List<IsisMessage> isisMessageList = new LinkedList<>(); 48 List<IsisMessage> isisMessageList = new LinkedList<>();
50 int dataLength = buffer.readableBytes(); 49 int dataLength = buffer.readableBytes();
...@@ -74,8 +73,7 @@ public class IsisMessageDecoder extends FrameDecoder { ...@@ -74,8 +73,7 @@ public class IsisMessageDecoder extends FrameDecoder {
74 isisMessageList.add(message); 73 isisMessageList.add(message);
75 } 74 }
76 } 75 }
77 - 76 + return (isisMessageList.size() > 0) ? isisMessageList : null;
78 - return isisMessageList;
79 } 77 }
80 78
81 /** 79 /**
......
...@@ -45,7 +45,6 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -45,7 +45,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
45 private IsisLsdbAge lsdbAge = null; 45 private IsisLsdbAge lsdbAge = null;
46 46
47 47
48 -
49 private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 48 private int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
50 private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 49 private int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
51 50
...@@ -80,6 +79,7 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -80,6 +79,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
80 public void setL2LspSeqNo(int l2LspSeqNo) { 79 public void setL2LspSeqNo(int l2LspSeqNo) {
81 this.l2LspSeqNo = l2LspSeqNo; 80 this.l2LspSeqNo = l2LspSeqNo;
82 } 81 }
82 +
83 /** 83 /**
84 * Returns the LSDB LSP key. 84 * Returns the LSDB LSP key.
85 * 85 *
...@@ -96,6 +96,7 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -96,6 +96,7 @@ public class DefaultIsisLsdb implements IsisLsdb {
96 return lspKey.toString(); 96 return lspKey.toString();
97 } 97 }
98 98
99 +
99 /** 100 /**
100 * Returns the neighbor L1 database information. 101 * Returns the neighbor L1 database information.
101 * 102 *
...@@ -218,7 +219,12 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -218,7 +219,12 @@ public class DefaultIsisLsdb implements IsisLsdb {
218 byte[] checkSum = {lspBytes[IsisConstants.CHECKSUMPOSITION], lspBytes[IsisConstants.CHECKSUMPOSITION + 1]}; 219 byte[] checkSum = {lspBytes[IsisConstants.CHECKSUMPOSITION], lspBytes[IsisConstants.CHECKSUMPOSITION + 1]};
219 lspdu.setCheckSum(ChannelBuffers.copiedBuffer(checkSum).readUnsignedShort()); 220 lspdu.setCheckSum(ChannelBuffers.copiedBuffer(checkSum).readUnsignedShort());
220 } 221 }
221 - DefaultLspWrapper lspWrapper = new DefaultLspWrapper(); 222 +
223 + DefaultLspWrapper lspWrapper = (DefaultLspWrapper) findLsp(lspdu.isisPduType(), lspdu.lspId());
224 + if (lspWrapper == null) {
225 + lspWrapper = new DefaultLspWrapper();
226 + }
227 +
222 lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime()); 228 lspWrapper.setLspAgeReceived(IsisConstants.LSPMAXAGE - lspdu.remainingLifeTime());
223 lspWrapper.setLspType(IsisPduType.get(lspdu.pduType())); 229 lspWrapper.setLspType(IsisPduType.get(lspdu.pduType()));
224 lspWrapper.setLsPdu(lspdu); 230 lspWrapper.setLsPdu(lspdu);
...@@ -228,8 +234,8 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -228,8 +234,8 @@ public class DefaultIsisLsdb implements IsisLsdb {
228 lspWrapper.setIsisInterface(isisInterface); 234 lspWrapper.setIsisInterface(isisInterface);
229 lspWrapper.setLsdbAge(lsdbAge); 235 lspWrapper.setLsdbAge(lsdbAge);
230 addLsp(lspWrapper, lspdu.lspId()); 236 addLsp(lspWrapper, lspdu.lspId());
231 - log.debug("Added LSp In LSDB: {}", lspWrapper);
232 237
238 + log.debug("Added LSp In LSDB: {}", lspWrapper);
233 return true; 239 return true;
234 } 240 }
235 241
...@@ -270,7 +276,6 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -270,7 +276,6 @@ public class DefaultIsisLsdb implements IsisLsdb {
270 lspWrapper.lsPdu().isisPduType(), 276 lspWrapper.lsPdu().isisPduType(),
271 binNumber, lspWrapper.remainingLifetime()); 277 binNumber, lspWrapper.remainingLifetime());
272 } 278 }
273 -
274 return false; 279 return false;
275 } 280 }
276 281
...@@ -344,4 +349,4 @@ public class DefaultIsisLsdb implements IsisLsdb { ...@@ -344,4 +349,4 @@ public class DefaultIsisLsdb implements IsisLsdb {
344 break; 349 break;
345 } 350 }
346 } 351 }
347 -} 352 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -36,10 +36,10 @@ import java.util.concurrent.TimeUnit; ...@@ -36,10 +36,10 @@ import java.util.concurrent.TimeUnit;
36 */ 36 */
37 public class DefaultIsisLsdbAge implements IsisLsdbAge { 37 public class DefaultIsisLsdbAge implements IsisLsdbAge {
38 private static final Logger log = LoggerFactory.getLogger(DefaultIsisLsdbAge.class); 38 private static final Logger log = LoggerFactory.getLogger(DefaultIsisLsdbAge.class);
39 - protected static int ageCounter = 0; 39 + protected int ageCounter = 0;
40 private InternalAgeTimer dbAgeTimer; 40 private InternalAgeTimer dbAgeTimer;
41 private ScheduledExecutorService exServiceage; 41 private ScheduledExecutorService exServiceage;
42 - private Integer maxBins = 1200; 42 + private Integer maxBins = IsisConstants.LSPMAXAGE;
43 private Map<Integer, IsisLspBin> ageBins = new ConcurrentHashMap<>(maxBins); 43 private Map<Integer, IsisLspBin> ageBins = new ConcurrentHashMap<>(maxBins);
44 private int ageCounterRollOver = 0; 44 private int ageCounterRollOver = 0;
45 private IsisLspQueueConsumer queueConsumer = null; 45 private IsisLspQueueConsumer queueConsumer = null;
...@@ -202,7 +202,7 @@ public class DefaultIsisLsdbAge implements IsisLsdbAge { ...@@ -202,7 +202,7 @@ public class DefaultIsisLsdbAge implements IsisLsdbAge {
202 } else { 202 } else {
203 binNumber = ageCounter - IsisConstants.LSPREFRESH; 203 binNumber = ageCounter - IsisConstants.LSPREFRESH;
204 } 204 }
205 - if (binNumber > IsisConstants.LSPMAXAGE) { 205 + if (binNumber >= IsisConstants.LSPMAXAGE) {
206 binNumber = binNumber - IsisConstants.LSPMAXAGE; 206 binNumber = binNumber - IsisConstants.LSPMAXAGE;
207 } 207 }
208 IsisLspBin lspBin = ageBins.get(binNumber); 208 IsisLspBin lspBin = ageBins.get(binNumber);
......
...@@ -21,11 +21,14 @@ import org.onosproject.isis.controller.IsisPduType; ...@@ -21,11 +21,14 @@ import org.onosproject.isis.controller.IsisPduType;
21 import org.onosproject.isis.controller.LspWrapper; 21 import org.onosproject.isis.controller.LspWrapper;
22 import org.onosproject.isis.io.isispacket.pdu.LsPdu; 22 import org.onosproject.isis.io.isispacket.pdu.LsPdu;
23 import org.onosproject.isis.io.util.IsisConstants; 23 import org.onosproject.isis.io.util.IsisConstants;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
24 26
25 /** 27 /**
26 * Representation of LSP wrapper where the LSPs are stored with metadata. 28 * Representation of LSP wrapper where the LSPs are stored with metadata.
27 */ 29 */
28 public class DefaultLspWrapper implements LspWrapper { 30 public class DefaultLspWrapper implements LspWrapper {
31 + private static final Logger log = LoggerFactory.getLogger(DefaultLspWrapper.class);
29 private int binNumber = -1; 32 private int binNumber = -1;
30 private boolean selfOriginated = false; 33 private boolean selfOriginated = false;
31 private IsisPduType lspType; 34 private IsisPduType lspType;
...@@ -229,7 +232,15 @@ public class DefaultLspWrapper implements LspWrapper { ...@@ -229,7 +232,15 @@ public class DefaultLspWrapper implements LspWrapper {
229 int currentAge = 0; 232 int currentAge = 0;
230 //ls age received 233 //ls age received
231 if (lsdbAge.ageCounter() >= ageCounterWhenReceived) { 234 if (lsdbAge.ageCounter() >= ageCounterWhenReceived) {
235 + if (!selfOriginated) {
236 + if (ageCounterRollOverWhenAdded == lsdbAge.ageCounterRollOver()) {
232 currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived); 237 currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived);
238 + } else {
239 + return IsisConstants.LSPMAXAGE;
240 + }
241 + } else {
242 + currentAge = lspAgeReceived + (lsdbAge.ageCounter() - ageCounterWhenReceived);
243 + }
233 } else { 244 } else {
234 currentAge = lspAgeReceived + ((IsisConstants.LSPMAXAGE + lsdbAge.ageCounter()) 245 currentAge = lspAgeReceived + ((IsisConstants.LSPMAXAGE + lsdbAge.ageCounter())
235 - ageCounterWhenReceived); 246 - ageCounterWhenReceived);
...@@ -245,6 +256,8 @@ public class DefaultLspWrapper implements LspWrapper { ...@@ -245,6 +256,8 @@ public class DefaultLspWrapper implements LspWrapper {
245 return currentAge; 256 return currentAge;
246 } 257 }
247 258
259 +
260 +
248 /** 261 /**
249 * Returns remaining time. 262 * Returns remaining time.
250 * 263 *
...@@ -252,7 +265,7 @@ public class DefaultLspWrapper implements LspWrapper { ...@@ -252,7 +265,7 @@ public class DefaultLspWrapper implements LspWrapper {
252 */ 265 */
253 public int remainingLifetime() { 266 public int remainingLifetime() {
254 //Calculate the remaining lifetime 267 //Calculate the remaining lifetime
255 - remainingLifetime = IsisConstants.LSPMAXAGE - lsdbAge.ageCounter(); 268 + remainingLifetime = IsisConstants.LSPMAXAGE - currentAge();
256 return remainingLifetime; 269 return remainingLifetime;
257 } 270 }
258 271
......
...@@ -100,7 +100,9 @@ public class IsisLspQueueConsumer implements Runnable { ...@@ -100,7 +100,9 @@ public class IsisLspQueueConsumer implements Runnable {
100 IsisConstants.CHECKSUMPOSITION + 1); 100 IsisConstants.CHECKSUMPOSITION + 1);
101 //write to the channel 101 //write to the channel
102 channel.write(IsisUtil.framePacket(lspBytes, isisInterface.interfaceIndex())); 102 channel.write(IsisUtil.framePacket(lspBytes, isisInterface.interfaceIndex()));
103 - 103 + // Updating the database with resetting remaining life time to default.
104 + IsisLsdb isisDb = isisInterface.isisLsdb();
105 + isisDb.addLsp(lsPdu, true, isisInterface);
104 log.debug("LSPQueueConsumer: processRefreshLsp - Flooded SelfOriginated LSP {}", 106 log.debug("LSPQueueConsumer: processRefreshLsp - Flooded SelfOriginated LSP {}",
105 wrapper.lsPdu()); 107 wrapper.lsPdu());
106 } 108 }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 16
17 package org.onosproject.isis.controller.impl; 17 package org.onosproject.isis.controller.impl;
18 18
19 +import com.fasterxml.jackson.databind.JsonNode;
20 +import com.fasterxml.jackson.databind.ObjectMapper;
19 import org.junit.After; 21 import org.junit.After;
20 import org.junit.Before; 22 import org.junit.Before;
21 import org.junit.Test; 23 import org.junit.Test;
...@@ -30,10 +32,65 @@ import static org.junit.Assert.assertThat; ...@@ -30,10 +32,65 @@ import static org.junit.Assert.assertThat;
30 public class ControllerTest { 32 public class ControllerTest {
31 33
32 private Controller controller; 34 private Controller controller;
35 + private ObjectMapper mapper;
36 + private JsonNode jsonNode;
37 + private JsonNode jsonNode1;
38 + private String jsonString = "{" +
39 + " \"processes\": [{" +
40 + " \"processId\": \"4.4.4.4\"," +
41 + " \"interface\": [{" +
42 + " \"interfaceIndex\": \"2\"," +
43 + " \"macAddress\": \"08:00:27:b7:ab:bf\"," +
44 + " \"interfaceIp\": \"192.168.56.101\"," +
45 + " \"networkMask\": \"255.255.255.224\"," +
46 + " \"intermediateSystemName\": \"ROUTERONE\"," +
47 + " \"systemId\": \"2929.2929.2929\"," +
48 + " \"lanId\": \"0000.0000.0000.00\"," +
49 + " \"idLength\": \"0\"," +
50 + " \"maxAreaAddresses\": \"3\"," +
51 + " \"reservedPacketCircuitType\": \"1\"," +
52 + " \"circuitId\": \"10\"," +
53 + " \"networkType\": \"2\"," +
54 + " \"areaAddress\": \"490000\"," +
55 + " \"areaLength\": \"3\"," +
56 + " \"lspId\": \"1313131313130000\"," +
57 + " \"holdingTime\": \"50\"," +
58 + " \"helloInterval\": \"10\"," +
59 + " \"priority\": \"0\"" +
60 + " }]" +
61 + " }]" +
62 + "}";
63 + private String jsonString1 = "{" +
64 + " \"processes\": {" +
65 + " \"interface\": [{" +
66 + " \"interfaceIndex\": \"2\"," +
67 + " \"interfaceIp\": \"100.100.100.100\"," +
68 + " \"macAddress\": \"08:00:27:b7:ab:bf\"," +
69 + " \"networkMask\": \"255.255.255.224\"," +
70 + " \"intermediateSystemName\": \"ROUTERONE\"," +
71 + " \"systemId\": \"2929.2929.2929\"," +
72 + " \"lanId\": \"0000.0000.0000.00\"," +
73 + " \"idLength\": \"0\"," +
74 + " \"maxAreaAddresses\": \"3\"," +
75 + " \"reservedPacketCircuitType\": \"1\"," +
76 + " \"circuitId\": \"10\"," +
77 + " \"networkType\": \"2\"," +
78 + " \"areaAddress\": \"490000\"," +
79 + " \"areaLength\": \"3\"," +
80 + " \"lspId\": \"1313131313130000\"," +
81 + " \"holdingTime\": \"50\"," +
82 + " \"helloInterval\": \"10\"," +
83 + " \"priority\": \"0\"" +
84 + " }]" +
85 + " }" +
86 + "}";
33 87
34 @Before 88 @Before
35 public void setUp() throws Exception { 89 public void setUp() throws Exception {
36 controller = new Controller(); 90 controller = new Controller();
91 + mapper = new ObjectMapper();
92 + jsonNode = mapper.readTree(jsonString);
93 + jsonNode1 = mapper.readTree(jsonString1);
37 } 94 }
38 95
39 @After 96 @After
...@@ -58,4 +115,18 @@ public class ControllerTest { ...@@ -58,4 +115,18 @@ public class ControllerTest {
58 controller.getAllConfiguredProcesses(); 115 controller.getAllConfiguredProcesses();
59 assertThat(controller, is(notNullValue())); 116 assertThat(controller, is(notNullValue()));
60 } 117 }
118 +
119 + /**
120 + * Tests updateConfig() method.
121 + */
122 + @Test
123 + public void testUpdateConfig() throws Exception {
124 + jsonNode.path("interface");
125 + controller.updateConfig(jsonNode);
126 + assertThat(controller, is(notNullValue()));
127 +
128 + controller.updateConfig(jsonNode1);
129 + assertThat(controller, is(notNullValue()));
130 + }
131 +
61 } 132 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -15,9 +15,13 @@ ...@@ -15,9 +15,13 @@
15 */ 15 */
16 package org.onosproject.isis.controller.impl; 16 package org.onosproject.isis.controller.impl;
17 17
18 +import com.fasterxml.jackson.databind.JsonNode;
19 +import com.fasterxml.jackson.databind.ObjectMapper;
20 +import org.easymock.EasyMock;
18 import org.junit.After; 21 import org.junit.After;
19 import org.junit.Before; 22 import org.junit.Before;
20 import org.junit.Test; 23 import org.junit.Test;
24 +import org.onosproject.isis.controller.topology.IsisRouterListener;
21 25
22 import static org.hamcrest.CoreMatchers.is; 26 import static org.hamcrest.CoreMatchers.is;
23 import static org.hamcrest.CoreMatchers.notNullValue; 27 import static org.hamcrest.CoreMatchers.notNullValue;
...@@ -27,11 +31,43 @@ import static org.junit.Assert.assertThat; ...@@ -27,11 +31,43 @@ import static org.junit.Assert.assertThat;
27 * Unit test case for DefaultIsisController. 31 * Unit test case for DefaultIsisController.
28 */ 32 */
29 public class DefaultIsisControllerTest { 33 public class DefaultIsisControllerTest {
34 + private ObjectMapper mapper;
35 + private JsonNode jsonNode;
30 private DefaultIsisController defaultIsisController; 36 private DefaultIsisController defaultIsisController;
37 + private String jsonString = "{" +
38 + " \"processes\": [{" +
39 + " \"processId\": \"4.4.4.4\"," +
40 + " \"interface\": [{" +
41 + " \"interfaceIndex\": \"2\"," +
42 + " \"macAddress\": \"08:00:27:b7:ab:bf\"," +
43 + " \"interfaceIp\": \"192.168.56.101\"," +
44 + " \"networkMask\": \"255.255.255.224\"," +
45 + " \"intermediateSystemName\": \"ROUTERONE\"," +
46 + " \"systemId\": \"2929.2929.2929\"," +
47 + " \"lanId\": \"0000.0000.0000.00\"," +
48 + " \"idLength\": \"0\"," +
49 + " \"maxAreaAddresses\": \"3\"," +
50 + " \"reservedPacketCircuitType\": \"1\"," +
51 + " \"circuitId\": \"10\"," +
52 + " \"networkType\": \"2\"," +
53 + " \"areaAddress\": \"490000\"," +
54 + " \"areaLength\": \"3\"," +
55 + " \"lspId\": \"1313131313130000\"," +
56 + " \"holdingTime\": \"50\"," +
57 + " \"helloInterval\": \"10\"," +
58 + " \"priority\": \"0\"" +
59 + " }]" +
60 + " }]" +
61 + "}";
62 +
63 + private IsisRouterListener isisRouterListener;
31 64
32 @Before 65 @Before
33 public void setUp() throws Exception { 66 public void setUp() throws Exception {
34 defaultIsisController = new DefaultIsisController(); 67 defaultIsisController = new DefaultIsisController();
68 + mapper = new ObjectMapper();
69 + jsonNode = mapper.readTree(jsonString);
70 + isisRouterListener = EasyMock.createNiceMock(IsisRouterListener.class);
35 } 71 }
36 72
37 @After 73 @After
...@@ -66,4 +102,31 @@ public class DefaultIsisControllerTest { ...@@ -66,4 +102,31 @@ public class DefaultIsisControllerTest {
66 defaultIsisController.allConfiguredProcesses(); 102 defaultIsisController.allConfiguredProcesses();
67 assertThat(defaultIsisController, is(notNullValue())); 103 assertThat(defaultIsisController, is(notNullValue()));
68 } 104 }
105 +
106 + /**
107 + * Tests updateConfig() method.
108 + */
109 + @Test
110 + public void testUpdateConfig() throws Exception {
111 + defaultIsisController.updateConfig(jsonNode);
112 + assertThat(defaultIsisController, is(notNullValue()));
113 + }
114 +
115 + /**
116 + * Tests addRouterListener() method.
117 + */
118 + @Test
119 + public void testaddRouterListener() throws Exception {
120 + defaultIsisController.addRouterListener(isisRouterListener);
121 + assertThat(defaultIsisController, is(notNullValue()));
122 + }
123 +
124 + /**
125 + * Tests removeRouterListener() method.
126 + */
127 + @Test
128 + public void testremoveRouterListener() throws Exception {
129 + defaultIsisController.removeRouterListener(isisRouterListener);
130 + assertThat(defaultIsisController, is(notNullValue()));
131 + }
69 } 132 }
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
15 */ 15 */
16 package org.onosproject.isis.controller.impl; 16 package org.onosproject.isis.controller.impl;
17 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.channel.Channel;
18 import org.junit.After; 22 import org.junit.After;
19 import org.junit.Before; 23 import org.junit.Before;
20 import org.junit.Test; 24 import org.junit.Test;
...@@ -23,15 +27,30 @@ import org.onlab.packet.MacAddress; ...@@ -23,15 +27,30 @@ import org.onlab.packet.MacAddress;
23 import org.onosproject.isis.controller.IsisInterface; 27 import org.onosproject.isis.controller.IsisInterface;
24 import org.onosproject.isis.controller.IsisInterfaceState; 28 import org.onosproject.isis.controller.IsisInterfaceState;
25 import org.onosproject.isis.controller.IsisLsdb; 29 import org.onosproject.isis.controller.IsisLsdb;
30 +import org.onosproject.isis.controller.IsisMessage;
26 import org.onosproject.isis.controller.IsisNeighbor; 31 import org.onosproject.isis.controller.IsisNeighbor;
27 import org.onosproject.isis.controller.IsisNetworkType; 32 import org.onosproject.isis.controller.IsisNetworkType;
33 +import org.onosproject.isis.controller.IsisPduType;
34 +import org.onosproject.isis.controller.IsisRouterType;
35 +import org.onosproject.isis.controller.impl.lsdb.DefaultIsisLsdb;
28 import org.onosproject.isis.io.isispacket.IsisHeader; 36 import org.onosproject.isis.io.isispacket.IsisHeader;
29 -import org.onosproject.isis.io.isispacket.pdu.HelloPdu; 37 +import org.onosproject.isis.io.isispacket.pdu.Csnp;
30 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; 38 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
31 - 39 +import org.onosproject.isis.io.isispacket.pdu.LsPdu;
40 +import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
41 +import org.onosproject.isis.io.isispacket.pdu.Psnp;
42 +import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv;
43 +import org.onosproject.isis.io.isispacket.tlv.AreaAddressTlv;
44 +import org.onosproject.isis.io.isispacket.tlv.LspEntriesTlv;
45 +import org.onosproject.isis.io.isispacket.tlv.LspEntry;
46 +import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
47 +import org.onosproject.isis.io.isispacket.tlv.TlvType;
48 +
49 +import java.util.ArrayList;
50 +import java.util.List;
32 import java.util.Set; 51 import java.util.Set;
33 52
34 -import static org.hamcrest.CoreMatchers.is; 53 +import static org.hamcrest.CoreMatchers.*;
35 import static org.junit.Assert.assertThat; 54 import static org.junit.Assert.assertThat;
36 55
37 /** 56 /**
...@@ -39,16 +58,26 @@ import static org.junit.Assert.assertThat; ...@@ -39,16 +58,26 @@ import static org.junit.Assert.assertThat;
39 */ 58 */
40 public class DefaultIsisInterfaceTest { 59 public class DefaultIsisInterfaceTest {
41 private final MacAddress macAddress = MacAddress.valueOf("AA:BB:CC:DD:EE:FF"); 60 private final MacAddress macAddress = MacAddress.valueOf("AA:BB:CC:DD:EE:FF");
42 - private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10"); 61 + private final MacAddress macAddress1 = MacAddress.valueOf("AA:CC:CC:DD:EE:FF");
62 + private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.0.0");
43 private final byte[] mask = { 63 private final byte[] mask = {
44 (byte) 255, (byte) 255, (byte) 255, (byte) 224 64 (byte) 255, (byte) 255, (byte) 255, (byte) 224
45 }; 65 };
66 + private final byte[] mask1 = {
67 + (byte) 0, (byte) 0, (byte) 0, (byte) 0
68 + };
46 private final String intSysName = "ROUTER"; 69 private final String intSysName = "ROUTER";
47 private final String sysId = "1111.1111.1111"; 70 private final String sysId = "1111.1111.1111";
48 private final String areaAddr = "49.002"; 71 private final String areaAddr = "49.002";
72 + private final byte[] csnpBytes = {
73 + 0, 67, 18, 52, 18, 52, 0,
74 + 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
75 + -1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0,
76 + 0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0,
77 + 0, 0, 0, 0, 1, 91, 126
78 + };
49 private IsisInterfaceState resultIfState; 79 private IsisInterfaceState resultIfState;
50 private DefaultIsisInterface defaultIsisInterface; 80 private DefaultIsisInterface defaultIsisInterface;
51 - private HelloPdu helloPdu;
52 private IsisHeader isisHeader; 81 private IsisHeader isisHeader;
53 private IsisInterface isisInterface; 82 private IsisInterface isisInterface;
54 private Set<MacAddress> resultSet; 83 private Set<MacAddress> resultSet;
...@@ -60,18 +89,35 @@ public class DefaultIsisInterfaceTest { ...@@ -60,18 +89,35 @@ public class DefaultIsisInterfaceTest {
60 private byte[] resultByteArr; 89 private byte[] resultByteArr;
61 private String resultStr; 90 private String resultStr;
62 private IsisNetworkType resultNwType; 91 private IsisNetworkType resultNwType;
63 - 92 + private List<Ip4Address> ip4Addresses = new ArrayList<>();
93 + private DefaultIsisNeighbor defaultIsisNeighbor;
94 + private IsisNeighbor result;
95 + private IsisLsdb result1;
96 + private Set<MacAddress> result2;
97 + private Channel result3;
98 + private IsisMessage isisMessage;
99 + private IsisLsdb isisLsdb;
100 + private Channel channel;
101 + private L1L2HelloPdu helloPdu;
102 + private LsPdu lsPdu;
103 + private Csnp csnp;
104 + private Psnp psnp;
105 + private P2PHelloPdu p2PHelloPdu;
106 + private boolean result4;
107 + private String result5;
64 108
65 @Before 109 @Before
66 public void setUp() throws Exception { 110 public void setUp() throws Exception {
111 + channel = EasyMock.createNiceMock(Channel.class);
67 defaultIsisInterface = new DefaultIsisInterface(); 112 defaultIsisInterface = new DefaultIsisInterface();
113 + defaultIsisInterface.setInterfaceMacAddress(macAddress);
68 isisHeader = new IsisHeader(); 114 isisHeader = new IsisHeader();
69 isisHeader.setIrpDiscriminator((byte) 1); 115 isisHeader.setIrpDiscriminator((byte) 1);
70 helloPdu = new L1L2HelloPdu(isisHeader); 116 helloPdu = new L1L2HelloPdu(isisHeader);
71 isisInterface = new DefaultIsisInterface(); 117 isisInterface = new DefaultIsisInterface();
72 - resultNeighborList = new DefaultIsisNeighbor(helloPdu, isisInterface); 118 + defaultIsisNeighbor = new DefaultIsisNeighbor(helloPdu, isisInterface);
73 - 119 + defaultIsisNeighbor.setNeighborMacAddress(macAddress);
74 - 120 + isisLsdb = new DefaultIsisLsdb();
75 } 121 }
76 122
77 @After 123 @After
...@@ -365,26 +411,6 @@ public class DefaultIsisInterfaceTest { ...@@ -365,26 +411,6 @@ public class DefaultIsisInterfaceTest {
365 } 411 }
366 412
367 /** 413 /**
368 - * Tests getLspId() getter method.
369 - */
370 - @Test
371 - public void testGetLspId() throws Exception {
372 - defaultIsisInterface.setLspId(sysId);
373 - resultStr = defaultIsisInterface.getLspId();
374 - assertThat(resultStr, is(sysId));
375 - }
376 -
377 - /**
378 - * Tests getLspId() setter method.
379 - */
380 - @Test
381 - public void testSetLspId() throws Exception {
382 - defaultIsisInterface.setLspId(sysId);
383 - resultStr = defaultIsisInterface.getLspId();
384 - assertThat(resultStr, is(sysId));
385 - }
386 -
387 - /**
388 * Tests holdingTime() getter method. 414 * Tests holdingTime() getter method.
389 */ 415 */
390 @Test 416 @Test
...@@ -483,4 +509,369 @@ public class DefaultIsisInterfaceTest { ...@@ -483,4 +509,369 @@ public class DefaultIsisInterfaceTest {
483 resultStr = defaultIsisInterface.circuitId(); 509 resultStr = defaultIsisInterface.circuitId();
484 assertThat(resultStr, is(sysId)); 510 assertThat(resultStr, is(sysId));
485 } 511 }
512 +
513 + /**
514 + * Tests setAllConfiguredInterfaceIps() setter method.
515 + */
516 + @Test
517 + public void testSetAllConfiguredInterfaceIps() throws Exception {
518 + ip4Addresses.add(ip4Address);
519 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
520 + assertThat(defaultIsisInterface, is(notNullValue()));
521 + }
522 +
523 + /**
524 + * Tests setAllConfiguredInterfaceIps() method.
525 + */
526 + @Test
527 + public void testRemoveNeighbor() throws Exception {
528 + defaultIsisInterface.removeNeighbor(defaultIsisNeighbor);
529 + assertThat(defaultIsisInterface, is(notNullValue()));
530 + }
531 +
532 + /**
533 + * Tests lookup() method.
534 + */
535 + @Test
536 + public void testLookup() throws Exception {
537 + result = defaultIsisInterface.lookup(defaultIsisNeighbor.neighborMacAddress());
538 + assertThat(result, is(nullValue()));
539 + }
540 +
541 + /**
542 + * Tests isisLsdb() method.
543 + */
544 + @Test
545 + public void testIsisLsdb() throws Exception {
546 + result1 = defaultIsisInterface.isisLsdb();
547 + assertThat(result1, is(nullValue()));
548 + }
549 +
550 + /**
551 + * Tests neighbors() method.
552 + */
553 + @Test
554 + public void testNeighbors() throws Exception {
555 + result2 = defaultIsisInterface.neighbors();
556 + assertThat(result2, is(notNullValue()));
557 + }
558 +
559 + /**
560 + * Tests channel() method.
561 + */
562 + @Test
563 + public void testChannel() throws Exception {
564 + result3 = defaultIsisInterface.channel();
565 + assertThat(result3, is(nullValue()));
566 + }
567 +
568 + /**
569 + * Tests processIsisMessage() method.
570 + */
571 + @Test
572 + public void testProcessIsisMessage() throws Exception {
573 + helloPdu = new L1L2HelloPdu(isisHeader);
574 + helloPdu.setSourceMac(macAddress1);
575 + helloPdu.setIsisPduType(IsisPduType.L2HELLOPDU.value());
576 + defaultIsisInterface.setNetworkType(IsisNetworkType.BROADCAST);
577 + isisMessage = helloPdu;
578 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
579 + assertThat(defaultIsisInterface, is(notNullValue()));
580 + }
581 +
582 + /**
583 + * Tests processIsisMessage() method.
584 + */
585 + @Test(expected = Exception.class)
586 + public void testProcessIsisMessage1() throws Exception {
587 + lsPdu = new LsPdu(isisHeader);
588 + lsPdu.setSourceMac(macAddress1);
589 + lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
590 + isisMessage = lsPdu;
591 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
592 + assertThat(defaultIsisInterface, is(notNullValue()));
593 + }
594 +
595 + /**
596 + * Tests processIsisMessage() method.
597 + */
598 + @Test
599 + public void testProcessIsisMessage2() throws Exception {
600 + csnp = new Csnp(isisHeader);
601 + csnp.setSourceMac(macAddress1);
602 + csnp.setIsisPduType(IsisPduType.L2CSNP.value());
603 + isisMessage = csnp;
604 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
605 + assertThat(defaultIsisInterface, is(notNullValue()));
606 + }
607 +
608 + /**
609 + * Tests processIsisMessage() method.
610 + */
611 + @Test
612 + public void testProcessIsisMessage3() throws Exception {
613 + psnp = new Psnp(isisHeader);
614 + psnp.setSourceMac(macAddress1);
615 + psnp.setIsisPduType(IsisPduType.L2PSNP.value());
616 + isisMessage = psnp;
617 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
618 + assertThat(defaultIsisInterface, is(notNullValue()));
619 + }
620 +
621 + /**
622 + * Tests processIsisMessage() method.
623 + */
624 + @Test
625 + public void testProcessIsisMessage4() throws Exception {
626 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
627 + p2PHelloPdu.setSourceMac(macAddress1);
628 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
629 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
630 + isisMessage = p2PHelloPdu;
631 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
632 + assertThat(defaultIsisInterface, is(notNullValue()));
633 + }
634 +
635 + /**
636 + * Tests validateHelloMessage() method.
637 + */
638 + @Test
639 + public void testValidateHelloMessage() throws Exception {
640 + helloPdu = new L1L2HelloPdu(isisHeader);
641 + result4 = defaultIsisInterface.validateHelloMessage(helloPdu);
642 + assertThat(result4, is(false));
643 + }
644 +
645 + /**
646 + * Tests processL1L2HelloPduMessage() method.
647 + */
648 + @Test(expected = Exception.class)
649 + public void testProcessL1L2HelloPduMessage() throws Exception {
650 + helloPdu = new L1L2HelloPdu(isisHeader);
651 + helloPdu.setSourceMac(macAddress1);
652 + helloPdu.setCircuitType((byte) IsisRouterType.L2.value());
653 + defaultIsisInterface.processL1L2HelloPduMessage(helloPdu, channel);
654 + assertThat(defaultIsisInterface, is(notNullValue()));
655 + }
656 +
657 + /**
658 + * Tests processP2pHelloPduMessage() method.
659 + */
660 + @Test(expected = Exception.class)
661 + public void testProcessP2pHelloPduMessagee() throws Exception {
662 + defaultIsisInterface.setSystemId(sysId);
663 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
664 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
665 + p2PHelloPdu.setSourceMac(macAddress1);
666 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
667 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
668 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
669 + assertThat(defaultIsisInterface, is(notNullValue()));
670 + }
671 +
672 + /**
673 + * Tests processP2pHelloPduMessage() method.
674 + */
675 + @Test(expected = Exception.class)
676 + public void testProcessP2pHelloPduMessagee1() throws Exception {
677 + defaultIsisInterface.setSystemId(sysId);
678 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
679 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
680 + p2PHelloPdu.setSourceMac(macAddress1);
681 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
682 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
683 + defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L2.value());
684 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
685 + defaultIsisInterface.setInterfaceIpAddress(ip4Address);
686 + defaultIsisInterface.setNetworkMask(mask1);
687 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
688 + assertThat(defaultIsisInterface, is(notNullValue()));
689 + }
690 +
691 + /**
692 + * Tests processP2pHelloPduMessage() method.
693 + */
694 + @Test(expected = Exception.class)
695 + public void testProcessP2pHelloPduMessagee2() throws Exception {
696 + defaultIsisInterface.setSystemId(sysId);
697 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
698 + TlvHeader tlvHeader = new TlvHeader();
699 + tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
700 + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
701 + areaAddressTlv.addAddress(areaAddr);
702 + p2PHelloPdu.addTlv(areaAddressTlv);
703 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
704 + p2PHelloPdu.setSourceMac(macAddress1);
705 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
706 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
707 + defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value());
708 + defaultIsisInterface.setAreaAddress(areaAddr);
709 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
710 + defaultIsisInterface.setInterfaceIpAddress(ip4Address);
711 + defaultIsisInterface.setNetworkMask(mask1);
712 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
713 + assertThat(defaultIsisInterface, is(notNullValue()));
714 + }
715 +
716 + /**
717 + * Tests processP2pHelloPduMessage() method.
718 + */
719 + @Test(expected = Exception.class)
720 + public void testProcessP2pHelloPduMessagee3() throws Exception {
721 + defaultIsisInterface.setSystemId(sysId);
722 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
723 + TlvHeader tlvHeader = new TlvHeader();
724 + tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
725 + AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
726 + adjacencyStateTlv.setNeighborSystemId(sysId);
727 + adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.DOWN.value());
728 + p2PHelloPdu.addTlv(adjacencyStateTlv);
729 + tlvHeader = new TlvHeader();
730 + tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
731 + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
732 + areaAddressTlv.addAddress(areaAddr);
733 + p2PHelloPdu.addTlv(areaAddressTlv);
734 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
735 + p2PHelloPdu.setSourceMac(macAddress1);
736 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
737 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
738 + defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1.value());
739 + defaultIsisInterface.setAreaAddress(areaAddr);
740 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
741 + defaultIsisInterface.setInterfaceIpAddress(ip4Address);
742 + defaultIsisInterface.setNetworkMask(mask1);
743 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
744 + assertThat(defaultIsisInterface, is(notNullValue()));
745 + }
746 +
747 + /**
748 + * Tests processP2pHelloPduMessage() method.
749 + */
750 + @Test(expected = Exception.class)
751 + public void testProcessP2pHelloPduMessagee4() throws Exception {
752 + defaultIsisInterface.setSystemId(sysId);
753 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
754 + TlvHeader tlvHeader = new TlvHeader();
755 + tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
756 + AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
757 + adjacencyStateTlv.setNeighborSystemId(sysId);
758 + adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.INITIAL.value());
759 + p2PHelloPdu.addTlv(adjacencyStateTlv);
760 + tlvHeader = new TlvHeader();
761 + tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
762 + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
763 + areaAddressTlv.addAddress(areaAddr);
764 + p2PHelloPdu.addTlv(areaAddressTlv);
765 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
766 + p2PHelloPdu.setSourceMac(macAddress1);
767 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L1.value());
768 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
769 + defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value());
770 + defaultIsisInterface.setAreaAddress(areaAddr);
771 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
772 + defaultIsisInterface.setInterfaceIpAddress(ip4Address);
773 + defaultIsisInterface.setNetworkMask(mask1);
774 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
775 + assertThat(defaultIsisInterface, is(notNullValue()));
776 + }
777 +
778 + @Test(expected = Exception.class)
779 + public void testProcessP2pHelloPduMessagee5() throws Exception {
780 + defaultIsisInterface.setSystemId(sysId);
781 + p2PHelloPdu = new P2PHelloPdu(isisHeader);
782 + TlvHeader tlvHeader = new TlvHeader();
783 + tlvHeader.setTlvType(TlvType.ADJACENCYSTATE.value());
784 + AdjacencyStateTlv adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
785 + adjacencyStateTlv.setNeighborSystemId(sysId);
786 + adjacencyStateTlv.setAdjacencyType((byte) IsisInterfaceState.UP.value());
787 + p2PHelloPdu.addTlv(adjacencyStateTlv);
788 + tlvHeader = new TlvHeader();
789 + tlvHeader.setTlvType(TlvType.AREAADDRESS.value());
790 + AreaAddressTlv areaAddressTlv = new AreaAddressTlv(tlvHeader);
791 + areaAddressTlv.addAddress(areaAddr);
792 + p2PHelloPdu.addTlv(areaAddressTlv);
793 + p2PHelloPdu.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
794 + p2PHelloPdu.setSourceMac(macAddress1);
795 + p2PHelloPdu.setCircuitType((byte) IsisRouterType.L2.value());
796 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
797 + defaultIsisInterface.setReservedPacketCircuitType(IsisRouterType.L1L2.value());
798 + defaultIsisInterface.setAreaAddress(areaAddr);
799 + defaultIsisInterface.setAllConfiguredInterfaceIps(ip4Addresses);
800 + defaultIsisInterface.setInterfaceIpAddress(ip4Address);
801 + defaultIsisInterface.setNetworkMask(mask1);
802 + defaultIsisInterface.processIsisMessage(p2PHelloPdu, isisLsdb, channel);
803 + assertThat(defaultIsisInterface, is(notNullValue()));
804 + }
805 +
806 + /**
807 + * Tests startHelloSender() method.
808 + */
809 + @Test(expected = Exception.class)
810 + public void testStartHelloSender() throws Exception {
811 + defaultIsisInterface.startHelloSender(channel);
812 + assertThat(defaultIsisInterface, is(notNullValue()));
813 + }
814 +
815 + /**
816 + * Tests lspKeyP2P() method.
817 + */
818 + @Test
819 + public void testLspKeyP2P() throws Exception {
820 + result5 = defaultIsisInterface.lspKeyP2P(sysId);
821 + assertThat(result5, is(notNullValue()));
822 + }
823 +
824 + /**
825 + * Tests processLsPduMessage() method.
826 + */
827 + @Test
828 + public void testProcessLsPduMessage() throws Exception {
829 + lsPdu = new LsPdu(isisHeader);
830 + lsPdu.setSourceMac(macAddress1);
831 + lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
832 + lsPdu.setLspId(sysId);
833 + isisMessage = lsPdu;
834 + defaultIsisInterface.setNetworkType(IsisNetworkType.P2P);
835 + defaultIsisInterface.setSystemId(sysId);
836 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
837 + assertThat(defaultIsisInterface, is(notNullValue()));
838 + }
839 +
840 + /**
841 + * Tests processPsnPduMessage() method.
842 + */
843 + @Test
844 + public void testProcessPsnPduMessage() throws Exception {
845 + psnp = new Psnp(isisHeader);
846 + psnp.setSourceMac(macAddress1);
847 + psnp.setIsisPduType(IsisPduType.L2PSNP.value());
848 + TlvHeader tlvHeader = new TlvHeader();
849 + tlvHeader.setTlvType(TlvType.LSPENTRY.value());
850 + tlvHeader.setTlvLength(0);
851 + LspEntriesTlv lspEntriesTlv = new LspEntriesTlv(tlvHeader);
852 + LspEntry lspEntry = new LspEntry();
853 + lspEntry.setLspChecksum(0);
854 + lspEntry.setLspSequenceNumber(0);
855 + lspEntry.setRemainingTime(0);
856 + lspEntriesTlv.addLspEntry(lspEntry);
857 + psnp.addTlv(lspEntriesTlv);
858 + isisMessage = psnp;
859 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
860 + assertThat(defaultIsisInterface, is(notNullValue()));
861 + }
862 +
863 + /**
864 + * Tests processCsnPduMessage() method.
865 + */
866 + @Test(expected = Exception.class)
867 + public void testProcessCsnPduMessage() throws Exception {
868 + ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes);
869 + csnp = new Csnp(isisHeader);
870 + csnp.readFrom(channelBuffer);
871 + csnp.setSourceMac(macAddress1);
872 + csnp.setIsisPduType(IsisPduType.L2CSNP.value());
873 + isisMessage = csnp;
874 + defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel);
875 + assertThat(defaultIsisInterface, is(notNullValue()));
876 + }
486 } 877 }
......
...@@ -36,6 +36,7 @@ public class DefaultIsisProcessTest { ...@@ -36,6 +36,7 @@ public class DefaultIsisProcessTest {
36 private final String processId = "1"; 36 private final String processId = "1";
37 private IsisProcess isisProcess; 37 private IsisProcess isisProcess;
38 private String result; 38 private String result;
39 + private IsisProcess defaultIsisProcess;
39 private IsisInterface isisInterface; 40 private IsisInterface isisInterface;
40 private List<IsisInterface> isisInterfaceList; 41 private List<IsisInterface> isisInterfaceList;
41 private List<IsisInterface> result1; 42 private List<IsisInterface> result1;
...@@ -44,6 +45,7 @@ public class DefaultIsisProcessTest { ...@@ -44,6 +45,7 @@ public class DefaultIsisProcessTest {
44 public void setUp() throws Exception { 45 public void setUp() throws Exception {
45 isisProcess = new DefaultIsisProcess(); 46 isisProcess = new DefaultIsisProcess();
46 isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class); 47 isisInterface = EasyMock.createNiceMock(DefaultIsisInterface.class);
48 + defaultIsisProcess = new DefaultIsisProcess();
47 } 49 }
48 50
49 @After 51 @After
...@@ -90,4 +92,4 @@ public class DefaultIsisProcessTest { ...@@ -90,4 +92,4 @@ public class DefaultIsisProcessTest {
90 result1 = isisProcess.isisInterfaceList(); 92 result1 = isisProcess.isisInterfaceList();
91 assertThat(result1, is(nullValue())); 93 assertThat(result1, is(nullValue()));
92 } 94 }
93 -} 95 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -23,10 +23,14 @@ import org.jboss.netty.channel.MessageEvent; ...@@ -23,10 +23,14 @@ import org.jboss.netty.channel.MessageEvent;
23 import org.junit.After; 23 import org.junit.After;
24 import org.junit.Before; 24 import org.junit.Before;
25 import org.junit.Test; 25 import org.junit.Test;
26 +import org.onlab.packet.Ip4Address;
27 +import org.onosproject.isis.controller.IsisInterface;
26 import org.onosproject.isis.controller.IsisMessage; 28 import org.onosproject.isis.controller.IsisMessage;
29 +import org.onosproject.isis.controller.IsisNetworkType;
27 import org.onosproject.isis.controller.IsisProcess; 30 import org.onosproject.isis.controller.IsisProcess;
28 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; 31 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
29 32
33 +import java.util.ArrayList;
30 import java.util.List; 34 import java.util.List;
31 35
32 import static org.hamcrest.CoreMatchers.is; 36 import static org.hamcrest.CoreMatchers.is;
...@@ -43,12 +47,14 @@ public class IsisChannelHandlerTest { ...@@ -43,12 +47,14 @@ public class IsisChannelHandlerTest {
43 private IsisChannelHandler isisChannelHandler; 47 private IsisChannelHandler isisChannelHandler;
44 private Controller controller; 48 private Controller controller;
45 private IsisProcess isisProcess; 49 private IsisProcess isisProcess;
46 - private List<IsisProcess> isisProcessList; 50 + private List<IsisProcess> isisProcessList = new ArrayList();
47 private ChannelHandlerContext channelHandlerContext; 51 private ChannelHandlerContext channelHandlerContext;
48 private ChannelStateEvent channelStateEvent; 52 private ChannelStateEvent channelStateEvent;
49 private ExceptionEvent exceptionEvent; 53 private ExceptionEvent exceptionEvent;
50 private MessageEvent messageEvent; 54 private MessageEvent messageEvent;
51 private IsisMessage isisMessage; 55 private IsisMessage isisMessage;
56 + private List<IsisInterface> isisInterfaceList = new ArrayList<>();
57 + private Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
52 58
53 @Before 59 @Before
54 public void setUp() throws Exception { 60 public void setUp() throws Exception {
...@@ -71,7 +77,7 @@ public class IsisChannelHandlerTest { ...@@ -71,7 +77,7 @@ public class IsisChannelHandlerTest {
71 /** 77 /**
72 * Tests initializeInterfaceMap() method. 78 * Tests initializeInterfaceMap() method.
73 */ 79 */
74 - @Test(expected = Exception.class) 80 + @Test
75 public void testInitializeInterfaceMap() throws Exception { 81 public void testInitializeInterfaceMap() throws Exception {
76 isisChannelHandler.initializeInterfaceMap(); 82 isisChannelHandler.initializeInterfaceMap();
77 assertThat(isisChannelHandler, is(notNullValue())); 83 assertThat(isisChannelHandler, is(notNullValue()));
...@@ -82,6 +88,32 @@ public class IsisChannelHandlerTest { ...@@ -82,6 +88,32 @@ public class IsisChannelHandlerTest {
82 */ 88 */
83 @Test(expected = Exception.class) 89 @Test(expected = Exception.class)
84 public void testUpdateInterfaceMap() throws Exception { 90 public void testUpdateInterfaceMap() throws Exception {
91 + IsisInterface isisInterface = new DefaultIsisInterface();
92 + IsisInterface isisInterface1 = new DefaultIsisInterface();
93 + isisInterface.setInterfaceIpAddress(ip4Address);
94 + isisInterface.setInterfaceIndex(1);
95 + isisInterfaceList.add(isisInterface);
96 + IsisProcess isisProcess = new DefaultIsisProcess();
97 + isisProcess.setIsisInterfaceList(isisInterfaceList);
98 + isisProcessList.add(isisProcess);
99 + isisChannelHandler.updateInterfaceMap(isisProcessList);
100 + assertThat(isisChannelHandler, is(notNullValue()));
101 + isisProcessList = new ArrayList<>();
102 + isisInterface1.setInterfaceIpAddress(ip4Address);
103 + isisInterface1.setInterfaceIndex(1);
104 + isisInterface1.setInterfaceIpAddress(ip4Address);
105 + isisInterface1.setInterfaceIndex(1);
106 + isisInterface1.setSystemId("9999.9999.9999");
107 + isisInterface1.setIntermediateSystemName("router");
108 + isisInterface1.setReservedPacketCircuitType(3);
109 + isisInterface1.setCircuitId("10");
110 + isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
111 + isisInterface1.setAreaAddress("490001");
112 + isisInterface1.setHoldingTime(50);
113 + isisInterface1.setHelloInterval(10);
114 + isisInterfaceList.add(isisInterface1);
115 + isisProcess.setIsisInterfaceList(isisInterfaceList);
116 + isisProcessList.add(isisProcess);
85 isisChannelHandler.updateInterfaceMap(isisProcessList); 117 isisChannelHandler.updateInterfaceMap(isisProcessList);
86 assertThat(isisChannelHandler, is(notNullValue())); 118 assertThat(isisChannelHandler, is(notNullValue()));
87 } 119 }
...@@ -89,7 +121,7 @@ public class IsisChannelHandlerTest { ...@@ -89,7 +121,7 @@ public class IsisChannelHandlerTest {
89 /** 121 /**
90 * Tests initializeInterfaceIpList() method. 122 * Tests initializeInterfaceIpList() method.
91 */ 123 */
92 - @Test(expected = Exception.class) 124 + @Test
93 public void testInitializeInterfaceIpList() throws Exception { 125 public void testInitializeInterfaceIpList() throws Exception {
94 isisChannelHandler.initializeInterfaceIpList(); 126 isisChannelHandler.initializeInterfaceIpList();
95 assertThat(isisChannelHandler, is(notNullValue())); 127 assertThat(isisChannelHandler, is(notNullValue()));
......
...@@ -58,7 +58,7 @@ public class IsisHelloPduSenderTest { ...@@ -58,7 +58,7 @@ public class IsisHelloPduSenderTest {
58 /** 58 /**
59 * Tests run() method. 59 * Tests run() method.
60 */ 60 */
61 - @Test 61 + @Test(expected = Exception.class)
62 public void testRun() throws Exception { 62 public void testRun() throws Exception {
63 isisInterface.setNetworkType(IsisNetworkType.P2P); 63 isisInterface.setNetworkType(IsisNetworkType.P2P);
64 isisInterface.setCircuitId(circuitId); 64 isisInterface.setCircuitId(circuitId);
......
...@@ -24,11 +24,14 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -24,11 +24,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
24 public class IsisMessageDecoderTest { 24 public class IsisMessageDecoderTest {
25 25
26 private final byte[] hello = { 26 private final byte[] hello = {
27 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 -125, 20, 1, 0, 17, 1, 0, 0, 28 -125, 20, 1, 0, 17, 1, 0, 0,
28 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3, 29 2, 51, 51, 51, 51, 51, 51, 0, 100, 5, -39, -126, 1, 4, 3,
29 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102 30 73, 0, 0, -127, 1, -52, -124, 4, -64, -88, 56, 102
30 }; 31 };
32 + private final byte[] array2 = {0, 0, 0, 0, 0, 0, 0};
31 private final String id = "127.0.0.1"; 33 private final String id = "127.0.0.1";
34 + private byte[] array1;
32 private IsisMessageDecoder isisMessageDecoder; 35 private IsisMessageDecoder isisMessageDecoder;
33 private ChannelHandlerContext ctx; 36 private ChannelHandlerContext ctx;
34 private Channel channel; 37 private Channel channel;
...@@ -49,7 +52,8 @@ public class IsisMessageDecoderTest { ...@@ -49,7 +52,8 @@ public class IsisMessageDecoderTest {
49 public void testDecode() throws Exception { 52 public void testDecode() throws Exception {
50 channel = EasyMock.createMock(Channel.class); 53 channel = EasyMock.createMock(Channel.class);
51 socketAddress = InetSocketAddress.createUnresolved(id, 7000); 54 socketAddress = InetSocketAddress.createUnresolved(id, 7000);
52 - byte[] array = IsisUtil.getPaddingTlvs(hello.length); 55 + byte[] array = IsisUtil.getPaddingTlvs(hello.length - 17);
56 + array1 = Bytes.concat(hello, array);
53 channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array)); 57 channelBuffer = ChannelBuffers.copiedBuffer(Bytes.concat(hello, array));
54 assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue())); 58 assertThat(isisMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
55 } 59 }
......
...@@ -22,8 +22,13 @@ import org.onosproject.isis.controller.IsisLsdb; ...@@ -22,8 +22,13 @@ import org.onosproject.isis.controller.IsisLsdb;
22 import org.onosproject.isis.controller.IsisLsdbAge; 22 import org.onosproject.isis.controller.IsisLsdbAge;
23 import org.onosproject.isis.controller.IsisPduType; 23 import org.onosproject.isis.controller.IsisPduType;
24 import org.onosproject.isis.controller.LspWrapper; 24 import org.onosproject.isis.controller.LspWrapper;
25 +import org.onosproject.isis.controller.impl.DefaultIsisInterface;
26 +import org.onosproject.isis.io.isispacket.IsisHeader;
27 +import org.onosproject.isis.io.isispacket.pdu.AttachedToOtherAreas;
28 +import org.onosproject.isis.io.isispacket.pdu.LsPdu;
25 import org.onosproject.isis.io.util.IsisConstants; 29 import org.onosproject.isis.io.util.IsisConstants;
26 30
31 +import java.util.List;
27 import java.util.Map; 32 import java.util.Map;
28 import java.util.concurrent.ConcurrentHashMap; 33 import java.util.concurrent.ConcurrentHashMap;
29 34
...@@ -37,19 +42,27 @@ public class DefaultIsisLsdbTest { ...@@ -37,19 +42,27 @@ public class DefaultIsisLsdbTest {
37 private final int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 42 private final int l1LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
38 private final int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM; 43 private final int l2LspSeqNo = IsisConstants.STARTLSSEQUENCENUM;
39 private final String srcId = "1111.1111.1111"; 44 private final String srcId = "1111.1111.1111";
40 -
41 private DefaultIsisLsdb defaultIsisLsdb; 45 private DefaultIsisLsdb defaultIsisLsdb;
42 private IsisLsdbAge lsdbAge = null; 46 private IsisLsdbAge lsdbAge = null;
43 -
44 -
45 private int resultInt; 47 private int resultInt;
46 private Map<String, LspWrapper> resultMap = new ConcurrentHashMap<>(); 48 private Map<String, LspWrapper> resultMap = new ConcurrentHashMap<>();
47 private IsisLsdb resultLsdb; 49 private IsisLsdb resultLsdb;
48 private LspWrapper resultLspWrapper; 50 private LspWrapper resultLspWrapper;
49 - 51 + private List<LspWrapper> lspWrapperList;
52 + private LsPdu lsPdu;
53 + private IsisHeader isisHeader;
54 + private DefaultIsisInterface defaultIsisInterface;
55 + private String lspId = "1234.1234.1234.00-00";
56 + private String result;
50 57
51 @Before 58 @Before
52 public void setUp() throws Exception { 59 public void setUp() throws Exception {
60 + defaultIsisInterface = new DefaultIsisInterface();
61 + isisHeader = new IsisHeader();
62 + lsPdu = new LsPdu(isisHeader);
63 + lsPdu.setLspId(lspId);
64 + lsPdu.setAttachedToOtherAreas(AttachedToOtherAreas.DEFAULTMETRIC);
65 + lsPdu.setIsisPduType(IsisPduType.L1LSPDU.value());
53 defaultIsisLsdb = new DefaultIsisLsdb(); 66 defaultIsisLsdb = new DefaultIsisLsdb();
54 } 67 }
55 68
...@@ -129,5 +142,60 @@ public class DefaultIsisLsdbTest { ...@@ -129,5 +142,60 @@ public class DefaultIsisLsdbTest {
129 resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId); 142 resultLspWrapper = defaultIsisLsdb.findLsp(IsisPduType.L1HELLOPDU, srcId);
130 assertThat(resultLspWrapper, is(nullValue())); 143 assertThat(resultLspWrapper, is(nullValue()));
131 } 144 }
145 +
146 + /**
147 + * Tests allLspHeaders() method.
148 + */
149 + @Test
150 + public void testAllLspHeaders() throws Exception {
151 + defaultIsisLsdb.addLsp(lsPdu, false, defaultIsisInterface);
152 + lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
153 + assertThat(lspWrapperList, is(notNullValue()));
154 +
155 + defaultIsisLsdb.addLsp(lsPdu, true, defaultIsisInterface);
156 + lspWrapperList = defaultIsisLsdb.allLspHeaders(true);
157 + assertThat(lspWrapperList, is(notNullValue()));
158 + }
159 +
160 + /**
161 + * Tests isNewerOrSameLsp() method.
162 + */
163 + @Test
164 + public void testIsNewerOrSameLsp() throws Exception {
165 + result = defaultIsisLsdb.isNewerOrSameLsp(lsPdu, lsPdu);
166 + assertThat(result, is("same"));
167 + }
168 +
169 + /**
170 + * Tests lsSequenceNumber() method.
171 + */
172 + @Test
173 + public void testLsSequenceNumber() throws Exception {
174 + resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1LSPDU);
175 + assertThat(resultInt, is(1));
176 +
177 + resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L2LSPDU);
178 + assertThat(resultInt, is(1));
179 +
180 + resultInt = defaultIsisLsdb.lsSequenceNumber(IsisPduType.L1CSNP);
181 + assertThat(resultInt, is(1));
182 + }
183 +
184 + /**
185 + * Tests deleteLsp() method.
186 + */
187 + @Test
188 + public void testdeleteLsp() throws Exception {
189 + defaultIsisLsdb.deleteLsp(lsPdu);
190 + assertThat(defaultIsisLsdb, is(notNullValue()));
191 +
192 + lsPdu.setIsisPduType(IsisPduType.L2LSPDU.value());
193 + defaultIsisLsdb.deleteLsp(lsPdu);
194 + assertThat(defaultIsisLsdb, is(notNullValue()));
195 +
196 + lsPdu.setIsisPduType(IsisPduType.L1CSNP.value());
197 + defaultIsisLsdb.deleteLsp(lsPdu);
198 + assertThat(defaultIsisLsdb, is(notNullValue()));
199 + }
132 } 200 }
133 201
......
...@@ -19,7 +19,11 @@ import org.junit.After; ...@@ -19,7 +19,11 @@ import org.junit.After;
19 import org.junit.Before; 19 import org.junit.Before;
20 import org.junit.Test; 20 import org.junit.Test;
21 import org.onosproject.isis.controller.IsisInterface; 21 import org.onosproject.isis.controller.IsisInterface;
22 +import org.onosproject.isis.controller.IsisLsdbAge;
23 +import org.onosproject.isis.controller.IsisPduType;
22 import org.onosproject.isis.controller.impl.DefaultIsisInterface; 24 import org.onosproject.isis.controller.impl.DefaultIsisInterface;
25 +import org.onosproject.isis.io.isispacket.IsisHeader;
26 +import org.onosproject.isis.io.isispacket.pdu.LsPdu;
23 27
24 import static org.hamcrest.CoreMatchers.is; 28 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.notNullValue; 29 import static org.hamcrest.CoreMatchers.notNullValue;
...@@ -36,11 +40,20 @@ public class DefaultLspWrapperTest { ...@@ -36,11 +40,20 @@ public class DefaultLspWrapperTest {
36 private int result1; 40 private int result1;
37 private IsisInterface isisInterface; 41 private IsisInterface isisInterface;
38 private IsisInterface result2; 42 private IsisInterface result2;
43 + private IsisPduType isisPduType;
44 + private boolean result3;
45 + private LsPdu lsPdu;
46 + private LsPdu pdu;
47 + private DefaultIsisLsdbAge defaultIsisLsdbAge;
48 + private IsisLsdbAge lsdbAge;
39 49
40 @Before 50 @Before
41 public void setUp() throws Exception { 51 public void setUp() throws Exception {
42 defaultLspWrapper = new DefaultLspWrapper(); 52 defaultLspWrapper = new DefaultLspWrapper();
43 isisInterface = new DefaultIsisInterface(); 53 isisInterface = new DefaultIsisInterface();
54 + pdu = new LsPdu(new IsisHeader());
55 + defaultIsisLsdbAge = new DefaultIsisLsdbAge();
56 + defaultIsisLsdbAge.startDbAging();
44 } 57 }
45 58
46 @After 59 @After
...@@ -108,4 +121,169 @@ public class DefaultLspWrapperTest { ...@@ -108,4 +121,169 @@ public class DefaultLspWrapperTest {
108 assertThat(result2, is(notNullValue())); 121 assertThat(result2, is(notNullValue()));
109 } 122 }
110 123
124 + /**
125 + * Tests ageCounterWhenReceived() getter method.
126 + */
127 + @Test
128 + public void testAgeCounterWhenReceived() throws Exception {
129 + defaultLspWrapper.setAgeCounterWhenReceived(1);
130 + result1 = defaultLspWrapper.ageCounterWhenReceived();
131 + assertThat(result1, is(notNullValue()));
132 + }
133 +
134 + /**
135 + * Tests ageCounterWhenReceived() setter method.
136 + */
137 + @Test
138 + public void testSetAgeCounterWhenReceived() throws Exception {
139 + defaultLspWrapper.setAgeCounterWhenReceived(1);
140 + result1 = defaultLspWrapper.ageCounterWhenReceived();
141 + assertThat(result1, is(notNullValue()));
142 + }
143 +
144 + /**
145 + * Tests ageCounterRollOverWhenAdded() getter method.
146 + */
147 + @Test
148 + public void testAgeCounterRollOverWhenAdded() throws Exception {
149 + defaultLspWrapper.setAgeCounterRollOverWhenAdded(1);
150 + result1 = defaultLspWrapper.ageCounterRollOverWhenAdded();
151 + assertThat(result1, is(notNullValue()));
152 + }
153 +
154 + /**
155 + * Tests ageCounterRollOverWhenAdded() setter method.
156 + */
157 + @Test
158 + public void testSetAgeCounterRollOverWhenAdded() throws Exception {
159 + defaultLspWrapper.setAgeCounterRollOverWhenAdded(1);
160 + result1 = defaultLspWrapper.ageCounterRollOverWhenAdded();
161 + assertThat(result1, is(notNullValue()));
162 + }
163 +
164 + /**
165 + * Tests lspType() getter method.
166 + */
167 + @Test
168 + public void testLspType() throws Exception {
169 + defaultLspWrapper.setLspType(IsisPduType.L1LSPDU);
170 + isisPduType = defaultLspWrapper.lspType();
171 + assertThat(isisPduType, is(IsisPduType.L1LSPDU));
172 + }
173 +
174 + /**
175 + * Tests lspType() setter method.
176 + */
177 + @Test
178 + public void testSetLspType() throws Exception {
179 + defaultLspWrapper.setLspType(IsisPduType.L1LSPDU);
180 + isisPduType = defaultLspWrapper.lspType();
181 + assertThat(isisPduType, is(IsisPduType.L1LSPDU));
182 + }
183 +
184 + /**
185 + * Tests isSelfOriginated() getter method.
186 + */
187 + @Test
188 + public void testIsSelfOriginated() throws Exception {
189 + defaultLspWrapper.setSelfOriginated(true);
190 + result3 = defaultLspWrapper.isSelfOriginated();
191 + assertThat(result3, is(true));
192 + }
193 +
194 + /**
195 + * Tests isSelfOriginated() setter method.
196 + */
197 + @Test
198 + public void testSetSelfOriginated() throws Exception {
199 + defaultLspWrapper.setSelfOriginated(true);
200 + result3 = defaultLspWrapper.isSelfOriginated();
201 + assertThat(result3, is(true));
202 + }
203 +
204 + /**
205 + * Tests binNumber() getter method.
206 + */
207 + @Test
208 + public void testBinNumber() throws Exception {
209 + defaultLspWrapper.setBinNumber(1);
210 + result1 = defaultLspWrapper.binNumber();
211 + assertThat(result1, is(1));
212 + }
213 +
214 + /**
215 + * Tests binNumber() setter method.
216 + */
217 + @Test
218 + public void testSetBinNumber() throws Exception {
219 + defaultLspWrapper.setBinNumber(1);
220 + result1 = defaultLspWrapper.binNumber();
221 + assertThat(result1, is(1));
222 + }
223 +
224 + /**
225 + * Tests lsPdu() getter method.
226 + */
227 + @Test
228 + public void testLsPdu() throws Exception {
229 + defaultLspWrapper.setLsPdu(pdu);
230 + lsPdu = defaultLspWrapper.lsPdu();
231 + assertThat(lsPdu, is(pdu));
232 + }
233 +
234 + /**
235 + * Tests lsPdu() setter method.
236 + */
237 + @Test
238 + public void testSetLsPdu() throws Exception {
239 + defaultLspWrapper.setLsPdu(pdu);
240 + lsPdu = defaultLspWrapper.lsPdu();
241 + assertThat(lsPdu, is(pdu));
242 + }
243 +
244 + /**
245 + * Tests lsdbAge() getter method.
246 + */
247 + @Test
248 + public void testlsdbAge() throws Exception {
249 + defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
250 + lsdbAge = defaultLspWrapper.lsdbAge();
251 + assertThat(lsdbAge, is(defaultIsisLsdbAge));
252 + }
253 +
254 + /**
255 + * Tests lsdbAge() setter method.
256 + */
257 + @Test
258 + public void testSetLsdbAge() throws Exception {
259 + defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
260 + lsdbAge = defaultLspWrapper.lsdbAge();
261 + assertThat(lsdbAge, is(defaultIsisLsdbAge));
262 + }
263 +
264 + /**
265 + * Tests remainingLifetime() getter method.
266 + */
267 + @Test
268 + public void testRemainingLifetime() throws Exception {
269 + defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
270 + defaultLspWrapper.setAgeCounterWhenReceived(1);
271 + defaultLspWrapper.currentAge();
272 + defaultLspWrapper.setRemainingLifetime(1);
273 + result1 = defaultLspWrapper.remainingLifetime();
274 + assertThat(result1, is(1));
275 + }
276 +
277 + /**
278 + * Tests remainingLifetime() setter method.
279 + */
280 + @Test
281 + public void testSetRemainingLifetime() throws Exception {
282 + defaultLspWrapper.setLsdbAge(defaultIsisLsdbAge);
283 + defaultLspWrapper.setAgeCounterWhenReceived(1);
284 + defaultLspWrapper.currentAge();
285 + defaultLspWrapper.setRemainingLifetime(1);
286 + result1 = defaultLspWrapper.remainingLifetime();
287 + assertThat(result1, is(1));
288 + }
111 } 289 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -18,7 +18,11 @@ package org.onosproject.isis.controller.impl.lsdb; ...@@ -18,7 +18,11 @@ package org.onosproject.isis.controller.impl.lsdb;
18 import org.junit.After; 18 import org.junit.After;
19 import org.junit.Before; 19 import org.junit.Before;
20 import org.junit.Test; 20 import org.junit.Test;
21 +import org.onosproject.isis.controller.impl.DefaultIsisInterface;
21 22
23 +import java.net.InetSocketAddress;
24 +import java.net.SocketAddress;
25 +import java.util.concurrent.ArrayBlockingQueue;
22 import java.util.concurrent.BlockingQueue; 26 import java.util.concurrent.BlockingQueue;
23 27
24 import static org.hamcrest.CoreMatchers.is; 28 import static org.hamcrest.CoreMatchers.is;
...@@ -31,10 +35,22 @@ import static org.junit.Assert.assertThat; ...@@ -31,10 +35,22 @@ import static org.junit.Assert.assertThat;
31 public class IsisLspQueueConsumerTest { 35 public class IsisLspQueueConsumerTest {
32 36
33 private IsisLspQueueConsumer isisLspQueueConsumer; 37 private IsisLspQueueConsumer isisLspQueueConsumer;
34 - private BlockingQueue blockingQueue; 38 + private BlockingQueue blockingQueue = new ArrayBlockingQueue(1024);
39 + private DefaultLspWrapper lspWrapper;
40 + private DefaultLspWrapper lspWrapper1;
41 + private SocketAddress socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
35 42
36 @Before 43 @Before
37 public void setUp() throws Exception { 44 public void setUp() throws Exception {
45 + lspWrapper = new DefaultLspWrapper();
46 + lspWrapper.setLspProcessing("refreshLsp");
47 + lspWrapper.setSelfOriginated(true);
48 + lspWrapper.setIsisInterface(new DefaultIsisInterface());
49 + lspWrapper1 = new DefaultLspWrapper();
50 + lspWrapper1.setLspProcessing("maxAgeLsp");
51 + lspWrapper1.setIsisInterface(new DefaultIsisInterface());
52 + blockingQueue.add(lspWrapper);
53 + blockingQueue.add(lspWrapper1);
38 isisLspQueueConsumer = new IsisLspQueueConsumer(blockingQueue); 54 isisLspQueueConsumer = new IsisLspQueueConsumer(blockingQueue);
39 } 55 }
40 56
......
...@@ -33,6 +33,7 @@ public final class IsisConstants { ...@@ -33,6 +33,7 @@ public final class IsisConstants {
33 public static final int IRPDISCRIMINATOR = 131; 33 public static final int IRPDISCRIMINATOR = 131;
34 public static final int ISISVERSION = 1; 34 public static final int ISISVERSION = 1;
35 public static final int RESERVED = 0; 35 public static final int RESERVED = 0;
36 + public static final int PRIORITY = 0;
36 public static final int MAXAREAADDRESS = 0; 37 public static final int MAXAREAADDRESS = 0;
37 public static final int SYSTEMIDLENGTH = 0; 38 public static final int SYSTEMIDLENGTH = 0;
38 public static final int PROTOCOLSUPPORTED = 204; 39 public static final int PROTOCOLSUPPORTED = 204;
...@@ -55,24 +56,15 @@ public final class IsisConstants { ...@@ -55,24 +56,15 @@ public final class IsisConstants {
55 public static final String DEFAULTLANID = "0000.0000.0000.00"; 56 public static final String DEFAULTLANID = "0000.0000.0000.00";
56 public static final String PROCESSESID = "processId"; 57 public static final String PROCESSESID = "processId";
57 public static final String INTERFACE = "interface"; 58 public static final String INTERFACE = "interface";
58 - public static final String INTERFACEIP = "interfaceIp";
59 - public static final String NETWORKMASK = "networkMask";
60 public static final String INTERFACEINDEX = "interfaceIndex"; 59 public static final String INTERFACEINDEX = "interfaceIndex";
61 public static final String INTERMEDIATESYSTEMNAME = "intermediateSystemName"; 60 public static final String INTERMEDIATESYSTEMNAME = "intermediateSystemName";
62 public static final String SYSTEMID = "systemId"; 61 public static final String SYSTEMID = "systemId";
63 - public static final String LANID = "lanId";
64 - public static final String IDLENGTH = "idLength";
65 - public static final String MAXAREAADDRESSES = "maxAreaAddresses";
66 public static final String RESERVEDPACKETCIRCUITTYPE = "reservedPacketCircuitType"; 62 public static final String RESERVEDPACKETCIRCUITTYPE = "reservedPacketCircuitType";
67 public static final String CIRCUITID = "circuitId"; 63 public static final String CIRCUITID = "circuitId";
68 public static final String NETWORKTYPE = "networkType"; 64 public static final String NETWORKTYPE = "networkType";
69 public static final String AREAADDRESS = "areaAddress"; 65 public static final String AREAADDRESS = "areaAddress";
70 - public static final String AREALENGTH = "areaLength";
71 - public static final String LSPID = "lspId";
72 public static final String HOLDINGTIME = "holdingTime"; 66 public static final String HOLDINGTIME = "holdingTime";
73 public static final String HELLOINTERVAL = "helloInterval"; 67 public static final String HELLOINTERVAL = "helloInterval";
74 - public static final String PRIORITY = "priority";
75 - public static final String MACADDRESS = "macAddress";
76 68
77 /** 69 /**
78 * Non parameterized constructor. 70 * Non parameterized constructor.
......
...@@ -22,6 +22,7 @@ import org.onosproject.isis.controller.IsisInterface; ...@@ -22,6 +22,7 @@ import org.onosproject.isis.controller.IsisInterface;
22 import org.onosproject.isis.controller.IsisInterfaceState; 22 import org.onosproject.isis.controller.IsisInterfaceState;
23 import org.onosproject.isis.controller.IsisNeighbor; 23 import org.onosproject.isis.controller.IsisNeighbor;
24 import org.onosproject.isis.controller.IsisPduType; 24 import org.onosproject.isis.controller.IsisPduType;
25 +import org.onosproject.isis.controller.IsisRouterType;
25 import org.onosproject.isis.io.isispacket.IsisHeader; 26 import org.onosproject.isis.io.isispacket.IsisHeader;
26 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; 27 import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
27 import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu; 28 import org.onosproject.isis.io.isispacket.pdu.P2PHelloPdu;
...@@ -394,7 +395,6 @@ public final class IsisUtil { ...@@ -394,7 +395,6 @@ public final class IsisUtil {
394 isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH); 395 isisHeader.setIdLength((byte) IsisConstants.SYSTEMIDLENGTH);
395 isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value()); 396 isisHeader.setIsisPduType(IsisPduType.P2PHELLOPDU.value());
396 isisHeader.setVersion2((byte) IsisConstants.ISISVERSION); 397 isisHeader.setVersion2((byte) IsisConstants.ISISVERSION);
397 - //isisHeader.setReserved((byte) IsisConstants.RESERVED);
398 isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION); 398 isisHeader.setReserved((byte) IsisConstants.PDULENGTHPOSITION);
399 isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS); 399 isisHeader.setMaximumAreaAddresses((byte) IsisConstants.MAXAREAADDRESS);
400 P2PHelloPdu p2pHelloPdu = new P2PHelloPdu(isisHeader); 400 P2PHelloPdu p2pHelloPdu = new P2PHelloPdu(isisHeader);
...@@ -510,14 +510,32 @@ public final class IsisUtil { ...@@ -510,14 +510,32 @@ public final class IsisUtil {
510 l1L2HelloPdu.addTlv(areaAddressTlv); 510 l1L2HelloPdu.addTlv(areaAddressTlv);
511 Set<MacAddress> neighbors = isisInterface.neighbors(); 511 Set<MacAddress> neighbors = isisInterface.neighbors();
512 if (neighbors.size() > 0) { 512 if (neighbors.size() > 0) {
513 + List<MacAddress> neighborMacs = new ArrayList<>();
514 + for (MacAddress neighbor : neighbors) {
515 + IsisNeighbor isisNeighbor = isisInterface.lookup(neighbor);
516 + if (isisPduType == IsisPduType.L1HELLOPDU) {
517 + if (isisNeighbor.routerType() == IsisRouterType.L1 ||
518 + isisNeighbor.routerType() == IsisRouterType.L1L2) {
519 + neighborMacs.add(neighbor);
520 + }
521 + } else if (isisPduType == IsisPduType.L2HELLOPDU) {
522 + if (isisNeighbor.routerType() == IsisRouterType.L2 ||
523 + isisNeighbor.routerType() == IsisRouterType.L1L2) {
524 + neighborMacs.add(neighbor);
525 + }
526 + }
527 + }
528 +
513 tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value()); 529 tlvHeader.setTlvType(TlvType.ISNEIGHBORS.value());
514 tlvHeader.setTlvLength(0); 530 tlvHeader.setTlvLength(0);
531 +
515 IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader); 532 IsisNeighborTlv isisNeighborTlv = new IsisNeighborTlv(tlvHeader);
516 - for (MacAddress neighbor : neighbors) { 533 + for (MacAddress neighbor : neighborMacs) {
517 isisNeighborTlv.addNeighbor(neighbor); 534 isisNeighborTlv.addNeighbor(neighbor);
518 } 535 }
519 l1L2HelloPdu.addTlv(isisNeighborTlv); 536 l1L2HelloPdu.addTlv(isisNeighborTlv);
520 } 537 }
538 +
521 tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value()); 539 tlvHeader.setTlvType(TlvType.PROTOCOLSUPPORTED.value());
522 tlvHeader.setTlvLength(0); 540 tlvHeader.setTlvLength(0);
523 ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader); 541 ProtocolSupportedTlv protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
...@@ -708,4 +726,4 @@ public final class IsisUtil { ...@@ -708,4 +726,4 @@ public final class IsisUtil {
708 } 726 }
709 return Bytes.toArray(byteList); 727 return Bytes.toArray(byteList);
710 } 728 }
711 -} 729 +}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -140,8 +140,15 @@ public class LspGenerator { ...@@ -140,8 +140,15 @@ public class LspGenerator {
140 metricOfIntRea.setExpenseIsInternal(true); 140 metricOfIntRea.setExpenseIsInternal(true);
141 Ip4Address ip4Address = isisInterface.interfaceIpAddress(); 141 Ip4Address ip4Address = isisInterface.interfaceIpAddress();
142 byte[] ipAddress = ip4Address.toOctets(); 142 byte[] ipAddress = ip4Address.toOctets();
143 - ipAddress[ipAddress.length - 1] = 0; 143 + // ipAddress[ipAddress.length - 1] = 0;
144 - metricOfIntRea.setIpAddress(Ip4Address.valueOf(ipAddress)); 144 + byte[] networkmass = isisInterface.networkMask();
145 + // metric calculation part
146 + byte[] result = new byte[ipAddress.length];
147 + result[0] = (byte) (ipAddress[0] & networkmass[0]);
148 + result[1] = (byte) (ipAddress[1] & networkmass[1]);
149 + result[2] = (byte) (ipAddress[2] & networkmass[2]);
150 + result[3] = (byte) (ipAddress[3] & networkmass[3]);
151 + metricOfIntRea.setIpAddress(Ip4Address.valueOf(result));
145 metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask())); 152 metricOfIntRea.setSubnetAddres(Ip4Address.valueOf(isisInterface.networkMask()));
146 ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea); 153 ipInterReacTlv.addInternalReachabilityMetric(metricOfIntRea);
147 lsp.addTlv(ipInterReacTlv); 154 lsp.addTlv(ipInterReacTlv);
......