@Test public void testProcessHelloMessage() throws Exception { ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11")); ospfInterface.setInterfaceType(1); ospfInterface.setIpNetworkMask(Ip4Address.valueOf("244.244.244.244")); ospfInterface.setHelloIntervalTime(10); ospfInterface.setRouterDeadIntervalTime(10); ospfArea.setAreaId(Ip4Address.valueOf("12.12.12.12")); channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class); OspfMessage message; helloPacket = new HelloPacket(); helloPacket.setSourceIp(Ip4Address.valueOf("1.1.1.1")); helloPacket.setOspfVer(2); helloPacket.setAreaId(Ip4Address.valueOf("12.12.12.12")); helloPacket.setNetworkMask(Ip4Address.valueOf("244.244.244.244")); helloPacket.setHelloInterval(10); helloPacket.setRouterDeadInterval(10); helloPacket.setDr(Ip4Address.valueOf("10.10.10.10")); helloPacket.setBdr(Ip4Address.valueOf("11.11.11.11")); helloPacket.setRouterId(Ip4Address.valueOf("111.111.111.111")); message = helloPacket; ospfInterface.processHelloMessage(message, channelHandlerContext); assertThat(ospfInterfaceChannelHandler, is(notNullValue())); }
void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.getChannel(); log.debug("OspfChannelHandler::processHelloMessage...!!!"); HelloPacket helloPacket = (HelloPacket) ospfMessage; log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", interfaceType(), state()); if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) { if (!helloPacket.networkMask().equals(ipNetworkMask())) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " + "match the same network mask as the configure Interface"); return; } } if (helloPacket.helloInterval() != helloIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "hello interval as configured Interface"); return; } if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "Router Dead interval as configured Interface"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() && !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) { log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) { OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(), helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) { if (state() == OspfInterfaceState.WAITING) { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) && (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) { stopWaitTimer(); setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); if (helloPacket.dr().equals(ipAddress())) { setState(OspfInterfaceState.DR); ospfArea.refreshArea(this); } else if (helloPacket.bdr().equals(ipAddress())) { setState(OspfInterfaceState.BDR); ospfArea.refreshArea(this); } else { setState(OspfInterfaceState.DROTHER); ospfArea.refreshArea(this); } } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (helloPacket.dr().equals(sourceIp)) { if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } if (helloPacket.bdr().equals(sourceIp)) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } else { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) && routerPriority() == 0) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr()); nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (nbr.routerPriority() != helloPacket.routerPriority()) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.dr()) && !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) && (nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.bdr()) && !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) && (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); } } } }
OspfInterfaceImpl implements OspfInterface { void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.getChannel(); log.debug("OspfChannelHandler::processHelloMessage...!!!"); HelloPacket helloPacket = (HelloPacket) ospfMessage; log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", interfaceType(), state()); if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) { if (!helloPacket.networkMask().equals(ipNetworkMask())) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " + "match the same network mask as the configure Interface"); return; } } if (helloPacket.helloInterval() != helloIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "hello interval as configured Interface"); return; } if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "Router Dead interval as configured Interface"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() && !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) { log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) { OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(), helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) { if (state() == OspfInterfaceState.WAITING) { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) && (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) { stopWaitTimer(); setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); if (helloPacket.dr().equals(ipAddress())) { setState(OspfInterfaceState.DR); ospfArea.refreshArea(this); } else if (helloPacket.bdr().equals(ipAddress())) { setState(OspfInterfaceState.BDR); ospfArea.refreshArea(this); } else { setState(OspfInterfaceState.DROTHER); ospfArea.refreshArea(this); } } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (helloPacket.dr().equals(sourceIp)) { if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } if (helloPacket.bdr().equals(sourceIp)) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } else { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) && routerPriority() == 0) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr()); nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (nbr.routerPriority() != helloPacket.routerPriority()) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.dr()) && !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) && (nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.bdr()) && !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) && (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); } } } } }
OspfInterfaceImpl implements OspfInterface { void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.getChannel(); log.debug("OspfChannelHandler::processHelloMessage...!!!"); HelloPacket helloPacket = (HelloPacket) ospfMessage; log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", interfaceType(), state()); if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) { if (!helloPacket.networkMask().equals(ipNetworkMask())) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " + "match the same network mask as the configure Interface"); return; } } if (helloPacket.helloInterval() != helloIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "hello interval as configured Interface"); return; } if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "Router Dead interval as configured Interface"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() && !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) { log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) { OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(), helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) { if (state() == OspfInterfaceState.WAITING) { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) && (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) { stopWaitTimer(); setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); if (helloPacket.dr().equals(ipAddress())) { setState(OspfInterfaceState.DR); ospfArea.refreshArea(this); } else if (helloPacket.bdr().equals(ipAddress())) { setState(OspfInterfaceState.BDR); ospfArea.refreshArea(this); } else { setState(OspfInterfaceState.DROTHER); ospfArea.refreshArea(this); } } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (helloPacket.dr().equals(sourceIp)) { if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } if (helloPacket.bdr().equals(sourceIp)) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } else { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) && routerPriority() == 0) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr()); nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (nbr.routerPriority() != helloPacket.routerPriority()) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.dr()) && !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) && (nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.bdr()) && !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) && (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); } } } }  }
OspfInterfaceImpl implements OspfInterface { void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.getChannel(); log.debug("OspfChannelHandler::processHelloMessage...!!!"); HelloPacket helloPacket = (HelloPacket) ospfMessage; log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", interfaceType(), state()); if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) { if (!helloPacket.networkMask().equals(ipNetworkMask())) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " + "match the same network mask as the configure Interface"); return; } } if (helloPacket.helloInterval() != helloIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "hello interval as configured Interface"); return; } if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "Router Dead interval as configured Interface"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() && !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) { log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) { OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(), helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) { if (state() == OspfInterfaceState.WAITING) { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) && (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) { stopWaitTimer(); setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); if (helloPacket.dr().equals(ipAddress())) { setState(OspfInterfaceState.DR); ospfArea.refreshArea(this); } else if (helloPacket.bdr().equals(ipAddress())) { setState(OspfInterfaceState.BDR); ospfArea.refreshArea(this); } else { setState(OspfInterfaceState.DROTHER); ospfArea.refreshArea(this); } } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (helloPacket.dr().equals(sourceIp)) { if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } if (helloPacket.bdr().equals(sourceIp)) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } else { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) && routerPriority() == 0) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr()); nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (nbr.routerPriority() != helloPacket.routerPriority()) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.dr()) && !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) && (nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.bdr()) && !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) && (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); } } } }  OspfInterfaceState state(); void setState(OspfInterfaceState ospfInterfaceState); void setChannel(Channel channel); OspfArea ospfArea(); void setController(Controller controller); void setOspfArea(OspfArea ospfArea); String interfaceState(); List<LsaHeader> linkStateHeaders(); Ip4Address ipNetworkMask(); @Override void setIpNetworkMask(Ip4Address ipNetworkMask); void addNeighbouringRouter(OspfNbr ospfNbr); OspfNbr neighbouringRouter(String neighborId); void removeNeighbors(); void removeNeighbor(OspfNbr ospfNeighbor); void addLsaHeaderForDelayAck(LsaHeader lsaHeader); void removeLsaFromNeighborMap(String lsaKey); boolean isNeighborInList(String neighborId); Map<String, OspfNbr> listOfNeighbors(); void setListOfNeighbors(HashMap<String, OspfNbr> listOfNeighbors); int interfaceIndex(); void setInterfaceIndex(int interfaceIndex); Ip4Address ipAddress(); void setIpAddress(Ip4Address ipAddress); int routerPriority(); void setRouterPriority(int routerPriority); int helloIntervalTime(); void setHelloIntervalTime(int helloIntervalTime); int routerDeadIntervalTime(); void setRouterDeadIntervalTime(int routerDeadIntervalTime); int interfaceType(); void setInterfaceType(int interfaceType); int mtu(); void setMtu(int mtu); int reTransmitInterval(); void setReTransmitInterval(int reTransmitInterval); Ip4Address dr(); void setDr(Ip4Address dr); Ip4Address bdr(); void setBdr(Ip4Address bdr); void interfaceUp(); void backupSeen(Channel ch); void waitTimer(Channel ch); void callDrElection(Channel ch); void neighborChange(); void interfaceDown(); void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx); boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket); void startHelloTimer(); void stopHelloTimer(); void startWaitTimer(); void stopWaitTimer(); void startDelayedAckTimer(); void stopDelayedAckTimer(); void electRouter(Channel ch); List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr); OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters); OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
                                      OspfEligibleRouter electedBdr); OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList); void addDeviceInformation(OspfRouter ospfRouter); void removeDeviceInformation(OspfRouter ospfRouter); void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); void removeLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
OspfInterfaceImpl implements OspfInterface { void processHelloMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.getChannel(); log.debug("OspfChannelHandler::processHelloMessage...!!!"); HelloPacket helloPacket = (HelloPacket) ospfMessage; log.debug("OspfChannelHandler::processHelloMessage::Interface Type {} OSPFInterfaceState {} ", interfaceType(), state()); if (interfaceType() != OspfInterfaceType.POINT_TO_POINT.value()) { if (!helloPacket.networkMask().equals(ipNetworkMask())) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received does not " + "match the same network mask as the configure Interface"); return; } } if (helloPacket.helloInterval() != helloIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "hello interval as configured Interface"); return; } if (helloPacket.routerDeadInterval() != routerDeadIntervalTime()) { log.debug("OspfChannelHandler::processHelloMessage::Hello Packet Received have the same " + "Router Dead interval as configured Interface"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value() && !helloPacket.dr().equals(OspfUtil.DEFAULTIP)) { log.debug("OspfChannelHandler::processHelloMessage:: Neighbor in broadcast network"); return; } if (interfaceType == OspfInterfaceType.POINT_TO_POINT.value()) { OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, helloPacket.sourceIp(), helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } } else if (interfaceType == OspfInterfaceType.BROADCAST.value()) { if (state() == OspfInterfaceState.WAITING) { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0"))) && (!helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0")))) { stopWaitTimer(); setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); if (helloPacket.dr().equals(ipAddress())) { setState(OspfInterfaceState.DR); ospfArea.refreshArea(this); } else if (helloPacket.bdr().equals(ipAddress())) { setState(OspfInterfaceState.BDR); ospfArea.refreshArea(this); } else { setState(OspfInterfaceState.DROTHER); ospfArea.refreshArea(this); } } else if (!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); } else { nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); } if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (helloPacket.dr().equals(sourceIp)) { if (helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } if (helloPacket.bdr().equals(sourceIp)) { stopWaitTimer(); backupSeen(ctx.getChannel()); } } else { if ((!helloPacket.dr().equals(Ip4Address.valueOf("0.0.0.0")) || !helloPacket.bdr().equals(Ip4Address.valueOf("0.0.0.0"))) && routerPriority() == 0) { setDr(helloPacket.dr()); setBdr(helloPacket.bdr()); } Ip4Address sourceIp = helloPacket.sourceIp(); OspfNbr nbr; if (!isNeighborInList(helloPacket.routerId().toString())) { nbr = new OspfNbrImpl(ospfArea, this, sourceIp, helloPacket.routerId(), helloPacket.options(), topologyForDeviceAndLink); nbr.setNeighborId(helloPacket.routerId()); nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); nbr.setRouterPriority(helloPacket.routerPriority()); addNeighbouringRouter(nbr); ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { log.debug("OspfChannelHandler::NeighborInList::helloPacket.bdr(): {}, " + "helloPacket.dr(): {}", helloPacket.bdr(), helloPacket.dr()); nbr = neighbouringRouter(helloPacket.routerId().toString()); nbr.setRouterPriority(helloPacket.routerPriority()); if (!helloPacket.containsNeighbour(ospfArea.routerId())) { ((OspfNbrImpl) nbr).oneWayReceived(helloPacket, channel); } else { ((OspfNbrImpl) nbr).twoWayReceived(helloPacket, ctx.getChannel()); } if (nbr.routerPriority() != helloPacket.routerPriority()) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.dr()) && !(nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.dr())) && (nbr.neighborIpAddr().equals(nbr.neighborDr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (nbr.neighborIpAddr().equals(helloPacket.bdr()) && !(nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } if (!(nbr.neighborIpAddr().equals(helloPacket.bdr())) && (nbr.neighborIpAddr().equals(nbr.neighborBdr()))) { nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); neighborChange(); } nbr.setNeighborBdr(helloPacket.bdr()); nbr.setNeighborDr(helloPacket.dr()); } } } }  OspfInterfaceState state(); void setState(OspfInterfaceState ospfInterfaceState); void setChannel(Channel channel); OspfArea ospfArea(); void setController(Controller controller); void setOspfArea(OspfArea ospfArea); String interfaceState(); List<LsaHeader> linkStateHeaders(); Ip4Address ipNetworkMask(); @Override void setIpNetworkMask(Ip4Address ipNetworkMask); void addNeighbouringRouter(OspfNbr ospfNbr); OspfNbr neighbouringRouter(String neighborId); void removeNeighbors(); void removeNeighbor(OspfNbr ospfNeighbor); void addLsaHeaderForDelayAck(LsaHeader lsaHeader); void removeLsaFromNeighborMap(String lsaKey); boolean isNeighborInList(String neighborId); Map<String, OspfNbr> listOfNeighbors(); void setListOfNeighbors(HashMap<String, OspfNbr> listOfNeighbors); int interfaceIndex(); void setInterfaceIndex(int interfaceIndex); Ip4Address ipAddress(); void setIpAddress(Ip4Address ipAddress); int routerPriority(); void setRouterPriority(int routerPriority); int helloIntervalTime(); void setHelloIntervalTime(int helloIntervalTime); int routerDeadIntervalTime(); void setRouterDeadIntervalTime(int routerDeadIntervalTime); int interfaceType(); void setInterfaceType(int interfaceType); int mtu(); void setMtu(int mtu); int reTransmitInterval(); void setReTransmitInterval(int reTransmitInterval); Ip4Address dr(); void setDr(Ip4Address dr); Ip4Address bdr(); void setBdr(Ip4Address bdr); void interfaceUp(); void backupSeen(Channel ch); void waitTimer(Channel ch); void callDrElection(Channel ch); void neighborChange(); void interfaceDown(); void processOspfMessage(OspfMessage ospfMessage, ChannelHandlerContext ctx); boolean compareDdPackets(DdPacket receivedDPacket, DdPacket lastDdPacket); void startHelloTimer(); void stopHelloTimer(); void startWaitTimer(); void stopWaitTimer(); void startDelayedAckTimer(); void stopDelayedAckTimer(); void electRouter(Channel ch); List<OspfEligibleRouter> calculateListOfEligibleRouters(OspfEligibleRouter electedDr); OspfEligibleRouter electBdr(List<OspfEligibleRouter> eligibleRouters); OspfEligibleRouter electDr(List<OspfEligibleRouter> eligibleRouters,
                                      OspfEligibleRouter electedBdr); OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList); void addDeviceInformation(OspfRouter ospfRouter); void removeDeviceInformation(OspfRouter ospfRouter); void addLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); void removeLinkInformation(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }