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 java.util.Collections; |
| 20 | import java.util.List; |
| 21 | import java.util.stream.Collectors; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 22 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.DefaultContext; |
| 23 | import org.onosproject.yang.gen.v1.tapicommon.rev20181016.tapicommon.Uuid; |
| 24 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.ConnectionEndPoint; |
| 25 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.DefaultConnectionEndPoint; |
| 26 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.DefaultLowerConnection; |
| 27 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.DefaultRoute; |
| 28 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connection.LowerConnection; |
| 29 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.ConnectionKeys; |
| 30 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.connectivitycontext.DefaultConnection; |
| 31 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181016.tapiconnectivity.context.augmentedtapicommoncontext.DefaultConnectivityContext; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 32 | import org.onosproject.yang.model.DefaultModelObjectData; |
| 33 | import org.onosproject.yang.model.ModelObjectData; |
| 34 | import org.onosproject.yang.model.ModelObjectId; |
| 35 | |
| 36 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
| 37 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
| 38 | |
| 39 | /** |
| 40 | * Utility class to deal with TAPI Connection with DCS. |
| 41 | */ |
| 42 | public final class TapiConnectionHandler extends TapiObjectHandler<DefaultConnection> { |
| 43 | |
| 44 | private TapiConnectionHandler() { |
| 45 | obj = new DefaultConnection(); |
| 46 | setId(); |
| 47 | } |
| 48 | |
| 49 | public static TapiConnectionHandler create() { |
| 50 | return new TapiConnectionHandler(); |
| 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() { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 65 | return ModelObjectId.builder() |
| 66 | .addChild(DefaultContext.class) |
| 67 | .addChild(DefaultConnectivityContext.class) |
| 68 | .build(); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public ModelObjectData getChildModelObjectData() { |
| 73 | |
| 74 | ConnectionKeys key = new ConnectionKeys(); |
| 75 | key.uuid(getId()); |
| 76 | |
| 77 | DefaultConnectionEndPoint mObj = new DefaultConnectionEndPoint(); |
| 78 | |
| 79 | ModelObjectId mId = ModelObjectId.builder() |
| 80 | .addChild(DefaultContext.class) |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 81 | .addChild(DefaultConnectivityContext.class) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 82 | .addChild(DefaultConnection.class, key) |
| 83 | .build(); |
| 84 | |
| 85 | return DefaultModelObjectData.builder() |
| 86 | .addModelObject(mObj) |
| 87 | .identifier(mId) |
| 88 | .build(); |
| 89 | } |
| 90 | |
| 91 | public TapiConnectionHandler addCep(ConnectionEndPoint cep) { |
| 92 | obj.addToConnectionEndPoint(cep); |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public TapiConnectionHandler addLowerConnection(DefaultConnection connection) { |
| 97 | DefaultLowerConnection lowerConnection = new DefaultLowerConnection(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 98 | lowerConnection.connectionUuid(connection.uuid()); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 99 | obj.addToLowerConnection(lowerConnection); |
| 100 | return this; |
| 101 | } |
| 102 | |
| 103 | public TapiConnectionHandler addRoute(DefaultRoute route) { |
| 104 | obj.addToRoute(route); |
| 105 | return this; |
| 106 | } |
| 107 | |
hiroki | fca084b | 2018-06-02 08:29:42 -0700 | [diff] [blame] | 108 | public List<ConnectionEndPoint> getCeps() { |
| 109 | return obj.connectionEndPoint(); |
| 110 | } |
| 111 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 112 | public List<TapiConnectionHandler> getLowerConnections() { |
| 113 | |
| 114 | try { |
| 115 | return obj.lowerConnection().stream() |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 116 | .map(LowerConnection::connectionUuid) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 117 | .map(id -> { |
| 118 | TapiConnectionHandler handler = new TapiConnectionHandler(); |
| 119 | handler.setId(Uuid.fromString(id.toString())); |
| 120 | return handler; |
| 121 | }).collect(Collectors.toList()); |
| 122 | } catch (NullPointerException e) { |
| 123 | return Collections.emptyList(); |
| 124 | } |
| 125 | } |
| 126 | } |