2 * Copyright © 2015 Dell, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
11 import java.util.Dictionary;
12 import java.util.Hashtable;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
17 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
18 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
19 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
20 import org.opendaylight.ovsdb.openstack.netvirt.sfc.standalone.openflow13.NetvirtSfcStandaloneOF13Provider;
21 import org.opendaylight.ovsdb.openstack.netvirt.sfc.standalone.openflow13.services.SfcClassifierService;
22 import org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround.NetvirtSfcWorkaroundOF13Provider;
23 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
24 import org.osgi.framework.BundleContext;
25 import org.osgi.framework.ServiceRegistration;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class NetvirtSfcProvider implements BindingAwareProvider, AutoCloseable {
30 private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcProvider.class);
31 private NetvirtSfcAclListener aclListener;
32 private NetvirtSfcClassifierListener classifierListener;
34 public void setOf13Provider(String of13Provider) {
35 LOG.info("of13Provider is: {}", of13Provider);
36 this.of13Provider = of13Provider;
39 private String of13Provider;
41 public void setBundleContext(BundleContext bundleContext) {
42 LOG.info("bundleContext is: {}", bundleContext);
43 this.bundleContext = bundleContext;
46 private BundleContext bundleContext;
48 public NetvirtSfcProvider(BundleContext bundleContext) {
49 LOG.info("NetvirtSfcProvider: bundleContext: {}", bundleContext);
50 this.bundleContext = bundleContext;
54 public void onSessionInitiated(ProviderContext session) {
55 LOG.info("NetvirtSfcProvider Session Initiated");
56 DataBroker dataBroker = session.getSALService(DataBroker.class);
58 MdsalUtils mdsalUtils = new MdsalUtils(dataBroker);
59 SfcUtils sfcUtils = new SfcUtils(mdsalUtils);
61 // Allocate provider based on config
62 INetvirtSfcOF13Provider provider;
63 if (of13Provider.equals("standalone")) {
64 provider = new NetvirtSfcStandaloneOF13Provider(dataBroker);
66 provider = new NetvirtSfcWorkaroundOF13Provider(dataBroker, mdsalUtils, sfcUtils);
68 aclListener = new NetvirtSfcAclListener(provider, dataBroker);
69 classifierListener = new NetvirtSfcClassifierListener(provider, dataBroker);
71 addToPipeline(provider);
72 provider.setDependencies(null);
76 public void close() throws Exception {
77 LOG.info("NetvirtSfcProvider Closed");
79 classifierListener.close();
82 private void addToPipeline(INetvirtSfcOF13Provider provider) {
83 if (provider instanceof NetvirtSfcStandaloneOF13Provider) {
84 SfcClassifierService sfcClassifierService =
85 new org.opendaylight.ovsdb.openstack.netvirt.sfc.standalone.openflow13.services.SfcClassifierService();
86 registerService(bundleContext, ISfcClassifierService.class.getName(),
87 sfcClassifierService, Service.SFC_CLASSIFIER);
88 sfcClassifierService.setDependencies(bundleContext, null);
90 org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround.services.SfcClassifierService sfcClassifierService =
91 new org.opendaylight.ovsdb.openstack.netvirt.sfc.workaround.services.SfcClassifierService();
92 registerService(bundleContext, ISfcClassifierService.class.getName(),
93 sfcClassifierService, Service.SFC_CLASSIFIER);
94 sfcClassifierService.setDependencies(bundleContext, null);
97 //provider.setSfcClassifierService(sfcClassifierService);
100 private ServiceRegistration<?> registerService(BundleContext bundleContext, String[] interfaces,
101 Dictionary<String, Object> properties, Object impl) {
102 ServiceRegistration<?> serviceRegistration = bundleContext.registerService(interfaces, impl, properties);
103 return serviceRegistration;
106 private ServiceRegistration<?> registerService(BundleContext bundleContext, String interfaceClassName,
107 Object impl, Object serviceProperty) {
108 Dictionary<String, Object> properties = new Hashtable<>();
109 properties.put(AbstractServiceInstance.SERVICE_PROPERTY, serviceProperty);
110 properties.put(Constants.PROVIDER_NAME_PROPERTY, OF13Provider.NAME);
111 return registerService(bundleContext,
112 new String[] {AbstractServiceInstance.class.getName(),interfaceClassName},