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.ServiceReference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Handle requests for Neutron Router.
27 public class RouterHandler extends AbstractHandler implements INeutronRouterAware, ConfigInterface {
28 private static final Logger LOG = LoggerFactory.getLogger(RouterHandler.class);
30 // The implementation for each of these services is resolved by the OSGi Service Manager
31 private volatile NeutronL3Adapter neutronL3Adapter;
34 * Services provide this interface method to indicate if the specified router can be created
37 * instance of proposed new Neutron Router object
39 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
40 * results in the create operation being interrupted and the returned status value reflected in the
44 public int canCreateRouter(NeutronRouter router) {
45 return HttpURLConnection.HTTP_OK;
49 * Services provide this interface method for taking action after a router has been created
52 * instance of new Neutron Router object
55 public void neutronRouterCreated(NeutronRouter router) {
56 enqueueEvent(new NorthboundEvent(router, Action.ADD));
60 * Services provide this interface method to indicate if the specified router can be changed using the specified
64 * updates to the router object using patch semantics
66 * instance of the Neutron Router object to be updated
68 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
69 * results in the update operation being interrupted and the returned status value reflected in the
73 public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
74 return HttpURLConnection.HTTP_OK;
78 * Services provide this interface method for taking action after a router has been updated
81 * instance of modified Neutron Router object
84 public void neutronRouterUpdated(NeutronRouter router) {
85 enqueueEvent(new NorthboundEvent(router, Action.UPDATE));
89 * Services provide this interface method to indicate if the specified router can be deleted
92 * instance of the Neutron Router object to be deleted
94 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
95 * results in the delete operation being interrupted and the returned status value reflected in the
99 public int canDeleteRouter(NeutronRouter router) {
100 return HttpURLConnection.HTTP_OK;
104 * Services provide this interface method for taking action after a router has been deleted
107 * instance of deleted Router Network object
110 public void neutronRouterDeleted(NeutronRouter router) {
111 enqueueEvent(new NorthboundEvent(router, Action.DELETE));
115 * Services provide this interface method to indicate if the specified interface can be attached to the specified
119 * instance of the base Neutron Router object
120 * @param routerInterface
121 * instance of the NeutronRouter_Interface to be attached to the router
123 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
124 * results in the attach operation being interrupted and the returned status value reflected in the
128 public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
129 LOG.debug(" Router {} asked if it can attach interface {}. Subnet {}",
131 routerInterface.getPortUUID(),
132 routerInterface.getSubnetUUID());
133 return HttpURLConnection.HTTP_OK;
137 * Services provide this interface method for taking action after an interface has been added to a router
140 * instance of the base Neutron Router object
141 * @param routerInterface
142 * instance of the NeutronRouter_Interface being attached to the router
145 public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
146 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.ADD));
150 * Services provide this interface method to indicate if the specified interface can be detached from the specified
154 * instance of the base Neutron Router object
155 * @param routerInterface
156 * instance of the NeutronRouter_Interface to be detached to the router
158 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
159 * results in the detach operation being interrupted and the returned status value reflected in the
163 public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
164 LOG.debug(" Router {} asked if it can detach interface {}. Subnet {}",
166 routerInterface.getPortUUID(),
167 routerInterface.getSubnetUUID());
169 return HttpURLConnection.HTTP_OK;
173 * Services provide this interface method for taking action after an interface has been removed from a router
176 * instance of the base Neutron Router object
177 * @param routerInterface
178 * instance of the NeutronRouter_Interface being detached from the router
181 public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
182 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.DELETE));
188 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
189 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
192 public void processEvent(AbstractEvent abstractEvent) {
193 if (!(abstractEvent instanceof NorthboundEvent)) {
194 LOG.error("Unable to process abstract event {}", abstractEvent);
197 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
198 switch (ev.getAction()) {
204 if (ev.getRouterInterface() == null) {
205 neutronL3Adapter.handleNeutronRouterEvent(ev.getRouter(), ev.getAction());
207 neutronL3Adapter.handleNeutronRouterInterfaceEvent(ev.getRouter(),
208 ev.getRouterInterface(),
213 LOG.warn("Unable to process event action {}", ev.getAction());
219 public void setDependencies(ServiceReference serviceReference) {
221 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
223 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
224 eventDispatcher.eventHandlerAdded(serviceReference, this);
228 public void setDependencies(Object impl) {}