Merge "Add UT for SouthboundMapper and SouthboundProvider"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / PortSecurityHandler.java
1 /*
2  * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import java.net.HttpURLConnection;
12
13 import org.opendaylight.neutron.spi.INeutronSecurityGroupAware;
14 import org.opendaylight.neutron.spi.INeutronSecurityRuleAware;
15 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
16 import org.opendaylight.neutron.spi.NeutronSecurityRule;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
18 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
19 import org.osgi.framework.ServiceReference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
25  */
26 public class PortSecurityHandler extends AbstractHandler
27         implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface {
28
29     private static final Logger LOG = LoggerFactory.getLogger(PortSecurityHandler.class);
30
31     @Override
32     public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
33         return HttpURLConnection.HTTP_CREATED;
34     }
35
36     @Override
37     public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
38         int result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
39         if (result != HttpURLConnection.HTTP_CREATED) {
40             LOG.debug("Neutron Security Group creation failed {} ", result);
41         }
42     }
43
44     @Override
45     public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
46         return HttpURLConnection.HTTP_OK;
47     }
48
49     @Override
50     public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
51         // Nothing to do
52     }
53
54     @Override
55     public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
56         return HttpURLConnection.HTTP_OK;
57     }
58
59     @Override
60     public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
61         //TODO: Trigger flowmod removals
62         int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
63         if  (result != HttpURLConnection.HTTP_OK) {
64             LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
65         }
66     }
67
68     /**
69      * Invoked when a Security Rules creation is requested
70      * to indicate if the specified Rule can be created.
71      *
72      * @param neutronSecurityRule  An instance of proposed new Neutron Security Rule object.
73      * @return A HTTP status code to the creation request.
74      */
75
76     @Override
77     public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
78         return HttpURLConnection.HTTP_CREATED;
79     }
80
81     @Override
82     public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
83         int result = canCreateNeutronSecurityRule(neutronSecurityRule);
84         if (result != HttpURLConnection.HTTP_CREATED) {
85             LOG.debug("Neutron Security Group creation failed {} ", result);
86         }
87     }
88
89     @Override
90     public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
91         return HttpURLConnection.HTTP_OK;
92     }
93
94     @Override
95     public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
96         // Nothing to do
97     }
98
99     @Override
100     public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
101         return HttpURLConnection.HTTP_OK;
102     }
103
104     @Override
105     public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
106         int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
107         if  (result != HttpURLConnection.HTTP_OK) {
108             LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
109         }
110     }
111
112     /**
113      * Process the event.
114      *
115      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
116      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
117      */
118     @Override
119     public void processEvent(AbstractEvent abstractEvent) {
120         if (!(abstractEvent instanceof NorthboundEvent)) {
121             LOG.error("Unable to process abstract event {}", abstractEvent);
122             return;
123         }
124         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
125         switch (ev.getAction()) {
126             // TODO: add handling of events here, once callbacks do something
127             //       other than logging.
128             default:
129                 LOG.warn("Unable to process event action {}", ev.getAction());
130                 break;
131         }
132     }
133
134     @Override
135     public void setDependencies(ServiceReference serviceReference) {
136         eventDispatcher =
137                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
138         eventDispatcher.eventHandlerAdded(serviceReference, this);
139     }
140
141     @Override
142     public void setDependencies(Object impl) {}
143 }