Java Code Examples for org.onosproject.net.PortNumber#fromString()
The following examples show how to use
org.onosproject.net.PortNumber#fromString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DevicePortStateCommand.java From onos with Apache License 2.0 | 6 votes |
@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(), p.number(), true); } else if ("disable".equals(portState)) { deviceAdminService.changePortState(dev.id(), p.number(), false); } else { print(" %s", "State must be enable or disable"); } }
Example 2
Source File: TestAllocateResource.java From onos with Apache License 2.0 | 6 votes |
@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); } }
Example 3
Source File: TestProtectionEndpointIntentCommand.java From onos with Apache License 2.0 | 6 votes |
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); } }
Example 4
Source File: DecodeInstructionCodecHelper.java From onos with Apache License 2.0 | 6 votes |
/** * 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; }
Example 5
Source File: PortProtoTranslator.java From onos with Apache License 2.0 | 5 votes |
/** * Translates gRPC PortDescription message to {@link PortDescription}. * * @param portDescription gRPC message * @return {@link PortDescription} */ public static PortDescription translate(PortDescriptionProto portDescription) { PortNumber number = PortNumber.fromString(portDescription.getPortNumber()); boolean isEnabled = portDescription.getIsEnabled(); Port.Type type = translate(portDescription.getType()).get(); long portSpeed = portDescription.getPortSpeed(); SparseAnnotations annotations = AnnotationsTranslator.asAnnotations(portDescription.getAnnotationsMap()); // TODO How to deal with more specific Port... return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled) .type(type).portSpeed(portSpeed).annotations(annotations) .build(); }
Example 6
Source File: XconnectPortEndpoint.java From onos with Apache License 2.0 | 2 votes |
/** * Gets XconnectPortEndpoint from string. * * @param s string * @return XconnectPortEndpoint */ public static XconnectPortEndpoint fromString(String s) { checkArgument(s.matches(PORT_PATTERN), "String {} does not match {} format", s, PORT_PATTERN); return new XconnectPortEndpoint(PortNumber.fromString(s)); }