2 * Copyright (C) 2014 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Dave Tucker, Flavio Fernandes
10 package org.opendaylight.ovsdb.openstack.netvirt;
12 import org.opendaylight.neutron.spi.INeutronRouterAware;
13 import org.opendaylight.neutron.spi.NeutronRouter;
14 import org.opendaylight.neutron.spi.NeutronRouter_Interface;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
17 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
19 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.ServiceReference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import java.net.HttpURLConnection;
28 * Handle requests for Neutron Router.
30 public class RouterHandler extends AbstractHandler implements INeutronRouterAware, ConfigInterface {
31 static final Logger logger = LoggerFactory.getLogger(RouterHandler.class);
33 // The implementation for each of these services is resolved by the OSGi Service Manager
34 private volatile NeutronL3Adapter neutronL3Adapter;
35 private volatile EventDispatcher eventDispatcher;
38 * Services provide this interface method to indicate if the specified router can be created
41 * instance of proposed new Neutron Router object
43 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
44 * results in the create operation being interrupted and the returned status value reflected in the
48 public int canCreateRouter(NeutronRouter router) {
49 return HttpURLConnection.HTTP_OK;
53 * Services provide this interface method for taking action after a router has been created
56 * instance of new Neutron Router object
59 public void neutronRouterCreated(NeutronRouter router) {
60 enqueueEvent(new NorthboundEvent(router, Action.ADD));
64 * Services provide this interface method to indicate if the specified router can be changed using the specified
68 * updates to the router object using patch semantics
70 * instance of the Neutron Router object to be updated
72 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
73 * results in the update operation being interrupted and the returned status value reflected in the
77 public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
78 return HttpURLConnection.HTTP_OK;
82 * Services provide this interface method for taking action after a router has been updated
85 * instance of modified Neutron Router object
88 public void neutronRouterUpdated(NeutronRouter router) {
89 enqueueEvent(new NorthboundEvent(router, Action.UPDATE));
93 * Services provide this interface method to indicate if the specified router can be deleted
96 * instance of the Neutron Router object to be deleted
98 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
99 * results in the delete operation being interrupted and the returned status value reflected in the
103 public int canDeleteRouter(NeutronRouter router) {
104 return HttpURLConnection.HTTP_OK;
108 * Services provide this interface method for taking action after a router has been deleted
111 * instance of deleted Router Network object
114 public void neutronRouterDeleted(NeutronRouter router) {
115 enqueueEvent(new NorthboundEvent(router, Action.DELETE));
119 * Services provide this interface method to indicate if the specified interface can be attached to the specified
123 * instance of the base Neutron Router object
124 * @param routerInterface
125 * instance of the NeutronRouter_Interface to be attached to the router
127 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
128 * results in the attach operation being interrupted and the returned status value reflected in the
132 public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
133 logger.debug(" Router {} asked if it can attach interface {}. Subnet {}",
135 routerInterface.getPortUUID(),
136 routerInterface.getSubnetUUID());
137 return HttpURLConnection.HTTP_OK;
141 * Services provide this interface method for taking action after an interface has been added to a router
144 * instance of the base Neutron Router object
145 * @param routerInterface
146 * instance of the NeutronRouter_Interface being attached to the router
149 public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
150 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.ADD));
154 * Services provide this interface method to indicate if the specified interface can be detached from the specified
158 * instance of the base Neutron Router object
159 * @param routerInterface
160 * instance of the NeutronRouter_Interface to be detached to the router
162 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
163 * results in the detach operation being interrupted and the returned status value reflected in the
167 public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
168 logger.debug(" Router {} asked if it can detach interface {}. Subnet {}",
170 routerInterface.getPortUUID(),
171 routerInterface.getSubnetUUID());
173 return HttpURLConnection.HTTP_OK;
177 * Services provide this interface method for taking action after an interface has been removed from a router
180 * instance of the base Neutron Router object
181 * @param routerInterface
182 * instance of the NeutronRouter_Interface being detached from the router
185 public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
186 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.DELETE));
192 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
193 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
196 public void processEvent(AbstractEvent abstractEvent) {
197 if (!(abstractEvent instanceof NorthboundEvent)) {
198 logger.error("Unable to process abstract event " + abstractEvent);
201 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
202 switch (ev.getAction()) {
208 if (ev.getRouterInterface() == null) {
209 neutronL3Adapter.handleNeutronRouterEvent(ev.getRouter(), ev.getAction());
211 neutronL3Adapter.handleNeutronRouterInterfaceEvent(ev.getRouter(),
212 ev.getRouterInterface(),
217 logger.warn("Unable to process event action " + ev.getAction());
223 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
225 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
227 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
228 eventDispatcher.eventHandlerAdded(
229 bundleContext.getServiceReference(INeutronRouterAware.class.getName()), this);
230 super.setDispatcher(eventDispatcher);
234 public void setDependencies(Object impl) {}