Search in sources :

Example 1 with Link

use of org.btrplace.model.view.network.Link in project scheduler by btrplace.

the class NetworkTest method defaultTest.

/**
 * Test the instantiation and the creation of the objects using the default routing implementation.
 */
@Test
public void defaultTest() {
    Model mo = new DefaultModel();
    Network net = new Network();
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    net.connect(2000, s, n1, n2);
    Assert.assertNull(Network.get(mo));
    mo.attach(net);
    Assert.assertEquals(Network.get(mo), net);
    Assert.assertTrue(net.getSwitches().size() == 1);
    Assert.assertEquals(net.getSwitches().get(0), s);
    Assert.assertTrue(s.getCapacity() == 1000);
    Assert.assertTrue(net.getLinks().size() == 2);
    Assert.assertTrue(net.getLinks().size() == 2);
    for (Link l : net.getLinks()) {
        Assert.assertTrue(l.getCapacity() == 2000);
        Assert.assertTrue(l.getSwitch().equals(s) || l.getElement() instanceof Switch);
    }
    Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Link(org.btrplace.model.view.network.Link) Test(org.testng.annotations.Test)

Example 2 with Link

use of org.btrplace.model.view.network.Link in project scheduler by btrplace.

the class NetworkTest method staticRoutingTest.

/**
 * Test the static routing implementation.
 */
@Test
public void staticRoutingTest() {
    Model mo = new DefaultModel();
    Network net = new Network(new StaticRouting());
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    net.connect(2000, s, n1, n2);
    Map<Link, Boolean> route = new LinkedHashMap<>();
    route.put(net.getConnectedLinks(n1).get(0), true);
    route.put(net.getConnectedLinks(n2).get(0), false);
    ((StaticRouting) net.getRouting()).setStaticRoute(new StaticRouting.NodesMap(n1, n2), route);
    mo.attach(net);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) StaticRouting(org.btrplace.model.view.network.StaticRouting) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Link(org.btrplace.model.view.network.Link) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 3 with Link

use of org.btrplace.model.view.network.Link in project scheduler by btrplace.

the class CNetwork method addLinkConstraints.

/**
 * Add the cumulative constraints for each link.
 *
 * Full-duplex links are considered, two cumulative constraints are defined per link by looking at
 * the migration direction for each link on the migration path.
 *
 * @param rp the reconfiguration problem
 */
private void addLinkConstraints(ReconfigurationProblem rp) {
    // Links limitation
    List<Task> tasksListUp = new ArrayList<>();
    List<Task> tasksListDown = new ArrayList<>();
    List<IntVar> heightsListUp = new ArrayList<>();
    List<IntVar> heightsListDown = new ArrayList<>();
    for (Link l : net.getLinks()) {
        for (VM vm : rp.getVMs()) {
            VMTransition a = rp.getVMAction(vm);
            if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
                Node src = source.getMapping().getVMLocation(vm);
                Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                List<Link> path = net.getRouting().getPath(src, dst);
                // Check first if the link is on migration path
                if (path.contains(l)) {
                    // Get link direction
                    LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
                    // UpLink
                    if (linkDirection == LinkDirection.UPLINK) {
                        tasksListUp.add(((RelocatableVM) a).getMigrationTask());
                        heightsListUp.add(((RelocatableVM) a).getBandwidth());
                    } else // DownLink
                    {
                        tasksListDown.add(((RelocatableVM) a).getMigrationTask());
                        heightsListDown.add(((RelocatableVM) a).getBandwidth());
                    }
                }
            }
        }
        if (!tasksListUp.isEmpty()) {
            // Post the cumulative constraint for the current UpLink
            csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
            tasksListUp.clear();
            heightsListUp.clear();
        }
        if (!tasksListDown.isEmpty()) {
            // Post the cumulative constraint for the current DownLink
            csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
            tasksListDown.clear();
            heightsListDown.clear();
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) LinkDirection(org.btrplace.model.view.network.Routing.LinkDirection) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) Link(org.btrplace.model.view.network.Link)

Example 4 with Link

use of org.btrplace.model.view.network.Link in project scheduler by btrplace.

the class StaticRoutingConverter method toJSON.

/**
 * Convert a Routing implementation into a JSON object
 *
 * @param routing the routing implementation to convert
 * @return the JSON formatted routing object
 */
@Override
public JSONObject toJSON(StaticRouting routing) {
    JSONObject o = new JSONObject();
    o.put("type", getJSONId());
    JSONArray a = new JSONArray();
    Map<StaticRouting.NodesMap, Map<Link, Boolean>> routes = routing.getStaticRoutes();
    for (Map.Entry<StaticRouting.NodesMap, Map<Link, Boolean>> e : routes.entrySet()) {
        StaticRouting.NodesMap nm = e.getKey();
        JSONObject ao = new JSONObject();
        ao.put("nodes_map", nodesMapToJSON(nm));
        JSONArray links = new JSONArray();
        Map<Link, Boolean> v = e.getValue();
        for (Link l : v.keySet()) {
            JSONObject lo = new JSONObject();
            lo.put("link", l.id());
            lo.put("direction", routes.get(nm).get(l).toString());
            links.add(lo);
        }
        ao.put("links", links);
        a.add(ao);
    }
    o.put(ROUTES_LABEL, a);
    return o;
}
Also used : JSONObject(net.minidev.json.JSONObject) StaticRouting(org.btrplace.model.view.network.StaticRouting) JSONArray(net.minidev.json.JSONArray) LinkedHashMap(java.util.LinkedHashMap) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) Map(java.util.Map) Link(org.btrplace.model.view.network.Link)

Example 5 with Link

use of org.btrplace.model.view.network.Link in project scheduler by btrplace.

the class StaticRoutingConverter method fromJSON.

@Override
public StaticRouting fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    Network v = Network.get(mo);
    TIntObjectMap<Link> idToLink = new TIntObjectHashMap<>();
    for (Link l : v.getLinks()) {
        idToLink.put(l.id(), l);
    }
    StaticRouting r = new StaticRouting();
    checkKeys(o, ROUTES_LABEL);
    JSONArray a = (JSONArray) o.get(ROUTES_LABEL);
    for (Object ao : a) {
        StaticRouting.NodesMap nm = nodesMapFromJSON(mo, (JSONObject) ((JSONObject) ao).get("nodes_map"));
        Map<Link, Boolean> links = new LinkedHashMap<>();
        JSONArray aoa = (JSONArray) ((JSONObject) ao).get("links");
        for (Object aoao : aoa) {
            links.put(idToLink.get(requiredInt((JSONObject) aoao, "link")), Boolean.valueOf(requiredString((JSONObject) aoao, "direction")));
        }
        r.setStaticRoute(nm, links);
    }
    return r;
}
Also used : JSONObject(net.minidev.json.JSONObject) StaticRouting(org.btrplace.model.view.network.StaticRouting) Network(org.btrplace.model.view.network.Network) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) Link(org.btrplace.model.view.network.Link) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Link (org.btrplace.model.view.network.Link)6 LinkedHashMap (java.util.LinkedHashMap)4 Node (org.btrplace.model.Node)4 Network (org.btrplace.model.view.network.Network)4 StaticRouting (org.btrplace.model.view.network.StaticRouting)4 JSONObject (net.minidev.json.JSONObject)3 DefaultModel (org.btrplace.model.DefaultModel)3 Model (org.btrplace.model.Model)3 Switch (org.btrplace.model.view.network.Switch)3 Test (org.testng.annotations.Test)3 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)2 Map (java.util.Map)2 JSONArray (net.minidev.json.JSONArray)2 TIntObjectMap (gnu.trove.map.TIntObjectMap)1 ArrayList (java.util.ArrayList)1 ModelConverter (org.btrplace.json.model.ModelConverter)1 VM (org.btrplace.model.VM)1 LinkDirection (org.btrplace.model.view.network.Routing.LinkDirection)1 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)1 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)1