blob: fe9f8841bdffd8a5fe0c74b44a1cf8e96ba039ca [file] [log] [blame]
Thomas Vachuska33979fd2015-07-31 11:41:14 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.incubator.net.virtual.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.apache.felix.scr.annotations.Service;
Thomas Vachuska33979fd2015-07-31 11:41:14 -070024import org.onosproject.incubator.net.tunnel.TunnelId;
25import org.onosproject.incubator.net.virtual.NetworkId;
26import org.onosproject.incubator.net.virtual.TenantId;
27import org.onosproject.incubator.net.virtual.VirtualDevice;
28import org.onosproject.incubator.net.virtual.VirtualLink;
29import org.onosproject.incubator.net.virtual.VirtualNetwork;
30import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService;
31import org.onosproject.incubator.net.virtual.VirtualNetworkEvent;
32import org.onosproject.incubator.net.virtual.VirtualNetworkListener;
Thomas Vachuska3d62fd72015-09-25 14:58:13 -070033import org.onosproject.incubator.net.virtual.VirtualNetworkProvider;
34import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry;
35import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService;
Thomas Vachuska33979fd2015-07-31 11:41:14 -070036import org.onosproject.incubator.net.virtual.VirtualNetworkService;
37import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
38import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate;
39import org.onosproject.incubator.net.virtual.VirtualPort;
40import org.onosproject.net.ConnectPoint;
41import org.onosproject.net.DeviceId;
42import org.onosproject.net.Port;
43import org.onosproject.net.PortNumber;
Thomas Vachuska3d62fd72015-09-25 14:58:13 -070044import org.onosproject.net.provider.AbstractListenerProviderRegistry;
45import org.onosproject.net.provider.AbstractProviderService;
Thomas Vachuska33979fd2015-07-31 11:41:14 -070046import org.slf4j.Logger;
47import org.slf4j.LoggerFactory;
48
49import java.util.Set;
50
51import static com.google.common.base.Preconditions.checkNotNull;
52
53/**
54 * Implementation of the virtual network service.
55 */
56@Component(immediate = true)
57@Service
58public class VirtualNetworkManager
Thomas Vachuska3d62fd72015-09-25 14:58:13 -070059 extends AbstractListenerProviderRegistry<VirtualNetworkEvent, VirtualNetworkListener,
60 VirtualNetworkProvider, VirtualNetworkProviderService>
61 implements VirtualNetworkService, VirtualNetworkAdminService, VirtualNetworkProviderRegistry {
Thomas Vachuska33979fd2015-07-31 11:41:14 -070062
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
73 private VirtualNetworkStoreDelegate delegate = new InternalStoreDelegate();
74
Thomas Vachuska3d62fd72015-09-25 14:58:13 -070075 // TODO: figure out how to coordinate "implementation" of a virtual network in a cluster
Thomas Vachuska33979fd2015-07-31 11:41:14 -070076
77 @Activate
78 protected void activate() {
79 store.setDelegate(delegate);
80 log.info("Started");
81 }
82
83 @Deactivate
84 protected void deactivate() {
85 store.unsetDelegate(delegate);
86 log.info("Stopped");
87 }
88
89 @Override
90 public void registerTenantId(TenantId tenantId) {
91 checkNotNull(tenantId, TENANT_NULL);
92 store.addTenantId(tenantId);
93 }
94
95 @Override
96 public void unregisterTenantId(TenantId tenantId) {
97 checkNotNull(tenantId, TENANT_NULL);
98 store.removeTenantId(tenantId);
99 }
100
101 @Override
102 public Set<TenantId> getTenantIds() {
103 return store.getTenantIds();
104 }
105
106 @Override
107 public VirtualNetwork createVirtualNetwork(TenantId tenantId) {
108 checkNotNull(tenantId, TENANT_NULL);
109 return store.addNetwork(tenantId);
110 }
111
112 @Override
113 public void removeVirtualNetwork(NetworkId networkId) {
114 checkNotNull(networkId, NETWORK_NULL);
115 store.removeNetwork(networkId);
116 }
117
118 @Override
119 public VirtualDevice createVirtualDevice(NetworkId networkId, DeviceId deviceId) {
120 checkNotNull(networkId, NETWORK_NULL);
121 checkNotNull(deviceId, DEVICE_NULL);
122 return store.addDevice(networkId, deviceId);
123 }
124
125 @Override
126 public void removeVirtualDevice(NetworkId networkId, DeviceId deviceId) {
127 checkNotNull(networkId, NETWORK_NULL);
128 checkNotNull(deviceId, DEVICE_NULL);
129 store.removeDevice(networkId, deviceId);
130 }
131
132 @Override
133 public VirtualLink createVirtualLink(NetworkId networkId,
134 ConnectPoint src, ConnectPoint dst,
135 TunnelId realizedBy) {
136 checkNotNull(networkId, NETWORK_NULL);
137 checkNotNull(src, LINK_POINT_NULL);
138 checkNotNull(dst, LINK_POINT_NULL);
139 checkNotNull(realizedBy, "Tunnel ID cannot be null");
140 return store.addLink(networkId, src, dst, realizedBy);
141 }
142
143 @Override
144 public void removeVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) {
145 checkNotNull(networkId, NETWORK_NULL);
146 checkNotNull(src, LINK_POINT_NULL);
147 checkNotNull(dst, LINK_POINT_NULL);
148 store.removeLink(networkId, src, dst);
149 }
150
151 @Override
152 public VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId,
153 PortNumber portNumber, Port realizedBy) {
154 checkNotNull(networkId, NETWORK_NULL);
155 checkNotNull(deviceId, DEVICE_NULL);
156 checkNotNull(portNumber, "Port description cannot be null");
157 return store.addPort(networkId, deviceId, portNumber, realizedBy);
158 }
159
160 @Override
161 public void removeVirtualPort(NetworkId networkId, DeviceId deviceId, PortNumber portNumber) {
162 checkNotNull(networkId, NETWORK_NULL);
163 checkNotNull(deviceId, DEVICE_NULL);
164 checkNotNull(portNumber, "Port number cannot be null");
165 store.removePort(networkId, deviceId, portNumber);
166 }
167
168 @Override
169 public Set<VirtualNetwork> getVirtualNetworks(TenantId tenantId) {
170 checkNotNull(tenantId, TENANT_NULL);
171 return store.getNetworks(tenantId);
172 }
173
174 @Override
175 public Set<VirtualDevice> getVirtualDevices(NetworkId networkId) {
176 checkNotNull(networkId, NETWORK_NULL);
177 return store.getDevices(networkId);
178 }
179
180 @Override
181 public Set<VirtualLink> getVirtualLinks(NetworkId networkId) {
182 checkNotNull(networkId, NETWORK_NULL);
183 return store.getLinks(networkId);
184 }
185
186 @Override
187 public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) {
188 checkNotNull(networkId, NETWORK_NULL);
189 checkNotNull(deviceId, DEVICE_NULL);
190 return store.getPorts(networkId, deviceId);
191 }
192
193 @Override
194 public <T> T get(NetworkId networkId, Class<T> serviceClass) {
195 checkNotNull(networkId, NETWORK_NULL);
196 return null;
197 }
198
Thomas Vachuska3d62fd72015-09-25 14:58:13 -0700199 @Override
200 protected VirtualNetworkProviderService createProviderService(VirtualNetworkProvider provider) {
201 return new InternalVirtualNetworkProviderService(provider);
202 }
203
204 // Service issued to registered virtual network providers so that they
205 // can interact with the core.
206 private class InternalVirtualNetworkProviderService
207 extends AbstractProviderService<VirtualNetworkProvider>
208 implements VirtualNetworkProviderService {
209 InternalVirtualNetworkProviderService(VirtualNetworkProvider provider) {
210 super(provider);
211 }
212 }
213
Thomas Vachuska33979fd2015-07-31 11:41:14 -0700214 // Auxiliary store delegate to receive notification about changes in
215 // the virtual network configuration store state - by the store itself.
216 private class InternalStoreDelegate implements VirtualNetworkStoreDelegate {
217 @Override
218 public void notify(VirtualNetworkEvent event) {
219 post(event);
220 }
221 }
222
223}