@Override public ObjectNode encode(Port port, CodecContext context) { checkNotNull(port, "Port cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(ELEMENT, port.element().id().toString()) .put(PORT_NAME, portName(port.number())) .put(IS_ENABLED, port.isEnabled()) .put(TYPE, port.type().toString().toLowerCase()) .put(PORT_SPEED, port.portSpeed()); return annotate(result, port, context); }
private String getPortStatStr(PortStatistics stat, Port port) { final String portName = port.annotations().value(AnnotationKeys.PORT_NAME); return String.format("port: %s(%s), ", stat.portNumber(), portName) + String.format("enabled: %b, ", port.isEnabled()) + String.format("pktRx: %d, ", stat.packetsReceived()) + String.format("pktTx: %d, ", stat.packetsSent()) + String.format("pktRxErr: %d, ", stat.packetsRxErrors()) + String.format("pktTxErr: %d, ", stat.packetsTxErrors()) + String.format("pktRxDrp: %d, ", stat.packetsRxDropped()) + String.format("pktTxDrp: %d", stat.packetsTxDropped()); }
private DeviceEvent updatePort(Device device, Port oldPort, Port newPort, Map<PortNumber, Port> ports) { if (oldPort.isEnabled() != newPort.isEnabled() || oldPort.type() != newPort.type() || oldPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { ports.put(oldPort.number(), newPort); return new DeviceEvent(PORT_UPDATED, device, newPort); } return null; }
/** * Produces JSON array containing ports of the specified device. * * @param service device service * @param mapper object mapper * @param device infrastructure devices * @return JSON array */ public JsonNode jsonPorts(DeviceService service, ObjectMapper mapper, Device device) { ObjectNode result = mapper.createObjectNode(); ArrayNode ports = mapper.createArrayNode(); for (Port port : service.getPorts(device.id())) { if (isIncluded(port)) { ports.add(mapper.createObjectNode() .put("port", port.number().toString()) .put("isEnabled", port.isEnabled()) .put("type", port.type().toString().toLowerCase()) .put("portSpeed", port.portSpeed()) .set("annotations", annotations(mapper, port.annotations()))); } } result.set("device", jsonForEntity(device, Device.class)); result.set("ports", ports); return result; }
private void printPort(Port port) { String portName = portName(port.number()); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); }
protected void printPorts(DeviceService service, Device device) { List<Port> ports = new ArrayList<>(service.getPorts(device.id())); Collections.sort(ports, Comparators.PORT_COMPARATOR); for (Port port : ports) { if (!isIncluded(port)) { continue; } String portName = port.number().toString(); Object portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); String annotations = annotations(port.annotations()); print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations); } } }
synchronized (openstackPortInfoMap) { if (portName.startsWith(PORTNAME_PREFIX_VM)) { if (port.isEnabled()) { OpenstackSwitchingRulePopulator rulePopulator = new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, } else if (!port.isEnabled() && openstackPortInfoMap.containsKey(portName)) { log.debug("Flowrules according to the port {} were removed", port.number()); OpenstackSwitchingRulePopulator rulePopulator =
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()); } } } }
case PORT_ADDED: case PORT_UPDATED: if (port.isEnabled()) { updateDevice(device).ifPresent(ld -> updatePort(ld, port)); } else {
/** * 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 processDeviceEvent(DeviceEvent event) { //FIXME handle the case where a device is suspended, this may or may not come up DeviceEvent.Type type = event.type(); DeviceId id = event.subject().id(); if (type == DEVICE_ADDED || type == DEVICE_AVAILABILITY_CHANGED && deviceService.isAvailable(id)) { // When device is added or becomes available, add all its ports deviceService.getPorts(event.subject().id()) .forEach(p -> addEdgePort(new ConnectPoint(id, p.number()))); } else if (type == DEVICE_REMOVED || type == DEVICE_AVAILABILITY_CHANGED && !deviceService.isAvailable(id)) { // When device is removed or becomes unavailable, remove all its ports. // Note: cannot rely on Device subsystem, ports may be gone. Optional.ofNullable(connectionPoints.remove(id)) .orElse(ImmutableSet.of()) .forEach(point -> post(new EdgePortEvent(EDGE_PORT_REMOVED, point))); } else if (type == DeviceEvent.Type.PORT_ADDED || type == PORT_UPDATED && event.port().isEnabled()) { addEdgePort(new ConnectPoint(id, event.port().number())); } else if (type == DeviceEvent.Type.PORT_REMOVED || type == PORT_UPDATED && !event.port().isEnabled()) { removeEdgePort(new ConnectPoint(id, event.port().number())); } }
? 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);
if (port.isEnabled()) { setVxLanFlowRule(vni, device.id(), hostxDpIpAddress, fixedIpx); setVxLanFlowRule(vni, d.id(), hostDpIpAddress, fixedIp);
/** * 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; }
case PORT_ADDED: case PORT_UPDATED: if (event.port().isEnabled()) { registerPortResource(device, event.port()); } else {
String portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase(); switch (port.type()) {