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.controller.networkconfig.neutron.INeutronRouterAware;
13 import org.opendaylight.controller.networkconfig.neutron.NeutronRouter;
14 import org.opendaylight.controller.networkconfig.neutron.NeutronRouter_Interface;
15 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
16 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
17 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import java.net.HttpURLConnection;
25 * Handle requests for Neutron Router.
27 public class RouterHandler extends AbstractHandler
28 implements INeutronRouterAware {
33 static final Logger logger = LoggerFactory.getLogger(RouterHandler.class);
35 // The implementation for each of these services is resolved by the OSGi Service Manager
36 private volatile OvsdbConfigurationService ovsdbConfigurationService;
37 private volatile OvsdbConnectionService connectionService;
38 private volatile OvsdbInventoryListener ovsdbInventoryListener;
41 * Services provide this interface method to indicate if the specified router can be created
44 * instance of proposed new Neutron Router object
46 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
47 * results in the create operation being interrupted and the returned status value reflected in the
51 public int canCreateRouter(NeutronRouter router) {
52 return HttpURLConnection.HTTP_OK;
56 * Services provide this interface method for taking action after a router has been created
59 * instance of new Neutron Router object
62 public void neutronRouterCreated(NeutronRouter router) {
63 logger.debug(" Router created {}, uuid {}", router.getName(), router.getRouterUUID());
67 * Services provide this interface method to indicate if the specified router can be changed using the specified
71 * updates to the router object using patch semantics
73 * instance of the Neutron Router object to be updated
75 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
76 * results in the update operation being interrupted and the returned status value reflected in the
80 public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
81 return HttpURLConnection.HTTP_OK;
85 * Services provide this interface method for taking action after a router has been updated
88 * instance of modified Neutron Router object
91 public void neutronRouterUpdated(NeutronRouter router) {
92 logger.debug(" Router updated {}", router.getName());
96 * Services provide this interface method to indicate if the specified router can be deleted
99 * instance of the Neutron Router object to be deleted
101 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
102 * results in the delete operation being interrupted and the returned status value reflected in the
106 public int canDeleteRouter(NeutronRouter router) {
107 return HttpURLConnection.HTTP_OK;
111 * Services provide this interface method for taking action after a router has been deleted
114 * instance of deleted Router Network object
117 public void neutronRouterDeleted(NeutronRouter router) {
118 logger.debug(" Router deleted {}, uuid {}", router.getName(), router.getRouterUUID());
122 * Services provide this interface method to indicate if the specified interface can be attached to the specified
126 * instance of the base Neutron Router object
127 * @param routerInterface
128 * instance of the NeutronRouter_Interface to be attached to the router
130 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
131 * results in the attach operation being interrupted and the returned status value reflected in the
135 public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
136 logger.debug(" Router {} asked if it can attach interface {}. Subnet {}",
138 routerInterface.getPortUUID(),
139 routerInterface.getSubnetUUID());
140 return HttpURLConnection.HTTP_OK;
144 * Services provide this interface method for taking action after an interface has been added to a router
147 * instance of the base Neutron Router object
148 * @param routerInterface
149 * instance of the NeutronRouter_Interface being attached to the router
152 public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
153 logger.debug(" Router {} interface {} attached. Subnet {}", router.getName(), routerInterface.getPortUUID(),
154 routerInterface.getSubnetUUID());
158 * Services provide this interface method to indicate if the specified interface can be detached from the specified
162 * instance of the base Neutron Router object
163 * @param routerInterface
164 * instance of the NeutronRouter_Interface to be detached to the router
166 * the return value is understood to be a HTTP status code. A return value outside of 200 through 299
167 * results in the detach operation being interrupted and the returned status value reflected in the
171 public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
172 logger.debug(" Router {} asked if it can detach interface {}. Subnet {}",
174 routerInterface.getPortUUID(),
175 routerInterface.getSubnetUUID());
177 return HttpURLConnection.HTTP_OK;
181 * Services provide this interface method for taking action after an interface has been removed from a router
184 * instance of the base Neutron Router object
185 * @param routerInterface
186 * instance of the NeutronRouter_Interface being detached from the router
189 public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
190 logger.debug(" Router {} interface {} detached. Subnet {}", router.getName(), routerInterface.getPortUUID(),
191 routerInterface.getSubnetUUID());
197 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
198 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
201 public void processEvent(AbstractEvent abstractEvent) {
202 if (!(abstractEvent instanceof NorthboundEvent)) {
203 logger.error("Unable to process abstract event " + abstractEvent);
206 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
207 switch (ev.getAction()) {
208 // TODO: add handling of events here, once callbacks do something
209 // other than logging.
211 logger.warn("Unable to process event action " + ev.getAction());