Search in sources :

Example 6 with DeviceEvent

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

the class EventsCommand method doExecute.

@Override
protected void doExecute() {
    EventHistoryService eventHistoryService = get(EventHistoryService.class);
    Stream<Event<?, ?>> events = eventHistoryService.history().stream();
    boolean dumpAll = all || !(mastership || device || link || topology || host || cluster || intent);
    if (!dumpAll) {
        Predicate<Event<?, ?>> filter = (defaultIs) -> false;
        if (mastership) {
            filter = filter.or(evt -> evt instanceof MastershipEvent);
        }
        if (device) {
            filter = filter.or(evt -> evt instanceof DeviceEvent);
        }
        if (link) {
            filter = filter.or(evt -> evt instanceof LinkEvent);
        }
        if (topology) {
            filter = filter.or(evt -> evt instanceof TopologyEvent);
        }
        if (host) {
            filter = filter.or(evt -> evt instanceof HostEvent);
        }
        if (cluster) {
            filter = filter.or(evt -> evt instanceof ClusterEvent);
        }
        if (intent) {
            filter = filter.or(evt -> evt instanceof IntentEvent);
        }
        events = events.filter(filter);
    }
    if (maxSize > 0) {
        events = events.limit(maxSize);
    }
    if (outputJson()) {
        ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
        printJson(jsonEvents);
    } else {
        events.forEach(this::printEvent);
    }
}
Also used : Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) MastershipEvent(org.onosproject.mastership.MastershipEvent) Topology(org.onosproject.net.topology.Topology) ImmutableList(com.google.common.collect.ImmutableList) HostEvent(org.onosproject.net.host.HostEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Collector(java.util.stream.Collector) Event(org.onosproject.event.Event) PrintWriter(java.io.PrintWriter) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) Predicate(java.util.function.Predicate) StringWriter(java.io.StringWriter) MoreObjects(com.google.common.base.MoreObjects) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Service(org.apache.karaf.shell.api.action.lifecycle.Service) DeviceEvent(org.onosproject.net.device.DeviceEvent) Option(org.apache.karaf.shell.api.action.Option) DeviceEvent(org.onosproject.net.device.DeviceEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 7 with DeviceEvent

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

the class ControlPlaneRedirectManagerTest method testAddDevice.

/**
 * Tests adding new Device to a openflow router.
 */
@Test
public void testAddDevice() {
    ConnectPoint sw1eth4 = new ConnectPoint(DEVICE_ID, PortNumber.portNumber(4));
    List<InterfaceIpAddress> interfaceIpAddresses = new ArrayList<>();
    interfaceIpAddresses.add(new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"), IpPrefix.valueOf("192.168.40.0/24")));
    interfaceIpAddresses.add(new InterfaceIpAddress(IpAddress.valueOf("2000::ff"), IpPrefix.valueOf("2000::ff/120")));
    Interface sw1Eth4 = new Interface(sw1eth4.deviceId().toString(), sw1eth4, interfaceIpAddresses, MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE);
    interfaces.add(sw1Eth4);
    EasyMock.reset(flowObjectiveService);
    setUpFlowObjectiveService();
    deviceListener.event(new DeviceEvent(DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED, dev3));
    verify(flowObjectiveService);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 8 with DeviceEvent

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

the class GossipDeviceStore method updateDevice.

// Updates the device and returns the appropriate event if necessary.
// Guarded by deviceDescs value (=Device lock)
private DeviceEvent updateDevice(ProviderId providerId, Device oldDevice, Device newDevice, Timestamp newTimestamp, boolean forceAvailable) {
    // We allow only certain attributes to trigger update
    boolean propertiesChanged = !Objects.equals(oldDevice.hwVersion(), newDevice.hwVersion()) || !Objects.equals(oldDevice.swVersion(), newDevice.swVersion()) || !Objects.equals(oldDevice.providerId(), newDevice.providerId()) || !Objects.equals(oldDevice.chassisId(), newDevice.chassisId()) || !Objects.equals(oldDevice.serialNumber(), newDevice.serialNumber()) || !Objects.equals(oldDevice.manufacturer(), newDevice.manufacturer());
    boolean annotationsChanged = !AnnotationsUtil.isEqual(oldDevice.annotations(), newDevice.annotations());
    // Primary providers can respond to all changes, but ancillary ones
    // should respond only to annotation changes.
    DeviceEvent event = null;
    if ((providerId.isAncillary() && annotationsChanged) || (!providerId.isAncillary() && (propertiesChanged || annotationsChanged))) {
        boolean replaced = devices.replace(newDevice.id(), oldDevice, newDevice);
        if (!replaced) {
            verify(replaced, "Replacing devices cache failed. PID:%s [expected:%s, found:%s, new=%s]", providerId, oldDevice, devices.get(newDevice.id()), newDevice);
        }
        log.debug("Device {} updated", newDevice.id());
        event = new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, newDevice, null);
    }
    if (!providerId.isAncillary() && forceAvailable) {
        notifyDelegateIfNotNull(markOnline(newDevice.id(), newTimestamp, false));
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent)

Example 9 with DeviceEvent

use of org.onosproject.net.device.DeviceEvent 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 10 with DeviceEvent

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

the class GossipDeviceStore method updatePortStatus.

@Override
public synchronized DeviceEvent updatePortStatus(ProviderId providerId, DeviceId deviceId, PortDescription portDescription) {
    final Timestamp newTimestamp;
    try {
        newTimestamp = deviceClockService.getTimestamp(deviceId);
    } catch (IllegalStateException e) {
        log.info("Timestamp was not available for device {}", deviceId);
        log.debug("  discarding {}", portDescription);
        // See updatePorts comment
        return null;
    }
    final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp);
    final DeviceEvent event;
    Timestamped<PortDescription> mergedDesc;
    final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
    synchronized (device) {
        event = updatePortStatusInternal(providerId, deviceId, deltaDesc);
        mergedDesc = device.get(providerId).getPortDesc(portDescription.portNumber());
        // on delete the port is removed, thus using latest known description
        if (mergedDesc == null) {
            mergedDesc = new Timestamped<>(portDescription, newTimestamp);
        }
    }
    if (event != null) {
        log.debug("Notifying peers of a port status update topology event for providerId: {} and deviceId: {}", providerId, deviceId);
        notifyPeers(new InternalPortStatusEvent(providerId, deviceId, mergedDesc));
    }
    return event;
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) Timestamped(org.onosproject.store.impl.Timestamped) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Aggregations

DeviceEvent (org.onosproject.net.device.DeviceEvent)77 Test (org.junit.Test)42 Device (org.onosproject.net.Device)26 DefaultDevice (org.onosproject.net.DefaultDevice)17 DefaultPort (org.onosproject.net.DefaultPort)17 PortDescription (org.onosproject.net.device.PortDescription)14 PortNumber (org.onosproject.net.PortNumber)11 Port (org.onosproject.net.Port)10 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)10 ProviderId (org.onosproject.net.provider.ProviderId)10 ArrayList (java.util.ArrayList)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 Timestamp (org.onosproject.store.Timestamp)8 MessageSubject (org.onosproject.store.cluster.messaging.MessageSubject)8 MastershipBasedTimestamp (org.onosproject.store.impl.MastershipBasedTimestamp)8 MultiValuedTimestamp (org.onosproject.store.service.MultiValuedTimestamp)8 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)8 BiFunction (java.util.function.BiFunction)7 Function (java.util.function.Function)7 DeviceDescription (org.onosproject.net.device.DeviceDescription)7