/* * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.ovsdb.openstack.netvirt; import java.net.HttpURLConnection; import org.opendaylight.neutron.spi.INeutronSecurityGroupAware; import org.opendaylight.neutron.spi.INeutronSecurityRuleAware; import org.opendaylight.neutron.spi.NeutronSecurityGroup; import org.opendaylight.neutron.spi.NeutronSecurityRule; import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher; import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper; import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Handle requests for OpenStack Neutron v2.0 Port Security API calls. */ public class PortSecurityHandler extends AbstractHandler implements INeutronSecurityGroupAware, INeutronSecurityRuleAware, ConfigInterface { private static final Logger LOG = LoggerFactory.getLogger(PortSecurityHandler.class); @Override public int canCreateNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) { return HttpURLConnection.HTTP_CREATED; } @Override public void neutronSecurityGroupCreated(NeutronSecurityGroup neutronSecurityGroup) { int result = canCreateNeutronSecurityGroup(neutronSecurityGroup); if (result != HttpURLConnection.HTTP_CREATED) { LOG.debug("Neutron Security Group creation failed {} ", result); } } @Override public int canUpdateNeutronSecurityGroup(NeutronSecurityGroup delta, NeutronSecurityGroup original) { return HttpURLConnection.HTTP_OK; } @Override public void neutronSecurityGroupUpdated(NeutronSecurityGroup neutronSecurityGroup) { // Nothing to do } @Override public int canDeleteNeutronSecurityGroup(NeutronSecurityGroup neutronSecurityGroup) { return HttpURLConnection.HTTP_OK; } @Override public void neutronSecurityGroupDeleted(NeutronSecurityGroup neutronSecurityGroup) { //TODO: Trigger flowmod removals int result = canDeleteNeutronSecurityGroup(neutronSecurityGroup); if (result != HttpURLConnection.HTTP_OK) { LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result); } } /** * Invoked when a Security Rules creation is requested * to indicate if the specified Rule can be created. * * @param neutronSecurityRule An instance of proposed new Neutron Security Rule object. * @return A HTTP status code to the creation request. */ @Override public int canCreateNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) { return HttpURLConnection.HTTP_CREATED; } @Override public void neutronSecurityRuleCreated(NeutronSecurityRule neutronSecurityRule) { int result = canCreateNeutronSecurityRule(neutronSecurityRule); if (result != HttpURLConnection.HTTP_CREATED) { LOG.debug("Neutron Security Group creation failed {} ", result); } } @Override public int canUpdateNeutronSecurityRule(NeutronSecurityRule delta, NeutronSecurityRule original) { return HttpURLConnection.HTTP_OK; } @Override public void neutronSecurityRuleUpdated(NeutronSecurityRule neutronSecurityRule) { // Nothing to do } @Override public int canDeleteNeutronSecurityRule(NeutronSecurityRule neutronSecurityRule) { return HttpURLConnection.HTTP_OK; } @Override public void neutronSecurityRuleDeleted(NeutronSecurityRule neutronSecurityRule) { int result = canDeleteNeutronSecurityRule(neutronSecurityRule); if (result != HttpURLConnection.HTTP_OK) { LOG.error(" delete Neutron Security Rule validation failed for result - {} ", result); } } /** * Process the event. * * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled. * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher */ @Override public void processEvent(AbstractEvent abstractEvent) { if (!(abstractEvent instanceof NorthboundEvent)) { LOG.error("Unable to process abstract event {}", abstractEvent); return; } NorthboundEvent ev = (NorthboundEvent) abstractEvent; switch (ev.getAction()) { // TODO: add handling of events here, once callbacks do something // other than logging. default: LOG.warn("Unable to process event action {}", ev.getAction()); break; } } @Override public void setDependencies(ServiceReference serviceReference) { eventDispatcher = (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this); eventDispatcher.eventHandlerAdded(serviceReference, this); } @Override public void setDependencies(Object impl) {} }