From 103db8d16cb1ec4502b0101fa5b0d2c86d7aa5c6 Mon Sep 17 00:00:00 2001 From: kharade <rohan.kharade@openairinterface.org> Date: Thu, 10 Jun 2021 15:57:39 +0200 Subject: [PATCH] core-network.sh script cleaned --- docker-compose/core-network.sh | 249 ++++++++++----------- docker-compose/docker-compose-gnbsim.yaml | 3 - docker-compose/docker-compose-vpp-upf.yaml | 4 +- docs/DEPLOY_SA5G_WITH_DS_TESTER.md | 19 +- docs/DEPLOY_SA5G_WITH_GNBSIM.md | 26 ++- 5 files changed, 162 insertions(+), 139 deletions(-) diff --git a/docker-compose/core-network.sh b/docker-compose/core-network.sh index 03f90bea..669b7df0 100755 --- a/docker-compose/core-network.sh +++ b/docker-compose/core-network.sh @@ -1,12 +1,15 @@ +## Author: Sagar Arora +## Revised by: Rohan + #!/bin/bash # Functioning of the script # 1. Start # 1.1 Start the core network components (Mysql ---> NRF ---> AMF ---> SMF --> SPGWU) -# 1.2 Check if the components started properly (skip) -# 1.3 Check if the components are healthy, calculate individual time -# 1.4 Check if the components are connected and core network is configured properly -# 1.5 Green light +# 1.1.1 Start the core network components (Mysql ---> NRF ---> AMF ---> SMF --> VPP-UPF) +# 1.2 Check if the components are healthy, calculate individual time +# 1.3 Check if the components are connected and core network is configured properly +# 1.4 Green light # 2. Stop RED='\033[0;31m' @@ -17,131 +20,121 @@ WHITE='\033[0;97m' STATUS=0 #STATUS 0 exit safe STATUS 1 exit with an error if [[ $1 == 'start' ]]; then - start_time=$(date +%s%N | cut -b1-13) - if [[ $2 == 'nrf' ]]; then - echo -e "${BLUE}Starting 5gcn components in the order nrf, mysql, amf, smf, spgwu${NC}..." - docker-compose -f docker-compose.yaml -p 5gcn up -d - elif [[ $2 == 'gnbsim' ]]; then - echo -e "${BLUE}Starting gnbsim ${NC}..." - docker-compose -f docker-compose-gnbsim.yaml up -d gnbsim$3 - elif [[ $2 == 'gnbsim-vpp' ]]; then - echo -e "${BLUE}Starting gnbsim ${NC}..." - docker-compose -f docker-compose-gnbsim.yaml up -d gnbsim-vpp - elif [[ $2 == 'vpp-upf' ]]; then - echo -e "${BLUE}Starting 5gcn with vpp-upf ${NC}..." - docker-compose -f docker-compose-vpp-upf.yaml up -d oai-amf - sleep 5 - docker-compose -f docker-compose-vpp-upf.yaml up -d oai-smf - else - echo -e "${BLUE}Starting 5gcn components in the order mysql, amf, smf, spgwu${NC}..." - docker-compose -f docker-compose-no-nrf.yaml -p 5gcn up -d - fi - echo -e "${GREEN}Checking the health status of the containers${NC}..." - for loop in $(seq 1 25); do - mysql_health=$(docker inspect --format='{{json .State.Health.Status}}' mysql) - if [[ $2 == 'nrf' ]]; then - nrf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-nrf) - elif [[ $2 == 'gnbsim' ]]; then - gnbsim_health=$(docker inspect --format='{{json .State.Health.Status}}' gnbsim) - - fi - amf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-amf) - smf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-smf) - if [[ $2 == 'vpp-upf' ]];then - vpp_upf_health=$(docker inspect --format='{{json .State.Health.Status}}' vpp-upf) - sleep 5 - upf_logs=$(docker logs oai-smf | grep 'handle_receive(16 bytes)') - else - spgwu_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-spgwu) - upf_logs=$(docker logs oai-spgwu | grep 'Received SX HEARTBEAT RESPONSE') - fi - if [[ ${mysql_health} == '"healthy"' && ${amf_health} == '"healthy"' && ${smf_health} == '"healthy"' && ${spgwu_health} == '"healthy"' && $2 != 'nrf' && $2 != 'gnbsim' ]]; then - echo -e "\n${GREEN}All components are healthy${NC}..." - STATUS=0 CVZxbag - break - elif [[ $2 == 'gnbsim' ]]; then - echo -ne "gnbsim : $gnbsim_health\033[0K\r" - if [[ ${gnbsim_health} == '"healthy"' ]]; then - STATUS=0 - break - fi - sleep 2 - elif [[ ${mysql_health} == '"healthy"' && ${amf_health} == '"healthy"' && ${smf_health} == '"healthy"' && ${spgwu_health} == '"healthy"' && ${nrf_health} == '"healthy"' && $2 == 'nrf' ]]; then - echo -e "\n${GREEN}All components are healthy${NC}..." - STATUS=0 - break - elif [[ $2 == 'vpp-upf' ]]; then - echo -ne "mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health,vpp-upf : $vpp_upf_health\033[0K\r" - STATUS=0 - sleep 2 - break - elif [[ $2 != 'nrf' ]]; then - echo -ne "mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health, oai-spgwu : $spgwu_health\033[0K\r" - STATUS=1 - sleep 2 - else - echo -ne "oai-nrf : $nrf_health, mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health, oai-spgwu : $spgwu_health\033[0K\r" - STATUS=1 - sleep 2 - fi - done - if [[ $2 == 'nrf' && $STATUS == 0 ]]; then - echo -e "\nChecking if SMF and UPF registered with nrf core network" - smf_registration_nrf=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="SMF" | grep -o '192.168.70.133') - upf_registration_nrf=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="UPF" | grep -o '192.168.66.134') - sample_registration=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="SMF") - echo -e "\n${BLUE}For example: oai-smf Registration with oai-nrf can be checked on this url /nnrf-nfm/v1/nf-instances?nf-type='SMF' $sample_registration${NC}" - if [[ -z $smf_registration_nrf && -z $upf_registration_nrf ]]; then - echo -e "${RED}Registration problem with NRF, check the reason manually${NC}..." - STATUS=1 - else - echo -e "${GREEN}SMF and UPF are registered to NRF${NC}..." - fi - elif [[ $2 == 'gnbsim' && $STATUS == 0 ]]; then - echo -e "${GREEN}#### gnbsim is healthy - gnb & ue is conncted to core network now !! #####${NC}" - else - echo -e "${BLUE}Checking if SMF is able to connect with UPF${NC}" - - if [[ $2 == 'vpp-upf' ]];then - sleep 5 - upf_logs=$(docker logs oai-smf | grep 'handle_receive(16 bytes)') - else - upf_logs=$(docker logs oai-spgwu | grep 'Received SX HEARTBEAT RESPONSE') - fi - - if [[ -z $upf_logs && $STATUS == 0 ]]; then - echo -e "\n${RED}UPF not receiving heartbeats from SMF${NC}..." - STATUS=1 - else - echo -e "\n${GREEN}UPF receiving heathbeats from SMF${NC}..." - fi - fi - end_time=$(date +%s%N | cut -b1-13) - final_time=$(expr $(expr $end_time - $start_time)) - if [[ $STATUS == 0 ]]; then - echo -e "\n${GREEN}Core network is configured and healthy, total time taken $final_time milli seconds${NC}" - exit $STATUS - else - echo -e "\n${RED}Core network is un-healthy, total time taken $final_time milli seconds\ndebug using docker inspect command...${NC}" - exit $STATUS - fi + start_time=$(date +%s%N | cut -b1-13) + if [[ $2 == 'nrf' ]]; then + echo -e "${BLUE}Starting 5gcn components in the order nrf, mysql, amf, smf, spgwu${NC}..." + docker-compose -f docker-compose.yaml -p 5gcn up -d + elif [[ $2 == 'no-nrf' ]]; then + if [[ $3 == 'vpp-upf' ]]; then + echo -e "${BLUE}Starting 5gcn components in the order mysql, amf, smf, vpp-upf${NC}..." + docker-compose -f docker-compose-vpp-upf.yaml -p 5gcn up -d oai-amf + sleep 5 + docker-compose -f docker-compose-vpp-upf.yaml -p 5gcn up -d oai-smf + elif [[ $3 == 'spgwu' ]]; then + echo -e "${BLUE}Starting 5gcn components in the order mysql, amf, smf, spgwu${NC}..." + docker-compose -f docker-compose-no-nrf.yaml -p 5gcn up -d + fi + fi + echo -e "${GREEN}Core network started, checking the health status of the containers${NC}..." + # 25 is a interval it can be increased or decreased + for loop in $(seq 1 25); do + mysql_health=$(docker inspect --format='{{json .State.Health.Status}}' mysql) + if [[ $2 == 'nrf' ]]; then + nrf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-nrf) + fi + amf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-amf) + smf_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-smf) + if [[ $3 == 'vpp-upf' ]];then + vpp_upf_health=$(docker inspect --format='{{json .State.Health.Status}}' vpp-upf) + else + spgwu_health=$(docker inspect --format='{{json .State.Health.Status}}' oai-spgwu) + fi + if [[ ${mysql_health} == '"healthy"' && ${amf_health} == '"healthy"' && ${smf_health} == '"healthy"' && ${spgwu_health} == '"healthy"' && $2 != 'nrf' && $3 != 'vpp-upf' ]]; then + echo -e "\n${GREEN}All components are healthy${NC}..." + STATUS=0 + break + elif [[ ${mysql_health} == '"healthy"' && ${amf_health} == '"healthy"' && ${smf_health} == '"healthy"' && ${spgwu_health} == '"healthy"' && ${nrf_health} == '"healthy"' && $2 == 'nrf' && $3 != 'vpp-upf' ]]; then + echo -e "\n${GREEN}All components are healthy${NC}..." + STATUS=0 + break + elif [[ ${mysql_health} == '"healthy"' && ${amf_health} == '"healthy"' && ${smf_health} == '"healthy"' && ${vpp_upf_health} == '"healthy"' && $2 != 'nrf' && $3 == 'vpp-upf' ]]; then + echo -e "\n${GREEN}All components are healthy${NC}..." + STATUS=0 + break + elif [[ $2 != 'nrf' && $3 == 'spgwu' ]]; then + echo -ne "mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health, oai-spgwu : $spgwu_health\033[0K\r" + STATUS=1 + sleep 2 + elif [[ $2 != 'nrf' && $3 == 'vpp-upf' ]]; then + echo -ne "mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health, vpp-upf : $vpp_upf_health\033[0K\r" + STATUS=1 + sleep 2 + elif [[ $2 == 'nrf' && $3 == 'spgwu' ]]; then + echo -ne "oai-nrf : $nrf_health, mysql : $mysql_health, oai-amf : $amf_health, oai-smf : $smf_health, oai-spgwu : $spgwu_health\033[0K\r" + STATUS=1 + sleep 2 + fi + done + echo -e "${BLUE}Checking the if the containers are configured${NC}..." + if [[ $2 == 'nrf' && $3 != 'vpp-upf' && $STATUS == 0 ]]; then + echo -e "\nChecking if SMF and UPF registered with nrf core network" + smf_registration_nrf=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="SMF" | grep -o '192.168.70.133') + upf_registration_nrf=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="UPF" | grep -o '192.168.70.134') + sample_registration=$(curl -s -X GET http://192.168.70.130/nnrf-nfm/v1/nf-instances?nf-type="SMF") + echo -e "\n${BLUE}For example: oai-smf Registration with oai-nrf can be checked on this url /nnrf-nfm/v1/nf-instances?nf-type='SMF' $sample_registration${NC}" + if [[ -z $smf_registration_nrf && -z $upf_registration_nrf ]]; then + echo -e "${RED}Registration problem with NRF, check the reason manually${NC}..." + STATUS=1 + else + echo -e "${GREEN}SMF and UPF are registered to NRF${NC}..." + fi + else + echo -e "${BLUE}Checking if SMF is able to connect with UPF${NC}" + if [[ $3 == 'vpp-upf' ]];then + upf_logs=$(docker logs oai-smf | grep 'handle_receive(16 bytes)') + else + upf_logs=$(docker logs oai-spgwu | grep 'Received SX HEARTBEAT RESPONSE') + fi + if [[ -z $upf_logs && $STATUS == 0 ]]; then + echo -e "\n${RED}UPF not receiving heartbeats from SMF${NC}..." + STATUS=1 + else + echo -e "\n${GREEN}UPF receiving heathbeats from SMF${NC}..." + fi + fi + end_time=$(date +%s%N | cut -b1-13) + final_time=$(expr $(expr $end_time - $start_time)) + if [[ $STATUS == 0 ]]; then + echo -e "\n${GREEN}Core network is configured and healthy, total time taken $final_time milli seconds${NC}" + exit $STATUS + else + echo -e "\n${RED}Core network is un-healthy, total time taken $final_time milli seconds\ndebug using docker inspect command...${NC}" + exit $STATUS + fi elif [[ $1 == 'stop' ]]; then - echo -e "${RED}Stopping service $2 ${NC}..." - if [[ $2 == 'nrf' ]]; then - docker-compose -f docker-compose.yaml -p 5gcn down - elif [[ $2 == 'gnbsim' ]]; then - docker-compose -f docker-compose-gnbsim.yaml down - elif [[ $2 == 'vpp-upf' ]]; then - docker-compose -f docker-compose-vpp-upf.yaml down - else - docker-compose -f docker-compose-no-nrf.yaml -p 5gcn down - fi - echo -e "${GREEN}Service $2 is stopped${NC}" + echo -e "${RED}Stopping service $2 ${NC}..." + if [[ $2 == 'nrf' && $3 == 'spgwu' ]]; then + docker-compose -f docker-compose.yaml -p 5gcn down + elif [[ $2 != 'nrf' && $3 == 'vpp-upf' ]]; then + docker-compose -f docker-compose-vpp-upf.yaml -p 5gcn down + elif [[ $2 = 'no-nrf' && $3 == 'spgwu' ]]; then + docker-compose -f docker-compose-no-nrf.yaml -p 5gcn down + fi + echo -e "${GREEN}Service $2 is stopped${NC}" else - echo -e "Only use the following options\n\n${RED}start ${WHITE}[option]${NC}: start the 5gCN/gnbsim\n"\ -"${RED}stop ${WHITE}[option]${NC}: stops the 5gCN/gnbsim\n${WHITE}--option\n${RED} nrf${NC} : nrf should be used\n"\ -"${RED} no-nrf${NC} : nrf should not be used\n${RED} vpp-upf${NC} : vpp-upf should be used (without nrf)\n"\ -"${RED} gnbsim${NC} : gnbsim should be used\n${RED} gnbsim-vpp${NC} : gnbsim should be used for vpp-upf\n"\ -"\nExample: ./core-network.sh start nrf\n" + echo -e "\nOnly use the following options\n +${RED}start ${WHITE}[option1]${NC} ${WHITE}[option2]${NC}: start the 5gCN\n\ +${RED}stop ${WHITE}[option1]${NC} ${WHITE}[option2]${NC}: stops the 5gCN\n\ +\n--option1\n\ +${RED}nrf${NC}: nrf should be used\n\ +${RED}no-nrf${NC}: nrf should not be used\n\ +\n--option2\n\ +${RED}vpp-upf${NC}: vpp-upf should be used (only works without nrf, no-nrf option1)\n\ +${RED}spgwu${NC} : spgwu should be used as upf (works with or without nrf, nrf or no-nrf option1)\n\n\ +Example 1 : ./core-network.sh start nrf spgwu\n\ +Example 2: ./core-network.sh start no-nrf vpp-upf\n\ +Example 1 : ./core-network.sh stop nrf spgwu\n\ +Example 2: ./core-network.sh stop no-nrf vpp-upf" fi + diff --git a/docker-compose/docker-compose-gnbsim.yaml b/docker-compose/docker-compose-gnbsim.yaml index 7c87db78..ec55302a 100644 --- a/docker-compose/docker-compose-gnbsim.yaml +++ b/docker-compose/docker-compose-gnbsim.yaml @@ -33,7 +33,6 @@ services: interval: 10s timeout: 5s retries: 5 - gnbsim2: container_name: gnbsim2 image: gnbsim:develop @@ -67,7 +66,6 @@ services: interval: 10s timeout: 5s retries: 5 - gnbsim3: container_name: gnbsim3 image: gnbsim:develop @@ -101,7 +99,6 @@ services: interval: 10s timeout: 5s retries: 5 - gnbsim4: container_name: gnbsim4 image: gnbsim:develop diff --git a/docker-compose/docker-compose-vpp-upf.yaml b/docker-compose/docker-compose-vpp-upf.yaml index 336fa16d..6bf920a9 100644 --- a/docker-compose/docker-compose-vpp-upf.yaml +++ b/docker-compose/docker-compose-vpp-upf.yaml @@ -68,9 +68,9 @@ services: - AUSF_PORT=80 - AUSF_API_VERSION=v1 depends_on: + - mysql - vpp-upf - oai-ext-dn - - mysql volumes: - ./amf-healthcheck.sh:/openair-amf/bin/amf-healthcheck.sh healthcheck: @@ -83,7 +83,7 @@ services: ipv4_address: 192.168.71.132 oai-smf: container_name: "oai-smf" - image: oai-smf:vpp-upf + image: oai-smf:nwi environment: - TZ=Europe/Paris - INSTANCE=0 diff --git a/docs/DEPLOY_SA5G_WITH_DS_TESTER.md b/docs/DEPLOY_SA5G_WITH_DS_TESTER.md index 79f16d4b..f688c93f 100644 --- a/docs/DEPLOY_SA5G_WITH_DS_TESTER.md +++ b/docs/DEPLOY_SA5G_WITH_DS_TESTER.md @@ -198,13 +198,24 @@ To know how to configure the machine with the above requirements vist [pre-requi (docker-compose-host)$ pwd /home/<docker-compose-host>/oai/oai-cn-fed/docker-compose (docker-compose-host)$ ./core-network + Only use the following options - start: start the 5gCN - stop: stops the 5gCN + start [option1] [option2]: start the 5gCN + stop [option1] [option2]: stops the 5gCN + + --option1 nrf: nrf should be used no-nrf: nrf should not be used - Example: ./core-network.sh start nrf + + --option2 + vpp-upf: vpp-upf should be used (only works without nrf, no-nrf option1) + spgwu : spgwu should be used as upf (works with or without nrf, nrf or no-nrf option1) + + Example 1 : ./core-network.sh start nrf spgwu + Example 2: ./core-network.sh start no-nrf vpp-upf + Example 1 : ./core-network.sh stop nrf spgwu + Example 2: ./core-network.sh stop no-nrf vpp-upf ``` - Before executing the script it is better to start capturing packets to see the message flow between smf <--> nrf <--> upf. The packets will be captured on **demo-oai** bridge which should be configured on the `docker-compose-host` machine. @@ -214,7 +225,7 @@ To know how to configure the machine with the above requirements vist [pre-requi - Starting the core network components, ```bash - (docker-compose-host)$ ./core-network start nrf + (docker-compose-host)$ ./core-network start nrf spgwu Starting 5gcn components in the order nrf, mysql, amf, smf, spgwu... Creating mysql ... done Creating oai-nrf ... done diff --git a/docs/DEPLOY_SA5G_WITH_GNBSIM.md b/docs/DEPLOY_SA5G_WITH_GNBSIM.md index 900382a0..63d5eb24 100644 --- a/docs/DEPLOY_SA5G_WITH_GNBSIM.md +++ b/docs/DEPLOY_SA5G_WITH_GNBSIM.md @@ -48,6 +48,28 @@ Let's begin !! we did for dsTest-host. * Before we procced further for end to end SA5G test, make sure you have healthy docker services for OAI cn5g - ```bash +oai-cn5g-fed/docker-compose$ ./core-network.sh start nrf spgwu +Starting 5gcn components in the order nrf, mysql, amf, smf, spgwu... +Creating mysql ... done +Creating oai-nrf ... done +Creating oai-amf ... done +Creating oai-spgwu ... done +Creating oai-smf ... done +Creating oai-ext-dn ... done +Core network started, checking the health status of the containers... +oai-nrf : "healthy", mysql : "starting", oai-amf : "healthy", oai-smf : "healthy", oai-spgwu : "healthy" +All components are healthy... +Checking the if the containers are configured... + +Checking if SMF and UPF registered with nrf core network + +For example: oai-smf Registration with oai-nrf can be checked on this url /nnrf-nfm/v1/nf-instances?nf-type='SMF' {"_links":{"item":[{"href":"192.168.70.133"}],"self":""}} +SMF and UPF are registered to NRF... + +Core network is configured and healthy, total time taken 43187 milli seconds +oai-cn5g-fed/docker-compose$ +``` +```bah oai-cn5g-fed/docker-compose$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c25db05aa023 ubuntu:bionic "/bin/bash -c ' apt …" 23 seconds ago Up 22 seconds oai-ext-dn @@ -71,7 +93,7 @@ $ docker build --tag gnbsim:develop --target gnbsim --file docker/Dockerfile.ubu * The configuration parameters, are preconfigured in [docker-compose.yaml](../docker-compose/docker-compose.yaml) and [docker-compose-gnbsim.yaml](../docker-compose/docker-compose-gnbsim.yaml) and one can modify it for test. * Launch gnbsim docker service ```bash -oai-cn5g-fed/docker-compose$ ./core-network.sh start gnbsim +oai-cn5g-fed/docker-compose$ docker-compose -f docker-compose-gnbsim.yaml up -d gnbsim Creating gnbsim ... done ``` @@ -184,7 +206,7 @@ iperf Done. Here we try some scaling test with gnbsim. There are additional IMSIs are added into database (208950000000031-208950000000040). Now we create few more gnbsim instances (4 more for now). We use same script to generate additional instance as follow - ```bash -oai-cn5g-fed/docker-compose$ ./core-network.sh start gnbsim 2 +oai-cn5g-fed/docker-compose$ docker-compose -f docker-compose-gnbsim.yaml up -d gnbsim2 Creating gnbsim2 ... done ``` So here basically, minimum configuration parameters that need to change is gnbid, imsi and container ip address in docker-compose-gnbsim.yaml. -- GitLab