package be.iminds.ilabt.jfed.rspec.rspec_source;

import be.iminds.ilabt.jfed.rspec.model.*;
import be.iminds.ilabt.jfed.rspec.model.impl.BasicRspecFactory;
import be.iminds.ilabt.jfed.rspec.parser.RspecParseException;
import be.iminds.ilabt.jfed.rspec.parser.StaxRspecParser;
import be.iminds.ilabt.jfed.rspec.parser.TestRspecsLibrary;
import be.iminds.ilabt.jfed.util.GeniUrn;
import org.testng.annotations.Test;

import java.util.Collections;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.testng.Assert.*;

/**
 * RspecSourceTest: Tests of RspecSource interface, and specific implementations of it
 */
public class RspecSourceTest {
    protected final RspecFactory rspecFactory;

    public RspecSourceTest() {
        this(BasicRspecFactory.getInstance());
    }

    public RspecSourceTest(RspecFactory rspecFactory) {
        this.rspecFactory = rspecFactory;
    }

    @Test
    public void testMultiSitePleSpecialCaseFromString() {
        StringRspec s = new StringRspec(multiSitePleRspec);
        RequestRspecSource requestRspecSource = new RequestRspecSource(s);

        String pleRspecRequestStr = requestRspecSource.getRspecXmlString(ModelRspec.RequestRspecSpecialCases.PLE);

        StringRspec resultStringRspec = new StringRspec(pleRspecRequestStr);
        List<String> compMan = resultStringRspec.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan + "  rspec=" + pleRspecRequestStr);
        assertTrue(compMan.contains("urn:publicid:IDN+ple:ibbtple+authority+cm"));

        RequestRspecSource newRequestRspecSouce = new RequestRspecSource(resultStringRspec);
        assertEquals(newRequestRspecSouce.getModelRspec().getNodes().size(), 2);
        assertEquals(newRequestRspecSouce.getModelRspec().getLinks().size(), 1);
    }

    @Test
    public void testMultiSitePleSpecialCaseFromModel() throws RspecParseException {
        ModelRspec m = new StaxRspecParser(multiSitePleRspec, rspecFactory).call();
        RequestRspecSource requestRspecSource = new RequestRspecSource(m);

        String pleRspecRequestStr = requestRspecSource.getRspecXmlString(ModelRspec.RequestRspecSpecialCases.PLE);

        StringRspec resultStringRspec = new StringRspec(pleRspecRequestStr);
        List<String> compMan = resultStringRspec.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan + "  rspec=" + pleRspecRequestStr);
        assertTrue(compMan.contains("urn:publicid:IDN+ple:ibbtple+authority+cm"));

        RequestRspecSource newRequestRspecSouce = new RequestRspecSource(resultStringRspec);
        assertEquals(newRequestRspecSouce.getModelRspec().getNodes().size(), 2);
        assertEquals(newRequestRspecSouce.getModelRspec().getLinks().size(), 1);
    }

    @Test
    public void testNormalRspecParsing() {
        StringRspec s = new StringRspec(normalRspec);
        List<String> compMan = s.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 5,
                "size is " + compMan.size() + ". list is: " + compMan);

        assertTrue(compMan.contains("urn:publicid:IDN+wall3+authority+cm"));
        assertTrue(compMan.contains("urn:publicid:IDN+wall4+authority+cm"));
        assertTrue(compMan.contains("urn:publicid:IDN+wall5+authority+cm"));
        assertTrue(compMan.contains("urn:publicid:IDN+wall6+authority+cm"));
        assertTrue(compMan.contains("urn:publicid:IDN+wall7+authority+cm"));
    }

    @Test
    public void fusecoRspecParsing() {
        fusecoRspecParsingInternal(fusecoManifestRspec);
    }

    @Test
    public void fusecoRspecParsing2() {
        fusecoRspecParsingInternal(fusecoManifestRspec2);
    }

    public void fusecoRspecParsingInternal(String manifestRspec) {
        final String FUSECO_CM_URN = "urn:publicid:IDN+fuseco.fokus.fraunhofer.de+authority+cm";

        StringRspec s = new StringRspec(manifestRspec);
        List<String> compMan = s.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains(FUSECO_CM_URN));


        ManifestRspecSource requestRspecSource =
                new ManifestRspecSource(manifestRspec, rspecFactory.getModelRspecType());
        ModelRspec model = requestRspecSource.getModelRspec();
        assertEquals(model.getAllComponentManagerUrns().size(), 1);
        assertEquals(model.getAllComponentManagerUrns().get(0).toString(), FUSECO_CM_URN);
        assertEquals(model.getLinks().size(), 0);
        assertEquals(model.getNodes().size(), 1);
        RspecNode n = model.getNodes().get(0);
        assertNotNull(n);
        assertEquals(n.getClientId(), "node0");
        assertEquals(n.getComponentManagerId().toString(), FUSECO_CM_URN);
        assertEquals(n.getUniqueId(), "node0@" + FUSECO_CM_URN);
        assertEquals(n.getSliverTypeName(), "m1.tiny");
    }

    /**
     * The previous version did it's best to ignore namespace problems, and could thus parse the info in this.
     * but the current stax version is not ignoring namespaces. But that is not that bad, we should not assume invalid XML can be handled anyway.
     */
    @Test
    public void testErrorRspecParsing() {
        StringRspec s = new StringRspec(errorRspec);
        assertFalse(s.isWellFormed());
//        List<String> compMan = s.getAllComponentManagerUrns();
//        assertNotNull(compMan);
//        assertEquals(compMan.size(), 5,
//                "size is " + compMan.size() + ". list is: " + compMan);
//        assertTrue(compMan.contains("urn:publicid:IDN+wall3+authority+cm"));
//        assertTrue(compMan.contains("urn:publicid:IDN+wall4+authority+cm"));
//        assertTrue(compMan.contains("urn:publicid:IDN+wall5+authority+cm"));
//        assertTrue(compMan.contains("urn:publicid:IDN+wall6+authority+cm"));
//        assertTrue(compMan.contains("urn:publicid:IDN+wall7+authority+cm"));
    }

    @Test
    public void testRspecBParsing() {
        StringRspec s = new StringRspec(brechtRspec);
        List<String> compMan = s.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
    }

    @Test
    public void testRspecB2Parsing() {
        RequestRspecSource s = new RequestRspecSource(brechtRspec, rspecFactory.getModelRspecType());
        List<GeniUrn> compMan = s.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm")));
    }

    @Test
    public void testRspecB3Parsing() throws RspecParseException {
        ModelRspec s = new StaxRspecParser(brechtRspec, rspecFactory).call();
        List<GeniUrn> compMan = s.getAllComponentManagerUrns();
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm")));
    }

    @Test
    public void testOpenflowAParsing() {
        StringRspec s = new StringRspec(openflowRspecA);
        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains("urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+authority+am"));
    }


    @Test
    public void testOpenflowBParsing() {
        StringRspec s = new StringRspec(openflowRspecB);
        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains("urn:publicid:IDN+openflow:foam:10.1.0.61+authority+am"));
    }


    @Test
    public void testOpenflowCParsing() {
        StringRspec s = new StringRspec(openflowRspecC);
        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains("urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am"));
    }

//Xml is too badly damaged, may match or not, we don't care in this case
//    @Test
//    public void testOpenflowDParsing() {
//        StringRspec s = new StringRspec(openflowRspecD);
//        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
//        assertTrue("size is "+compMan.size()+". list is: "+compMan, compMan.size() == 1);
//        assertTrue(compMan.contains("urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+authority+am"));
//    }

    @Test
    public void testOpenflowEParsing() {
        StringRspec s = new StringRspec(openflowRspecE);
        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains("urn:publicid:IDN+openflow:foam:foam.atlantis.ugent.be+authority+am"));
    }

    @Test
    public void testOpenflowDatapathParsing() throws RspecParseException {
        String COMP_MAN_ID = "urn:publicid:IDN+openflow:foam:None+authority+am";
        String COMP_ID1 = "urn:publicid:IDN+openflow:foam:None+datapath+00:01:00:06:f6:73:e8:80";
        String COMP_ID2 = "urn:publicid:IDN+openflow:foam:None+datapath+00:01:e0:2f:6d:45:ba:00";
        String COMP_ID3 = "urn:publicid:IDN+openflow:foam:None+datapath+00:00:00:1c:73:2f:f7:80";
        String DPID1 = "00:01:00:06:f6:73:e8:80";
        String DPID2 = "00:01:e0:2f:6d:45:ba:00";
        String DPID3 = "00:00:00:1c:73:2f:f7:80";

        StringRspec s = new StringRspec(TestRspecsLibrary.advertisementWithOpenflowDatapaths);
        List<String> compMan = StringRspec.parseOpenflowComponentManagers(s.getXmlString());
        assertEquals(compMan.size(), 1,
                "size is " + compMan.size() + ". list is: " + compMan);
        assertTrue(compMan.contains(COMP_MAN_ID));

        ModelRspec modelRspec =
                new StaxRspecParser(TestRspecsLibrary.advertisementWithOpenflowDatapaths, rspecFactory).call();
        assertEquals(modelRspec.getNodes().size(), 0);
        assertEquals(modelRspec.getLinks().size(), 0);
        assertEquals(modelRspec.getOpenflowDataPaths().size(), 3);
        OpenflowDataPath path1 = modelRspec.getOpenflowDataPaths().get(0);
        OpenflowDataPath path2 = modelRspec.getOpenflowDataPaths().get(1);
        OpenflowDataPath path3 = modelRspec.getOpenflowDataPaths().get(2);
        assertEquals(path1.getComponentManagerId(), COMP_MAN_ID);
        assertEquals(path2.getComponentManagerId(), COMP_MAN_ID);
        assertEquals(path3.getComponentManagerId(), COMP_MAN_ID);
        assertEquals(path1.getComponentId(), COMP_ID1);
        assertEquals(path2.getComponentId(), COMP_ID2);
        assertEquals(path3.getComponentId(), COMP_ID3);
        assertEquals(path1.getDpid(), DPID1);
        assertEquals(path2.getDpid(), DPID2);
        assertEquals(path3.getDpid(), DPID3);
    }

    /**
     * node client_id and node component_manager_id are in the lookup.
     *
     * @return
     */
    public RspecNode dummyNodeForLoginServiceLookup(String clientId, String comManId) {
        RspecNode res = rspecFactory.createNodeWithClientId(null, clientId);
        res.setComponentManagerId(comManId);
        return res;
    }

    @Test
    public void testDanglingInterfaceParsing() {
        RequestRspecSource requestRspecSource =
                new RequestRspecSource(TestRspecsLibrary.requestNodeWithInterfaceButNoLink, rspecFactory.getModelRspecType());

        ModelRspec model = requestRspecSource.getModelRspec();
        assertEquals(model.getAllComponentManagerUrns().size(), 1);
        assertEquals(model.getAllComponentManagerUrns().get(0).toString(), "urn:publicid:IDN+example.com+authority+cm");
        assertEquals(model.getLinks().size(), 0);
        assertEquals(model.getNodes().size(), 1);
        RspecNode n = model.getNodes().get(0);
        assertNotNull(n);
        assertEquals(n.getClientId(), "node");
        assertEquals(n.getComponentManagerId().toString(), "urn:publicid:IDN+example.com+authority+cm");
        assertEquals(n.getSliverTypeName(), "raw-pc");
        assertEquals(n.getInterfaces().size(), 1);
        assertNotNull(n.getInterfaceByClientId("if0"));
        assertEquals(n.getInterfaceByClientId("if0").getClientId(), "if0");
        assertEquals(n.getInterfaceByClientId("if0").getComponentId(), "urn:publicid:IDN+example.com+interface+node:if0");
        assertEquals(n.getInterfaceByClientId("if0").getIpAddresses().size(), 1);
        assertEquals(n.getInterfaceByClientId("if0").getIpAddresses().get(0).getAddress(), "10.0.1.0");
        assertEquals(n.getInterfaceByClientId("if0").getIpAddresses().get(0).getNetmask(), "255.255.255.0");
        assertEquals(n.getInterfaceByClientId("if0").getIpAddresses().get(0).getType(), "ipv4");
    }

    @Test
    public void testHardwareTypes() throws RspecParseException {
        //TODO: this fails sometimes, but not always!
//        RequestRspecSource requestRspecSource = new RequestRspecSource(TestRspecsLibrary.advertisementWithTypeSlots, rspecFactory.getModelRspecType());
//        ModelRspec model = requestRspecSource.getModelRspec();

        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.advertisementWithTypeSlots, rspecFactory);
        ModelRspec model = parser.call();


        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 1);
        RspecNode n = model.getNodes().get(0);
        assertNotNull(n);
        assertEquals(n.getClientId(), null);
        assertEquals(n.getComponentManagerId().toString(), "urn:publicid:IDN+exogeni.net:osfvmsite+authority+am");
        assertEquals(n.getComponentId().toString(), "urn:publicid:IDN+exogeni.net:osfvmsite+node+orca-vm-cloud");
        assertEquals(n.getComponentName(), "orca-vm-cloud");
        assertEquals(n.getExclusive(), Boolean.FALSE);
        assertEquals(n.getSliverTypes().size(), 3);
        assertEquals(n.getInterfaces().size(), 2);
        assertNotNull(n.getInterfaces().get(0).getRole());
        assertEquals(n.getInterfaces().get(0).getRole(), "experimental");
        assertEquals(n.getHardwareTypes().size(), 1);
        HardwareType hwType = n.getHardwareTypes().get(0);
        assertEquals(hwType.getName(), "orca-vm-cloud");
        assertTrue(hwType.hasTypeSlots());
        assertFalse(hwType.hasUnlimitedTypeSlots());
        assertEquals(hwType.getTypeSlotsInt(), new Integer(112));
        assertEquals(hwType.getTypeSlotsString(), "112");
    }

    @Test
    public void testHardwareTypes2() throws RspecParseException {
        //TODO: this fails sometimes, but not always!
//        RequestRspecSource requestRspecSource = new RequestRspecSource(TestRspecsLibrary.advertisementWithTypeSlots, rspecFactory.getModelRspecType());
//        ModelRspec model = requestRspecSource.getModelRspec();

        StaxRspecParser parser =
                new StaxRspecParser(TestRspecsLibrary.advertisementWithUnlimitedTypeSlots, rspecFactory);
        ModelRspec model = parser.call();


        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 1);
        RspecNode n = model.getNodes().get(0);
        assertNotNull(n);
        assertEquals(n.getClientId(), null);
        assertEquals(n.getComponentManagerId().toString(), "urn:publicid:IDN+exogeni.net:osfvmsite+authority+am");
        assertEquals(n.getComponentId().toString(), "urn:publicid:IDN+exogeni.net:osfvmsite+node+orca-vm-cloud");
        assertEquals(n.getComponentName(), "orca-vm-cloud");
        assertEquals(n.getExclusive(), Boolean.FALSE);
        assertEquals(n.getSliverTypes().size(), 3);
        assertEquals(n.getInterfaces().size(), 2);
        assertNotNull(n.getInterfaces().get(0).getRole());
        assertEquals(n.getInterfaces().get(0).getRole(), "experimental");
        assertEquals(n.getHardwareTypes().size(), 1);
        HardwareType hwType = n.getHardwareTypes().get(0);
        assertEquals(hwType.getName(), "orca-vm-cloud");
        assertTrue(hwType.hasTypeSlots());
        assertTrue(hwType.hasUnlimitedTypeSlots());
        assertEquals(hwType.getTypeSlotsInt(), null);
        assertEquals(hwType.getTypeSlotsString(), "unlimited");
    }

    @Test
    public void testRouteableIpParsingA() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecA_routableAddresses, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 2);

        assertNotNull(model.getRoutableAddressesAvailable());
        assertNotNull(model.getRoutableAddressesConfigured());
        assertEquals(model.getRoutableAddressesAvailable(), new Integer(16));
        assertEquals(model.getRoutableAddressesConfigured(), new Integer(20));
    }

    @Test
    public void testExecuteAnsibleCookbookA() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecAwithExecuteAnsiblePlaybookA, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 2);

        assertNotNull(model.getExecuteAnsiblePlaybooks());
        assertThat(model.getExecuteAnsiblePlaybooks(), hasSize(1));
        ExecuteAnsiblePlaybook cookbook1 = model.getExecuteAnsiblePlaybooks().get(0);
        assertNotNull(cookbook1);
        assertThat(cookbook1.getSource(), is(notNullValue()));
        assertThat(cookbook1.getOutputFilename(), is(notNullValue()));
        assertThat(cookbook1.getSource(), is(equalTo("http://example.com/cookbook.yml")));
        assertThat(cookbook1.getOutputFilename(), is(equalTo("/home/test/ansible_output.txt")));
    }
    @Test
    public void testExecuteAnsibleCookbookB() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecAwithExecuteAnsiblePlaybookB, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 2);

        assertNotNull(model.getExecuteAnsiblePlaybooks());
        assertThat(model.getExecuteAnsiblePlaybooks(), hasSize(2));
        ExecuteAnsiblePlaybook cookbook1 = model.getExecuteAnsiblePlaybooks().get(0);
        ExecuteAnsiblePlaybook cookbook2 = model.getExecuteAnsiblePlaybooks().get(1);
        assertNotNull(cookbook1);
        assertNotNull(cookbook2);

        assertThat(cookbook1.getSource(), is(notNullValue()));
        assertThat(cookbook1.getOutputFilename(), is(nullValue()));
        assertThat(cookbook1.getSource(), is(equalTo("http://example.com/cookbook.yml")));

        assertThat(cookbook2.getSource(), is(notNullValue()));
        assertThat(cookbook2.getOutputFilename(), is(notNullValue()));
        assertThat(cookbook2.getSource(), is(equalTo("http://example.com/cookbook2.yml")));
        assertThat(cookbook2.getOutputFilename(), is(equalTo("output.txt")));
    }

    @Test
    public void testRouteableIpParsingB() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecA, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 2);

        assertNull(model.getRoutableAddressesAvailable());
        assertNull(model.getRoutableAddressesConfigured());
    }

    @Test
    public void testManifestProxyParsingA() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecManifestA, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertThat(model.getNodes(), hasSize(2));

        RspecNode nodeA = model.getNodes().get(0);
        RspecNode nodeB = model.getNodes().get(1);
        assertNotNull(nodeA);
        assertNotNull(nodeB);

        List<LoginService> servicesA = nodeA.getLoginServices();
        List<LoginService> servicesB = nodeB.getLoginServices();

        assertThat(servicesA, hasSize(1));
        assertThat(servicesB, hasSize(1));

        assertThat(nodeA.getProxyServices(), hasSize(0));
        assertThat(nodeB.getProxyServices(), hasSize(0));

        assertThat(servicesA.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesA.get(0).getPort(), is("22"));
        assertThat(servicesA.get(0).getIntPort(), is(22));
        assertThat(servicesA.get(0).getHostname(), is("n095-10a.wall2.ilabt.iminds.be"));
        assertThat(servicesA.get(0).getUsername(), is("tester"));


        assertThat(servicesB.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesB.get(0).getPort(), is("22"));
        assertThat(servicesB.get(0).getIntPort(), is(22));
        assertThat(servicesB.get(0).getHostname(), is("n095-05b.wall2.ilabt.iminds.be"));
        assertThat(servicesB.get(0).getUsername(), is("tester"));
    }

    @Test
    public void testManifestAVlanParsing() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecManifestAvlan, rspecFactory);
        ModelRspec origModel = parser.call();

        assertNotNull(origModel);
        assertNotNull(origModel.getNodes());
        assertThat(origModel.getNodes(), hasSize(2));

        List<? extends RspecLink> links = origModel.getLinks();
        assertThat(links, hasSize(1));
        RspecLink link = links.get(0);
        assertThat(link, is(notNullValue()));
        assertThat(link.getVlanTag(), is(42));

        ModelRspec copyModel = rspecFactory.copyModelRspec(origModel, null/*newType (request, manifest, ...)*/);
        assertNotNull(copyModel);
        assertNotNull(copyModel.getNodes());
        assertThat(copyModel.getNodes(), hasSize(2));

        List<? extends RspecLink> copyLinks = copyModel.getLinks();
        assertThat(copyLinks, hasSize(1));
        RspecLink copyLink = copyLinks.get(0);
        assertThat(copyLink, is(notNullValue()));
        assertThat(copyLink.getVlanTag(), is(42));

        ModelRspec copy2Model = new StaxRspecParser(origModel.toGeni3Rspec(), rspecFactory).call();
        assertNotNull(copy2Model);
        assertNotNull(copy2Model.getNodes());
        assertThat(copy2Model.getNodes(), hasSize(2));

        List<? extends RspecLink> copy2Links = copy2Model.getLinks();
        assertThat(copy2Links, hasSize(1));
        RspecLink copy2Link = copy2Links.get(0);
        assertThat(copy2Link, is(notNullValue()));
        assertThat(copy2Link.getVlanTag(), is(42));
    }

    @Test
    public void testManifestProxyParsingB() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecManifestAcustomProxy, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertThat(model.getNodes(), hasSize(2));

        RspecNode nodeA = model.getNodes().get(0);
        RspecNode nodeB = model.getNodes().get(1);
        assertNotNull(nodeA);
        assertNotNull(nodeB);

        List<LoginService> servicesA = nodeA.getLoginServices();
        List<LoginService> servicesB = nodeB.getLoginServices();

        assertThat(servicesA, hasSize(1));
        assertThat(servicesB, hasSize(1));

        List<ProxyService> proxyServicesA = nodeA.getProxyServices();
        List<ProxyService> proxyServicesB = nodeB.getProxyServices();

        assertThat(proxyServicesA, hasSize(1));
        assertThat(proxyServicesB, hasSize(1));

        assertThat(servicesA.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesA.get(0).getPort(), is("22"));
        assertThat(servicesA.get(0).getIntPort(), is(22));
        assertThat(servicesA.get(0).getHostname(), is("n095-10a.wall2.ilabt.iminds.be"));
        assertThat(servicesA.get(0).getUsername(), is("tester"));


        assertThat(servicesB.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesB.get(0).getPort(), is("22"));
        assertThat(servicesB.get(0).getIntPort(), is(22));
        assertThat(servicesB.get(0).getHostname(), is("n095-05b.wall2.ilabt.iminds.be"));
        assertThat(servicesB.get(0).getUsername(), is("tester"));

        assertThat(proxyServicesA.get(0).getFor(), is("tester@n095-10a.wall2.ilabt.iminds.be:22"));
        assertThat(proxyServicesA.get(0).getHostKey(), is(nullValue()));
        assertThat(proxyServicesA.get(0).getProxy(), is("proxyuser@bastion.test.iminds.be:80"));

        assertThat(proxyServicesB.get(0).getFor(), is("tester@n095-05b.wall2.ilabt.iminds.be:22"));
        assertThat(proxyServicesB.get(0).getHostKey(), is(nullValue()));
        assertThat(proxyServicesB.get(0).getProxy(), is("proxyuser@bastion.test.iminds.be:80"));
    }

    @Test
    public void testRspecWithAutoSharedLan() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecWithLinkAutoShareLan, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertThat(model.getNodes(), hasSize(2));
        assertThat(model.getLinks(), hasSize(1));

        RspecNode nodeA = model.getNodes().get(0);
        RspecNode nodeB = model.getNodes().get(1);
        assertNotNull(nodeA);
        assertNotNull(nodeB);

        RspecLink link = model.getLinks().get(0);
        assertNotNull(link);

        assertThat(link.getAutoShareLanNames(), hasSize(1));
        String autoShareName = link.getAutoShareLanNames().get(0);
        assertNotNull(autoShareName);
        assertThat(autoShareName, is(equalTo("testSharedLan")));
    }

    @Test
    public void testManifestProxyParsingC() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.rspecManifestAcustomProxyAndProxyLogin, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertThat(model.getNodes(), hasSize(2));

        RspecNode nodeA = model.getNodes().get(0);
        RspecNode nodeB = model.getNodes().get(1);
        assertNotNull(nodeA);
        assertNotNull(nodeB);

        List<LoginService> servicesA = nodeA.getLoginServices();
        List<LoginService> servicesB = nodeB.getLoginServices();

        assertThat(servicesA, hasSize(2));
        assertThat(servicesB, hasSize(2));

        List<ProxyService> proxyServicesA = nodeA.getProxyServices();
        List<ProxyService> proxyServicesB = nodeB.getProxyServices();

        assertThat(proxyServicesA, hasSize(1));
        assertThat(proxyServicesB, hasSize(1));

        assertThat(servicesA.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesA.get(0).getPort(), is("22"));
        assertThat(servicesA.get(0).getIntPort(), is(22));
        assertThat(servicesA.get(0).getHostname(), is("n095-10a.wall2.ilabt.iminds.be"));
        assertThat(servicesA.get(0).getUsername(), is("tester"));


        assertThat(servicesB.get(1).getAuthentication(), is("ssh-keys"));
        assertThat(servicesB.get(1).getPort(), is("22"));
        assertThat(servicesB.get(1).getIntPort(), is(22));
        assertThat(servicesB.get(1).getHostname(), is("n095-05b.wall2.ilabt.iminds.be"));
        assertThat(servicesB.get(1).getUsername(), is("tester"));

        assertThat(servicesA.get(1).getAuthentication(), is("ssh-keys"));
        assertThat(servicesA.get(1).getPort(), is("80"));
        assertThat(servicesA.get(1).getIntPort(), is(80));
        assertThat(servicesA.get(1).getHostname(), is("bastion.test.iminds.be"));
        assertThat(servicesA.get(1).getUsername(), is("proxyuser"));

        assertThat(servicesB.get(0).getAuthentication(), is("ssh-keys"));
        assertThat(servicesB.get(0).getPort(), is("80"));
        assertThat(servicesB.get(0).getIntPort(), is(80));
        assertThat(servicesB.get(0).getHostname(), is("bastion.test.iminds.be"));
        assertThat(servicesB.get(0).getUsername(), is("proxyuser"));

        assertThat(proxyServicesA.get(0).getFor(), is("tester@n095-10a.wall2.ilabt.iminds.be:22"));
        assertThat(proxyServicesA.get(0).getHostKey(), is(nullValue()));
        assertThat(proxyServicesA.get(0).getProxy(), is("proxyuser@bastion.test.iminds.be:80"));

        assertThat(proxyServicesB.get(0).getFor(), is("tester@n095-05b.wall2.ilabt.iminds.be:22"));
        assertThat(proxyServicesB.get(0).getHostKey(), is(nullValue()));
        assertThat(proxyServicesB.get(0).getProxy(), is("proxyuser@bastion.test.iminds.be:80"));
    }


    @Test
    public void testLoginServiceParsingA() {
        ManifestRspecSource s = new ManifestRspecSource(manifestA, rspecFactory.getModelRspecType());
        List<BasicStringRspec.LoginService> logins =
                s.getNodeLoginInfo(
                        dummyNodeForLoginServiceLookup("node0", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "n095-08b.wall2.ilabt.iminds.be");
        assertEquals(logins.get(0).getUsername(), "wvdemeer");
        assertEquals(logins.get(0).getPort(), 22);
    }

    @Test
    public void testLoginServiceParsingA2() {
        StringRspec s = new StringRspec(manifestA);
        List<BasicStringRspec.LoginService> logins =
                new ManifestRspecSource(s).getNodeLoginInfoWithoutModel(
                        dummyNodeForLoginServiceLookup("node0", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "n095-08b.wall2.ilabt.iminds.be");
        assertEquals(logins.get(0).getUsername(), "wvdemeer");
        assertEquals(logins.get(0).getPort(), 22);
    }


    @Test
    public void testLoginServiceParsingA3() throws RspecParseException {
        ModelRspec s = new StaxRspecParser(manifestA, rspecFactory).call();
        List<LoginService> logins = s.getNodeByClientId("node0").getLoginServices();
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "n095-08b.wall2.ilabt.iminds.be");
        assertEquals(logins.get(0).getUsername(), "wvdemeer");
        assertEquals(logins.get(0).getPort(), "22");
    }


    @Test
    public void testLoginServiceParsingB() {
        ManifestRspecSource s = new ManifestRspecSource(manifestB, rspecFactory.getModelRspecType());
        List<BasicStringRspec.LoginService> logins = s.getNodeLoginInfo(
                dummyNodeForLoginServiceLookup("node0", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost0");
        assertEquals(logins.get(0).getUsername(), "dummyuser0");
        assertEquals(logins.get(0).getPort(), 22);

        logins = s.getNodeLoginInfo(
                dummyNodeForLoginServiceLookup("node1", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost1");
        assertEquals(logins.get(0).getUsername(), "dummyuser1");
        assertEquals(logins.get(0).getPort(), 22);

        logins = s.getNodeLoginInfo(
                dummyNodeForLoginServiceLookup("bridge", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 2, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhostbridge1");
        assertEquals(logins.get(0).getUsername(), "dummyuserbridge1");
        assertEquals(logins.get(0).getPort(), 22);
        assertEquals(logins.get(1).getHostname(), "dummyhostbridge2");
        assertEquals(logins.get(1).getUsername(), "dummyuserbridge2");
        assertEquals(logins.get(1).getPort(), 22);
    }

    @Test
    public void testLoginServiceParsingB2() {
        StringRspec s = new StringRspec(manifestB);
        List<BasicStringRspec.LoginService> logins =
                new ManifestRspecSource(s).getNodeLoginInfoWithoutModel(
                        dummyNodeForLoginServiceLookup("node0", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost0");
        assertEquals(logins.get(0).getUsername(), "dummyuser0");
        assertEquals(logins.get(0).getPort(), 22);

        logins = new ManifestRspecSource(s).getNodeLoginInfoWithoutModel(
                dummyNodeForLoginServiceLookup("node1", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost1");
        assertEquals(logins.get(0).getUsername(), "dummyuser1");
        assertEquals(logins.get(0).getPort(), 22);

        logins = new ManifestRspecSource(s).getNodeLoginInfoWithoutModel(
                dummyNodeForLoginServiceLookup("bridge", "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        assertNotNull(logins);
        assertEquals(logins.size(), 2, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhostbridge1");
        assertEquals(logins.get(0).getUsername(), "dummyuserbridge1");
        assertEquals(logins.get(0).getPort(), 22);
        assertEquals(logins.get(1).getHostname(), "dummyhostbridge2");
        assertEquals(logins.get(1).getUsername(), "dummyuserbridge2");
        assertEquals(logins.get(1).getPort(), 22);
    }

    @Test
    public void testLoginServiceParsingB3() throws RspecParseException {
        ModelRspec s = new StaxRspecParser(manifestB, rspecFactory).call();
        List<LoginService> logins = s.getNodeByClientId("node0").getLoginServices();
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost0");
        assertEquals(logins.get(0).getUsername(), "dummyuser0");
        assertEquals(logins.get(0).getPort(), "22");

        logins = s.getNodeByClientId("node1").getLoginServices();
        assertNotNull(logins);
        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhost1");
        assertEquals(logins.get(0).getUsername(), "dummyuser1");
        assertEquals(logins.get(0).getPort(), "22");

        logins = s.getNodeByClientId("bridge").getLoginServices();
        assertNotNull(logins);
        assertEquals(logins.size(), 2, "size is " + logins.size() + ". list is: " + logins);
        assertEquals(logins.get(0).getHostname(), "dummyhostbridge1");
        assertEquals(logins.get(0).getUsername(), "dummyuserbridge1");
        assertEquals(logins.get(0).getPort(), "22");
        assertEquals(logins.get(1).getHostname(), "dummyhostbridge2");
        assertEquals(logins.get(1).getUsername(), "dummyuserbridge2");
        assertEquals(logins.get(1).getPort(), "22");

    }

    @Test
    public void testFelixRequest() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.felixRequest, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 4);

        assertNotNull(model.getInterfaceByClientId("urn:publicid:IDN+fms:aist:serm+datapath+00:00:00:00:00:00:00:10_4"));
        assertEquals(model.getInterfaceByClientId("urn:publicid:IDN+fms:aist:serm+datapath+00:00:00:00:00:00:00:10_4").getFelixVlan(), new Integer(1795));
    }


    @Test
    public void testDuplicateClientIdParsing1() throws RspecParseException {
        ModelRspec s =
                new StaxRspecParser(TestRspecsLibrary.rspecWithDuplicateIfaceNames_notreconstructable, rspecFactory).call();
        testDuplicateClientIdParsingInternal(s);
    }

    @Test
    public void testDuplicateClientIdParsing2() throws RspecParseException {
        ModelRspec s =
                new StaxRspecParser(TestRspecsLibrary.rspecWithDuplicateIfaceNames_reconstructable, rspecFactory).call();
        testDuplicateClientIdParsingInternal(s);
    }

    public void testDuplicateClientIdParsingInternal(ModelRspec s) throws RspecParseException {

        assertThat(s.getNodes(), hasSize(4));
        assertThat(s.getLinks(), hasSize(2));
        assertThat(s.getLinks().get(0).getClientId(), equalTo("link0"));
        assertThat(s.getLinks().get(1).getClientId(), equalTo("link0"));
        assertThat(s.getLinks().get(0).getComponentManagerUrns(), hasSize(1));
        assertThat(s.getLinks().get(1).getComponentManagerUrns(), hasSize(1));
        assertThat(s.getLinks().get(0).getComponentManagerUrns(), not(equalTo(s.getLinks().get(1).getComponentManagerUrns())));

        RspecNode n0 =
                s.getNodeByUniqueId(BasicStringRspec.makeUniqueNodeId("node0", null, "urn:publicid:IDN+example.com+authority+cm"));
        RspecNode n1 =
                s.getNodeByUniqueId(BasicStringRspec.makeUniqueNodeId("node1", null, "urn:publicid:IDN+example.com+authority+cm"));
        RspecNode n2 =
                s.getNodeByUniqueId(BasicStringRspec.makeUniqueNodeId("node0", null, "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));
        RspecNode n3 =
                s.getNodeByUniqueId(BasicStringRspec.makeUniqueNodeId("node1", null, "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm"));

        RspecLink l1 =
                s.getLinkByUniqueId(BasicStringRspec.makeUniqueLinkId("link0", null, Collections.singletonList("urn:publicid:IDN+example.com+authority+cm")));
        RspecLink l2 =
                s.getLinkByUniqueId(BasicStringRspec.makeUniqueLinkId("link0", null, Collections.singletonList("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm")));

        assertThat(n0, notNullValue());
        assertThat(n1, notNullValue());
        assertThat(n2, notNullValue());
        assertThat(n3, notNullValue());
        assertThat(l1, notNullValue());
        assertThat(l2, notNullValue());

        assertThat(n0.getInterfaces(), hasSize(1));
        assertThat(n1.getInterfaces(), hasSize(1));
        assertThat(n2.getInterfaces(), hasSize(1));
        assertThat(n3.getInterfaces(), hasSize(1));

        assertThat(l1.getInterfaces(), hasSize(2));
        assertThat(l2.getInterfaces(), hasSize(2));

        assertThat(n0.getInterfaces().get(0).getLink(), sameInstance(l1));

        assertThat(n0.getInterfaces().get(0).getClientId(), equalTo("node0:if0"));
        assertThat(n0.getInterfaces().get(0).getComponentId(), equalTo("urn:publicid:IDN+example.com+interface+node0a"));
        assertThat(n0.getInterfaces().get(0).getSliverId(), equalTo(GeniUrn.parse("urn:publicid:IDN+example.com+sliver+s1")));

        assertThat(n1.getInterfaces().get(0).getLink(), sameInstance(l1));
        assertThat(n1.getInterfaces().get(0).getClientId(), equalTo("node1:if0"));
        assertThat(n1.getInterfaces().get(0).getComponentId(), equalTo("urn:publicid:IDN+example.com+interface+node1a"));
        assertThat(n1.getInterfaces().get(0).getSliverId(), equalTo(GeniUrn.parse("urn:publicid:IDN+example.com+sliver+s2")));

        assertThat(n2.getInterfaces().get(0).getLink(), sameInstance(l2));
        assertThat(n2.getInterfaces().get(0).getClientId(), equalTo("node0:if0"));
        assertThat(n2.getInterfaces().get(0).getComponentId(), equalTo("urn:publicid:IDN+wall2.ilabt.iminds.be+interface+node0a"));
        assertThat(n2.getInterfaces().get(0).getSliverId(), equalTo(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+s1")));

        assertThat(n3.getInterfaces().get(0).getLink(), sameInstance(l2));
        assertThat(n3.getInterfaces().get(0).getClientId(), equalTo("node1:if0"));
        assertThat(n3.getInterfaces().get(0).getComponentId(), equalTo("urn:publicid:IDN+wall2.ilabt.iminds.be+interface+node1a"));
        assertThat(n3.getInterfaces().get(0).getSliverId(), equalTo(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+s2")));
    }


    @Test
    public void testPerformLteManifest() throws RspecParseException {
        StaxRspecParser parser = new StaxRspecParser(TestRspecsLibrary.performltrManifest, rspecFactory);
        ModelRspec model = parser.call();

        assertNotNull(model);
        assertNotNull(model.getNodes());
        assertEquals(model.getNodes().size(), 1);

        RspecNode node = model.getNodes().get(0);

        assertNotNull(node);
        List<LoginService> loginServices = node.getLoginServices();
        assertThat(loginServices, hasSize(1));
        LoginService login = loginServices.get(0);
        assertNotNull(login);
        assertThat(login.getIntPort(), is(equalTo(11004)));
        assertThat(login.getAuthentication(), is(equalTo("ssh-keys")));
        assertThat(login.getHostname(), is(equalTo("performlte.morse.uma.es")));
        assertThat(login.getUsername(), is(equalTo("maldoror")));
    }

//    @Test
//    public void testLoginServiceParsingPle() {
//        ManifestRspecSource s = new ManifestRspecSource(manifestPle);
//        RspecNode requestNode = rspecFactory.createNode(null, "node0");
//        requestNode.setComponentId("urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it");
//        requestNode.setComponentManagerId("urn:publicid:IDN+ple+authority+cm");
//        List<BasicStringRspec.LoginService> logins = s.getNodeLoginInfo(requestNode);
//        assertNotNull(logins);
//        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
//        assertEquals(logins.get(0).getHostname(), "marie.iet.unipi.it");
//        assertEquals(logins.get(0).getUsername(), "wall3testibbtbe_DebugjFed");
//        assertEquals(logins.get(0).getPort(), 22);
//    }
//
//    @Test
//    public void testLoginServiceParsingPle2() {
//        ManifestRspecSource s = new ManifestRspecSource(manifestPle);
//        RspecNode requestNode = rspecFactory.createNode(null, "node0");
//        requestNode.setComponentId("urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it");
//        requestNode.setComponentManagerId("urn:publicid:IDN+ple:ibbtple+authority+cm");
//        List<BasicStringRspec.LoginService> logins = s.getNodeLoginInfo(requestNode);
//        assertNotNull(logins);
//        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
//        assertEquals(logins.get(0).getHostname(), "marie.iet.unipi.it");
//        assertEquals(logins.get(0).getUsername(), "wall3testibbtbe_DebugjFed");
//        assertEquals(logins.get(0).getPort(), 22);
//    }
//
//    @Test
//    public void testLoginServiceParsingPle3() {
//        StringRspec s = new StringRspec(manifestPle);
//        RspecNode requestNode = rspecFactory.createNode(null, "node0");
//        requestNode.setComponentId("urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it");
//        requestNode.setComponentManagerId("urn:publicid:IDN+ple+authority+cm");
//        List<BasicStringRspec.LoginService> logins =
//                new ManifestRspecSource(s).getNodeLoginInfoWithoutModel(requestNode);
//        assertNotNull(logins);
//        assertEquals(logins.size(), 1, "size is " + logins.size() + ". list is: " + logins);
//        assertEquals(logins.get(0).getHostname(), "marie.iet.unipi.it");
//        assertEquals(logins.get(0).getUsername(), "wall3testibbtbe_DebugjFed");
//        assertEquals(logins.get(0).getPort(), 22);
//    }


    //Rspecs for tests (these rspecs make no sense, they are just for testing)
    private static String normalRspec =
            "<rspec type=\"request\" generated_by=\"Flack\" generated=\"2013-01-11T10:30:10Z\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd \" xmlns:flack=\"http://www.protogeni.net/resources/rspec/ext/flack/1\" xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.geni.net/resources/rspec/3\">\n" +
                    "  <node client_id=\"PC\" component_manager_id=\"urn:publicid:IDN+wall3+authority+cm\" exclusive=\"true\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <interface client_id=\"PC:if0\">\n" +
                    "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
                    "    </interface>\n" +
                    "    <flack:node_info x=\"67\" y=\"116\" unbound=\"true\"/>\n" +
                    "  </node>\n" +
                    "  <node client_id=\"PC\" component_manager_id=\"urn:publicid:IDN+wall3+authority+cm\" exclusive=\"true\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <interface client_id=\"PC:if0\">\n" +
                    "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
                    "    </interface>\n" +
                    "    <flack:node_info x=\"67\" y=\"116\" unbound=\"true\"/>\n" +
                    "  </node>\n" +
                    "  <node client_id=\"PC-0\" component_manager_id=\"urn:publicid:IDN+wall4+authority+cm\" exclusive=\"true\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <interface client_id=\"PC-0:if0\">\n" +
                    "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
                    "    </interface>\n" +
                    "    <flack:node_info x=\"375\" y=\"172\" unbound=\"true\"/>\n" +
                    "  </node>\n" +
                    "  <link client_id=\"lan0\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall5+authority+cm\"/>\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall6+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"PC:if0\"/>\n" +
                    "    <interface_ref client_id=\"PC-0:if0\"/>\n" +
                    "    <property source_id=\"PC:if0\" dest_id=\"PC-0:if0\" capacity=\"1000000\"/>\n" +
                    "    <property source_id=\"PC-0:if0\" dest_id=\"PC:if0\" capacity=\"1000000\"/>\n" +
                    "    <link_type name=\"lan\"/>\n" +
                    "    <flack:link_info x=\"-1\" y=\"-1\" unboundVlantag=\"true\"/>\n" +
                    "  </link>\n" +
                    "  <link client_id=\"lan1\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall7+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"PC:if0\"/>\n" +
                    "    <interface_ref client_id=\"PC-0:if0\"/>\n" +
                    "    <property source_id=\"PC:if0\" dest_id=\"PC-0:if0\" capacity=\"1000000\"/>\n" +
                    "    <property source_id=\"PC-0:if0\" dest_id=\"PC:if0\" capacity=\"1000000\"/>\n" +
                    "    <link_type name=\"lan\"/>\n" +
                    "    <flack:link_info x=\"-1\" y=\"-1\" unboundVlantag=\"true\"/>\n" +
                    "  </link>\n" +
                    "  <link client_id=\"lan1\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall6+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"PC:if0\"/>\n" +
                    "    <interface_ref client_id=\"PC-0:if0\"/>\n" +
                    "    <property source_id=\"PC:if0\" dest_id=\"PC-0:if0\" capacity=\"1000000\"/>\n" +
                    "    <property source_id=\"PC-0:if0\" dest_id=\"PC:if0\" capacity=\"1000000\"/>\n" +
                    "    <link_type name=\"lan\"/>\n" +
                    "    <flack:link_info x=\"-1\" y=\"-1\" unboundVlantag=\"true\"/>\n" +
                    "  </link>\n" +
                    "  <client:client_info name=\"Flack\" environment=\"Flash Version: LNX 11,2,202,258, OS: Linux 2.6.32-34-generic, Arch: x86, Screen: 1920x1080 @ 72 DPI with touchscreen type none\" version=\"v14.46\" url=\"https://www.emulab.net/protogeni/flack2/flack.swf?mode=public&amp;debug=0&amp;usejs=1\"/>\n" +
                    "  </rspec>";
    private static String brechtRspec = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<rspec generated=\"2014-02-01T16:47:22.736+01:00\" generated_by=\"Experimental jFed Rspec Editor\" type=\"request\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:jFed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >\n" +
            "<node client_id=\"node0\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "<sliver_type name=\"raw-pc\">\n" +
            "<disk_image name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//DEB60_64-VLAN\"/>\n" +
            "</sliver_type>\n" +
            "<services>\n" +
            "<execute shell=\"sh\" command=\"sudo apt-get install dstat\"/>\n" +
            "<install url=\"http://download.videolan.org/pub/videolan/vlc/0.5.1/vlc-0.5.1.tar.gz\" install_path=\"/local\"/>\n" +
            "</services>\n" +
            "<jFed:location x=\"73.0\" y=\"27.0\"/>\n" +
            "<interface client_id=\"node0:if0\"/>\n" +
            "</node>\n" +
            "<node client_id=\"node1\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "<sliver_type name=\"raw-pc\"/>\n" +
            "<jFed:location x=\"296.0\" y=\"207.0\"/>\n" +
            "<interface client_id=\"node1:if0\"/>\n" +
            "</node>\n" +
            "<node client_id=\"bridge\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "<sliver_type name=\"delay\">\n" +
            "<delay:sliver_type_shaping>\n" +
            "<pipe source=\"delay:left\" dest=\"delay:right\" capacity=\"1000\" latency=\"50\" />\n" +
            "<pipe source=\"delay:right\" dest=\"delay:left\" capacity=\"10000\" latency=\"25\" packet_loss=\"0.01\"/>\n" +
            "</delay:sliver_type_shaping>\n" +
            "</sliver_type>\n" +
            "<interface client_id=\"delay:left\" />\n" +
            "<interface client_id=\"delay:right\" />\n" +
            "</node>\n" +
            "<link client_id=\"link1\">\n" +
            "<interface_ref client_id=\"node0:if0\" />\n" +
            "<interface_ref client_id=\"delay:left\" />\n" +
            "<property source_id=\"delay:left\" dest_id=\"node0:if0\"/>\n" +
            "<property source_id=\"node0:if0\" dest_id=\"delay:left\"/>\n" +
            "<link_type name=\"lan\"/>\n" +
            "</link>\n" +
            "<link client_id=\"link2\">\n" +
            "<interface_ref client_id=\"node1:if0\" />\n" +
            "<interface_ref client_id=\"delay:right\" />\n" +
            "<property source_id=\"delay:right\" dest_id=\"node1:if0\"/>\n" +
            "<property source_id=\"node1:if0\" dest_id=\"delay:right\"/>\n" +
            "<link_type name=\"lan\"/>\n" +
            "</link>\n" +
            "</rspec>";
    private static String errorRspec = "<rspec>\n" +
            "  <node component_manager_id=\"urn:publicid:IDN+wall3+authority+cm\" exclusive=\"true\" test=\"test\">\n" +
            "    <sliver_type name=\"raw-pc\"/>\n" +
            "    <interface client_id=\"PC:if0\">\n" +
            "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <node client_id=\"PC\" exclusive=\"true\">\n" +
            "    <sliver_type name=\"raw-pc\"/>\n" +
            "    <interface client_id=\"PC:if0\">\n" +
            "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <link client_id=\"lan0\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall5+authority+cm\"/>\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall6+authority+cm\"/>\n" +
            "    <component_manager/>\n" +
            "    <interface_ref client_id=\"PC:if0\"/>\n" +
            "    <interface_ref client_id=\"PC-0:if0\"/>\n" +
            "    <property source_id=\"PC:if0\" dest_id=\"PC-0:if0\" capacity=\"1000000\"/>\n" +
            "    <property source_id=\"PC-0:if0\" dest_id=\"PC:if0\" capacity=\"1000000\"/>\n" +
            "    <link_type name=\"lan\"/>\n" +
            "    <flack:link_info x=\"-1\" y=\"-1\" unboundVlantag=\"true\"/>\n" +
            "  </link>\n" +
            "  <link client_id=\"lan100\">\n" +
            "  </link>\n" +
            "  <link client_id=\"lan0\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall7+authority+cm\"/>\n" +
            "    <interface_ref client_id=\"PC:if0\"/>\n" +
            "    <interface_ref client_id=\"PC-0:if0\"/>\n" +
            "    <property source_id=\"PC:if0\" dest_id=\"PC-0:if0\" capacity=\"1000000\"/>\n" +
            "    <property source_id=\"PC-0:if0\" dest_id=\"PC:if0\" capacity=\"1000000\"/>\n" +
            "    <link_type name=\"lan\"/>\n" +
            "    <flack:link_info x=\"-1\" y=\"-1\" unboundVlantag=\"true\"/>\n" +
            "  </link>\n" +
            "  <link>\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall3+authority+cm\" blah=\"blah\"/>\n" +
            "  </link>\n" +
            "  <node client_id=\"PC-0\" component_manager_id=\"urn:publicid:IDN+wall4+authority+cm\" exclusive=\"true\">\n" +
            "    <sliver_type name=\"raw-pc\"/>\n" +
            "    <interface client_id=\"PC-0:if0\">\n" +
            "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
            "    </interface>\n" +
            "    <flack:node_info x=\"375\" y=\"172\" unbound=\"true\"/>\n" +
            "  </node>\n" +
            "  <node client_id=\"PC-0\" component_manager_id=\"\" exclusive=\"true\">\n" +
            "    <sliver_type name=\"raw-pc\"/>\n" +
            "    <interface client_id=\"PC-0:if0\">\n" +
            "      <flack:interface_info addressUnset=\"true\" bound=\"false\"/>\n" +
            "    </interface>\n" +
            "    <flack:node_info x=\"375\" y=\"172\" unbound=\"true\"/>\n" +
            "  </node>\n" +
            "  <client:client_info name=\"Flack\" environment=\"Flash Version: LNX 11,2,202,258, OS: Linux 2.6.32-34-generic, Arch: x86, Screen: 1920x1080 @ 72 DPI with touchscreen type none\" version=\"v14.46\" url=\"https://www.emulab.net/protogeni/flack2/flack.swf?mode=public&amp;debug=0&amp;usejs=1\"/>\n" +
            "  </rspec>";
    private static String openflowRspecA = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "       xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
            "       xmlns:openflow=\"http://www.geni.net/resources/rspec/ext/openflow/3\"\n" +
            "       xs:schemaLocation=\"http://www.geni.net/resources/rspec/3\n" +
            "           http://www.geni.net/resources/rspec/3/request.xsd\n" +
            "           http://www.geni.net/resources/rspec/ext/openflow/3\n" +
            "           http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd\"\n" +
            "       type=\"request\">\n" +
            "\n" +
            "  <openflow:sliver description=\" InstaGENI OpenFlow\" email=\"lnevers@bbn.com\">\n" +
            "    <openflow:controller url=\"tcp:mallorea.gpolab.bbn.com:33018\" type=\"primary\" />\n" +
            "\n" +
            "    <openflow:group name=\"bbn-instageni-1750\">\n" +
            "      <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+datapath+06:d6:84:34:97:c6:c9:00\" \n" +
            "\tcomponent_manager_id=\"urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+authority+am\"  />\n" +
            "    </openflow:group>\n" +
            "\n" +
            "    <openflow:match>\n" +
            "\n" +
            "      <openflow:use-group name=\"bbn-instageni-1750\" />\n" +
            "\n" +
            "      <openflow:packet>\n" +
            "        <openflow:dl_type value=\"0x800,0x806\"/>\n" +
            "        <openflow:nw_dst value=\"10.42.18.0/24\"/>\n" +
            "        <openflow:nw_src value=\"10.42.18.0/24\"/>\n" +
            "      </openflow:packet>\n" +
            "\n" +
            "    </openflow:match>\n" +
            "\n" +
            "  </openflow:sliver>\n" +
            "\n" +
            "</rspec>\n" +
            "\n";
    private static String openflowRspecB = "<rspec type=\"advertisement\"\n" +
            "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:openflow=\"http://www.geni.net/resources/rspec/ext/openflow/3\"\n" +
            "    xmlns:topology=\"http://geni.bssoftworks.com/rspec/ext/topo/1\"\n" +
            "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\" xs:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/ad.xsd http://www.geni.net/resources/rspec/ext/openflow/3 http://www.geni.net/resources/rspec/ext/openflow/3/of-ad.xsd http://geni.bssoftworks.com/rspec/ext/topo/1 http://geni.bssoftworks.com/rspec/ext/topo/1\">\n" +
            "    <openflow:datapath\n" +
            "        component_id=\"urn:publicid:IDN+openflow:foam:10.1.0.61+datapath+00:01:00:06:f6:73:e8:80\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+openflow:foam:10.1.0.61+authority+am\" dpid=\"00:01:00:06:f6:73:e8:80\">\n" +
            "        <openflow:port name=\"Eth1/23\" num=\"23\"/>\n" +
            "        <openflow:port name=\"Eth1/25\" num=\"25\"/>\n" +
            "        <openflow:port name=\"Eth1/24\" num=\"24\"/>\n" +
            "        <openflow:port name=\"Eth1/20\" num=\"20\">\n" +
            "            <topology:geni-of desc=\"switch.10.1.0.61[Eth1/20]\"\n" +
            "                remote-component-id=\"urn:publicid:IDN+10.1.0.61+switch+00:01:00:06:f6:73:e8:80\" remote-port-name=\"Eth1/20\"/>\n" +
            "        </openflow:port>\n" +
            "        <openflow:port name=\"Eth1/21\" num=\"21\"/>\n" +
            "        <openflow:port name=\"Eth1/22\" num=\"22\"/>\n" +
            "    </openflow:datapath>\n" +
            "    <openflow:datapath\n" +
            "        component_id=\"urn:publicid:IDN+openflow:foam:10.1.0.61+datapath+00:01:e0:2f:6d:45:ba:00\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+openflow:foam:10.1.0.61+authority+am\" dpid=\"00:01:e0:2f:6d:45:ba:00\">\n" +
            "        <openflow:port name=\"Eth1/23\" num=\"23\"/>\n" +
            "        <openflow:port name=\"Eth1/24\" num=\"24\"/>\n" +
            "        <openflow:port name=\"Eth1/21\" num=\"21\"/>\n" +
            "        <openflow:port name=\"Eth1/25\" num=\"25\"/>\n" +
            "        <openflow:port name=\"Eth1/20\" num=\"20\"/>\n" +
            "        <openflow:port name=\"Eth1/22\" num=\"22\"/>\n" +
            "    </openflow:datapath>\n" +
            "</rspec>\n" +
            "\n";
    private static String openflowRspecC = "<?xml version=\"1.0\" ?>\n" +
            "<!-- Resources at AM:\n" +
            "\tURN: unspecified_AM_URN\n" +
            "\tURL: https://foam.gpolab.bbn.com:3626/foam/gapi/1\n" +
            " -->\n" +
            "\n" +
            "<rspec type=\"advertisement\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:openflow=\"http://www.geni.net/resources/rspec/ext/openflow/3\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\" xs:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/ad.xsd http://www.geni.net/resources/rspec/ext/openflow/3 http://www.geni.net/resources/rspec/ext/openflow/3/of-ad.xsd\">\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:a4:00:12:e2:b8:a5:d0\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:a4:00:12:e2:b8:a5:d0\">\n" +
            "    <openflow:port name=\"GBE0/20\" num=\"20\"/>\n" +
            "    <openflow:port name=\"GBE0/21\" num=\"21\"/>\n" +
            "    <openflow:port name=\"GBE0/22\" num=\"22\"/>\n" +
            "  </openflow:datapath>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:a4:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:a4:00:24:a8:c4:b9:00\">\n" +
            "    <openflow:port name=\"1\" num=\"25\"/>\n" +
            "    <openflow:port name=\"2\" num=\"26\"/>\n" +
            "    <openflow:port name=\"6\" num=\"30\"/>\n" +
            "    <openflow:port name=\"8\" num=\"32\"/>\n" +
            "    <openflow:port name=\"9\" num=\"33\"/>\n" +
            "    <openflow:port name=\"11\" num=\"35\"/>\n" +
            "    <openflow:port name=\"47\" num=\"71\"/>\n" +
            "    <openflow:port name=\"local\" num=\"65534\"/>\n" +
            "    <openflow:port name=\"7\" num=\"31\"/>\n" +
            "    <openflow:port name=\"5\" num=\"29\"/>\n" +
            "  </openflow:datapath>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:c6:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:c6:00:24:a8:c4:b9:00\">\n" +
            "    <openflow:port name=\"31\" num=\"55\"/>\n" +
            "    <openflow:port name=\"41\" num=\"65\"/>\n" +
            "    <openflow:port name=\"local\" num=\"65534\"/>\n" +
            "  </openflow:datapath>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:d6:00:12:e2:b8:a5:d0\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:d6:00:12:e2:b8:a5:d0\">\n" +
            "    <openflow:port name=\"GBE0/3\" num=\"3\"/>\n" +
            "    <openflow:port name=\"GBE0/5\" num=\"5\"/>\n" +
            "    <openflow:port name=\"GBE0/9\" num=\"9\"/>\n" +
            "    <openflow:port name=\"GBE0/11\" num=\"11\"/>\n" +
            "    <openflow:port name=\"GBE0/18\" num=\"18\"/>\n" +
            "    <openflow:port name=\"GBE0/20\" num=\"20\"/>\n" +
            "    <openflow:port name=\"GBE0/21\" num=\"21\"/>\n" +
            "    <openflow:port name=\"GBE0/22\" num=\"22\"/>\n" +
            "    <openflow:port name=\"GBE0/15\" num=\"15\"/>\n" +
            "  </openflow:datapath>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:d6:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:d6:00:24:a8:c4:b9:00\">\n" +
            "    <openflow:port name=\"25\" num=\"49\"/>\n" +
            "    <openflow:port name=\"26\" num=\"50\"/>\n" +
            "    <openflow:port name=\"27\" num=\"51\"/>\n" +
            "    <openflow:port name=\"28\" num=\"52\"/>\n" +
            "    <openflow:port name=\"29\" num=\"53\"/>\n" +
            "    <openflow:port name=\"31\" num=\"55\"/>\n" +
            "    <openflow:port name=\"32\" num=\"56\"/>\n" +
            "    <openflow:port name=\"47\" num=\"71\"/>\n" +
            "    <openflow:port name=\"local\" num=\"65534\"/>\n" +
            "    <openflow:port name=\"8\" num=\"32\"/>\n" +
            "    <openflow:port name=\"4\" num=\"28\"/>\n" +
            "    <openflow:port name=\"9\" num=\"33\"/>\n" +
            "    <openflow:port name=\"1\" num=\"25\"/>\n" +
            "    <openflow:port name=\"11\" num=\"35\"/>\n" +
            "    <openflow:port name=\"2\" num=\"26\"/>\n" +
            "    <openflow:port name=\"12\" num=\"36\"/>\n" +
            "    <openflow:port name=\"6\" num=\"30\"/>\n" +
            "    <openflow:port name=\"10\" num=\"34\"/>\n" +
            "    <openflow:port name=\"3\" num=\"27\"/>\n" +
            "    <openflow:port name=\"7\" num=\"31\"/>\n" +
            "    <openflow:port name=\"5\" num=\"29\"/>\n" +
            "  </openflow:datapath>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:ae:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:ae:00:24:a8:c4:b9:00\"/>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:b3:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:b3:00:24:a8:c4:b9:00\"/>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:b0:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:b0:00:24:a8:c4:b9:00\"/>\n" +
            "  <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+datapath+06:af:00:24:a8:c4:b9:00\" component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.gpolab.bbn.com+authority+am\" dpid=\"06:af:00:24:a8:c4:b9:00\"/>\n" +
            "</rspec>\n" +
            "\n";
    private static String openflowRspecD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "       xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
            "       xs:schemaLocation=\"http://www.geni.net/resources/rspec/3\n" +
            "           http://www.geni.net/resources/rspec/3/request.xsd\n" +
            "           http://www.geni.net/resources/rspec/ext/openflow/3\n" +
            "           http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd\"\n" +
            "       type=\"request\">\n" +
            "\n" +
            "  <sliver description=\" InstaGENI OpenFlow\" email=\"lnevers@bbn.com\">\n" +
            "    <openflow:controller url=\"tcp:mallorea.gpolab.bbn.com:33018\" type=\"primary\" />\n" +
            "\n" +
            "    <openflow:group name=\"bbn-instageni-1750\">\n" +
            "      <openflow:datapath component_id=\"urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+datapath+06:d6:84:34:97:c6:c9:00\" \n" +
            "\tcomponent_manager_id=\"urn:publicid:IDN+openflow:foam:foam.instageni.gpolab.bbn.com+authority+am\"  />\n" +
            "    </openflow:group>\n" +
            "\n" +
            "    <openflow:match>\n" +
            "\n" +
            "      <openflow:use-group name=\"bbn-instageni-1750\" />\n" +
            "\n" +
            "      <openflow:packet>\n" +
            "        <openflow:dl_type value=\"0x800,0x806\"/>\n" +
            "        <openflow:nw_dst value=\"10.42.18.0/24\"/>\n" +
            "        <openflow:nw_src value=\"10.42.18.0/24\"/>\n" +
            "      </openflow:packet>\n" +
            "\n" +
            "    </openflow:match>\n" +
            "\n" +
            "  </openflow:sliver>\n" +
            "\n" +
            "</rspec>\n" +
            "\n";
    private static String openflowRspecE = "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n" +
            "<rspec  xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "        xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
            "        xmlns:openflow=\"http://www.geni.net/resources/rspec/ext/openflow/3\"\n" +
            "        xs:schemaLocation=\"http://www.geni.net/resources/rspec/3\n" +
            "              http://www.geni.net/resources/rspec/3/request.xsd\n" +
            "              http://www.geni.net/resources/rspec/ext/openflow/3\n" +
            "              http://www.geni.net/resources/rspec/ext/openflow/3/of-resv.xsd\"\n" +
            "    type=\"request\">\n" +
            " \n" +
            "    <openflow:sliver description=\"My awesome experiment that you should opt-in because I'm awesome.\"\n" +
            "                     email=\"john.doe@example.net\"\n" +
            "                     ref=\"http://wiki.example.net/myproject\">\n" +
            " \n" +
            "        <openflow:controller url=\"tcp:10.2.33.65:6633\" type=\"primary\" />\n" +
            "        \n" +
            "        <openflow:group name=\"johngrp\">\n" +
            "            <openflow:datapath\n" +
            "                component_id=\"urn:publicid:IDN+openflow:foam:foam.atlantis.ugent.be+datapath+00:00:86:5e:a1:df:d1:a3\"\n" +
            "                component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.atlantis.ugent.be+authority+am\">\n" +
            "                <openflow:port num=\"1\" name=\"br0\" />\n" +
            "                \n" +
            "             </openflow:datapath>\n" +
            " \n" +
            "             \n" +
            "        </openflow:group>\n" +
            " \n" +
            "        \n" +
            " \n" +
            "        <openflow:match>\n" +
            "            <openflow:datapath\n" +
            "                component_id=\"urn:publicid:IDN+openflow:foam:foam.atlantis.ugent.be+datapath+00:00:86:5e:a1:df:d1:a3\"\n" +
            "                component_manager_id=\"urn:publicid:IDN+openflow:foam:foam.atlantis.ugent.be+authority+am\"\n" +
            "                dpid=\"00:00:86:5e:a1:df:d1:a3\">\n" +
            "              <openflow:port num=\"1\" />\n" +
            "              \n" +
            "            </openflow:datapath>\n" +
            " \n" +
            "            <openflow:packet>\n" +
            "                <openflow:dl_src value=\"22:33:44:55:66:77\" />\n" +
            "                <openflow:dl_dst value=\"00:33:44:55:66:99\" />\n" +
            "                <openflow:dl_type value=\"0x800\" />\n" +
            "                <openflow:dl_vlan value=\"15\" />\n" +
            "                <openflow:nw_src value=\"192.168.3.0/24\" />\n" +
            "                <openflow:nw_dst value=\"192.168.3.0/24\" />\n" +
            "                <openflow:nw_proto value=\"17\" />\n" +
            "                <openflow:tp_src value=\"100\" />\n" +
            "                <openflow:tp_dst value=\"1024-1026\" />\n" +
            "            </openflow:packet>\n" +
            "        </openflow:match>\n" +
            "    </openflow:sliver>\n" +
            "</rspec>";
    private static final String manifestA =
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:jFed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" generated=\"2014-02-05T13:38:12.981+01:00\" generated_by=\"Experimental jFed Rspec Editor\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd\">\n" +
                    "    <node xmlns:jFed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" client_id=\"node0\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n095-08b\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+2345\">\n" +
                    "        <sliver_type name=\"raw-pc\"/>\n" +
                    "        <jFed:location x=\"38.0\" y=\"25.0\"/>\n" +
                    "        <jFed:nodeDescription>simple-node</jFed:nodeDescription>\n" +
                    "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n095-08b\"/>" +
                    "<host name=\"node0.tstManifest1.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/>" +
                    "<services><login authentication=\"ssh-keys\" hostname=\"n095-08b.wall2.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/></services></node>\n" +
                    "</rspec>";
    private static final String manifestB = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<rspec generated=\"2014-02-01T16:47:22.736+01:00\" generated_by=\"Experimental jFed Rspec Editor\" type=\"request\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:jFed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" > \n" +
            "    <node client_id=\"node0\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "        <sliver_type name=\"raw-pc\">\n" +
            "            <disk_image name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+image+emulab-ops//DEB60_64-VLAN\"/>\n" +
            "        </sliver_type>\n" +
            "        <services>\n" +
            "            <execute shell=\"sh\" command=\"sudo apt-get install dstat\"/>\n" +
            "            <install url=\"http://download.videolan.org/pub/videolan/vlc/0.5.1/vlc-0.5.1.tar.gz\" install_path=\"/local\"/>\n" +
            "            <login authentication=\"ssh-keys\" hostname=\"dummyhost0\" port=\"22\" username=\"dummyuser0\"/>\n" +
            "        </services>\n" +
            "        <jFed:location x=\"73.0\" y=\"27.0\"/>\n" +
            "        <interface client_id=\"node0:if0\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"node1\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "        <sliver_type name=\"raw-pc\"/>\n" +
            "        <jFed:location x=\"296.0\" y=\"207.0\"/>\n" +
            "        <interface client_id=\"node1:if0\"/>\n" +
            "        <services><login authentication=\"ssh-keys\" hostname=\"dummyhost1\" port=\"22\" username=\"dummyuser1\"/></services>\n" +
            "    </node>\n" +
            "  <node client_id=\"bridge\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "   <sliver_type name=\"delay\">\n" +
            "     <delay:sliver_type_shaping>\n" +
            "       <pipe source=\"delay:left\" dest=\"delay:right\" capacity=\"1000\" latency=\"50\" />\n" +
            "       <pipe source=\"delay:right\" dest=\"delay:left\" capacity=\"10000\" latency=\"25\" packet_loss=\"0.01\"/>\n" +
            "     </delay:sliver_type_shaping>\n" +
            "   </sliver_type>\n" +
            "   <interface client_id=\"delay:left\" />\n" +
            "   <interface client_id=\"delay:right\" />\n" +
            "        <services>" +
            "             <login authentication=\"ssh-keys\" hostname=\"dummyhostbridge1\" port=\"22\" username=\"dummyuserbridge1\"/>" +
            "             <login authentication=\"ssh-keys\" hostname=\"dummyhostbridge2\" port=\"22\" username=\"dummyuserbridge2\"/>" +
            "        </services>" +
            " </node>\n" +
            " <link client_id=\"link1\">\n" +
            "    <interface_ref client_id=\"node0:if0\" />\n" +
            "    <interface_ref client_id=\"delay:left\" />\n" +
            "     <property source_id=\"delay:left\" dest_id=\"node0:if0\"/>\n" +
            "\t    <property source_id=\"node0:if0\" dest_id=\"delay:left\"/>\n" +
            "\t    <link_type name=\"lan\"/>\n" +
            " </link>\n" +
            " <link client_id=\"link2\">\n" +
            "   <interface_ref client_id=\"node1:if0\" />\n" +
            "   <interface_ref client_id=\"delay:right\" />\n" +
            "   <property source_id=\"delay:right\" dest_id=\"node1:if0\"/>\n" +
            "\t<property source_id=\"node1:if0\" dest_id=\"delay:right\"/>\n" +
            "\t<link_type name=\"lan\"/>\n" +
            " </link>\n" +
            "</rspec>";

    //PLE doesn't give these broken manifests anymore
//    private static final String manifestPle = "<?xml version=\"1.0\"?>\n" +
//            "<RSpec type=\"SFA\" expires=\"2013-07-18T12:37:03Z\" generated=\"2013-07-04T10:45:38Z\">\n" +
//            "  <network name=\"ple\">\n" +
//            "    <node component_manager_id=\"urn:publicid:IDN+ple+authority+cm\" component_id=\"urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it\" component_name=\"marie.iet.unipi.it\" site_id=\"urn:publicid:IDN+ple:quantavisple+authority+sa\">\n" +
//            "      <hostname>marie.iet.unipi.it</hostname>\n" +
//            "      <location country=\"unknown\" longitude=\"10.3252\" latitude=\"43.5052\"/>\n" +
//            "      <exclusive>FALSE</exclusive>\n" +
//            "      <interface component_id=\"urn:publicid:IDN+ple+interface+node14271:eth0\" client_id=\"14271:165\" ipv4=\"131.114.53.188\"/>\n" +
//            "      <services>\n" +
//            "        <login authentication=\"ssh-keys\" hostname=\"marie.iet.unipi.it\" port=\"22\" username=\"wall3testibbtbe_DebugjFed\"/>\n" +
//            "      </services>\n" +
//            "      <hrn>ple.quantavisple.marie\\.iet\\.unipi\\.it</hrn>\n" +
//            "      <responsew>n/a</responsew>\n" +
//            "      <memw>n/a</memw>\n" +
//            "      <reliabilityy>0</reliabilityy>\n" +
//            "      <responsem>n/a</responsem>\n" +
//            "      <sliver name=\"wall3testibbtbe_DebugjFed\"/>\n" +
//            "    </node>\n" +
//            "    <sliver_defaults>\n" +
//            "      <vsys>vif_up</vsys>\n" +
//            "      <vsys>vif_down</vsys>\n" +
//            "      <vsys>fd_tuntap</vsys>\n" +
//            "      <vsys>promisc</vsys>\n" +
//            "      <vsys>vroute</vsys>\n" +
//            "    </sliver_defaults>\n" +
//            "  </network>\n" +
//            "</RSpec>\n";


    private static String multiSitePleRspec = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<rspec generated=\"2014-02-26T10:40:01.195+01:00\" generated_by=\"Experimental jFed Rspec Editor\" type=\"request\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:jFed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
            "    <node client_id=\"pleNode\" component_id=\"urn:publicid:IDN+ple:ibbtple+node+planck250ple.test.iminds.be\" component_manager_id=\"urn:publicid:IDN+ple:ibbtple+authority+cm\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"plab-vserver\"/>\n" +
            "        <jFed:location x=\"32.0\" y=\"44.0\"/>\n" +
            "        <jFed:nodeDescription>simple-node</jFed:nodeDescription>\n" +
            "        <sliver/>\n" +
            "        <interface client_id=\"pleNode:if0\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"wall2Node\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "        <sliver_type name=\"raw-pc\"/>\n" +
            "        <jFed:location x=\"26.0\" y=\"297.0\"/>\n" +
            "        <jFed:nodeDescription>simple-node</jFed:nodeDescription>\n" +
            "        <interface client_id=\"wall2Node:if0\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"pleNode2\" component_id=\"urn:publicid:IDN+ple:ibbtple+node+planck249ple.test.iminds.be\" component_manager_id=\"urn:publicid:IDN+ple:ibbtple+authority+cm\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"plab-vserver\"/>\n" +
            "        <jFed:location x=\"29.0\" y=\"125.0\"/>\n" +
            "        <sliver/>\n" +
            "        <interface client_id=\"pleNode2:if0\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"wall2Node2\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
            "        <sliver_type name=\"raw-pc\"/>\n" +
            "        <jFed:location x=\"21.0\" y=\"206.0\"/>\n" +
            "        <interface client_id=\"wall2Node2:if0\"/>\n" +
            "    </node>\n" +
            "    <link client_id=\"link5\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+ple:ibbtple+authority+cm\"/>\n" +
            "        <link_type name=\"lan\"/>\n" +
            "        <interface_ref client_id=\"pleNode:if0\"/>\n" +
            "        <interface_ref client_id=\"pleNode2:if0\"/>\n" +
            "    </link>\n" +
            "    <link client_id=\"link6\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
            "        <link_type name=\"lan\"/>\n" +
            "        <interface_ref client_id=\"wall2Node2:if0\"/>\n" +
            "        <interface_ref client_id=\"wall2Node:if0\"/>\n" +
            "    </link>\n" +
            "</rspec>\n";

    private static final String fusecoManifestRspec =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "\n" +
                    "<rspec type=\"manifest\" " +
                    "       xmlns:ns2=\"http://fiteagle.org/rspec/ext/1\" " +
                    "       xmlns=\"http://www.geni.net/resources/rspec/3\"" +
                    "       xmlns:ns3=\"http://fiteagle.org/rspec/ext/1/openstackVMResource\">" + "\n" +
                    "   <node client_id=\"node0\" " +
                    "         component_manager_id=\"urn:publicid:IDN+fuseco.fokus.fraunhofer.de+authority+cm\">" + "\n" +
                    "       <sliver_type name=\"m1.tiny\"><disk_image name=\"fed4fireNightlyTest\"/>" + "\n" +
                    "       </sliver_type>" + "\n" +
                    "       <services>" + "\n" +
                    "          <login authentication=\"ssh-keys\" hostname=\"193.175.132.250\" port=\"8081\" username=\"ubuntu\"/>" + "\n" +
                    "       </services>" + "\n" +
                    "   </node>" + "\n" +
                    "</rspec>";
    private static final String fusecoManifestRspec2 =
            "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "\n" +
                    "<rspec type=\"manifest\" " +
                    "       xmlns:ns2=\"http://fiteagle.org/rspec/ext/1\" " +
                    "       xmlns=\"http://www.geni.net/resources/rspec/3\" " +
                    "       xmlns:ns3=\"http://fiteagle.org/rspec/ext/1/openstackVMResource\">" + "\n" +
                    "   <node client_id=\"node0\" component_manager_id=\"urn:publicid:IDN+fuseco.fokus.fraunhofer.de+authority+cm\">" + "\n" +
                    "      <sliver_type name=\"m1.tiny\">" + "\n" +
                    "         <disk_image name=\"fed4fireNightlyTest\"/>" + "\n" +
                    "      </sliver_type>" + "\n" +
                    "      <services>" + "\n" +
                    "         <login authentication=\"ssh-keys\" hostname=\"193.175.132.250\" port=\"8081\" username=\"ubuntu\"/>" + "\n" +
                    "      </services>" + "\n" +
                    "   </node>" + "\n" +
                    "</rspec>";
}
