/** * Adds neighboring router to list. * * @param ospfNbr ospfNbr instance */ public void addNeighbouringRouter(OspfNbr ospfNbr) { listOfNeighbors.put(ospfNbr.neighborId().toString(), ospfNbr); }
@Override public ObjectNode encode(NiciraSetTunnelDst niciraSetTunnelDst, CodecContext context) { checkNotNull(niciraSetTunnelDst, "Nicira Set Tunnel DST cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(TUNNEL_DST, niciraSetTunnelDst.tunnelDst().toString()); return root; }
private void getLinksToDelete(Set<Ip4Address> list, Ip4Address value, OspfArea ospfArea) { Iterator iterator = list.iterator(); while (iterator.hasNext()) { Ip4Address secondValue = (Ip4Address) iterator.next(); if (!value.equals("0.0.0.0")) { if ((!value.equals(secondValue))) { if ((!secondValue.equals(ospfArea.routerId()))) { String key = "link:" + value.toString() + "-" + secondValue.toString(); String key1 = "link:" + secondValue.toString() + "-" + value.toString(); LinkInformation linkDetails = getLinkInformation(key); LinkInformation linkDetailsOther = getLinkInformation(key1); linkInformationMapForPointToPoint.put(key, linkDetails); linkInformationMapForPointToPoint.put(key1, linkDetailsOther); } } } } }
/** * Removes links from LinkInformationMap. * * @param routerId router id */ public void removeLinks(Ip4Address routerId) { Map<String, LinkInformation> linkInformationMapLocal = linkInformationMap; if (linkInformationMapLocal != null) { for (Map.Entry<String, LinkInformation> entry : linkInformationMap.entrySet()) { String key = entry.getKey(); boolean check = key.contains(routerId.toString()); LinkInformation linkInformation = linkInformationMap.get(key); boolean check1 = (linkInformation.linkDestinationId() == routerId) ? true : false; if (check || check1) { toRemove.add(key); } } removeLinkFromMap(); } }
/** * Checks Link State ID is equal to one of the router's own IP interface addresses. * * @param linkStateId link state id * @return true if link state matches or false */ private boolean isLinkStateMatchesOwnRouterId(String linkStateId) { boolean isLinkStateMatches = false; List<OspfInterface> interfaceLst = ospfArea.ospfInterfaceList(); for (OspfInterface ospfInterface : interfaceLst) { if (ospfInterface.ipAddress().toString().equals(linkStateId)) { isLinkStateMatches = true; break; } } return isLinkStateMatches; }
Ip4Address ipAddress = getInterfaceIp(interfaceIndex); NetworkInterface networkInterface = NetworkInterface.getByInetAddress( InetAddress.getByName(ipAddress.toString())); Enumeration ipAddresses = networkInterface.getInetAddresses(); int index = 0;
@Override public void routerRemoved(OspfRouter ospfRouter) { String routerId = ospfRouter.routerIp().toString(); log.info("Delete device {}", routerId); DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); if (deviceProviderService == null) { return; } deviceProviderService.deviceDisconnected(deviceId); log.info("delete device {}", routerId); }
/** * DR election process. * * @param routersList list of eligible routers. * @return OSPF eligible router instance. */ public OspfEligibleRouter selectRouterBasedOnPriority(List<OspfEligibleRouter> routersList) { OspfEligibleRouter initialRouter = routersList.get(0); for (int i = 1; i < routersList.size(); i++) { OspfEligibleRouter router = routersList.get(i); if (router.getRouterPriority() > initialRouter.getRouterPriority()) { initialRouter = router; } else if (router.getRouterPriority() == initialRouter.getRouterPriority()) { try { if (OspfUtil.ipAddressToLong(router.getIpAddress().toString()) > OspfUtil.ipAddressToLong(initialRouter.getIpAddress().toString())) { initialRouter = router; } } catch (Exception e) { log.debug("OSPFInterfaceChannelHandler::selectRouterBasedOnPriority ->" + " eligibleRouters: {}", initialRouter); } } } return initialRouter; }
for (OspfNbr neigbor : nghbrList) { print("%-20s%-20s%-20s%-20s%-20s\n", neigbor.neighborId(), neigbor.routerPriority(), neigbor.getState() + "/" + checkDrBdrOther(neigbor.neighborIpAddr().toString(), neigbor.neighborDr().toString(), neigbor.neighborBdr().toString()), neigbor.neighborIpAddr().toString(), interfc.ipAddress());
/** * Produces JSON object for a route. * * @param mapper the JSON object mapper to use * @param route the route with the data * @return JSON object for the route */ private ObjectNode json(ObjectMapper mapper, BgpRouteEntry route) { ObjectNode result = mapper.createObjectNode(); result.put("prefix", route.prefix().toString()); result.put("nextHop", route.nextHop().toString()); result.put("bgpId", route.getBgpSession().remoteInfo().bgpId().toString()); result.put("origin", BgpConstants.Update.Origin.typeToString(route.getOrigin())); result.set("asPath", json(mapper, route.getAsPath())); result.put("localPref", route.getLocalPref()); result.put("multiExitDisc", route.getMultiExitDisc()); return result; }
LsAcknowledge lsAckPacket = (LsAcknowledge) ospfMessage; OspfNbrImpl nbr = (OspfNbrImpl) neighbouringRouter(lsAckPacket.routerId().toString()); if (nbr != null) { if (nbr.getState().getValue() < OspfNeighborState.EXCHANGE.getValue()) {
@Override public void deleteLink(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) { log.debug("Delete link {}", ospfRouter.routerIp().toString()); if (linkProviderService == null) { return; } LinkDescription linkDes = buildLinkDes(ospfRouter, ospfLinkTed); //Updating ports of the link List<PortDescription> srcPortDescriptions = new LinkedList<>(); srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true)); deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions); List<PortDescription> dstPortDescriptions = new LinkedList<>(); dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true)); deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions); linkProviderService.linkVanished(linkDes); }
result.put("remoteAs4", bgpSession.remoteInfo().as4Number()); result.put("remoteHoldtime", bgpSession.remoteInfo().holdtime()); result.put("remoteBgpId", bgpSession.remoteInfo().bgpId().toString()); result.put("remoteIpv4Unicast", bgpSession.remoteInfo().ipv4Unicast()); result.put("remoteIpv4Multicast", bgpSession.remoteInfo().ipv4Multicast()); result.put("localAs4", bgpSession.localInfo().as4Number()); result.put("localHoldtime", bgpSession.localInfo().holdtime()); result.put("localBgpId", bgpSession.localInfo().bgpId().toString()); result.put("localIpv4Unicast", bgpSession.localInfo().ipv4Unicast()); result.put("localIpv4Multicast", bgpSession.localInfo().ipv4Multicast());
@Override public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { while (channelBuffer.readableBytes() >= OspfUtil.LSREQUEST_LENGTH) { LsRequestPacket lsRequestPacket = new LsRequestPacket(); lsRequestPacket.setLsType(channelBuffer.readInt()); byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); lsRequestPacket.setLinkStateId(Ip4Address.valueOf(tempByteArray).toString()); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); lsRequestPacket.setOwnRouterId(Ip4Address.valueOf(tempByteArray).toString()); this.addLinkStateRequests(lsRequestPacket); } }
@Override protected void execute() { BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); Collection<BgpSession> bgpSessions = service.getBgpSessions(); if (bgpNeighbor != null) { // Print a single neighbor (if found) BgpSession foundBgpSession = null; for (BgpSession bgpSession : bgpSessions) { if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) { foundBgpSession = bgpSession; break; } } if (foundBgpSession != null) { printNeighbor(foundBgpSession); } else { print("BGP neighbor %s not found", bgpNeighbor); } return; } // Print all neighbors printNeighbors(bgpSessions); }
log.debug("OspfChannelHandler::processLsUpdateMessage"); LsUpdate lsUpdate = (LsUpdate) ospfMessage; String neighbourId = lsUpdate.routerId().toString();
/** * Builds link description. * * @param ospfRouter OSPF router instance * @param ospfLinkTed OSPF link TED instance * @return link description instance */ private LinkDescription buildLinkDes(OspfRouter ospfRouter, OspfLinkTed ospfLinkTed) { long srcAddress = 0; long dstAddress = 0; boolean localPseduo = false; //Changing of port numbers srcAddress = Ip4Address.valueOf(ospfRouter.routerIp().toString()).toInt(); dstAddress = Ip4Address.valueOf(ospfRouter.neighborRouterId().toString()).toInt(); DeviceId srcId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); DeviceId dstId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.neighborRouterId())); if (ospfRouter.isDr()) { localPseduo = true; } if (localPseduo && srcAddress == 0) { srcAddress = PSEUDO_PORT; } ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress)); ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress)); return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false); }
@Override public void routerAdded(OspfRouter ospfRouter) { String routerId = ospfRouter.routerIp().toString(); log.info("Added device {}", routerId); DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); Device.Type deviceType = Device.Type.ROUTER; //If our routerType is Dr or Bdr type is PSEUDO if (ospfRouter.isDr()) { deviceType = Device.Type.ROUTER; } else { deviceType = Device.Type.VIRTUAL; } //deviceId = DeviceId.deviceId(routerDetails); ChassisId cId = new ChassisId(); DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); newBuilder.set(AnnotationKeys.TYPE, "l3"); newBuilder.set("routerId", routerId); DeviceDescription description = new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()), deviceType, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); deviceProviderService.deviceConnected(deviceId, description); }
@Override protected void execute() { BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); // Print summary of the routes if (routesSummary) { printSummary(service.getBgpRoutes4(), service.getBgpRoutes6()); return; } BgpSession foundBgpSession = null; if (bgpNeighbor != null) { // Print the routes from a single neighbor (if found) for (BgpSession bgpSession : service.getBgpSessions()) { if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) { foundBgpSession = bgpSession; break; } } if (foundBgpSession == null) { print("BGP neighbor %s not found", bgpNeighbor); return; } } // Print the routes if (foundBgpSession != null) { printRoutes(foundBgpSession.getBgpRibIn4(), foundBgpSession.getBgpRibIn6()); } else { printRoutes(service.getBgpRoutes4(), service.getBgpRoutes6()); } }
routerLsa.setLinkStateId(routerId.toString()); routerLsa.setLsType(OspfLsaType.ROUTER.value()); routerLsa.setAge(1);