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