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 : Madhu Venugopal, Brent Salisbury
11 package org.opendaylight.ovsdb.openstack.netvirt;
13 import org.opendaylight.neutron.spi.INeutronSubnetAware;
14 import org.opendaylight.neutron.spi.NeutronSubnet;
15 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
17 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
19 import com.google.common.base.Preconditions;
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;
26 import java.net.HttpURLConnection;
28 public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
30 static final Logger logger = LoggerFactory.getLogger(SubnetHandler.class);
32 // The implementation for each of these services is resolved by the OSGi Service Manager
33 private volatile NeutronL3Adapter neutronL3Adapter;
34 private EventDispatcher eventDispatcher;
37 public int canCreateSubnet(NeutronSubnet subnet) {
38 return HttpURLConnection.HTTP_OK;
42 public void neutronSubnetCreated(NeutronSubnet subnet) {
43 enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
47 public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
48 return HttpURLConnection.HTTP_OK;
52 public void neutronSubnetUpdated(NeutronSubnet subnet) {
53 enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
57 public int canDeleteSubnet(NeutronSubnet subnet) {
58 return HttpURLConnection.HTTP_OK;
62 public void neutronSubnetDeleted(NeutronSubnet subnet) {
63 enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
69 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
70 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
73 public void processEvent(AbstractEvent abstractEvent) {
74 if (!(abstractEvent instanceof NorthboundEvent)) {
75 logger.error("Unable to process abstract event " + abstractEvent);
78 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
79 switch (ev.getAction()) {
85 Preconditions.checkNotNull(neutronL3Adapter);
86 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
89 logger.warn("Unable to process event action " + ev.getAction());
95 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
97 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
99 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
100 eventDispatcher.eventHandlerAdded(
101 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
102 super.setDispatcher(eventDispatcher);
106 public void setDependencies(Object impl) {