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 | |
| 19 | import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext; |
| 20 | import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid; |
| 21 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connection.DefaultRoute; |
| 22 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.ConnectionKeys; |
| 23 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.connectivitycontext.DefaultConnection; |
| 24 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.route.ConnectionEndPoint; |
| 25 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.route.DefaultConnectionEndPoint; |
| 26 | import org.onosproject.yang.model.ModelObjectId; |
| 27 | |
| 28 | import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.getLocalId; |
| 29 | import static org.onosproject.odtn.utils.tapi.TapiLocalClassUtil.setLocalId; |
| 30 | |
| 31 | /** |
| 32 | * Utility class to deal with TAPI Route with DCS. |
| 33 | */ |
| 34 | public final class TapiRouteHandler extends TapiObjectHandler<DefaultRoute> { |
| 35 | |
| 36 | private Uuid connectionId; |
| 37 | |
| 38 | private TapiRouteHandler() { |
| 39 | obj = new DefaultRoute(); |
| 40 | setId(); |
| 41 | } |
| 42 | |
| 43 | public static TapiRouteHandler create() { |
| 44 | return new TapiRouteHandler(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected Uuid getIdDetail() { |
| 49 | return Uuid.fromString(getLocalId(obj)); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected void setIdDetail(Uuid uuid) { |
| 54 | setLocalId(obj, uuid.toString()); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public ModelObjectId getParentModelObjectId() { |
| 59 | ConnectionKeys connectionKeys = new ConnectionKeys(); |
| 60 | connectionKeys.uuid(connectionId); |
| 61 | |
| 62 | return ModelObjectId.builder() |
| 63 | .addChild(DefaultContext.class) |
| 64 | .addChild(DefaultConnection.class, connectionKeys) |
| 65 | .build(); |
| 66 | } |
| 67 | |
| 68 | public TapiRouteHandler addCep(TapiCepRef cepRef) { |
| 69 | DefaultConnectionEndPoint cep = new DefaultConnectionEndPoint(); |
| 70 | cep.topologyId(cepRef.getTopologyId()); |
| 71 | cep.nodeId(cepRef.getNodeId()); |
| 72 | cep.ownedNodeEdgePointId(cepRef.getNepId()); |
| 73 | cep.connectionEndPointId(cepRef.getCepId()); |
| 74 | |
| 75 | obj.addToConnectionEndPoint(cep); |
| 76 | return this; |
| 77 | } |
| 78 | |
| 79 | public TapiCepRef getRouteStart() { |
| 80 | ConnectionEndPoint cep = obj.connectionEndPoint().get(0); |
| 81 | return TapiCepRef.create(cep.topologyId().toString(), cep.nodeId().toString(), |
| 82 | cep.ownedNodeEdgePointId().toString(), cep.connectionEndPointId().toString()); |
| 83 | } |
| 84 | |
| 85 | public TapiCepRef getRouteEnd() { |
| 86 | ConnectionEndPoint cep = obj.connectionEndPoint().get(obj.connectionEndPoint().size() - 1); |
| 87 | return TapiCepRef.create(cep.topologyId().toString(), cep.nodeId().toString(), |
| 88 | cep.ownedNodeEdgePointId().toString(), cep.connectionEndPointId().toString()); |
| 89 | } |
| 90 | |
| 91 | public TapiRouteHandler setConnectionId(Uuid connectionId) { |
| 92 | this.connectionId = connectionId; |
| 93 | return this; |
| 94 | } |
| 95 | } |