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 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;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
19 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.framework.ServiceReference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import java.net.HttpURLConnection;
28 * Handle requests for OpenStack Neutron v2.0 Port Security API calls.
30 public class PortSecurityHandler extends AbstractHandler
31 implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface {
33 static final Logger logger = LoggerFactory.getLogger(PortSecurityHandler.class);
34 private volatile EventDispatcher eventDispatcher;
37 public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
38 return HttpURLConnection.HTTP_CREATED;
42 public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) {
43 int result = HttpURLConnection.HTTP_BAD_REQUEST;
45 result = canCreateNeutronSecurityGroup(neutronSecurityGroup);
46 if (result != HttpURLConnection.HTTP_CREATED) {
47 logger.debug("Neutron Security Group creation failed {} ", result);
53 public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) {
54 return HttpURLConnection.HTTP_OK;
58 public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) {
63 public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) {
64 return HttpURLConnection.HTTP_OK;
68 public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) {
69 //TODO: Trigger flowmod removals
70 int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup);
71 if (result != HttpURLConnection.HTTP_OK) {
72 logger.error(" delete Neutron Security Rule validation failed for result - {} ", result);
78 * Invoked when a Security Rules creation is requested
79 * to indicate if the specified Rule can be created.
81 * @param neutronSecurityRule An instance of proposed new Neutron Security Rule object.
82 * @return A HTTP status code to the creation request.
86 public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
87 return HttpURLConnection.HTTP_CREATED;
91 public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) {
92 int result = HttpURLConnection.HTTP_BAD_REQUEST;
94 result = canCreateNeutronSecurityRule(neutronSecurityRule);
95 if (result != HttpURLConnection.HTTP_CREATED) {
96 logger.debug("Neutron Security Group creation failed {} ", result);
102 public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) {
103 return HttpURLConnection.HTTP_OK;
107 public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) {
112 public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) {
113 return HttpURLConnection.HTTP_OK;
117 public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) {
118 int result = canDeleteNeutronSecurityRule(neutronSecurityRule);
119 if (result != HttpURLConnection.HTTP_OK) {
120 logger.error(" delete Neutron Security Rule validation failed for result - {} ", result);
128 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
129 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
132 public void processEvent(AbstractEvent abstractEvent) {
133 if (!(abstractEvent instanceof NorthboundEvent)) {
134 logger.error("Unable to process abstract event " + abstractEvent);
137 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
138 switch (ev.getAction()) {
139 // TODO: add handling of events here, once callbacks do something
140 // other than logging.
142 logger.warn("Unable to process event action " + ev.getAction());
148 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
150 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
151 eventDispatcher.eventHandlerAdded(
152 bundleContext.getServiceReference(INeutronSecurityGroupAware.class.getName()), this);
153 super.setDispatcher(eventDispatcher);
157 public void setDependencies(Object impl) {}