Search in sources :

Example 26 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class DefaultOFSwitch method processStatsRequest.

@Override
public void processStatsRequest(Channel channel, OFMessage msg) {
    if (msg.getType() != OFType.STATS_REQUEST) {
        log.warn("Ignoring message of type {}.", msg.getType());
        return;
    }
    OFStatsRequest ofStatsRequest = (OFStatsRequest) msg;
    OFStatsReply ofStatsReply = null;
    switch(ofStatsRequest.getStatsType()) {
        case PORT_DESC:
            List<OFPortDesc> portDescs = new ArrayList<>();
            Set<Port> ports = ofSwitchService.ports(networkId, deviceId);
            ports.forEach(port -> {
                OFPortDesc ofPortDesc = portDesc(port);
                portDescs.add(ofPortDesc);
            });
            ofStatsReply = FACTORY.buildPortDescStatsReply().setXid(msg.getXid()).setEntries(portDescs).build();
            break;
        case PORT:
            OFPortStatsRequest portStatsRequest = (OFPortStatsRequest) msg;
            OFPort ofPort = portStatsRequest.getPortNo();
            List<OFPortStatsEntry> portStatsEntries = new ArrayList<>();
            List<PortStatistics> portStatistics = ofSwitchService.getPortStatistics(networkId, deviceId);
            if (ofPort.equals(OFPort.ANY)) {
                portStatistics.forEach(portStatistic -> {
                    OFPortStatsEntry ofPortStatsEntry = portStatsEntry(portStatistic);
                    portStatsEntries.add(ofPortStatsEntry);
                });
            }
            ofStatsReply = FACTORY.buildPortStatsReply().setEntries(portStatsEntries).setXid(msg.getXid()).build();
            break;
        case METER_FEATURES:
            OFMeterFeatures ofMeterFeatures = FACTORY.buildMeterFeatures().build();
            ofStatsReply = FACTORY.buildMeterFeaturesStatsReply().setXid(msg.getXid()).setFeatures(ofMeterFeatures).build();
            break;
        case FLOW:
            List<OFFlowStatsEntry> flowStatsEntries = new ArrayList<>();
            List<FlowEntry> flowStats = ofSwitchService.getFlowEntries(networkId, deviceId);
            flowStats.forEach(flowEntry -> {
                OFFlowStatsEntry ofFlowStatsEntry = ofFlowStatsEntry(flowEntry);
                flowStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildFlowStatsReply().setEntries(flowStatsEntries).setXid(msg.getXid()).build();
            break;
        case TABLE:
            List<OFTableStatsEntry> ofTableStatsEntries = new ArrayList<>();
            List<TableStatisticsEntry> tableStats = ofSwitchService.getFlowTableStatistics(networkId, deviceId);
            tableStats.forEach(tableStatisticsEntry -> {
                OFTableStatsEntry ofFlowStatsEntry = ofFlowTableStatsEntry(tableStatisticsEntry);
                ofTableStatsEntries.add(ofFlowStatsEntry);
            });
            ofStatsReply = FACTORY.buildTableStatsReply().setEntries(ofTableStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP:
            List<Group> groupStats = ofSwitchService.getGroups(networkId, deviceId);
            List<OFGroupStatsEntry> ofGroupStatsEntries = new ArrayList<>();
            groupStats.forEach(group -> {
                OFGroupStatsEntry entry = ofGroupStatsEntry(group);
                ofGroupStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupStatsReply().setEntries(ofGroupStatsEntries).setXid(msg.getXid()).build();
            break;
        case GROUP_DESC:
            List<OFGroupDescStatsEntry> ofGroupDescStatsEntries = new ArrayList<>();
            List<Group> groupStats2 = ofSwitchService.getGroups(networkId, deviceId);
            groupStats2.forEach(group -> {
                OFGroupDescStatsEntry entry = ofGroupDescStatsEntry(group);
                ofGroupDescStatsEntries.add(entry);
            });
            ofStatsReply = FACTORY.buildGroupDescStatsReply().setEntries(ofGroupDescStatsEntries).setXid(msg.getXid()).build();
            break;
        case DESC:
            ofStatsReply = FACTORY.buildDescStatsReply().setXid(msg.getXid()).build();
            break;
        default:
            log.debug("Functionality not yet supported for type {} statsType{} msg {}", msg.getType(), ofStatsRequest.getStatsType(), msg);
            break;
    }
    if (ofStatsReply != null) {
        log.trace("request {}; reply {}", msg, ofStatsReply);
        channel.writeAndFlush(Collections.singletonList(ofStatsReply));
    }
}
Also used : OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFGroup(org.projectfloodlight.openflow.types.OFGroup) Group(org.onosproject.net.group.Group) OFGroupDescStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry) Port(org.onosproject.net.Port) OFPort(org.projectfloodlight.openflow.types.OFPort) ArrayList(java.util.ArrayList) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) FlowEntry(org.onosproject.net.flow.FlowEntry) OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFStatsRequest(org.projectfloodlight.openflow.protocol.OFStatsRequest) PortStatistics(org.onosproject.net.device.PortStatistics) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OFGroupStatsEntry(org.projectfloodlight.openflow.protocol.OFGroupStatsEntry) OFTableStatsEntry(org.projectfloodlight.openflow.protocol.OFTableStatsEntry) OFPort(org.projectfloodlight.openflow.types.OFPort) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) OFMeterFeatures(org.projectfloodlight.openflow.protocol.OFMeterFeatures)

Example 27 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class GossipDeviceStore method composePort.

/**
 * Returns a Port, merging description given from multiple Providers.
 *
 * @param device   device the port is on
 * @param number   port number
 * @param descsMap Collection of Descriptions from multiple providers
 * @return Port instance
 */
private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) {
    ProviderId primary = pickPrimaryPid(descsMap);
    DeviceDescriptions primDescs = descsMap.get(primary);
    // if no primary, assume not enabled
    boolean isEnabled = false;
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    Timestamp newest = null;
    final Timestamped<PortDescription> portDesc = primDescs.getPortDesc(number);
    if (portDesc != null) {
        isEnabled = portDesc.value().isEnabled();
        annotations.putAll(portDesc.value().annotations());
        newest = portDesc.timestamp();
    }
    Port updated = null;
    for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) {
        if (e.getKey().equals(primary)) {
            continue;
        }
        // Note: should keep track of Description timestamp in the future
        // and only merge conflicting keys when timestamp is newer.
        // Currently assuming there will never be a key conflict between
        // providers
        // annotation merging. not so efficient, should revisit later
        final Timestamped<PortDescription> otherPortDesc = e.getValue().getPortDesc(number);
        if (otherPortDesc != null) {
            if (newest != null && newest.isNewerThan(otherPortDesc.timestamp())) {
                continue;
            }
            annotations.putAll(otherPortDesc.value().annotations());
            PortDescription other = otherPortDesc.value();
            updated = buildTypedPort(device, number, isEnabled, other, annotations.build());
            newest = otherPortDesc.timestamp();
        }
    }
    if (portDesc == null) {
        return updated == null ? new DefaultPort(device, number, false, annotations.build()) : updated;
    }
    PortDescription current = portDesc.value();
    return updated == null ? buildTypedPort(device, number, isEnabled, current, annotations.build()) : updated;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortDescription(org.onosproject.net.device.PortDescription) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) DefaultPort(org.onosproject.net.DefaultPort)

Example 28 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class GossipDeviceStore method pruneOldPorts.

// Prunes the specified list of ports based on which ports are in the
// processed list and returns list of corresponding events.
// Guarded by deviceDescs value (=Device lock)
private List<DeviceEvent> pruneOldPorts(Device device, Map<PortNumber, Port> ports, Set<PortNumber> processed) {
    List<DeviceEvent> events = new ArrayList<>();
    Iterator<Entry<PortNumber, Port>> iterator = ports.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<PortNumber, Port> e = iterator.next();
        PortNumber portNumber = e.getKey();
        if (!processed.contains(portNumber)) {
            events.add(new DeviceEvent(PORT_REMOVED, device, e.getValue()));
            iterator.remove();
        }
    }
    return events;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Entry(java.util.Map.Entry) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ArrayList(java.util.ArrayList) PortNumber(org.onosproject.net.PortNumber)

Example 29 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class GossipDeviceStore method removePort.

private DeviceEvent removePort(DeviceId deviceId, PortNumber portNumber, ProviderId providerId, Map<ProviderId, DeviceDescriptions> descsMap) {
    log.info("Deleted port: " + deviceId.toString() + "/" + portNumber.toString());
    Port deletedPort = devicePorts.get(deviceId).remove(portNumber);
    descsMap.computeIfPresent(providerId, (provider, deviceDescriptions) -> {
        deviceDescriptions.removePortDesc(portNumber);
        return deviceDescriptions;
    });
    return new DeviceEvent(PORT_REMOVED, getDevice(deviceId), deletedPort);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort)

Example 30 with Port

use of org.onosproject.net.Port in project onos by opennetworkinglab.

the class GossipDeviceStore method removeDeviceInternal.

private DeviceEvent removeDeviceInternal(DeviceId deviceId, Timestamp timestamp) {
    Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptionsMap(deviceId);
    synchronized (descs) {
        // accept removal request if given timestamp is newer than
        // the latest Timestamp from Primary provider
        DeviceDescriptions primDescs = getPrimaryDescriptions(descs);
        if (primDescs == null) {
            return null;
        }
        Timestamp lastTimestamp = primDescs.getLatestTimestamp();
        // If no timestamp is set, default the timestamp to the last timestamp for the device.
        if (timestamp == null) {
            timestamp = lastTimestamp;
        }
        if (timestamp.compareTo(lastTimestamp) <= 0) {
            // outdated event ignore
            return null;
        }
        removalRequest.put(deviceId, timestamp);
        Device device = devices.remove(deviceId);
        // removing internal description
        deviceDescs.remove(deviceId);
        // should DEVICE_REMOVED carry removed ports?
        Map<PortNumber, Port> ports = devicePorts.get(deviceId);
        if (ports != null) {
            ports.clear();
        }
        markOfflineInternal(deviceId, timestamp);
        descs.clear();
        // Forget about the device
        offline.remove(deviceId);
        return device == null ? null : new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, device, null);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) PortNumber(org.onosproject.net.PortNumber) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Aggregations

Port (org.onosproject.net.Port)200 DeviceService (org.onosproject.net.device.DeviceService)92 PortNumber (org.onosproject.net.PortNumber)85 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)76 Device (org.onosproject.net.Device)63 List (java.util.List)51 Set (java.util.Set)47 Optional (java.util.Optional)43 DefaultPort (org.onosproject.net.DefaultPort)38 Logger (org.slf4j.Logger)38 ArrayList (java.util.ArrayList)36 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 Collection (java.util.Collection)33 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 Test (org.junit.Test)31 Ethernet (org.onlab.packet.Ethernet)31 Map (java.util.Map)29 Sets (com.google.common.collect.Sets)28