2 * Copyright (C) 2013 Red Hat, Inc.
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
8 * Authors : Brent Salisbury, Madhu Venugopal
11 package org.opendaylight.ovsdb.openstack.netvirt;
13 import java.net.HttpURLConnection;
15 import org.opendaylight.neutron.spi.INeutronSecurityGroupAware;
16 import org.opendaylight.neutron.spi.INeutronSecurityRuleAware;
17 import org.opendaylight.neutron.spi.NeutronSecurityGroup;
18 import org.opendaylight.neutron.spi.NeutronSecurityRule;
19 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
20 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
29 public class PortSecurityHandler extends AbstractHandler
30 implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface {
32 private static final Logger LOG = LoggerFactory.getLogger(PortSecurityHandler.class);
35 public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
36 return HttpURLConnection.HTTP_CREATED;
40 public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
41 int result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
42 if (result != HttpURLConnection.HTTP_CREATED) {
43 LOG.debug("Neutron Security Group creation failed {} ", result);
48 public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
49 return HttpURLConnection.HTTP_OK;
53 public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
58 public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
59 return HttpURLConnection.HTTP_OK;
63 public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
64 //TODO: Trigger flowmod removals
65 int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
66 if (result != HttpURLConnection.HTTP_OK) {
67 LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
72 * Invoked when a Security Rules creation is requested
73 * to indicate if the specified Rule can be created.
75 * @param neutronSecurityRule An instance of proposed new Neutron Security Rule object.
76 * @return A HTTP status code to the creation request.
80 public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
81 return HttpURLConnection.HTTP_CREATED;
85 public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
86 int result = canCreateNeutronSecurityRule(neutronSecurityRule);
87 if (result != HttpURLConnection.HTTP_CREATED) {
88 LOG.debug("Neutron Security Group creation failed {} ", result);
93 public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
94 return HttpURLConnection.HTTP_OK;
98 public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
103 public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
104 return HttpURLConnection.HTTP_OK;
108 public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
109 int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
110 if (result != HttpURLConnection.HTTP_OK) {
111 LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result);
118 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
119 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
122 public void processEvent(AbstractEvent abstractEvent) {
123 if (!(abstractEvent instanceof NorthboundEvent)) {
124 LOG.error("Unable to process abstract event {}", abstractEvent);
127 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
128 switch (ev.getAction()) {
129 // TODO: add handling of events here, once callbacks do something
130 // other than logging.
132 LOG.warn("Unable to process event action {}", ev.getAction());
138 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
140 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
141 eventDispatcher.eventHandlerAdded(
142 bundleContext.getServiceReference(INeutronSecurityGroupAware.class.getName()), this);
146 public void setDependencies(Object impl) {}