hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.odtn.utils.tapi; |
| 18 | |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | |
| 23 | import org.onosproject.net.Port; |
| 24 | import org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 25 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext; |
| 26 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.LayerProtocolName; |
| 27 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 28 | |
| 29 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.PORT_TYPE; |
| 30 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList; |
| 31 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
| 32 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 33 | import static org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.layerprotocolname.LayerProtocolNameEnum.DSR; |
| 34 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.tapicontext.DefaultServiceInterfacePoint; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 35 | import org.onosproject.yang.model.ModelObjectId; |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 36 | import org.slf4j.Logger; |
| 37 | import org.slf4j.LoggerFactory; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Utility class to deal with TAPI SIP with DCS. |
| 41 | */ |
| 42 | public final class TapiSipHandler extends TapiObjectHandler<DefaultServiceInterfacePoint> { |
| 43 | |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 44 | private static final Logger log = |
| 45 | LoggerFactory.getLogger(TapiSipHandler.class); |
| 46 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 47 | 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 Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 75 | * |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 76 | * @param port onos port object |
| 77 | * @return is this handler for SIP or not |
| 78 | */ |
| 79 | public static boolean isSip(Port port) { |
Ramon Casellas | 03f194f | 2018-11-15 16:06:02 +0100 | [diff] [blame] | 80 | // 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 | } |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 94 | 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); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 112 | obj.layerProtocolName(LayerProtocolName.of(DSR)); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 113 | return this; |
| 114 | } |
| 115 | |
| 116 | } |