blob: 367122e7fe357ee5ac56a2c88f2bcb0451e23349 [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.utils.tapi;
18
19import java.util.HashMap;
20import java.util.Map;
21import org.onosproject.net.ConnectPoint;
22
23import org.onosproject.net.Port;
24import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery;
hirokid8fd7862018-10-09 15:24:24 +090025import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext;
26import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.LayerProtocolName;
27import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid;
hirokif4ed5212018-05-26 22:39:38 -070028
29import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.PORT_TYPE;
30import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
31import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
32import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
hirokid8fd7862018-10-09 15:24:24 +090033import static org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.layerprotocolname.LayerProtocolNameEnum.DSR;
34import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.tapicontext.DefaultServiceInterfacePoint;
hirokif4ed5212018-05-26 22:39:38 -070035import org.onosproject.yang.model.ModelObjectId;
36
37/**
38 * Utility class to deal with TAPI SIP with DCS.
39 */
40public final class TapiSipHandler extends TapiObjectHandler<DefaultServiceInterfacePoint> {
41
42 private TapiSipHandler() {
43 obj = new DefaultServiceInterfacePoint();
44 setId();
45 }
46
47 public static TapiSipHandler create() {
48 return new TapiSipHandler();
49 }
50
51 @Override
52 protected Uuid getIdDetail() {
53 return getUuid(obj);
54 }
55
56 @Override
57 protected void setIdDetail(Uuid uuid) {
58 setUuid(obj, uuid);
59 }
60
61 @Override
62 public ModelObjectId getParentModelObjectId() {
63 return ModelObjectId.builder()
64 .addChild(DefaultContext.class)
65 .build();
66 }
67
68 /**
69 * Check this handler dealing with port for SIP or not.
70 * @param port onos port object
71 * @return is this handler for SIP or not
72 */
73 public static boolean isSip(Port port) {
74 // FIXME modify this method to appropriate way
75 String portType = port.annotations().value(PORT_TYPE);
76 OdtnDeviceDescriptionDiscovery.OdtnPortType odtnPortType
77 = OdtnDeviceDescriptionDiscovery.OdtnPortType.fromValue(portType);
78 return odtnPortType.value().equals(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
79 }
80
81 public TapiSipHandler setPort(Port port) {
82 if (!isSip(port)) {
83 throw new IllegalStateException("Not allowed to use this port as SIP.");
84 }
85 ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
86 return setConnectPoint(cp);
87 }
88
89 public TapiSipHandler setConnectPoint(ConnectPoint cp) {
90 Map<String, String> kvs = new HashMap<>();
91 kvs.put(ONOS_CP, cp.toString());
92 addNameList(obj, kvs);
hirokid8fd7862018-10-09 15:24:24 +090093 obj.layerProtocolName(LayerProtocolName.of(DSR));
hirokif4ed5212018-05-26 22:39:38 -070094 return this;
95 }
96
97}