/** * Combines connect point with vlan id with separator ':' as circuit id. * e.g. of:0000000000000204/1:100 * * @return serialized circuit id for connect point and vlan ID */ public byte[] serialize() { return String .format(CIRCUIT_ID_FORMAT, connectPoint, vlanId.toString()) .getBytes(StandardCharsets.US_ASCII); }
private void printInterface(DeviceInterfaceDescription intf) { StringBuilder formatStringBuilder = new StringBuilder(FORMAT); if (intf.mode().equals(DeviceInterfaceDescription.Mode.ACCESS)) { formatStringBuilder.append(MODE_FORMAT) .append(ACCESS_MODE) .append(VLAN_FORMAT); formatStringBuilder.append(intf.vlans().get(0).toString()); } else if (intf.mode().equals(DeviceInterfaceDescription.Mode.TRUNK)) { formatStringBuilder.append(MODE_FORMAT) .append(TRUNK_MODE) .append(VLAN_FORMAT); for (int i = 0; i < intf.vlans().size(); i++) { formatStringBuilder.append(intf.vlans().get(i)); if (i != intf.vlans().size() - 1) { formatStringBuilder.append(","); } } } if (intf.isRateLimited()) { formatStringBuilder.append(LIMIT_FORMAT); formatStringBuilder.append(intf.rateLimit()); formatStringBuilder.append(PERCENT); } print(formatStringBuilder.toString(), intf.name()); } }
/** * 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); }
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode() .put("id", host.id().toString()) .put("mac", host.mac().toString()) .put("vlan", host.vlan().toString()) .put("innerVlan", host.innerVlan().toString()) .put("outerTpid", host.tpid().toString()) .put("configured", host.configured()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); final ArrayNode jsonLocations = result.putArray("locations"); for (final HostLocation location : host.locations()) { jsonLocations.add(locationCodec.encode(location, context)); } result.set("locations", jsonLocations); return annotate(result, host, context); }