blob: 12b5e516c804b013e7c3aa8f7fda54c4941391b5 [file] [log] [blame]
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -08001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
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.
Ramon Casellas390efe92018-03-01 11:45:27 +010015 *
16 *
17 * This work was partially supported by EC H2020 project METRO-HAUL (761727).
18 * Contact: Ramon Casellas <ramon.casellas@cttc.es>
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -080019 */
Ramon Casellas390efe92018-03-01 11:45:27 +010020
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -080021package org.onosproject.odtn.impl;
22
Ramon Casellas390efe92018-03-01 11:45:27 +010023import java.util.List;
24
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -080025import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Deactivate;
28import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -080030import org.onosproject.net.config.NetworkConfigService;
31import org.onosproject.yang.model.SchemaContextProvider;
32import org.onosproject.yang.runtime.YangRuntimeService;
33import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
Ramon Casellas390efe92018-03-01 11:45:27 +010036import org.onosproject.config.DynamicConfigListener;
37import org.onosproject.config.DynamicConfigService;
38import org.onosproject.config.DynamicConfigEvent;
39import org.onosproject.config.Filter;
40import org.onosproject.config.FailedException;
41import static org.onosproject.config.DynamicConfigEvent.Type.NODE_ADDED;
42import static org.onosproject.config.DynamicConfigEvent.Type.NODE_DELETED;
43
44// import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180216.TapiConnectivity;
45import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180216.TapiConnectivityService;
46
47import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180216.
48 tapiconnectivity.createconnectivityservice.CreateConnectivityServiceInput;
49
50import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180216.
51 tapiconnectivity.createconnectivityservice.createconnectivityserviceinput.EndPoint;
52
53
54
55// onos-yang-tools
56import org.onosproject.yang.model.DataNode;
57
58import org.onosproject.yang.model.NodeKey;
59import org.onosproject.yang.model.ResourceData;
60import org.onosproject.yang.model.DefaultResourceData;
61import org.onosproject.yang.model.ModelObject;
62import org.onosproject.yang.model.ModelObjectData;
63import org.onosproject.yang.model.ModelConverter;
64
65import org.onosproject.yang.model.ResourceId;
66import org.onosproject.yang.model.SchemaId;
67
68import org.onosproject.yang.model.RpcRegistry;
69import org.onosproject.yang.model.RpcService;
70import org.onosproject.yang.model.RpcInput;
71import org.onosproject.yang.model.RpcOutput;
72
73
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -080074/**
75 * OSGi Component for ODTN Service application.
76 */
77@Component(immediate = true)
78public class ServiceApplicationComponent {
79
80 private final Logger log = LoggerFactory.getLogger(getClass());
81
82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected DynamicConfigService dynConfigService;
84
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 protected NetworkConfigService netcfgService;
87
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 protected YangRuntimeService yangRuntime;
90
91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 protected SchemaContextProvider schemaContextProvider;
93
Ramon Casellas390efe92018-03-01 11:45:27 +010094 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected RpcRegistry rpcRegistry;
96
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 protected ModelConverter modelConverter;
99
100
101
102 // Listener for events from the DCS
103 private final DynamicConfigListener dynamicConfigServiceListener =
104 new InternalDynamicConfigListener();
105
106 // Rpc Service for TAPI Connectivity
107 private final RpcService rpcTapiConnectivity =
108 new TapiConnectivityRpc();
109
110
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800111 @Activate
112 protected void activate() {
113 log.info("Started");
Ramon Casellas390efe92018-03-01 11:45:27 +0100114 dynConfigService.addListener(dynamicConfigServiceListener);
115 rpcRegistry.registerRpcService(rpcTapiConnectivity);
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800116 }
117
Ramon Casellas390efe92018-03-01 11:45:27 +0100118
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800119 @Deactivate
120 protected void deactivate() {
121 log.info("Stopped");
Ramon Casellas390efe92018-03-01 11:45:27 +0100122 rpcRegistry.unregisterRpcService(rpcTapiConnectivity);
123 dynConfigService.removeListener(dynamicConfigServiceListener);
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800124 }
125
Ramon Casellas390efe92018-03-01 11:45:27 +0100126
127
128
129 /**
130 * Representation of internal listener, listening for dynamic config event.
131 */
132 private class InternalDynamicConfigListener implements DynamicConfigListener {
133
134 /**
135 * Check if the DCS event should be further processed.
136 *
137 * @param event config event
138 * @return true if event is supported; false otherwise
139 */
140 @Override
141 public boolean isRelevant(DynamicConfigEvent event) {
142 // Only care about add and delete
143 if ((event.type() != NODE_ADDED) &&
144 (event.type() != NODE_DELETED)) {
145 return false;
146 }
147 return true;
148 }
149
150
151
152
153 /**
154 * Process an Event from the Dynamic Configuration Store.
155 *
156 * @param event config event
157 */
158 @Override
159 public void event(DynamicConfigEvent event) {
160 ResourceId rsId = event.subject();
161 DataNode node;
162 try {
163 Filter filter = Filter.builder().addCriteria(rsId).build();
164 node = dynConfigService.readNode(rsId, filter);
165 } catch (FailedException e) {
166 node = null;
167 }
168 switch (event.type()) {
169 case NODE_ADDED:
170 onDcsNodeAdded(rsId, node);
171 break;
172
173 case NODE_DELETED:
174 onDcsNodeDeleted(node);
175 break;
176
177 default:
178 log.warn("Unknown Event", event.type());
179 break;
180 }
181 }
182
183
184
185 /**
186 * Process the event that a node has been added to the DCS.
187 *
188 * @param rsId ResourceId of the added node
189 * @param node added node. Access the key and value
190 */
191 private void onDcsNodeAdded(ResourceId rsId, DataNode node) {
192 switch (node.type()) {
193 case SINGLE_INSTANCE_NODE:
194 break;
195 case MULTI_INSTANCE_NODE:
196 break;
197 case SINGLE_INSTANCE_LEAF_VALUE_NODE:
198 break;
199 case MULTI_INSTANCE_LEAF_VALUE_NODE:
200 break;
201 default:
202 break;
203 }
204
205 NodeKey dataNodeKey = node.key();
206 SchemaId schemaId = dataNodeKey.schemaId();
207 if (!schemaId.namespace().contains("tapi")) {
208 return;
209 }
210
211 // Consolidate events
212 log.info("namespace {}", schemaId.namespace());
213 }
214
215
216 /**
217 * Process the event that a node has been deleted from the DCS.
218 *
219 * @param dataNode data node
220 */
221 private void onDcsNodeDeleted(DataNode dataNode) {
222 // TODO: Implement release logic
223 }
224
225 }
226
227
228
229
230
231 private class TapiConnectivityRpc implements TapiConnectivityService {
232
233
234 /**
235 * Service interface of createConnectivityService.
236 *
237 * @param inputVar input of service interface createConnectivityService
238 * @return rpcOutput output of service interface createConnectivityService
239 */
240 public RpcOutput createConnectivityService(RpcInput inputVar) {
241 DataNode data = inputVar.data();
242 ResourceId rid = inputVar.id();
243
244 log.info("RpcInput Data {}", data);
245 log.info("RpcInput ResourceId {}", rid);
246
247 for (ModelObject mo : getModelObjects(data, rid)) {
248 if (mo instanceof CreateConnectivityServiceInput) {
249 CreateConnectivityServiceInput i = (CreateConnectivityServiceInput) mo;
250 log.info("i {}", i);
251 List<EndPoint> epl = i.endPoint();
252 for (EndPoint ep : epl) {
253 log.info("ep {}", ep);
254 }
255 }
256 }
257
258 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
259 }
260
261
262
263 /**
264 * Service interface of deleteConnectivityService.
265 *
266 * @param inputVar input of service interface deleteConnectivityService
267 * @return rpcOutput output of service interface deleteConnectivityService
268 */
269 public RpcOutput deleteConnectivityService(RpcInput inputVar) {
270 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
271 }
272
273
274
275 /**
276 * Service interface of getConnectionDetails.
277 *
278 * @param inputVar input of service interface getConnectionDetails
279 * @return rpcOutput output of service interface getConnectionDetails
280 */
281 public RpcOutput getConnectionDetails(RpcInput inputVar) {
282 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
283
284 }
285
286 /**
287 * Service interface of getConnectivityServiceList.
288 *
289 * @param inputVar input of service interface getConnectivityServiceList
290 * @return rpcOutput output of service interface getConnectivityServiceList
291 */
292 public RpcOutput getConnectivityServiceList(RpcInput inputVar) {
293 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
294
295 }
296
297 /**
298 * Service interface of getConnectivityServiceDetails.
299 *
300 * @param inputVar input of service interface getConnectivityServiceDetails
301 * @return rpcOutput output of service interface getConnectivityServiceDetails
302 */
303 public RpcOutput getConnectivityServiceDetails(RpcInput inputVar) {
304 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
305
306 }
307
308
309 /**
310 * Service interface of updateConnectivityService.
311 *
312 * @param inputVar input of service interface updateConnectivityService
313 * @return rpcOutput output of service interface updateConnectivityService
314 */
315 public RpcOutput updateConnectivityService(RpcInput inputVar) {
316 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
317
318 }
319
320
321 private ResourceData createResourceData(DataNode dataNode, ResourceId resId) {
322 return DefaultResourceData.builder()
323 .addDataNode(dataNode)
324 .resourceId(resId)
325 .build();
326 }
327
328 /**
329 * Returns model objects of the store.
330 *
331 * @param dataNode data node from store
332 * @param resId parent resource id
333 * @return model objects
334 */
335 private List<ModelObject> getModelObjects(DataNode dataNode, ResourceId resId) {
336 ResourceData data = createResourceData(dataNode, resId);
337 ModelObjectData modelData = modelConverter.createModel(data);
338 return modelData.modelObjects();
339 }
340
341
342
343 }
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800344}