Merge pull request #75 from Echtzeitsysteme/feature/gips-algos-vnet-set-check

GIPS VNE algorithms: check if the model is conform to the given set of virtual networks
This commit is contained in:
Maximilian Kratz 2024-06-06 10:45:40 +02:00 committed by GitHub
commit fd08fc97b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 300 additions and 3 deletions

View file

@ -46,7 +46,7 @@ public class VneGipsAlgorithmRejectionTest extends AAlgorithmTest {
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in RSLANG
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsAlgorithm.prepare(sNet, vNets);
}

View file

@ -36,7 +36,7 @@ public class VneGipsAlgorithmSimpleTest extends AAlgorithmTest {
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in RSLANG
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsAlgorithm.prepare(sNet, vNets);
}

View file

@ -0,0 +1,82 @@
package test.algorithms.gips;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import algorithms.AlgorithmConfig;
import algorithms.AlgorithmConfig.Objective;
import algorithms.gips.VneGipsAlgorithm;
import model.SubstrateNetwork;
import model.VirtualNetwork;
import test.algorithms.generic.AAlgorithmTest;
/**
* Test class for the VNE GIPS algorithm implementation to check its rejection
* of an invalid model state.
*
* @author Maximilian Kratz {@literal <maximilian.kratz@es.tu-darmstadt.de>}
*/
public class VneGipsAlgorithmVnetSetExceptionTest extends AAlgorithmTest {
/**
* Substrate network.
*/
SubstrateNetwork sNet;
/**
* Virtual network.
*/
VirtualNetwork vNet;
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsAlgorithm.prepare(sNet, vNets);
}
@AfterEach
public void resetAlgo() {
facade.resetAll();
if (algo != null) {
((VneGipsAlgorithm) algo).dispose();
}
}
//
// Tests
//
// No virtual elements
@Test
public void testTwoVirtualNetworksEmbedding() {
facade.addServerToNetwork("ssrv1", "sub", 1, 1, 1, 1);
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
// Second virtual network should trigger an exception
facade.addNetworkToRoot("vnet2", true);
checkAndValidate();
}
//
// Utility methods
//
private void checkAndValidate() {
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
assertThrows(IllegalStateException.class, () -> {
initAlgo(sNet, Set.of(vNet));
});
}
}

View file

@ -22,7 +22,7 @@ public class VneGipsMigrationAlgorithmSimpleTest extends VneGipsAlgorithmSimpleT
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in RSLANG
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsMigrationAlgorithm.prepare(sNet, vNets);
}

View file

@ -0,0 +1,82 @@
package test.algorithms.gips.migration;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import algorithms.AlgorithmConfig;
import algorithms.AlgorithmConfig.Objective;
import algorithms.gips.VneGipsMigrationAlgorithm;
import model.SubstrateNetwork;
import model.VirtualNetwork;
import test.algorithms.generic.AAlgorithmTest;
/**
* Test class for the VNE GIPS migration algorithm implementation to check its
* rejection of an invalid model state.
*
* @author Maximilian Kratz {@literal <maximilian.kratz@es.tu-darmstadt.de>}
*/
public class VneGipsMigrationAlgorithmVnetSetExceptionTest extends AAlgorithmTest {
/**
* Substrate network.
*/
SubstrateNetwork sNet;
/**
* Virtual network.
*/
VirtualNetwork vNet;
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsMigrationAlgorithm.prepare(sNet, vNets);
}
@AfterEach
public void resetAlgo() {
facade.resetAll();
if (algo != null) {
((VneGipsMigrationAlgorithm) algo).dispose();
}
}
//
// Tests
//
// No virtual elements
@Test
public void testTwoVirtualNetworksEmbedding() {
facade.addServerToNetwork("ssrv1", "sub", 1, 1, 1, 1);
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
// Second virtual network should trigger an exception
facade.addNetworkToRoot("vnet2", true);
checkAndValidate();
}
//
// Utility methods
//
private void checkAndValidate() {
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
assertThrows(IllegalStateException.class, () -> {
initAlgo(sNet, Set.of(vNet));
});
}
}

View file

@ -0,0 +1,82 @@
package test.algorithms.gips.seq;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import algorithms.AlgorithmConfig;
import algorithms.AlgorithmConfig.Objective;
import algorithms.gips.VneGipsSeqAlgorithm;
import model.SubstrateNetwork;
import model.VirtualNetwork;
import test.algorithms.generic.AAlgorithmTest;
/**
* Test class for the VNE GIPS sequence algorithm implementation to check its
* rejection of an invalid model state.
*
* @author Maximilian Kratz {@literal <maximilian.kratz@es.tu-darmstadt.de>}
*/
public class VneGipsSeqAlgorithmVnetSetExceptionTest extends AAlgorithmTest {
/**
* Substrate network.
*/
SubstrateNetwork sNet;
/**
* Virtual network.
*/
VirtualNetwork vNet;
@Override
public void initAlgo(final SubstrateNetwork sNet, final Set<VirtualNetwork> vNets) {
// The algorithm is only able to use the total communication objective C because
// it is hard-coded in GIPSL
AlgorithmConfig.obj = Objective.TOTAL_COMMUNICATION_OBJECTIVE_C;
algo = VneGipsSeqAlgorithm.prepare(sNet, vNets);
}
@AfterEach
public void resetAlgo() {
facade.resetAll();
if (algo != null) {
((VneGipsSeqAlgorithm) algo).dispose();
}
}
//
// Tests
//
// No virtual elements
@Test
public void testTwoVirtualNetworksEmbedding() {
facade.addServerToNetwork("ssrv1", "sub", 1, 1, 1, 1);
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
// Second virtual network should trigger an exception
facade.addNetworkToRoot("vnet2", true);
checkAndValidate();
}
//
// Utility methods
//
private void checkAndValidate() {
sNet = (SubstrateNetwork) facade.getNetworkById("sub");
vNet = (VirtualNetwork) facade.getNetworkById("virt");
assertThrows(IllegalStateException.class, () -> {
initAlgo(sNet, Set.of(vNet));
});
}
}

View file

@ -69,6 +69,8 @@ public class VneGipsAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsAlgorithm(sNet, vNets);
}

View file

@ -0,0 +1,45 @@
package algorithms.gips;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import facade.ModelFacade;
import model.Network;
import model.VirtualNetwork;
public class VneGipsAlgorithmUtils {
/**
* Checks if the given set of virtual networks exactly match the non-embedded
* virtual networks within the model.
*
* @param vNets Set of virtual networks to check for.
*/
protected static void checkGivenVnets(final Set<VirtualNetwork> vNets) {
if (vNets == null) {
throw new IllegalArgumentException("Virtual network set was null.");
}
final Collection<Network> modelNets = ModelFacade.getInstance().getAllNetworks();
final Set<VirtualNetwork> modelVnets = new HashSet<VirtualNetwork>();
for (final Network n : modelNets) {
if (n instanceof VirtualNetwork vnet) {
if (vnet.getHost() == null && vnet.getHostServer() == null) {
modelVnets.add(vnet);
}
}
}
if (vNets.size() != modelVnets.size()) {
throw new IllegalStateException("Number of given virtual networks does not match the number of "
+ "non-embedded virtual networks existing in the model.");
}
if (!vNets.containsAll(modelVnets) || !modelVnets.containsAll(vNets)) {
throw new IllegalStateException("Given set of virtual network does not match the set of non-embedded"
+ " virtual networks existing in the model.");
}
}
}

View file

@ -84,6 +84,8 @@ public class VneGipsMigrationAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsMigrationAlgorithm(sNet, vNets);
}

View file

@ -69,6 +69,8 @@ public class VneGipsSeqAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsSeqAlgorithm(sNet, vNets);
}