Phaneendra Manda
Committed by Gerrit Code Review

[ONOS-4227] Port chain updated to store classifier and forwarder devices

Change-Id: Ibd772e8d524efbe8fc9a11e5091b5510a57e4f66
......@@ -26,6 +26,8 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.onosproject.net.DeviceId;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
......@@ -43,7 +45,8 @@ public final class DefaultPortChain implements PortChain {
private final Map<FiveTuple, LoadBalanceId> sfcLoadBalanceIdMap = new ConcurrentHashMap<>();
private final Map<LoadBalanceId, List<PortPairId>> sfcLoadBalancePathMap = new ConcurrentHashMap<>();
private final Map<LoadBalanceId, List<DeviceId>> sfcClassifiersMap = new ConcurrentHashMap<>();
private final Map<LoadBalanceId, List<DeviceId>> sfcForwardersMap = new ConcurrentHashMap<>();
/**
* Default constructor to create port chain.
*
......@@ -122,6 +125,40 @@ public final class DefaultPortChain implements PortChain {
}
@Override
public void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
this.sfcClassifiersMap.put(id, classifierList);
}
@Override
public void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
this.sfcForwardersMap.put(id, forwarderList);
}
@Override
public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
List<DeviceId> list = getSfcClassifiers(id);
list.removeAll(classifierList);
this.sfcForwardersMap.put(id, list);
}
@Override
public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
List<DeviceId> list = getSfcForwarders(id);
list.removeAll(forwarderList);
this.sfcForwardersMap.put(id, list);
}
@Override
public List<DeviceId> getSfcClassifiers(LoadBalanceId id) {
return ImmutableList.copyOf(this.sfcClassifiersMap.get(id));
}
@Override
public List<DeviceId> getSfcForwarders(LoadBalanceId id) {
return ImmutableList.copyOf(this.sfcForwardersMap.get(id));
}
@Override
public LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple) {
return this.sfcLoadBalanceIdMap.get(fiveTuple);
}
......@@ -132,6 +169,11 @@ public final class DefaultPortChain implements PortChain {
}
@Override
public Set<LoadBalanceId> getLoadBalancePathMapKeys() {
return ImmutableSet.copyOf(sfcLoadBalancePathMap.keySet());
}
@Override
public List<PortPairId> getLoadBalancePath(LoadBalanceId id) {
return ImmutableList.copyOf(this.sfcLoadBalancePathMap.get(id));
}
......
......@@ -19,6 +19,8 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import org.onosproject.net.DeviceId;
/**
* Abstraction of an entity providing Port Chain information.
* A Port Chain (Service Function Path) consists of
......@@ -82,7 +84,55 @@ public interface PortChain {
List<PortPairId> path);
/**
* Get the load balance id from five tuple.
* Adds sfc classifiers to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @param classifierList list of classifier devices
*/
void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList);
/**
* Adds sfc forwarders to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @param forwarderList list of forwarder devices
*/
void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList);
/**
* Removes sfc classifiers to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @param classifierList list of classifier devices
*/
void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList);
/**
* Removes sfc forwarders to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @param forwarderList list of forwarder devices
*/
void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList);
/**
* Returns sfc classifiers to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @return list of classifier devices
*/
List<DeviceId> getSfcClassifiers(LoadBalanceId id);
/**
* Returns sfc forwarders to the given load balance id for a port chain.
*
* @param id load balance path identifier
* @return list of forwarder devices
*/
List<DeviceId> getSfcForwarders(LoadBalanceId id);
/**
* Returns the load balance id from five tuple.
*
* @param fiveTuple five tuple from the packet
* @return load balance identifier for the given packet
......@@ -90,14 +140,21 @@ public interface PortChain {
LoadBalanceId getLoadBalanceId(FiveTuple fiveTuple);
/**
* Get the keys set from load balanced id map.
* Returns the keys set from load balance id map.
*
* @return set of five tuple info
*/
Set<FiveTuple> getLoadBalanceIdMapKeys();
/**
* Get the load balanced path from load balance Id.
* Returns the keys set from load balance path map.
*
* @return set of load balance id's
*/
Set<LoadBalanceId> getLoadBalancePathMapKeys();
/**
* Returns the load balanced path from load balance Id.
*
* @param id load balance id.
* @return path containing list of port pairs
......@@ -105,7 +162,7 @@ public interface PortChain {
List<PortPairId> getLoadBalancePath(LoadBalanceId id);
/**
* Get the load balanced path from five tuple.
* Returns the load balanced path from five tuple.
*
* @param fiveTuple five tuple from the packet
* @return path containing list of port pairs
......@@ -113,7 +170,7 @@ public interface PortChain {
List<PortPairId> getLoadBalancePath(FiveTuple fiveTuple);
/**
* Get the no of load balance paths created.
* Returns the no of load balance paths created.
*
* @return size of load balanced paths
*/
......
......@@ -26,6 +26,7 @@ import java.util.Set;
import org.junit.Test;
import org.onlab.packet.IPv4;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import com.google.common.collect.Lists;
......@@ -158,4 +159,40 @@ public class DefaultPortChainTest {
assertThat(keys.contains(fiveTuple1), is(true));
assertThat(path.contains(portPairId), is(true));
}
/**
* Verifies sfc classifiers.
*/
@Test
public void testSfcClassifier() {
final PortChain portChain = getPortChain();
final LoadBalanceId id1 = LoadBalanceId.of((byte) 1);
List<DeviceId> classifierList = Lists.newArrayList();
DeviceId deviceId1 = DeviceId.deviceId("of:000000001");
classifierList.add(deviceId1);
DeviceId deviceId2 = DeviceId.deviceId("of:000000002");
classifierList.add(deviceId2);
portChain.addSfcClassifiers(id1, classifierList);
assertThat(portChain.getSfcClassifiers(id1).contains(deviceId1), is(true));
}
/**
* Verifies sfc forwarders.
*/
@Test
public void testSfcForwarder() {
final PortChain portChain = getPortChain();
final LoadBalanceId id1 = LoadBalanceId.of((byte) 1);
List<DeviceId> forwarderList = Lists.newArrayList();
DeviceId deviceId1 = DeviceId.deviceId("of:000000001");
forwarderList.add(deviceId1);
DeviceId deviceId2 = DeviceId.deviceId("of:000000002");
forwarderList.add(deviceId2);
portChain.addSfcForwarders(id1, forwarderList);
assertThat(portChain.getSfcForwarders(id1).contains(deviceId1), is(true));
}
}
......
......@@ -26,6 +26,7 @@ import org.onlab.osgi.ServiceDirectory;
import org.onlab.osgi.TestServiceDirectory;
import org.onlab.rest.BaseResource;
import org.onosproject.codec.CodecService;
import org.onosproject.net.DeviceId;
import org.onosproject.vtnrsc.FiveTuple;
import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.vtnrsc.LoadBalanceId;
......@@ -172,6 +173,37 @@ public class PortChainResourceTest extends VtnResourceTest {
public int getLoadBalancePathSize() {
return 0;
}
@Override
public void addSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
}
@Override
public void addSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
}
@Override
public void removeSfcClassifiers(LoadBalanceId id, List<DeviceId> classifierList) {
}
@Override
public void removeSfcForwarders(LoadBalanceId id, List<DeviceId> forwarderList) {
}
@Override
public List<DeviceId> getSfcClassifiers(LoadBalanceId id) {
return null;
}
@Override
public List<DeviceId> getSfcForwarders(LoadBalanceId id) {
return null;
}
@Override
public Set<LoadBalanceId> getLoadBalancePathMapKeys() {
return null;
}
}
/**
......