blob: ffb7deb5fc724860745d4cf532a79e809808e9de [file] [log] [blame]
Andrea Campanella241896c2017-05-10 13:11:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Andrea Campanella241896c2017-05-10 13:11:04 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.driver;
17
18import com.google.common.annotations.Beta;
19
Andrea Campanella241896c2017-05-10 13:11:04 -070020/**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070021 * Abstraction of handler behaviour used to set-up and tear-down connections
Carmelo Cascone3977ea42019-02-28 13:43:42 -080022 * with a device. A connection is intended as the presence of state (e.g. a
23 * transport session) required to carry messages between this node and the
24 * device.
Andrea Campanella241896c2017-05-10 13:11:04 -070025 */
26@Beta
27public interface DeviceConnect extends HandlerBehaviour {
28
29 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070030 * Connects to the device, for example by opening the transport session that
31 * will be later used to send control messages. Returns true if the
Carmelo Casconec2be50a2019-04-10 00:15:39 -070032 * connection was created successfully, false otherwise.
33 * <p>
34 * The implementation should trigger without blocking any necessary
35 * handshake with the device to initialize the connection over the network,
36 * eventually generating a {@link org.onosproject.net.device.DeviceAgentEvent.Type#CHANNEL_OPEN}
37 * event when ready.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070038 * <p>
Carmelo Cascone3977ea42019-02-28 13:43:42 -080039 * When calling this method while a connection to the device already exists,
40 * the behavior is not defined. For example, some implementations might
41 * require to first call {@link #disconnect()}, while other might behave as
42 * a no-op.
Andrea Campanella241896c2017-05-10 13:11:04 -070043 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070044 * @return true if a connection was created successfully, false otherwise
Carmelo Cascone3977ea42019-02-28 13:43:42 -080045 * @throws IllegalStateException if a connection already exists and the
46 * implementation requires to call {@link
47 * #disconnect()} first.
Andrea Campanella241896c2017-05-10 13:11:04 -070048 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070049 boolean connect() throws IllegalStateException;
Andrea Campanella241896c2017-05-10 13:11:04 -070050
51 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -080052 * Returns true if a connection to the device exists, false otherwise. This
53 * method is NOT expected to send any message over the network to check for
54 * device reachability, but rather it should only give an indication if any
55 * internal connection state exists for the device. As such, it should NOT
56 * block execution.
57 * <p>
58 * In general, when called after {@link #connect()} it should always return
59 * true, while it is expected to always return false after calling {@link
60 * #disconnect()} or if {@link #connect()} was never called.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070061 *
62 * @return true if the connection is open, false otherwise
63 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070064 boolean hasConnection();
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070065
66 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070067 * Disconnects from the device, for example closing any transport session
Carmelo Cascone3977ea42019-02-28 13:43:42 -080068 * previously opened.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070069 * <p>
70 * Calling multiple times this method while a connection to the device is
Carmelo Cascone3977ea42019-02-28 13:43:42 -080071 * already closed should result in a no-op.
Carmelo Casconec2be50a2019-04-10 00:15:39 -070072 * <p>
73 * If a connection to the device existed and it was open, the implementation
74 * is expected to generate a
75 * {@link org.onosproject.net.device.DeviceAgentEvent.Type#CHANNEL_CLOSED}
76 * event.
Andrea Campanella241896c2017-05-10 13:11:04 -070077 */
Carmelo Cascone3977ea42019-02-28 13:43:42 -080078 void disconnect();
Andrea Campanella241896c2017-05-10 13:11:04 -070079}