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 | |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame^] | 19 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext; |
| 20 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid; |
| 21 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.ConnectivityServiceKeys; |
| 22 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.DefaultConnectivityService; |
| 23 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivityservice.DefaultConnection; |
| 24 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivityservice.EndPoint; |
| 25 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.context.augmentedtapicommoncontext.DefaultConnectivityContext; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 26 | import org.onosproject.yang.model.DefaultModelObjectData; |
| 27 | import org.onosproject.yang.model.ModelObjectData; |
| 28 | import org.onosproject.yang.model.ModelObjectId; |
| 29 | |
| 30 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
| 31 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
| 32 | |
| 33 | /** |
| 34 | * Utility class to deal with TAPI ConnectivityService with DCS. |
| 35 | */ |
| 36 | public final class TapiConnectivityServiceHandler extends TapiObjectHandler<DefaultConnectivityService> { |
| 37 | |
| 38 | private TapiConnectivityServiceHandler() { |
| 39 | obj = new DefaultConnectivityService(); |
| 40 | setId(); |
| 41 | } |
| 42 | |
| 43 | public static TapiConnectivityServiceHandler create() { |
| 44 | return new TapiConnectivityServiceHandler(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected Uuid getIdDetail() { |
| 49 | return getUuid(obj); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected void setIdDetail(Uuid uuid) { |
| 54 | setUuid(obj, uuid); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public ModelObjectId getParentModelObjectId() { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame^] | 59 | return ModelObjectId.builder() |
| 60 | .addChild(DefaultContext.class) |
| 61 | .addChild(DefaultConnectivityContext.class) |
| 62 | .build(); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public ModelObjectData getChildModelObjectData() { |
| 67 | |
| 68 | ConnectivityServiceKeys key = new ConnectivityServiceKeys(); |
| 69 | key.uuid(getId()); |
| 70 | |
| 71 | DefaultConnection mObj = new DefaultConnection(); |
| 72 | |
| 73 | ModelObjectId mId = ModelObjectId.builder() |
| 74 | .addChild(DefaultContext.class) |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame^] | 75 | .addChild(DefaultConnectivityContext.class) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 76 | .addChild(DefaultConnectivityService.class, key) |
| 77 | .build(); |
| 78 | |
| 79 | return DefaultModelObjectData.builder() |
| 80 | .addModelObject(mObj) |
| 81 | .identifier(mId) |
| 82 | .build(); |
| 83 | } |
| 84 | |
| 85 | public TapiConnectivityServiceHandler addSep(EndPoint sep) { |
| 86 | obj.addToEndPoint(sep); |
| 87 | return this; |
| 88 | } |
| 89 | |
| 90 | public TapiConnectivityServiceHandler addConnection(Uuid connectionUuid) { |
| 91 | DefaultConnection connection = new DefaultConnection(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame^] | 92 | connection.connectionUuid(connectionUuid.toString()); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 93 | obj.addToConnection(connection); |
| 94 | return this; |
| 95 | } |
| 96 | } |