use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class NetconfDeviceProvider method initiateConnection.
// initiating the SSh connection the a given device.
private void initiateConnection(DeviceId deviceId) {
if (!isReachable(deviceId)) {
log.warn("Can't connect to device {}", deviceId);
return;
}
try {
NetconfDevice deviceNetconf = controller.connectDevice(deviceId);
if (deviceNetconf != null) {
// storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
NetconfDeviceConfig config = cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
// getting the device description
DeviceDescription deviceDescription = getDeviceDescription(deviceId, config);
// connecting device to ONOS
log.debug("Connected NETCONF device {}, on {}:{} {} with username {}", deviceId, config.ip(), config.port(), (config.path().isPresent() ? "/" + config.path().get() : ""), config.username());
providerService.deviceConnected(deviceId, deviceDescription);
} else {
mastershipService.relinquishMastership(deviceId);
deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
log.error("Can't connect to NETCONF device {}", deviceId);
}
} catch (Exception e) {
mastershipService.relinquishMastership(deviceId);
deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
throw new IllegalStateException(new NetconfException("Can't connect to NETCONF device " + deviceId, e));
}
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class NetconfDeviceProvider method getDeviceRepresentation.
private DeviceDescription getDeviceRepresentation(DeviceId deviceId, NetconfDeviceConfig config, DeviceDescriptionDiscovery deviceDescriptionDiscovery) {
DeviceDescription existingOrEmptyDescription = existingOrEmptyDescription(deviceId, config);
DeviceDescription newDescription = deviceDescriptionDiscovery.discoverDeviceDetails();
if (newDescription == null) {
return existingOrEmptyDescription;
}
// merging and returning
return new DefaultDeviceDescription(newDescription, true, DefaultAnnotations.merge((DefaultAnnotations) newDescription.annotations(), existingOrEmptyDescription.annotations()));
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class ECDeviceStore method composeDevice.
/**
* Returns a Device, merging descriptions from multiple Providers.
*
* @param deviceId device identifier
* @return Device instance
*/
private Device composeDevice(DeviceId deviceId) {
ProviderId primaryProviderId = getPrimaryProviderId(deviceId);
DeviceDescription primaryDeviceDescription = deviceDescriptions.get(new DeviceKey(primaryProviderId, deviceId));
Type type = primaryDeviceDescription.type();
String manufacturer = primaryDeviceDescription.manufacturer();
String hwVersion = primaryDeviceDescription.hwVersion();
String swVersion = primaryDeviceDescription.swVersion();
String serialNumber = primaryDeviceDescription.serialNumber();
ChassisId chassisId = primaryDeviceDescription.chassisId();
DefaultAnnotations annotations = mergeAnnotations(deviceId);
return new DefaultDevice(primaryProviderId, deviceId, type, manufacturer, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class GossipDeviceStore method createOrUpdateDevice.
@Override
public synchronized DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId, DeviceDescription deviceDescription) {
NodeId localNode = clusterService.getLocalNode().id();
NodeId deviceNode = mastershipService.getMasterFor(deviceId);
boolean isMaster = localNode.equals(deviceNode);
// Process device update only if we're the master,
// otherwise signal the actual master.
DeviceEvent deviceEvent = null;
// If this node is the master for the device, acquire a new timestamp. Otherwise,
// use a 0,0 or tombstone timestamp to create the device if it doesn't already exist.
Timestamp newTimestamp;
try {
newTimestamp = isMaster ? deviceClockService.getTimestamp(deviceId) : removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
} catch (IllegalStateException e) {
newTimestamp = removalRequest.getOrDefault(deviceId, DEFAULT_TIMESTAMP);
isMaster = false;
}
final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp);
final Timestamped<DeviceDescription> mergedDesc;
final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
synchronized (device) {
deviceEvent = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc);
if (deviceEvent == null) {
return null;
}
mergedDesc = device.get(providerId).getDeviceDesc();
}
// If this node is the master for the device, update peers.
if (isMaster) {
log.debug("Notifying peers of a device update topology event for providerId: {} and deviceId: {}", providerId, deviceId);
notifyPeers(new InternalDeviceEvent(providerId, deviceId, mergedDesc));
}
notifyDelegateIfNotNull(deviceEvent);
return deviceEvent;
}
use of org.onosproject.net.device.DeviceDescription in project onos by opennetworkinglab.
the class GossipDeviceStore method handleAdvertisement.
/**
* Responds to anti-entropy advertisement message.
* <p>
* Notify sender about out-dated information using regular replication message.
* Send back advertisement to sender if not in sync.
*
* @param advertisement to respond to
*/
private void handleAdvertisement(DeviceAntiEntropyAdvertisement advertisement) {
/*
* NOTE that when an instance rejoins the cluster, it will generate
* device events and send to the local apps through the delegate. This
* approach might be not the best if the apps are not enough robust or
* if there is no proper coordination in the cluster. Also, note that
* any ECMap will act on the same way during the bootstrap process
*/
final NodeId sender = advertisement.sender();
Map<DeviceFragmentId, Timestamp> devAds = new HashMap<>(advertisement.deviceFingerPrints());
Map<PortFragmentId, Timestamp> portAds = new HashMap<>(advertisement.ports());
Map<DeviceId, Timestamp> offlineAds = new HashMap<>(advertisement.offline());
// Fragments to request
Collection<DeviceFragmentId> reqDevices = new ArrayList<>();
Collection<PortFragmentId> reqPorts = new ArrayList<>();
for (Entry<DeviceId, Map<ProviderId, DeviceDescriptions>> de : deviceDescs.entrySet()) {
final DeviceId deviceId = de.getKey();
final Map<ProviderId, DeviceDescriptions> lDevice = de.getValue();
synchronized (lDevice) {
// latestTimestamp across provider
// Note: can be null initially
Timestamp localLatest = offline.get(deviceId);
// handle device Ads
for (Entry<ProviderId, DeviceDescriptions> prov : lDevice.entrySet()) {
final ProviderId provId = prov.getKey();
final DeviceDescriptions lDeviceDescs = prov.getValue();
final DeviceFragmentId devFragId = new DeviceFragmentId(deviceId, provId);
Timestamped<DeviceDescription> lProvDevice = lDeviceDescs.getDeviceDesc();
Timestamp advDevTimestamp = devAds.get(devFragId);
if (advDevTimestamp == null || lProvDevice.isNewerThan(advDevTimestamp)) {
// remote does not have it or outdated, suggest
log.trace("send to {} device update {} for {}", sender, lProvDevice, deviceId);
notifyPeer(sender, new InternalDeviceEvent(provId, deviceId, lProvDevice));
} else if (!lProvDevice.timestamp().equals(advDevTimestamp)) {
// local is outdated, request
log.trace("need update {} < {} for device {} from {}", lProvDevice.timestamp(), advDevTimestamp, deviceId, sender);
reqDevices.add(devFragId);
}
// handle port Ads
for (Entry<PortNumber, Timestamped<PortDescription>> pe : lDeviceDescs.getPortDescs().entrySet()) {
final PortNumber num = pe.getKey();
final Timestamped<PortDescription> lPort = pe.getValue();
final PortFragmentId portFragId = new PortFragmentId(deviceId, provId, num);
Timestamp advPortTimestamp = portAds.get(portFragId);
if (advPortTimestamp == null || lPort.isNewerThan(advPortTimestamp)) {
// remote does not have it or outdated, suggest
log.trace("send to {} port update {} for {}/{}", sender, lPort, deviceId, num);
notifyPeer(sender, new InternalPortStatusEvent(provId, deviceId, lPort));
} else if (!lPort.timestamp().equals(advPortTimestamp)) {
// local is outdated, request
log.trace("need update {} < {} for port {} from {}", lPort.timestamp(), advPortTimestamp, num, sender);
reqPorts.add(portFragId);
}
// remove port Ad already processed
portAds.remove(portFragId);
}
// end local port loop
// remove device Ad already processed
devAds.remove(devFragId);
// find latest and update
final Timestamp providerLatest = lDeviceDescs.getLatestTimestamp();
if (localLatest == null || providerLatest.compareTo(localLatest) > 0) {
localLatest = providerLatest;
}
}
// end local provider loop
// checking if remote timestamp is more recent.
Timestamp rOffline = offlineAds.get(deviceId);
if (localLatest == null || (rOffline != null && rOffline.compareTo(localLatest) > 0)) {
// remote offline timestamp suggests that the
// device is off-line
log.trace("remote offline timestamp from {} suggests that the device {} is off-line", sender, deviceId);
markOfflineInternal(deviceId, rOffline);
}
Timestamp lOffline = offline.get(deviceId);
if (lOffline != null && rOffline == null) {
// locally offline, but remote is online, suggest offline
log.trace("suggest to {} sthat the device {} is off-line", sender, deviceId);
notifyPeer(sender, new InternalDeviceStatusChangeEvent(deviceId, lOffline, false));
}
// remove device offline Ad already processed
offlineAds.remove(deviceId);
}
// end local device loop
}
// device lock
// If there is any Ads left, request them
log.trace("Ads left {}, {}", devAds, portAds);
reqDevices.addAll(devAds.keySet());
reqPorts.addAll(portAds.keySet());
if (reqDevices.isEmpty() && reqPorts.isEmpty()) {
log.trace("Nothing to request to remote peer {}", sender);
return;
}
log.debug("Need to sync {} {}", reqDevices, reqPorts);
// 2-way Anti-Entropy for now
try {
unicastMessage(sender, DEVICE_ADVERTISE, createAdvertisement());
} catch (IOException e) {
log.error("Failed to send response advertisement to " + sender, e);
}
// Sketch of 3-way Anti-Entropy
// DeviceAntiEntropyRequest request = new DeviceAntiEntropyRequest(self, reqDevices, reqPorts);
// ClusterMessage message = new ClusterMessage(
// clusterService.getLocalNode().id(),
// GossipDeviceStoreMessageSubjects.DEVICE_REQUEST,
// SERIALIZER.encode(request));
//
// try {
// clusterCommunicator.unicast(message, advertisement.sender());
// } catch (IOException e) {
// log.error("Failed to send advertisement reply to "
// + advertisement.sender(), e);
// }
}
Aggregations