[ONOS-3833] Added data structure to store load balance path info
Change-Id: Icf73a7c91652c2532db889fb4df70232a16650a2
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
index 7915ce0..ce27fc7 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
@@ -15,11 +15,13 @@
*/
package org.onosproject.vtnrsc;
+import static com.google.common.base.Preconditions.checkNotNull;
+
import java.util.Objects;
+
import org.onlab.packet.IpPrefix;
import com.google.common.base.MoreObjects;
-import static com.google.common.base.Preconditions.checkNotNull;
/**
* Provides Default flow classifier.
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java
index 89b94b3..d2c2e2e 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortChain.java
@@ -18,10 +18,16 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
/**
* Implementation of port chain.
@@ -35,6 +41,9 @@
private final List<PortPairGroupId> portPairGroupList;
private final List<FlowClassifierId> flowClassifierList;
+ private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>();
+ private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>();
+
/**
* Default constructor to create port chain.
*
@@ -58,6 +67,23 @@
this.flowClassifierList = flowClassifierList;
}
+ /**
+ * Match for two given paths.
+ *
+ * @param path1 path of sfc
+ * @param path2 path of sfc
+ * @return true if the given path are same false otherwise
+ */
+ private boolean comparePath(List<PortPairId> path1, List<PortPairId> path2) {
+ Iterator it = path1.iterator();
+ for (PortPairId portPairId: path2) {
+ if (!portPairId.equals(it.next())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public PortChainId portChainId() {
return portChainId;
@@ -89,6 +115,47 @@
}
@Override
+ public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id,
+ List<PortPairId> path) {
+ this.sfcLoadBalanceIdMap.put(fiveTuple, id);
+ this.sfcLoadBalancePathMap.put(id, path);
+ }
+
+ @Override
+ public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
+ return this.sfcLoadBalanceIdMap.get(fiveTuple);
+ }
+
+ @Override
+ public Set<FiveTuple> getLoadBalanceIdMapKeys() {
+ return ImmutableSet.copyOf(sfcLoadBalanceIdMap.keySet());
+ }
+
+ @Override
+ public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
+ return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(id));
+ }
+
+ @Override
+ public List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple) {
+ return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(this.sfcLoadBalanceIdMap.get(fiveTuple)));
+ }
+
+ @Override
+ public Optional<LoadBalanceId> matchPath(List<PortPairId> path) {
+
+ LoadBalanceId id = null;
+ for (Map.Entry<LoadBalanceId, List<PortPairId>> entry : sfcLoadBalancePathMap.entrySet()) {
+ List<PortPairId> tempPath = entry.getValue();
+ if (comparePath(path, tempPath)) {
+ id = entry.getKey();
+ break;
+ }
+ }
+ return Optional.of(id);
+ }
+
+ @Override
public int hashCode() {
return Objects.hash(portChainId, tenantId, name, description,
portPairGroupList, flowClassifierList);
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java
index 877cc6c..d455ff3 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultPortPairGroup.java
@@ -19,7 +19,9 @@
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
import com.google.common.collect.ImmutableList;
@@ -33,6 +35,7 @@
private final String name;
private final String description;
private final List<PortPairId> portPairList;
+ private final Map<PortPairId, Integer> portPairLoadMap;
/**
* Default constructor to create Port Pair Group.
@@ -52,6 +55,10 @@
this.name = name;
this.description = description;
this.portPairList = portPairList;
+ portPairLoadMap = new ConcurrentHashMap<>();
+ for (PortPairId portPairId : portPairList) {
+ portPairLoadMap.put(portPairId, new Integer(0));
+ }
}
@Override
@@ -80,6 +87,18 @@
}
@Override
+ public void addLoad(PortPairId portPairId) {
+ int load = portPairLoadMap.get(portPairId);
+ load = load + 1;
+ portPairLoadMap.put(portPairId, new Integer(load));
+ }
+
+ @Override
+ public int getLoad(PortPairId portPairId) {
+ return portPairLoadMap.get(portPairId);
+ }
+
+ @Override
public int hashCode() {
return Objects.hash(portPairGroupId, tenantId, name, description,
portPairList);
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java
index d147eaa..ba87010 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChain.java
@@ -16,6 +16,8 @@
package org.onosproject.vtnrsc;
import java.util.List;
+import java.util.Optional;
+import java.util.Set;
/**
* Abstraction of an entity providing Port Chain information.
@@ -70,6 +72,55 @@
List<FlowClassifierId> flowClassifiers();
/**
+ * Adds a new load balanced path.
+ *
+ * @param fiveTuple five tuple from the packet
+ * @param id load balance path identifier
+ * @param path load balanced path of list of port pairs
+ */
+ void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id,
+ List<PortPairId> path);
+
+ /**
+ * Get the load balance id from five tuple.
+ *
+ * @param fiveTuple five tuple from the packet
+ * @return load balance identifier for the given packet
+ */
+ LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple);
+
+ /**
+ * Get the keys set from load balanced id map.
+ *
+ * @return set of five tuple info
+ */
+ Set<FiveTuple> getLoadBalanceIdMapKeys();
+
+ /**
+ * Get the load balanced path from load balance Id.
+ *
+ * @param id load balance id.
+ * @return path containing list of port pairs
+ */
+ List<PortPairId> getLoadBalancePath(LoadBalanceId id);
+
+ /**
+ * Get the load balanced path from five tuple.
+ *
+ * @param fiveTuple five tuple from the packet
+ * @return path containing list of port pairs
+ */
+ List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple);
+
+ /**
+ * Match the given path with existing load balanced paths.
+ *
+ * @param path load balanced path
+ * @return load balance id if the path matches, null otherwise.
+ */
+ Optional<LoadBalanceId> matchPath(List<PortPairId> path);
+
+ /**
* Returns whether this port chain is an exact match to the port chain given
* in the argument.
* <p>
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java
index f647b57..abc3349 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroup.java
@@ -59,6 +59,21 @@
List<PortPairId> portPairs();
/**
+ * Adds the load on the given port pair id.
+ *
+ * @param portPairId port pair id.
+ */
+ public void addLoad(PortPairId portPairId);
+
+ /**
+ * Get the load on the given port pair id.
+ *
+ * @param portPairId port pair id
+ * @return load on the given port pair id.
+ */
+ public int getLoad(PortPairId portPairId);
+
+ /**
* Returns whether this port pair group is an exact match to the
* port pair group given in the argument.
* <p>
diff --git a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortChainTest.java b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortChainTest.java
index 27234ac..0916a68 100644
--- a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortChainTest.java
+++ b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortChainTest.java
@@ -15,21 +15,57 @@
*/
package org.onosproject.vtnrsc;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.junit.Test;
-
-import com.google.common.testing.EqualsTester;
-
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.onlab.packet.IPv4;
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.PortNumber;
+
+import com.google.common.collect.Lists;
+import com.google.common.testing.EqualsTester;
+
/**
* Unit tests for DefaultPortChain class.
*/
public class DefaultPortChainTest {
+
+ 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> portPairGroups = new LinkedList<PortPairGroupId>();
+ final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
+
+ private PortChain getPortChain() {
+
+ portPairGroups.clear();
+ flowClassifiers.clear();
+ // create list of Port Pair Groups.
+ PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairGroups.add(portPairGroupId);
+ portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
+ portPairGroups.add(portPairGroupId);
+ // create list of Flow classifiers.
+ FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ flowClassifiers.add(flowClassifierId);
+ flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
+ flowClassifiers.add(flowClassifierId);
+
+ DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
+ final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
+ .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
+ .build();
+
+ return portChain;
+ }
+
/**
* Checks that the DefaultPortChain class is immutable.
*/
@@ -43,33 +79,10 @@
*/
@Test
public void testEquals() {
+
// Create same two port chain objects.
- final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortChain1";
- final String description = "PortChain1";
- // create list of Port Pair Groups.
- final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
- PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairGroups.add(portPairGroupId);
- portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
- portPairGroups.add(portPairGroupId);
- // create list of Flow classifiers.
- final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
- FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- flowClassifiers.add(flowClassifierId);
- flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
- flowClassifiers.add(flowClassifierId);
-
- DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
- final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
-
- portChainBuilder = new DefaultPortChain.Builder();
- final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
+ final PortChain portChain1 = getPortChain();
+ final PortChain samePortChain1 = getPortChain();
// Create different port chain object.
final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
@@ -78,18 +91,18 @@
final String description2 = "PortChain2";
// create list of Port Pair Groups.
final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>();
- portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
+ PortPairGroupId portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
portPairGroups2.add(portPairGroupId);
portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af");
portPairGroups2.add(portPairGroupId);
// create list of Flow classifiers.
final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>();
- flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
+ FlowClassifierId flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
flowClassifiers2.add(flowClassifierId);
flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af");
flowClassifiers2.add(flowClassifierId);
- portChainBuilder = new DefaultPortChain.Builder();
+ DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2)
.setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2)
.build();
@@ -102,27 +115,8 @@
*/
@Test
public void testConstruction() {
- final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortChain";
- final String description = "PortChain";
- // create list of Port Pair Groups.
- final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
- PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairGroups.add(portPairGroupId);
- portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
- portPairGroups.add(portPairGroupId);
- // create list of Flow classifiers.
- final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
- FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- flowClassifiers.add(flowClassifierId);
- flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
- flowClassifiers.add(flowClassifierId);
- DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
- final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
+ final PortChain portChain = getPortChain();
assertThat(portChainId, is(portChain.portChainId()));
assertThat(tenantId, is(portChain.tenantId()));
@@ -131,4 +125,37 @@
assertThat(portPairGroups, is(portChain.portPairGroups()));
assertThat(flowClassifiers, is(portChain.flowClassifiers()));
}
+
+ /**
+ * Verifies the load balance data structures.
+ */
+ @Test
+ public void testLoadBalanceIdMap() {
+
+ final PortChain portChain = getPortChain();
+
+ final FiveTuple fiveTuple1 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("1.1.1.1"))
+ .setIpDst(IpAddress.valueOf("2.2.2.2"))
+ .setPortSrc(PortNumber.portNumber(500))
+ .setPortDst(PortNumber.portNumber(1000))
+ .setProtocol(IPv4.PROTOCOL_TCP)
+ .build();
+
+ PortPairId portPairId = PortPairId.of("a4444444-4a56-2a6e-cd3a-9dee4e2ec345");
+
+ final LoadBalanceId id1 = LoadBalanceId.of((byte) 1);
+
+ List<PortPairId> tempPath = Lists.newArrayList();
+ tempPath.add(portPairId);
+
+ portChain.addLoadBalancePath(fiveTuple1, id1, tempPath);
+ Set<FiveTuple> keys = portChain.getLoadBalanceIdMapKeys();
+ List<PortPairId> path = portChain.getLoadBalancePath(fiveTuple1);
+
+ assertThat(portChain.getLoadBalancePath(fiveTuple1), is(path));
+ assertThat(portChain.getLoadBalancePath(id1), is(path));
+ assertThat(portChain.getLoadBalanceId(fiveTuple1), is(id1));
+ assertThat(keys.contains(fiveTuple1), is(true));
+ assertThat(path.contains(portPairId), is(true));
+ }
}
diff --git a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortPairGroupTest.java b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortPairGroupTest.java
index 1b484e9..7d05698 100644
--- a/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortPairGroupTest.java
+++ b/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/DefaultPortPairGroupTest.java
@@ -15,6 +15,10 @@
*/
package org.onosproject.vtnrsc;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
import java.util.LinkedList;
import java.util.List;
@@ -22,14 +26,34 @@
import com.google.common.testing.EqualsTester;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
/**
* Unit tests for DefaultPortPairGroup class.
*/
public class DefaultPortPairGroupTest {
+
+ final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final TenantId tenantId = TenantId.tenantId("1");
+ final String name = "PortPairGroup1";
+ final String description = "PortPairGroup1";
+ final List<PortPairId> portPairList = new LinkedList<PortPairId>();
+
+ private PortPairGroup getPortPairGroup() {
+
+ portPairList.clear();
+ // Create same two port-pair-group objects.
+ PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairList.add(portPairId);
+ portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
+ portPairList.add(portPairId);
+
+ DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
+ PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
+ .setName(name).setDescription(description).setPortPairs(portPairList).build();
+
+ return portPairGroup;
+
+ }
+
/**
* Checks that the DefaultPortPairGroup class is immutable.
*/
@@ -43,25 +67,11 @@
*/
@Test
public void testEquals() {
- // Create same two port-pair-group objects.
- final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPairGroup1";
- final String description = "PortPairGroup1";
- // create port-pair-id list
- final List<PortPairId> portPairList = new LinkedList<PortPairId>();
- PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
- portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
+
+ final PortPairGroup portPairGroup1 = getPortPairGroup();
DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
-
- portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
+ final PortPairGroup samePortPairGroup1 = getPortPairGroup();
// Create different port-pair-group object.
final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
@@ -70,7 +80,7 @@
final String description2 = "PortPairGroup2";
// create port-pair-id list
final List<PortPairId> portPairList2 = new LinkedList<PortPairId>();
- portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
+ PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
portPairList2.add(portPairId);
portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
portPairList2.add(portPairId);
@@ -80,7 +90,7 @@
.setName(name2).setDescription(description2).setPortPairs(portPairList2).build();
new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2)
- .testEquals();
+ .testEquals();
}
/**
@@ -88,20 +98,8 @@
*/
@Test
public void testConstruction() {
- final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPairGroup";
- final String description = "PortPairGroup";
- // create port-pair-id list
- final List<PortPairId> portPairList = new LinkedList<PortPairId>();
- PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
- portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
- DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
+ final PortPairGroup portPairGroup = getPortPairGroup();
assertThat(portPairGroupId, is(portPairGroup.portPairGroupId()));
assertThat(tenantId, is(portPairGroup.tenantId()));
@@ -109,4 +107,19 @@
assertThat(description, is(portPairGroup.description()));
assertThat(portPairList, is(portPairGroup.portPairs()));
}
+
+ /**
+ * Checks the port pair load map.
+ */
+ @Test
+ public void testPortPairLod() {
+
+ PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
+ final PortPairGroup portPairGroup = getPortPairGroup();
+ int load1 = portPairGroup.getLoad(portPairId);
+ portPairGroup.addLoad(portPairId);
+ int load2 = portPairGroup.getLoad(portPairId);
+
+ assertThat((load1 + 1), is(load2));
+ }
}
diff --git a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java
index a4b3be0..b172c09 100644
--- a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java
+++ b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortChainResourceTest.java
@@ -30,11 +30,11 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import javax.ws.rs.core.MediaType;
-import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -42,14 +42,18 @@
import org.onlab.osgi.TestServiceDirectory;
import org.onlab.rest.BaseResource;
import org.onosproject.codec.CodecService;
+import org.onosproject.vtnrsc.FiveTuple;
import org.onosproject.vtnrsc.FlowClassifierId;
+import org.onosproject.vtnrsc.LoadBalanceId;
import org.onosproject.vtnrsc.PortChain;
import org.onosproject.vtnrsc.PortChainId;
import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.PortPairId;
import org.onosproject.vtnrsc.TenantId;
import org.onosproject.vtnrsc.portchain.PortChainService;
import org.onosproject.vtnweb.web.SfcCodecContext;
+import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -135,6 +139,41 @@
Objects.equals(this.portChainId, portChain.portChainId()) &&
Objects.equals(this.tenantId, portChain.tenantId());
}
+
+ @Override
+ public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id, List<PortPairId> path) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Set<FiveTuple> getLoadBalanceIdMapKeys() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Optional<LoadBalanceId> matchPath(List<PortPairId> path) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
/**
diff --git a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java
index 70335ba..9b7c987 100644
--- a/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java
+++ b/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/resources/PortPairGroupResourceTest.java
@@ -34,7 +34,6 @@
import javax.ws.rs.core.MediaType;
-import com.eclipsesource.json.Json;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +48,7 @@
import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
import org.onosproject.vtnweb.web.SfcCodecContext;
+import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -122,6 +122,17 @@
Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) &&
Objects.equals(this.tenantId, portPairGroup.tenantId());
}
+
+ @Override
+ public void addLoad(PortPairId portPairId) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public int getLoad(PortPairId portPairId) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
/**