blob: 1f709434b807a61c71b3480ee611b3f42bd2e726 [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
hiroki96ab3c22018-12-11 14:10:52 -080019import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext;
20import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.Uuid;
21import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.connection.DefaultRoute;
22import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.connectivitycontext.ConnectionKeys;
23import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.connectivitycontext.DefaultConnection;
24import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.context.augmentedtapicommoncontext.DefaultConnectivityContext;
25import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.route.ConnectionEndPoint;
26import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.route.DefaultConnectionEndPoint;
hirokif4ed5212018-05-26 22:39:38 -070027import org.onosproject.yang.model.ModelObjectId;
28
29import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.getLocalId;
30import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.setLocalId;
31
32/**
33 * Utility class to deal with TAPI Route with DCS.
34 */
35public final class TapiRouteHandler extends TapiObjectHandler<DefaultRoute> {
36
37 private Uuid connectionId;
38
39 private TapiRouteHandler() {
40 obj = new DefaultRoute();
41 setId();
42 }
43
44 public static TapiRouteHandler create() {
45 return new TapiRouteHandler();
46 }
47
48 @Override
49 protected Uuid getIdDetail() {
50 return Uuid.fromString(getLocalId(obj));
51 }
52
53 @Override
54 protected void setIdDetail(Uuid uuid) {
55 setLocalId(obj, uuid.toString());
56 }
57
58 @Override
59 public ModelObjectId getParentModelObjectId() {
60 ConnectionKeys connectionKeys = new ConnectionKeys();
61 connectionKeys.uuid(connectionId);
62
63 return ModelObjectId.builder()
64 .addChild(DefaultContext.class)
hirokid8fd7862018-10-09 15:24:24 +090065 .addChild(DefaultConnectivityContext.class)
hirokif4ed5212018-05-26 22:39:38 -070066 .addChild(DefaultConnection.class, connectionKeys)
67 .build();
68 }
69
70 public TapiRouteHandler addCep(TapiCepRef cepRef) {
71 DefaultConnectionEndPoint cep = new DefaultConnectionEndPoint();
hirokid8fd7862018-10-09 15:24:24 +090072 cep.topologyUuid(cepRef.getTopologyId());
73 cep.nodeUuid(cepRef.getNodeId());
74 cep.nodeEdgePointUuid(cepRef.getNepId());
75 cep.connectionEndPointUuid(cepRef.getCepId());
hirokif4ed5212018-05-26 22:39:38 -070076
77 obj.addToConnectionEndPoint(cep);
78 return this;
79 }
80
81 public TapiCepRef getRouteStart() {
82 ConnectionEndPoint cep = obj.connectionEndPoint().get(0);
hirokid8fd7862018-10-09 15:24:24 +090083 return TapiCepRef.create(cep.topologyUuid().toString(), cep.nodeUuid().toString(),
84 cep.nodeEdgePointUuid().toString(), cep.connectionEndPointUuid().toString());
hirokif4ed5212018-05-26 22:39:38 -070085 }
86
87 public TapiCepRef getRouteEnd() {
88 ConnectionEndPoint cep = obj.connectionEndPoint().get(obj.connectionEndPoint().size() - 1);
hirokid8fd7862018-10-09 15:24:24 +090089 return TapiCepRef.create(cep.topologyUuid().toString(), cep.nodeUuid().toString(),
90 cep.nodeEdgePointUuid().toString(), cep.connectionEndPointUuid().toString());
hirokif4ed5212018-05-26 22:39:38 -070091 }
92
93 public TapiRouteHandler setConnectionId(Uuid connectionId) {
94 this.connectionId = connectionId;
95 return this;
96 }
97}