private String portName(PortNumber port) { return port.equals(PortNumber.LOCAL) ? PORT_NAME_LOCAL : port.toString(); }
@Override public String toString() { return MoreObjects.toStringHelper(getClass()) .omitNullValues() .add("DeviceId", deviceId.toString()) .add("InLabelId", inLabelId.toString()) .add("OutLabelId", outLabelId.toString()) .add("InPort", inPort.toString()) .add("OutPort", outPort.toString()) .toString(); }
private String portName(PortNumber port) { return port.equals(PortNumber.LOCAL) ? "local" : port.toString(); }
@Override public ObjectNode encode(HostLocation hostLocation, CodecContext context) { checkNotNull(hostLocation, "Host location cannot be null"); return context.mapper().createObjectNode() .put("elementId", hostLocation.elementId().toString()) .put("port", hostLocation.port().toString()); }
@Override protected List<String> choices() { DeviceId deviceId = lookForDeviceId(); if (deviceId == null) { return Collections.emptyList(); } DeviceService deviceService = getService(DeviceService.class); return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false) .map(port -> port.number().toString()) .collect(Collectors.toList()); }
private static PortNumber logicalToPipelineSpecific( PortNumber logicalPort, Device device) throws PiTranslationException { if (!device.is(PiPipelineInterpreter.class)) { throw new PiTranslationException( "missing interpreter, cannot map logical port " + logicalPort.toString()); } final PiPipelineInterpreter interpreter = device.as(PiPipelineInterpreter.class); Optional<Integer> mappedPort = interpreter.mapLogicalPortNumber(logicalPort); if (!mappedPort.isPresent()) { throw new PiTranslationException( "interpreter cannot map logical port " + logicalPort.toString()); } return PortNumber.portNumber(mappedPort.get()); } }
@Override public ObjectNode encode(ConnectPoint point, CodecContext context) { checkNotNull(point, "Connect point cannot be null"); ObjectNode root = context.mapper().createObjectNode() .put(PORT, point.port().toString()); if (point.elementId() instanceof DeviceId) { root.put(ELEMENT_DEVICE, point.deviceId().toString()); } else if (point.elementId() instanceof HostId) { root.put(ELEMENT_HOST, point.hostId().toString()); } return root; }
/** * Adds a BGP speaker to the configuration. * * @param speaker the BGP speaker configuration entry */ public void addSpeaker(BgpSpeakerConfig speaker) { // Create the new speaker node and set the parameters ObjectNode speakerNode = JsonNodeFactory.instance.objectNode(); speakerNode.put(NAME, speaker.name().get()); speakerNode.put(VLAN, speaker.vlan().toString()); speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() + "/" + speaker.connectPoint().port().toString()); ArrayNode peersNode = speakerNode.putArray(PEERS); for (IpAddress peerAddress: speaker.peers()) { peersNode.add(peerAddress.toString()); } // Add the new BGP speaker to the existing node array ArrayNode speakersArray = bgpSpeakers().isEmpty() ? initBgpSpeakersConfiguration() : (ArrayNode) object.get(SPEAKERS); speakersArray.add(speakerNode); }
/** * 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; }
@Override public ObjectNode encode(GroupBucket bucket, CodecContext context) { checkNotNull(bucket, "Driver cannot be null"); ObjectNode result = context.mapper().createObjectNode() .put(TYPE, bucket.type().toString()) .put(WEIGHT, bucket.weight()) .put(PACKETS, bucket.packets()) .put(BYTES, bucket.bytes()) .put(BUCKET_ID, bucket.hashCode()); if (bucket.watchPort() != null) { result.put(WATCH_PORT, bucket.watchPort().toString()); } if (bucket.watchGroup() != null) { result.put(WATCH_GROUP, bucket.watchGroup().toString()); } if (bucket.treatment() != null) { result.set(TREATMENT, context.codec(TrafficTreatment.class).encode(bucket.treatment(), context)); } return result; }
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); } } }
final Instructions.OutputInstruction outputInstruction = (Instructions.OutputInstruction) instruction; result.put(InstructionCodec.PORT, outputInstruction.port().toString()); break; result.put(InstructionCodec.QUEUE_ID, setQueueInstruction.queueId()); if (setQueueInstruction.port() != null) { result.put(InstructionCodec.PORT, setQueueInstruction.port().toString());
continue; String portName = port.number().toString(); String portIsEnabled = port.isEnabled() ? "enabled" : "disabled"; String portType = port.type().toString().toLowerCase();