<artifactId>utils.mdsal-openflow</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
</dependencies>
<build>
+++ /dev/null
-/*
- * Copyright (C) 2014 Red Hat, Inc.
- *
- * 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
- */
-
-package org.opendaylight.ovsdb.openstack.netvirt.providers;
-
-import java.util.UUID;
-
-/**
- * A PipelineOrchestrator provides the necessary orchestration logic to allow multiple network services
- * to share a common OpenFlow 1.3 based multi-table pipeline.
- */
-public interface PipelineOrchestrator {
-
- enum ServiceDirection {
- UNDEFINED,
- INGRESS,
- EGRESS
- }
-
- static final Integer PRE_NAT = 2;
- static final Integer PRE_ACL = 7;
- //ToDo: Add some sensible altitude constants
-
- /**
- * Register a new service in the pipeline
- * @param altitude an integer representing the desired placement in the pipeline where 0 = lowest.
- * @param direction whether the service is ingress, egress
- * @return a unique service identifier
- */
- UUID registerService(Integer altitude, ServiceDirection direction);
-
- /**
- * Unregister a service from the pipeline
- * This clears any assigned table IDs and registers
- */
- void unregisterService(UUID serviceID);
-
- /**
- * Get the OpenFlow Table ID
- * @param serviceID unique service identifier
- */
- Integer getTableId(UUID serviceID);
-
- /**
- * Assign an OVS Register to a service
- * @return the integer value of the assigned register
- */
- Integer assignRegister(UUID serviceID);
-
-}
+++ /dev/null
-package org.opendaylight.ovsdb.openstack.netvirt.providers;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Queues;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.UUID;
-
-/**
- * Created by dave on 27/08/14.
- */
-public class PipelineOrchestratorImpl implements PipelineOrchestrator {
-
- private Map<UUID, ServiceProperties> serviceRegistry = Maps.newHashMap();
- private Queue<Integer> registerQueue = Queues.newArrayBlockingQueue(16);
- private List<Integer> tableIdList = Lists.newArrayList(255);
-
- public UUID registerService(Integer altitude, ServiceDirection direction) {
- return UUID.randomUUID();
- }
-
- @Override
- public void unregisterService(UUID serviceID) {
- ServiceProperties sp = serviceRegistry.get(serviceID);
- List<Integer> registers = sp.getRegisters();
- if (registers != null) {
- for (Integer register : registers) {
- registerQueue.add(register);
- }
- }
- // Add Table ID allocation back
-
- }
-
- @Override
- public Integer getTableId(UUID serviceID) {
- ServiceProperties sp = serviceRegistry.get(serviceID);
- return sp.tableId;
- }
-
- @Override
- public Integer assignRegister(UUID serviceID) {
- Integer register = registerQueue.poll();
- if (register == null) {
- throw new RuntimeException("No registers remaining");
- }
- return register;
- }
-
- private Integer assignTableId(Integer altitude) {
- return null;
- }
-
- private class ServiceProperties {
- Integer altitude;
- ServiceDirection direction;
- Integer tableId;
- List<Integer> registers;
-
- public ServiceProperties(Integer altitude,
- ServiceDirection direction,
- Integer tableId,
- List<Integer> registers) {
- this.altitude = altitude;
- this.direction = direction;
- this.tableId = tableId;
- this.registers = registers;
- }
-
- public Integer getAltitude() {
- return altitude;
- }
-
- public void setAltitude(Integer altitude) {
- this.altitude = altitude;
- }
-
- public ServiceDirection getDirection() {
- return direction;
- }
-
- public void setDirection(ServiceDirection direction) {
- this.direction = direction;
- }
-
- public Integer getTableId() {
- return tableId;
- }
-
- public void setTableId(Integer tableId) {
- this.tableId = tableId;
- }
-
- public List<Integer> getRegisters() {
- return registers;
- }
-
- public void setRegisters(List<Integer> registers) {
- this.registers = registers;
- }
-
- public void addRegister(Integer register) {
- this.registers.add(register);
- }
-
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Madhu Venugopal
+ */
+package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
+
+public abstract class AbstractServiceInstance {
+ Service service;
+ public AbstractServiceInstance (Service service) {
+ this.service = service;
+ }
+
+ public int getTable() {
+ return service.getTable();
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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;
+
+/**
+ * A PipelineOrchestrator provides the necessary orchestration logic to allow multiple network services
+ * to share a common OpenFlow 1.3 based multi-table pipeline.
+ */
+public interface PipelineOrchestrator {
+ void registerService(Service service, AbstractServiceInstance serviceInstance);
+ void unregisterService(Service service);
+ public Service getNextServiceInPipeline(Service service);
+ AbstractServiceInstance getServiceInstance(Service service);
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 java.util.List;
+import java.util.Map;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class PipelineOrchestratorImpl implements PipelineOrchestrator {
+
+ private List<Service> staticPipeline = Lists.newArrayList(
+ Service.CLASSIFIER,
+ Service.DIRECTOR,
+ Service.ARP_RESPONDER,
+ Service.INBOUND_NAT,
+ Service.INGRESS_ACL,
+ Service.LOAD_BALANCER,
+ Service.ROUTING,
+ Service.L2_REWRITE,
+ Service.L2_FORWARDING,
+ Service.EGRESS_ACL,
+ Service.OUTBOUND_NAT
+ );
+ Map<Service, AbstractServiceInstance> serviceRegistry = Maps.newConcurrentMap();
+
+ public PipelineOrchestratorImpl() {
+ }
+ @Override
+ public void registerService(Service service,
+ AbstractServiceInstance serviceInstance) {
+ serviceRegistry.put(service, serviceInstance);
+ }
+
+ @Override
+ public void unregisterService(Service service) {
+ serviceRegistry.remove(service);
+ }
+
+ @Override
+ public Service getNextServiceInPipeline(Service service) {
+ int index = staticPipeline.indexOf(service);
+ if (index >= staticPipeline.size() - 1) return null;
+ return staticPipeline.get(index + 1);
+ }
+
+ @Override
+ public AbstractServiceInstance getServiceInstance(Service service) {
+ if (service == null) return null;
+ return serviceRegistry.get(service);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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 : Madhu Venugopal
+ */
+
+package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
+
+public enum Service {
+
+ CLASSIFIER ((short) 0, "Classifier"),
+ DIRECTOR ((short) 10, "Director"),
+ ARP_RESPONDER ((short) 20, "Distributed ARP Responder"),
+ INBOUND_NAT ((short) 30, "DNAT for inbound floating-ip traffic"),
+ INGRESS_ACL ((short) 40, "Ingress Acces-control. Typically Openstack Egress Security group policies are applied here."),
+ LOAD_BALANCER ((short) 50, "Distributed LBaaS"),
+ ROUTING ((short) 60, "Distributed Virtual Routing (DVR)"),
+ L2_REWRITE ((short) 70, "Layer2 rewrite service"),
+ L2_FORWARDING ((short) 80, "Layer2 mac,vlan based forwarding"),
+ EGRESS_ACL ((short) 90, "Egress Acces-control.Typically Openstack Ingress Security group policies are applied here."),
+ OUTBOUND_NAT ((short) 100, "SNAT for traffic accessing external network");
+
+ short table;
+ String description;
+
+ private Service (short table, String description) {
+ this.table = table;
+ this.description = description;
+ }
+
+ public short getTable() {
+ return table;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+}
--- /dev/null
+package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class PipelineOrchestratorTest {
+ PipelineOrchestrator orchestrator;
+ @Before
+ public void initialize() {
+ orchestrator = new PipelineOrchestratorImpl();
+ }
+
+ @Test
+ public void testPipeline() {
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.CLASSIFIER), Service.DIRECTOR);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.DIRECTOR), Service.ARP_RESPONDER);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.ARP_RESPONDER), Service.INBOUND_NAT);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.INBOUND_NAT), Service.INGRESS_ACL);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.INGRESS_ACL), Service.LOAD_BALANCER);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.LOAD_BALANCER), Service.ROUTING);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.ROUTING), Service.L2_REWRITE);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_REWRITE), Service.L2_FORWARDING);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.L2_FORWARDING), Service.EGRESS_ACL);
+ assertEquals(orchestrator.getNextServiceInPipeline(Service.EGRESS_ACL), Service.OUTBOUND_NAT);
+ assertNull(orchestrator.getNextServiceInPipeline(Service.OUTBOUND_NAT));
+ }
+}