Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / helm / e2sim / templates / bin / _e2sim-run.sh.tpl
1 {{/*
2    Copyright (c) 2019 AT&T Intellectual Property.
3    Copyright (c) 2019 Nokia.
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 #!/bin/sh
18
19 # Launch the e2 simulator on ${E2SIM_BIND_ADDR}:${E2SIM_BIND_PORT}
20 #  If E2SIM_BIND_ADDR is not supplied, picks the address of the interface
21 #  associated with the default route for E2SIM_BIND_AF (either
22 #  "inet" [default] or "inet6").
23
24 if [ -z "${E2SIM_BIND_ADDR}" ]; then
25   if [ `echo "x${E2SIM_BIND_AF}x" | tr [A-Z] [a-z]` != "xinet6x" ]; then
26     AF='inet'
27     DEFROUTE='0/0'
28     LO='127.0.0.1'
29   else
30     AF='inet6'
31     DEFROUTE='::0/0'
32     LO='00:00:00:00:00:00'
33   fi
34   if [ -z "${E2SIM_BIND_IF}" ]; then
35     # bind on the address associated with the default route
36     E2SIM_BIND_IF=`ip -br -f ${AF} route show ${DEFROUTE}| sed 's/.*dev[\ ]*\([^\ ]*\).*/\1/'`
37     if [ -z ${E2SIM_BIND_IF} ]; then
38       # this is kinda bogus, but it's the only real fallback: take the first
39       # non-loopback interface.
40       E2SIM_BIND_IF=`ip -f ${AF} -o link list up | grep -v LOOPBACK | head -1 |awk -F: '{print $2}'`
41     fi
42   fi
43   E2SIM_BIND_ADDR=`ip -f ${AF} -o addr show ${E2SIM_BIND_IF:-eth0} scope global | sed -e 's/.*inet[6\ ]*\([^\ ]*\)\/.*/\1/'`
44 fi
45
46 if [ -z $E2SIM_BIND_ADDR ]; then
47   # search failed.  be nondestructively useless.
48   echo "No suitable address found, binding on loopback addess ${LO}"
49   E2SIM_BIND_ADDR=${LO}
50 else
51   echo "e2sim starting at ${E2SIM_BIND_ADDR}:${E2SIM_PORT:-36421}"
52 fi
53
54 ${E2SIM:-/home/e2sim/build/e2sim} ${E2SIM_BIND_ADDR} ${E2SIM_PORT:-36421}