Search in sources :

Example 21 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortStatisticsByDeviceIdAndPort.

/**
 * Gets port statistics of a specified device and port.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @param port port
 * @return 200 OK with JSON encoded array of port statistics for the specified port
 */
@GET
@Path("ports/{deviceId}/{port}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, @PathParam("port") String port) {
    final DeviceService service = get(DeviceService.class);
    final PortNumber portNumber = portNumber(port);
    final PortStatistics portStatsEntry = service.getStatisticsForPort(DeviceId.deviceId(deviceId), portNumber);
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntry != null) {
        statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this));
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class PortStatsDriver method updatePorts.

public void updatePorts(Device device) {
    Set<PortStatistics> portStats = new HashSet<>();
    for (Port port : deviceService.getPorts(device.id())) {
        portStats.add(DefaultPortStatistics.builder().setBytesReceived(Math.abs(random.nextInt())).setBytesSent(Math.abs(random.nextInt())).setPacketsReceived(Math.abs(random.nextInt())).setPacketsSent(Math.abs(random.nextInt())).setDurationSec(2).setDeviceId(device.id()).setPort(port.number()).build());
    }
    deviceProviderService.updatePortStatistics(device.id(), portStats);
}
Also used : Port(org.onosproject.net.Port) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) HashSet(java.util.HashSet)

Example 23 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class OpenFlowDeviceProvider method buildPortStatistics.

private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId, List<OFPortStatsEntry> entries) {
    HashSet<PortStatistics> stats = Sets.newHashSet();
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    for (OFPortStatsEntry entry : entries) {
        try {
            if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) {
                continue;
            }
            DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
            boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion();
            Optional<OFPortStatsPropOptical> optical = propSupported ? entry.getProperties().stream().filter(OFPortStatsPropOptical.class::isInstance).map(OFPortStatsPropOptical.class::cast).findAny() : Optional.empty();
            if (optical.isPresent()) {
                long flags = optical.get().getFlags();
                boolean useFreq = false;
                for (OFPortDesc pd : sw.getPorts()) {
                    if (pd.getPortNo().equals(entry.getPortNo())) {
                        for (OFPortDescProp prop : pd.getProperties()) {
                            if (prop instanceof OFPortDescPropOptical) {
                                OFPortDescPropOptical oprop = (OFPortDescPropOptical) prop;
                                long supported = oprop.getSupported();
                                int useFreqVal = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL;
                                if ((supported & useFreqVal) != 0) {
                                    useFreq = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL;
                long txFreq = optical.get().getTxFreqLmda();
                long txOffset = optical.get().getTxOffset();
                long txGridSpan = optical.get().getTxGridSpan();
                annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM, freqLmdaToAnnotation(txFreq, useFreq));
                annotations.set(propertyFrequency ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM, freqLmdaToAnnotation(txOffset, useFreq));
                annotations.set(propertyFrequency ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(txGridSpan, useFreq));
                int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
                long rxFreq = optical.get().getRxFreqLmda();
                long rxOffset = optical.get().getRxOffset();
                long rxGridSpan = optical.get().getRxGridSpan();
                annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
                annotations.set(propertyFrequency ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM, freqLmdaToAnnotation(rxFreq, useFreq));
                annotations.set(propertyFrequency ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM, freqLmdaToAnnotation(rxOffset, useFreq));
                annotations.set(propertyFrequency ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM, freqLmdaToAnnotation(rxGridSpan, useFreq));
                int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
                int txPwr = optical.get().getTxPwr();
                annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TX_PWR, Integer.toString(txPwr));
                int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL;
                int rxPwr = optical.get().getRxPwr();
                annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled");
                annotations.set(AK_RX_PWR, Integer.toString(rxPwr));
                int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL;
                int biasCurrent = optical.get().getBiasCurrent();
                annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled");
                annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent));
                int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL;
                int temperature = optical.get().getTemperature();
                annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled");
                annotations.set(AK_TEMPERATURE, Integer.toString(temperature));
            }
            DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
            DefaultPortStatistics stat = builder.setDeviceId(deviceId).setPort(PortNumber.portNumber(entry.getPortNo().getPortNumber())).setPacketsReceived(entry.getRxPackets().getValue()).setPacketsSent(entry.getTxPackets().getValue()).setBytesReceived(entry.getRxBytes().getValue()).setBytesSent(entry.getTxBytes().getValue()).setPacketsRxDropped(entry.getRxDropped().getValue()).setPacketsTxDropped(entry.getTxDropped().getValue()).setPacketsRxErrors(entry.getRxErrors().getValue()).setPacketsTxErrors(entry.getTxErrors().getValue()).setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec()).setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec()).setAnnotations(annotations.build()).build();
            stats.add(stat);
        } catch (Exception e) {
            LOG.warn("Unable to process port stats", e);
        }
    }
    return Collections.unmodifiableSet(stats);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) Builder(org.onosproject.net.DefaultAnnotations.Builder) Dpid(org.onosproject.openflow.controller.Dpid) OFPortDescProp(org.projectfloodlight.openflow.protocol.OFPortDescProp) OFPortStatsPropOptical(org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) OFPortDescPropOptical(org.projectfloodlight.openflow.protocol.OFPortDescPropOptical) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry)

Example 24 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class ZtePortStatisticsDiscovery method discoverPortStatistics.

@Override
public Collection<PortStatistics> discoverPortStatistics() {
    DeviceId deviceId = handler().data().deviceId();
    LOG.debug("Discovering ZTE PortStatistics for device {}", deviceId);
    NetconfController controller = handler().get(NetconfController.class);
    if (null == controller) {
        LOG.error("Cannot find NetconfController");
        return null;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    if (null == session) {
        LOG.error("No session available for device {}", deviceId);
        return null;
    }
    DeviceService deviceService = this.handler().get(DeviceService.class);
    List<Port> ports = deviceService.getPorts(deviceId);
    Collection<PortStatistics> portStatistics = Lists.newArrayList();
    ports.stream().filter(Port::isEnabled).filter(this::isClientPort).forEach(port -> portStatistics.add(discoverSpecifiedPortStatistics(session, deviceId, port)));
    return portStatistics;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) NetconfController(org.onosproject.netconf.NetconfController) PortStatistics(org.onosproject.net.device.PortStatistics) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics)

Example 25 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class NetconfDeviceProvider method updatePortStatistics.

private void updatePortStatistics(Device device) {
    if (device.is(PortStatisticsDiscovery.class)) {
        PortStatisticsDiscovery d = device.as(PortStatisticsDiscovery.class);
        Collection<PortStatistics> portStatistics = d.discoverPortStatistics();
        if (portStatistics != null) {
            providerService.updatePortStatistics(device.id(), portStatistics);
        }
    } else {
        log.debug("No port statistics getter behaviour for device {}", device.id());
    }
}
Also used : PortStatisticsDiscovery(org.onosproject.net.device.PortStatisticsDiscovery) PortStatistics(org.onosproject.net.device.PortStatistics)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)52 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 DeviceId (org.onosproject.net.DeviceId)14 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 Device (org.onosproject.net.Device)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4