@Test public final void testUpdatePortStatus() { putDevice(DID1, SW1); List<PortDescription> pds = Arrays.<PortDescription>asList( new DefaultPortDescription(P1, true) ); deviceStore.updatePorts(PID, DID1, pds); Capture<InternalPortStatusEvent> message = new Capture<>(); Capture<MessageSubject> subject = new Capture<>(); Capture<Function<InternalPortStatusEvent, byte[]>> encoder = new Capture<>(); resetCommunicatorExpectingSingleBroadcast(message, subject, encoder); final DefaultPortDescription desc = new DefaultPortDescription(P1, false); DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, desc); assertEquals(PORT_UPDATED, event.type()); assertDevice(DID1, SW1, event.subject()); assertEquals(P1, event.port().number()); assertFalse("Port is disabled", event.port().isEnabled()); verify(clusterCommunicator); assertInternalPortStatusEvent(NID1, DID1, PID, desc, NO_ANNOTATION, message, subject, encoder); assertTrue(message.hasCaptured()); }
@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); return null; } final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); final DeviceEvent event; final Timestamped<PortDescription> mergedDesc; final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId); synchronized (device) { event = updatePortStatusInternal(providerId, deviceId, deltaDesc); mergedDesc = device.get(providerId) .getPortDesc(portDescription.portNumber()); } 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; }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @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); return null; } final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); final DeviceEvent event; final Timestamped<PortDescription> mergedDesc; final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId); synchronized (device) { event = updatePortStatusInternal(providerId, deviceId, deltaDesc); mergedDesc = device.get(providerId) .getPortDesc(portDescription.portNumber()); } 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; } }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @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); return null; } final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); final DeviceEvent event; final Timestamped<PortDescription> mergedDesc; final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId); synchronized (device) { event = updatePortStatusInternal(providerId, deviceId, deltaDesc); mergedDesc = device.get(providerId) .getPortDesc(portDescription.portNumber()); } 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; }  }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @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); return null; } final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); final DeviceEvent event; final Timestamped<PortDescription> mergedDesc; final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId); synchronized (device) { event = updatePortStatusInternal(providerId, deviceId, deltaDesc); mergedDesc = device.get(providerId) .getPortDesc(portDescription.portNumber()); } 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; }  @Activate void activate(); @Deactivate void deactivate(); @Override int getDeviceCount(); @Override Iterable<Device> getDevices(); @Override Iterable<Device> getAvailableDevices(); @Override Device getDevice(DeviceId deviceId); @Override synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId,
                                                         DeviceId deviceId,
                                                         DeviceDescription deviceDescription); @Override DeviceEvent markOffline(DeviceId deviceId); @Override synchronized List<DeviceEvent> updatePorts(ProviderId providerId,
                                                      DeviceId deviceId,
                                                      List<PortDescription> portDescriptions); @Override synchronized DeviceEvent updatePortStatus(ProviderId providerId,
                                                     DeviceId deviceId,
                                                     PortDescription portDescription); @Override List<Port> getPorts(DeviceId deviceId); @Override DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId,
                                            Collection<PortStatistics> newStatsCollection); PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats); @Override List<PortStatistics> getPortStatistics(DeviceId deviceId); @Override List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId); @Override Port getPort(DeviceId deviceId, PortNumber portNumber); @Override boolean isAvailable(DeviceId deviceId); @Override synchronized DeviceEvent removeDevice(DeviceId deviceId); }
GossipDeviceStore extends AbstractStore<DeviceEvent, DeviceStoreDelegate> implements DeviceStore { @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); return null; } final Timestamped<PortDescription> deltaDesc = new Timestamped<>(portDescription, newTimestamp); final DeviceEvent event; final Timestamped<PortDescription> mergedDesc; final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId); synchronized (device) { event = updatePortStatusInternal(providerId, deviceId, deltaDesc); mergedDesc = device.get(providerId) .getPortDesc(portDescription.portNumber()); } 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; }  @Activate void activate(); @Deactivate void deactivate(); @Override int getDeviceCount(); @Override Iterable<Device> getDevices(); @Override Iterable<Device> getAvailableDevices(); @Override Device getDevice(DeviceId deviceId); @Override synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId,
                                                         DeviceId deviceId,
                                                         DeviceDescription deviceDescription); @Override DeviceEvent markOffline(DeviceId deviceId); @Override synchronized List<DeviceEvent> updatePorts(ProviderId providerId,
                                                      DeviceId deviceId,
                                                      List<PortDescription> portDescriptions); @Override synchronized DeviceEvent updatePortStatus(ProviderId providerId,
                                                     DeviceId deviceId,
                                                     PortDescription portDescription); @Override List<Port> getPorts(DeviceId deviceId); @Override DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId,
                                            Collection<PortStatistics> newStatsCollection); PortStatistics calcDeltaStats(DeviceId deviceId, PortStatistics prvStats, PortStatistics newStats); @Override List<PortStatistics> getPortStatistics(DeviceId deviceId); @Override List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId); @Override Port getPort(DeviceId deviceId, PortNumber portNumber); @Override boolean isAvailable(DeviceId deviceId); @Override synchronized DeviceEvent removeDevice(DeviceId deviceId);  }