blob: 8b9c0d3a7645167c80fd6fadfbe8e1ed5f7e320d [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08003 *
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 org.onosproject.net.Annotations;
19
Andrea Campanella80520b82016-01-05 17:55:29 -080020import java.util.List;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080021import java.util.Map;
Yuta HIGUCHId6587b92018-04-06 19:15:10 -070022import java.util.Optional;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080023import java.util.Set;
24
25/**
26 * Representation of a specific family of device drivers. Behaviour configuration
27 * data is stored using {@link org.onosproject.net.Annotations}.
28 */
29public interface Driver extends Annotations {
30
31 /**
32 * Returns the driver name. This is expected to be a reverse-DNS,
33 * Java package-like name.
34 *
35 * @return driver name
36 */
37 String name();
38
39 /**
Thomas Vachuska635c2d72015-05-08 14:32:13 -070040 * Returns the parent driver from which this driver inherits behaviours
41 * and properties.
42 *
43 * @return parent driver; null if driver has no parent
Ray Milkeyea125322016-02-16 13:35:09 -080044 * @deprecated 1.5.0 Falcon Release
Thomas Vachuska635c2d72015-05-08 14:32:13 -070045 */
Andrea Campanella80520b82016-01-05 17:55:29 -080046 @Deprecated
Thomas Vachuska635c2d72015-05-08 14:32:13 -070047 Driver parent();
48
49 /**
Andrea Campanella80520b82016-01-05 17:55:29 -080050 * Returns all the parent drivers from which this driver inherits behaviours
51 * and properties.
52 *
sangyun-han04c461d2017-03-02 20:29:39 +090053 * @return list of parent drivers
Andrea Campanella80520b82016-01-05 17:55:29 -080054 */
55 List<Driver> parents();
56
57 /**
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080058 * Returns the device manufacturer name.
59 *
60 * @return manufacturer name
61 */
62 String manufacturer();
63
64 /**
65 * Returns the device hardware version.
66 *
67 * @return hardware version
68 */
69 String hwVersion();
70
71 /**
72 * Returns the device software version.
73 *
74 * @return software version
75 */
76 String swVersion();
77
78 /**
79 * Returns the set of behaviours supported by this driver.
Thomas Vachuska635c2d72015-05-08 14:32:13 -070080 * It reflects behaviours of only this driver and not its parent.
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080081 *
82 * @return set of device driver behaviours
83 */
84 Set<Class<? extends Behaviour>> behaviours();
85
86 /**
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070087 * Returns the implementation class for the specified behaviour.
Thomas Vachuska635c2d72015-05-08 14:32:13 -070088 * It reflects behaviours of only this driver and not its parent.
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070089 *
90 * @param behaviour behaviour interface
91 * @return implementation class
92 */
93 Class<? extends Behaviour> implementation(Class<? extends Behaviour> behaviour);
94
95 /**
Thomas Vachuska635c2d72015-05-08 14:32:13 -070096 * Indicates whether or not the driver, or any of its parents, support
HIGUCHI Yuta82b3c112016-01-07 22:22:26 -080097 * the specified class of behaviour.
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080098 *
99 * @param behaviourClass behaviour class
100 * @return true if behaviour is supported
101 */
102 boolean hasBehaviour(Class<? extends Behaviour> behaviourClass);
103
104 /**
105 * Creates an instance of behaviour primed with the specified driver data.
Thomas Vachuska635c2d72015-05-08 14:32:13 -0700106 * If the current driver does not support the specified behaviour and the
107 * driver has parent, the request is delegated to the parent driver.
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -0800108 *
109 * @param data driver data context
110 * @param behaviourClass driver behaviour class
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -0800111 * @param <T> type of behaviour
112 * @return behaviour instance
113 */
Thomas Vachuskafacc3f52015-04-10 08:58:36 -0700114 <T extends Behaviour> T createBehaviour(DriverData data, Class<T> behaviourClass);
115
116 /**
Thomas Vachuskaf133bb12016-03-31 08:54:49 -0700117 * Creates an instance of behaviour primed with the specified driver handler.
Thomas Vachuska635c2d72015-05-08 14:32:13 -0700118 * If the current driver does not support the specified behaviour and the
119 * driver has parent, the request is delegated to the parent driver.
Thomas Vachuskafacc3f52015-04-10 08:58:36 -0700120 *
121 * @param handler driver handler context
122 * @param behaviourClass driver behaviour class
123 * @param <T> type of behaviour
124 * @return behaviour instance
125 */
126 <T extends Behaviour> T createBehaviour(DriverHandler handler, Class<T> behaviourClass);
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -0800127
128 /**
129 * Returns the set of annotations as map of key/value properties.
130 *
131 * @return map of properties
132 */
133 Map<String, String> properties();
134
Thomas Vachuska5c2f8132015-04-08 23:09:08 -0700135 /**
Charles Chana59f9b762017-07-30 18:09:44 -0700136 * Gets the value of given property name.
137 * If the driver does not define the property, a BFS will be performed to search its ancestors.
138 *
139 * @param name property name
140 * @return the value of the property,
141 * or null if the property is not defined in this driver nor in any of its ancestors
142 */
143 String getProperty(String name);
144
145 /**
Yuta HIGUCHId6587b92018-04-06 19:15:10 -0700146 * Gets the value of given property name.
147 * If the driver does not define the property, a BFS will be performed to search its ancestors.
148 *
149 * @param name property name
150 * @param defaultValue to use if the property is not defined in this driver nor in any of its ancestors
151 * @return the value of the property,
152 * or {@code defaultValue} if the property is not defined in this driver nor in any of its ancestors
Yuta HIGUCHId6587b92018-04-06 19:15:10 -0700153 */
154 default String getProperty(String name, String defaultValue) {
155 return Optional.ofNullable(getProperty(name)).orElse(defaultValue);
156 }
157
158 /**
Thomas Vachuska5c2f8132015-04-08 23:09:08 -0700159 * Merges the specified driver behaviours and properties into this one,
160 * giving preference to the other driver when dealing with conflicts.
161 *
162 * @param other other driver
163 * @return merged driver
164 */
165 Driver merge(Driver other);
166
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -0800167}