Search in sources :

Example 6 with Network

use of org.btrplace.model.view.network.Network 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 7 with Network

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

the class NetworkFuzzer method decorate.

@Override
public void decorate(ReconfigurationPlan p) {
    Network net = new Network();
    Mapping m = p.getOrigin().getMapping();
    Switch s = net.newSwitch(1000 * (1 + rnd.nextInt(40)));
    for (Node n : m.getAllNodes()) {
        int bw = 1000 * (1 + rnd.nextInt(40));
        net.connect(bw, s, n);
    }
}
Also used : Switch(org.btrplace.model.view.network.Switch) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping)

Example 8 with Network

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

the class NetworkConverter method fromJSON.

@Override
public Network fromJSON(Model mo, JSONObject o) throws JSONConverterException {
    checkKeys(o, IDENTIFIER, "switches", "links", "routing");
    String id = requiredString(o, ModelViewConverter.IDENTIFIER);
    if (!id.equals(getJSONId())) {
        return null;
    }
    Network net = new Network();
    switchesFromJSON(net, (JSONArray) o.get("switches"));
    linksFromJSON(mo, net, (JSONArray) o.get("links"));
    mo.attach(net);
    net.setRouting(routingFromJSON(mo, (JSONObject) o.get("routing")));
    mo.detach(net);
    return net;
}
Also used : JSONObject(net.minidev.json.JSONObject) Network(org.btrplace.model.view.network.Network) JSONs.requiredString(org.btrplace.json.JSONs.requiredString)

Example 9 with Network

use of org.btrplace.model.view.network.Network 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)

Example 10 with Network

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

the class NetworkConverterTest method switchesAndLinksTest.

@Test
public void switchesAndLinksTest() throws JSONConverterException {
    Model mo = new DefaultModel();
    Network net = new Network();
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    net.connect(1000, s, n1, n2);
    mo.attach(net);
    ModelConverter mc = new ModelConverter();
    JSONObject jo = mc.toJSON(mo);
    System.err.println(jo);
    Model mo2 = mc.fromJSON(jo);
    Network net2 = Network.get(mo2);
    Assert.assertTrue(net.getSwitches().equals(net2.getSwitches()));
    Assert.assertTrue(net.getLinks().equals(net2.getLinks()));
    Assert.assertTrue(net.getConnectedNodes().equals(net2.getConnectedNodes()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) JSONObject(net.minidev.json.JSONObject) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ModelConverter(org.btrplace.json.model.ModelConverter) Test(org.testng.annotations.Test)

Aggregations

Network (org.btrplace.model.view.network.Network)22 Switch (org.btrplace.model.view.network.Switch)19 SatConstraint (org.btrplace.model.constraint.SatConstraint)14 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)14 ArrayList (java.util.ArrayList)13 ShareableResource (org.btrplace.model.view.ShareableResource)13 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)13 Test (org.testng.annotations.Test)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)11 MigrateVM (org.btrplace.plan.event.MigrateVM)9 Fence (org.btrplace.model.constraint.Fence)7 SchedulerException (org.btrplace.scheduler.SchedulerException)7 Model (org.btrplace.model.Model)5 Node (org.btrplace.model.Node)5 JSONObject (net.minidev.json.JSONObject)4 DefaultModel (org.btrplace.model.DefaultModel)4 Link (org.btrplace.model.view.network.Link)4 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)4 LinkedHashMap (java.util.LinkedHashMap)3