Merge "Add Interfaces for Openstack L3 forwarding"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / FloatingIPHandler.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.INeutronFloatingIPAware;
13 import org.opendaylight.controller.networkconfig.neutron.NeutronFloatingIP;
14 import org.opendaylight.ovsdb.plugin.api.OvsdbConfigurationService;
15 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
16 import org.opendaylight.ovsdb.plugin.api.OvsdbInventoryListener;
17
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import java.net.HttpURLConnection;
22
23 /**
24  * Handle requests for Neutron Floating IP.
25  */
26 public class FloatingIPHandler extends AbstractHandler
27         implements INeutronFloatingIPAware {
28
29     /**
30      * Logger instance.
31      */
32     static final Logger logger = LoggerFactory.getLogger(FloatingIPHandler.class);
33
34     // The implementation for each of these services is resolved by the OSGi Service Manager
35     private volatile OvsdbConfigurationService ovsdbConfigurationService;
36     private volatile OvsdbConnectionService connectionService;
37     private volatile OvsdbInventoryListener ovsdbInventoryListener;
38
39     /**
40      * Services provide this interface method to indicate if the specified floatingIP can be created
41      *
42      * @param floatingIP
43      *            instance of proposed new Neutron FloatingIP object
44      * @return integer
45      *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299
46      *            results in the create operation being interrupted and the returned status value reflected in the
47      *            HTTP response.
48      */
49     @Override
50     public int canCreateFloatingIP(NeutronFloatingIP floatingIP) {
51         return HttpURLConnection.HTTP_OK;
52     }
53
54
55     /**
56      * Services provide this interface method for taking action after a floatingIP has been created
57      *
58      * @param floatingIP
59      *            instance of new Neutron FloatingIP object
60      */
61     @Override
62     public void neutronFloatingIPCreated(NeutronFloatingIP floatingIP) {
63         logger.debug(" Floating IP created {}, uuid {}",
64                      floatingIP.getFixedIPAddress(),
65                      floatingIP.getFloatingIPUUID());
66     }
67
68     /**
69      * Services provide this interface method to indicate if the specified floatingIP can be changed using the specified
70      * delta
71      *
72      * @param delta
73      *            updates to the floatingIP object using patch semantics
74      * @param original
75      *            instance of the Neutron FloatingIP object to be updated
76      * @return integer
77      *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299
78      *            results in the update operation being interrupted and the returned status value reflected in the
79      *            HTTP response.
80      */
81     @Override
82     public int canUpdateFloatingIP(NeutronFloatingIP delta, NeutronFloatingIP original) {
83         return HttpURLConnection.HTTP_OK;
84     }
85
86     /**
87      * Services provide this interface method for taking action after a floatingIP has been updated
88      *
89      * @param floatingIP
90      *            instance of modified Neutron FloatingIP object
91      */
92     @Override
93     public void neutronFloatingIPUpdated(NeutronFloatingIP floatingIP) {
94         logger.debug(" Floating IP updated {}, uuid {}",
95                      floatingIP.getFixedIPAddress(),
96                      floatingIP.getFloatingIPUUID());
97     }
98
99     /**
100      * Services provide this interface method to indicate if the specified floatingIP can be deleted
101      *
102      * @param floatingIP
103      *            instance of the Neutron FloatingIP object to be deleted
104      * @return integer
105      *            the return value is understood to be a HTTP status code.  A return value outside of 200 through 299
106      *            results in the delete operation being interrupted and the returned status value reflected in the
107      *            HTTP response.
108      */
109     @Override
110     public int canDeleteFloatingIP(NeutronFloatingIP floatingIP) {
111         return HttpURLConnection.HTTP_OK;
112     }
113
114     /**
115      * Services provide this interface method for taking action after a floatingIP has been deleted
116      *
117      * @param floatingIP
118      *            instance of deleted Neutron FloatingIP object
119      */
120     @Override
121     public void neutronFloatingIPDeleted(NeutronFloatingIP floatingIP) {
122         logger.debug(" Floating IP deleted {}, uuid {}",
123                      floatingIP.getFixedIPAddress(),
124                      floatingIP.getFloatingIPUUID());
125     }
126
127     /**
128      * Process the event.
129      *
130      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
131      * @see EventDispatcher
132      */
133     @Override
134     public void processEvent(AbstractEvent abstractEvent) {
135         if (!(abstractEvent instanceof NorthboundEvent)) {
136             logger.error("Unable to process abstract event " + abstractEvent);
137             return;
138         }
139         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
140         switch (ev.getAction()) {
141             // TODO: add handling of events here, once callbacks do something
142             //       other than logging.
143             default:
144                 logger.warn("Unable to process event action " + ev.getAction());
145                 break;
146         }
147     }
148 }