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.HashMap; |
| 20 | import java.util.Map; |
| 21 | import org.onosproject.net.ConnectPoint; |
| 22 | |
| 23 | import static org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID; |
| 24 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.addNameList; |
| 25 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.getUuid; |
| 26 | import static org.onosproject.odtn.utils.tapi.TapiGlobalClassUtil.setUuid; |
| 27 | |
| 28 | import org.onosproject.net.Port; |
hiroki | 96ab3c2 | 2018-12-11 14:10:52 -0800 | [diff] [blame^] | 29 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext; |
| 30 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.Uuid; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 31 | |
hiroki | 96ab3c2 | 2018-12-11 14:10:52 -0800 | [diff] [blame^] | 32 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.ceplist.DefaultConnectionEndPoint; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 33 | |
hiroki | 96ab3c2 | 2018-12-11 14:10:52 -0800 | [diff] [blame^] | 34 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.context.topologycontext.topology.node.ownednodeedgepoint.DefaultAugmentedTapiTopologyOwnedNodeEdgePoint; |
| 35 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.context.topologycontext.topology.node.ownednodeedgepoint.augmentedtapitopologyownednodeedgepoint.DefaultCepList; |
| 36 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.context.augmentedtapicommoncontext.DefaultTopologyContext; |
| 37 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.node.DefaultOwnedNodeEdgePoint; |
| 38 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.nodeedgepoint.DefaultMappedServiceInterfacePoint; |
| 39 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topology.DefaultNode; |
| 40 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topology.NodeKeys; |
| 41 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.DefaultTopology; |
| 42 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.TopologyKeys; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 43 | import org.onosproject.yang.model.ModelObjectId; |
| 44 | |
| 45 | /** |
| 46 | * Utility class to deal with TAPI NEP with DCS. |
| 47 | */ |
| 48 | public final class TapiNepHandler extends TapiObjectHandler<DefaultOwnedNodeEdgePoint> { |
| 49 | |
| 50 | private Uuid topologyUuid; |
| 51 | private Uuid nodeUuid; |
| 52 | |
| 53 | private ConnectPoint cp; |
| 54 | private Map<String, String> kvs = new HashMap<>(); |
| 55 | |
| 56 | private TapiNepHandler() { |
| 57 | obj = new DefaultOwnedNodeEdgePoint(); |
| 58 | setId(); |
| 59 | } |
| 60 | |
| 61 | public static TapiNepHandler create() { |
| 62 | return new TapiNepHandler(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected Uuid getIdDetail() { |
| 67 | return getUuid(obj); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected void setIdDetail(Uuid uuid) { |
| 72 | setUuid(obj, uuid); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public ModelObjectId getParentModelObjectId() { |
| 77 | TopologyKeys topologyKey = new TopologyKeys(); |
| 78 | topologyKey.uuid(topologyUuid); |
| 79 | |
| 80 | NodeKeys nodeKey = new NodeKeys(); |
| 81 | nodeKey.uuid(nodeUuid); |
| 82 | |
| 83 | return ModelObjectId.builder() |
| 84 | .addChild(DefaultContext.class) |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 85 | .addChild(DefaultTopologyContext.class) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 86 | .addChild(DefaultTopology.class, topologyKey) |
| 87 | .addChild(DefaultNode.class, nodeKey) |
| 88 | .build(); |
| 89 | } |
| 90 | |
| 91 | public TapiNepHandler setTopologyUuid(Uuid topologyUuid) { |
| 92 | this.topologyUuid = topologyUuid; |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public TapiNepHandler setNodeUuid(Uuid nodeUuid) { |
| 97 | this.nodeUuid = nodeUuid; |
| 98 | return this; |
| 99 | } |
| 100 | |
| 101 | public TapiNepHandler setPort(Port port) { |
| 102 | ConnectPoint cp = new ConnectPoint(port.element().id(), port.number()); |
| 103 | kvs.put(ODTN_PORT_TYPE, port.annotations().value(ODTN_PORT_TYPE)); |
| 104 | kvs.put(CONNECTION_ID, port.annotations().value(CONNECTION_ID)); |
| 105 | addNameList(obj, kvs); |
| 106 | return setConnectPoint(cp); |
| 107 | } |
| 108 | |
| 109 | public TapiNepHandler setConnectPoint(ConnectPoint cp) { |
| 110 | kvs.put(ONOS_CP, cp.toString()); |
| 111 | addNameList(obj, kvs); |
| 112 | return this; |
| 113 | } |
| 114 | |
| 115 | public TapiNepHandler addSip(Uuid sipUuid) { |
| 116 | DefaultMappedServiceInterfacePoint mappedSip = new DefaultMappedServiceInterfacePoint(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 117 | mappedSip.serviceInterfacePointUuid(sipUuid); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 118 | obj.addToMappedServiceInterfacePoint(mappedSip); |
| 119 | return this; |
| 120 | } |
| 121 | |
| 122 | public TapiNepHandler addCep(DefaultConnectionEndPoint cep) { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 123 | |
| 124 | DefaultCepList cepList = new DefaultCepList(); |
| 125 | cepList.addToConnectionEndPoint(cep); |
| 126 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 127 | DefaultAugmentedTapiTopologyOwnedNodeEdgePoint augmentNep = |
| 128 | new DefaultAugmentedTapiTopologyOwnedNodeEdgePoint(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 129 | augmentNep.cepList(cepList); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 130 | obj.addAugmentation(augmentNep); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 131 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 132 | return this; |
| 133 | } |
| 134 | |
| 135 | public ConnectPoint getConnectPoint() { |
| 136 | return cp; |
| 137 | } |
| 138 | |
| 139 | } |