use of org.onosproject.tl1.Tl1Device in project onos by opennetworkinglab.
the class LumentumWaveReadyDiscovery method logout.
// Unused but provided here for convenience.
private void logout() {
DeviceId deviceId = handler().data().deviceId();
Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
Optional<Tl1Device> device = ctrl.getDevice(deviceId);
if (!device.isPresent()) {
return;
}
// Logout command
Tl1Command logoutCmd = DefaultTl1Command.builder().withVerb(CANC).withModifier(USER).withAid(device.get().username()).withCtag(103).build();
Future<String> logout = ctrl.sendMsg(deviceId, logoutCmd);
try {
String logoutResponse = logout.get(TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Lougout failed", e);
}
}
use of org.onosproject.tl1.Tl1Device in project onos by opennetworkinglab.
the class DefaultTl1Controller method sendMsg.
@Override
public /**
* This implementation returns an empty string on failure.
*/
CompletableFuture<String> sendMsg(DeviceId deviceId, Tl1Command msg) {
log.debug("Sending TL1 message to device {}: {}", deviceId, msg);
Tl1Device device = deviceMap.get(deviceId);
if (device == null || !device.isConnected() || !mastershipService.isLocalMaster(deviceId)) {
return CompletableFuture.completedFuture(StringUtils.EMPTY);
}
// Create and store completable future, complete it in the channel handler when we receive a response
CompletableFuture<String> future = new CompletableFuture<>();
Channel channel = device.channel();
if (!msgMap.containsKey(channel)) {
return CompletableFuture.completedFuture(StringUtils.EMPTY);
}
msgMap.get(channel).put(msg.ctag(), future);
// Write message to channel
channel.writeAndFlush(Unpooled.copiedBuffer(msg.toString(), CharsetUtil.UTF_8));
return future;
}
use of org.onosproject.tl1.Tl1Device in project onos by opennetworkinglab.
the class DefaultTl1Controller method connectDevice.
@Override
public void connectDevice(DeviceId deviceId) {
Tl1Device device = deviceMap.get(deviceId);
if (device == null || device.isConnected()) {
return;
}
Bootstrap b = new Bootstrap();
b.group(workerGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(8192, DELIMITER));
socketChannel.pipeline().addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
// TODO
// socketChannel.pipeline().addLast(new Tl1Decoder());
socketChannel.pipeline().addLast(new Tl1InboundHandler());
}
}).remoteAddress(device.ip().toInetAddress(), device.port()).connect().addListener((ChannelFuture channelFuture) -> {
if (channelFuture.isSuccess()) {
msgMap.put(channelFuture.channel(), new ConcurrentHashMap<>());
device.connect(channelFuture.channel());
tl1Listeners.forEach(l -> executor.execute(() -> l.deviceConnected(deviceId)));
}
});
}
use of org.onosproject.tl1.Tl1Device in project onos by opennetworkinglab.
the class LumentumWaveReadyDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId deviceId = handler().data().deviceId();
Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
// Something reasonable, unavailable by default
DeviceDescription defaultDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, LUMENTUM, WAVEREADY, SWVERSION, SERIAL, new ChassisId(), false, DefaultAnnotations.EMPTY);
Optional<Tl1Device> device = ctrl.getDevice(deviceId);
if (!device.isPresent()) {
return defaultDescription;
}
// Login
Tl1Command loginCmd = DefaultTl1Command.builder().withVerb(ACT).withModifier(USER).withAid(device.get().username()).withCtag(100).withParameters(device.get().password()).build();
Future<String> login = ctrl.sendMsg(deviceId, loginCmd);
try {
String loginResponse = login.get(TIMEOUT, TimeUnit.MILLISECONDS);
if (loginResponse.contains("Access denied")) {
log.error("Access denied: {}", loginResponse);
return defaultDescription;
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Login failed", e);
return defaultDescription;
}
// Fetch device description
Tl1Command ddCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(NETYPE).withCtag(101).build();
Future<String> dd = ctrl.sendMsg(deviceId, ddCmd);
try {
String ddResponse = dd.get(TIMEOUT, TimeUnit.MILLISECONDS);
return new DefaultDeviceDescription(defaultDescription, true, extractAnnotations(ddResponse));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
log.error("Device description not found", e);
return defaultDescription;
}
}
use of org.onosproject.tl1.Tl1Device in project onos by opennetworkinglab.
the class Tl1DeviceProvider method isReachable.
// Assumes device is registered in TL1 controller.
@Override
public boolean isReachable(DeviceId deviceId) {
try {
// First check if device is already connected.
// If not, try to open a socket.
Tl1Device device = controller.getDevice(deviceId).get();
if (device.isConnected()) {
return true;
}
Socket socket = new Socket();
socket.connect(new InetSocketAddress(device.ip().toInetAddress(), device.port()), REACHABILITY_TIMEOUT);
socket.close();
return true;
} catch (NoSuchElementException | IOException | IllegalArgumentException e) {
log.error("Cannot reach device {}", deviceId, e);
return false;
}
}
Aggregations