3gpp yang model pruning and installation
[o-du/l2.git] / build / scripts / load_yang.sh
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) [2020-2021] [HCL Technologies Ltd.]                          #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 # This script is used to install yang module and load initial configuration
18
19 #initialize globle variables
20 CURRENT_DIR=$PWD
21 ROOT_DIR=$CURRENT_DIR/../../
22 CONFIG_PATH=$ROOT_DIR/bin/odu/config/
23 YANG_PATH_3GPP="https://forge.3gpp.org/rep/sa5/MnS/-/raw/0032d2835382c47bc402c077b40ef71d77c9a3c9/yang-models"
24
25 #list of 3gpp yang models
26 declare -a YANG_MODEL_3GPP=( "_3gpp-common-yang-types.yang"
27                         "_3gpp-common-top.yang"
28                         "_3gpp-common-measurements.yang"
29                         "_3gpp-common-trace.yang"
30                         "_3gpp-common-managed-function.yang"
31                         "_3gpp-common-subscription-control.yang"
32                         "_3gpp-common-fm.yang"
33                         "_3gpp-common-managed-element.yang"
34                         "_3gpp-5g-common-yang-types.yang"
35                         "_3gpp-nr-nrm-rrmpolicy.yang"
36                         "_3gpp-nr-nrm-gnbdufunction.yang"
37                         "_3gpp-nr-nrm-nrcelldu.yang")
38
39
40 #list of ORAN yang models
41 declare -a YANG_MODEL_ORAN=( "o-ran-sc-odu-alarm-v1.yang"
42                         "o-ran-sc-du-hello-world.yang"
43                         "o-ran-sc-odu-interface-v1.yang")
44
45
46 #list of config files
47 declare -a CONFIGURATION_ARRAY=( "startup_config.xml"
48                                  "nacm_config.xml"
49                                  "netconf_server_ipv6.xml")
50
51 #list of modules corresponding to the above config files
52 declare -a MODULE_ARRAY=( "o-ran-sc-odu-interface-v1"
53                           "ietf-netconf-acm"
54                           "ietf-netconf-server")
55
56
57 #check 3GPP yang module if not available then  downalod and update
58 check3gppYang()
59 {
60    #check 3GPP yang modules available
61    for yang in "${YANG_MODEL_3GPP[@]}"
62    do
63
64       if [ ! -f "$ROOT_DIR/build/yang/$yang" ]
65       then
66             wget $YANG_PATH_3GPP/$yang -P $ROOT_DIR/build/yang
67       fi
68
69    done
70 }
71
72 #3GPP yang modules having some warning so fix it.
73 updateYang()
74 {
75    sed -i -e "s/'\.\/tj/'\.\.\/tj/g" $ROOT_DIR/build/yang/_3gpp-common-trace.yang
76    sed -i -e "s/\ \.\/tj/\ \.\.\/tj/g" $ROOT_DIR/build/yang/_3gpp-common-trace.yang
77    sed -i -e 's/"IMMEDIATE_MDT"/"IMMEDIATE_MDT_ONLY"/g' $ROOT_DIR/build/yang/_3gpp-common-trace.yang
78    sed -i -e 's/"TRACE"/"TRACE_ONLY"/g' $ROOT_DIR/build/yang/_3gpp-common-trace.yang
79
80    echo "updateYang done"
81 }
82
83
84 #initialize the variable
85 init()
86 {
87    if [ -d "$ROOT_DIR/bin/odu/config" ]
88    then
89       CONFIG_PATH=$ROOT_DIR/bin/odu/config/
90       echo "CONFIG_PATH = $CONFIG_PATH"
91    else
92       CONFIG_PATH=$ROOT_DIR/build/config/
93       echo "CONFIG_PATH = $CONFIG_PATH"
94    fi
95       echo "CONFIG_PATH = $CONFIG_PATH"
96
97 }
98
99 #install 3GPP and ORAN yang modules
100 installYang()
101 {
102    echo "### install yang modules ###"
103    #install 3GPP yang modules
104    for yang in "${YANG_MODEL_3GPP[@]}"
105    do
106       sysrepoctl -i      $ROOT_DIR/build/yang/$yang
107    done
108
109    #install ORAN yang modules
110    for yang in "${YANG_MODEL_ORAN[@]}"
111    do
112       sysrepoctl -i      $ROOT_DIR/build/yang/$yang
113    done
114 }
115
116 #load initial configuration
117 loadConfig()
118 {
119    echo "### load initial configuration ###"
120
121    for ((i=0;i<${#CONFIGURATION_ARRAY[@]};i++))
122    do
123       sysrepocfg --import=$CONFIG_PATH/${CONFIGURATION_ARRAY[$i]} -v 3 --datastore running --module  ${MODULE_ARRAY[$i]}
124    done
125
126    echo "### load initial configuration done ###"
127 }
128
129 init
130 check3gppYang
131 updateYang
132 installYang
133 loadConfig
134
135 ################################################################################
136 #                              End of file                                     #
137 ################################################################################