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 java.net.HttpURLConnection;
15 import org.opendaylight.neutron.spi.INeutronSubnetAware;
16 import org.opendaylight.neutron.spi.NeutronSubnet;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
19 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
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 com.google.common.base.Preconditions;
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;
36 public int canCreateSubnet(NeutronSubnet subnet) {
37 return HttpURLConnection.HTTP_OK;
41 public void neutronSubnetCreated(NeutronSubnet subnet) {
42 enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
46 public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
47 return HttpURLConnection.HTTP_OK;
51 public void neutronSubnetUpdated(NeutronSubnet subnet) {
52 enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
56 public int canDeleteSubnet(NeutronSubnet subnet) {
57 return HttpURLConnection.HTTP_OK;
61 public void neutronSubnetDeleted(NeutronSubnet subnet) {
62 enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
68 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
69 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
72 public void processEvent(AbstractEvent abstractEvent) {
73 if (!(abstractEvent instanceof NorthboundEvent)) {
74 logger.error("Unable to process abstract event " + abstractEvent);
77 NorthboundEvent ev = (NorthboundEvent) abstractEvent;
78 switch (ev.getAction()) {
84 Preconditions.checkNotNull(neutronL3Adapter);
85 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
88 logger.warn("Unable to process event action " + ev.getAction());
94 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
96 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
98 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
99 eventDispatcher.eventHandlerAdded(
100 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
104 public void setDependencies(Object impl) {