Java Code Examples for org.onosproject.net.device.DeviceService#getPort()

The following examples show how to use org.onosproject.net.device.DeviceService#getPort() . 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: RoadmUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
public static OchSignal createOchSignalFromWavelength(double wavelength, DeviceService deviceService,
                                                      DeviceId deviceId, PortNumber portNumber) {
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(deviceId, portNumber);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);

    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultiplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        return null;
    }

}
 
Example 2
Source File: PortWaveLengthCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private OchSignal createOchSignalFromWavelength(DeviceService deviceService, ConnectPoint cp) {
    long wavelength = Long.parseLong(parameter);
    if (wavelength == 0L) {
        return null;
    }
    Port port = deviceService.getPort(cp);
    Optional<OchPort> ochPortOpt = OchPortHelper.asOchPort(port);

    if (ochPortOpt.isPresent()) {
        OchPort ochPort = ochPortOpt.get();
        GridType gridType = ochPort.lambda().gridType();
        ChannelSpacing channelSpacing = ochPort.lambda().channelSpacing();
        int slotGranularity = ochPort.lambda().slotGranularity();
        int multiplier = getMultplier(wavelength, gridType, channelSpacing);
        return new OchSignal(gridType, channelSpacing, multiplier, slotGranularity);
    } else {
        print("Connect point %s is not OChPort", cp);
        return null;
    }

}
 
Example 3
Source File: OFOpticalSwitch13LambdaQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);

    // Only OMS ports expose lambda resources
    if (p == null || !p.type().equals(Port.Type.OMS)) {
        return Collections.emptySet();
    }

    short lambdaCount = ((OmsPort) p).totalChannels();
    // OMS ports expose 'lambdaCount' fixed grid lambdas of 50GHz width, starting from min-frequency 191.7 THz.
    return IntStream.rangeClosed(1, lambdaCount)
            .mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x))
            .collect(GuavaCollectors.toImmutableSet());
}
 
Example 4
Source File: DefaultTributarySlotQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<TributarySlot> queryTributarySlots(PortNumber port) {
    // currently return all slots by default.
    DeviceService deviceService = opticalView(this.handler().get(DeviceService.class));
    Port p = deviceService.getPort(this.data().deviceId(), port);

    if (p == null) {
        return Collections.emptySet();
    }

    switch (p.type()) {
        case OCH:
            return queryOchTributarySlots(p);
        case OTU:
            return queryOtuTributarySlots(p);
        default:
            return Collections.emptySet();
    }
}
 
Example 5
Source File: OplinkPowerConfigUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Find specified port power from port description.
 *
 * @param portNum the port number
 * @param annotation annotation in port description
 * @return power value in 0.01 dBm
 */
private Long getPortPower(PortNumber portNum, String annotation) {
    // Check if switch is connected, otherwise do not return value in store, which is obsolete.
    if (getOpenFlowDevice() == null) {
        // Warning already exists in method getOpenFlowDevice()
        return null;
    }
    final DriverHandler handler = behaviour.handler();
    DeviceService deviceService = handler.get(DeviceService.class);
    Port port = deviceService.getPort(handler.data().deviceId(), portNum);
    if (port == null) {
        log.warn("Unexpected port: {}", portNum);
        return null;
    }
    String power = port.annotations().value(annotation);
    if (power == null) {
        // Do not need warning here for port polling.
        log.debug("Cannot get {} from port {}.", annotation, portNum);
        return null;
    }
    return Long.valueOf(power);
}
 
Example 6
Source File: OplinkHandshakerUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
private boolean linkValidation(DeviceService deviceService, OplinkPortAdjacency neighbor) {
    // check neighbor object
    if (neighbor == null) {
        return false;
    }
    // check src device is validate or not
    if (!deviceService.isAvailable(neighbor.getDeviceId())) {
        log.debug("Invalid adjacency device. devId = {}", neighbor.getDeviceId());
        return false;
    }
    // check src port is validate or not
    if (deviceService.getPort(neighbor.getDeviceId(), neighbor.getPort()) == null) {
        log.debug("Invalid adjacency port. devId = {}, port = {}",
                  neighbor.getDeviceId(), neighbor.getPort());
        return false;
    }
    // validate link
    return true;
}
 
Example 7
Source File: CzechLightLambdaQuery.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber portNumber) {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Port port = deviceService.getPort(data().deviceId(), portNumber);

    if ((port.type() == Port.Type.FIBER) || (port.type() == Port.Type.OMS)) {
        final int startMultiplier50 = (int) (START_CENTER_FREQ_50.subtract(Spectrum.CENTER_FREQUENCY).asHz()
                / Frequency.ofGHz(50).asHz());
        final int endMultiplier50 = (int) (END_CENTER_FREQ_50.subtract(Spectrum.CENTER_FREQUENCY).asHz()
                / Frequency.ofGHz(50).asHz());
        return IntStream.range(startMultiplier50, endMultiplier50 + 1)
                .mapToObj(x -> OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, x))
                .collect(Collectors.toSet());
    } else {
        return Collections.emptySet();
    }
}
 
Example 8
Source File: BitErrorCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() throws Exception {
    DeviceService deviceService = get(DeviceService.class);
    ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPoint);
    Port port = deviceService.getPort(cp);
    if (port == null) {
        print("[ERROR] %s does not exist", cp);
        return;
    }

    Device device = deviceService.getDevice(cp.deviceId());
    BitErrorRateState bitErrorRateState = device.as(BitErrorRateState.class);
    Optional<Double> preFecBerVal = bitErrorRateState.getPreFecBer(cp.deviceId(), cp.port());
    if (preFecBerVal.isPresent()) {
        double preFecBer = preFecBerVal.orElse(Double.MIN_VALUE);
        print("The pre-fec-ber value in port %s on device %s is %f.",
              cp.port().toString(), cp.deviceId().toString(), preFecBer);
    }
    Optional<Double> postFecBerVal = bitErrorRateState.getPostFecBer(cp.deviceId(), cp.port());
    if (postFecBerVal.isPresent()) {
        double postFecBer = postFecBerVal.orElse(Double.MIN_VALUE);
        print("The post-fec-ber value in port %s on device %s is %f.",
              cp.port().toString(), cp.deviceId().toString(), postFecBer);
    }
}
 
Example 9
Source File: DevicePortStateCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@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 10
Source File: ServiceApplicationComponent.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new optical intent created from the method parameters.
 *
 * @param ingress ingress description (device/port)
 * @param egress egress description (device/port)
 * @param key intent key
 * @param appId application id. As per Intent class, it cannot be null
 *
 * @return created intent
 */
protected Intent createOpticalIntent(ConnectPoint ingress, ConnectPoint egress,
                                     Key key, ApplicationId appId) {

    if (ingress == null || egress == null) {
        log.error("Invalid endpoint(s) for optical intent: ingress {}, egress {}",
            ingress, egress);
        return null;
    }
    DeviceService ds = opticalView(deviceService);
    Port srcPort = ds.getPort(ingress.deviceId(), ingress.port());
    Port dstPort = ds.getPort(egress.deviceId(), egress.port());
    if (srcPort == null || dstPort == null) {
        log.error("Invalid port(s) for optical intent: src {}, dst {}",
            srcPort, dstPort);
        return null;
    }

    OduSignalType signalType = ((OchPort) srcPort).signalType();
    return OpticalConnectivityIntent.builder()
        .appId(appId)
        .key(key)
        .src(ingress)
        .dst(egress)
        .signalType(signalType)
        .bidirectional(true) //TODO Revisit this.
        .build();
}
 
Example 11
Source File: PortViewMessageHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(ObjectNode payload) {
    String id = string(payload, ID);
    String devId = string(payload, DEV_ID);

    DeviceService deviceService = get(DeviceService.class);
    Port port = deviceService.getPort(deviceId(devId), portNumber(id));

    ObjectNode data = objectNode();

    data.put(ID, id);
    data.put(DEV_ID, devId);
    data.put(TYPE, displayType(port.type()));
    data.put(SPEED, displaySpeed(port.portSpeed()));
    data.put(ENABLED, port.isEnabled());

    data.put(TYPE_IID, getIconIdForPortType(port.type()));

    ObjectNode rootNode = objectNode();
    rootNode.set(DETAILS, data);

    // NOTE: ... an alternate way of getting all the details of an item:
    // Use the codec context to get a JSON of the port. See ONOS-5976.
    rootNode.set(PORT, getJsonCodecContext().encode(port, Port.class));

    sendMessage(PORT_DETAILS_RESP, rootNode);
}
 
Example 12
Source File: AnnotatePortCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netcfgService = get(NetworkConfigService.class);


    ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(port);
    if (deviceService.getPort(connectPoint) == null) {
        print("Port %s does not exist.", port);
        return;
    }

    if (removeCfg && key == null) {
        // remove whole port annotation config
        netcfgService.removeConfig(connectPoint, PortAnnotationConfig.class);
        print("Annotation Config about %s removed", connectPoint);
        return;
    }

    if (key == null) {
        print("[ERROR] Annotation key not specified.");
        return;
    }

    PortAnnotationConfig cfg = netcfgService.addConfig(connectPoint, PortAnnotationConfig.class);
    if (removeCfg) {
        // remove config about entry
        cfg.annotation(key);
    } else {
        // add remove request config
        cfg.annotation(key, value);
    }
    cfg.apply();
}
 
Example 13
Source File: PortQueryVlansCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService service = get(DeviceService.class);
    for (String portStr : ports) {
        ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(portStr);
        Port port = service.getPort(connectPoint.deviceId(), connectPoint.port());
        printPort(port);
        printVlans(port);
    }
}
 
Example 14
Source File: ConfigureLinkCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    NetworkConfigService netCfgService = get(NetworkConfigService.class);

    ConnectPoint srcCp = ConnectPoint.deviceConnectPoint(src);
    if (deviceService.getPort(srcCp) == null) {
        print("[ERROR] %s does not exist", srcCp);
        return;
    }

    ConnectPoint dstCp = ConnectPoint.deviceConnectPoint(dst);
    if (deviceService.getPort(dstCp) == null) {
        print("[ERROR] %s does not exist", dstCp);
        return;
    }

    LinkKey link = linkKey(srcCp, dstCp);
    if (remove) {
        netCfgService.removeConfig(link, BasicLinkConfig.class);
        return;
    }

    Long bw = Optional.ofNullable(bandwidth)
                    .map(Long::valueOf)
                    .orElse(null);

    Link.Type linkType = Link.Type.valueOf(type);

    BasicLinkConfig cfg = netCfgService.addConfig(link, BasicLinkConfig.class);
    cfg.isAllowed(!disallow);
    cfg.isBidirectional(!isUniDi);
    cfg.type(linkType);
    if (bw != null) {
        cfg.bandwidth(bw);
    }

    cfg.apply();
}
 
Example 15
Source File: LumentumRoadmLambdaQuery.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber portNumber) {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Port port = deviceService.getPort(data().deviceId(), portNumber);

    if ((port.type() == Port.Type.FIBER) || (port.type() == Port.Type.OMS)) {

        //Complete set of 50GHz OchSignal
        int startMultiplier50 = (int) (START_CENTER_FREQ_50.subtract(Spectrum.CENTER_FREQUENCY).asHz()
                / Frequency.ofGHz(50).asHz());

        Set<OchSignal> channels50 = IntStream.range(0, LAMBDA_COUNT_50)
                .mapToObj(x -> new OchSignal(GRID_TYPE, CHANNEL_SPACING_50,
                        startMultiplier50 + x,
                        4))
                .collect(Collectors.toSet());

    /*//Complete set of 100GHz OchSignal
    int startMultiplier100 = (int) (START_CENTER_FREQ_100.subtract(Spectrum.CENTER_FREQUENCY).asHz()
            / Frequency.ofGHz(100).asHz());

    Set<OchSignal> channels100 = IntStream.range(0, LAMBDA_COUNT_100)
            .mapToObj(x -> new OchSignal(GRID_TYPE,
                    CHANNEL_SPACING_100, startMultiplier100 + x, 8))
            .collect(Collectors.toSet());

    Set<OchSignal> channels = Sets.union(channels50, channels100);*/

        return channels50;
    } else {
        return Collections.emptySet();
    }
}
 
Example 16
Source File: CassiniBitErrorRateState.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected String ocName(DeviceId deviceId, PortNumber port) {
    DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
    if (deviceService.getPort(deviceId, port) == null) {
        throw new IllegalArgumentException(PORT_NOT_PRESENT);
    }
    return deviceService.getPort(deviceId, port).annotations().value(OC_NAME);
}
 
Example 17
Source File: TapiDeviceLambdaQuery.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Set<OchSignal> queryLambdas(PortNumber port) {
    RestSBController controller = checkNotNull(handler().get(RestSBController.class));
    DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
    DeviceId deviceId = did();
    Device dev = deviceService.getDevice(deviceId);
    if (dev == null) {
        log.error("Device {} does not exist", deviceId);
        return ImmutableSet.of();
    }
    Port p = deviceService.getPort(dev.id(), port);
    if (p == null) {
        log.error("Port {} does not exist", port);
        return ImmutableSet.of();
    }
    String uuid = p.annotations().value(UUID);

    try {
        InputStream inputStream = controller.get(deviceId, SIP_REQUEST_DATA_API + uuid,
                MediaType.APPLICATION_JSON_TYPE);
        log.debug("Service interface point UUID: {}", uuid);
        JsonNode sipAttributes = new ObjectMapper().readTree(inputStream);
        JsonNode mcPool = sipAttributes.get(MEDIA_CHANNEL_SERVICE_INTERFACE_POINT_SPEC).get(MC_POOL);

        //This creates a hashset of OChSignals representing the spectrum availability at the target port.
        return TapiDeviceHelper.getOchSignal(mcPool);

    } catch (IOException e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableSet.of();
    }
}
 
Example 18
Source File: OpenRoadmFlowRuleProgrammable.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a connection name given an OpenRoadmFlowRule.
 *
 * @param xc the flow rule or crossconnection.
 *
 */
private String openRoadmConnectionName(OpenRoadmFlowRule xc) {
    DeviceService deviceService = this.handler().get(DeviceService.class);
    Port srcPort = deviceService.getPort(did(), xc.inPort());
    Port dstPort = deviceService.getPort(did(), xc.outPort());
    Frequency centerFreq = xc.ochSignal().centralFrequency();
    return openRoadmConnectionName(srcPort, dstPort, centerFreq);
}
 
Example 19
Source File: PowerConfigCommand.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected void doExecute() throws Exception {
    DeviceService deviceService = get(DeviceService.class);
    ConnectPoint cp = ConnectPoint.deviceConnectPoint(connectPoint);
    Port port = deviceService.getPort(cp);
    if (port == null) {
        print("[ERROR] %s does not exist", cp);
        return;
    }
    if (!port.type().equals(Port.Type.OCH) &&
            !port.type().equals(Port.Type.OTU) &&
            !port.type().equals(Port.Type.OMS)) {
        log.warn("The power of selected port %s isn't editable.", port.number().toString());
        print("The power of selected port %s isn't editable.", port.number().toString());
        return;
    }
    Device device = deviceService.getDevice(cp.deviceId());
    PowerConfig powerConfig = device.as(PowerConfig.class);
    // FIXME the parameter "component" equals NULL now, because there is one-to-one mapping between
    //  <component> and <optical-channel>.
    if (operation.equals("get")) {
        Optional<Double> val = powerConfig.getTargetPower(cp.port(), Direction.ALL);
        if (val.isPresent()) {
            double power = val.orElse(Double.MIN_VALUE);
            print("The target-output-power value in port %s on device %s is %f.",
                    cp.port().toString(), cp.deviceId().toString(), power);
        }
        Optional<Double> currentPower = powerConfig.currentPower(cp.port(), Direction.ALL);
        if (currentPower.isPresent()) {
            double currentPowerVal = currentPower.orElse(Double.MIN_VALUE);
            print("The current-output-power value in port %s on device %s is %f.",
                    cp.port().toString(), cp.deviceId().toString(), currentPowerVal);
        }
        Optional<Double> currentInputPower = powerConfig.currentInputPower(cp.port(), Direction.ALL);
        if (currentInputPower.isPresent()) {
            double inputPowerVal = currentInputPower.orElse(Double.MIN_VALUE);
            print("The current-input-power value in port %s on device %s is %f.",
                    cp.port().toString(), cp.deviceId().toString(), inputPowerVal);
        }
    } else if (operation.equals("edit-config")) {
        checkNotNull(value);
        powerConfig.setTargetPower(cp.port(), Direction.ALL, value);
        print("Set %f power on port", value, connectPoint);
    } else {
        print("Operation %s are not supported now.", operation);
    }
}
 
Example 20
Source File: OpenRoadmConnection.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 *
 * @param openRoadmName name of the Connection.
 * @param xc the associated OpenRoadmFlowRule.
 * @param deviceService ONOS device service.
 */
public OpenRoadmConnection(String openRoadmName, OpenRoadmFlowRule xc,
                           DeviceService deviceService) {
  connectionName = openRoadmName;
  deviceId = xc.deviceId();
  id = xc.id();
  priority = xc.priority();

  inPortNumber = xc.inPort();
  outPortNumber = xc.outPort();
  ochSignal = xc.ochSignal();
  type = xc.type();

  srcPort = deviceService.getPort(deviceId, xc.inPort());
  dstPort = deviceService.getPort(deviceId, xc.outPort());

  // Conversion from ochSignal (center frequency + diameter) to OpenRoadm
  // Media Channel (start - end)
  Frequency freqRadius = Frequency.ofHz(
      xc.ochSignal().channelSpacing().frequency().asHz() / 2);
  Frequency centerFreq = xc.ochSignal().centralFrequency();

  // e.g. DEG1-TTP-RX
  String srcTag =
      srcPort.annotations().value(OPENROADM_LOGICAL_CONNECTION_POINT) +
      "-" + centerFreq.asTHz();

  // e.g. DEG2-TTP-TX or SRG2-PP1-TX
  String dstTag =
      dstPort.annotations().value(OPENROADM_LOGICAL_CONNECTION_POINT) +
      "-" + centerFreq.asTHz();

  srcMcMinFrequency = centerFreq.subtract(freqRadius);
  srcMcMaxFrequency = centerFreq.add(freqRadius);
  dstMcMinFrequency = srcMcMinFrequency;
  dstMcMaxFrequency = srcMcMaxFrequency;
  srcNmcFrequency = centerFreq;
  dstNmcFrequency = centerFreq;
  srcNmcWidth = xc.ochSignal().channelSpacing().frequency();
  dstNmcWidth = xc.ochSignal().channelSpacing().frequency();

  srcMcSupportingInterface =
      "OMS-" +
      srcPort.annotations().value(OPENROADM_LOGICAL_CONNECTION_POINT);
  dstMcSupportingInterface =
      "OMS-" +
      dstPort.annotations().value(OPENROADM_LOGICAL_CONNECTION_POINT);

  // Media Channel Interfaces
  srcMcName = "MC-TTP-" + srcTag;
  srcMcSupportingCircuitPack =
      srcPort.annotations().value(OPENROADM_CIRCUIT_PACK_NAME);
  srcMcSupportingPort = srcPort.annotations().value(OPENROADM_PORT_NAME);

  dstMcName = "MC-TTP-" + dstTag;
  dstMcSupportingCircuitPack =
      dstPort.annotations().value(OPENROADM_CIRCUIT_PACK_NAME);
  dstMcSupportingPort = dstPort.annotations().value(OPENROADM_PORT_NAME);

  // Network Media Channel Interfaces
  srcNmcName = "NMC-CTP-" + srcTag;
  srcConnInterface = srcNmcName;
  srcNmcSupportingInterface = srcMcName;
  srcNmcSupportingCircuitPack =
      srcPort.annotations().value(OPENROADM_CIRCUIT_PACK_NAME);
  srcNmcSupportingPort = srcPort.annotations().value(OPENROADM_PORT_NAME);

  dstNmcName = "NMC-CTP-" + dstTag;
  dstConnInterface = dstNmcName;
  dstNmcSupportingInterface = dstMcName;
  dstNmcSupportingCircuitPack =
      dstPort.annotations().value(OPENROADM_CIRCUIT_PACK_NAME);
  dstNmcSupportingPort = dstPort.annotations().value(OPENROADM_PORT_NAME);
}