private static Set<PiPreReplica> getReplicas( Collection<OutputInstruction> instructions, Device device) throws PiTranslationException { // Account for multiple replicas for the same port. final Map<PortNumber, Set<PiPreReplica>> replicaMap = Maps.newHashMap(); final List<PortNumber> ports = instructions.stream() .map(OutputInstruction::port) .collect(Collectors.toList()); for (PortNumber port : ports) { if (port.isLogical()) { port = logicalToPipelineSpecific(port, device); } // Use incremental instance IDs for replicas of the same port. replicaMap.putIfAbsent(port, Sets.newHashSet()); replicaMap.get(port).add( new PiPreReplica(port, replicaMap.get(port).size() + 1)); } return replicaMap.values().stream() .flatMap(Collection::stream) .collect(Collectors.toSet()); }
private boolean isEdgePort(ConnectPoint point) { // Logical ports are not counted as edge ports nor are infrastructure // ports. Ports that have only edge links are considered edge ports. return !point.port().isLogical() && deviceService.getPort(point) != null && linkService.getLinks(point).stream() .allMatch(link -> link.type() == Type.EDGE); }
private void removeEdgePort(ConnectPoint point) { // trying to remove edge ports, so we shouldn't check if it's EdgePoint if (!point.port().isLogical()) { Set<ConnectPoint> set = connectionPoints.get(point.deviceId()); if (set == null) { return; } if (set.remove(point)) { post(new EdgePortEvent(EDGE_PORT_REMOVED, point)); } if (set.isEmpty()) { connectionPoints.computeIfPresent(point.deviceId(), (k, v) -> { if (v.isEmpty()) { return null; } else { return v; } }); } } } }
/** * Updates discovery helper state of the specified port. * * Adds a port to the discovery helper if up and discovery is enabled, * or calls {@link #removePort(Port)} otherwise. */ private void updatePort(LinkDiscovery discoverer, Port port) { if (port == null) { return; } if (port.number().isLogical()) { // silently ignore logical ports return; } if (rules.isSuppressed(port) || isBlacklisted(port)) { log.trace("LinkDiscovery from {} disabled by configuration", port); removePort(port); return; } // check if enabled and turn off discovery? if (!port.isEnabled()) { removePort(port); return; } discoverer.addPort(port); }
private void dumpCpStatistics(ConnectPoint cp, Collection<PortStatistics> devPortStats, Collection<PortStatistics> devPortDeltaStats, String direction, ServiceRefs svcs) { if (cp == null) { return; } dump(" %s:", direction); if (cp.port().isLogical()) { dump(" - logical: device: %s, port: %s", cp.deviceId(), cp.port()); return; } Port port = svcs.deviceService.getPort(cp.deviceId(), cp.port()); if (port == null) { return; } try { devPortStats.stream() .filter(stat -> stat.portNumber().equals(cp.port())) .forEach(stat -> dump(" - stat : %s:", getPortStatStr(stat, port))); } catch (IllegalStateException e) { error("error: " + e); return; } try { devPortDeltaStats.stream() .filter(stat -> stat.portNumber().equals(cp.port())) .forEach(stat -> dump(" - delta : %s:", getPortStatStr(stat, port))); } catch (IllegalStateException e) { error("error: " + e); } }
@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 DeviceService service = AbstractShellCommand.get(DeviceService.class); // Generate the device ID/port number identifiers for (Device device : service.getDevices()) { SortedSet<String> strings = delegate.getStrings(); for (Port port : service.getPorts(device.id())) { if (!port.number().isLogical()) { strings.add(device.id().toString() + "/" + port.number()); } } } // Now let the completer do the work for figuring out what to offer. return delegate.complete(session, commandLine, candidates); }