No BSD License  

Highlights from
MatPlanWDM v0.5

image thumbnail
from MatPlanWDM v0.5 by Pablo Pavon MariƱo
Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)

generateFlow (generatorParameters, simTime, netState, phys)
%>>>generateFlow 
%
%This function returns the arriving flow flowData information (flow ingress
%and egress node, flow average rate in Gbps, flow duration in seconds, flow
%priority) and the time when the next flow should arrive (timeToNextFlow).

%>>>The inputs are:
%
% 1) generatorParameters: parameters of the generator what are taken from 
%    the guide aplication (Average flow rate (Gbps) Average flow duration (s)
%    Flag truncated exponential (0=not truncated, 1=truncated)).
%
% 2) simTime: current moment of simulation.
%
% 3) netState: NetState Structure. More information about netState in
%    section "Structure of netState variable" from Help. 
%
% 4) phys: Phys Structure. More information about netState in section 
%    "Structure of phys variable" from Help.
%
%>>>The outputs are:
%
% 1) timeToNextEvent: time that there is to the next event. 
%
% 2) flowProperties: is a struct with the properties of the flow to
%   process. It has the next fields:
%       -flowDuration: duration of the flow. This duration is expresed in seg.   
%       -flowAverageRate: average rate of the flow what has caused the event.
%       This bit rate is expresed in Gbps. 
%       -pairIngressEgress: vector with two positions and (Ingress Node Id,
%       Egress Node Id). 
%       -flowPriority: priority of the flow.
%       -flowSerialNumber: serial number of the flow.
%       -flowSetUpTime: arrival time of the flow.
%
% 3) exitFlag: If exitFlag = 0, the processing of the generator parameters
%   string was succesful. If exitFlag = -1, the processing of the generator
%   parameters string was failed.  
%
% 4) exitMsg: Exit Message.
%
%


function [timeToNextEvent , flowProperties, exitFlag, exitMsg] = generateFlow (generatorParameters, simTime, netState, phys)

flowProperties = struct('flowDuration',[],'flowAverageRate',[],'pairIngressEgress',[],'flowPriority',[],'flowSerialNumber',[],'flowSetUpTime',[]);

global firstTime;
global generatorListOfPendingEvents;
global averageRate;
global averageDuration;
global IAT;
global truncatedExponentialFlag;
global rate;
global duration;
global truncated;

exitFlag=0;
exitMsg='';
timeToNextEvent=0;
flowProperties=[];

if isempty(firstTime)

    firstTime=1;

    s=pwd;
    s=[s '\data\traffics\*.traff'];
    c=dir(s);
    traffMatrixs = struct2cell(c);
    traffMatrixs=traffMatrixs(1,:)';
    numberOfTraffMatrixs=length(traffMatrixs);

    if isempty(numberOfTraffMatrixs), 
        exitMsg='No valid parameters'; 
        exitFlag=-1;
        netState=[];
        return
    end

    %%%%%%%%%%%%%%%%%%%%%%%%0. PARAMETERS PROCESSING %%%%%%%%%%%%%%%%%%%%%%%%%
    %We define the default parameter values 
    cellOfDefaultParameters=cell(4,4);
    cellOfDefaultParameters(1,1:4) = {['rate'], ['0.2'], ['numeric'], ['[0.000001,inf)']};
    cellOfDefaultParameters(2,1:4) = {['duration'], ['120'], ['integer'], ['[1,inf)']};   
    cellOfDefaultParameters(3,1:4) = {['truncated'], ['1'], ['boolean'], ['{0,1}']};
    cellOfDefaultParameters(4,1:4) = {['traffMatrix'], ['simplenet4.traff'], ['string'], [traffMatrixs]};

    %We process the string of the algorithm parameters      
    [exitFlagOfProcessParam exitMsgOfProcessParam structOfReadParameters] = ...
        processAlgorithmParameters (generatorParameters, cellOfDefaultParameters);

    if (exitFlagOfProcessParam ~= 0)
        exitFlag = -1;
        exitMsg = 'Bad Algorithm Parameters';
        return
    end

    fullpathname=[pwd '\data\traffics\' structOfReadParameters.traffMatrix];
    [trafficMatrix] = IO_readTraffFile(fullpathname);

    numberOfNodes=phys.N;
    if(length(trafficMatrix)~=numberOfNodes)
        exitFlag = -2;
        errordlg('The number of Nodes from Traffic Matrix and the number of Nodes from Physical Topology are different','modal');
        return
    end   

    averageRate=structOfReadParameters.rate;
    averageDuration=structOfReadParameters.duration;
    truncatedExponentialFlag=structOfReadParameters.truncated;

    IAT=zeros(numberOfNodes,numberOfNodes);
    for ingressNode = 1:numberOfNodes
        for egressNode = 1:numberOfNodes
            if(ingressNode~=egressNode)
                IAT(ingressNode,egressNode)= averageRate*averageDuration/trafficMatrix(ingressNode,egressNode);
            end
        end
    end

    timeToNextEvent = exprnd(IAT);
    for ingressNode = 1:numberOfNodes
        for egressNode = 1:numberOfNodes
            if(ingressNode~=egressNode)
                generatorListOfPendingEvents = [generatorListOfPendingEvents;[timeToNextEvent(ingressNode,egressNode) ingressNode egressNode]];
            end
        end
    end

    generatorListOfPendingEvents = sortrows(generatorListOfPendingEvents,1);
    timeToNextEvent = abs(simTime-generatorListOfPendingEvents(1,1));
    flowProperties.flowDuration = [];
    flowProperties.flowAverageRate = []; %Gbps
    flowProperties.pairIngressEgress = [];
    flowProperties.flowPriority = 0;
    flowProperties.flowSerialNumber = -1;
    flowProperties.flowSetUpTime = -1;
    
else

    flowProperties.flowDuration = exprnd(averageDuration);
    flowProperties.flowAverageRate = exprnd(averageRate); %Gbps
    flowProperties.pairIngressEgress = [generatorListOfPendingEvents(1,2:3)];
    flowProperties.flowPriority = 0;
    flowProperties.flowSerialNumber = -1;
    flowProperties.flowSetUpTime = -1;
        
    if (truncatedExponentialFlag==1)
        while (flowProperties.flowAverageRate>phys.lightpathCapacity)
            flowProperties.flowAverageRate = exprnd(averageRate);
        end
    end
    
    generatorListOfPendingEvents(1,1) = exprnd(IAT(flowProperties.pairIngressEgress(1),flowProperties.pairIngressEgress(2))) + simTime;
    generatorListOfPendingEvents = sortrows(generatorListOfPendingEvents,1);
    timeToNextEvent = abs(simTime-generatorListOfPendingEvents(1,1));
    
end




Contact us