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; |
| 36 | |
| 37 | /** |
| 38 | * Utility class to deal with TAPI SIP with DCS. |
| 39 | */ |
| 40 | public 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); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame^] | 93 | obj.layerProtocolName(LayerProtocolName.of(DSR)); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 94 | return this; |
| 95 | } |
| 96 | |
| 97 | } |