blob: 87ae4f4829a9fee14bd7c3f428cfda7a1ddc172d [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;
Yuta HIGUCHI348bba72018-03-08 13:46:48 -080045import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.TapiConnectivityService;
Ramon Casellas390efe92018-03-01 11:45:27 +010046
Yuta HIGUCHI348bba72018-03-08 13:46:48 -080047import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.
Ramon Casellas390efe92018-03-01 11:45:27 +010048 tapiconnectivity.createconnectivityservice.CreateConnectivityServiceInput;
49
Yuta HIGUCHI348bba72018-03-08 13:46:48 -080050import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.
Ramon Casellas390efe92018-03-01 11:45:27 +010051 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 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800240 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100241 public RpcOutput createConnectivityService(RpcInput inputVar) {
242 DataNode data = inputVar.data();
243 ResourceId rid = inputVar.id();
244
245 log.info("RpcInput Data {}", data);
246 log.info("RpcInput ResourceId {}", rid);
247
248 for (ModelObject mo : getModelObjects(data, rid)) {
249 if (mo instanceof CreateConnectivityServiceInput) {
250 CreateConnectivityServiceInput i = (CreateConnectivityServiceInput) mo;
251 log.info("i {}", i);
252 List<EndPoint> epl = i.endPoint();
253 for (EndPoint ep : epl) {
254 log.info("ep {}", ep);
255 }
256 }
257 }
258
259 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
260 }
261
262
263
264 /**
265 * Service interface of deleteConnectivityService.
266 *
267 * @param inputVar input of service interface deleteConnectivityService
268 * @return rpcOutput output of service interface deleteConnectivityService
269 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800270 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100271 public RpcOutput deleteConnectivityService(RpcInput inputVar) {
272 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
273 }
274
275
276
277 /**
278 * Service interface of getConnectionDetails.
279 *
280 * @param inputVar input of service interface getConnectionDetails
281 * @return rpcOutput output of service interface getConnectionDetails
282 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800283 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100284 public RpcOutput getConnectionDetails(RpcInput inputVar) {
285 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
286
287 }
288
289 /**
290 * Service interface of getConnectivityServiceList.
291 *
292 * @param inputVar input of service interface getConnectivityServiceList
293 * @return rpcOutput output of service interface getConnectivityServiceList
294 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800295 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100296 public RpcOutput getConnectivityServiceList(RpcInput inputVar) {
297 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
298
299 }
300
301 /**
302 * Service interface of getConnectivityServiceDetails.
303 *
304 * @param inputVar input of service interface getConnectivityServiceDetails
305 * @return rpcOutput output of service interface getConnectivityServiceDetails
306 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800307 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100308 public RpcOutput getConnectivityServiceDetails(RpcInput inputVar) {
309 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
310
311 }
312
313
314 /**
315 * Service interface of updateConnectivityService.
316 *
317 * @param inputVar input of service interface updateConnectivityService
318 * @return rpcOutput output of service interface updateConnectivityService
319 */
Yuta HIGUCHI348bba72018-03-08 13:46:48 -0800320 @Override
Ramon Casellas390efe92018-03-01 11:45:27 +0100321 public RpcOutput updateConnectivityService(RpcInput inputVar) {
322 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
323
324 }
325
326
327 private ResourceData createResourceData(DataNode dataNode, ResourceId resId) {
328 return DefaultResourceData.builder()
329 .addDataNode(dataNode)
330 .resourceId(resId)
331 .build();
332 }
333
334 /**
335 * Returns model objects of the store.
336 *
337 * @param dataNode data node from store
338 * @param resId parent resource id
339 * @return model objects
340 */
341 private List<ModelObject> getModelObjects(DataNode dataNode, ResourceId resId) {
342 ResourceData data = createResourceData(dataNode, resId);
343 ModelObjectData modelData = modelConverter.createModel(data);
344 return modelData.modelObjects();
345 }
346
347
348
349 }
Yuta HIGUCHIa9ae6e62018-02-26 12:56:20 -0800350}