No BSD License  

Highlights from
MatPlanWDM v0.5

image thumbnail

MatPlanWDM v0.5

by

 

29 Jan 2007 (Updated )

Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)

io_writeXML(metadata, phys, sweepOfNetStates, XMLfilename, DTDpathname)
%%%COMMENTS:
%The function writes a XML file.
%INPUT arguments:
    %1)metadata: struct with metadata info.
    %2)phys: struct with phys info.
    %3)netState: struct with netState info.
    %4)XMLfilename: Filename or full pathname where the XML file will be 
    %  stored.
    %5)DTDpathname: Pathname where the "DOCTYPE.dtd" is stored. 
    %The "DOCTYPE.dtd" is the DTD (Document Type Definition) file used for
    %validating the XML file.
    %NOTE: This info is necessary to write the DOC TYPE declaration in the XML
    %file

function io_writeXML(metadata, phys, sweepOfNetStates, XMLfilename, DTDpathname)

import org.apache.xerces.dom.CoreDocumentImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import java.io.FileOutputStream;
import java.io.File;

%1. --------- DOM DEFINITION AND ROOT NODE SETUP ------------------------
% We Create the Document Object Model
DOMnode = CoreDocumentImpl();
% Create a document type node and add it to the document.
DocType = DOMnode.createDocumentType('DOCTYPE', [], DTDpathname );
DOMnode.appendChild(DocType);
% We Create the Root Node and add it to the document.
docRootNode=DOMnode.createElement('network');
DOMnode.appendChild(docRootNode);

%NETWORK METADATA 
%We add the metadata as attributes in the root node
docRootNode.setAttribute('title', metadata.title);
docRootNode.setAttribute('author', metadata.author);
docRootNode.setAttribute('date', metadata.date);
docRootNode.setAttribute('multihourPlanning', metadata.multihourPlanning);
docRootNode.setAttribute('planningAlgorithmFile', metadata.planningAlgorithmFile);
docRootNode.setAttribute('planningAlgorithmParametersString', metadata.planningAlgorithmParametersString);
docRootNode.setAttribute('flowGeneratorFile', metadata.flowGeneratorFile);
docRootNode.setAttribute('flowGeneratorParametersString', metadata.flowGeneratorParametersString);
docRootNode.setAttribute('trafficMatrixFile', metadata.trafficMatrixFile);
docRootNode.setAttribute('description', metadata.description);

%2. -------- NETWORK LAYER NODES DEFINITION --------------
%We estimate if netState is empty (and therefore, the later 'trafficDemand' and 'virtualTopology' are not necessary)
for timeSlot=1:size(sweepOfNetStates)
    netStateIsEmpty = 0;
    namesOfNetStateFields = fieldnames(sweepOfNetStates{timeSlot});
    for index = 1:length(namesOfNetStateFields),
        if isempty(getfield(sweepOfNetStates{timeSlot},namesOfNetStateFields{index})), netStateIsEmpty = 1; , break, end
    end

    if netStateIsEmpty == 0, 
        %2.1) %%%%%%%%%%%%%%%% TRAFFIC DEMAND LAYER (OPTIONAL) %%%%%%%%%%%%%%%%
        %We write the info about the TRAFFIC DEMAND layer

        layerElement = DOMnode.createElement('layer');
        layerElement.setAttribute('id', 'trafficDemand');
        layerElement.setAttribute('numberOfTimeSlot',num2str(timeSlot));

        %We create the traffic flow demands:
        numberOfFlows = size(sweepOfNetStates{timeSlot}.flowTable,1);
        for flowID = 1:numberOfFlows
            flowElement = DOMnode.createElement('flow'); 
            flowElement.setAttribute('id',num2str(flowID));
            flowElement.setAttribute('serialNumber',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,1)))
            flowElement.setAttribute('origNodeId',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,2)));
            flowElement.setAttribute('destNodeId',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,3)));
            flowElement.setAttribute('flowAverageRateDemand',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,4)));
            if sweepOfNetStates{timeSlot}.flowTable(flowID,5) ~= -1, flowElement.setAttribute('flowPriority',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,5))), end
            if sweepOfNetStates{timeSlot}.flowTable(flowID,6) ~= -1, flowElement.setAttribute('flowInitTime',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,6))), end
            if sweepOfNetStates{timeSlot}.flowTable(flowID,7) ~= -1, flowElement.setAttribute('flowDuration',num2str(sweepOfNetStates{timeSlot}.flowTable(flowID,7))), end

            %We compute the routing of the current lightpath
            routingElement = DOMnode.createElement('flowRouting');
            lpIDsOfThisFlow = find(sweepOfNetStates{timeSlot}.flowRoutingMatrix (flowID,:)~=0);
            for thisLP = lpIDsOfThisFlow,
                lightpathElement = DOMnode.createElement('lightpathInFlow');
                lightpathElement.setAttribute('id',num2str(thisLP));
                lightpathElement.setAttribute('averageRate',num2str(sweepOfNetStates{timeSlot}.flowRoutingMatrix(flowID,thisLP)));
                routingElement.appendChild(lightpathElement);  
            end
            flowElement.appendChild(routingElement);

            layerElement.appendChild(flowElement);
        end

        docRootNode.appendChild(layerElement);


        %2.2) %%%%%%%%%%%%%%%% VIRTUAL TOPOLOGY LAYER (OPTIONAL) %%%%%%%%%%%%%%%%
        % We write the info about the virtual topology layer
        layerElement = DOMnode.createElement('layer');
        layerElement.setAttribute('id', 'virtualTopology');
        layerElement.setAttribute('numberOfTimeSlot',num2str(timeSlot));
        
        %We create the lightpaths:
        numberOfLightpaths = size(sweepOfNetStates{timeSlot}.lightpathTable,1);
        for lpID = 1:numberOfLightpaths
            lightpathElement = DOMnode.createElement('lightpath'); 
            lightpathElement.setAttribute('id',num2str(lpID));
            lightpathElement.setAttribute('serialNumber',num2str(sweepOfNetStates{timeSlot}.lightpathTable(lpID,1)))
            lightpathElement.setAttribute('origNodeId',num2str(sweepOfNetStates{timeSlot}.lightpathTable(lpID,2)));
            lightpathElement.setAttribute('destNodeId',num2str(sweepOfNetStates{timeSlot}.lightpathTable(lpID,3)));

            %We compute the routing of the current lightpath
            routingElement = DOMnode.createElement('lightpathRouting');
            linkIDsOfThisLP = find(sweepOfNetStates{timeSlot}.lightpathRoutingMatrix (lpID,:)~=0);
            for thisFibre = linkIDsOfThisLP,
                fibreElement = DOMnode.createElement('fibreInLightpath');
                fibreElement.setAttribute('id',num2str(thisFibre));
                fibreElement.setAttribute('wavelengthId',num2str(sweepOfNetStates{timeSlot}.lightpathRoutingMatrix(lpID,thisFibre)));
                routingElement.appendChild(fibreElement);  
            end
            lightpathElement.appendChild(routingElement);

            layerElement.appendChild(lightpathElement);
        end

        docRootNode.appendChild(layerElement);
    end
end
%2.3) %%%%%%%%%%%%%%%% PHYSICAL TOPOLOGY LAYER (MANDATORY) %%%%%%%%%%%%%%%%
%We write the info about the physical topology layer
layerElement = DOMnode.createElement('layer');
layerElement.setAttribute('id', 'physicalTopology');
layerElement.setAttribute('numberOfTimeSlot',num2str(-1));

%We obtain the next data
numberOfNodes = phys.N;
numberOfLinks = phys.M;
numberOfLevels = size(phys.levelMatrix,1);

%We create the nodes:
for nodeID = 1:numberOfNodes,
    nodeElement = DOMnode.createElement('node'); 
    nodeElement.setAttribute('id', num2str(nodeID));
    nodeElement.setAttribute('nodeName', phys.nodeName{nodeID});
    nodeElement.setAttribute('xCoord',num2str(phys.nodesPlaceMatrix(nodeID,1)));
    nodeElement.setAttribute('yCoord',num2str(phys.nodesPlaceMatrix(nodeID,2)));
    nodeElement.setAttribute('nodePopulation',num2str(phys.nodePopulation(nodeID)));
    nodeElement.setAttribute('nodeTimezone',num2str(phys.nodeTimezone(nodeID)));
    nodeElement.setAttribute('nodeLevel',num2str(phys.nodeLevel(nodeID)));
    
    eoTxElement = DOMnode.createElement('eoTransmitter');
    eoTxElement.setAttribute('number',num2str(phys.numberTxPerNode(nodeID)));
    nodeElement.appendChild(eoTxElement);
    
    oeRxElement = DOMnode.createElement('oeReceiver');
    oeRxElement.setAttribute('number',num2str(phys.numberRxPerNode(nodeID)));
    nodeElement.appendChild(oeRxElement);
    
    wcElement = DOMnode.createElement('wc');
    wcElement.setAttribute('number',num2str(phys.numberTWCPerNode(nodeID)));
    nodeElement.appendChild(wcElement);
    
    layerElement.appendChild(nodeElement);
end

%We create the links:
for linkID = 1:numberOfLinks,
    fibreElement = DOMnode.createElement('fibre');
    fibreElement.setAttribute('id',num2str(linkID));
    fibreElement.setAttribute('origNodeId',num2str(phys.linkTable(linkID,1)));
    fibreElement.setAttribute('destNodeId',num2str(phys.linkTable(linkID,2)));
    fibreElement.setAttribute('linkLengthInKm',num2str(phys.linkLengthInKm(linkID)));
    fibreElement.setAttribute('numberWavelengths',num2str(phys.numberWavelengthPerFiber(linkID)));
    
    layerElement.appendChild(fibreElement);  
end

%We create the levels:
levelMatrixElement = DOMnode.createElement('levelInformationMatrix');
for levelIDOrig = 1:numberOfLevels,
    for levelIDDest = 1:numberOfLevels,
        factorElement = DOMnode.createElement('factor');
        factorElement.setAttribute('idOrig',num2str(levelIDOrig));
        factorElement.setAttribute('idDest',num2str(levelIDDest));
        factorElement.setAttribute('value',num2str(phys.levelMatrix(levelIDOrig,levelIDDest)));
    
        levelMatrixElement.appendChild(factorElement);      
    end
end
layerElement.appendChild(levelMatrixElement);
    
lightpathCapacityElement = DOMnode.createElement('lightpathCapacity');
lightpathCapacityElement.setAttribute('value',num2str(phys.lightpathCapacity));
layerElement.appendChild(lightpathCapacityElement);

docRootNode.appendChild(layerElement);
    

%3. -------- XML WRITING --------------
%We write the XML file with the info in the DOM
format = OutputFormat(DOMnode);
% to generate a file output use fileoutputstream instead of system.out
serializer = XMLSerializer(FileOutputStream(File(XMLfilename)), format);
serializer.serialize(DOMnode);






Contact us