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.impl.NeutronL3Adapter;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import java.net.HttpURLConnection;
24 * Handle requests for Neutron Router.
26 public class RouterHandler extends AbstractHandler implements INeutronRouterAware {
27 static final Logger logger = LoggerFactory.getLogger(RouterHandler.class);
29 // The implementation for each of these services is resolved by the OSGi Service Manager
30 private volatile NeutronL3Adapter neutronL3Adapter;
33 * Services provide this interface method to indicate if the specified router can be created
36 * instance of proposed new Neutron Router object
38 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
39 * results in the create operation being interrupted and the returned status value reflected in the
43 public int canCreateRouter(NeutronRouter router) {
44 return HttpURLConnection.HTTP_OK;
48 * Services provide this interface method for taking action after a router has been created
51 * instance of new Neutron Router object
54 public void neutronRouterCreated(NeutronRouter router) {
55 enqueueEvent(new NorthboundEvent(router, Action.ADD));
59 * Services provide this interface method to indicate if the specified router can be changed using the specified
63 * updates to the router object using patch semantics
65 * instance of the Neutron Router object to be updated
67 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
68 * results in the update operation being interrupted and the returned status value reflected in the
72 public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
73 return HttpURLConnection.HTTP_OK;
77 * Services provide this interface method for taking action after a router has been updated
80 * instance of modified Neutron Router object
83 public void neutronRouterUpdated(NeutronRouter router) {
84 enqueueEvent(new NorthboundEvent(router, Action.UPDATE));
88 * Services provide this interface method to indicate if the specified router can be deleted
91 * instance of the Neutron Router object to be deleted
93 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
94 * results in the delete operation being interrupted and the returned status value reflected in the
98 public int canDeleteRouter(NeutronRouter router) {
99 return HttpURLConnection.HTTP_OK;
103 * Services provide this interface method for taking action after a router has been deleted
106 * instance of deleted Router Network object
109 public void neutronRouterDeleted(NeutronRouter router) {
110 enqueueEvent(new NorthboundEvent(router, Action.DELETE));
114 * Services provide this interface method to indicate if the specified interface can be attached to the specified
118 * instance of the base Neutron Router object
119 * @param routerInterface
120 * instance of the NeutronRouter_Interface to be attached to the router
122 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
123 * results in the attach operation being interrupted and the returned status value reflected in the
127 public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
128 logger.debug(" Router {} asked if it can attach interface {}. Subnet {}",
130 routerInterface.getPortUUID(),
131 routerInterface.getSubnetUUID());
132 return HttpURLConnection.HTTP_OK;
136 * Services provide this interface method for taking action after an interface has been added to a router
139 * instance of the base Neutron Router object
140 * @param routerInterface
141 * instance of the NeutronRouter_Interface being attached to the router
144 public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
145 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.ADD));
149 * Services provide this interface method to indicate if the specified interface can be detached from the specified
153 * instance of the base Neutron Router object
154 * @param routerInterface
155 * instance of the NeutronRouter_Interface to be detached to the router
157 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
158 * results in the detach operation being interrupted and the returned status value reflected in the
162 public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
163 logger.debug(" Router {} asked if it can detach interface {}. Subnet {}",
165 routerInterface.getPortUUID(),
166 routerInterface.getSubnetUUID());
168 return HttpURLConnection.HTTP_OK;
172 * Services provide this interface method for taking action after an interface has been removed from a router
175 * instance of the base Neutron Router object
176 * @param routerInterface
177 * instance of the NeutronRouter_Interface being detached from the router
180 public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
181 enqueueEvent(new NorthboundEvent(router, routerInterface, Action.DELETE));
187 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
188 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
191 public void processEvent(AbstractEvent abstractEvent) {
192 if (!(abstractEvent instanceof NorthboundEvent)) {
193 logger.error("Unable to process abstract event " + abstractEvent);
196 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
197 switch (ev.getAction()) {
203 if (ev.getRouterInterface() == null) {
204 neutronL3Adapter.handleNeutronRouterEvent(ev.getRouter(), ev.getAction());
206 neutronL3Adapter.handleNeutronRouterInterfaceEvent(ev.getRouter(),
207 ev.getRouterInterface(),
212 logger.warn("Unable to process event action " + ev.getAction());