/** * Extracts port number of the given json node. * * @param jsonNode json node * @return port number */ private PortNumber getPortNumber(ObjectNode jsonNode) { PortNumber portNumber; JsonNode portNode = nullIsIllegal(jsonNode.get(InstructionCodec.PORT), InstructionCodec.PORT + InstructionCodec.ERROR_MESSAGE); if (portNode.isLong() || portNode.isInt()) { portNumber = PortNumber.portNumber(portNode.asLong()); } else if (portNode.isTextual()) { portNumber = PortNumber.fromString(portNode.textValue()); } else { throw new IllegalArgumentException("Port value " + portNode.toString() + " is not supported"); } return portNumber; }
@Override protected void doExecute() { deviceService = get(DeviceService.class); resourceService = get(ResourceService.class); if (typeStrings != null) { typesToPrint = new HashSet<>(Arrays.asList(typeStrings)); } else { typesToPrint = Collections.emptySet(); } if (intentStrings != null) { intentsToPrint = new HashSet<>(Arrays.asList(intentStrings)); } else { intentsToPrint = Collections.emptySet(); } if (deviceIdStr != null && portNumberStr != null) { DeviceId deviceId = deviceId(deviceIdStr); PortNumber portNumber = PortNumber.fromString(portNumberStr); printAllocation(deviceId, portNumber, 0); } else if (deviceIdStr != null) { DeviceId deviceId = deviceId(deviceIdStr); printAllocation(deviceId, 0); } else { printAllocation(); } }
@Override protected void doExecute() { resourceService = get(ResourceService.class); DeviceId did = DeviceId.deviceId(deviceIdStr); PortNumber portNum = PortNumber.fromString(portNumberStr); ResourceConsumer consumer = IntentId.valueOf(nIntendId); Resource resource = Resources.discrete(did, portNum, createLambda(Integer.parseInt(lambda))).resource(); Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource); if (allocate.isPresent()) { print("Allocated: %s", allocate.get()); } else { print("Failed to allocate %s for %s", resource, consumer); } }
@Override protected void doExecute() { resourceService = get(ResourceQueryService.class); if (typeStrings != null) { typesToPrint = new HashSet<>(Arrays.asList(typeStrings)); } else { typesToPrint = Collections.emptySet(); } if (deviceIdStr != null && portNumberStr != null) { DeviceId deviceId = deviceId(deviceIdStr); PortNumber portNumber = PortNumber.fromString(portNumberStr); printResource(Resources.discrete(deviceId, portNumber).resource(), 0); } else if (deviceIdStr != null) { DeviceId deviceId = deviceId(deviceIdStr); printResource(Resources.discrete(deviceId).resource(), 0); } else { printResource(Resource.ROOT, 0); } }
@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); } }
portNumber = PortNumber.fromString(portNumberStr);