Merge "l3 support (partial): move event dispatch from southBoundHandler"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / RouterHandler.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Dave Tucker, Flavio Fernandes
9  */
10 package org.opendaylight.ovsdb.openstack.netvirt;
11
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;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import java.net.HttpURLConnection;
23
24 /**
25  * Handle requests for Neutron Router.
26  */
27 public class RouterHandler extends AbstractHandler
28         implements INeutronRouterAware {
29
30     /**
31      * Logger instance.
32      */
33     static final Logger logger = LoggerFactory.getLogger(RouterHandler.class);
34
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;
39
40     /**
41      * Services provide this interface method to indicate if the specified router can be created
42      *
43      * @param router
44      *            instance of proposed new Neutron Router object
45      * @return integer
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
48      *            HTTP response.
49      */
50     @Override
51     public int canCreateRouter(NeutronRouter router) {
52         return HttpURLConnection.HTTP_OK;
53     }
54
55     /**
56      * Services provide this interface method for taking action after a router has been created
57      *
58      * @param router
59      *            instance of new Neutron Router object
60      */
61     @Override
62     public void neutronRouterCreated(NeutronRouter router) {
63         logger.debug(" Router created {}, uuid {}", router.getName(), router.getRouterUUID());
64     }
65
66     /**
67      * Services provide this interface method to indicate if the specified router can be changed using the specified
68      * delta
69      *
70      * @param delta
71      *            updates to the router object using patch semantics
72      * @param router
73      *            instance of the Neutron Router object to be updated
74      * @return integer
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
77      *            HTTP response.
78      */
79     @Override
80     public int canUpdateRouter(NeutronRouter delta, NeutronRouter original) {
81         return HttpURLConnection.HTTP_OK;
82     }
83
84     /**
85      * Services provide this interface method for taking action after a router has been updated
86      *
87      * @param router
88      *            instance of modified Neutron Router object
89      */
90     @Override
91     public void neutronRouterUpdated(NeutronRouter router) {
92         logger.debug(" Router updated {}", router.getName());
93     }
94
95     /**
96      * Services provide this interface method to indicate if the specified router can be deleted
97      *
98      * @param router
99      *            instance of the Neutron Router object to be deleted
100      * @return integer
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
103      *            HTTP response.
104      */
105     @Override
106     public int canDeleteRouter(NeutronRouter router) {
107         return HttpURLConnection.HTTP_OK;
108     }
109
110     /**
111      * Services provide this interface method for taking action after a router has been deleted
112      *
113      * @param router
114      *            instance of deleted Router Network object
115      */
116     @Override
117     public void neutronRouterDeleted(NeutronRouter router) {
118         logger.debug(" Router deleted {}, uuid {}", router.getName(), router.getRouterUUID());
119     }
120
121     /**
122      * Services provide this interface method to indicate if the specified interface can be attached to the specified
123      * route
124      *
125      * @param router
126      *            instance of the base Neutron Router object
127      * @param routerInterface
128      *            instance of the NeutronRouter_Interface to be attached to the router
129      * @return integer
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
132      *            HTTP response.
133      */
134     @Override
135     public int canAttachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
136         logger.debug(" Router {} asked if it can attach interface {}. Subnet {}",
137                      router.getName(),
138                      routerInterface.getPortUUID(),
139                      routerInterface.getSubnetUUID());
140         return HttpURLConnection.HTTP_OK;
141     }
142
143     /**
144      * Services provide this interface method for taking action after an interface has been added to a router
145      *
146      * @param router
147      *            instance of the base Neutron Router object
148      * @param routerInterface
149      *            instance of the NeutronRouter_Interface being attached to the router
150      */
151     @Override
152     public void neutronRouterInterfaceAttached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
153         logger.debug(" Router {} interface {} attached. Subnet {}", router.getName(), routerInterface.getPortUUID(),
154                      routerInterface.getSubnetUUID());
155     }
156
157     /**
158      * Services provide this interface method to indicate if the specified interface can be detached from the specified
159      * router
160      *
161      * @param router
162      *            instance of the base Neutron Router object
163      * @param routerInterface
164      *            instance of the NeutronRouter_Interface to be detached to the router
165      * @return integer
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
168      *            HTTP response.
169      */
170     @Override
171     public int canDetachInterface(NeutronRouter router, NeutronRouter_Interface routerInterface) {
172         logger.debug(" Router {} asked if it can detach interface {}. Subnet {}",
173                      router.getName(),
174                      routerInterface.getPortUUID(),
175                      routerInterface.getSubnetUUID());
176
177         return HttpURLConnection.HTTP_OK;
178     }
179
180     /**
181      * Services provide this interface method for taking action after an interface has been removed from a router
182      *
183      * @param router
184      *            instance of the base Neutron Router object
185      * @param routerInterface
186      *            instance of the NeutronRouter_Interface being detached from the router
187      */
188     @Override
189     public void neutronRouterInterfaceDetached(NeutronRouter router, NeutronRouter_Interface routerInterface) {
190         logger.debug(" Router {} interface {} detached. Subnet {}", router.getName(), routerInterface.getPortUUID(),
191                      routerInterface.getSubnetUUID());
192     }
193
194     /**
195      * Process the event.
196      *
197      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
198      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
199      */
200     @Override
201     public void processEvent(AbstractEvent abstractEvent) {
202         if (!(abstractEvent instanceof NorthboundEvent)) {
203             logger.error("Unable to process abstract event " + abstractEvent);
204             return;
205         }
206         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
207         switch (ev.getAction()) {
208             // TODO: add handling of events here, once callbacks do something
209             //       other than logging.
210             default:
211                 logger.warn("Unable to process event action " + ev.getAction());
212                 break;
213         }
214     }
215 }