2 * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
11 import java.net.HttpURLConnection;
13 import org.opendaylight.neutron.spi.INeutronRouterAware;
14 import org.opendaylight.neutron.spi.NeutronRouter;
15 import org.opendaylight.neutron.spi.NeutronRouter_Interface;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
18 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;
26 * Handle requests for Neutron Router.
28 public class RouterHandler extends AbstractHandler implements INeutronRouterAware, ConfigInterface {
29 private static final Logger LOG = LoggerFactory.getLogger(RouterHandler.class);
31 // The implementation for each of these services is resolved by the OSGi Service Manager
32 private volatile NeutronL3Adapter neutronL3Adapter;
35 * Services provide this interface method to indicate if the specified router can be created
38 * instance of proposed new Neutron Router object
40 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
41 * results in the create operation being interrupted and the returned status value reflected in the
45 public int canCreateRouter(NeutronRouter router) {
46 return HttpURLConnection.HTTP_OK;
50 * Services provide this interface method for taking action after a router has been created
53 * instance of new Neutron Router object
56 public void neutronRouterCreated(NeutronRouter router) {
57 enqueueEvent(new NorthboundEvent(router, Action.ADD));
61 * Services provide this interface method to indicate if the specified router can be changed using the specified
65 * updates to the router object using patch semantics
67 * instance of the Neutron Router object to be updated
69 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
70 * results in the update operation being interrupted and the returned status value reflected in the
74 public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
75 return HttpURLConnection.HTTP_OK;
79 * Services provide this interface method for taking action after a router has been updated
82 * instance of modified Neutron Router object
85 public void neutronRouterUpdated(NeutronRouter router) {
86 enqueueEvent(new NorthboundEvent(router, Action.UPDATE));
90 * Services provide this interface method to indicate if the specified router can be deleted
93 * instance of the Neutron Router object to be deleted
95 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
96 * results in the delete operation being interrupted and the returned status value reflected in the
100 public int canDeleteRouter(NeutronRouter router) {
101 return HttpURLConnection.HTTP_OK;
105 * Services provide this interface method for taking action after a router has been deleted
108 * instance of deleted Router Network object
111 public void neutronRouterDeleted(NeutronRouter router) {
112 enqueueEvent(new NorthboundEvent(router, Action.DELETE));
116 * Services provide this interface method to indicate if the specified interface can be attached to the specified
120 * instance of the base Neutron Router object
121 * @param routerInterface
122 * instance of the NeutronRouter_Interface to be attached to the router
124 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
125 * results in the attach operation being interrupted and the returned status value reflected in the
129 public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
130 LOG.debug(" Router {} asked if it can attach interface {}. Subnet {}",
132 routerInterface.getPortUUID(),
133 routerInterface.getSubnetUUID());
134 return HttpURLConnection.HTTP_OK;
138 * Services provide this interface method for taking action after an interface has been added to a router
141 * instance of the base Neutron Router object
142 * @param routerInterface
143 * instance of the NeutronRouter_Interface being attached to the router
146 public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
147 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.ADD));
151 * Services provide this interface method to indicate if the specified interface can be detached from the specified
155 * instance of the base Neutron Router object
156 * @param routerInterface
157 * instance of the NeutronRouter_Interface to be detached to the router
159 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
160 * results in the detach operation being interrupted and the returned status value reflected in the
164 public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
165 LOG.debug(" Router {} asked if it can detach interface {}. Subnet {}",
167 routerInterface.getPortUUID(),
168 routerInterface.getSubnetUUID());
170 return HttpURLConnection.HTTP_OK;
174 * Services provide this interface method for taking action after an interface has been removed from a router
177 * instance of the base Neutron Router object
178 * @param routerInterface
179 * instance of the NeutronRouter_Interface being detached from the router
182 public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
183 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.DELETE));
189 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
190 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
193 public void processEvent(AbstractEvent abstractEvent) {
194 if (!(abstractEvent instanceof NorthboundEvent)) {
195 LOG.error("Unable to process abstract event {}", abstractEvent);
198 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
199 switch (ev.getAction()) {
205 if (ev.getRouterInterface() == null) {
206 neutronL3Adapter.handleNeutronRouterEvent(ev.getRouter(), ev.getAction());
208 neutronL3Adapter.handleNeutronRouterInterfaceEvent(ev.getRouter(),
209 ev.getRouterInterface(),
214 LOG.warn("Unable to process event action {}", ev.getAction());
220 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
222 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
224 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
225 eventDispatcher.eventHandlerAdded(
226 bundleContext.getServiceReference(INeutronRouterAware.class.getName()), this);
230 public void setDependencies(Object impl) {}