blob: 9f81739fc2b6cc985ac3f1b0421551d4eeac1883 [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;
Ramon Casellas03f194f2018-11-15 16:06:02 +010036import org.slf4j.Logger;
37import org.slf4j.LoggerFactory;
hirokif4ed5212018-05-26 22:39:38 -070038
39/**
40 * Utility class to deal with TAPI SIP with DCS.
41 */
42public final class TapiSipHandler extends TapiObjectHandler<DefaultServiceInterfacePoint> {
43
Ramon Casellas03f194f2018-11-15 16:06:02 +010044 private static final Logger log =
45 LoggerFactory.getLogger(TapiSipHandler.class);
46
hirokif4ed5212018-05-26 22:39:38 -070047 private TapiSipHandler() {
48 obj = new DefaultServiceInterfacePoint();
49 setId();
50 }
51
52 public static TapiSipHandler create() {
53 return new TapiSipHandler();
54 }
55
56 @Override
57 protected Uuid getIdDetail() {
58 return getUuid(obj);
59 }
60
61 @Override
62 protected void setIdDetail(Uuid uuid) {
63 setUuid(obj, uuid);
64 }
65
66 @Override
67 public ModelObjectId getParentModelObjectId() {
68 return ModelObjectId.builder()
69 .addChild(DefaultContext.class)
70 .build();
71 }
72
73 /**
74 * Check this handler dealing with port for SIP or not.
Ramon Casellas03f194f2018-11-15 16:06:02 +010075 *
hirokif4ed5212018-05-26 22:39:38 -070076 * @param port onos port object
77 * @return is this handler for SIP or not
78 */
79 public static boolean isSip(Port port) {
Ramon Casellas03f194f2018-11-15 16:06:02 +010080 // RCAS Note: We may end up controlling more devices that do
81 // not have annotations or do not have the PORT_TYPE
82 // annotation. Let's accomodate other devices (e.g.
83 // OpenROADM) and be less strict. In short, if the
84 // annotation does not exist, simply return false.
85 //
86 // Note: for phase 1.5+ , we should also allow SIPs to
87 // be the transceiver LINE side, when we establish
88 // OpticalConnectivityIntent
89
90 if (!port.annotations().keys().contains(PORT_TYPE)) {
91 log.warn("No annotation of {} on port {}", PORT_TYPE, port);
92 return false;
93 }
hirokif4ed5212018-05-26 22:39:38 -070094 String portType = port.annotations().value(PORT_TYPE);
95 OdtnDeviceDescriptionDiscovery.OdtnPortType odtnPortType
96 = OdtnDeviceDescriptionDiscovery.OdtnPortType.fromValue(portType);
97 return odtnPortType.value().equals(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value());
98 }
99
100 public TapiSipHandler setPort(Port port) {
101 if (!isSip(port)) {
102 throw new IllegalStateException("Not allowed to use this port as SIP.");
103 }
104 ConnectPoint cp = new ConnectPoint(port.element().id(), port.number());
105 return setConnectPoint(cp);
106 }
107
108 public TapiSipHandler setConnectPoint(ConnectPoint cp) {
109 Map<String, String> kvs = new HashMap<>();
110 kvs.put(ONOS_CP, cp.toString());
111 addNameList(obj, kvs);
hirokid8fd7862018-10-09 15:24:24 +0900112 obj.layerProtocolName(LayerProtocolName.of(DSR));
hirokif4ed5212018-05-26 22:39:38 -0700113 return this;
114 }
115
116}