+# Function to perpare the consul configuration according to the current simulator configuration
+# args: SDNC|NOSDNC <output-file>
+# (Function for test scripts)
+prepare_consul_config() {
+ echo -e $BOLD"Prepare Consul config"$EBOLD
+
+ echo " Writing consul config for "$POLICY_AGENT_APP_NAME" to file: "$2
+
+ if [ $# != 2 ]; then
+ ((RES_CONF_FAIL++))
+ __print_err "need two args, SDNC|NOSDNC <output-file>" $@
+ exit 1
+ fi
+
+ if [ $1 == "SDNC" ]; then
+ echo -e " Config$BOLD including SDNC$EBOLD configuration"
+ elif [ $1 == "NOSDNC" ]; then
+ echo -e " Config$BOLD excluding SDNC$EBOLD configuration"
+ else
+ ((RES_CONF_FAIL++))
+ __print_err "need two args, SDNC|NOSDNC <output-file>" $@
+ exit 1
+ fi
+
+ config_json="\n {"
+ if [ $1 == "SDNC" ]; then
+ config_json=$config_json"\n \"controller\": ["
+ config_json=$config_json"\n {"
+ config_json=$config_json"\n \"name\": \"$SDNC_APP_NAME\","
+ config_json=$config_json"\n \"baseUrl\": \"http://$SDNC_APP_NAME:$SDNC_INTERNAL_PORT\","
+ config_json=$config_json"\n \"userName\": \"$SDNC_USER\","
+ config_json=$config_json"\n \"password\": \"$SDNC_PWD\""
+ config_json=$config_json"\n }"
+ config_json=$config_json"\n ],"
+ fi
+
+
+ config_json=$config_json"\n \"streams_publishes\": {"
+ config_json=$config_json"\n \"dmaap_publisher\": {"
+ config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
+ config_json=$config_json"\n \"dmaap_info\": {"
+ config_json=$config_json"\n \"topic_url\": \"http://$MR_APP_NAME:$MR_INTERNAL_PORT/events/A1-POLICY-AGENT-WRITE\""
+ config_json=$config_json"\n }"
+ config_json=$config_json"\n }"
+ config_json=$config_json"\n },"
+ config_json=$config_json"\n \"streams_subscribes\": {"
+ config_json=$config_json"\n \"dmaap_subscriber\": {"
+ config_json=$config_json"\n \"type\": \"$MR_APP_NAME\","
+ config_json=$config_json"\n \"dmaap_info\": {"
+ config_json=$config_json"\n \"topic_url\": \"http://$MR_APP_NAME:$MR_INTERNAL_PORT/events/A1-POLICY-AGENT-READ/users/policy-agent\""
+ config_json=$config_json"\n }"
+ config_json=$config_json"\n }"
+ config_json=$config_json"\n },"
+
+ config_json=$config_json"\n \"ric\": ["
+
+ rics=$(docker ps | grep ricsim | awk '{print $NF}')
+
+ if [ $? -ne 0 ] || [ -z "$rics" ]; then
+ echo -e $RED" FAIL - the names of the running RIC Simulator cannot be retrieved." $ERED
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+
+ cntr=0
+ for ric in $rics; do
+ if [ $cntr -gt 0 ]; then
+ config_json=$config_json"\n ,"
+ fi
+ config_json=$config_json"\n {"
+ config_json=$config_json"\n \"name\": \"$ric\","
+ config_json=$config_json"\n \"baseUrl\": \"http://$ric:$RIC_SIM_INTERNAL_PORT\","
+ if [ $1 == "SDNC" ]; then
+ config_json=$config_json"\n \"controller\": \"$SDNC_APP_NAME\","
+ fi
+ config_json=$config_json"\n \"managedElementIds\": ["
+ config_json=$config_json"\n \"me1_$ric\","
+ config_json=$config_json"\n \"me2_$ric\""
+ config_json=$config_json"\n ]"
+ config_json=$config_json"\n }"
+ let cntr=cntr+1
+ done
+
+ config_json=$config_json"\n ]"
+ config_json=$config_json"\n}"
+
+
+ printf "$config_json">$2
+
+ echo ""
+}
+
+
+# Start Consul and CBS
+# args: -
+# (Function for test scripts)
+start_consul_cbs() {
+
+ echo -e $BOLD"Starting Consul and CBS"$EBOLD
+
+ __start_container consul_cbs NODOCKERARGS "$CONSUL_APP_NAME" "$CONSUL_EXTERNAL_PORT" "/ui/dc1/kv" \
+ "$CBS_APP_NAME" "$CBS_EXTERNAL_PORT" "/healthcheck"
+}
+
+###########################
+### RIC Simulator functions
+###########################
+
+# Start one group (ricsim_g1, ricsim_g2 or ricsim_g3) with a number of RIC Simulators using a given A interface
+# args: ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>
+# (Function for test scripts)
+start_ric_simulators() {
+
+ echo -e $BOLD"Starting RIC Simulators"$EBOLD
+
+ if [ $# != 3 ]; then
+ ((RES_CONF_FAIL++))
+ __print_err "need three args, ricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
+ exit 1
+ fi
+ echo " $2 simulators using basename: $1 on interface: $3"
+ #Set env var for simulator count and A1 interface vesion for the given group
+ if [ $1 == "ricsim_g1" ]; then
+ G1_COUNT=$2
+ G1_A1_VERSION=$3
+ elif [ $1 == "ricsim_g2" ]; then
+ G2_COUNT=$2
+ G2_A1_VERSION=$3
+ elif [ $1 == "ricsim_g3" ]; then
+ G3_COUNT=$2
+ G3_A1_VERSION=$3
+ else
+ ((RES_CONF_FAIL++))
+ __print_err "need three args, gricsim_g1|ricsim_g2|ricsim_g3 <count> <interface-id>" $@
+ exit 1
+ fi
+
+ # Create .env file to compose project, all ric container will get this prefix
+ echo "COMPOSE_PROJECT_NAME="$RIC_SIM_PREFIX > $SIM_GROUP/ric/.env
+
+ export G1_A1_VERSION
+ export G2_A1_VERSION
+ export G3_A1_VERSION
+
+ docker_args="--scale g1=$G1_COUNT --scale g2=$G2_COUNT --scale g3=$G3_COUNT"
+ app_data=""
+ cntr=1
+ while [ $cntr -le $2 ]; do
+ app=$1"_"$cntr
+ port=0
+ app_data="$app_data $app $port /"
+ let cntr=cntr+1
+ done
+
+ __start_container ric "$docker_args" $app_data
+
+}
+
+###########################
+### Control Panel functions
+###########################
+
+# Start the Control Panel container
+# args: -
+# (Function for test scripts)
+start_control_panel() {
+
+ echo -e $BOLD"Starting Control Panel"$EBOLD
+
+ __start_container control_panel NODOCKERARGS $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_EXTERNAL_PORT "/"
+
+}
+
+##################
+### SDNC functions
+##################
+
+# Start the SDNC A1 Controller
+# args: -
+# (Function for test scripts)
+start_sdnc() {
+
+ echo -e $BOLD"Starting SDNC A1 Controller"$EBOLD
+
+ __start_container sdnc NODOCKERARGS $SDNC_APP_NAME $SDNC_EXTERNAL_PORT "/apidoc/explorer"
+
+}
+
+#####################
+### MR stub functions
+#####################
+
+# Start the Message Router stub interface in the simulator group
+# args: -
+# (Function for test scripts)
+start_mr() {
+
+ echo -e $BOLD"Starting Message Router 'mrstub'"$EBOLD
+
+ __start_container mr NODOCKERARGS $MR_APP_NAME $MR_EXTERNAL_PORT "/"
+
+}
+
+################
+### CR functions
+################
+
+# Start the Callback reciver in the simulator group
+# args: -
+# (Function for test scripts)
+start_cr() {
+
+ echo -e $BOLD"Starting Callback Receiver"$EBOLD
+
+ __start_container cr NODOCKERARGS $CR_APP_NAME $CR_EXTERNAL_PORT "/"
+
+}
+
+###########################
+### Policy Agents functions
+###########################
+
+# Start the policy agwent
+# args: -
+# (Function for test scripts)
+start_policy_agent() {
+
+ echo -e $BOLD"Starting Policy Agent"$EBOLD
+
+ __start_container policy_agent NODOCKERARGS $POLICY_AGENT_APP_NAME $POLICY_AGENT_EXTERNAL_PORT "/status"
+
+}
+
+# All calls to the agent will be directed to the agent REST interface from now on
+# args: -
+# (Function for test scripts)
+use_agent_rest() {
+ echo -e $BOLD"Using agent REST interface"$EBOLD
+ export ADAPTER=$RESTBASE
+ echo ""
+}
+
+# All calls to the agent will be directed to the agent dmaap interface from now on
+# args: -
+# (Function for test scripts)
+use_agent_dmaap() {
+ echo -e $BOLD"Using agent DMAAP interface"$EBOLD
+ export ADAPTER=$DMAAPBASE
+ echo ""
+
+}
+
+# Turn on debug level tracing in the agent
+# args: -
+# (Function for test scripts)
+set_agent_debug() {
+ echo -e $BOLD"Setting agent debug"$EBOLD
+ curl $LOCALHOST$POLICY_AGENT_EXTERNAL_PORT/actuator/loggers/org.oransc.policyagent -X POST -H 'Content-Type: application/json' -d '{"configuredLevel":"debug"}' &> /dev/null
+ if [ $? -ne 0 ]; then
+ __print_err "could not set debug mode" $@
+ return 1
+ fi
+ return 0
+ echo ""
+}
+
+# Perform curl retries when making direct call to the agent for the specified http response codes
+# Speace separated list of http response codes
+# args: [<response-code>]*
+use_agent_retries() {
+ echo -e $BOLD"Do curl retries to the agent REST inteface for these response codes:$@"$EBOLD
+ AGENT_RETRY_CODES=$@
+ echo ""
+}
+
+#################
+### Log functions
+#################
+
+# Check the agent logs for WARNINGs and ERRORs
+# args: -
+# (Function for test scripts)
+
+check_policy_agent_logs() {
+ __check_container_logs "Policy Agent" $POLICY_AGENT_APP_NAME $POLICY_AGENT_LOGPATH
+}
+
+check_control_panel_logs() {
+ __check_container_logs "Control Panel" $CONTROL_PANEL_APP_NAME $CONTROL_PANEL_LOGPATH
+}
+
+__check_container_logs() {
+ dispname=$1
+ appname=$2
+ logpath=$3
+ echo -e $BOLD"Checking $dispname container $appname log ($logpath) for WARNINGs and ERRORs"$EBOLD
+
+ #tmp=$(docker ps | grep $appname)
+ tmp=$(docker ps -q --filter name=$appname) #get the container id
+ if [ -z "$tmp" ]; then #Only check logs for running Policy Agent apps
+ echo $dispname" is not running, no check made"
+ return
+ fi
+ foundentries="$(docker exec -it $tmp grep WARN $logpath | wc -l)"