Example #1
0
 // Parses the given node with port information.
 private PortDescription parsePort(JsonNode node) {
   Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER"));
   return new DefaultPortDescription(
       portNumber(node.path("port").asLong(0)),
       node.path("enabled").asBoolean(true),
       type,
       node.path("speed").asLong(1_000));
 }
Example #2
0
  // Parses the given node with port information.
  private PortDescription parsePort(DeviceId deviceId, JsonNode node) {
    Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER"));
    // TL1-based ports have a name
    PortNumber port = null;
    if (node.has("name")) {
      for (Port p : deviceService.getPorts(deviceId)) {
        if (p.number().name().equals(node.get("name").asText())) {
          port = p.number();
          break;
        }
      }
    } else {
      port = portNumber(node.path("port").asLong(0));
    }

    if (port == null) {
      log.error("Cannot find port given in node {}", node);
      return null;
    }

    String portName = Strings.emptyToNull(port.name());
    SparseAnnotations annotations = null;
    if (portName != null) {
      annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portName).build();
    }
    switch (type) {
      case COPPER:
        return new DefaultPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            type,
            node.path("speed").asLong(1_000),
            annotations);
      case FIBER:
        // Currently, assume OMS when FIBER. Provide sane defaults.
        annotations = annotations(node.get("annotations"));
        return new OmsPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            CENTER,
            CENTER.add(TOTAL),
            Frequency.ofGHz(100),
            annotations);
      case ODUCLT:
        annotations = annotations(node.get("annotations"));
        OduCltPort oduCltPort = (OduCltPort) deviceService.getPort(deviceId, port);
        return new OduCltPortDescription(
            port, node.path("enabled").asBoolean(true), oduCltPort.signalType(), annotations);
      case OCH:
        annotations = annotations(node.get("annotations"));
        OchPort ochPort = (OchPort) deviceService.getPort(deviceId, port);
        return new OchPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            ochPort.signalType(),
            ochPort.isTunable(),
            ochPort.lambda(),
            annotations);
      case OMS:
        annotations = annotations(node.get("annotations"));
        OmsPort omsPort = (OmsPort) deviceService.getPort(deviceId, port);
        return new OmsPortDescription(
            port,
            node.path("enabled").asBoolean(true),
            omsPort.minFrequency(),
            omsPort.maxFrequency(),
            omsPort.grid(),
            annotations);
      default:
        log.warn("{}: Unsupported Port Type");
    }
    return new DefaultPortDescription(
        port,
        node.path("enabled").asBoolean(true),
        type,
        node.path("speed").asLong(1_000),
        annotations);
  }