5 COMPOSE_FILE_NAME=docker-compose.yml
6 NETOPEER_CONTAINER_NAME=netopeer
7 SIMULATOR_CONTAINER_NAME=pnf-simulator
9 SIMULATOR_START_URL=http://localhost:$SIMULATOR_PORT/simulator/start
10 SIMULATOR_STOP_URL=http://localhost:$SIMULATOR_PORT/simulator/stop
11 SIMULATOR_STATUS_URL=http://localhost:$SIMULATOR_PORT/simulator/status
12 RUNNING_COMPOSE_CONFIG=$COMPOSE_FILE_NAME
22 start $COMPOSE_FILE_NAME;;
24 start_netconf_server $COMPOSE_FILE_NAME;;
40 function build_image(){
41 if [ -f pom.xml ]; then
42 mvn clean package docker:build
44 echo "pom.xml file not found"
49 function start_netconf_server() {
50 docker-compose -f $1 up -d $NETOPEER_CONTAINER_NAME
52 echo "NETCONF server container's logs:"
53 docker exec $NETOPEER_CONTAINER_NAME /bin/bash -c "sysrepoctl --install --yang=/netconf/\$NETCONF_MODEL.yang --owner=netconf:nogroup --permissions=777"
54 docker exec $NETOPEER_CONTAINER_NAME /bin/bash -c "sysrepocfg --import=/netconf/\$NETCONF_MODEL.data.xml --datastore=startup --format=xml --level=3 \$NETCONF_MODEL"
55 docker exec -d $NETOPEER_CONTAINER_NAME /bin/bash -c "/opt/dev/sysrepo/build/examples/application_example \$NETCONF_MODEL"
61 if [[ $(running_containers) ]]; then
62 echo "Simulator containers are already up"
64 echo "Starting simulator containers using netconf model specified in config/netconf.env"
67 start_netconf_server $1
68 docker-compose -f $1 up -d $SIMULATOR_CONTAINER_NAME
69 RUNNING_COMPOSE_CONFIG=$1
73 function running_containers(){
74 docker-compose -f $COMPOSE_FILE_NAME ps -q
79 if [[ $(running_containers) ]]; then
80 docker-compose -f $RUNNING_COMPOSE_CONFIG down
82 echo "Simulator containers are already down"
86 function run_simulator(){
89 $(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)
93 function stop_simulator(){
96 $(curl -s -X POST $SIMULATOR_STOP_URL)
100 function get_status(){
102 if [[ $(running_containers) ]]; then
105 echo "Simulator containers are down"
109 function print_status(){
111 $(docker-compose -f $RUNNING_COMPOSE_CONFIG ps)
114 $(curl -s -X GET $SIMULATOR_STATUS_URL)
118 function print_help(){
121 build - locally builds simulator image from existing code
122 start - starts simulator and netopeer2 containers using remote simulator image and specified model name
123 start-dev - starts only netopeer2 container
124 run-simulator - starts sending PNF registration messages with parameters specified in config.json
125 stop-simulator - stop sending PNF registration messages
126 stop - stops both containers
127 status - prints simulator status
128 clear-logs - deletes log folder
132 - Setup environment with "./simulator.sh start". It will download required docker images from the internet and run them on docker machine
133 - To start the simulation use "./simulator.sh run-simulator", which will start sending PNF registration messages with parameters specified in config.json
135 To stop simulation use "./simulator.sh stop-simulator" command. To check simulator's status use "./simulator.sh status".
136 If you want to change message parameters simply edit config.json, then start the simulation with "./simulator.sh run-simulator" again
137 Logs are written to logs/pnf-simulator.log. After each "start/start-dev" old log files are moved to the archive
140 1. Build local simulator image using "./simulator.sh build"
141 2. Run containers with "./simulator.sh start-debug"
143 If you change the source code you have to rebuild image with "./simulator.sh build" and run "./simulator.sh start/start-dev" again
147 function archive_logs(){
150 echo "Moving log file to archive"
151 DIR_PATH=logs/archive/simulator[$(timestamp)]
153 if [ -f logs/pnfsimulator.log ]; then
154 mv logs/pnfsimulator.log $DIR_PATH
157 if [ -f logs/*.xml ]; then
158 mv logs/*.xml $DIR_PATH
166 function clear_logs(){
168 if [[ $(running_containers) ]]; then
169 echo "Cannot delete logs when simulator is running"
175 function timestamp(){