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; |
| 29 | import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.DefaultContext; |
| 30 | import org.onosproject.yang.gen.v1.tapicommon.rev20180307.tapicommon.Uuid; |
| 31 | |
| 32 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.ceplist.DefaultConnectionEndPoint; |
| 33 | |
| 34 | import org.onosproject.yang.gen.v1.tapiconnectivity.rev20180307.tapiconnectivity.context.topology.node.ownednodeedgepoint.DefaultAugmentedTapiTopologyOwnedNodeEdgePoint; |
| 35 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.node.DefaultOwnedNodeEdgePoint; |
| 36 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.nodeedgepoint.DefaultMappedServiceInterfacePoint; |
| 37 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.DefaultNode; |
| 38 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topology.NodeKeys; |
| 39 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.DefaultTopology; |
| 40 | import org.onosproject.yang.gen.v1.tapitopology.rev20180307.tapitopology.topologycontext.TopologyKeys; |
| 41 | import org.onosproject.yang.model.ModelObjectId; |
| 42 | |
| 43 | /** |
| 44 | * Utility class to deal with TAPI NEP with DCS. |
| 45 | */ |
| 46 | public final class TapiNepHandler extends TapiObjectHandler<DefaultOwnedNodeEdgePoint> { |
| 47 | |
| 48 | private Uuid topologyUuid; |
| 49 | private Uuid nodeUuid; |
| 50 | |
| 51 | private ConnectPoint cp; |
| 52 | private Map<String, String> kvs = new HashMap<>(); |
| 53 | |
| 54 | private TapiNepHandler() { |
| 55 | obj = new DefaultOwnedNodeEdgePoint(); |
| 56 | setId(); |
| 57 | } |
| 58 | |
| 59 | public static TapiNepHandler create() { |
| 60 | return new TapiNepHandler(); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | protected Uuid getIdDetail() { |
| 65 | return getUuid(obj); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | protected void setIdDetail(Uuid uuid) { |
| 70 | setUuid(obj, uuid); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public ModelObjectId getParentModelObjectId() { |
| 75 | TopologyKeys topologyKey = new TopologyKeys(); |
| 76 | topologyKey.uuid(topologyUuid); |
| 77 | |
| 78 | NodeKeys nodeKey = new NodeKeys(); |
| 79 | nodeKey.uuid(nodeUuid); |
| 80 | |
| 81 | return ModelObjectId.builder() |
| 82 | .addChild(DefaultContext.class) |
| 83 | .addChild(DefaultTopology.class, topologyKey) |
| 84 | .addChild(DefaultNode.class, nodeKey) |
| 85 | .build(); |
| 86 | } |
| 87 | |
| 88 | public TapiNepHandler setTopologyUuid(Uuid topologyUuid) { |
| 89 | this.topologyUuid = topologyUuid; |
| 90 | return this; |
| 91 | } |
| 92 | |
| 93 | public TapiNepHandler setNodeUuid(Uuid nodeUuid) { |
| 94 | this.nodeUuid = nodeUuid; |
| 95 | return this; |
| 96 | } |
| 97 | |
| 98 | public TapiNepHandler setPort(Port port) { |
| 99 | ConnectPoint cp = new ConnectPoint(port.element().id(), port.number()); |
| 100 | kvs.put(ODTN_PORT_TYPE, port.annotations().value(ODTN_PORT_TYPE)); |
| 101 | kvs.put(CONNECTION_ID, port.annotations().value(CONNECTION_ID)); |
| 102 | addNameList(obj, kvs); |
| 103 | return setConnectPoint(cp); |
| 104 | } |
| 105 | |
| 106 | public TapiNepHandler setConnectPoint(ConnectPoint cp) { |
| 107 | kvs.put(ONOS_CP, cp.toString()); |
| 108 | addNameList(obj, kvs); |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | public TapiNepHandler addSip(Uuid sipUuid) { |
| 113 | DefaultMappedServiceInterfacePoint mappedSip = new DefaultMappedServiceInterfacePoint(); |
| 114 | mappedSip.serviceInterfacePointId(sipUuid); |
| 115 | obj.addToMappedServiceInterfacePoint(mappedSip); |
| 116 | return this; |
| 117 | } |
| 118 | |
| 119 | public TapiNepHandler addCep(DefaultConnectionEndPoint cep) { |
| 120 | DefaultAugmentedTapiTopologyOwnedNodeEdgePoint augmentNep = |
| 121 | new DefaultAugmentedTapiTopologyOwnedNodeEdgePoint(); |
| 122 | augmentNep.addToConnectionEndPoint(cep); |
| 123 | obj.addAugmentation(augmentNep); |
| 124 | return this; |
| 125 | } |
| 126 | |
| 127 | public ConnectPoint getConnectPoint() { |
| 128 | return cp; |
| 129 | } |
| 130 | |
| 131 | } |