blob: 1d897adb3caf7a2b991f66028a1c5ee7eab88994 [file] [log] [blame]
hirokiec18d3a2018-05-16 15:27:37 -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 java.util.HashMap;
20import java.util.Map;
hirokif4ed5212018-05-26 22:39:38 -070021
22import static com.google.common.base.Preconditions.checkNotNull;
hiroki684aa2f2018-05-19 20:48:49 -070023import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList;
hirokif4ed5212018-05-26 22:39:38 -070024import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid;
hirokiec18d3a2018-05-16 15:27:37 -070025import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid;
26
27import org.onosproject.net.DeviceId;
28import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext;
29import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid;
30import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.OwnedNodeEdgePoint;
31import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode;
32import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology;
33import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys;
hirokiec18d3a2018-05-16 15:27:37 -070034import org.onosproject.yang.model.ModelObjectId;
35
36/**
hirokif4ed5212018-05-26 22:39:38 -070037 * Utility class to deal with TAPI Node with DCS.
hirokiec18d3a2018-05-16 15:27:37 -070038 */
hirokif4ed5212018-05-26 22:39:38 -070039public final class TapiNodeHandler extends TapiObjectHandler<DefaultNode> {
hirokiec18d3a2018-05-16 15:27:37 -070040
41 private Uuid topologyUuid;
hirokiec18d3a2018-05-16 15:27:37 -070042
hirokif4ed5212018-05-26 22:39:38 -070043 private TapiNodeHandler() {
44 obj = new DefaultNode();
45 setId();
hirokiec18d3a2018-05-16 15:27:37 -070046 }
47
hirokif4ed5212018-05-26 22:39:38 -070048 public static TapiNodeHandler create() {
49 return new TapiNodeHandler();
hirokiec18d3a2018-05-16 15:27:37 -070050 }
51
52 @Override
hirokif4ed5212018-05-26 22:39:38 -070053 protected Uuid getIdDetail() {
54 return getUuid(obj);
hirokiec18d3a2018-05-16 15:27:37 -070055 }
56
57 @Override
hirokif4ed5212018-05-26 22:39:38 -070058 protected void setIdDetail(Uuid uuid) {
59 setUuid(obj, uuid);
hirokiec18d3a2018-05-16 15:27:37 -070060 }
61
62 @Override
hirokif4ed5212018-05-26 22:39:38 -070063 public ModelObjectId getParentModelObjectId() {
64 checkNotNull(topologyUuid);
65
hirokiec18d3a2018-05-16 15:27:37 -070066 TopologyKeys topologyKey = new TopologyKeys();
67 topologyKey.uuid(topologyUuid);
hiroki684aa2f2018-05-19 20:48:49 -070068 return ModelObjectId.builder()
hirokiec18d3a2018-05-16 15:27:37 -070069 .addChild(DefaultContext.class)
70 .addChild(DefaultTopology.class, topologyKey)
71 .build();
hirokiec18d3a2018-05-16 15:27:37 -070072 }
73
hirokif4ed5212018-05-26 22:39:38 -070074 public TapiNodeHandler setTopologyUuid(Uuid topologyUuid) {
75 this.topologyUuid = topologyUuid;
76 return this;
77 }
78
79 public TapiNodeHandler addNep(OwnedNodeEdgePoint nep) {
80 obj.addToOwnedNodeEdgePoint(nep);
81 return this;
82 }
83
84 public TapiNodeHandler setDeviceId(DeviceId deviceId) {
85 Map<String, String> kvs = new HashMap<>();
86 kvs.put(DEVICE_ID, deviceId.toString());
87 addNameList(obj, kvs);
88 return this;
89 }
90
hirokiec18d3a2018-05-16 15:27:37 -070091}