Search in sources :

Example 1 with Tl1Command

use of org.onosproject.tl1.Tl1Command 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);
    }
}
Also used : Tl1Command(org.onosproject.tl1.Tl1Command) DefaultTl1Command(org.onosproject.tl1.DefaultTl1Command) Tl1Controller(org.onosproject.tl1.Tl1Controller) DeviceId(org.onosproject.net.DeviceId) Tl1Device(org.onosproject.tl1.Tl1Device) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with Tl1Command

use of org.onosproject.tl1.Tl1Command 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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) Channel(io.netty.channel.Channel) Tl1Device(org.onosproject.tl1.Tl1Device)

Example 3 with Tl1Command

use of org.onosproject.tl1.Tl1Command 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;
    }
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) Tl1Command(org.onosproject.tl1.Tl1Command) DefaultTl1Command(org.onosproject.tl1.DefaultTl1Command) DeviceId(org.onosproject.net.DeviceId) Tl1Controller(org.onosproject.tl1.Tl1Controller) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Tl1Device(org.onosproject.tl1.Tl1Device) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Tl1Command

use of org.onosproject.tl1.Tl1Command in project onos by opennetworkinglab.

the class LumentumWaveReadyDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId deviceId = handler().data().deviceId();
    Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
    // Assume we're successfully logged in
    // Fetch port descriptions
    Tl1Command pdCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(PLUGGABLE_INV).withCtag(102).build();
    Future<String> pd = ctrl.sendMsg(deviceId, pdCmd);
    try {
        String pdResponse = pd.get(TIMEOUT, TimeUnit.MILLISECONDS);
        return extractPorts(pdResponse);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Port description not found", e);
        return Collections.EMPTY_LIST;
    }
}
Also used : Tl1Command(org.onosproject.tl1.Tl1Command) DefaultTl1Command(org.onosproject.tl1.DefaultTl1Command) Tl1Controller(org.onosproject.tl1.Tl1Controller) DeviceId(org.onosproject.net.DeviceId) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultTl1Command (org.onosproject.tl1.DefaultTl1Command)3 Tl1Command (org.onosproject.tl1.Tl1Command)3 Tl1Controller (org.onosproject.tl1.Tl1Controller)3 Tl1Device (org.onosproject.tl1.Tl1Device)3 Channel (io.netty.channel.Channel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ChassisId (org.onlab.packet.ChassisId)1 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)1 DeviceDescription (org.onosproject.net.device.DeviceDescription)1