/*
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (c) 2014, 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
- *
- * Authors : Dave Tucker, Madhu Venugopal
*/
package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
-import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
+
import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager;
+import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
public class PipelineOrchestratorImpl implements ConfigInterface, NodeCacheListener, PipelineOrchestrator {
private static final Logger LOG = LoggerFactory.getLogger(PipelineOrchestratorImpl.class);
+
+ public List<Service> getStaticPipeline() {
+ return staticPipeline;
+ }
+
private List<Service> staticPipeline = Lists.newArrayList(
Service.CLASSIFIER,
Service.ARP_RESPONDER,
Service.OUTBOUND_NAT,
Service.L2_FORWARDING
);
+
+ public Map<Service, AbstractServiceInstance> getServiceRegistry() {
+ return serviceRegistry;
+ }
+
Map<Service, AbstractServiceInstance> serviceRegistry = Maps.newConcurrentMap();
private volatile BlockingQueue<Node> queue;
private ExecutorService eventHandler;
Service service = (Service)ref.getProperty(AbstractServiceInstance.SERVICE_PROPERTY);
LOG.info("registerService {} - {}", serviceInstance, service);
serviceRegistry.put(service, serviceInstance);
+ // insert the service if not already there. The list is ordered based of table ID.
+ if (!staticPipeline.contains(service) && !isTableInPipeline(service.getTable())) {
+ staticPipeline.add(service);
+ Collections.sort(staticPipeline, Service.insertComparator);
+ }
+ LOG.info("registerService: {}", staticPipeline);
+ }
+
+ private boolean isTableInPipeline (short tableId) {
+ boolean found = false;
+ for (Service service : staticPipeline) {
+ if (service.getTable() == tableId) {
+ found = true;
+ break;
+ }
+ }
+ return found;
}
public void unregisterService(final ServiceReference ref) {
return serviceRegistry.get(service);
}
- public void start() {
+ public final void start() {
eventHandler.submit(new Runnable() {
@Override
public void run() {
try {
while (true) {
Node node = queue.take();
- /*
- * Since we are hooking on OpendaylightInventoryListener and as observed in
- * Bug 1997 multiple Threads trying to write to a same table at the same time
- * causes programming issues. Hence delaying the programming by a second to
- * avoid the clash. This hack/workaround should be removed once Bug 1997 is resolved.
- */
LOG.info(">>>>> dequeue: {}", node);
- Thread.sleep(1000);
for (Service service : staticPipeline) {
AbstractServiceInstance serviceInstance = getServiceInstance(service);
- //LOG.info("pipeline: {} - {}", service, serviceInstance);
- if (serviceInstance != null) {
- if (southbound.getBridge(node) != null) {
- serviceInstance.programDefaultPipelineRule(node);
- }
+ if (serviceInstance != null && southbound.getBridge(node) != null) {
+ serviceInstance.programDefaultPipelineRule(node);
}
}
}