aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/vtn/sfcmgr/src
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/vtn/sfcmgr/src')
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarderService.java (renamed from framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarder.java)28
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/ServiceFunctionForwarderImpl.java293
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/NshSpiIdGenerators.java51
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/SfcService.java37
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/impl/SfcManager.java159
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/manager/impl/SfcManagerTest.java269
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowClassifierManagerTestImpl.java93
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowObjectiveServiceTestImpl.java53
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortChainManagerTestImpl.java85
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairGroupManagerTestImpl.java89
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairManagerTestImpl.java89
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VirtualPortManagerTestImpl.java98
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java72
14 files changed, 1369 insertions, 67 deletions
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarder.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarderService.java
index e91e6b69..0ed42fcf 100644
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarder.java
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/ServiceFunctionForwarderService.java
@@ -15,29 +15,37 @@
*/
package org.onosproject.sfc.forwarder;
-import org.onosproject.core.ApplicationId;
import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.NshServicePathId;
import org.onosproject.vtnrsc.PortChain;
/**
* Abstraction of an entity which provides Service function forwarder.
*/
-public interface ServiceFunctionForwarder {
+public interface ServiceFunctionForwarderService {
/**
- * Install Service function chain.
+ * Install Forwarding rule.
*
- * @param portChain Port chain
+ * @param portChain port-chain
+ * @param nshSPI nsh spi
*/
- void install(PortChain portChain);
+ void installForwardingRule(PortChain portChain, NshServicePathId nshSPI);
/**
- * Programs forwarding object for Service Function.
+ * Uninstall Forwarding rule.
*
- * @param portChain port chain
- * @param appid application id
+ * @param portChain port-chain
+ * @param nshSPI nsh spi
+ */
+ void unInstallForwardingRule(PortChain portChain, NshServicePathId nshSPI);
+
+ /**
+ * Prepare forwarding object for Service Function.
+ *
+ * @param portChain port-chain
+ * @param nshSPI nsh spi
* @param type forwarding objective operation type
*/
- void programServiceFunctionForwarder(PortChain portChain, ApplicationId appid,
- Objective.Operation type);
+ void prepareServiceFunctionForwarder(PortChain portChain, NshServicePathId nshSPI, Objective.Operation type);
}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/ServiceFunctionForwarderImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/ServiceFunctionForwarderImpl.java
new file mode 100644
index 00000000..2846ee01
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/ServiceFunctionForwarderImpl.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.forwarder.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.behaviour.ExtensionSelectorResolver;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.NshServicePathId;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.criteria.ExtensionSelector;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.FlowObjectiveService;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.flowobjective.ForwardingObjective.Flag;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.service.VtnRscService;
+import org.onosproject.vtnrsc.PortChain;
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.PortPairId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+import org.onosproject.vtnrsc.portpair.PortPairService;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
+import org.onosproject.vtnrsc.portchain.PortChainService;
+import org.onosproject.sfc.forwarder.ServiceFunctionForwarderService;
+
+import org.slf4j.Logger;
+
+/**
+ * Provides Service Function Forwarder implementation.
+ */
+public class ServiceFunctionForwarderImpl implements ServiceFunctionForwarderService {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DriverService driverService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VirtualPortService virtualPortService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VtnRscService vtnRscService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PortPairService portPairService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PortPairGroupService portPairGroupService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowClassifierService flowClassifierService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected PortChainService portChainService;
+
+ private final Logger log = getLogger(getClass());
+ protected ApplicationId appId;
+ protected FlowObjectiveService flowObjectiveService;
+
+ private static final String DRIVER_NAME = "onosfw";
+ private static final String PORT_CHAIN_NOT_NULL = "Port-Chain cannot be null";
+ private static final String PORT_CHAIN_ID_NOT_NULL = "Port-Chain-Id cannot be null";
+ private static final String APP_ID_NOT_NULL = "Application-Id cannot be null";
+ private static final int NULL = 0;
+
+ /**
+ * Default constructor.
+ */
+ public ServiceFunctionForwarderImpl() {
+ }
+
+ /**
+ * Explicit constructor.
+ */
+ public ServiceFunctionForwarderImpl(ApplicationId appId) {
+ this.appId = checkNotNull(appId, APP_ID_NOT_NULL);
+ ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
+ this.flowObjectiveService = serviceDirectory.get(FlowObjectiveService.class);
+ }
+
+ @Override
+ public void installForwardingRule(PortChain portChain, NshServicePathId nshSPI) {
+ checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
+ prepareServiceFunctionForwarder(portChain, nshSPI, Objective.Operation.ADD);
+ }
+
+ @Override
+ public void unInstallForwardingRule(PortChain portChain, NshServicePathId nshSPI) {
+ checkNotNull(portChain, PORT_CHAIN_NOT_NULL);
+ prepareServiceFunctionForwarder(portChain, nshSPI, Objective.Operation.REMOVE);
+ }
+
+ @Override
+ public void prepareServiceFunctionForwarder(PortChain portChain, NshServicePathId nshSPI,
+ Objective.Operation type) {
+
+ // Go through the port pair group list
+ List<PortPairGroupId> portPairGrpList = portChain.portPairGroups();
+ ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator();
+
+ // Get source port pair group
+ if (!listGrpIterator.hasNext()) {
+ return;
+ }
+ PortPairGroupId portPairGrpId = listGrpIterator.next();
+ PortPairGroup currentPortPairGroup = portPairGroupService.getPortPairGroup(portPairGrpId);
+
+ // Get destination port pair group
+ if (!listGrpIterator.hasNext()) {
+ return;
+ }
+ portPairGrpId = listGrpIterator.next();
+ PortPairGroup nextPortPairGroup = portPairGroupService.getPortPairGroup(portPairGrpId);
+
+ // push SFF to OVS
+ pushServiceFunctionForwarder(currentPortPairGroup, nextPortPairGroup, listGrpIterator, nshSPI, type);
+ }
+
+ /**
+ * Push service-function-forwarder to OVS.
+ *
+ * @param currentPortPairGroup current port-pair-group
+ * @param nextPortPairGroup next port-pair-group
+ * @param listGrpIterator pointer to port-pair-group list
+ */
+ public void pushServiceFunctionForwarder(PortPairGroup currentPortPairGroup, PortPairGroup nextPortPairGroup,
+ ListIterator<PortPairGroupId> listGrpIterator, NshServicePathId nshSPI, Objective.Operation type) {
+ MacAddress srcMacAddress = null;
+ MacAddress dstMacAddress = null;
+ DeviceId deviceId = null;
+ DeviceId currentDeviceId = null;
+ DeviceId nextDeviceId = null;
+ PortPairGroupId portPairGrpId = null;
+
+ // Travel from SF to SF.
+ do {
+ // Get the required information on port pairs from source port pair
+ // group
+ List<PortPairId> portPairList = currentPortPairGroup.portPairs();
+ ListIterator<PortPairId> portPLIterator = portPairList.listIterator();
+ if (!portPLIterator.hasNext()) {
+ break;
+ }
+
+ PortPairId portPairId = portPLIterator.next();
+ PortPair portPair = portPairService.getPortPair(portPairId);
+
+ currentDeviceId = vtnRscService.getSFToSFFMaping(VirtualPortId.portId(portPair.ingress()));
+ if (deviceId == null) {
+ deviceId = currentDeviceId;
+ }
+ srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())).macAddress();
+ dstMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.egress())).macAddress();
+
+ // pack traffic selector
+ TrafficSelector.Builder selector = packTrafficSelector(deviceId, srcMacAddress, dstMacAddress, nshSPI);
+
+ // Get the required information on port pairs from destination port
+ // pair group
+ portPairList = nextPortPairGroup.portPairs();
+ portPLIterator = portPairList.listIterator();
+ if (!portPLIterator.hasNext()) {
+ break;
+ }
+
+ portPairId = portPLIterator.next();
+ portPair = portPairService.getPortPair(portPairId);
+
+ nextDeviceId = vtnRscService.getSFToSFFMaping(VirtualPortId.portId(portPair.ingress()));
+
+ // pack traffic treatment
+ TrafficTreatment.Builder treatment = packTrafficTreatment(currentDeviceId, nextDeviceId, portPair);
+
+ // Send SFF to OVS
+ sendServiceFunctionForwarder(selector, treatment, deviceId, type);
+
+ // Replace source port pair group with destination port pair group
+ // for moving to next SFF processing.
+ currentPortPairGroup = nextPortPairGroup;
+ if (!listGrpIterator.hasNext()) {
+ break;
+ }
+ portPairGrpId = listGrpIterator.next();
+ nextPortPairGroup = portPairGroupService.getPortPairGroup(portPairGrpId);
+ } while (true);
+ }
+
+ /**
+ * Pack Traffic selector.
+ *
+ * @param deviceId device id
+ * @param srcMacAddress source mac-address
+ * @param dstMacAddress destination mac-address
+ * @param nshSPI nsh spi
+ * @return traffic treatment
+ */
+ public TrafficSelector.Builder packTrafficSelector(DeviceId deviceId, MacAddress srcMacAddress,
+ MacAddress dstMacAddress, NshServicePathId nshSPI) {
+ TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+ selector.matchEthSrc(srcMacAddress);
+ selector.matchEthDst(dstMacAddress);
+
+ DriverHandler handler = driverService.createHandler(deviceId);
+ ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class);
+ ExtensionSelector nspSpiSelector = resolver.getExtensionSelector(NICIRA_MATCH_NSH_SPI.type());
+
+ try {
+ nspSpiSelector.setPropertyValue("nshSpi", nshSPI);
+ } catch (Exception e) {
+ log.error("Failed to get extension instruction to set Nsh Spi Id {}", deviceId);
+ }
+
+ selector.extension(nspSpiSelector, deviceId);
+ return selector;
+ }
+
+ /**
+ * Pack Traffic treatment.
+ *
+ * @param currentDeviceId current device id
+ * @param nextDeviceId next device id
+ * @param portPair port-pair
+ * @return traffic treatment
+ */
+ public TrafficTreatment.Builder packTrafficTreatment(DeviceId currentDeviceId, DeviceId nextDeviceId,
+ PortPair portPair) {
+ MacAddress srcMacAddress = null;
+ MacAddress dstMacAddress = null;
+
+ // Check the treatment whether destination SF is on same OVS or in
+ // different OVS.
+ TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
+ if (currentDeviceId.equals(nextDeviceId)) {
+ srcMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.ingress())).macAddress();
+ dstMacAddress = virtualPortService.getPort(VirtualPortId.portId(portPair.egress())).macAddress();
+ treatment.setEthSrc(srcMacAddress);
+ treatment.setEthDst(dstMacAddress);
+ } else {
+ treatment.setVlanId(VlanId.vlanId(Short.parseShort((vtnRscService.getL3vni(portPair
+ .tenantId()).toString()))));
+ }
+
+ return treatment;
+ }
+
+ /**
+ * Send service function forwarder to OVS.
+ *
+ * @param selector traffic selector
+ * @param treatment traffic treatment
+ * @param deviceId device id
+ * @param type operation type
+ */
+ public void sendServiceFunctionForwarder(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment,
+ DeviceId deviceId, Objective.Operation type) {
+ ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build())
+ .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC);
+ if (type.equals(Objective.Operation.ADD)) {
+ log.debug("ADD");
+ flowObjectiveService.forward(deviceId, objective.add());
+ } else {
+ log.debug("REMOVE");
+ flowObjectiveService.forward(deviceId, objective.remove());
+ }
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/package-info.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/package-info.java
new file mode 100644
index 00000000..02221196
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/forwarder/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * SFC Service manager for interacting with SFC.
+ */
+package org.onosproject.sfc.forwarder.impl;
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/NshSpiIdGenerators.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/NshSpiIdGenerators.java
new file mode 100644
index 00000000..1dbe8c8f
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/NshSpiIdGenerators.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.manager;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Unique NSH SPI Id generator for NSH header.
+ */
+public final class NshSpiIdGenerators {
+
+ private static final AtomicInteger NSH_SPI_ID_GEN = new AtomicInteger();
+ private static final int MAX_NSH_SPI_ID = 0x7FFFFFFF;
+ private static int nshSpiId;
+
+ /**
+ * Default constructor.
+ */
+ private NshSpiIdGenerators() {
+ }
+
+ /**
+ * Get the next NSH SPI id.
+ *
+ * @return NSH SPI id
+ */
+ public static int create() {
+ do {
+ if (nshSpiId >= MAX_NSH_SPI_ID) {
+ if (NSH_SPI_ID_GEN.get() >= MAX_NSH_SPI_ID) {
+ NSH_SPI_ID_GEN.set(0);
+ }
+ }
+ nshSpiId = NSH_SPI_ID_GEN.incrementAndGet();
+ } while (nshSpiId > MAX_NSH_SPI_ID);
+ return nshSpiId;
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/SfcService.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/SfcService.java
index ef5fc529..4af2d47c 100644
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/SfcService.java
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/SfcService.java
@@ -15,6 +15,11 @@
*/
package org.onosproject.sfc.manager;
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.FlowClassifier;
+import org.onosproject.vtnrsc.PortChain;
+
/**
* SFC application that applies flows to the device.
*/
@@ -23,48 +28,64 @@ public interface SfcService {
/**
* When port-pair is created, check whether Forwarding Rule needs to be
* updated in OVS.
+ *
+ * @param portPair port-pair
*/
- public void onPortPairCreated();
+ void onPortPairCreated(PortPair portPair);
/**
* When port-pair is deleted, check whether Forwarding Rule needs to be
* updated in OVS.
+ *
+ * @param portPair port-pair
*/
- public void onPortPairDeleted();
+ void onPortPairDeleted(PortPair portPair);
/**
* When port-pair-group is created, check whether Forwarding Rule needs to
* be updated in OVS.
+ *
+ * @param portPairGroup port-pair-group
*/
- public void onPortPairGroupCreated();
+ void onPortPairGroupCreated(PortPairGroup portPairGroup);
/**
* When port-pair-group is deleted, check whether Forwarding Rule needs to
* be updated in OVS.
+ *
+ * @param portPairGroup port-pair-group
*/
- public void onPortPairGroupDeleted();
+ void onPortPairGroupDeleted(PortPairGroup portPairGroup);
/**
* When flow-classifier is created, check whether Forwarding Rule needs to
* be updated in OVS.
+ *
+ * @param flowClassifier flow-classifier
*/
- public void onFlowClassifierCreated();
+ void onFlowClassifierCreated(FlowClassifier flowClassifier);
/**
* When flow-classifier is deleted, check whether Forwarding Rule needs to
* be updated in OVS.
+ *
+ * @param flowClassifier flow-classifier
*/
- public void onFlowClassifierDeleted();
+ void onFlowClassifierDeleted(FlowClassifier flowClassifier);
/**
* When port-chain is created, check whether Forwarding Rule needs to be
* updated in OVS.
+ *
+ * @param portChain port-chain
*/
- public void onPortChainCreated();
+ void onPortChainCreated(PortChain portChain);
/**
* When port-chain is deleted, check whether Forwarding Rule needs to be
* updated in OVS.
+ *
+ * @param portChain port-chain
*/
- public void onPortChainDeleted();
+ void onPortChainDeleted(PortChain portChain);
}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/impl/SfcManager.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/impl/SfcManager.java
index 12d27c87..4df07929 100644
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/impl/SfcManager.java
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/manager/impl/SfcManager.java
@@ -20,9 +20,26 @@ import static org.slf4j.LoggerFactory.getLogger;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
import org.onosproject.sfc.manager.SfcService;
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairId;
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.FlowClassifier;
+import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.vtnrsc.PortChain;
+import org.onosproject.vtnrsc.PortChainId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.event.VtnRscEvent;
+import org.onosproject.vtnrsc.event.VtnRscListener;
+import org.onosproject.vtnrsc.service.VtnRscService;
+
import org.slf4j.Logger;
/**
@@ -33,93 +50,137 @@ import org.slf4j.Logger;
public class SfcManager implements SfcService {
private final Logger log = getLogger(getClass());
+ private static final String APP_ID = "org.onosproject.app.vtn";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected VtnRscService vtnRscService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ protected ApplicationId appId;
+
+ private final VtnRscListener vtnRscListener = new InnerVtnRscListener();
@Activate
public void activate() {
+ appId = coreService.registerApplication(APP_ID);
+
+ vtnRscService.addListener(vtnRscListener);
+
+ KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
+ .register(TenantId.class)
+ .register(PortPairId.class)
+ .register(PortPairGroupId.class)
+ .register(FlowClassifierId.class)
+ .register(PortChainId.class);
+
log.info("Started");
}
@Deactivate
public void deactivate() {
+ vtnRscService.removeListener(vtnRscListener);
+
log.info("Stopped");
}
+ /*
+ * Handle events.
+ */
+ private class InnerVtnRscListener implements VtnRscListener {
+ @Override
+ public void event(VtnRscEvent event) {
+
+ if (VtnRscEvent.Type.PORT_PAIR_PUT == event.type()) {
+ PortPair portPair = (PortPair) event.subject();
+ onPortPairCreated(portPair);
+ } else if (VtnRscEvent.Type.PORT_PAIR_DELETE == event.type()) {
+ PortPair portPair = (PortPair) event.subject();
+ onPortPairDeleted(portPair);
+ } else if (VtnRscEvent.Type.PORT_PAIR_UPDATE == event.type()) {
+ PortPair portPair = (PortPair) event.subject();
+ onPortPairDeleted(portPair);
+ onPortPairCreated(portPair);
+ } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) {
+ PortPairGroup portPairGroup = (PortPairGroup) event.subject();
+ onPortPairGroupCreated(portPairGroup);
+ } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) {
+ PortPairGroup portPairGroup = (PortPairGroup) event.subject();
+ onPortPairGroupDeleted(portPairGroup);
+ } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) {
+ PortPairGroup portPairGroup = (PortPairGroup) event.subject();
+ onPortPairGroupDeleted(portPairGroup);
+ onPortPairGroupCreated(portPairGroup);
+ } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) {
+ FlowClassifier flowClassifier = (FlowClassifier) event.subject();
+ onFlowClassifierCreated(flowClassifier);
+ } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) {
+ FlowClassifier flowClassifier = (FlowClassifier) event.subject();
+ onFlowClassifierDeleted(flowClassifier);
+ } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) {
+ FlowClassifier flowClassifier = (FlowClassifier) event.subject();
+ onFlowClassifierDeleted(flowClassifier);
+ onFlowClassifierCreated(flowClassifier);
+ } else if (VtnRscEvent.Type.PORT_CHAIN_PUT == event.type()) {
+ PortChain portChain = (PortChain) event.subject();
+ onPortChainCreated(portChain);
+ } else if (VtnRscEvent.Type.PORT_CHAIN_DELETE == event.type()) {
+ PortChain portChain = (PortChain) event.subject();
+ onPortChainDeleted(portChain);
+ } else if (VtnRscEvent.Type.PORT_CHAIN_UPDATE == event.type()) {
+ PortChain portChain = (PortChain) event.subject();
+ onPortChainDeleted(portChain);
+ onPortChainCreated(portChain);
+ }
+ }
+ }
+
@Override
- public void onPortPairCreated() {
+ public void onPortPairCreated(PortPair portPair) {
log.debug("onPortPairCreated");
- // TODO: Process port-pair on creation.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on port-pair creation.
}
@Override
- public void onPortPairDeleted() {
+ public void onPortPairDeleted(PortPair portPair) {
log.debug("onPortPairDeleted");
- // TODO: Process port-pair on deletion.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on port-pair deletion.
}
@Override
- public void onPortPairGroupCreated() {
+ public void onPortPairGroupCreated(PortPairGroup portPairGroup) {
log.debug("onPortPairGroupCreated");
- // TODO: Process port-pair-group on creation.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on port-pair-group creation.
}
@Override
- public void onPortPairGroupDeleted() {
+ public void onPortPairGroupDeleted(PortPairGroup portPairGroup) {
log.debug("onPortPairGroupDeleted");
- // TODO: Process port-pair-group on deletion.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on port-pair-group deletion.
}
@Override
- public void onFlowClassifierCreated() {
+ public void onFlowClassifierCreated(FlowClassifier flowClassifier) {
log.debug("onFlowClassifierCreated");
- // TODO: Process flow-classifier on creation.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on flow-classifier creation.
}
@Override
- public void onFlowClassifierDeleted() {
+ public void onFlowClassifierDeleted(FlowClassifier flowClassifier) {
log.debug("onFlowClassifierDeleted");
- // TODO: Process flow-classifier on deletion.
- // TODO: Parameter also needs to be modified.
+ // TODO: Modify forwarding rule on flow-classifier deletion.
}
@Override
- public void onPortChainCreated() {
- log.debug("onPortChainCreated");
- // TODO: Process port-chain on creation.
- // TODO: Parameter also needs to be modified.
-
+ public void onPortChainCreated(PortChain portChain) {
+ log.debug("onPortChainCreated");
+ //TODO: Apply forwarding rule on port-chain creation.
}
@Override
- public void onPortChainDeleted() {
+ public void onPortChainDeleted(PortChain portChain) {
log.debug("onPortChainDeleted");
- // TODO: Process port-chain on deletion.
- // TODO: Parameter also needs to be modified.
- }
-
- /**
- * Install SF Forwarding rule into OVS.
- *
- * @param portChain
- * port chain
- */
- public void installForwardingRule(PortChain portChain) {
- log.debug("installForwardingRule");
- // TODO: Installation of SF Forwarding rule into OVS.
- }
-
- /**
- * Uninstall SF Forwarding rule from OVS.
- *
- * @param portChain
- * port chain
- */
- public void unInstallForwardingRule(PortChain portChain) {
- log.debug("unInstallForwardingRule");
- // TODO: Uninstallation of SF Forwarding rule from OVS.
+ //TODO: Apply forwarding rule on port-chain deletion.
}
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/manager/impl/SfcManagerTest.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/manager/impl/SfcManagerTest.java
new file mode 100644
index 00000000..e4f31f98
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/manager/impl/SfcManagerTest.java
@@ -0,0 +1,269 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.manager.impl;
+
+import org.junit.Test;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import org.onlab.packet.IpPrefix;
+import org.onosproject.sfc.manager.SfcService;
+import org.onosproject.vtnrsc.DefaultPortChain;
+import org.onosproject.vtnrsc.DefaultPortPair;
+import org.onosproject.vtnrsc.DefaultPortPairGroup;
+import org.onosproject.vtnrsc.PortChain;
+import org.onosproject.vtnrsc.PortChainId;
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.PortPairId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.DefaultFlowClassifier;
+import org.onosproject.vtnrsc.FlowClassifierId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.FlowClassifier;
+
+/**
+ * Unit tests for SfcManager class.
+ */
+public class SfcManagerTest {
+ /**
+ * Checks the operation of onPortPairCreated() method.
+ */
+ @Test
+ public void testOnPortPairCreated() {
+ final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortPair";
+ final String description = "PortPair";
+ final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
+ final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
+ DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
+ PortPair portPair = null;
+ SfcService sfcService = new SfcManager();
+
+ // create port pair
+ portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name).setDescription(description)
+ .setIngress(ingress).setEgress(egress).build();
+ sfcService.onPortPairCreated(portPair);
+ }
+
+ /**
+ * Checks the operation of onPortPairDeleted() method.
+ */
+ @Test
+ public void testOnPortPairDeleted() {
+ final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortPair";
+ final String description = "PortPair";
+ final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
+ final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
+ DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
+ PortPair portPair = null;
+ SfcService sfcService = new SfcManager();
+
+ // create port pair
+ portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name).setDescription(description)
+ .setIngress(ingress).setEgress(egress).build();
+ sfcService.onPortPairDeleted(portPair);
+ }
+
+ /**
+ * Checks the operation of onPortPairGroupCreated() method.
+ */
+ @Test
+ public void testOnPortPairGroupCreated() {
+ final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortPairGroup";
+ final String description = "PortPairGroup";
+ final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
+ DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
+ PortPairGroup portPairGroup = null;
+ SfcService sfcService = new SfcManager();
+
+ // create port-pair-id list
+ PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairIdList.add(portPairId);
+ portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairIdList.add(portPairId);
+
+ // create port pair
+ portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name)
+ .setDescription(description).setPortPairs(portPairIdList).build();
+ sfcService.onPortPairGroupCreated(portPairGroup);
+ }
+
+ /**
+ * Checks the operation of onPortPairGroupDeleted() method.
+ */
+ @Test
+ public void testOnPortPairGroupDeleted() {
+ final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortPairGroup";
+ final String description = "PortPairGroup";
+ final List<PortPairId> portPairIdList = new LinkedList<PortPairId>();
+ DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
+ PortPairGroup portPairGroup = null;
+ SfcService sfcService = new SfcManager();
+
+ // create port-pair-id list
+ PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairIdList.add(portPairId);
+ portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairIdList.add(portPairId);
+
+ // create port pair
+ portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId).setName(name)
+ .setDescription(description).setPortPairs(portPairIdList).build();
+ sfcService.onPortPairGroupDeleted(portPairGroup);
+ }
+
+ /**
+ * Checks the operation of onFlowClassifierCreated() method.
+ */
+ @Test
+ public void testOnFlowClassifierCreated() {
+ final String name = "FlowClassifier";
+ final String description = "FlowClassifier";
+ final String ethType = "IPv4";
+ final String protocol = "udp";
+ final int minSrcPortRange = 1024;
+ final int maxSrcPortRange = 5000;
+ final int minDstPortRange = 1024;
+ final int maxDstPortRange = 5000;
+ final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("8");
+ final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
+ final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
+ final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
+ final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
+ DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
+ FlowClassifier flowClassifier = null;
+ SfcService sfcService = new SfcManager();
+
+ // create flow classifier
+ flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
+ .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
+ .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
+ .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
+ .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
+ sfcService.onFlowClassifierCreated(flowClassifier);
+ }
+
+ /**
+ * Checks the operation of onFlowClassifierDeleted() method.
+ */
+ @Test
+ public void testOnFlowClassifierDeleted() {
+ final String name = "FlowClassifier";
+ final String description = "FlowClassifier";
+ final String ethType = "IPv4";
+ final String protocol = "udp";
+ final int minSrcPortRange = 1024;
+ final int maxSrcPortRange = 5000;
+ final int minDstPortRange = 1024;
+ final int maxDstPortRange = 5000;
+ final FlowClassifierId flowClassifierId = FlowClassifierId.of("71111111-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("8");
+ final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
+ final IpPrefix dstIpPrefix = IpPrefix.valueOf("100.100.100.100/0");
+ final VirtualPortId virtualSrcPort = VirtualPortId.portId("100");
+ final VirtualPortId virtualDstPort = VirtualPortId.portId("200");
+ DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
+ FlowClassifier flowClassifier = null;
+ SfcService sfcService = new SfcManager();
+
+ // create flow classifier
+ flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId).setTenantId(tenantId)
+ .setName(name).setDescription(description).setEtherType(ethType).setProtocol(protocol)
+ .setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
+ .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
+ .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
+ sfcService.onFlowClassifierDeleted(flowClassifier);
+ }
+
+ /**
+ * Checks the operation of onPortChainCreated() method.
+ */
+ @Test
+ public void testOnPortChainCreated() {
+ final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortChain";
+ final String description = "PortChain";
+ final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
+ final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
+ DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
+ DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
+ PortChain portChain = null;
+ SfcService sfcService = new SfcManager();
+
+ // create list of Port Pair Groups.
+ PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairGroupList.add(portPairGroupId);
+ portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
+ portPairGroupList.add(portPairGroupId);
+
+ // create list of Flow classifiers.
+ FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ flowClassifierList.add(flowClassifierId);
+ flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
+ flowClassifierList.add(flowClassifierId);
+
+ // create port chain
+ portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description)
+ .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build();
+ sfcService.onPortChainCreated(portChain);
+ }
+
+ /**
+ * Checks the operation of onPortChainDeleted() method.
+ */
+ @Test
+ public void testOnPortChainDeleted() {
+ final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortChain";
+ final String description = "PortChain";
+ final List<PortPairGroupId> portPairGroupList = new LinkedList<PortPairGroupId>();
+ final List<FlowClassifierId> flowClassifierList = new LinkedList<FlowClassifierId>();
+ DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
+ DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
+ PortChain portChain = null;
+ SfcService sfcService = new SfcManager();
+
+ // create list of Port Pair Groups.
+ PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairGroupList.add(portPairGroupId);
+ portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
+ portPairGroupList.add(portPairGroupId);
+
+ // create list of Flow classifiers.
+ FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ flowClassifierList.add(flowClassifierId);
+ flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
+ flowClassifierList.add(flowClassifierId);
+
+ // create port chain
+ portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name).setDescription(description)
+ .setPortPairGroups(portPairGroupList).setFlowClassifiers(flowClassifierList).build();
+ sfcService.onPortChainDeleted(portChain);
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowClassifierManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowClassifierManagerTestImpl.java
new file mode 100644
index 00000000..fe5babbd
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowClassifierManagerTestImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.onosproject.vtnrsc.FlowClassifierId;
+import org.onosproject.vtnrsc.FlowClassifier;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Provides implementation of the Flow Classifier Service.
+ */
+public class FlowClassifierManagerTestImpl implements FlowClassifierService {
+
+ private final ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean exists(FlowClassifierId id) {
+ return flowClassifierStore.containsKey(id);
+ }
+
+ @Override
+ public int getFlowClassifierCount() {
+ return flowClassifierStore.size();
+ }
+
+ @Override
+ public Iterable<FlowClassifier> getFlowClassifiers() {
+ return ImmutableList.copyOf(flowClassifierStore.values());
+ }
+
+ @Override
+ public FlowClassifier getFlowClassifier(FlowClassifierId id) {
+ return flowClassifierStore.get(id);
+ }
+
+ @Override
+ public boolean createFlowClassifier(FlowClassifier flowClassifier) {
+ FlowClassifierId id = flowClassifier.flowClassifierId();
+
+ flowClassifierStore.put(id, flowClassifier);
+ if (!flowClassifierStore.containsKey(id)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
+
+ if (!flowClassifierStore.containsKey(flowClassifier.flowClassifierId())) {
+ return false;
+ }
+
+ flowClassifierStore.put(flowClassifier.flowClassifierId(), flowClassifier);
+
+ if (!flowClassifier.equals(flowClassifierStore.get(flowClassifier.flowClassifierId()))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeFlowClassifier(FlowClassifierId id) {
+ return true;
+ }
+
+ @Override
+ public void addListener(FlowClassifierListener listener) {
+ }
+
+ @Override
+ public void removeListener(FlowClassifierListener listener) {
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowObjectiveServiceTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowObjectiveServiceTestImpl.java
new file mode 100644
index 00000000..9da9ee94
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/FlowObjectiveServiceTestImpl.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.flowobjective.FlowObjectiveService;
+import org.onosproject.net.flowobjective.FilteringObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.NextObjective;
+
+/**
+ * Testing version of implementation on FlowObjectiveService.
+ */
+public class FlowObjectiveServiceTestImpl implements FlowObjectiveService {
+
+ @Override
+ public void filter(DeviceId deviceId, FilteringObjective filteringObjective) {
+
+ }
+
+ @Override
+ public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
+
+ }
+
+ @Override
+ public void next(DeviceId deviceId, NextObjective nextObjective) {
+
+ }
+
+ @Override
+ public int allocateNextId() {
+ return 0;
+ }
+
+ @Override
+ public void initPolicy(String policy) {
+
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortChainManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortChainManagerTestImpl.java
new file mode 100644
index 00000000..4a3ba03d
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortChainManagerTestImpl.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collections;
+
+import org.onosproject.vtnrsc.PortChain;
+import org.onosproject.vtnrsc.PortChainId;
+import org.onosproject.vtnrsc.portchain.PortChainService;
+import org.onosproject.vtnrsc.portchain.PortChainEvent;
+import org.onosproject.vtnrsc.portchain.PortChainListener;
+import org.onosproject.event.AbstractListenerManager;
+
+/**
+ * Provides implementation of the portChainService.
+ */
+public class PortChainManagerTestImpl
+ extends AbstractListenerManager<PortChainEvent, PortChainListener>
+ implements PortChainService {
+
+ private ConcurrentMap<PortChainId, PortChain> portChainStore = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean exists(PortChainId portChainId) {
+ return portChainStore.containsKey(portChainId);
+ }
+
+ @Override
+ public int getPortChainCount() {
+ return portChainStore.size();
+ }
+
+ @Override
+ public Iterable<PortChain> getPortChains() {
+ return Collections.unmodifiableCollection(portChainStore.values());
+ }
+
+ @Override
+ public PortChain getPortChain(PortChainId portChainId) {
+ return portChainStore.get(portChainId);
+ }
+
+ @Override
+ public boolean createPortChain(PortChain portChain) {
+ portChainStore.put(portChain.portChainId(), portChain);
+ if (!portChainStore.containsKey(portChain.portChainId())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updatePortChain(PortChain portChain) {
+ if (!portChainStore.containsKey(portChain.portChainId())) {
+ return false;
+ }
+
+ portChainStore.put(portChain.portChainId(), portChain);
+
+ if (!portChain.equals(portChainStore.get(portChain.portChainId()))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removePortChain(PortChainId portChainId) {
+ return true;
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairGroupManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairGroupManagerTestImpl.java
new file mode 100644
index 00000000..ba31cd60
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairGroupManagerTestImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collections;
+
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
+
+/**
+ * Provides implementation of the portPairGroupService.
+ */
+public class PortPairGroupManagerTestImpl implements PortPairGroupService {
+
+ private ConcurrentMap<PortPairGroupId, PortPairGroup> portPairGroupStore = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean exists(PortPairGroupId portPairGroupId) {
+ return portPairGroupStore.containsKey(portPairGroupId);
+ }
+
+ @Override
+ public int getPortPairGroupCount() {
+ return portPairGroupStore.size();
+ }
+
+ @Override
+ public Iterable<PortPairGroup> getPortPairGroups() {
+ return Collections.unmodifiableCollection(portPairGroupStore.values());
+ }
+
+ @Override
+ public PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId) {
+ return portPairGroupStore.get(portPairGroupId);
+ }
+
+ @Override
+ public boolean createPortPairGroup(PortPairGroup portPairGroup) {
+ portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup);
+ if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updatePortPairGroup(PortPairGroup portPairGroup) {
+ if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) {
+ return false;
+ }
+
+ portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup);
+
+ if (!portPairGroup.equals(portPairGroupStore.get(portPairGroup.portPairGroupId()))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removePortPairGroup(PortPairGroupId portPairGroupId) {
+ return true;
+ }
+
+ @Override
+ public void addListener(PortPairGroupListener listener) {
+ }
+
+ @Override
+ public void removeListener(PortPairGroupListener listener) {
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairManagerTestImpl.java
new file mode 100644
index 00000000..aff58823
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/PortPairManagerTestImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Collections;
+
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairId;
+import org.onosproject.vtnrsc.portpair.PortPairListener;
+import org.onosproject.vtnrsc.portpair.PortPairService;
+
+/**
+ * Provides implementation of the portPairService.
+ */
+public class PortPairManagerTestImpl implements PortPairService {
+
+ private ConcurrentMap<PortPairId, PortPair> portPairStore = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean exists(PortPairId portPairId) {
+ return portPairStore.containsKey(portPairId);
+ }
+
+ @Override
+ public int getPortPairCount() {
+ return portPairStore.size();
+ }
+
+ @Override
+ public Iterable<PortPair> getPortPairs() {
+ return Collections.unmodifiableCollection(portPairStore.values());
+ }
+
+ @Override
+ public PortPair getPortPair(PortPairId portPairId) {
+ return portPairStore.get(portPairId);
+ }
+
+ @Override
+ public boolean createPortPair(PortPair portPair) {
+ portPairStore.put(portPair.portPairId(), portPair);
+ if (!portPairStore.containsKey(portPair.portPairId())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updatePortPair(PortPair portPair) {
+ if (!portPairStore.containsKey(portPair.portPairId())) {
+ return false;
+ }
+
+ portPairStore.put(portPair.portPairId(), portPair);
+
+ if (!portPair.equals(portPairStore.get(portPair.portPairId()))) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removePortPair(PortPairId portPairId) {
+ return true;
+ }
+
+ @Override
+ public void addListener(PortPairListener listener) {
+ }
+
+ @Override
+ public void removeListener(PortPairListener listener) {
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VirtualPortManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VirtualPortManagerTestImpl.java
new file mode 100644
index 00000000..de056a78
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VirtualPortManagerTestImpl.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.Collection;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.DeviceId;
+import org.onosproject.vtnrsc.FixedIp;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPort;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.TenantNetworkId;
+import org.onosproject.vtnrsc.virtualport.VirtualPortService;
+
+/**
+ * Provides implementation of the VirtualPort APIs.
+ */
+public class VirtualPortManagerTestImpl implements VirtualPortService {
+
+ protected ConcurrentMap<VirtualPortId, VirtualPort> vPortStore = new ConcurrentHashMap<>();
+
+ @Override
+ public boolean exists(VirtualPortId vPortId) {
+ return vPortStore.containsKey(vPortId);
+ }
+
+ @Override
+ public VirtualPort getPort(VirtualPortId vPortId) {
+ return vPortStore.get(vPortId);
+ }
+
+ @Override
+ public VirtualPort getPort(FixedIp fixedIP) {
+ return null;
+ }
+
+ @Override
+ public Collection<VirtualPort> getPorts() {
+ return null;
+ }
+
+ @Override
+ public Collection<VirtualPort> getPorts(TenantNetworkId networkId) {
+ return null;
+ }
+
+ @Override
+ public Collection<VirtualPort> getPorts(TenantId tenantId) {
+ return null;
+ }
+
+ @Override
+ public Collection<VirtualPort> getPorts(DeviceId deviceId) {
+ return null;
+ }
+
+ @Override
+ public VirtualPort getPort(TenantNetworkId networkId, IpAddress ipAddress) {
+ return null;
+ }
+
+ @Override
+ public boolean createPorts(Iterable<VirtualPort> vPorts) {
+ for (VirtualPort vPort : vPorts) {
+ vPortStore.put(vPort.portId(), vPort);
+ if (!vPortStore.containsKey(vPort.portId())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean updatePorts(Iterable<VirtualPort> vPorts) {
+ return true;
+ }
+
+ @Override
+ public boolean removePorts(Iterable<VirtualPortId> vPortIds) {
+ return true;
+ }
+}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java
new file mode 100644
index 00000000..4188cee6
--- /dev/null
+++ b/framework/src/onos/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.sfc.util;
+
+import java.util.Iterator;
+
+import org.onlab.packet.MacAddress;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.vtnrsc.SegmentationId;
+import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
+import org.onosproject.vtnrsc.event.VtnRscListener;
+import org.onosproject.vtnrsc.service.VtnRscService;
+
+/**
+ * Provides implementation of the VtnRsc service.
+ */
+public class VtnRscManagerTestImpl implements VtnRscService {
+ @Override
+ public void addListener(VtnRscListener listener) {
+ }
+
+ @Override
+ public void removeListener(VtnRscListener listener) {
+ }
+
+ @Override
+ public SegmentationId getL3vni(TenantId tenantId) {
+ return null;
+ }
+
+ @Override
+ public Iterator<Device> getClassifierOfTenant(TenantId tenantId) {
+ return null;
+ }
+
+ @Override
+ public Iterator<Device> getSFFOfTenant(TenantId tenantId) {
+ return null;
+ }
+
+ @Override
+ public MacAddress getGatewayMac(HostId hostId) {
+ return null;
+ }
+
+ @Override
+ public boolean isServiceFunction(VirtualPortId portId) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public DeviceId getSFToSFFMaping(VirtualPortId portId) {
+ return DeviceId.deviceId("www.google.com");
+ }
+}