2 * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
11 import java.net.HttpURLConnection;
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.BundleContext;
20 import org.osgi.framework.ServiceReference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
27 public class PortSecurityHandler extends AbstractHandler
28 implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface {
30 private static final Logger LOG = LoggerFactory.getLogger(PortSecurityHandler.class);
33 public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
34 return HttpURLConnection.HTTP_CREATED;
38 public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
39 int result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
40 if (result != HttpURLConnection.HTTP_CREATED) {
41 LOG.debug("Neutron Security Group creation failed {} ", result);
46 public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
47 return HttpURLConnection.HTTP_OK;
51 public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
56 public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
57 return HttpURLConnection.HTTP_OK;
61 public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
62 //TODO: Trigger flowmod removals
63 int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
64 if (result != HttpURLConnection.HTTP_OK) {
65 LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
70 * Invoked when a Security Rules creation is requested
71 * to indicate if the specified Rule can be created.
73 * @param neutronSecurityRule An instance of proposed new Neutron Security Rule object.
74 * @return A HTTP status code to the creation request.
78 public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
79 return HttpURLConnection.HTTP_CREATED;
83 public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
84 int result = canCreateNeutronSecurityRule(neutronSecurityRule);
85 if (result != HttpURLConnection.HTTP_CREATED) {
86 LOG.debug("Neutron Security Group creation failed {} ", result);
91 public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
92 return HttpURLConnection.HTTP_OK;
96 public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
101 public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
102 return HttpURLConnection.HTTP_OK;
106 public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
107 int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
108 if (result != HttpURLConnection.HTTP_OK) {
109 LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
116 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
117 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
120 public void processEvent(AbstractEvent abstractEvent) {
121 if (!(abstractEvent instanceof NorthboundEvent)) {
122 LOG.error("Unable to process abstract event {}", abstractEvent);
125 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
126 switch (ev.getAction()) {
127 // TODO: add handling of events here, once callbacks do something
128 // other than logging.
130 LOG.warn("Unable to process event action {}", ev.getAction());
136 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
138 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
139 eventDispatcher.eventHandlerAdded(
140 bundleContext.getServiceReference(INeutronSecurityGroupAware.class.getName()), this);
144 public void setDependencies(Object impl) {}