@Override public Annotations decode(ObjectNode json, CodecContext context) { Builder builder = DefaultAnnotations.builder(); json.fields().forEachRemaining(e -> builder.set(e.getKey(), e.getValue().asText())); return builder.build(); } }
private Path createPath(List<PcepHopNodeDescription> hopList, PathType pathtype, PathState pathState) { if (hopList == null || hopList.size() == 0) { return null; } List<Link> links = new ArrayList<>(); for (int i = 1; i < hopList.size() - 1; i = i + 2) { links.add(link(hopList.get(i).getDeviceId(), hopList.get(i) .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList .get(i + 1).getPortNum())); } int hopNum = hopList.size() - 2; DefaultAnnotations extendAnnotations = DefaultAnnotations.builder() .set("pathNum", String.valueOf(hopNum)) .set("pathState", String.valueOf(pathState)) .set("pathType", String.valueOf(pathtype)).build(); return new DefaultPath(id(), links, hopNum, extendAnnotations); }
private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) { SparseAnnotations annotations = null; String portName = Strings.emptyToNull(port.getName()); if (portName != null) { annotations = DefaultAnnotations.builder() .set(AnnotationKeys.PORT_NAME, portName) .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build(); } return annotations; }
/** * Builds the annotation details. * * @param annotationBuilder default annotation builder instance * @param isisLink ISIS link instance * @return annotation builder instance */ private DefaultAnnotations.Builder buildAnnotations(DefaultAnnotations.Builder annotationBuilder, IsisLink isisLink) { int administrativeGroup = 0; long teMetric = 0; Bandwidth maxReservableBandwidth = Bandwidth.bps(0); String routerId = null; String neighborId = null; //TE Info IsisLinkTed isisLinkTed = isisLink.linkTed(); log.info("Ted Information: {}", isisLinkTed.toString()); administrativeGroup = isisLinkTed.administrativeGroup(); teMetric = isisLinkTed.teDefaultMetric(); maxReservableBandwidth = isisLinkTed.maximumReservableLinkBandwidth(); routerId = isisLink.localSystemId(); neighborId = isisLink.remoteSystemId(); annotationBuilder.set(ADMINISTRATIVEGROUP, String.valueOf(administrativeGroup)); annotationBuilder.set(TE_METRIC, String.valueOf(teMetric)); annotationBuilder.set(MAXRESERVABLEBANDWIDTH, String.valueOf(maxReservableBandwidth)); annotationBuilder.set(ROUTERID, String.valueOf(routerId)); annotationBuilder.set(NEIGHBORID, String.valueOf(neighborId)); return annotationBuilder; }
/** * Generates an annotation from an existing annotation and LinkConfig. * * @param cfg the link config entity from network config * @param an the annotation * @return annotation combining both sources */ public static SparseAnnotations combine(BasicLinkConfig cfg, SparseAnnotations an) { DefaultAnnotations.Builder b = DefaultAnnotations.builder(); b.putAll(an); if (cfg.metric() != DEF_METRIC) { b.set(AnnotationKeys.METRIC, String.valueOf(cfg.metric())); } if (!cfg.latency().equals(DEF_DURATION)) { //Convert the latency from Duration to long, //so that it's computable in the latencyConstraint. b.set(AnnotationKeys.LATENCY, String.valueOf(cfg.latency().toNanos())); } if (cfg.bandwidth() != DEF_BANDWIDTH) { b.set(AnnotationKeys.BANDWIDTH, String.valueOf(cfg.bandwidth())); } if (cfg.isDurable() != null) { b.set(AnnotationKeys.DURABLE, String.valueOf(cfg.isDurable())); } return b.build(); }
/** * Creates ODU client port description based on the supplied information. * * @param number port number * @param isEnabled port enabled state * @param signalType ODU client signal type * @param annotations key/value annotations map * @return port description */ public static PortDescription oduCltPortDescription(PortNumber number, boolean isEnabled, CltSignalType signalType, SparseAnnotations annotations) { Builder builder = DefaultAnnotations.builder(); builder.putAll(annotations); builder.set(SIGNAL_TYPE, signalType.toString()); long portSpeed = signalType.bitRate(); return DefaultPortDescription.builder() .withPortNumber(number) .isEnabled(isEnabled) .type(Port.Type.ODUCLT) .portSpeed(portSpeed) .annotations(builder.build()) .build(); }
/** * Creates OTU port description based on the supplied information. * * @param number port number * @param isEnabled port enabled state * @param signalType OTU client signal type * @param annotations key/value annotations map * @return port description */ public static PortDescription otuPortDescription(PortNumber number, boolean isEnabled, OtuSignalType signalType, SparseAnnotations annotations) { Builder builder = DefaultAnnotations.builder(); builder.putAll(annotations); builder.set(SIGNAL_TYPE, signalType.toString()); long portSpeed = 0; // TODO specify appropriate value? return DefaultPortDescription.builder() .withPortNumber(number) .isEnabled(isEnabled) .type(Port.Type.OTU) .portSpeed(portSpeed) .annotations(builder.build()) .build(); }
@Override public void routerAdded(OspfRouter ospfRouter) { String routerId = ospfRouter.routerIp().toString(); log.info("Added device {}", routerId); DeviceId deviceId = DeviceId.deviceId(OspfRouterId.uri(ospfRouter.routerIp())); Device.Type deviceType = Device.Type.ROUTER; //If our routerType is Dr or Bdr type is PSEUDO if (ospfRouter.isDr()) { deviceType = Device.Type.ROUTER; } else { deviceType = Device.Type.VIRTUAL; } //deviceId = DeviceId.deviceId(routerDetails); ChassisId cId = new ChassisId(); DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); newBuilder.set(AnnotationKeys.TYPE, "l3"); newBuilder.set("routerId", routerId); DeviceDescription description = new DefaultDeviceDescription(OspfRouterId.uri(ospfRouter.routerIp()), deviceType, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); deviceProviderService.deviceConnected(deviceId, description); }
/** * Creates or update tunnel in the controller device. * * @param handler DriverHandler * @param srcIp the ipAddress of the local controller device * @param dstIp the ipAddress of the remote controller device */ public static void applyTunnelConfig(DriverHandler handler, IpAddress srcIp, IpAddress dstIp) { DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); } TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(srcIp); TunnelDescription tunnel = new DefaultTunnelDescription( tunnelAsSrc, null, TunnelDescription.Type.VXLAN, TunnelName.tunnelName(DEFAULT_TUNNEL), optionBuilder.build()); tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), tunnel); }
@Override public void routerAdded(IsisRouter isisRouter) { String systemId = isisRouter.systemId(); log.info("Added device {}", systemId); DeviceId deviceId = DeviceId.deviceId(IsisRouterId.uri(systemId)); Device.Type deviceType = Device.Type.ROUTER; //If our routerType is Dr or Bdr type is PSEUDO if (isisRouter.isDis()) { deviceType = Device.Type.ROUTER; } else { deviceType = Device.Type.VIRTUAL; } ChassisId cId = new ChassisId(); DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder(); newBuilder.set(AnnotationKeys.TYPE, "L3"); newBuilder.set("RouterId", systemId); DeviceDescription description = new DefaultDeviceDescription(IsisRouterId.uri(systemId), deviceType, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build()); deviceProviderService.deviceConnected(deviceId, description); System.out.println("Device added: " + systemId); }
/** * Generates an annotation from an existing annotation and OptcalPortConfig. * * @param opc the port config entity from network config * @param an the annotation * @return annotation combining both sources */ private static SparseAnnotations combine(OpticalPortConfig opc, SparseAnnotations an) { DefaultAnnotations.Builder b = DefaultAnnotations.builder(); b.putAll(an); if (!opc.staticPort().isEmpty()) { b.set(AnnotationKeys.STATIC_PORT, opc.staticPort()); } if (opc.staticLambda().isPresent()) { b.set(AnnotationKeys.STATIC_LAMBDA, String.valueOf(opc.staticLambda().get())); } // The following may not need to be carried. if (!opc.name().isEmpty()) { b.set(AnnotationKeys.PORT_NAME, opc.name()); } return b.build(); }
private void deviceAdded(RestSBDevice nodeId) { Preconditions.checkNotNull(nodeId, ISNOTNULL); DeviceId deviceId = nodeId.deviceId(); ChassisId cid = new ChassisId(); String ipAddress = nodeId.ip().toString(); SparseAnnotations annotations = DefaultAnnotations.builder() .set(IPADDRESS, ipAddress) .set(AnnotationKeys.PROTOCOL, REST.toUpperCase()) .build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( deviceId.uri(), Device.Type.SWITCH, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); nodeId.setActive(true); providerService.deviceConnected(deviceId, deviceDescription); addedDevices.add(deviceId); }
/** * Generates an annotation from an existing annotation and DeviceConfig. * * @param cfg the device config entity from network config * @param an the annotation * @return annotation combining both sources */ public static SparseAnnotations combine(BasicDeviceConfig cfg, SparseAnnotations an) { DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); builder.putAll(an); if (!Objects.equals(cfg.driver(), an.value(AnnotationKeys.DRIVER))) { builder.set(AnnotationKeys.DRIVER, cfg.driver()); } combineElementAnnotations(cfg, builder); if (cfg.managementAddress() != null) { builder.set(AnnotationKeys.MANAGEMENT_ADDRESS, cfg.managementAddress()); } return builder.build(); }
private SparseAnnotations getAnnotations(PcepLspObject lspObj, StatefulIPv4LspIdentifiersTlv ipv4LspIdenTlv, float bandwidth, LspType lspType, String costType) { Builder builder = DefaultAnnotations.builder(); /* * [RFC 5440] The absence of the METRIC object MUST be interpreted by the PCE as a path computation request * for which no constraints need be applied to any of the metrics. */ if (costType != null) { builder.set(COST_TYPE, costType); } SparseAnnotations annotations = builder .set(BANDWIDTH, (new Float(bandwidth)).toString()).set(LSP_SIG_TYPE, lspType.name()) .set(PCC_TUNNEL_ID, String.valueOf(ipv4LspIdenTlv.getTunnelId())) .set(PLSP_ID, String.valueOf(lspObj.getPlspId())) .set(LOCAL_LSP_ID, String.valueOf(ipv4LspIdenTlv.getLspId())) .set(DELEGATE, String.valueOf(lspObj.getDFlag())) .build(); return annotations; }
/** * Creates an annotation for the port name if one is available. * * @param portName the port name * @param portMac the port mac * @return annotation containing the port name if one is found, * null otherwise */ private SparseAnnotations makePortAnnotation(String portName, String portMac) { SparseAnnotations annotations = null; String pName = Strings.emptyToNull(portName); String pMac = Strings.emptyToNull(portMac); if (portName != null) { annotations = DefaultAnnotations.builder() .set(AnnotationKeys.PORT_NAME, pName) .set(AnnotationKeys.PORT_MAC, pMac).build(); } return annotations; }
@Override public void nodeAdded(OvsdbNodeId nodeId) { checkNotNull(nodeId, ISNOTNULL); DeviceId deviceId = DeviceId.deviceId(nodeId.toString()); URI uri = URI.create(nodeId.toString()); ChassisId cid = new ChassisId(); String ipAddress = nodeId.getIpAddress(); SparseAnnotations annotations = DefaultAnnotations.builder() .set("ipaddress", ipAddress).build(); DeviceDescription deviceDescription = new DefaultDeviceDescription( uri, Device.Type.CONTROLLER, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cid, annotations); providerService.deviceConnected(deviceId, deviceDescription); }
private ControllerInfo parseCInfoString(String cInfoString) { Annotations annotation; String[] config = cInfoString.split(","); if (config.length == 2) { String[] pair = config[1].split("="); if (pair.length == 2) { annotation = DefaultAnnotations.builder() .set(pair[0], pair[1]).build(); } else { print("Wrong format {}", config[1]); return null; } return getControllerInfo(annotation, config[0]); } else { return getControllerInfo(null, config[0]); } }
private LinkDescription description(Link link, String key, String value) { checkNotNull(key, "Key cannot be null"); DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); if (value != null) { builder.set(key, value); } else { builder.remove(key); } return new DefaultLinkDescription(link.src(), link.dst(), link.type(), link.isExpected(), builder.build()); }
private Annotations genAnnots(BasicRegionConfig cfg, RegionId rid) { DefaultAnnotations.Builder builder = DefaultAnnotations.builder() .set(BasicElementConfig.NAME, cfg.name()) .set(BasicElementConfig.LATITUDE, dstr(cfg.latitude())) .set(BasicElementConfig.LONGITUDE, dstr(cfg.longitude())); // only set the UI_TYPE annotation if it is not null in the config String uiType = cfg.uiType(); if (uiType != null) { builder.set(BasicElementConfig.UI_TYPE, uiType); } List<LayoutLocation> locMappings = cfg.getMappings(); builder.set(PEER_LOCATIONS, toCompactListString(locMappings)); return builder.build(); }
@Override public DefaultAnnotations read(Kryo kryo, Input input, Class<DefaultAnnotations> type) { DefaultAnnotations.Builder b = DefaultAnnotations.builder(); Map<String, String> map = kryo.readObject(input, HashMap.class, MAP_SERIALIZER); map.forEach((k, v) -> b.set(k, v)); return b.build(); }