blob: a12e388cf75d8388972de64910de45e88b125b4e [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 Ericsson Telecom AB //
// //
// All rights reserved. This program and the accompanying materials //
// are made available under the terms of the Eclipse Public License v2.0 //
// which accompanies this distribution, and is available at //
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html //
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_CLL_PTCDeployment_PrivateFunctions
//
// Purpose:
// This module contains the implementation of the EPTF_PTCDeployment private functions.
//
// Module depends on:
// <EPTF_CLL_Common_Definitions>
// <EPTF_CLL_PTCDeployment_Definitions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_Logging_Functions>
//
// Current Owner:
// Zsolt Szalai (EZSOSZA)
//
// Last Review Date:
// 2007-11-14
//
// Detailed Comments:
// This module contains the private functions for EPTF_PTCDeployment.
//
///////////////////////////////////////////////////////////////
module EPTF_CLL_PTCDeployment_PrivateFunctions {
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_PTCDeployment_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Logging_Functions all;
friend module EPTF_CLL_PTCDeployment_Functions;
///////////////////////////////////////////////////////////
// Function: f_PTCD_role_in_database
//
// Purpose:
// Decides whether there is such a role in the database.
//
// Parameters:
// pl_role - *in* *charstring* - name of the role
// pl_roleindex - *out* *integer* - the index of the role in the database
//
// Return Value:
// Boolean - true if the role is present
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_PTCD_role_in_database(in charstring pl_role, out integer pl_roleindex) runs on EPTF_PTCD_CT return boolean {
var integer i := 0;
while (i < sizeof(v_roledatabase) and v_roledatabase[i].role != pl_role){i := i+1;}
if (i == sizeof(v_roledatabase)) {return false;}
else {pl_roleindex := i; return true;}
}
///////////////////////////////////////////////////////////
// Function: f_PTCD_choose_host
//
// Purpose:
// Main function on choosing the host from the role.
//
// Parameters:
// pl_hostdeploymentlist - *in* <EPTF_HostDeploymentEntryList> - list of hosts and weights
// pl_method - *in* *integer* - methodology of choosing the host
//
// Return Value:
// charstring - the host
//
// Errors:
// Gives back "" on error
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_PTCD_choose_host(in EPTF_HostDeploymentEntryList pl_hostdeploymentlist, in integer pl_method) runs on EPTF_PTCD_CT return charstring {
var EPTF_HostDeploymentEntryList vl_hostlist:={};
//filter for invalid hosts(empty host, or weight leq 0)
for (var integer i:=0,j:=0;i<sizeof(pl_hostdeploymentlist);i:=i+1){
if (pl_hostdeploymentlist[i].host != "" and not pl_hostdeploymentlist[i].weight<=0){
vl_hostlist[j] := pl_hostdeploymentlist[i];
j:=j+1;
}
}
// filter for emptyness
if (sizeof(vl_hostlist)==0){return "";}
// get the host
return vl_hostlist[f_PTCD_probrandomindex(vl_hostlist, pl_method)].host;
}
///////////////////////////////////////////////////////////
// Function: f_PTCD_probrandomindex
//
// Purpose:
// Gets a random index from hostlist according to probability calculations.
//
// Parameters:
// pl_hostdeploymentlist - *in* <EPTF_HostDeploymentEntryList> - list of hosts and weights
//
// Return Value:
// integer - an index in the hostlist
//
// Errors:
// -
//
// Detailed Comments:
// Works in thw different way: Deterministic and using rnd to choose the index.
//
///////////////////////////////////////////////////////////
private function f_PTCD_probrandomindex(in EPTF_HostDeploymentEntryList pl_hostdeploymentlist, in integer method) runs on EPTF_PTCD_CT return integer {
var integer size := sizeof(pl_hostdeploymentlist);
if (method == 1){
var EPTF_IntegerList burstlist := {};
var EPTF_FloatList rof;
for (var integer i:=0;i<size;i:=i+1){
rof[i] := int2float(pl_hostdeploymentlist[i].weight);
}
var float sum:=0.0;
for (var integer i:=0;i<sizeof(rof);i:=i+1){sum := sum + rof[i]}
// normalize
for(var integer i:=0;i<size;i:=i+1) {
rof[i] := rof[i]/sum;
}
var integer r := 0;
for(var integer i:=0;i<size;i:=i+1) {
if (i>=sizeof(v_currentBurst)) {v_currentBurst[i] := 0.0;}
v_currentBurst[i] := v_currentBurst[i]+rof[i];
burstlist[i] := float2int(v_currentBurst[i]);
v_currentBurst[i] := v_currentBurst[i] - int2float(burstlist[i]);
if (burstlist[i] == 1) {r := i;}
}
log(burstlist, v_currentBurst, rof);
return r;
} else {
// all inputs are valid now!
var float scale := 100.0;
if (sizeof(pl_hostdeploymentlist) == 1){return 0;}
var EPTF_IntegerList roi;
// get the weights in a record of integer
for (var integer i:=0;i<size;i:=i+1){
roi[i] := pl_hostdeploymentlist[i].weight;
}
var integer sum := f_sumroi(roi);
// roi := scanl1(add,map(f_calcpercent,roi));
roi[0] := float2int((int2float(roi[0])/int2float(sum)) * scale);
for (var integer i:=1;i<size-1;i:=i+1){
roi[i] := float2int((int2float(roi[i])/int2float(sum)) * scale) + roi[i-1];
}
roi[size-1] := float2int(scale);
var integer rnum := float2int(rnd()*scale);
var integer i := 0;
// search for the proper interval and return it
while(rnum>=roi[i]){i:=i+1;}
return i;
}
}
///////////////////////////////////////////////////////////
// Function: f_sumroi
//
// Purpose:
// Sums up the elements of a record of integer.
//
// Parameters:
// roi - *in* <EPTF_IntegerList> - list of integers
//
// Return Value:
// integer - The sum
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
private function f_sumroi(in EPTF_IntegerList roi) return integer {
var integer sum:=0;
for (var integer i:=0;i<sizeof(roi);i:=i+1){sum := sum + roi[i]}
return sum;
}
///////////////////////////////////////////////////////////
// Function: f_PTCD_AddRole
//
// Purpose:
// Adds a role to the end of the database
//
// Parameters:
// pl_ptcdentry - *in* <EPTF_PtcDeploymentEntry> - a role
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_PTCD_AddRole(in EPTF_PtcDeploymentEntry pl_ptcdentry) runs on EPTF_PTCD_CT {
v_roledatabase[sizeof(v_roledatabase)] := pl_ptcdentry;
}
///////////////////////////////////////////////////////////
// Function: f_PTCD_RemoveHost
//
// Purpose:
// Removes the given host from a role
//
// Parameters:
// pl_roleindex - *in* *integer* - the role's index
// pl_host - *in* *charstring* - the host to erease
//
// Return Value:
// -
//
// Errors:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_PTCD_RemoveHost(in integer pl_roleindex, in charstring pl_host) runs on EPTF_PTCD_CT {
var EPTF_HostDeploymentEntryList data:={};
for (var integer i:=0;i<sizeof(v_roledatabase[pl_roleindex].deployment);i:=i+1){
if (v_roledatabase[pl_roleindex].deployment[i].host != pl_host) {
data[sizeof(data)] := v_roledatabase[pl_roleindex].deployment[i];
}
}
v_roledatabase[pl_roleindex].deployment := data;
}
group Logging {
///////////////////////////////////////////////////////////
// Function: f_EPTF_PTCDeployment_error
//
// Purpose:
// Function to log an error from PTCDeployment feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_PTCDeployment_error(in charstring pl_message)
runs on EPTF_PTCD_CT
{
f_EPTF_Logging_error(true, tsp_EPTF_PTCDeployment_loggingComponentMask&": "&pl_message);
f_EPTF_Base_stopAll();
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_PTCDeployment_warning
//
// Purpose:
// Function to log a warning from PTCDeployment feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_PTCDeployment_warning(in @lazy charstring pl_message)
runs on EPTF_PTCD_CT
{
f_EPTF_Logging_warningV2(pl_message, v_PTCDeployment_loggingMaskId, {c_EPTF_PTCDeployment_loggingClassIdx_Warning});
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_PTCDeployment_debug
//
// Purpose:
// Function to log a debug message from PTCDeployment feature.
//
// Parameters:
// - pl_message - *in* *charstring* - the message to log
//
// Return Value:
// -
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_PTCDeployment_debug(in @lazy charstring pl_message)
runs on EPTF_PTCD_CT
{
f_EPTF_Logging_debugV2(pl_message, v_PTCDeployment_loggingMaskId, {c_EPTF_PTCDeployment_loggingClassIdx_Debug});
}
///////////////////////////////////////////////////////////
// Function: f_EPTF_PTCDeployment_debugEnabled
//
// Purpose:
// Function to check if debug is enabled for PTCDeployment
//
// Parameters:
// -
//
// Return Value:
// *boolean* - true if debug enalbed
//
// Errors & assertions:
// -
//
// Detailed Comments:
// -
//
///////////////////////////////////////////////////////////
friend function f_EPTF_PTCDeployment_debugEnabled()
runs on EPTF_PTCD_CT
return boolean
{
return f_EPTF_Logging_isEnabled(v_PTCDeployment_loggingMaskId, c_EPTF_PTCDeployment_loggingClassIdx_Debug);
}
} // group Logging
}