Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 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 | package org.onosproject.incubator.net.virtual.impl; |
| 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | import org.apache.felix.scr.annotations.Service; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 24 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 25 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 26 | import org.onosproject.incubator.net.virtual.TenantId; |
| 27 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
| 28 | import org.onosproject.incubator.net.virtual.VirtualLink; |
| 29 | import org.onosproject.incubator.net.virtual.VirtualNetwork; |
| 30 | import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService; |
| 31 | import org.onosproject.incubator.net.virtual.VirtualNetworkEvent; |
| 32 | import org.onosproject.incubator.net.virtual.VirtualNetworkListener; |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 33 | import org.onosproject.incubator.net.virtual.VirtualNetworkProvider; |
| 34 | import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry; |
| 35 | import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 36 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
| 37 | import org.onosproject.incubator.net.virtual.VirtualNetworkStore; |
| 38 | import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; |
| 39 | import org.onosproject.incubator.net.virtual.VirtualPort; |
| 40 | import org.onosproject.net.ConnectPoint; |
| 41 | import org.onosproject.net.DeviceId; |
| 42 | import org.onosproject.net.Port; |
| 43 | import org.onosproject.net.PortNumber; |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 44 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
| 45 | import org.onosproject.net.provider.AbstractProviderService; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 46 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; |
| 48 | |
| 49 | import java.util.Set; |
| 50 | |
| 51 | import static com.google.common.base.Preconditions.checkNotNull; |
| 52 | |
| 53 | /** |
| 54 | * Implementation of the virtual network service. |
| 55 | */ |
| 56 | @Component(immediate = true) |
| 57 | @Service |
| 58 | public class VirtualNetworkManager |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 59 | extends AbstractListenerProviderRegistry<VirtualNetworkEvent, VirtualNetworkListener, |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 60 | VirtualNetworkProvider, VirtualNetworkProviderService> |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 61 | implements VirtualNetworkService, VirtualNetworkAdminService, VirtualNetworkProviderRegistry { |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 62 | |
| 63 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 64 | |
| 65 | private static final String TENANT_NULL = "Tenant ID cannot be null"; |
| 66 | private static final String NETWORK_NULL = "Network ID cannot be null"; |
| 67 | private static final String DEVICE_NULL = "Device ID cannot be null"; |
| 68 | private static final String LINK_POINT_NULL = "Link end-point cannot be null"; |
| 69 | |
| 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 71 | protected VirtualNetworkStore store; |
| 72 | |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 73 | private VirtualNetworkStoreDelegate delegate = this::post; |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 74 | |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 75 | // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 76 | |
| 77 | @Activate |
| 78 | protected void activate() { |
| 79 | store.setDelegate(delegate); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 80 | eventDispatcher.addSink(VirtualNetworkEvent.class, listenerRegistry); |
| 81 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 82 | log.info("Started"); |
| 83 | } |
| 84 | |
| 85 | @Deactivate |
| 86 | protected void deactivate() { |
| 87 | store.unsetDelegate(delegate); |
Brian Stanke | 0e5c94e | 2016-03-08 11:20:04 -0500 | [diff] [blame] | 88 | eventDispatcher.removeSink(VirtualNetworkEvent.class); |
| 89 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 90 | log.info("Stopped"); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void registerTenantId(TenantId tenantId) { |
| 95 | checkNotNull(tenantId, TENANT_NULL); |
| 96 | store.addTenantId(tenantId); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void unregisterTenantId(TenantId tenantId) { |
| 101 | checkNotNull(tenantId, TENANT_NULL); |
| 102 | store.removeTenantId(tenantId); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public Set<TenantId> getTenantIds() { |
| 107 | return store.getTenantIds(); |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public VirtualNetwork createVirtualNetwork(TenantId tenantId) { |
| 112 | checkNotNull(tenantId, TENANT_NULL); |
| 113 | return store.addNetwork(tenantId); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void removeVirtualNetwork(NetworkId networkId) { |
| 118 | checkNotNull(networkId, NETWORK_NULL); |
| 119 | store.removeNetwork(networkId); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public VirtualDevice createVirtualDevice(NetworkId networkId, DeviceId deviceId) { |
| 124 | checkNotNull(networkId, NETWORK_NULL); |
| 125 | checkNotNull(deviceId, DEVICE_NULL); |
| 126 | return store.addDevice(networkId, deviceId); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void removeVirtualDevice(NetworkId networkId, DeviceId deviceId) { |
| 131 | checkNotNull(networkId, NETWORK_NULL); |
| 132 | checkNotNull(deviceId, DEVICE_NULL); |
| 133 | store.removeDevice(networkId, deviceId); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public VirtualLink createVirtualLink(NetworkId networkId, |
| 138 | ConnectPoint src, ConnectPoint dst, |
| 139 | TunnelId realizedBy) { |
| 140 | checkNotNull(networkId, NETWORK_NULL); |
| 141 | checkNotNull(src, LINK_POINT_NULL); |
| 142 | checkNotNull(dst, LINK_POINT_NULL); |
| 143 | checkNotNull(realizedBy, "Tunnel ID cannot be null"); |
| 144 | return store.addLink(networkId, src, dst, realizedBy); |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void removeVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { |
| 149 | checkNotNull(networkId, NETWORK_NULL); |
| 150 | checkNotNull(src, LINK_POINT_NULL); |
| 151 | checkNotNull(dst, LINK_POINT_NULL); |
| 152 | store.removeLink(networkId, src, dst); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId, |
| 157 | PortNumber portNumber, Port realizedBy) { |
| 158 | checkNotNull(networkId, NETWORK_NULL); |
| 159 | checkNotNull(deviceId, DEVICE_NULL); |
| 160 | checkNotNull(portNumber, "Port description cannot be null"); |
| 161 | return store.addPort(networkId, deviceId, portNumber, realizedBy); |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void removeVirtualPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) { |
| 166 | checkNotNull(networkId, NETWORK_NULL); |
| 167 | checkNotNull(deviceId, DEVICE_NULL); |
| 168 | checkNotNull(portNumber, "Port number cannot be null"); |
| 169 | store.removePort(networkId, deviceId, portNumber); |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public Set<VirtualNetwork> getVirtualNetworks(TenantId tenantId) { |
| 174 | checkNotNull(tenantId, TENANT_NULL); |
| 175 | return store.getNetworks(tenantId); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public Set<VirtualDevice> getVirtualDevices(NetworkId networkId) { |
| 180 | checkNotNull(networkId, NETWORK_NULL); |
| 181 | return store.getDevices(networkId); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public Set<VirtualLink> getVirtualLinks(NetworkId networkId) { |
| 186 | checkNotNull(networkId, NETWORK_NULL); |
| 187 | return store.getLinks(networkId); |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) { |
| 192 | checkNotNull(networkId, NETWORK_NULL); |
| 193 | checkNotNull(deviceId, DEVICE_NULL); |
| 194 | return store.getPorts(networkId, deviceId); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public <T> T get(NetworkId networkId, Class<T> serviceClass) { |
| 199 | checkNotNull(networkId, NETWORK_NULL); |
| 200 | return null; |
| 201 | } |
| 202 | |
Thomas Vachuska | 3d62fd7 | 2015-09-25 14:58:13 -0700 | [diff] [blame] | 203 | @Override |
| 204 | protected VirtualNetworkProviderService createProviderService(VirtualNetworkProvider provider) { |
| 205 | return new InternalVirtualNetworkProviderService(provider); |
| 206 | } |
| 207 | |
| 208 | // Service issued to registered virtual network providers so that they |
| 209 | // can interact with the core. |
| 210 | private class InternalVirtualNetworkProviderService |
| 211 | extends AbstractProviderService<VirtualNetworkProvider> |
| 212 | implements VirtualNetworkProviderService { |
| 213 | InternalVirtualNetworkProviderService(VirtualNetworkProvider provider) { |
| 214 | super(provider); |
| 215 | } |
| 216 | } |
| 217 | |
Thomas Vachuska | 33979fd | 2015-07-31 11:41:14 -0700 | [diff] [blame] | 218 | } |