blob: 45d81d27e765b408c9091234ead3fa4a1d243629 [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
andreaeb70a942015-10-16 21:34:46 -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 */
16
17package org.onosproject.netconf;
18
19import org.onlab.packet.IpAddress;
20import org.onosproject.net.DeviceId;
21
22import java.util.Map;
Andrea Campanella86294db2016-03-07 11:42:49 -080023import java.util.Set;
gyewan.an91d7e7e2019-01-17 15:12:48 +090024import java.util.concurrent.CompletableFuture;
andreaeb70a942015-10-16 21:34:46 -070025
26/**
27 * Abstraction of an NETCONF controller. Serves as a one stop shop for obtaining
28 * NetconfDevice and (un)register listeners on NETCONF device events.
29 */
30public interface NetconfController {
31
32 /**
33 * Adds Device Event Listener.
34 *
35 * @param listener node listener
36 */
37 void addDeviceListener(NetconfDeviceListener listener);
38
39 /**
40 * Removes Device Listener.
41 *
42 * @param listener node listener
43 */
44 void removeDeviceListener(NetconfDeviceListener listener);
45
46 /**
47 * Tries to connect to a specific NETCONF device, if the connection is succesful
48 * it creates and adds the device to the ONOS core as a NetconfDevice.
49 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070050 * @param deviceId deviceId of the device to connect
andreaeb70a942015-10-16 21:34:46 -070051 * @return NetconfDevice Netconf device
Andrea Campanella101417d2015-12-11 17:58:07 -080052 * @throws NetconfException when device is not available
andreaeb70a942015-10-16 21:34:46 -070053 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070054 NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070055
56 /**
gyewan.an91d7e7e2019-01-17 15:12:48 +090057 * Tries to connect to a specific NETCONF device, if the connection is succesful
58 * it creates and adds the device to the ONOS core as a NetconfDevice.
59 * If isMaster true: Will create two sessions for a device : secure transport session and proxy session.
60 * If isMaster false: Will create only proxy session.
61 * @param deviceId deviceId of the device to connect
62 * @param isMaster if the controller is master for the device
63 * @return NetconfDevice Netconf device
64 * @throws NetconfException when device is not available
65 */
66 default NetconfDevice connectDevice(DeviceId deviceId, boolean isMaster) throws NetconfException {
67 return connectDevice(deviceId);
68 }
69
70 /**
Andrea Campanella86294db2016-03-07 11:42:49 -080071 * Disconnects a Netconf device and removes it from the core.
72 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070073 * @param deviceId id of the device to remove
74 * @param remove true if device is to be removed from core
Andrea Campanella86294db2016-03-07 11:42:49 -080075 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070076 void disconnectDevice(DeviceId deviceId, boolean remove);
Andrea Campanella86294db2016-03-07 11:42:49 -080077
78 /**
79 * Removes a Netconf device from the core.
andreaeb70a942015-10-16 21:34:46 -070080 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070081 * @param deviceId id of the device to remove
andreaeb70a942015-10-16 21:34:46 -070082 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070083 void removeDevice(DeviceId deviceId);
andreaeb70a942015-10-16 21:34:46 -070084
85 /**
86 * Gets all the nodes information.
87 *
88 * @return map of devices
89 */
90 Map<DeviceId, NetconfDevice> getDevicesMap();
91
92 /**
Andrea Campanella86294db2016-03-07 11:42:49 -080093 * Gets all Netconf Devices.
94 *
95 * @return List of all the NetconfDevices Ids
96 */
97 Set<DeviceId> getNetconfDevices();
98
99 /**
andreaeb70a942015-10-16 21:34:46 -0700100 * Gets a Netconf Device by node identifier.
101 *
102 * @param deviceInfo node identifier
103 * @return NetconfDevice Netconf device
104 */
105 NetconfDevice getNetconfDevice(DeviceId deviceInfo);
106
107 /**
108 * Gets a Netconf Device by node identifier.
109 *
110 * @param ip device ip
111 * @param port device port
112 * @return NetconfDevice Netconf device
113 */
114 NetconfDevice getNetconfDevice(IpAddress ip, int port);
David K. Bainbridge56e90232018-12-18 23:25:08 -0800115
116 /**
117 * Gets a Netconf Device by node identifier.
118 *
119 * @param ip device ip
120 * @param port device port
121 * @param path device path
122 * @return NetconfDevice Netconf device
123 */
124 NetconfDevice getNetconfDevice(IpAddress ip, int port, String path);
gyewan.an91d7e7e2019-01-17 15:12:48 +0900125
126 /**
127 * If master, will execute the call locally else will use
128 * clusterCommunicationManager to execute at master controller.
129 * Meant only for internal synchronization and not to be used by applications.
130 *
131 * @param proxyMessage proxy message
132 * @param <T> return type
133 * @return Completable future of class T
134 * @throws NetconfException netconf exception
135 */
136 default <T> CompletableFuture<T> executeAtMaster(NetconfProxyMessage proxyMessage) throws NetconfException {
137 CompletableFuture<T> errorFuture = new CompletableFuture<>();
138 errorFuture.completeExceptionally(new NetconfException("Method executeAtMaster not implemented"));
139 return errorFuture;
140 }
andreaeb70a942015-10-16 21:34:46 -0700141}