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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations