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