private void addProtection(DeviceId did, ProtectionConfig added) { ProtectedTransportEndpointDescription description = added.asDescription(); log.info("adding protection {}-{}", did, description); ProtectionConfigBehaviour behaviour = getBehaviour(did); CompletableFuture<ConnectPoint> result; result = behaviour.createProtectionEndpoint(description); result.handle((vPort, e) -> { if (vPort != null) { log.info("Virtual Port {} created for {}", vPort, description); log.debug("{}", deviceService.getPort(vPort)); } else { log.error("Protection {} exceptionally failed.", added, e); } return vPort; }); }
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; }
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; }
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); }
OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); Optional<IntentId> intentId = resourceService.getResourceAllocations(Resources.discrete(ochCP.deviceId(), ochCP.port()).id())
@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()); }
private void updateProtection(DeviceId did, ProtectionConfig before, ProtectionConfig after) { ProtectedTransportEndpointDescription description = after.asDescription(); log.info("updating protection {}-{}", did, description); ProtectionConfigBehaviour behaviour = getBehaviour(did); Optional<ConnectPoint> existing = findFirstVirtualPort(behaviour, after.fingerprint()); if (!existing.isPresent()) { log.warn("Update requested, but not found, falling back as add"); addProtection(did, after); return; } ConnectPoint vPort = existing.get(); log.info("updating protection virtual Port {} : {}", vPort, description); behaviour.updateProtectionEndpoint(vPort, description) .handle((vPortNew, e) -> { if (vPort != null) { log.info("Virtual Port {} updated for {}", vPort, description); log.debug("{}", deviceService.getPort(vPort)); } else { log.error("Protection {} -> {} exceptionally failed.", before, after, e); } return vPort; }); }
/** * Query bandwidth capacity on a port. * * @param did {@link DeviceId} * @param number {@link PortNumber} * @return bandwidth capacity */ private Optional<Bandwidth> queryBandwidth(DeviceId did, PortNumber number) { // Check and use netcfg first. ConnectPoint cp = new ConnectPoint(did, number); BandwidthCapacity config = netcfgService.getConfig(cp, BandwidthCapacity.class); if (config != null) { log.trace("Registering configured bandwidth {} for {}/{}", config.capacity(), did, number); return Optional.of(config.capacity()); } // populate bandwidth value, assuming portSpeed == bandwidth Port port = deviceService.getPort(did, number); if (port != null) { return Optional.of(Bandwidth.mbps(port.portSpeed())); } return Optional.empty(); }
@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 void updateFailoverGroup(PointToPointIntent pointIntent) { DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId(); GroupKey groupKey = makeGroupKey(pointIntent.id()); Group group = waitForGroup(deviceId, groupKey); Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator(); while (groupIterator.hasNext()) { GroupBucket bucket = groupIterator.next(); Instruction individualInstruction = bucket.treatment().allInstructions().get(0); if (individualInstruction instanceof Instructions.OutputInstruction) { Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) individualInstruction; Port port = deviceService.getPort(deviceId, outInstruction.port()); if (port == null || !port.isEnabled()) { GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket)); groupService.removeBucketsFromGroup(deviceId, groupKey, removeBuckets, groupKey, pointIntent.appId()); } } } }
final DeviceId did = (DeviceId) cp.elementId(); Device device = deviceService.getDevice(did); Port port = deviceService.getPort(did, cp.port()); updateDevice(device).ifPresent(ld -> updatePort(ld, port));
ConnectPoint connectPoint = (link.src().elementId() instanceof DeviceId) ? link.src() : link.dst(); Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); if (port == null || !port.isEnabled()) { setPathsToRemove(intent); Port port1 = deviceService.getPort(link.src().deviceId(), link.src().port()); Port port2 = deviceService.getPort(link.dst().deviceId(), link.dst().port()); if (port1 == null || !port1.isEnabled() || port2 == null || !port2.isEnabled()) { setPathsToRemove(intent);
/** * Gets primary port number through failover group associated * with this intent. */ private PortNumber getPrimaryPort(PointToPointIntent intent) { Group group = groupService.getGroup(intent.filteredIngressPoint().connectPoint().deviceId(), makeGroupKey(intent.id())); PortNumber primaryPort = null; if (group != null) { List<GroupBucket> buckets = group.buckets().buckets(); Iterator<GroupBucket> iterator = buckets.iterator(); while (primaryPort == null && iterator.hasNext()) { GroupBucket bucket = iterator.next(); Instruction individualInstruction = bucket.treatment().allInstructions().get(0); if (individualInstruction instanceof Instructions.OutputInstruction) { Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) individualInstruction; PortNumber tempPortNum = outInstruction.port(); Port port = deviceService.getPort(intent.filteredIngressPoint().connectPoint().deviceId(), tempPortNum); if (port != null && port.isEnabled()) { primaryPort = tempPortNum; } } } } return primaryPort; }
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 protected void doExecute() { DeviceService deviceService = get(DeviceService.class); DeviceAdminService deviceAdminService = get(DeviceAdminService.class); Device dev = deviceService.getDevice(DeviceId.deviceId(uri)); if (dev == null) { print(" %s", "Device does not exist"); return; } PortNumber pnum = PortNumber.fromString(portNumber); Port p = deviceService.getPort(dev.id(), pnum); if (p == null) { print(" %s", "Port does not exist"); return; } if ("enable".equals(portState)) { deviceAdminService.changePortState(dev.id(), pnum, true); } else if ("disable".equals(portState)) { deviceAdminService.changePortState(dev.id(), pnum, false); } else { print(" %s", "State must be enable or disable"); } } }
private FilteredConnectPoint output(DeviceId did, String portNumberStr, String vlanStr) { ConnectPoint cp = new ConnectPoint(did, PortNumber.fromString(portNumberStr)); if (deviceService.getPort(cp) == null) { print("Unknown port: %s", cp); } if (vlanStr == null) { return new FilteredConnectPoint(cp); } else { VlanId vlan = VlanId.vlanId(vlanStr); TrafficSelector sel = DefaultTrafficSelector.builder() .matchVlanId(vlan) .build(); return new FilteredConnectPoint(cp, sel); } }
@Override protected void doExecute() { DeviceService deviceService = get(DeviceService.class); NetworkConfigService netcfgService = get(NetworkConfigService.class); ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port); if (deviceService.getPort(connectPoint) == null) { print("Port %s does not exist.", port); return; } if (removeCfg && key == null) { // remove whole port annotation config netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class); print("Annotation Config about %s removed", connectPoint); return; } if (key == null) { print("[ERROR] Annotation key not specified."); return; } PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class); if (removeCfg) { // remove config about entry cfg.annotation(key); } else { // add remove request config cfg.annotation(key, value); } cfg.apply(); }