mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 19:01:06 +02:00
[ONOS-7149] Re-query DeviceDescription when Netconf device connects again
Change-Id: I4f22dc3e8a8a2eb0202925afb2ad7e4151ee6e46
This commit is contained in:
parent
1a7e4f9b9a
commit
105736e0c0
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.onosproject.drivers.netconf;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.onlab.packet.ChassisId;
|
||||||
|
import org.onosproject.net.Device;
|
||||||
|
import org.onosproject.net.device.DefaultDeviceDescription;
|
||||||
|
import org.onosproject.net.device.DeviceDescription;
|
||||||
|
import org.onosproject.net.device.DeviceDescriptionDiscovery;
|
||||||
|
import org.onosproject.net.device.PortDescription;
|
||||||
|
import org.onosproject.net.driver.AbstractHandlerBehaviour;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discovers the device detail of the ovs based simulator used in NETCONF SB testing and development.
|
||||||
|
*/
|
||||||
|
public class OvsNetconfDeviceDescriptionDiscovery
|
||||||
|
extends AbstractHandlerBehaviour implements DeviceDescriptionDiscovery {
|
||||||
|
|
||||||
|
private final Logger log = getLogger(getClass());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceDescription discoverDeviceDetails() {
|
||||||
|
log.debug("Discovering device details {}", handler().data().deviceId());
|
||||||
|
return new DefaultDeviceDescription(handler().data().deviceId().uri(),
|
||||||
|
Device.Type.VIRTUAL,
|
||||||
|
"Of-Config",
|
||||||
|
"VirtualBox",
|
||||||
|
"1.0",
|
||||||
|
"1",
|
||||||
|
new ChassisId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PortDescription> discoverPortDetails() {
|
||||||
|
log.debug("Discovering device ports {}", handler().data().deviceId());
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
}
|
@ -16,19 +16,17 @@
|
|||||||
-->
|
-->
|
||||||
<drivers>
|
<drivers>
|
||||||
<!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB-->
|
<!--This driver is for simulated NETCONF devices through of-config tool on top og OVSDB-->
|
||||||
<driver name="ovs-netconf" manufacturer="" hwVersion="" swVersion="">
|
|
||||||
<behaviour api="org.onosproject.net.behaviour.ControllerConfig"
|
|
||||||
impl="org.onosproject.drivers.netconf.NetconfControllerConfig"/>
|
|
||||||
<behaviour api="org.onosproject.net.behaviour.ConfigGetter"
|
|
||||||
impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/>
|
|
||||||
<behaviour api="org.onosproject.net.behaviour.ConfigSetter"
|
|
||||||
impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/>
|
|
||||||
</driver>
|
|
||||||
<driver name="netconf" manufacturer="" hwVersion="" swVersion="">
|
<driver name="netconf" manufacturer="" hwVersion="" swVersion="">
|
||||||
<behaviour api="org.onosproject.net.behaviour.ConfigGetter"
|
<behaviour api="org.onosproject.net.behaviour.ConfigGetter"
|
||||||
impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/>
|
impl="org.onosproject.drivers.netconf.NetconfConfigGetter"/>
|
||||||
<behaviour api="org.onosproject.net.behaviour.ConfigSetter"
|
<behaviour api="org.onosproject.net.behaviour.ConfigSetter"
|
||||||
impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/>
|
impl="org.onosproject.drivers.netconf.NetconfConfigSetter"/>
|
||||||
</driver>
|
</driver>
|
||||||
|
<driver name="ovs-netconf" manufacturer="" hwVersion="" swVersion="" extends="netconf">
|
||||||
|
<behaviour api="org.onosproject.net.behaviour.ControllerConfig"
|
||||||
|
impl="org.onosproject.drivers.netconf.NetconfControllerConfig"/>
|
||||||
|
<behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
|
||||||
|
impl="org.onosproject.drivers.netconf.OvsNetconfDeviceDescriptionDiscovery"/>
|
||||||
|
</driver>
|
||||||
</drivers>
|
</drivers>
|
||||||
|
|
||||||
|
@ -436,25 +436,42 @@ public class NetconfDeviceProvider extends AbstractProvider
|
|||||||
log.debug("Connecting NETCONF device {}, on {}:{} with username {}",
|
log.debug("Connecting NETCONF device {}, on {}:{} with username {}",
|
||||||
deviceId, config.ip(), config.port(), config.username());
|
deviceId, config.ip(), config.port(), config.username());
|
||||||
storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
|
storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
|
||||||
retriedPortDiscoveryMap.putIfAbsent(deviceId, new AtomicInteger(0));
|
retriedPortDiscoveryMap.put(deviceId, new AtomicInteger(0));
|
||||||
if (deviceService.getDevice(deviceId) == null) {
|
if (deviceService.getDevice(deviceId) == null) {
|
||||||
providerService.deviceConnected(deviceId, deviceDescription);
|
providerService.deviceConnected(deviceId, deviceDescription);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
checkAndUpdateDevice(deviceId, deviceDescription);
|
checkAndUpdateDevice(deviceId, deviceDescription, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception checking {}", deviceId, e);
|
log.error("Unhandled exception checking {}", deviceId, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAndUpdateDevice(DeviceId deviceId, DeviceDescription deviceDescription) {
|
private void checkAndUpdateDevice(DeviceId deviceId, DeviceDescription deviceDescription, boolean newlyConnected) {
|
||||||
Device device = deviceService.getDevice(deviceId);
|
Device device = deviceService.getDevice(deviceId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.debug("Device {} has not been added to store, " +
|
log.debug("Device {} has not been added to store, since it's not reachable", deviceId);
|
||||||
"since it's not reachable", deviceId);
|
return;
|
||||||
} else {
|
}
|
||||||
boolean isReachable = isReachable(deviceId);
|
boolean isReachable = isReachable(deviceId);
|
||||||
if (isReachable && !deviceService.isAvailable(deviceId)) {
|
if (!isReachable && deviceService.isAvailable(deviceId)) {
|
||||||
|
providerService.deviceDisconnected(deviceId);
|
||||||
|
return;
|
||||||
|
} else if (newlyConnected) {
|
||||||
|
updateDeviceDescription(deviceId, deviceDescription, device);
|
||||||
|
}
|
||||||
|
if (isReachable && deviceService.isAvailable(deviceId) &&
|
||||||
|
mastershipService.isLocalMaster(deviceId)) {
|
||||||
|
//if ports are not discovered, retry the discovery
|
||||||
|
if (deviceService.getPorts(deviceId).isEmpty() &&
|
||||||
|
retriedPortDiscoveryMap.get(deviceId).getAndIncrement() < maxRetries) {
|
||||||
|
discoverPorts(deviceId);
|
||||||
|
}
|
||||||
|
updatePortStatistics(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDeviceDescription(DeviceId deviceId, DeviceDescription deviceDescription, Device device) {
|
||||||
if (device.is(DeviceDescriptionDiscovery.class)) {
|
if (device.is(DeviceDescriptionDiscovery.class)) {
|
||||||
if (mastershipService.isLocalMaster(deviceId)) {
|
if (mastershipService.isLocalMaster(deviceId)) {
|
||||||
DeviceDescriptionDiscovery deviceDescriptionDiscovery =
|
DeviceDescriptionDiscovery deviceDescriptionDiscovery =
|
||||||
@ -481,19 +498,6 @@ public class NetconfDeviceProvider extends AbstractProvider
|
|||||||
deviceId, new DefaultDeviceDescription(
|
deviceId, new DefaultDeviceDescription(
|
||||||
deviceDescription, true, deviceDescription.annotations()));
|
deviceDescription, true, deviceDescription.annotations()));
|
||||||
}
|
}
|
||||||
} else if (!isReachable && deviceService.isAvailable(deviceId)) {
|
|
||||||
providerService.deviceDisconnected(deviceId);
|
|
||||||
} else if (isReachable && deviceService.isAvailable(deviceId) &&
|
|
||||||
mastershipService.isLocalMaster(deviceId)) {
|
|
||||||
|
|
||||||
//if ports are not discovered, retry the discovery
|
|
||||||
if (deviceService.getPorts(deviceId).isEmpty() &&
|
|
||||||
retriedPortDiscoveryMap.get(deviceId).getAndIncrement() < maxRetries) {
|
|
||||||
discoverPorts(deviceId);
|
|
||||||
}
|
|
||||||
updatePortStatistics(device);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePortStatistics(Device device) {
|
private void updatePortStatistics(Device device) {
|
||||||
@ -529,7 +533,7 @@ public class NetconfDeviceProvider extends AbstractProvider
|
|||||||
cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
|
cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
|
||||||
DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
|
DeviceDescription deviceDescription = createDeviceRepresentation(deviceId, config);
|
||||||
storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
|
storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
|
||||||
checkAndUpdateDevice(deviceId, deviceDescription);
|
checkAndUpdateDevice(deviceId, deviceDescription, false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user