blob: daf92fa8dbcbe72b0efd8690880f5b92a8fca3ec [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
gyewan.an3c99ee72019-02-18 15:53:55 +09002 * Copyright 2019-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;
gyewan.an3c99ee72019-02-18 15:53:55 +090020import org.onosproject.cluster.NodeId;
andreaeb70a942015-10-16 21:34:46 -070021import org.onosproject.net.DeviceId;
22
23import java.util.Map;
Andrea Campanella86294db2016-03-07 11:42:49 -080024import java.util.Set;
gyewan.an91d7e7e2019-01-17 15:12:48 +090025import java.util.concurrent.CompletableFuture;
andreaeb70a942015-10-16 21:34:46 -070026
27/**
28 * Abstraction of an NETCONF controller. Serves as a one stop shop for obtaining
29 * NetconfDevice and (un)register listeners on NETCONF device events.
30 */
31public interface NetconfController {
32
33 /**
34 * Adds Device Event Listener.
35 *
36 * @param listener node listener
37 */
38 void addDeviceListener(NetconfDeviceListener listener);
39
40 /**
41 * Removes Device Listener.
42 *
43 * @param listener node listener
44 */
45 void removeDeviceListener(NetconfDeviceListener listener);
46
47 /**
48 * Tries to connect to a specific NETCONF device, if the connection is succesful
49 * it creates and adds the device to the ONOS core as a NetconfDevice.
50 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070051 * @param deviceId deviceId of the device to connect
andreaeb70a942015-10-16 21:34:46 -070052 * @return NetconfDevice Netconf device
Andrea Campanella101417d2015-12-11 17:58:07 -080053 * @throws NetconfException when device is not available
andreaeb70a942015-10-16 21:34:46 -070054 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070055 NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070056
57 /**
gyewan.an91d7e7e2019-01-17 15:12:48 +090058 * Tries to connect to a specific NETCONF device, if the connection is succesful
59 * it creates and adds the device to the ONOS core as a NetconfDevice.
60 * If isMaster true: Will create two sessions for a device : secure transport session and proxy session.
61 * If isMaster false: Will create only proxy session.
62 * @param deviceId deviceId of the device to connect
63 * @param isMaster if the controller is master for the device
64 * @return NetconfDevice Netconf device
65 * @throws NetconfException when device is not available
66 */
67 default NetconfDevice connectDevice(DeviceId deviceId, boolean isMaster) throws NetconfException {
68 return connectDevice(deviceId);
69 }
70
71 /**
Andrea Campanella86294db2016-03-07 11:42:49 -080072 * Disconnects a Netconf device and removes it from the core.
73 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070074 * @param deviceId id of the device to remove
75 * @param remove true if device is to be removed from core
Andrea Campanella86294db2016-03-07 11:42:49 -080076 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070077 void disconnectDevice(DeviceId deviceId, boolean remove);
Andrea Campanella86294db2016-03-07 11:42:49 -080078
79 /**
80 * Removes a Netconf device from the core.
andreaeb70a942015-10-16 21:34:46 -070081 *
Andrea Campanella7e6200a2016-03-21 09:48:40 -070082 * @param deviceId id of the device to remove
andreaeb70a942015-10-16 21:34:46 -070083 */
Andrea Campanella7e6200a2016-03-21 09:48:40 -070084 void removeDevice(DeviceId deviceId);
andreaeb70a942015-10-16 21:34:46 -070085
86 /**
87 * Gets all the nodes information.
88 *
89 * @return map of devices
90 */
91 Map<DeviceId, NetconfDevice> getDevicesMap();
92
93 /**
Andrea Campanella86294db2016-03-07 11:42:49 -080094 * Gets all Netconf Devices.
95 *
96 * @return List of all the NetconfDevices Ids
97 */
98 Set<DeviceId> getNetconfDevices();
99
100 /**
andreaeb70a942015-10-16 21:34:46 -0700101 * Gets a Netconf Device by node identifier.
102 *
103 * @param deviceInfo node identifier
104 * @return NetconfDevice Netconf device
105 */
106 NetconfDevice getNetconfDevice(DeviceId deviceInfo);
107
108 /**
109 * Gets a Netconf Device by node identifier.
110 *
111 * @param ip device ip
112 * @param port device port
113 * @return NetconfDevice Netconf device
114 */
115 NetconfDevice getNetconfDevice(IpAddress ip, int port);
David K. Bainbridge56e90232018-12-18 23:25:08 -0800116
117 /**
118 * Gets a Netconf Device by node identifier.
119 *
120 * @param ip device ip
121 * @param port device port
122 * @param path device path
123 * @return NetconfDevice Netconf device
124 */
125 NetconfDevice getNetconfDevice(IpAddress ip, int port, String path);
gyewan.an91d7e7e2019-01-17 15:12:48 +0900126
127 /**
128 * If master, will execute the call locally else will use
129 * clusterCommunicationManager to execute at master controller.
130 * Meant only for internal synchronization and not to be used by applications.
131 *
132 * @param proxyMessage proxy message
133 * @param <T> return type
134 * @return Completable future of class T
135 * @throws NetconfException netconf exception
136 */
137 default <T> CompletableFuture<T> executeAtMaster(NetconfProxyMessage proxyMessage) throws NetconfException {
138 CompletableFuture<T> errorFuture = new CompletableFuture<>();
139 errorFuture.completeExceptionally(new NetconfException("Method executeAtMaster not implemented"));
140 return errorFuture;
141 }
gyewan.an3c99ee72019-02-18 15:53:55 +0900142
143 /**
144 * Get a contoller node Id .
145 *
146 * @return controller node Id
147 */
148 default NodeId getLocalNodeId() {
149 return null;
150 }
andreaeb70a942015-10-16 21:34:46 -0700151}