blob: 315e10c231b68dd064cf5e367cc80915a5ae8e7c [file] [log] [blame]
hirokif4ed5212018-05-26 22:39:38 -07001/*
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.
15 */
16
17package org.onosproject.odtn.internal;
18
19import org.onosproject.config.DynamicConfigService;
20import org.onosproject.odtn.TapiResolver;
21import org.onosproject.odtn.utils.tapi.TapiGetSipListOutputHandler;
22import org.onosproject.yang.gen.v1.tapicommon.rev20180307.TapiCommonService;
23import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
24import org.onosproject.yang.model.ModelConverter;
25import org.onosproject.yang.model.RpcInput;
26import org.onosproject.yang.model.RpcOutput;
27
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
31import static org.onlab.osgi.DefaultServiceDirectory.getService;
32
33/**
34 * DCS-dependent tapi-common yang RPCs implementation.
35 */
36public class DcsBasedTapiCommonRpc implements TapiCommonService {
37
38 private final Logger log = LoggerFactory.getLogger(getClass());
39
40 protected DynamicConfigService dcs;
41 protected ModelConverter modelConverter;
42 protected TapiResolver resolver;
43
44 public void init() {
45 dcs = getService(DynamicConfigService.class);
46 modelConverter = getService(ModelConverter.class);
47 resolver = getService(TapiResolver.class);
48 }
49
50 /**
51 * Service interface of getServiceInterfacePointDetails.
52 *
53 * @param rpcInput input of service interface getServiceInterfacePointDetails
54 * @return rpcOutput output of service interface getServiceInterfacePointDetails
55 */
56 @Override
57 public RpcOutput getServiceInterfacePointDetails(RpcInput rpcInput) {
58 log.error("Not implemented");
59 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
60 }
61
62 /**
63 * Service interface of getServiceInterfacePointList.
64 *
65 * @param rpcInput input of service interface getServiceInterfacePointList
66 * @return rpcOutput output of service interface getServiceInterfacePointList
67 */
68 @Override
69 public RpcOutput getServiceInterfacePointList(RpcInput rpcInput) {
70
71 try {
72 TapiGetSipListOutputHandler output = TapiGetSipListOutputHandler.create();
73
74 resolver.getNepRefs().stream()
75 .filter(nepRef -> nepRef.getSipId() != null)
76 .forEach(nepRef -> {
77 output.addSip(Uuid.fromString(nepRef.getSipId()));
78 });
79
80 return new RpcOutput(RpcOutput.Status.RPC_SUCCESS, output.getDataNode());
81 } catch (Throwable e) {
82 log.error("Error:", e);
83 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
84 }
85
86 }
87
88 /**
89 * Service interface of updateServiceInterfacePoint.
90 *
91 * @param rpcInput input of service interface updateServiceInterfacePoint
92 * @return rpcOutput output of service interface updateServiceInterfacePoint
93 */
94 @Override
95 public RpcOutput updateServiceInterfacePoint(RpcInput rpcInput) {
96 log.error("Not implemented");
97 return new RpcOutput(RpcOutput.Status.RPC_FAILURE, null);
98 }
99}
100