Replace FHoSS with pyHSS

This commit is contained in:
herlesupreeth
2023-08-05 19:35:15 +02:00
parent 410e907fd0
commit b259d34a60
15 changed files with 455 additions and 264 deletions

4
.env
View File

@@ -55,8 +55,8 @@ RTPENGINE_IP=172.22.0.16
# MYSQL
MYSQL_IP=172.22.0.17
# FHOSS
FHOSS_IP=172.22.0.18
# PYHSS
PYHSS_IP=172.22.0.18
# ICSCF
ICSCF_IP=172.22.0.19

View File

@@ -45,7 +45,7 @@ sed -i 's|DNS_IP|'$DNS_IP'|g' /etc/bind/ims_zone
sed -i 's|PCSCF_IP|'$PCSCF_IP'|g' /etc/bind/ims_zone
sed -i 's|ICSCF_IP|'$ICSCF_IP'|g' /etc/bind/ims_zone
sed -i 's|SCSCF_IP|'$SCSCF_IP'|g' /etc/bind/ims_zone
sed -i 's|FHOSS_IP|'$FHOSS_IP'|g' /etc/bind/ims_zone
sed -i 's|PYHSS_IP|'$PYHSS_IP'|g' /etc/bind/ims_zone
sed -i 's|SMSC_IP|'$SMSC_IP'|g' /etc/bind/ims_zone
sed -i 's|PUB_3GPP_DOMAIN|'$PUB_3GPP_DOMAIN'|g' /etc/bind/pub_3gpp_zone

View File

@@ -22,7 +22,7 @@ scscf 1D IN A SCSCF_IP
_sip._udp.scscf 1D SRV 0 0 6060 scscf
_sip._tcp.scscf 1D SRV 0 0 6060 scscf
hss 1D IN A FHOSS_IP
hss 1D IN A PYHSS_IP
smsc 1D IN A SMSC_IP
_sip._udp.smsc 1D SRV 0 0 7090 smsc

View File

@@ -471,13 +471,14 @@ services:
networks:
default:
ipv4_address: ${MYSQL_IP}
fhoss:
build: ./fhoss
image: docker_fhoss
container_name: fhoss
pyhss:
build: ./pyhss
image: docker_pyhss
container_name: pyhss
dns: ${DNS_IP}
volumes:
- ./fhoss:/mnt/fhoss
- ./pyhss:/mnt/pyhss
- ./pyhss/logs:/pyhss/log/
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
env_file:
@@ -492,7 +493,7 @@ services:
- "8080:8080/tcp"
networks:
default:
ipv4_address: ${FHOSS_IP}
ipv4_address: ${PYHSS_IP}
icscf:
image: docker_kamailio
container_name: icscf
@@ -508,7 +509,7 @@ services:
depends_on:
- dns
- mysql
- fhoss
- pyhss
expose:
- "3869/udp"
- "3869/tcp"
@@ -532,7 +533,7 @@ services:
depends_on:
- dns
- mysql
- fhoss
- pyhss
expose:
- "3870/udp"
- "3870/tcp"

View File

@@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- HSS Server config -->
<DiameterPeer
FQDN="hss.IMS_DOMAIN"
Realm="IMS_DOMAIN"
Vendor_Id="10415"
Product_Name="JavaDiameterPeer"
AcceptUnknownPeers="1"
DropUnknownOnDisconnect="1"
Tc="30"
Workers="4"
QueueLength="32"
>
<Peer FQDN="icscf.IMS_DOMAIN" Realm="IMS_DOMAIN" port="3869" />
<Peer FQDN="scscf.IMS_DOMAIN" Realm="IMS_DOMAIN" port="3870" />
<Acceptor port="3868" bind="FHOSS_IP" />
<Auth id="16777216" vendor="10415"/><!-- 3GPP Cx -->
<Auth id="16777216" vendor="4491"/><!-- CableLabs Cx -->
<Auth id="16777216" vendor="13019"/><!-- ETSI/TISPAN Cx -->
<Auth id="16777216" vendor="0"/><!-- ETSI/TISPAN Cx -->
<Auth id="16777217" vendor="10415"/><!-- 3GPP Sh -->
<Auth id="16777221" vendor="10415"/>
</DiameterPeer>

View File

@@ -1,71 +0,0 @@
# THIRD PARTY SOFTWARE NOTICES AND INFORMATION
# Do Not Translate or Localize
#
# This repository includes Oracle Java 7 JDK downloaded from Oracle website, which is distributed
# under Oracle Binary Code License Agreement for Java SE. By using this repository you agree to
# have reviewed and accepted the Oracle Binary Code License Agreement for Java SE and hold
# no liability.
#
# =========================================
# BSD 2-Clause License
# Copyright (c) 2020, Supreeth Herle
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
# Install updates and dependencies
RUN apt-get update && \
apt-get -y install git vim wget subversion mysql-server
# Install Oracle Java 7 SE JDK
RUN mkdir -p /usr/lib/jvm/ && \
cd / && wget https://files-cdn.liferay.com/mirrors/download.oracle.com/otn-pub/java/jdk/7u80-b15/jdk-7u80-linux-x64.tar.gz && \
tar -zxf /jdk-7u80-linux-x64.tar.gz -C /usr/lib/jvm/ && \
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_80/bin/java 100 && \
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_80/bin/javac 100
# Install Ant
RUN cd / && wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.9.14-bin.tar.gz && \
tar xvfvz apache-ant-1.9.14-bin.tar.gz && \
mv apache-ant-1.9.14 /usr/local/ && \
ln -s /usr/local/apache-ant-1.9.14/bin/ant /usr/bin/ant
RUN mkdir -p /opt/OpenIMSCore && \
cd /opt/OpenIMSCore && \
git clone https://github.com/herlesupreeth/FHoSS
ENV JAVA_HOME="/usr/lib/jvm/jdk1.7.0_80"
ENV CLASSPATH="/usr/lib/jvm/jdk1.7.0_80/jre/lib/"
ENV ANT_HOME="/usr/local/apache-ant-1.9.14"
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN cd /opt/OpenIMSCore/FHoSS && \
ant compile deploy | tee ant_compile_deploy.txt
CMD /mnt/fhoss/fhoss_init.sh

View File

@@ -1,28 +0,0 @@
#!/bin/bash
# Initialization & global vars
# if you execute this script for the second time
# you should change these variables to the latest
# domain name and ip address
DDOMAIN="open-ims\.test"
DSDOMAIN="open-ims\\\.test"
DEFAULTIP="127\.0\.0\.1"
CONFFILES=`ls *.cfg *.xml *.sql *.properties 2>/dev/null`
# Interaction
domainname=$1
ip_address=$2
# input domain is to be slashed for cfg regexes
slasheddomain=`echo $domainname | sed 's/\./\\\\\\\\\./g'`
printf "changing: "
for i in $CONFFILES
do
sed -i -e "s/$DDOMAIN/$domainname/g" $i
sed -i -e "s/$DSDOMAIN/$slasheddomain/g" $i
sed -i -e "s/$DEFAULTIP/$ip_address/g" $i
printf "$i "
done
echo

View File

@@ -1,88 +0,0 @@
#!/bin/bash
# BSD 2-Clause License
# Copyright (c) 2020, Supreeth Herle
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[ ${#MNC} == 3 ] && IMS_DOMAIN="ims.mnc${MNC}.mcc${MCC}.3gppnetwork.org" || IMS_DOMAIN="ims.mnc0${MNC}.mcc${MCC}.3gppnetwork.org"
cp /mnt/fhoss/configurator.sh /opt/OpenIMSCore/FHoSS/deploy
cp /mnt/fhoss/DiameterPeerHSS.xml /opt/OpenIMSCore/FHoSS/deploy
cp /mnt/fhoss/hibernate.properties /opt/OpenIMSCore/FHoSS/deploy
cp /mnt/fhoss/configurator.sh /opt/OpenIMSCore/FHoSS/scripts
cp /mnt/fhoss/configurator.sh /opt/OpenIMSCore/FHoSS/config
cd /opt/OpenIMSCore/FHoSS/deploy && ./configurator.sh ${IMS_DOMAIN} ${FHOSS_IP}
sed -i 's|open-ims.org|'$IMS_DOMAIN'|g' /opt/OpenIMSCore/FHoSS/deploy/webapps/hss.web.console/WEB-INF/web.xml
sed -i 's|MYSQL_IP|'$MYSQL_IP'|g' /opt/OpenIMSCore/FHoSS/deploy/hibernate.properties
sed -i 's|FHOSS_IP|'$FHOSS_IP'|g' /opt/OpenIMSCore/FHoSS/deploy/DiameterPeerHSS.xml
sed -i 's|IMS_DOMAIN|'$IMS_DOMAIN'|g' /opt/OpenIMSCore/FHoSS/deploy/DiameterPeerHSS.xml
cd /opt/OpenIMSCore/FHoSS/scripts && ./configurator.sh ${IMS_DOMAIN} ${FHOSS_IP}
cd /opt/OpenIMSCore/FHoSS/config && ./configurator.sh ${IMS_DOMAIN} ${FHOSS_IP}
sed -i 's|open-ims.org|'$IMS_DOMAIN'|g' /opt/OpenIMSCore/FHoSS/src-web/WEB-INF/web.xml
while ! mysqladmin ping -h ${MYSQL_IP} --silent; do
sleep 5;
done
# Sleep until permissions are set
sleep 10;
# Create FHoSS database, populate tables and grant privileges
if [[ -z "`mysql -u root -h ${MYSQL_IP} -qfsBe "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='hss_db'" 2>&1`" ]];
then
mysql -u root -h ${MYSQL_IP} -e "create database hss_db;"
mysql -u root -h ${MYSQL_IP} hss_db < /opt/OpenIMSCore/FHoSS/scripts/hss_db.sql
FHOSS_USER_EXISTS=`mysql -u root -h ${MYSQL_IP} -s -N -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE User = 'hss' AND Host = '%')"`
if [[ "$FHOSS_USER_EXISTS" == 0 ]]
then
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'hss'@'%' IDENTIFIED WITH mysql_native_password BY 'hss'";
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'hss'@'$FHOSS_IP' IDENTIFIED WITH mysql_native_password BY 'hss'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON hss_db.* TO 'hss'@'%'";
mysql -u root -h ${MYSQL_IP} -e "GRANT ALL ON hss_db.* TO 'hss'@'$FHOSS_IP'";
mysql -u root -h ${MYSQL_IP} -e "FLUSH PRIVILEGES;"
fi
mysql -u root -h ${MYSQL_IP} hss_db < /opt/OpenIMSCore/FHoSS/scripts/userdata.sql
fi
VIS_NET_PRESENT=`mysql -u root -h ${MYSQL_IP} hss_db -s -N -e "SELECT count(*) FROM visited_network;"`
if [[ "$VIS_NET_PRESENT" -gt 0 ]]
then
mysql -u root -h ${MYSQL_IP} hss_db -e "DELETE FROM visited_network;"
mysql -u root -h ${MYSQL_IP} hss_db -e "INSERT INTO visited_network VALUES (1, '$IMS_DOMAIN');"
fi
PREF_SCSCF_PRESENT=`mysql -u root -h ${MYSQL_IP} hss_db -s -N -e "SELECT count(*) FROM preferred_scscf_set;"`
if [[ "$PREF_SCSCF_PRESENT" -gt 0 ]]
then
mysql -u root -h ${MYSQL_IP} hss_db -e "DELETE FROM preferred_scscf_set;"
mysql -u root -h ${MYSQL_IP} hss_db -e "INSERT INTO preferred_scscf_set VALUES (1, 1, 'scscf1', 'sip:scscf.$IMS_DOMAIN:6060', 0);"
fi
# Sync docker time
#ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
cp /mnt/fhoss/hss.sh /
cd / && ./hss.sh

View File

@@ -1,21 +0,0 @@
## MySQL
# hibernate configuration
hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://MYSQL_IP:3306/hss_db
hibernate.connection.username=hss
hibernate.connection.password=hss
hibernate.connection.isolation=1
hibernate.connection.characterEncoding=utf8
hibernate.connection.useUnicode=true
hibernate.connection.CharSet=utf8
# C3P0 configuration
hibernate.c3p0.acquire_increment=1
hibernate.c3p0.min_size=1
hibernate.c3p0.max_size=30
hibernate.c3p0.timeout=3600
hibernate.c3p0.max_statements=0
hibernate.c3p0.idle_test_period=1200

View File

@@ -1,18 +0,0 @@
#!/bin/bash
# --------------------------------------------------------------
# Include JAR Files
# --------------------------------------------------------------
cd /opt/OpenIMSCore/FHoSS/deploy
JAVA_HOME="/usr/lib/jvm/jdk1.7.0_80"
CLASSPATH="/usr/lib/jvm/jdk1.7.0_80/jre/lib/"
echo "Building Classpath"
CLASSPATH=$CLASSPATH:log4j.properties:.
for i in lib/*.jar; do CLASSPATH="$i":"$CLASSPATH"; done
echo "Classpath is $CLASSPATH."
# --------------------------------------------------------------
# Start-up
# --------------------------------------------------------------
$JAVA_HOME/bin/java -cp $CLASSPATH de.fhg.fokus.hss.main.HSSContainer $1 $2 $3 $4 $5 $6 $7 $8 $9

54
pyhss/Dockerfile Normal file
View File

@@ -0,0 +1,54 @@
# BSD 2-Clause License
# Copyright (c) 2020, Supreeth Herle
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
FROM ubuntu:focal
ENV DEBIAN_FRONTEND=noninteractive
# Install updates and dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3-pip \
python3-dev \
python3-setuptools \
python3-wheel \
git \
pkg-config \
libsystemd-dev \
libmysqlclient-dev \
gcc \
mysql-server
# Get pyhss code and install
RUN git clone https://github.com/nickvsnetworking/pyhss
RUN cd pyhss && pip3 install -r requirements.txt
RUN mkdir -p /pyhss/log/
WORKDIR pyhss
CMD /mnt/pyhss/pyhss_init.sh

122
pyhss/config.yaml Normal file
View File

@@ -0,0 +1,122 @@
## HSS Parameters
hss:
transport: "TCP"
#IP Addresses to bind on (List) - For TCP only the first IP is used, for SCTP all used for Transport (Multihomed).
bind_ip: ["PYHSS_IP"]
#Port to listen on (Same for TCP & SCTP)
bind_port: 3868
#Value to populate as the OriginHost in Diameter responses
OriginHost: "hss.IMS_DOMAIN"
#Value to populate as the OriginRealm in Diameter responses
OriginRealm: "IMS_DOMAIN"
#Value to populate as the Product name in Diameter responses
ProductName: "pyHSS"
#Name of the Site, shown in API
site_name: "Test Site"
#Your Home Mobile Country Code (Used for PLMN calcluation)
MCC: "OP_MCC"
#Your Home Mobile Network Code (Used for PLMN calcluation)
MNC: "OP_MNC"
#Enable GMLC / SLh Interface
SLh_enabled: False
#IMSI of Test Subscriber for Unit Checks (Optional)
test_sub_imsi: '001021234567890'
#Device Watchdog Request Interval (In Seconds - If set to 0 disabled)
device_watchdog_request_interval: 5
#Async Queue Check Interval (In Seconds - If set to 0 disabled)
async_check_interval: 0
#The maximum time to wait, in seconds, before disconnecting a client when no data is received.
client_socket_timeout: 120
#The maximum amount of times a failed diameter response/query should be resent before considering the peer offline and terminating their connection
diameter_max_retries: 1
#Prevent updates from being performed without a valid 'Provisioning-Key' in the header
lock_provisioning: False
#Provisioning Key for this HSS, alias for an API key. Required to be present in the header of requests to this HSS' api, if lock_provisioning is True.
provisioning_key: "hss"
#If enabled sends CLRs to old MME when new MME attaches active sub
CancelLocationRequest_Enabled: False
#Workaround for some MMEs to force an Insert Subscriber Data request to be sent immediately after ULA
Insert_Subscriber_Data_Force: False
#Default Initial Filter Criteria for IMS Subscribers
#Jinja Formatted Template, see the example for variables passed to it.
Default_iFC: 'default_ifc.xml'
#Default Sh User Data
Default_Sh_UserData: 'default_sh_user_data.xml'
#S-CSCF Pool
scscf_pool:
- 'sip:scscf.IMS_DOMAIN:6060'
api:
page_size: 200
external:
external_webhook_notification_enabled: False
external_webhook_notification_url: https://api.example.com/webhook
eir:
imsi_imei_logging: True #Store current IMEI / IMSI pair in backend
sim_swap_notify_webhook: http://PYHSS_IP:5000/webhooks/sim_swap_notify/
no_match_response: 2 #Greylist
tac_database_csv: '/etc/pyhss/tac_database_Nov2022.csv'
logging:
level: WARNING
logfiles:
hss_logging_file: log/hss.log
diameter_logging_file: log/diameter.log
database_logging_file: log/db.log
log_to_terminal: True
sqlalchemy_sql_echo: True
sqlalchemy_pool_recycle: 15
sqlalchemy_pool_size: 30
sqlalchemy_max_overflow: 0
## Database Parameters
database:
db_type: mysql #Supported types are MySQL and Postgres
server: MYSQL_IP
username: pyhss
password: ims_db_pass
database: ims_hss_db
## Geographic Redundancy Parameters
geored:
enabled: False
sync_actions: ['HSS', 'IMS', 'PCRF', 'EIR'] #What event actions should be synced
sync_endpoints: #List of PyHSS API Endpoints to update
- 'http://hss01.mnc001.mcc001.3gppnetwork.org:8080'
- 'http://hss02.mnc001.mcc001.3gppnetwork.org:8080'
## Stats Parameters
redis:
enabled: False
clear_stats_on_boot: True
host: PYHSS_IP
port: 6379
prometheus:
enabled: False
port: 8081 #If the API is run the API runs on the next port number up from this
snmp:
port: 1161
listen_address: PYHSS_IP

174
pyhss/default_ifc.xml Normal file
View File

@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--This is the default iFC template used by PyHSS, variables come from the Jinja2 template passed inside diameter.py where you can additional variables if required -->
<IMSSubscription>
<PrivateID>{{ iFC_vars['imsi'] }}@ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org</PrivateID>
<ServiceProfile>
<PublicIdentity>
<Identity>sip:{{ iFC_vars['msisdn'] }}@ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org</Identity>
<Extension>
<IdentityType>0</IdentityType>
<Extension>
<AliasIdentityGroupID>1</AliasIdentityGroupID>
</Extension>
</Extension>
</PublicIdentity>
<PublicIdentity>
<Identity>tel:{{ iFC_vars['msisdn'] }}</Identity>
<Extension>
<IdentityType>0</IdentityType>
<Extension>
<AliasIdentityGroupID>1</AliasIdentityGroupID>
</Extension>
</Extension>
</PublicIdentity>
<PublicIdentity>
<Identity>sip:{{ iFC_vars['imsi'] }}@ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org</Identity>
<Extension>
<IdentityType>0</IdentityType>
</Extension>
</PublicIdentity>
<!-- Copy SIP REGISTER towards Application Server -->
<!-- <InitialFilterCriteria>
<Priority>10</Priority>
<TriggerPoint>
<ConditionTypeCNF>0</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>0</Group>
<Method>REGISTER</Method>
<Extension></Extension>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:applicationserver.ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org:5060</ServerName>
<DefaultHandling>0</DefaultHandling>
<Extension>
<IncludeRegisterRequest/>
<IncludeRegisterResponse/>
</Extension>
</ApplicationServer>
</InitialFilterCriteria> -->
<!-- Copy SIP REGISTER towards SMSc -->
<!-- <InitialFilterCriteria>
<Priority>11</Priority>
<TriggerPoint>
<ConditionTypeCNF>0</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>0</Group>
<Method>REGISTER</Method>
<Extension></Extension>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:smsc.ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org:7090</ServerName>
<DefaultHandling>0</DefaultHandling>
<Extension>
<IncludeRegisterRequest/>
<IncludeRegisterResponse/>
</Extension>
</ApplicationServer>
</InitialFilterCriteria> -->
<!-- SIP MESSAGE Traffic -->
<InitialFilterCriteria>
<Priority>20</Priority>
<TriggerPoint>
<ConditionTypeCNF>1</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>0</Group>
<Method>MESSAGE</Method>
<Extension></Extension>
</SPT>
<SPT>
<ConditionNegated>1</ConditionNegated>
<Group>1</Group>
<SIPHeader>
<Header>Server</Header>
</SIPHeader>
</SPT>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>2</Group>
<SessionCase>0</SessionCase>
<Extension></Extension>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:smsc.ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org:5060</ServerName>
<DefaultHandling>0</DefaultHandling>
</ApplicationServer>
</InitialFilterCriteria>
<!-- SIP USSD Traffic to USSD-GW-->
<!-- <InitialFilterCriteria>
<Priority>25</Priority>
<TriggerPoint>
<ConditionTypeCNF>1</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>1</Group>
<SIPHeader>
<Header>Recv-Info</Header>
<Content>"g.3gpp.ussd"</Content>
</SIPHeader>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:ussd.ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org:5060</ServerName>
<DefaultHandling>0</DefaultHandling>
</ApplicationServer>
</InitialFilterCriteria> -->
<!-- SIP INVITE Traffic from Registered Sub-->
<!-- <InitialFilterCriteria>
<Priority>30</Priority>
<TriggerPoint>
<ConditionTypeCNF>1</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>0</Group>
<Method>INVITE</Method>
<Extension></Extension>
</SPT>
<SPT>
<Group>0</Group>
<SessionCase>0</SessionCase>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:applicationserver.ims.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org</ServerName>
<DefaultHandling>0</DefaultHandling>
</ApplicationServer>
</InitialFilterCriteria> -->
<!-- SIP INVITE Traffic for calls to Unregistered Sub (TERMINATING_UNREGISTERED) -->
<!-- <InitialFilterCriteria>
<Priority>40</Priority>
<TriggerPoint>
<ConditionTypeCNF>0</ConditionTypeCNF>
<SPT>
<ConditionNegated>0</ConditionNegated>
<Group>0</Group>
<Method>INVITE</Method>
<Extension></Extension>
</SPT>
<SPT>
<Group>0</Group>
<SessionCase>2</SessionCase>
</SPT>
</TriggerPoint>
<ApplicationServer>
<ServerName>sip:voicemail.mnc{{ iFC_vars['mnc'] }}.mcc{{ iFC_vars['mcc'] }}.3gppnetwork.org:5060</ServerName>
<DefaultHandling>0</DefaultHandling>
</ApplicationServer>
</InitialFilterCriteria> -->
</ServiceProfile>
</IMSSubscription>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--This is the default iFC template used by PyHSS, variables come from the Jinja2 template passed inside diameter.py where you can additional variables if required -->
<Sh-Data>
<!-- This provides the Public Identifiers to the Application Server -->
<PublicIdentifiers>
<IMSPublicIdentity>sip:{{ Sh_template_vars['msisdn'] }}@ims.mnc{{ Sh_template_vars['mnc'] }}.mcc{{ Sh_template_vars['mcc'] }}.3gppnetwork.org</IMSPublicIdentity>
<MSISDN>{{ Sh_template_vars['msisdn'] }}</MSISDN>
</PublicIdentifiers>
<!-- This optional extension provides the Location of the serving MME for this subscriber and the TAC for the ULA -->
<Extension>
<EPSLocationInformation>{% if Sh_template_vars['serving_mme'] is not none %}
<E-UTRANCellGlobalId></E-UTRANCellGlobalId>
<TrackingAreaId></TrackingAreaId>
<MMEName>{{ Sh_template_vars['serving_mme'] }}</MMEName>
<AgeOfLocationInformation>0</AgeOfLocationInformation>
<Extension>
<VisitedPLMNID></VisitedPLMNID>
</Extension>{% endif %}
</EPSLocationInformation>
</Extension>
<!-- This container for the XCAP Data for the Subscriber -->
<!-- XCAP data from Database -->
{{ Sh_template_vars['sh_profile'] }}
</Sh-Data>

64
pyhss/pyhss_init.sh Executable file
View File

@@ -0,0 +1,64 @@
#!/bin/bash
# BSD 2-Clause License
# Copyright (c) 2020, Supreeth Herle
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
while ! mysqladmin ping -h ${MYSQL_IP} --silent; do
sleep 5;
done
# Sleep until permissions are set
sleep 10;
# Create IMS HSS database user
PYHSS_USER_EXISTS=`mysql -u root -h ${MYSQL_IP} -s -N -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE User = 'pyhss' AND Host = '%')"`
if [[ "$PYHSS_USER_EXISTS" == 0 ]]
then
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'pyhss'@'%' IDENTIFIED WITH mysql_native_password BY 'ims_db_pass'";
mysql -u root -h ${MYSQL_IP} -e "CREATE USER 'pyhss'@'$PYHSS_IP' IDENTIFIED WITH mysql_native_password BY 'ims_db_pass'";
mysql -u root -h ${MYSQL_IP} -e "FLUSH PRIVILEGES;"
fi
[ ${#MNC} == 3 ] && EPC_DOMAIN="epc.mnc${MNC}.mcc${MCC}.3gppnetwork.org" || EPC_DOMAIN="epc.mnc0${MNC}.mcc${MCC}.3gppnetwork.org"
[ ${#MNC} == 3 ] && IMS_DOMAIN="ims.mnc${MNC}.mcc${MCC}.3gppnetwork.org" || IMS_DOMAIN="ims.mnc0${MNC}.mcc${MCC}.3gppnetwork.org"
cp /mnt/pyhss/config.yaml ./
cp /mnt/pyhss/default_ifc.xml ./
cp /mnt/pyhss/default_sh_user_data.xml ./
sed -i 's|PYHSS_IP|'$PYHSS_IP'|g' ./config.yaml
sed -i 's|IMS_DOMAIN|'$IMS_DOMAIN'|g' ./config.yaml
sed -i 's|OP_MCC|'$MCC'|g' ./config.yaml
sed -i 's|OP_MNC|'$MNC'|g' ./config.yaml
sed -i 's|MYSQL_IP|'$MYSQL_IP'|g' ./config.yaml
# Sync docker time
#ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
export FLASK_APP=PyHSS_API.py
flask run --host=$PYHSS_IP --port=8080 &
python3 hss.py