Phaneendra Manda
Committed by Thomas Vachuska

[ONOS-3833] Added data structure to store load balance path info

Change-Id: Icf73a7c91652c2532db889fb4df70232a16650a2
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
15 */ 15 */
16 package org.onosproject.vtnrsc; 16 package org.onosproject.vtnrsc;
17 17
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +
18 import java.util.Objects; 20 import java.util.Objects;
21 +
19 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
20 23
21 import com.google.common.base.MoreObjects; 24 import com.google.common.base.MoreObjects;
22 -import static com.google.common.base.Preconditions.checkNotNull;
23 25
24 /** 26 /**
25 * Provides Default flow classifier. 27 * Provides Default flow classifier.
......
...@@ -18,10 +18,16 @@ package org.onosproject.vtnrsc; ...@@ -18,10 +18,16 @@ package org.onosproject.vtnrsc;
18 import static com.google.common.base.MoreObjects.toStringHelper; 18 import static com.google.common.base.MoreObjects.toStringHelper;
19 import static com.google.common.base.Preconditions.checkNotNull; 19 import static com.google.common.base.Preconditions.checkNotNull;
20 20
21 +import java.util.Iterator;
21 import java.util.List; 22 import java.util.List;
23 +import java.util.Map;
22 import java.util.Objects; 24 import java.util.Objects;
25 +import java.util.Optional;
26 +import java.util.Set;
27 +import java.util.concurrent.ConcurrentHashMap;
23 28
24 import com.google.common.collect.ImmutableList; 29 import com.google.common.collect.ImmutableList;
30 +import com.google.common.collect.ImmutableSet;
25 31
26 /** 32 /**
27 * Implementation of port chain. 33 * Implementation of port chain.
...@@ -35,6 +41,9 @@ public final class DefaultPortChain implements PortChain { ...@@ -35,6 +41,9 @@ public final class DefaultPortChain implements PortChain {
35 private final List<PortPairGroupId> portPairGroupList; 41 private final List<PortPairGroupId> portPairGroupList;
36 private final List<FlowClassifierId> flowClassifierList; 42 private final List<FlowClassifierId> flowClassifierList;
37 43
44 + private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>();
45 + private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>();
46 +
38 /** 47 /**
39 * Default constructor to create port chain. 48 * Default constructor to create port chain.
40 * 49 *
...@@ -58,6 +67,23 @@ public final class DefaultPortChain implements PortChain { ...@@ -58,6 +67,23 @@ public final class DefaultPortChain implements PortChain {
58 this.flowClassifierList = flowClassifierList; 67 this.flowClassifierList = flowClassifierList;
59 } 68 }
60 69
70 + /**
71 + * Match for two given paths.
72 + *
73 + * @param path1 path of sfc
74 + * @param path2 path of sfc
75 + * @return true if the given path are same false otherwise
76 + */
77 + private boolean comparePath(List<PortPairId> path1, List<PortPairId> path2) {
78 + Iterator it = path1.iterator();
79 + for (PortPairId portPairId: path2) {
80 + if (!portPairId.equals(it.next())) {
81 + return false;
82 + }
83 + }
84 + return true;
85 + }
86 +
61 @Override 87 @Override
62 public PortChainId portChainId() { 88 public PortChainId portChainId() {
63 return portChainId; 89 return portChainId;
...@@ -89,6 +115,47 @@ public final class DefaultPortChain implements PortChain { ...@@ -89,6 +115,47 @@ public final class DefaultPortChain implements PortChain {
89 } 115 }
90 116
91 @Override 117 @Override
118 + public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id,
119 + List<PortPairId> path) {
120 + this.sfcLoadBalanceIdMap.put(fiveTuple, id);
121 + this.sfcLoadBalancePathMap.put(id, path);
122 + }
123 +
124 + @Override
125 + public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
126 + return this.sfcLoadBalanceIdMap.get(fiveTuple);
127 + }
128 +
129 + @Override
130 + public Set<FiveTuple> getLoadBalanceIdMapKeys() {
131 + return ImmutableSet.copyOf(sfcLoadBalanceIdMap.keySet());
132 + }
133 +
134 + @Override
135 + public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
136 + return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(id));
137 + }
138 +
139 + @Override
140 + public List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple) {
141 + return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(this.sfcLoadBalanceIdMap.get(fiveTuple)));
142 + }
143 +
144 + @Override
145 + public Optional<LoadBalanceId> matchPath(List<PortPairId> path) {
146 +
147 + LoadBalanceId id = null;
148 + for (Map.Entry<LoadBalanceId, List<PortPairId>> entry : sfcLoadBalancePathMap.entrySet()) {
149 + List<PortPairId> tempPath = entry.getValue();
150 + if (comparePath(path, tempPath)) {
151 + id = entry.getKey();
152 + break;
153 + }
154 + }
155 + return Optional.of(id);
156 + }
157 +
158 + @Override
92 public int hashCode() { 159 public int hashCode() {
93 return Objects.hash(portChainId, tenantId, name, description, 160 return Objects.hash(portChainId, tenantId, name, description,
94 portPairGroupList, flowClassifierList); 161 portPairGroupList, flowClassifierList);
......
...@@ -19,7 +19,9 @@ import static com.google.common.base.MoreObjects.toStringHelper; ...@@ -19,7 +19,9 @@ import static com.google.common.base.MoreObjects.toStringHelper;
19 import static com.google.common.base.Preconditions.checkNotNull; 19 import static com.google.common.base.Preconditions.checkNotNull;
20 20
21 import java.util.List; 21 import java.util.List;
22 +import java.util.Map;
22 import java.util.Objects; 23 import java.util.Objects;
24 +import java.util.concurrent.ConcurrentHashMap;
23 25
24 import com.google.common.collect.ImmutableList; 26 import com.google.common.collect.ImmutableList;
25 27
...@@ -33,6 +35,7 @@ public final class DefaultPortPairGroup implements PortPairGroup { ...@@ -33,6 +35,7 @@ public final class DefaultPortPairGroup implements PortPairGroup {
33 private final String name; 35 private final String name;
34 private final String description; 36 private final String description;
35 private final List<PortPairId> portPairList; 37 private final List<PortPairId> portPairList;
38 + private final Map<PortPairId, Integer> portPairLoadMap;
36 39
37 /** 40 /**
38 * Default constructor to create Port Pair Group. 41 * Default constructor to create Port Pair Group.
...@@ -52,6 +55,10 @@ public final class DefaultPortPairGroup implements PortPairGroup { ...@@ -52,6 +55,10 @@ public final class DefaultPortPairGroup implements PortPairGroup {
52 this.name = name; 55 this.name = name;
53 this.description = description; 56 this.description = description;
54 this.portPairList = portPairList; 57 this.portPairList = portPairList;
58 + portPairLoadMap = new ConcurrentHashMap<>();
59 + for (PortPairId portPairId : portPairList) {
60 + portPairLoadMap.put(portPairId, new Integer(0));
61 + }
55 } 62 }
56 63
57 @Override 64 @Override
...@@ -80,6 +87,18 @@ public final class DefaultPortPairGroup implements PortPairGroup { ...@@ -80,6 +87,18 @@ public final class DefaultPortPairGroup implements PortPairGroup {
80 } 87 }
81 88
82 @Override 89 @Override
90 + public void addLoad(PortPairId portPairId) {
91 + int load = portPairLoadMap.get(portPairId);
92 + load = load + 1;
93 + portPairLoadMap.put(portPairId, new Integer(load));
94 + }
95 +
96 + @Override
97 + public int getLoad(PortPairId portPairId) {
98 + return portPairLoadMap.get(portPairId);
99 + }
100 +
101 + @Override
83 public int hashCode() { 102 public int hashCode() {
84 return Objects.hash(portPairGroupId, tenantId, name, description, 103 return Objects.hash(portPairGroupId, tenantId, name, description,
85 portPairList); 104 portPairList);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
16 package org.onosproject.vtnrsc; 16 package org.onosproject.vtnrsc;
17 17
18 import java.util.List; 18 import java.util.List;
19 +import java.util.Optional;
20 +import java.util.Set;
19 21
20 /** 22 /**
21 * Abstraction of an entity providing Port Chain information. 23 * Abstraction of an entity providing Port Chain information.
...@@ -70,6 +72,55 @@ public interface PortChain { ...@@ -70,6 +72,55 @@ public interface PortChain {
70 List<FlowClassifierId> flowClassifiers(); 72 List<FlowClassifierId> flowClassifiers();
71 73
72 /** 74 /**
75 + * Adds a new load balanced path.
76 + *
77 + * @param fiveTuple five tuple from the packet
78 + * @param id load balance path identifier
79 + * @param path load balanced path of list of port pairs
80 + */
81 + void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id,
82 + List<PortPairId> path);
83 +
84 + /**
85 + * Get the load balance id from five tuple.
86 + *
87 + * @param fiveTuple five tuple from the packet
88 + * @return load balance identifier for the given packet
89 + */
90 + LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple);
91 +
92 + /**
93 + * Get the keys set from load balanced id map.
94 + *
95 + * @return set of five tuple info
96 + */
97 + Set<FiveTuple> getLoadBalanceIdMapKeys();
98 +
99 + /**
100 + * Get the load balanced path from load balance Id.
101 + *
102 + * @param id load balance id.
103 + * @return path containing list of port pairs
104 + */
105 + List<PortPairId> getLoadBalancePath(LoadBalanceId id);
106 +
107 + /**
108 + * Get the load balanced path from five tuple.
109 + *
110 + * @param fiveTuple five tuple from the packet
111 + * @return path containing list of port pairs
112 + */
113 + List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple);
114 +
115 + /**
116 + * Match the given path with existing load balanced paths.
117 + *
118 + * @param path load balanced path
119 + * @return load balance id if the path matches, null otherwise.
120 + */
121 + Optional<LoadBalanceId> matchPath(List<PortPairId> path);
122 +
123 + /**
73 * Returns whether this port chain is an exact match to the port chain given 124 * Returns whether this port chain is an exact match to the port chain given
74 * in the argument. 125 * in the argument.
75 * <p> 126 * <p>
......
...@@ -59,6 +59,21 @@ public interface PortPairGroup { ...@@ -59,6 +59,21 @@ public interface PortPairGroup {
59 List<PortPairId> portPairs(); 59 List<PortPairId> portPairs();
60 60
61 /** 61 /**
62 + * Adds the load on the given port pair id.
63 + *
64 + * @param portPairId port pair id.
65 + */
66 + public void addLoad(PortPairId portPairId);
67 +
68 + /**
69 + * Get the load on the given port pair id.
70 + *
71 + * @param portPairId port pair id
72 + * @return load on the given port pair id.
73 + */
74 + public int getLoad(PortPairId portPairId);
75 +
76 + /**
62 * Returns whether this port pair group is an exact match to the 77 * Returns whether this port pair group is an exact match to the
63 * port pair group given in the argument. 78 * port pair group given in the argument.
64 * <p> 79 * <p>
......
...@@ -15,61 +15,74 @@ ...@@ -15,61 +15,74 @@
15 */ 15 */
16 package org.onosproject.vtnrsc; 16 package org.onosproject.vtnrsc;
17 17
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
21 +
18 import java.util.LinkedList; 22 import java.util.LinkedList;
19 import java.util.List; 23 import java.util.List;
24 +import java.util.Set;
20 25
21 import org.junit.Test; 26 import org.junit.Test;
27 +import org.onlab.packet.IPv4;
28 +import org.onlab.packet.IpAddress;
29 +import org.onosproject.net.PortNumber;
22 30
31 +import com.google.common.collect.Lists;
23 import com.google.common.testing.EqualsTester; 32 import com.google.common.testing.EqualsTester;
24 33
25 -import static org.hamcrest.MatcherAssert.assertThat;
26 -import static org.hamcrest.Matchers.is;
27 -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28 -
29 /** 34 /**
30 * Unit tests for DefaultPortChain class. 35 * Unit tests for DefaultPortChain class.
31 */ 36 */
32 public class DefaultPortChainTest { 37 public class DefaultPortChainTest {
33 - /**
34 - * Checks that the DefaultPortChain class is immutable.
35 - */
36 - @Test
37 - public void testImmutability() {
38 - assertThatClassIsImmutable(DefaultPortChain.class);
39 - }
40 38
41 - /** 39 + final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
42 - * Checks the operation of equals() methods. 40 + final TenantId tenantId = TenantId.tenantId("1");
43 - */ 41 + final String name = "PortChain";
44 - @Test 42 + final String description = "PortChain";
45 - public void testEquals() { 43 + final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
46 - // Create same two port chain objects. 44 + final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
47 - final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae"); 45 +
48 - final TenantId tenantId = TenantId.tenantId("1"); 46 + private PortChain getPortChain() {
49 - final String name = "PortChain1"; 47 +
50 - final String description = "PortChain1"; 48 + portPairGroups.clear();
49 + flowClassifiers.clear();
51 // create list of Port Pair Groups. 50 // create list of Port Pair Groups.
52 - final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
53 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae"); 51 PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
54 portPairGroups.add(portPairGroupId); 52 portPairGroups.add(portPairGroupId);
55 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af"); 53 portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
56 portPairGroups.add(portPairGroupId); 54 portPairGroups.add(portPairGroupId);
57 // create list of Flow classifiers. 55 // create list of Flow classifiers.
58 - final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
59 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae"); 56 FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
60 flowClassifiers.add(flowClassifierId); 57 flowClassifiers.add(flowClassifierId);
61 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af"); 58 flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
62 flowClassifiers.add(flowClassifierId); 59 flowClassifiers.add(flowClassifierId);
63 60
64 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); 61 DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
65 - final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) 62 + final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
66 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) 63 .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
67 .build(); 64 .build();
68 65
69 - portChainBuilder = new DefaultPortChain.Builder(); 66 + return portChain;
70 - final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name) 67 + }
71 - .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers) 68 +
72 - .build(); 69 + /**
70 + * Checks that the DefaultPortChain class is immutable.
71 + */
72 + @Test
73 + public void testImmutability() {
74 + assertThatClassIsImmutable(DefaultPortChain.class);
75 + }
76 +
77 + /**
78 + * Checks the operation of equals() methods.
79 + */
80 + @Test
81 + public void testEquals() {
82 +
83 + // Create same two port chain objects.
84 + final PortChain portChain1 = getPortChain();
85 + final PortChain samePortChain1 = getPortChain();
73 86
74 // Create different port chain object. 87 // Create different port chain object.
75 final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); 88 final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
...@@ -78,18 +91,18 @@ public class DefaultPortChainTest { ...@@ -78,18 +91,18 @@ public class DefaultPortChainTest {
78 final String description2 = "PortChain2"; 91 final String description2 = "PortChain2";
79 // create list of Port Pair Groups. 92 // create list of Port Pair Groups.
80 final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>(); 93 final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>();
81 - portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); 94 + PortPairGroupId portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
82 portPairGroups2.add(portPairGroupId); 95 portPairGroups2.add(portPairGroupId);
83 portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af"); 96 portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af");
84 portPairGroups2.add(portPairGroupId); 97 portPairGroups2.add(portPairGroupId);
85 // create list of Flow classifiers. 98 // create list of Flow classifiers.
86 final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>(); 99 final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>();
87 - flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae"); 100 + FlowClassifierId flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
88 flowClassifiers2.add(flowClassifierId); 101 flowClassifiers2.add(flowClassifierId);
89 flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af"); 102 flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af");
90 flowClassifiers2.add(flowClassifierId); 103 flowClassifiers2.add(flowClassifierId);
91 104
92 - portChainBuilder = new DefaultPortChain.Builder(); 105 + DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
93 final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2) 106 final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2)
94 .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2) 107 .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2)
95 .build(); 108 .build();
...@@ -102,27 +115,8 @@ public class DefaultPortChainTest { ...@@ -102,27 +115,8 @@ public class DefaultPortChainTest {
102 */ 115 */
103 @Test 116 @Test
104 public void testConstruction() { 117 public void testConstruction() {
105 - final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
106 - final TenantId tenantId = TenantId.tenantId("1");
107 - final String name = "PortChain";
108 - final String description = "PortChain";
109 - // create list of Port Pair Groups.
110 - final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
111 - PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
112 - portPairGroups.add(portPairGroupId);
113 - portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
114 - portPairGroups.add(portPairGroupId);
115 - // create list of Flow classifiers.
116 - final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
117 - FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
118 - flowClassifiers.add(flowClassifierId);
119 - flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
120 - flowClassifiers.add(flowClassifierId);
121 118
122 - DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder(); 119 + final PortChain portChain = getPortChain();
123 - final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
124 - .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
125 - .build();
126 120
127 assertThat(portChainId, is(portChain.portChainId())); 121 assertThat(portChainId, is(portChain.portChainId()));
128 assertThat(tenantId, is(portChain.tenantId())); 122 assertThat(tenantId, is(portChain.tenantId()));
...@@ -131,4 +125,37 @@ public class DefaultPortChainTest { ...@@ -131,4 +125,37 @@ public class DefaultPortChainTest {
131 assertThat(portPairGroups, is(portChain.portPairGroups())); 125 assertThat(portPairGroups, is(portChain.portPairGroups()));
132 assertThat(flowClassifiers, is(portChain.flowClassifiers())); 126 assertThat(flowClassifiers, is(portChain.flowClassifiers()));
133 } 127 }
128 +
129 + /**
130 + * Verifies the load balance data structures.
131 + */
132 + @Test
133 + public void testLoadBalanceIdMap() {
134 +
135 + final PortChain portChain = getPortChain();
136 +
137 + final FiveTuple fiveTuple1 = DefaultFiveTuple.builder().setIpSrc(IpAddress.valueOf("1.1.1.1"))
138 + .setIpDst(IpAddress.valueOf("2.2.2.2"))
139 + .setPortSrc(PortNumber.portNumber(500))
140 + .setPortDst(PortNumber.portNumber(1000))
141 + .setProtocol(IPv4.PROTOCOL_TCP)
142 + .build();
143 +
144 + PortPairId portPairId = PortPairId.of("a4444444-4a56-2a6e-cd3a-9dee4e2ec345");
145 +
146 + final LoadBalanceId id1 = LoadBalanceId.of((byte) 1);
147 +
148 + List<PortPairId> tempPath = Lists.newArrayList();
149 + tempPath.add(portPairId);
150 +
151 + portChain.addLoadBalancePath(fiveTuple1, id1, tempPath);
152 + Set<FiveTuple> keys = portChain.getLoadBalanceIdMapKeys();
153 + List<PortPairId> path = portChain.getLoadBalancePath(fiveTuple1);
154 +
155 + assertThat(portChain.getLoadBalancePath(fiveTuple1), is(path));
156 + assertThat(portChain.getLoadBalancePath(id1), is(path));
157 + assertThat(portChain.getLoadBalanceId(fiveTuple1), is(id1));
158 + assertThat(keys.contains(fiveTuple1), is(true));
159 + assertThat(path.contains(portPairId), is(true));
160 + }
134 } 161 }
......
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
15 */ 15 */
16 package org.onosproject.vtnrsc; 16 package org.onosproject.vtnrsc;
17 17
18 +import static org.hamcrest.MatcherAssert.assertThat;
19 +import static org.hamcrest.Matchers.is;
20 +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
21 +
18 import java.util.LinkedList; 22 import java.util.LinkedList;
19 import java.util.List; 23 import java.util.List;
20 24
...@@ -22,14 +26,34 @@ import org.junit.Test; ...@@ -22,14 +26,34 @@ import org.junit.Test;
22 26
23 import com.google.common.testing.EqualsTester; 27 import com.google.common.testing.EqualsTester;
24 28
25 -import static org.hamcrest.MatcherAssert.assertThat;
26 -import static org.hamcrest.Matchers.is;
27 -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28 -
29 /** 29 /**
30 * Unit tests for DefaultPortPairGroup class. 30 * Unit tests for DefaultPortPairGroup class.
31 */ 31 */
32 public class DefaultPortPairGroupTest { 32 public class DefaultPortPairGroupTest {
33 +
34 + final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
35 + final TenantId tenantId = TenantId.tenantId("1");
36 + final String name = "PortPairGroup1";
37 + final String description = "PortPairGroup1";
38 + final List<PortPairId> portPairList = new LinkedList<PortPairId>();
39 +
40 + private PortPairGroup getPortPairGroup() {
41 +
42 + portPairList.clear();
43 + // Create same two port-pair-group objects.
44 + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
45 + portPairList.add(portPairId);
46 + portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
47 + portPairList.add(portPairId);
48 +
49 + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
50 + PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
51 + .setName(name).setDescription(description).setPortPairs(portPairList).build();
52 +
53 + return portPairGroup;
54 +
55 + }
56 +
33 /** 57 /**
34 * Checks that the DefaultPortPairGroup class is immutable. 58 * Checks that the DefaultPortPairGroup class is immutable.
35 */ 59 */
...@@ -43,25 +67,11 @@ public class DefaultPortPairGroupTest { ...@@ -43,25 +67,11 @@ public class DefaultPortPairGroupTest {
43 */ 67 */
44 @Test 68 @Test
45 public void testEquals() { 69 public void testEquals() {
46 - // Create same two port-pair-group objects.
47 - final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
48 - final TenantId tenantId = TenantId.tenantId("1");
49 - final String name = "PortPairGroup1";
50 - final String description = "PortPairGroup1";
51 - // create port-pair-id list
52 - final List<PortPairId> portPairList = new LinkedList<PortPairId>();
53 - PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
54 - portPairList.add(portPairId);
55 - portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
56 - portPairList.add(portPairId);
57 70
58 - DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); 71 + final PortPairGroup portPairGroup1 = getPortPairGroup();
59 - final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
60 - .setName(name).setDescription(description).setPortPairs(portPairList).build();
61 72
62 - portPairGroupBuilder = new DefaultPortPairGroup.Builder(); 73 + DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
63 - final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId) 74 + final PortPairGroup samePortPairGroup1 = getPortPairGroup();
64 - .setName(name).setDescription(description).setPortPairs(portPairList).build();
65 75
66 // Create different port-pair-group object. 76 // Create different port-pair-group object.
67 final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae"); 77 final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
...@@ -70,7 +80,7 @@ public class DefaultPortPairGroupTest { ...@@ -70,7 +80,7 @@ public class DefaultPortPairGroupTest {
70 final String description2 = "PortPairGroup2"; 80 final String description2 = "PortPairGroup2";
71 // create port-pair-id list 81 // create port-pair-id list
72 final List<PortPairId> portPairList2 = new LinkedList<PortPairId>(); 82 final List<PortPairId> portPairList2 = new LinkedList<PortPairId>();
73 - portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); 83 + PortPairId portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
74 portPairList2.add(portPairId); 84 portPairList2.add(portPairId);
75 portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae"); 85 portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
76 portPairList2.add(portPairId); 86 portPairList2.add(portPairId);
...@@ -80,7 +90,7 @@ public class DefaultPortPairGroupTest { ...@@ -80,7 +90,7 @@ public class DefaultPortPairGroupTest {
80 .setName(name2).setDescription(description2).setPortPairs(portPairList2).build(); 90 .setName(name2).setDescription(description2).setPortPairs(portPairList2).build();
81 91
82 new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2) 92 new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2)
83 - .testEquals(); 93 + .testEquals();
84 } 94 }
85 95
86 /** 96 /**
...@@ -88,20 +98,8 @@ public class DefaultPortPairGroupTest { ...@@ -88,20 +98,8 @@ public class DefaultPortPairGroupTest {
88 */ 98 */
89 @Test 99 @Test
90 public void testConstruction() { 100 public void testConstruction() {
91 - final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
92 - final TenantId tenantId = TenantId.tenantId("1");
93 - final String name = "PortPairGroup";
94 - final String description = "PortPairGroup";
95 - // create port-pair-id list
96 - final List<PortPairId> portPairList = new LinkedList<PortPairId>();
97 - PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
98 - portPairList.add(portPairId);
99 - portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
100 - portPairList.add(portPairId);
101 101
102 - DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder(); 102 + final PortPairGroup portPairGroup = getPortPairGroup();
103 - final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
104 - .setName(name).setDescription(description).setPortPairs(portPairList).build();
105 103
106 assertThat(portPairGroupId, is(portPairGroup.portPairGroupId())); 104 assertThat(portPairGroupId, is(portPairGroup.portPairGroupId()));
107 assertThat(tenantId, is(portPairGroup.tenantId())); 105 assertThat(tenantId, is(portPairGroup.tenantId()));
...@@ -109,4 +107,19 @@ public class DefaultPortPairGroupTest { ...@@ -109,4 +107,19 @@ public class DefaultPortPairGroupTest {
109 assertThat(description, is(portPairGroup.description())); 107 assertThat(description, is(portPairGroup.description()));
110 assertThat(portPairList, is(portPairGroup.portPairs())); 108 assertThat(portPairList, is(portPairGroup.portPairs()));
111 } 109 }
110 +
111 + /**
112 + * Checks the port pair load map.
113 + */
114 + @Test
115 + public void testPortPairLod() {
116 +
117 + PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
118 + final PortPairGroup portPairGroup = getPortPairGroup();
119 + int load1 = portPairGroup.getLoad(portPairId);
120 + portPairGroup.addLoad(portPairId);
121 + int load2 = portPairGroup.getLoad(portPairId);
122 +
123 + assertThat((load1 + 1), is(load2));
124 + }
112 } 125 }
......
...@@ -30,11 +30,11 @@ import java.net.HttpURLConnection; ...@@ -30,11 +30,11 @@ import java.net.HttpURLConnection;
30 import java.util.HashSet; 30 import java.util.HashSet;
31 import java.util.List; 31 import java.util.List;
32 import java.util.Objects; 32 import java.util.Objects;
33 +import java.util.Optional;
33 import java.util.Set; 34 import java.util.Set;
34 35
35 import javax.ws.rs.core.MediaType; 36 import javax.ws.rs.core.MediaType;
36 37
37 -import com.eclipsesource.json.Json;
38 import org.junit.After; 38 import org.junit.After;
39 import org.junit.Before; 39 import org.junit.Before;
40 import org.junit.Test; 40 import org.junit.Test;
...@@ -42,14 +42,18 @@ import org.onlab.osgi.ServiceDirectory; ...@@ -42,14 +42,18 @@ import org.onlab.osgi.ServiceDirectory;
42 import org.onlab.osgi.TestServiceDirectory; 42 import org.onlab.osgi.TestServiceDirectory;
43 import org.onlab.rest.BaseResource; 43 import org.onlab.rest.BaseResource;
44 import org.onosproject.codec.CodecService; 44 import org.onosproject.codec.CodecService;
45 +import org.onosproject.vtnrsc.FiveTuple;
45 import org.onosproject.vtnrsc.FlowClassifierId; 46 import org.onosproject.vtnrsc.FlowClassifierId;
47 +import org.onosproject.vtnrsc.LoadBalanceId;
46 import org.onosproject.vtnrsc.PortChain; 48 import org.onosproject.vtnrsc.PortChain;
47 import org.onosproject.vtnrsc.PortChainId; 49 import org.onosproject.vtnrsc.PortChainId;
48 import org.onosproject.vtnrsc.PortPairGroupId; 50 import org.onosproject.vtnrsc.PortPairGroupId;
51 +import org.onosproject.vtnrsc.PortPairId;
49 import org.onosproject.vtnrsc.TenantId; 52 import org.onosproject.vtnrsc.TenantId;
50 import org.onosproject.vtnrsc.portchain.PortChainService; 53 import org.onosproject.vtnrsc.portchain.PortChainService;
51 import org.onosproject.vtnweb.web.SfcCodecContext; 54 import org.onosproject.vtnweb.web.SfcCodecContext;
52 55
56 +import com.eclipsesource.json.Json;
53 import com.eclipsesource.json.JsonObject; 57 import com.eclipsesource.json.JsonObject;
54 import com.google.common.collect.ImmutableList; 58 import com.google.common.collect.ImmutableList;
55 import com.google.common.collect.Lists; 59 import com.google.common.collect.Lists;
...@@ -135,6 +139,41 @@ public class PortChainResourceTest extends VtnResourceTest { ...@@ -135,6 +139,41 @@ public class PortChainResourceTest extends VtnResourceTest {
135 Objects.equals(this.portChainId, portChain.portChainId()) && 139 Objects.equals(this.portChainId, portChain.portChainId()) &&
136 Objects.equals(this.tenantId, portChain.tenantId()); 140 Objects.equals(this.tenantId, portChain.tenantId());
137 } 141 }
142 +
143 + @Override
144 + public void addLoadBalancePath(FiveTuple fiveTuple, LoadBalanceId id, List<PortPairId> path) {
145 + // TODO Auto-generated method stub
146 + }
147 +
148 + @Override
149 + public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
150 + // TODO Auto-generated method stub
151 + return null;
152 + }
153 +
154 + @Override
155 + public Set<FiveTuple> getLoadBalanceIdMapKeys() {
156 + // TODO Auto-generated method stub
157 + return null;
158 + }
159 +
160 + @Override
161 + public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
162 + // TODO Auto-generated method stub
163 + return null;
164 + }
165 +
166 + @Override
167 + public List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple) {
168 + // TODO Auto-generated method stub
169 + return null;
170 + }
171 +
172 + @Override
173 + public Optional<LoadBalanceId> matchPath(List<PortPairId> path) {
174 + // TODO Auto-generated method stub
175 + return null;
176 + }
138 } 177 }
139 178
140 /** 179 /**
......
...@@ -34,7 +34,6 @@ import java.util.Set; ...@@ -34,7 +34,6 @@ import java.util.Set;
34 34
35 import javax.ws.rs.core.MediaType; 35 import javax.ws.rs.core.MediaType;
36 36
37 -import com.eclipsesource.json.Json;
38 import org.junit.After; 37 import org.junit.After;
39 import org.junit.Before; 38 import org.junit.Before;
40 import org.junit.Test; 39 import org.junit.Test;
...@@ -49,6 +48,7 @@ import org.onosproject.vtnrsc.TenantId; ...@@ -49,6 +48,7 @@ import org.onosproject.vtnrsc.TenantId;
49 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; 48 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
50 import org.onosproject.vtnweb.web.SfcCodecContext; 49 import org.onosproject.vtnweb.web.SfcCodecContext;
51 50
51 +import com.eclipsesource.json.Json;
52 import com.eclipsesource.json.JsonObject; 52 import com.eclipsesource.json.JsonObject;
53 import com.google.common.collect.ImmutableList; 53 import com.google.common.collect.ImmutableList;
54 import com.google.common.collect.Lists; 54 import com.google.common.collect.Lists;
...@@ -122,6 +122,17 @@ public class PortPairGroupResourceTest extends VtnResourceTest { ...@@ -122,6 +122,17 @@ public class PortPairGroupResourceTest extends VtnResourceTest {
122 Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && 122 Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) &&
123 Objects.equals(this.tenantId, portPairGroup.tenantId()); 123 Objects.equals(this.tenantId, portPairGroup.tenantId());
124 } 124 }
125 +
126 + @Override
127 + public void addLoad(PortPairId portPairId) {
128 + // TODO Auto-generated method stub
129 + }
130 +
131 + @Override
132 + public int getLoad(PortPairId portPairId) {
133 + // TODO Auto-generated method stub
134 + return 0;
135 + }
125 } 136 }
126 137
127 /** 138 /**
......