hiroki | ec18d3a | 2018-05-16 15:27:37 -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.tapitopology.rev20180307.tapitopology.link.DefaultNodeEdgePoint; |
| 22 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultLink; |
| 23 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology; |
| 24 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 25 | import org.onosproject.yang.model.ModelObjectId; |
| 26 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 29 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
| 30 | |
| 31 | /** |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 32 | * Utility class to deal with TAPI Link with DCS. |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 33 | */ |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 34 | public final class TapiLinkHandler extends TapiObjectHandler<DefaultLink> { |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 35 | |
| 36 | private Uuid topologyUuid; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 37 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 38 | private TapiLinkHandler() { |
| 39 | obj = new DefaultLink(); |
| 40 | setId(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 41 | } |
| 42 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 43 | public static TapiLinkHandler create() { |
| 44 | return new TapiLinkHandler(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 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() { |
| 59 | checkNotNull(topologyUuid); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 60 | |
| 61 | TopologyKeys topologyKey = new TopologyKeys(); |
| 62 | topologyKey.uuid(topologyUuid); |
hiroki | 684aa2f | 2018-05-19 20:48:49 -0700 | [diff] [blame] | 63 | return ModelObjectId.builder() |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 64 | .addChild(DefaultContext.class) |
| 65 | .addChild(DefaultTopology.class, topologyKey) |
| 66 | .build(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 67 | } |
| 68 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 69 | public TapiLinkHandler setTopologyUuid(Uuid topologyUuid) { |
| 70 | this.topologyUuid = topologyUuid; |
| 71 | return this; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 72 | } |
| 73 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 74 | public TapiLinkHandler addNep(TapiNepRef nepRef) { |
| 75 | DefaultNodeEdgePoint nep = new DefaultNodeEdgePoint(); |
| 76 | nep.topologyId(nepRef.getTopologyId()); |
| 77 | nep.nodeId(nepRef.getNodeId()); |
| 78 | nep.ownedNodeEdgePointId(nepRef.getNepId()); |
| 79 | obj.addToNodeEdgePoint(nep); |
| 80 | return this; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | } |