5 COMPOSE_FILE_NAME=docker-compose.yml
6 DEV_COMPOSE_FILE_NAME=docker-compose.dev.yml
7 NETOPEER_CONTAINER_NAME=netopeer
8 SIMULATOR_CONTAINER_NAME=pnf-simulator
10 SIMULATOR_START_URL=http://localhost:$SIMULATOR_PORT/simulator/start
11 SIMULATOR_STOP_URL=http://localhost:$SIMULATOR_PORT/simulator/stop
12 SIMULATOR_STATUS_URL=http://localhost:$SIMULATOR_PORT/simulator/status
13 RUNNING_COMPOSE_CONFIG=$COMPOSE_FILE_NAME
23 start $COMPOSE_FILE_NAME;;
25 start $DEV_COMPOSE_FILE_NAME;;
27 start_netconf_server $DEV_COMPOSE_FILE_NAME;;
43 function build_image(){
44 if [ -f pom.xml ]; then
47 echo "pom.xml file not found"
52 function start_netconf_server() {
53 docker-compose -f $1 up -d $NETOPEER_CONTAINER_NAME
55 echo "NETCONF server container's logs:"
56 docker exec $NETOPEER_CONTAINER_NAME /bin/bash -c "sysrepoctl --install --yang=/netconf/\$NETCONF_MODEL.yang --owner=netconf:nogroup --permissions=777"
57 docker exec $NETOPEER_CONTAINER_NAME /bin/bash -c "sysrepocfg --import=/netconf/\$NETCONF_MODEL.data.xml --datastore=startup --format=xml --level=3 \$NETCONF_MODEL"
58 docker exec -d $NETOPEER_CONTAINER_NAME /bin/bash -c "/opt/dev/sysrepo/build/examples/application_example \$NETCONF_MODEL"
64 if [[ $(running_containers) ]]; then
65 echo "Simulator containers are already up"
67 echo "Starting simulator containers using netconf model specified in config/netconf.env"
70 start_netconf_server $1
71 docker-compose -f $1 up -d $SIMULATOR_CONTAINER_NAME
72 RUNNING_COMPOSE_CONFIG=$1
76 function running_containers(){
77 docker-compose -f $COMPOSE_FILE_NAME ps -q && docker-compose -f $DEV_COMPOSE_FILE_NAME ps -q
82 if [[ $(running_containers) ]]; then
83 docker-compose -f $RUNNING_COMPOSE_CONFIG down
85 echo "Simulator containers are already down"
89 function run_simulator(){
92 $(curl -s -X POST -H "Content-Type: application/json" -H "X-ONAP-RequestID: 123" -H "X-InvocationID: 456" -d @config/config.json $SIMULATOR_START_URL)
96 function stop_simulator(){
99 $(curl -s -X POST $SIMULATOR_STOP_URL)
103 function get_status(){
105 if [[ $(running_containers) ]]; then
108 echo "Simulator containers are down"
112 function print_status(){
114 $(docker-compose -f $RUNNING_COMPOSE_CONFIG ps)
117 $(curl -s -X GET $SIMULATOR_STATUS_URL)
121 function print_help(){
124 build - locally builds simulator image from existing code
125 start - starts simulator and netopeer2 containers using remote simulator image and specified model name
126 start-dev - starts simulator and netopeer2 containers using remote simulator image
127 start-debug - starts only netopeer2 container
128 run-simulator - starts sending PNF registration messages with parameters specified in config.json
129 stop-simulator - stop sending PNF registration messages
130 stop - stops both containers
131 status - prints simulator status
132 clear-logs - deletes log folder
136 - Setup environment with "./simulator.sh start". It will download required docker images from the internet and run them on docker machine
137 - To start the simulation use "./simulator.sh run-simulator", which will start sending PNF registration messages with parameters specified in config.json
139 To stop simulation use "./simulator.sh stop-simulator" command. To check simulator's status use "./simulator.sh status".
140 If you want to change message parameters simply edit config.json, then start the simulation with "./simulator.sh run-simulator" again
141 Logs are written to logs/pnf-simulator.log. After each "start/start-dev" old log files are moved to the archive
144 1. Build local simulator image using "./simulator.sh build"
145 2. Run containers with "./simulator.sh start-dev"
147 If you change the source code you have to rebuild image with "./simulator.sh build" and run "./simulator.sh start/start-dev" again
151 function archive_logs(){
154 echo "Moving log file to archive"
155 DIR_PATH=logs/archive/simulator[$(timestamp)]
157 if [ -f logs/pnfsimulator.log ]; then
158 mv logs/pnfsimulator.log $DIR_PATH
161 if [ -f logs/*.xml ]; then
162 mv logs/*.xml $DIR_PATH
170 function clear_logs(){
172 if [[ $(running_containers) ]]; then
173 echo "Cannot delete logs when simulator is running"
179 function timestamp(){