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