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 | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 19 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext; |
| 20 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid; |
| 21 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.DefaultRoute; |
| 22 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.ConnectionKeys; |
| 23 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.DefaultConnection; |
| 24 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.context.augmentedtapicommoncontext.DefaultConnectivityContext; |
| 25 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.route.ConnectionEndPoint; |
| 26 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.route.DefaultConnectionEndPoint; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 27 | import org.onosproject.yang.model.ModelObjectId; |
| 28 | |
| 29 | import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.getLocalId; |
| 30 | import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.setLocalId; |
| 31 | |
| 32 | /** |
| 33 | * Utility class to deal with TAPI Route with DCS. |
| 34 | */ |
| 35 | public 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) |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 65 | .addChild(DefaultConnectivityContext.class) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 66 | .addChild(DefaultConnection.class, connectionKeys) |
| 67 | .build(); |
| 68 | } |
| 69 | |
| 70 | public TapiRouteHandler addCep(TapiCepRef cepRef) { |
| 71 | DefaultConnectionEndPoint cep = new DefaultConnectionEndPoint(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 72 | cep.topologyUuid(cepRef.getTopologyId()); |
| 73 | cep.nodeUuid(cepRef.getNodeId()); |
| 74 | cep.nodeEdgePointUuid(cepRef.getNepId()); |
| 75 | cep.connectionEndPointUuid(cepRef.getCepId()); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 76 | |
| 77 | obj.addToConnectionEndPoint(cep); |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public TapiCepRef getRouteStart() { |
| 82 | ConnectionEndPoint cep = obj.connectionEndPoint().get(0); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 83 | return TapiCepRef.create(cep.topologyUuid().toString(), cep.nodeUuid().toString(), |
| 84 | cep.nodeEdgePointUuid().toString(), cep.connectionEndPointUuid().toString()); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | public TapiCepRef getRouteEnd() { |
| 88 | ConnectionEndPoint cep = obj.connectionEndPoint().get(obj.connectionEndPoint().size() - 1); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 89 | return TapiCepRef.create(cep.topologyUuid().toString(), cep.nodeUuid().toString(), |
| 90 | cep.nodeEdgePointUuid().toString(), cep.connectionEndPointUuid().toString()); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | public TapiRouteHandler setConnectionId(Uuid connectionId) { |
| 94 | this.connectionId = connectionId; |
| 95 | return this; |
| 96 | } |
| 97 | } |