Committed by
Gerrit Code Review
[ONOS-4227] Port chain updated to store classifier and forwarder devices
Change-Id: Ibd772e8d524efbe8fc9a11e5091b5510a57e4f66
Showing
4 changed files
with
174 additions
and
6 deletions
| ... | @@ -26,6 +26,8 @@ import java.util.Optional; | ... | @@ -26,6 +26,8 @@ import java.util.Optional; |
| 26 | import java.util.Set; | 26 | import java.util.Set; |
| 27 | import java.util.concurrent.ConcurrentHashMap; | 27 | import java.util.concurrent.ConcurrentHashMap; |
| 28 | 28 | ||
| 29 | +import org.onosproject.net.DeviceId; | ||
| 30 | + | ||
| 29 | import com.google.common.collect.ImmutableList; | 31 | import com.google.common.collect.ImmutableList; |
| 30 | import com.google.common.collect.ImmutableSet; | 32 | import com.google.common.collect.ImmutableSet; |
| 31 | 33 | ||
| ... | @@ -43,7 +45,8 @@ public final class DefaultPortChain implements PortChain { | ... | @@ -43,7 +45,8 @@ public final class DefaultPortChain implements PortChain { |
| 43 | 45 | ||
| 44 | private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>(); | 46 | private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>(); |
| 45 | private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>(); | 47 | private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>(); |
| 46 | - | 48 | + private final Map<LoadBalanceId, List<DeviceId>> sfcClassifiersMap = new ConcurrentHashMap<>(); |
| 49 | + private final Map<LoadBalanceId, List<DeviceId>> sfcForwardersMap = new ConcurrentHashMap<>(); | ||
| 47 | /** | 50 | /** |
| 48 | * Default constructor to create port chain. | 51 | * Default constructor to create port chain. |
| 49 | * | 52 | * |
| ... | @@ -122,6 +125,40 @@ public final class DefaultPortChain implements PortChain { | ... | @@ -122,6 +125,40 @@ public final class DefaultPortChain implements PortChain { |
| 122 | } | 125 | } |
| 123 | 126 | ||
| 124 | @Override | 127 | @Override |
| 128 | + public void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) { | ||
| 129 | + this.sfcClassifiersMap.put(id, classifierList); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) { | ||
| 134 | + this.sfcForwardersMap.put(id, forwarderList); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) { | ||
| 139 | + List<DeviceId> list = getSfcClassifiers(id); | ||
| 140 | + list.removeAll(classifierList); | ||
| 141 | + this.sfcForwardersMap.put(id, list); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) { | ||
| 146 | + List<DeviceId> list = getSfcForwarders(id); | ||
| 147 | + list.removeAll(forwarderList); | ||
| 148 | + this.sfcForwardersMap.put(id, list); | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + @Override | ||
| 152 | + public List<DeviceId> getSfcClassifiers(LoadBalanceId id) { | ||
| 153 | + return ImmutableList.copyOf(this.sfcClassifiersMap.get(id)); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + @Override | ||
| 157 | + public List<DeviceId> getSfcForwarders(LoadBalanceId id) { | ||
| 158 | + return ImmutableList.copyOf(this.sfcForwardersMap.get(id)); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + @Override | ||
| 125 | public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) { | 162 | public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) { |
| 126 | return this.sfcLoadBalanceIdMap.get(fiveTuple); | 163 | return this.sfcLoadBalanceIdMap.get(fiveTuple); |
| 127 | } | 164 | } |
| ... | @@ -132,6 +169,11 @@ public final class DefaultPortChain implements PortChain { | ... | @@ -132,6 +169,11 @@ public final class DefaultPortChain implements PortChain { |
| 132 | } | 169 | } |
| 133 | 170 | ||
| 134 | @Override | 171 | @Override |
| 172 | + public Set<LoadBalanceId> getLoadBalancePathMapKeys() { | ||
| 173 | + return ImmutableSet.copyOf(sfcLoadBalancePathMap.keySet()); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + @Override | ||
| 135 | public List<PortPairId> getLoadBalancePath(LoadBalanceId id) { | 177 | public List<PortPairId> getLoadBalancePath(LoadBalanceId id) { |
| 136 | return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(id)); | 178 | return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(id)); |
| 137 | } | 179 | } | ... | ... |
| ... | @@ -19,6 +19,8 @@ import java.util.List; | ... | @@ -19,6 +19,8 @@ import java.util.List; |
| 19 | import java.util.Optional; | 19 | import java.util.Optional; |
| 20 | import java.util.Set; | 20 | import java.util.Set; |
| 21 | 21 | ||
| 22 | +import org.onosproject.net.DeviceId; | ||
| 23 | + | ||
| 22 | /** | 24 | /** |
| 23 | * Abstraction of an entity providing Port Chain information. | 25 | * Abstraction of an entity providing Port Chain information. |
| 24 | * A Port Chain (Service Function Path) consists of | 26 | * A Port Chain (Service Function Path) consists of |
| ... | @@ -82,7 +84,55 @@ public interface PortChain { | ... | @@ -82,7 +84,55 @@ public interface PortChain { |
| 82 | List<PortPairId> path); | 84 | List<PortPairId> path); |
| 83 | 85 | ||
| 84 | /** | 86 | /** |
| 85 | - * Get the load balance id from five tuple. | 87 | + * Adds sfc classifiers to the given load balance id for a port chain. |
| 88 | + * | ||
| 89 | + * @param id load balance path identifier | ||
| 90 | + * @param classifierList list of classifier devices | ||
| 91 | + */ | ||
| 92 | + void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList); | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * Adds sfc forwarders to the given load balance id for a port chain. | ||
| 96 | + * | ||
| 97 | + * @param id load balance path identifier | ||
| 98 | + * @param forwarderList list of forwarder devices | ||
| 99 | + */ | ||
| 100 | + void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList); | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Removes sfc classifiers to the given load balance id for a port chain. | ||
| 104 | + * | ||
| 105 | + * @param id load balance path identifier | ||
| 106 | + * @param classifierList list of classifier devices | ||
| 107 | + */ | ||
| 108 | + void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList); | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * Removes sfc forwarders to the given load balance id for a port chain. | ||
| 112 | + * | ||
| 113 | + * @param id load balance path identifier | ||
| 114 | + * @param forwarderList list of forwarder devices | ||
| 115 | + */ | ||
| 116 | + void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList); | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Returns sfc classifiers to the given load balance id for a port chain. | ||
| 120 | + * | ||
| 121 | + * @param id load balance path identifier | ||
| 122 | + * @return list of classifier devices | ||
| 123 | + */ | ||
| 124 | + List<DeviceId> getSfcClassifiers(LoadBalanceId id); | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * Returns sfc forwarders to the given load balance id for a port chain. | ||
| 128 | + * | ||
| 129 | + * @param id load balance path identifier | ||
| 130 | + * @return list of forwarder devices | ||
| 131 | + */ | ||
| 132 | + List<DeviceId> getSfcForwarders(LoadBalanceId id); | ||
| 133 | + | ||
| 134 | + /** | ||
| 135 | + * Returns the load balance id from five tuple. | ||
| 86 | * | 136 | * |
| 87 | * @param fiveTuple five tuple from the packet | 137 | * @param fiveTuple five tuple from the packet |
| 88 | * @return load balance identifier for the given packet | 138 | * @return load balance identifier for the given packet |
| ... | @@ -90,14 +140,21 @@ public interface PortChain { | ... | @@ -90,14 +140,21 @@ public interface PortChain { |
| 90 | LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple); | 140 | LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple); |
| 91 | 141 | ||
| 92 | /** | 142 | /** |
| 93 | - * Get the keys set from load balanced id map. | 143 | + * Returns the keys set from load balance id map. |
| 94 | * | 144 | * |
| 95 | * @return set of five tuple info | 145 | * @return set of five tuple info |
| 96 | */ | 146 | */ |
| 97 | Set<FiveTuple> getLoadBalanceIdMapKeys(); | 147 | Set<FiveTuple> getLoadBalanceIdMapKeys(); |
| 98 | 148 | ||
| 99 | /** | 149 | /** |
| 100 | - * Get the load balanced path from load balance Id. | 150 | + * Returns the keys set from load balance path map. |
| 151 | + * | ||
| 152 | + * @return set of load balance id's | ||
| 153 | + */ | ||
| 154 | + Set<LoadBalanceId> getLoadBalancePathMapKeys(); | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * Returns the load balanced path from load balance Id. | ||
| 101 | * | 158 | * |
| 102 | * @param id load balance id. | 159 | * @param id load balance id. |
| 103 | * @return path containing list of port pairs | 160 | * @return path containing list of port pairs |
| ... | @@ -105,7 +162,7 @@ public interface PortChain { | ... | @@ -105,7 +162,7 @@ public interface PortChain { |
| 105 | List<PortPairId> getLoadBalancePath(LoadBalanceId id); | 162 | List<PortPairId> getLoadBalancePath(LoadBalanceId id); |
| 106 | 163 | ||
| 107 | /** | 164 | /** |
| 108 | - * Get the load balanced path from five tuple. | 165 | + * Returns the load balanced path from five tuple. |
| 109 | * | 166 | * |
| 110 | * @param fiveTuple five tuple from the packet | 167 | * @param fiveTuple five tuple from the packet |
| 111 | * @return path containing list of port pairs | 168 | * @return path containing list of port pairs |
| ... | @@ -113,7 +170,7 @@ public interface PortChain { | ... | @@ -113,7 +170,7 @@ public interface PortChain { |
| 113 | List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple); | 170 | List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple); |
| 114 | 171 | ||
| 115 | /** | 172 | /** |
| 116 | - * Get the no of load balance paths created. | 173 | + * Returns the no of load balance paths created. |
| 117 | * | 174 | * |
| 118 | * @return size of load balanced paths | 175 | * @return size of load balanced paths |
| 119 | */ | 176 | */ | ... | ... |
| ... | @@ -26,6 +26,7 @@ import java.util.Set; | ... | @@ -26,6 +26,7 @@ import java.util.Set; |
| 26 | import org.junit.Test; | 26 | import org.junit.Test; |
| 27 | import org.onlab.packet.IPv4; | 27 | import org.onlab.packet.IPv4; |
| 28 | import org.onlab.packet.IpAddress; | 28 | import org.onlab.packet.IpAddress; |
| 29 | +import org.onosproject.net.DeviceId; | ||
| 29 | import org.onosproject.net.PortNumber; | 30 | import org.onosproject.net.PortNumber; |
| 30 | 31 | ||
| 31 | import com.google.common.collect.Lists; | 32 | import com.google.common.collect.Lists; |
| ... | @@ -158,4 +159,40 @@ public class DefaultPortChainTest { | ... | @@ -158,4 +159,40 @@ public class DefaultPortChainTest { |
| 158 | assertThat(keys.contains(fiveTuple1), is(true)); | 159 | assertThat(keys.contains(fiveTuple1), is(true)); |
| 159 | assertThat(path.contains(portPairId), is(true)); | 160 | assertThat(path.contains(portPairId), is(true)); |
| 160 | } | 161 | } |
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * Verifies sfc classifiers. | ||
| 165 | + */ | ||
| 166 | + @Test | ||
| 167 | + public void testSfcClassifier() { | ||
| 168 | + final PortChain portChain = getPortChain(); | ||
| 169 | + | ||
| 170 | + final LoadBalanceId id1 = LoadBalanceId.of((byte) 1); | ||
| 171 | + List<DeviceId> classifierList = Lists.newArrayList(); | ||
| 172 | + DeviceId deviceId1 = DeviceId.deviceId("of:000000001"); | ||
| 173 | + classifierList.add(deviceId1); | ||
| 174 | + DeviceId deviceId2 = DeviceId.deviceId("of:000000002"); | ||
| 175 | + classifierList.add(deviceId2); | ||
| 176 | + portChain.addSfcClassifiers(id1, classifierList); | ||
| 177 | + | ||
| 178 | + assertThat(portChain.getSfcClassifiers(id1).contains(deviceId1), is(true)); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + /** | ||
| 182 | + * Verifies sfc forwarders. | ||
| 183 | + */ | ||
| 184 | + @Test | ||
| 185 | + public void testSfcForwarder() { | ||
| 186 | + final PortChain portChain = getPortChain(); | ||
| 187 | + | ||
| 188 | + final LoadBalanceId id1 = LoadBalanceId.of((byte) 1); | ||
| 189 | + List<DeviceId> forwarderList = Lists.newArrayList(); | ||
| 190 | + DeviceId deviceId1 = DeviceId.deviceId("of:000000001"); | ||
| 191 | + forwarderList.add(deviceId1); | ||
| 192 | + DeviceId deviceId2 = DeviceId.deviceId("of:000000002"); | ||
| 193 | + forwarderList.add(deviceId2); | ||
| 194 | + portChain.addSfcForwarders(id1, forwarderList); | ||
| 195 | + | ||
| 196 | + assertThat(portChain.getSfcForwarders(id1).contains(deviceId1), is(true)); | ||
| 197 | + } | ||
| 161 | } | 198 | } | ... | ... |
| ... | @@ -26,6 +26,7 @@ import org.onlab.osgi.ServiceDirectory; | ... | @@ -26,6 +26,7 @@ import org.onlab.osgi.ServiceDirectory; |
| 26 | import org.onlab.osgi.TestServiceDirectory; | 26 | import org.onlab.osgi.TestServiceDirectory; |
| 27 | import org.onlab.rest.BaseResource; | 27 | import org.onlab.rest.BaseResource; |
| 28 | import org.onosproject.codec.CodecService; | 28 | import org.onosproject.codec.CodecService; |
| 29 | +import org.onosproject.net.DeviceId; | ||
| 29 | import org.onosproject.vtnrsc.FiveTuple; | 30 | import org.onosproject.vtnrsc.FiveTuple; |
| 30 | import org.onosproject.vtnrsc.FlowClassifierId; | 31 | import org.onosproject.vtnrsc.FlowClassifierId; |
| 31 | import org.onosproject.vtnrsc.LoadBalanceId; | 32 | import org.onosproject.vtnrsc.LoadBalanceId; |
| ... | @@ -172,6 +173,37 @@ public class PortChainResourceTest extends VtnResourceTest { | ... | @@ -172,6 +173,37 @@ public class PortChainResourceTest extends VtnResourceTest { |
| 172 | public int getLoadBalancePathSize() { | 173 | public int getLoadBalancePathSize() { |
| 173 | return 0; | 174 | return 0; |
| 174 | } | 175 | } |
| 176 | + | ||
| 177 | + @Override | ||
| 178 | + public void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) { | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + @Override | ||
| 182 | + public void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) { | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + @Override | ||
| 186 | + public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) { | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + @Override | ||
| 190 | + public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) { | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + @Override | ||
| 194 | + public List<DeviceId> getSfcClassifiers(LoadBalanceId id) { | ||
| 195 | + return null; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + @Override | ||
| 199 | + public List<DeviceId> getSfcForwarders(LoadBalanceId id) { | ||
| 200 | + return null; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + @Override | ||
| 204 | + public Set<LoadBalanceId> getLoadBalancePathMapKeys() { | ||
| 205 | + return null; | ||
| 206 | + } | ||
| 175 | } | 207 | } |
| 176 | 208 | ||
| 177 | /** | 209 | /** | ... | ... |
-
Please register or login to post a comment