@Override public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(portDescriptions, PORT_DESC_LIST_NULL); checkValidity(); if (!mastershipService.isLocalMaster(deviceId)) { // Never been a master for this device // any update will be ignored. log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions); return; } PortDescriptionsConfig portConfig = networkConfigService.getConfig(deviceId, PortDescriptionsConfig.class); if (portConfig != null) { // Updating the ports if configuration exists (on new lists as // the passed one might be immutable) portDescriptions = Lists.newArrayList(portDescriptions); portDescriptions.addAll(portConfig.portDescriptions()); } portDescriptions = portDescriptions.stream() .map(e -> applyAllPortOps(deviceId, e)) .collect(Collectors.toList()); List<DeviceEvent> events = store.updatePorts(this.provider().id(), deviceId, portDescriptions); if (events != null) { for (DeviceEvent event : events) { post(event); } } }
@Override public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) { checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(portStatistics, "Port statistics list cannot be null"); checkValidity(); DeviceEvent event = store.updatePortStatistics(this.provider().id(), deviceId, portStatistics); post(event); } }
log.info("Device {} disconnected from this node", deviceId); List<PortDescription> descs = store.getPortDescriptions(provider().id(), deviceId) .map(desc -> ensurePortEnabledState(desc, false)) .collect(Collectors.toList()); store.updatePorts(this.provider().id(), deviceId, descs); try { if (mastershipService.isLocalMaster(deviceId)) {
DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId, deviceDescription); applyRole(deviceId, role); List<PortDescription> complete = store.getPortDescriptions(provider().id(), deviceId) .collect(Collectors.toList()); complete.addAll(portConfig.portDescriptions()); .map(e -> applyAllPortOps(deviceId, e)) .collect(Collectors.toList()); store.updatePorts(provider().id(), deviceId, portDescriptions);
@Override public void deletePort(DeviceId deviceId, PortDescription basePortDescription) { checkNotNull(deviceId, DEVICE_ID_NULL); checkNotNull(basePortDescription, PORT_DESCRIPTION_NULL); checkValidity(); if (!mastershipService.isLocalMaster(deviceId)) { // Never been a master for this device // any update will be ignored. log.trace("Ignoring {} port update on standby node. {}", deviceId, basePortDescription); return; } Device device = getDevice(deviceId); if (device == null) { log.trace("Device not found: {}", deviceId); } PortDescription newPortDescription = DefaultPortDescription.builder(basePortDescription) .isRemoved(true) .build(); final DeviceEvent event = store.updatePortStatus(this.provider().id(), deviceId, newPortDescription); if (event != null) { log.info("Device {} port {} status changed", deviceId, event.port().number()); post(event); } }
/** * Apply role in reaction to provider event. * * @param deviceId device identifier * @param newRole new role to apply to the device * @return true if the request was sent to provider */ private boolean applyRole(DeviceId deviceId, MastershipRole newRole) { if (newRole.equals(MastershipRole.NONE)) { //no-op return true; } DeviceProvider provider = provider(); if (provider == null) { log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole); return false; } provider.roleChanged(deviceId, newRole); // not triggering probe when triggered by provider service event return true; }