% calculateNetMetrics
%
%>> Usage: [distancesMatrix, linkDistances, linkPropDelays, lightpathDistances,...
% lightpathPropDelays, NrUsedTransmittersPerNode, NrUsedReceiversPerNode,...
% NrUsedWavelengthsPerFiber, NrUsedPhysHops, linkTraffic, offeredTraffic,...
% carriedPhysTraffic, carriedVirtTraffic, averPhysicalHops, averVirtualHops,...
% singleHopTraffic, networkCongestion, totalNrOfUsedWavelengths,...
% maximumLinkLoadinNrLightpaths, messagePropagationDelay, ...
% totalNrOfUsedConverters, NrUsedConvertersPerNode, NrUsedConvertersPerLP, averNrUsedConverPerLP] = ...
% calculateNetMetrics(phys, netState, verbose)
%
%>> Abstract: This function calculates the main network performance
% metrics, both the general metrics and the wavelength conversion
% specific metrics. The wavelength conversion metrics describe the
% wavelength converters distribution on the network.
%
%>> Arguments:
% o In:
%
% . netState: NetState Structure. More information about netState in
% section "Structure of netState variable" from Help.
%
% . phys: Phys Structure. More information about netState in section
% "Structure of phys variable" from Help.
%
% . verbose: is a flag. When its value is '1', then all the possible
% statistics are calculated. When its value is '0', then only several
% statistics are calculated.
%
% o Out:
%
% distancesMatrix (NxN): Matrix of distances. As entry (x,y) is the
% euclidean distance in kilometers between the node 'x' and the node 'y'.
%
% . linkDistances(Mx1): Link distances vector for a given physical
% topology. It is a vecor as many rows as 'M' physical links. Each row
% is a physical link 'm', containing the euclidean distance in Km of the
% physical link from node 'x' to node 'y'.
%
% . linkPropDelays(Mx1): Link propagation delays vector for a given
% physical topology. It is a vecor as many rows as 'M' physical links.
% Each row is a physical link 'm', containing the propagation delay in
% 'us' over a physical link from node 'x' to node 'y'.
%
% lightpathDistances(Lx1): Lightpath distances vector for a given
% physical topology. It is a vecor as many rows as 'L' lightpaths. Each
% row is a 'l', containing the euclidean distance in Km of the
% lightpath from node 'i' to node 'j'. It is computed based on the link
% distances.
%
% . lightpathPropDelays(Lx1): Lightpath propagation delays vector for a
% given physical topology. It is a vecor as many rows as 'L' lightpaths.
% Each row is a lightpaths 'l', containing the total propagation delay in
% 'us' in a lightpath established from node 'i' to node 'j'.
%
% NrUsedTransmittersPerNode(1xN): The number of used optical
% transmitters in each node. It is a 1-by-N nodes integer vector, where
% N is the number of nodes.
%
% NrUsedReceiversPerNode(1xN): The number of used optical transmitters
% in each node. It is a 1-by-N nodes integer vector, where N is the
% number of nodes.
%
% NrUsedWavelengthsPerFiber(1xM): The number of Used Wavelengths in
% each fiber link. It is a 1-by-M links integer vector, where M is the
% number of links.
%
% NrUsedPhysHops(1xL): The number of Used Physical Hops in a lightpath.
% It is a 1-by-L lightpaths integer vector, where L is the number of
% lightpaths.
%
% . offeredTraffic(1x1): Total offered traffic. This metric is computed as
% the sum of all the average traffic flows offered onto the network node
% pairs. It is a real value in units of Gbps.
%
% . carriedPhysTraffic(1x1): Total carried physical traffic. This is the
% total traffic carried by the links in the physical topology and it is
% computed as the sum of all the lightpath flows multiplied by the
% number of used links a lightpath. It is a real value in units of Gbps.
%
% . carriedVirtTraffic(1x1): Total carried virtual traffic. This is the
% total traffic carried by the ightpaths in the virtual topology and it
% is computed as the sum of all the lightpath flows. It is a real value
% in units of Gbps.
%
% . linkTraffic(1xM): Vector of the traffic carried by each fiber link.
% It is a vector with 'M' number of links elemnts. It is a real value
% in units of Gbps..
%
% . averVirtualHops(1x1): Average Number of Virtual Hops in the network.
% This metric is the average number of lighpaths which a message has to
% transverse in the virtual topology to arrive to its destination node.
% It is a real value.
%
% . averPhysicalHops(1x1): Average Number of Physical Hops in the network.
% This metric is the average number of physical links which a message
% has to transverse in the physical topology to arrive to its
% destination node. It is a real value.
%
% . singleHopTraffic(1x1): The amount of traffic which is carried in one
% virtual hop. It is a real value in units of Gbps.
% NOTE: This metric is computed asumming that the whole traffic flow
% offered onto a pair of nodes is routed by a lightpath established
% between them, regardless of the lightpath capacity, the number of
% lightpaths estableshed between the pair of nodes and the sub-flows
% between them (number of sub-flows and amount of them).
%
% . networkCongestion(1x1): Value of Network Congestion. It is the
% theoretical value of the network congestion computed as the maximum
% traffic flow offered on any lightpath in the network.
%
% totalNrOfUsedWavelengths(1x1): Total number of used wavelength
% channels in the network.
%
% . maximumLinkLoadinNrLightpaths(1x1): Maximum Link Load in Number of
% Lightpaths. It is defined as the maximum number of lightpaths used in
% any link in the network. It is an integer value.
%
% . messagePropagationDelay(1x1): The propagation delay experienced by a
% message in the network.It is a real value in units of 'useg'.
%
% . totalNrOfUsedConverters(1x1): The total number of used wavelength
% converters in the entire network if the network nodes have wavelength
% conversion capability. It is an integer value.
%
% . NrUsedConvertersPerNode(1xN): The number of used wavelength converters
% in each node if the network nodes have wavelength conversion
% capability. It is a 1-by-N nodes integer vector, where "N" is the number
% of nodes.
%
% . NrUsedConvertersPerLP(1xL): The number of used wavelength converters
% in each lightpath if the network nodes have wavelength conversion
% capability. It is an 1-by-L nodes integer matrix, where "L" is the
% number of lightpaths.
%
% . averNrUsedConverPerLP(1x1): Average number of wavelength converters
% per lightpath. It is a real value.
%
%
function [distancesMatrix, linkDistances, linkPropDelays, lightpathDistances,...
lightpathPropDelays, NrUsedTransmittersPerNode, NrUsedReceiversPerNode,...
NrUsedWavelengthsPerFiber, NrUsedPhysHops, linkTraffic, offeredTraffic,...
carriedPhysTraffic, carriedVirtTraffic, averPhysicalHops, averVirtualHops,...
singleHopTraffic, networkCongestion, totalNrOfUsedWavelengths,...
maximumLinkLoadinNrLightpaths, messagePropagationDelay, ...
totalNrOfUsedConverters, NrUsedConvertersPerNode, NrUsedConvertersPerLP, averNrUsedConverPerLP] = ...
calculateNetMetrics(phys, netState,verbose)
if (nargin==0), help calculateNetMetrics;return, end %help calling
if (nargin~=3), error('1: Incorrect number of arguments.'),end %Number of input arguments different of 7
numberOfNodes=max(max(phys.linkTable));
numberOfLinks=size(phys.linkTable,1);
numberOfLightpaths=size(netState.lightpathRoutingMatrix ,1);
if verbose == 0
distancesMatrix = zeros (numberOfNodes,numberOfNodes);
linkDistances=zeros (numberOfLinks,1);
linkPropDelays=zeros (numberOfLinks,1);
lightpathDistances=zeros (numberOfLightpaths,1);
lightpathPropDelays=zeros (numberOfLightpaths,1);
NrUsedTransmittersPerNode=zeros(1,numberOfNodes);
NrUsedReceiversPerNode=zeros(1,numberOfNodes);
messagePropagationDelay=0;
totalNrOfUsedConverters = 0;
NrUsedConvertersPerNode = zeros (1,numberOfNodes);
NrUsedConvertersPerLP=zeros (1,numberOfLightpaths);
averNrUsedConverPerLP=0;
singleHopTraffic=0;
NrUsedWavelengthsPerFiber= zeros(1,numberOfLinks);
linkTraffic=zeros(1,numberOfLinks);
end
%------------------------------------------------------------------------------------------------
%--------******** Network Performance Metrics*********------------------------------------
%-------------------------------------------------------------------------------------------
%A) DISTANCES AND DELAYS ************************
if verbose == 1
% 1.- Euclidean distances (in Km) between the pairs of nodes
[distancesMatrix]=calculateDistanceMatrix(phys.nodesPlaceMatrix);
% 2.- Distances in Km of the Physical Links
linkDistances=zeros(numberOfLinks,1);
for m=1:numberOfLinks,
linkDistances(m)=distancesMatrix(phys.linkTable(m,1),phys.linkTable(m,2));
end
% 3.- Propagation Delays in 'us' of the Physical Links
% The propagation delay matrix is based on the link distance table.
propagationVelocity=0.2; %km/us
linkPropDelays=linkDistances./propagationVelocity;% distance in km, delay in us
% 4.- Distances in Km of the Lightpaths
% The aforementioned distance is the sum of all partial-euclidean
% distances in each physical hop of a lightpath
lightpathDistances=zeros(numberOfLightpaths,1);
for l=1:numberOfLightpaths,
lightpathLinks=find(netState.lightpathRoutingMatrix (l,:)>0);
lightpathDistances(l)=sum(linkDistances(lightpathLinks));
end
% 5.- Propagation Delays in 'us' of the Lightpaths
% The propagation delay matrix is based on the lightpath distances matrix.
propagationVelocity=0.2; %km/us
lightpathPropDelays=lightpathDistances./propagationVelocity;% distance in km, delay in us
%B) USED RESOURCES *****************************
% 6.- Used Transmitters Per Node & 7.- Used Receivers Per Node
NrUsedTransmittersPerNode=zeros(1,numberOfNodes);
NrUsedReceiversPerNode=zeros(1,numberOfNodes);
for i=1:numberOfNodes,
NrUsedTransmittersPerNode(i)= length(find(netState.lightpathTable(:,2)==i));
NrUsedReceiversPerNode(i)= length(find(netState.lightpathTable(:,3)==i));
end
% 8.- Used Wavelengths Per Fiber Link
NrUsedWavelengthsPerFiber= zeros(1,numberOfLinks);
for m=1:numberOfLinks,
NrUsedWavelengthsPerFiber(m)=length(find(netState.lightpathRoutingMatrix(:,m)>0));
end
end
% 9.- Used Physical Hops a Lightpath
NrUsedPhysHops=zeros(1,numberOfLightpaths);
for l=1:numberOfLightpaths,
NrUsedPhysHops(l)=length(find(netState.lightpathRoutingMatrix(l,:)>0));
end
%C) TRAFFICS ***********************************
% 10.- Total offered traffic to the network
offeredTraffic=sum(netState.flowTable(:,4));
% offeredTraffic=sum(sum(traff_trafficMatrix,1));
% 11.- Total carried traffic by the physical links
lightpathFlows=sum(netState.flowRoutingMatrix,1);% ojo: este no se muetra en dinamico (el lpflows)
carriedPhysTraffic=sum(lightpathFlows.*NrUsedPhysHops);
% 12.- Total carried traffic by the lightpaths
carriedVirtTraffic=sum(lightpathFlows);
if verbose == 1
% 13.-Link Traffic
linkTraffic=zeros(1,numberOfLinks);
for m=1:numberOfLinks,
lightpathIDsOfLink=find(netState.lightpathRoutingMatrix(:,m)>0);
linkTraffic(m)=sum(lightpathFlows(lightpathIDsOfLink));
end
end
%D) NET METRICS ********************************
% 14.-Average Number of Physical Hops in the network
if offeredTraffic==0
averPhysicalHops=0;
else
averPhysicalHops=carriedPhysTraffic/offeredTraffic;
end
% 15.-Average Number of Virtual Hops in the network
if offeredTraffic==0
averVirtualHops=0;
else
averVirtualHops=carriedVirtTraffic/offeredTraffic;
end
if verbose == 1
% 16.-Single Hop Traffic
singleHopTraffic=0;
for i=1:size(netState.flowRoutingMatrix,1)
if length(find(netState.flowRoutingMatrix(i,:)~=0))==1
singleHopTraffic=singleHopTraffic+netState.flowRoutingMatrix(i,find(netState.flowRoutingMatrix(i,:)~=0));
end
end
end
% 17.-Network Congestion
networkCongestion=max(sum(netState.flowRoutingMatrix,1));
% 18.-Total Number of Used Wavelength Channels in the Network
totalNrOfUsedWavelengths=length(find(netState.lightpathRoutingMatrix>0));
% 19.-Maximum Link Load in terms of Number of Used Wavelength Channels in any Fiber Link
maximumLinkLoadinNrLightpaths=max(NrUsedWavelengthsPerFiber);
if verbose == 1
% 20.-Message Propagation Delay
if carriedVirtTraffic==0
messagePropagationDelay = 0;
else
messagePropagationDelay = lightpathFlows*lightpathPropDelays / carriedVirtTraffic;
end
%E) WAVELENGTH CONVERSION METRICS **************
[totalNrOfUsedConverters, NrUsedConvertersPerNode, NrUsedConvertersPerLP, averNrUsedConverPerLP] = ...
calculateConversionMetrics(phys, netState);
end