Merge remote-tracking branch 'origin/master' into merge-branch
[netvirt.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / PortSecurityHandler.java
1 /*
2  * Copyright (C) 2013 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 : Brent Salisbury, Madhu Venugopal
9  */
10
11 package org.opendaylight.ovsdb.neutron;
12
13 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityGroupAware;
14 import org.opendaylight.controller.networkconfig.neutron.INeutronSecurityRuleAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityGroup;
16 import org.opendaylight.controller.networkconfig.neutron.NeutronSecurityRule;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 import java.net.HttpURLConnection;
21
22 /**
23  * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
24  */
25 public class PortSecurityHandler extends BaseHandler
26         implements INeutronSecurityGroupAware, INeutronSecurityRuleAware{
27
28     static final Logger logger = LoggerFactory.getLogger(PortSecurityHandler.class);
29
30     @Override
31     public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
32         return HttpURLConnection.HTTP_CREATED;
33     }
34
35     @Override
36     public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
37         int result = HttpURLConnection.HTTP_BAD_REQUEST;
38
39         result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
40         if (result != HttpURLConnection.HTTP_CREATED) {
41             logger.debug("Neutron Security Group creation failed {} ", result);
42             return;
43         }
44     }
45
46     @Override
47     public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
48         return HttpURLConnection.HTTP_OK;
49     }
50
51     @Override
52     public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
53         return;
54     }
55
56     @Override
57     public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
58         return HttpURLConnection.HTTP_OK;
59     }
60
61     @Override
62     public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
63         //TODO: Trigger flowmod removals
64         int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
65         if  (result != HttpURLConnection.HTTP_OK) {
66             logger.error(" delete Neutron Security Rule validation failed for result - {} ", result);
67             return;
68         }
69     }
70
71     /**
72      * Invoked when a Security Rules creation is requested
73      * to indicate if the specified Rule can be created.
74      *
75      * @param neutronSecurityRule  An instance of proposed new Neutron Security Rule object.
76      * @return A HTTP status code to the creation request.
77      */
78
79     @Override
80     public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
81         return HttpURLConnection.HTTP_CREATED;
82     }
83
84     @Override
85     public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
86         int result = HttpURLConnection.HTTP_BAD_REQUEST;
87
88         result = canCreateNeutronSecurityRule(neutronSecurityRule);
89         if (result != HttpURLConnection.HTTP_CREATED) {
90             logger.debug("Neutron Security Group creation failed {} ", result);
91             return;
92         }
93     }
94
95     @Override
96     public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
97         return HttpURLConnection.HTTP_OK;
98     }
99
100     @Override
101     public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
102         return;
103     }
104
105     @Override
106     public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
107         return HttpURLConnection.HTTP_OK;
108     }
109
110     @Override
111     public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
112         int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
113         if  (result != HttpURLConnection.HTTP_OK) {
114             logger.error(" delete Neutron Security Rule validation failed for result - {} ", result);
115             return;
116         }
117     }
118 }