private void updatePortData(DeviceId deviceId, PortStatistics stats) { ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port())); DataPoint c = current.get(cp); // Create a new data point and make it the current one current.put(cp, new DataPoint(stats)); // If we have a current data point, demote it to previous if (c != null) { previous.put(cp, c); } }
@Override public ObjectNode encode(ConnectPoint point, CodecContext context) { checkNotNull(point, "Connect point cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(PORT, point.port().toString()); if (point.elementId() instanceof DeviceId) { root.put(ELEMENT_DEVICE, point.deviceId().toString()); } else if (point.elementId() instanceof HostId) { root.put(ELEMENT_HOST, point.hostId().toString()); } return root; }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
@Override public boolean isEdgePoint(ConnectPoint point) { checkPermission(TOPOLOGY_READ); Set<ConnectPoint> connectPoints = connectionPoints.get(point.deviceId()); return connectPoints != null && connectPoints.contains(point); }
/** * Creates a list of continuous bandwidth resources given a list of connect * points and a bandwidth. * * @param cps the list of connect points * @param bw the bandwidth expressed as a double * @return the list of resources */ private static List<Resource> resources(List<ConnectPoint> cps, double bw) { return cps.stream() // Make sure the element id is a valid device id .filter(cp -> cp.elementId() instanceof DeviceId) // Create a continuous resource for each CP we're going through .map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(bw)) .collect(Collectors.toList()); }
@Override protected void doExecute() { DeviceService service = get(DeviceService.class); for (String portStr : ports) { ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(portStr); Port port = service.getPort(connectPoint.deviceId(), connectPoint.port()); printPort(port); printVlans(port); } }
private LinkedList<PcepValueType> createEroSubObj(Path path) { LinkedList<PcepValueType> subObjects = new LinkedList<>(); List<Link> links = path.links(); ConnectPoint source = null; ConnectPoint destination = null; IpAddress ipDstAddress = null; IpAddress ipSrcAddress = null; PcepValueType subObj = null; long portNo; for (Link link : links) { source = link.src(); if (!(source.equals(destination))) { //set IPv4SubObject for ERO object portNo = source.port().toLong(); portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipSrcAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipSrcAddress.getIp4Address().toInt()); subObjects.add(subObj); } destination = link.dst(); portNo = destination.port().toLong(); portNo = ((portNo & IDENTIFIER_SET) == IDENTIFIER_SET) ? portNo & SET : portNo; ipDstAddress = Ip4Address.valueOf((int) portNo); subObj = new IPv4SubObject(ipDstAddress.getIp4Address().toInt()); subObjects.add(subObj); } return subObjects; }
@Override public int complete(Session session, CommandLine commandLine, List<String> candidates) { // Delegate string completer StringsCompleter delegate = new StringsCompleter(); // Fetch our service and feed it's offerings to the string completer LinkService service = AbstractShellCommand.get(LinkService.class); // Link source the previous argument. String srcArg = commandLine.getArguments()[commandLine.getCursorArgumentIndex() - 1]; // Generate the device ID/port number identifiers SortedSet<String> strings = delegate.getStrings(); try { ConnectPoint src = ConnectPoint.deviceConnectPoint(srcArg); service.getEgressLinks(src) .forEach(link -> strings.add(link.dst().elementId().toString() + "/" + link.dst().port())); } catch (NumberFormatException e) { System.err.println("Invalid connect-point"); } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }
.filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))) .filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())) .findFirst()
/** * Returns the point where the OLT is connected to the fabric given a * connect point on the agent device. * * @param agentConnectPoint connect point on the agent device * @return point were OLT is connected to fabric */ public Optional<ConnectPoint> getOltConnectPoint(ConnectPoint agentConnectPoint) { int index = ((int) agentConnectPoint.port().toLong()) / CHIP_PORT_RANGE_SIZE; if (index >= sortedOltChips.size()) { return Optional.empty(); } return Optional.of(sortedOltChips.get(index).getKey()); }
ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number()); ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number());
private boolean isAllowed(ConnectPoint circuitCp, ConnectPoint connectivityCp) { ConnectPoint staticPort = staticPort(circuitCp); return staticPort == null || staticPort.equals(connectivityCp); }
@Override protected List<String> choices() { DeviceService deviceService = getService(DeviceService.class); LinkService linkService = getService(LinkService.class); Optional<ConnectPoint> port = Arrays.asList(commandLine.getArguments()).stream() .filter(s -> s.contains(":") && s.contains("/")) .map(s -> { try { return deviceConnectPoint(s); } catch (IllegalArgumentException e) { // silently ill-formed String return null; } }) .filter(Objects::nonNull) .filter(cp -> deviceService.getPort(cp) != null) .findFirst(); if (!port.isPresent()) { // no candidate return Collections.emptyList(); } final ConnectPoint cp = port.get(); return linkService.getLinks(cp).stream() .flatMap(l -> Stream.of(l.src(), l.dst())) .filter(peer -> !cp.equals(peer)) .distinct() .map(ConnectPoint::toString) .collect(Collectors.toList()); }
/** * Returns the routing control plane connect point. * * @return control plane connect point */ public ConnectPoint getControlPlaneConnectPoint() { return ConnectPoint.deviceConnectPoint(object.path(CP_CONNECT_POINT).asText()); }
private FilteredConnectPoint getFilteredPointFromLink(Link link) { FilteredConnectPoint filteredConnectPoint; if (link.src().elementId() instanceof DeviceId) { filteredConnectPoint = new FilteredConnectPoint(link.src()); } else if (link.dst().elementId() instanceof DeviceId) { filteredConnectPoint = new FilteredConnectPoint(link.dst()); } else { throw new IntentCompilationException(DEVICE_ID_NOT_FOUND); } return filteredConnectPoint; }
private ConnectPoint staticPort(ConnectPoint connectPoint) { Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); // FIXME: need a better way to match the port if (staticPort != null) { for (Port p : deviceService.getPorts(connectPoint.deviceId())) { if (staticPort.equals(p.number().name())) { return new ConnectPoint(p.element().id(), p.number()); } } } return null; }
@Override public Set<Host> getConnectedHosts(DeviceId deviceId) { Set<Host> hostset = new HashSet<>(); for (ConnectPoint p : locations.keySet()) { if (p.deviceId().equals(deviceId)) { hostset.addAll(locations.get(p)); } } return hostset; }