hiroki | bca3e93 | 2018-05-15 15:25:54 -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.internal; |
| 18 | |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 19 | import org.onosproject.config.DynamicConfigService; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.Device; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.net.Link; |
| 24 | import org.onosproject.net.Port; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 25 | import org.onosproject.odtn.TapiResolver; |
| 26 | import org.onosproject.odtn.TapiTopologyManager; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 27 | import org.onosproject.odtn.utils.tapi.TapiConnectivityContextHandler; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 28 | import org.onosproject.odtn.utils.tapi.TapiCepHandler; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 29 | import org.onosproject.odtn.utils.tapi.TapiContextHandler; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | import org.onosproject.odtn.utils.tapi.TapiLinkHandler; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 31 | import org.onosproject.odtn.utils.tapi.TapiNepHandler; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 32 | import org.onosproject.odtn.utils.tapi.TapiNepRef; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 33 | import org.onosproject.odtn.utils.tapi.TapiNodeHandler; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 34 | import org.onosproject.odtn.utils.tapi.TapiNodeRef; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 35 | import org.onosproject.odtn.utils.tapi.TapiSipHandler; |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 36 | import org.onosproject.odtn.utils.tapi.TapiTopologyContextHandler; |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 37 | import org.onosproject.odtn.utils.tapi.TapiTopologyHandler; |
hiroki | 96ab3c2 | 2018-12-11 14:10:52 -0800 | [diff] [blame^] | 38 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext; |
| 39 | import org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.Uuid; |
| 40 | import org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.DefaultTopology; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 41 | import org.onosproject.yang.model.ModelConverter; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 42 | import org.osgi.service.component.annotations.Activate; |
| 43 | import org.osgi.service.component.annotations.Component; |
| 44 | import org.osgi.service.component.annotations.Deactivate; |
| 45 | import org.osgi.service.component.annotations.Reference; |
| 46 | import org.osgi.service.component.annotations.ReferenceCardinality; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 47 | import org.slf4j.Logger; |
| 48 | |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 49 | import static org.slf4j.LoggerFactory.getLogger; |
| 50 | |
| 51 | /** |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 52 | * OSGi Component for ODTN TAPI topology manager application. |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 53 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 54 | @Component(immediate = true, service = TapiTopologyManager.class) |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 55 | public class DcsBasedTapiTopologyManager implements TapiTopologyManager { |
| 56 | |
| 57 | private final Logger log = getLogger(getClass()); |
| 58 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 60 | protected DynamicConfigService dcs; |
| 61 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 63 | protected ModelConverter modelConverter; |
| 64 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 65 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
hiroki | 684aa2f | 2018-05-19 20:48:49 -0700 | [diff] [blame] | 66 | protected TapiResolver tapiResolver; |
| 67 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 68 | private DefaultContext context; |
| 69 | private DefaultTopology topology; |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 70 | |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 71 | @Activate |
| 72 | public void activate() { |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 73 | initDcsTapiContext(); |
| 74 | initDcsTapiTopology(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 75 | initDcsTapiConnectivityContext(); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 76 | log.info("Started"); |
| 77 | } |
| 78 | |
| 79 | @Deactivate |
| 80 | public void deactivate() { |
| 81 | log.info("Stopped"); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public void addDevice(Device device) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 86 | log.debug("Add device: {}", device); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 87 | DeviceId deviceId = device.id(); |
| 88 | if (tapiResolver.hasNodeRef(deviceId)) { |
| 89 | return; |
| 90 | } |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 91 | TapiNodeHandler.create() |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 92 | .setTopologyUuid(topology.uuid()) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 93 | .setDeviceId(deviceId).add(); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void removeDevice(Device device) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 98 | //TODO Implement |
| 99 | log.warn("NOT-IMPLEMENTED, Remove device: {}", device); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void addLink(Link link) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 104 | log.debug("Add link: {}", link); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 105 | |
hiroki | 684aa2f | 2018-05-19 20:48:49 -0700 | [diff] [blame] | 106 | // TODO: existence check |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 107 | |
| 108 | // link |
| 109 | TapiNepRef srcNepRef = tapiResolver.getNepRef(link.src()); |
| 110 | TapiNepRef dstNepRef = tapiResolver.getNepRef(link.dst()); |
| 111 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 112 | TapiLinkHandler.create() |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 113 | .setTopologyUuid(topology.uuid()) |
hiroki | 684aa2f | 2018-05-19 20:48:49 -0700 | [diff] [blame] | 114 | .addNep(srcNepRef) |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 115 | .addNep(dstNepRef).add(); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public void removeLink(Link link) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 120 | //TODO Implement |
| 121 | log.warn("NOT-IMPLEMENTED, Remove link: {}", link); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 125 | public void addPort(Port port) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 126 | log.debug("Add port: {}", port); |
hiroki | 684aa2f | 2018-05-19 20:48:49 -0700 | [diff] [blame] | 127 | |
| 128 | ConnectPoint cp = new ConnectPoint(port.element().id(), port.number()); |
| 129 | if (tapiResolver.hasNepRef(cp)) { |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 130 | return; |
| 131 | } |
| 132 | |
| 133 | TapiNodeRef nodeRef = tapiResolver.getNodeRef(port.element().id()); |
| 134 | String nodeId = nodeRef.getNodeId(); |
| 135 | |
| 136 | // nep |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 137 | TapiNepHandler nepBuilder = TapiNepHandler.create() |
| 138 | .setPort(port) |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 139 | .setTopologyUuid(topology.uuid()) |
| 140 | .setNodeUuid(Uuid.fromString(nodeId)); |
| 141 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 142 | // cep |
| 143 | TapiCepHandler cepBuilder = TapiCepHandler.create() |
| 144 | .setTopologyUuid(topology.uuid()) |
| 145 | .setNodeUuid(Uuid.fromString(nodeId)) |
| 146 | .setNepUuid(nepBuilder.getId()) |
| 147 | .setParentNep(); |
| 148 | nepBuilder.addCep(cepBuilder.getModelObject()); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 149 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 150 | if (TapiSipHandler.isSip(port)) { |
| 151 | TapiSipHandler sipBuilder = TapiSipHandler.create().setPort(port); |
| 152 | nepBuilder.addSip(sipBuilder.getId()); |
| 153 | |
| 154 | sipBuilder.add(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 155 | } |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 156 | |
| 157 | nepBuilder.add(); |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | @Override |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 161 | public void removePort(Port port) { |
Andrea Campanella | 77e9b33 | 2018-11-29 13:33:19 -0800 | [diff] [blame] | 162 | //TODO implement |
| 163 | log.warn("NOT-IMPLEMENTED, Remove port: {}", port); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 164 | } |
| 165 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 166 | /** |
| 167 | * Add Tapi Context to Dcs store. |
| 168 | */ |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 169 | private void initDcsTapiContext() { |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 170 | TapiContextHandler contextHandler = TapiContextHandler.create(); |
| 171 | context = contextHandler.getModelObject(); |
| 172 | contextHandler.add(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 173 | } |
| 174 | |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 175 | /** |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 176 | * Add Tapi TopologyContext and Topology to Dcs store. |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 177 | * |
| 178 | * Assumed there is only one topology for ODTN Phase 1.0 |
| 179 | */ |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 180 | private void initDcsTapiTopology() { |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 181 | TapiTopologyContextHandler topologyContextHandler = TapiTopologyContextHandler.create(); |
| 182 | topologyContextHandler.add(); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 183 | TapiTopologyHandler topologyHandler = TapiTopologyHandler.create(); |
hiroki | f4ed521 | 2018-05-26 22:39:38 -0700 | [diff] [blame] | 184 | topologyHandler.add(); |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 185 | topology = topologyHandler.getModelObject(); |
hiroki | ec18d3a | 2018-05-16 15:27:37 -0700 | [diff] [blame] | 186 | } |
hiroki | d8fd786 | 2018-10-09 15:24:24 +0900 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * Add Tapi ConnectivityContext to Dcs store. |
| 190 | * |
| 191 | * Assumed there is only one topology for ODTN Phase 1.0 |
| 192 | */ |
| 193 | private void initDcsTapiConnectivityContext() { |
| 194 | TapiConnectivityContextHandler connectivityContextHandler = TapiConnectivityContextHandler.create(); |
| 195 | connectivityContextHandler.add(); |
| 196 | } |
| 197 | |
hiroki | bca3e93 | 2018-05-15 15:25:54 -0700 | [diff] [blame] | 198 | } |