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 | 96ab3c2 | 2018-12-11 14:10:52 -0800 | [diff] [blame^] | 19 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext; |
| 20 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.Uuid; |
| 21 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.ceplist.DefaultConnectionEndPoint; |
| 22 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.connectionendpoint.DefaultParentNodeEdgePoint; |
| 23 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.context.augmentedtapicommoncontext.DefaultTopologyContext; |
| 24 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.node.DefaultOwnedNodeEdgePoint; |
| 25 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.node.OwnedNodeEdgePointKeys; |
| 26 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topology.DefaultNode; |
| 27 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topology.NodeKeys; |
| 28 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.DefaultTopology; |
| 29 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.TopologyKeys; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 30 | import org.onosproject.yang.model.ModelObjectId; |
| 31 | |
| 32 | import static com.google.common.base.Preconditions.checkNotNull; |
| 33 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
| 34 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
| 35 | |
| 36 | /** |
| 37 | * Utility class to deal with TAPI CEP with DCS. |
| 38 | */ |
| 39 | public final class TapiCepHandler extends TapiObjectHandler<DefaultConnectionEndPoint> { |
| 40 | |
| 41 | private Uuid topologyUuid; |
| 42 | private Uuid nodeUuid; |
| 43 | private Uuid nepUuid; |
| 44 | |
| 45 | private TapiCepHandler() { |
| 46 | obj = new DefaultConnectionEndPoint(); |
| 47 | setId(); |
| 48 | } |
| 49 | |
| 50 | public static TapiCepHandler create() { |
| 51 | return new TapiCepHandler(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected Uuid getIdDetail() { |
| 56 | return getUuid(obj); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected void setIdDetail(Uuid uuid) { |
| 61 | setUuid(obj, uuid); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public ModelObjectId getParentModelObjectId() { |
| 66 | checkNotNull(topologyUuid); |
| 67 | checkNotNull(nodeUuid); |
| 68 | checkNotNull(nodeUuid); |
| 69 | |
| 70 | TopologyKeys topologyKey = new TopologyKeys(); |
| 71 | topologyKey.uuid(topologyUuid); |
| 72 | |
| 73 | NodeKeys nodeKey = new NodeKeys(); |
| 74 | nodeKey.uuid(nodeUuid); |
| 75 | |
| 76 | OwnedNodeEdgePointKeys nepKey = new OwnedNodeEdgePointKeys(); |
| 77 | nepKey.uuid(nepUuid); |
| 78 | |
| 79 | return ModelObjectId.builder() |
| 80 | .addChild(DefaultContext.class) |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 81 | .addChild(DefaultTopologyContext.class) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 82 | .addChild(DefaultTopology.class, topologyKey) |
| 83 | .addChild(DefaultNode.class, nodeKey) |
| 84 | .addChild(DefaultOwnedNodeEdgePoint.class, nepKey) |
| 85 | .build(); |
| 86 | } |
| 87 | |
| 88 | public TapiCepHandler setTopologyUuid(Uuid topologyUuid) { |
| 89 | this.topologyUuid = topologyUuid; |
| 90 | return this; |
| 91 | } |
| 92 | |
| 93 | public TapiCepHandler setNodeUuid(Uuid nodeUuid) { |
| 94 | this.nodeUuid = nodeUuid; |
| 95 | return this; |
| 96 | } |
| 97 | |
| 98 | public TapiCepHandler setNepUuid(Uuid nepUuid) { |
| 99 | this.nepUuid = nepUuid; |
| 100 | return this; |
| 101 | } |
| 102 | |
| 103 | public TapiCepHandler setParentNep() { |
| 104 | checkNotNull(topologyUuid); |
| 105 | checkNotNull(nodeUuid); |
| 106 | checkNotNull(nepUuid); |
| 107 | |
| 108 | DefaultParentNodeEdgePoint parentNep = new DefaultParentNodeEdgePoint(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 109 | parentNep.topologyUuid(topologyUuid); |
| 110 | parentNep.nodeUuid(nodeUuid); |
| 111 | parentNep.nodeEdgePointUuid(nepUuid); |
| 112 | obj.parentNodeEdgePoint(parentNep); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 113 | |
| 114 | return this; |
| 115 | } |
| 116 | |
| 117 | public TapiCepHandler setParentNep(TapiNepRef nepRef) { |
| 118 | topologyUuid = Uuid.fromString(nepRef.getTopologyId()); |
| 119 | nodeUuid = Uuid.fromString(nepRef.getNodeId()); |
| 120 | nepUuid = Uuid.fromString(nepRef.getNepId()); |
| 121 | |
| 122 | setParentNep(); |
| 123 | return this; |
| 124 | } |
| 125 | } |