Commit 474b7631 authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'nrf_python_client' into 'prepare-public-release'

nrf python client

See merge request oai/cn5g/oai-cn5g-upf-vpp!5
parents 17c02ea1 abf41403
......@@ -91,7 +91,8 @@ RUN yum repolist --disablerepo=* && \
tshark \
tzdata\
iproute \
wget && \
wget \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm && \
wget http://repo.openfusion.net/centos7-x86_64/hyperscan-devel-5.3.0-1.of.el7.x86_64.rpm \
http://repo.openfusion.net/centos7-x86_64/hyperscan-5.3.0-1.of.el7.x86_64.rpm && \
rpm -i *.rpm && \
......@@ -99,14 +100,18 @@ RUN yum repolist --disablerepo=* && \
yum remove -y wget && \
rm -rf /var/lib/apt/lists/*
RUN yum install -y python-pip && pip install termcolor
WORKDIR /openair-upf/bin
COPY --from=vpp-upf-builder /vpp-upf/scripts/entrypoint.sh .
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp .
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl .
COPY --from=vpp-upf-builder /vpp-upf/scripts/nrf_client.py .
WORKDIR /openair-upf/etc
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/init.conf .
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/startup_debug.conf .
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/upf_profile.json .
WORKDIR /usr/lib64
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/ .
......
......@@ -93,16 +93,23 @@ RUN apt-get update && \
iproute2 \
iputils-ping \
vim \
python \
python-pip \
libcurl4-openssl-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pip install pycurl termcolor
WORKDIR /openair-upf/bin
COPY --from=vpp-upf-builder /vpp-upf/scripts/entrypoint.sh .
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp .
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl .
COPY --from=vpp-upf-builder /vpp-upf/scripts/nrf_client.py .
WORKDIR /openair-upf/etc
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/init.conf .
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/startup_debug.conf .
COPY --from=vpp-upf-builder /vpp-upf/scripts/upf_conf/upf_profile.json .
WORKDIR /usr/lib/x86_64-linux-gnu/
COPY --from=vpp-upf-builder /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/ .
......
#!/usr/bin/env bash
#"""
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1 (the "License"); you may not use this
# * file except in compliance with the License. You may obtain a copy of the
# * License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
#
#/*! \file nrf_client.py
# \author Rohan KHARADE
# \date 2021
# \email: rohan.kharade@openairinterface.org
#*/
#"""
# files are common to docker and native installation
#____________
# init.conf => upf config
......@@ -10,12 +39,19 @@
set -euo pipefail
CONFIG_DIR="/openair-upf/etc"
SGI_IPV4=$(ifconfig $INTERFACE_SGI | grep "inet " | awk '{print $2}')
ACCESS_IPV4=$(ifconfig $INTERFACE_ACCESS | grep "inet " | awk '{print $2}')
CORE_IPV4=$(ifconfig $INTERFACE_CORE | grep "inet " | awk '{print $2}')
N3_IPV4_ADDRESS_LOCAL=$(ifconfig $INTERFACE_ACCESS | grep "inet " | awk '{print $2}' | cut -d"." -f1-3)".202"
N4_IPV4_ADDRESS_LOCAL=$(ifconfig $INTERFACE_CORE | grep "inet " | awk '{print $2}' | cut -d"." -f1-3)".202"
N6_IPV4_ADDRESS_LOCAL=$(ifconfig $INTERFACE_SGI | grep "inet " | awk '{print $2}' | cut -d"." -f1-3)".202"
###############################
# UPF Config
###############################
for c in ${CONFIG_DIR}/*.conf; do
array=(${CONFIG_DIR}/*.conf ${CONFIG_DIR}/*.json)
for c in "${array[@]}"; do
# grep variable names (format: ${VAR}) from template to be rendered
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${c} | sort | uniq | xargs)
# create sed expressions for substituting each occurrence of ${VAR}
......@@ -44,7 +80,6 @@ done
# Near future we will have multiple interfaces (e.g. two n6 interface for edge computing case)
# We define in this order in docker-compose -> it is alphabetical order
#
SGI_IPV4=$(ifconfig $INTERFACE_SGI | grep "inet " | awk '{print $2}')
ip link set $INTERFACE_ACCESS down
ip link set $INTERFACE_ACCESS name access
......
#!/usr/bin/env python
"""
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file nrf_client.py
\author Rohan KHARADE
\date 2018
\email: rohan.kharade@openairinterface.org
*/
"""
import time, sys, json, logging, uuid, pycurl, argparse, atexit
from termcolor import colored
logging.basicConfig(format='%(asctime)s] %(filename)s: %(levelname)s '
'- %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
class upf_profile(object):
def __init__(self, nrf_ip = None, nrf_port = None, http_version = None):
self.logger = logging.getLogger("upf")
atexit.register(self.goodbye) # register a message to print out when exit
message = " NRF UPF client started "
self.logger.info(message)
#@@@@@@@@ Initialize arguments #@@@@@@@@
self.nrf_ip = nrf_ip
self.nrf_port = nrf_port
self.http_version = http_version
self.status_code = 0
self.uuid = uuid.uuid4()
self.url = 'http://'+str(self.nrf_ip)+':'+str(self.nrf_port)+'/nnrf-nfm/v1/nf-instances/'+str(self.uuid)
self.curl = pycurl.Curl()
self.headers = ["Content-Type:application/json"]
self.dir_config = '/openair-upf/'
self.file_name = self.dir_config+'etc/upf_profile.json'
self.conf_file = open(self.file_name,)
self.upf_profile = json.load(self.conf_file)
#@@@@@@@@ Initialize upf profile #@@@@@@@@
self.upf_profile['nfInstanceId'] = str(self.uuid)
self.capacity = self.upf_profile['capacity']
self.fqdn = self.upf_profile['fqdn']
self.heartBeatTimer = self.upf_profile['heartBeatTimer']
self.ipv4Addresses = self.upf_profile['ipv4Addresses']
self.nfInstanceId = self.upf_profile['nfInstanceId']
self.nfInstanceName = self.upf_profile['nfInstanceName']
self.nfStatus = self.upf_profile['nfStatus']
self.nfType = self.upf_profile['nfType']
self.priority = self.upf_profile['priority']
self.sNssais = self.upf_profile['sNssais']
self.upfInfo = self.upf_profile['upfInfo']
message = " UPF profile is parsed "
self.logger.info(message)
def display_upf_profile(self):
message = " Display UPF profile "
self.logger.info(message)
print(colored('[*] UPF Profile \n \t fqdn = '+self.fqdn+ \
'\n \t capacity = '+str(self.capacity)+ \
'\n \t heartBeatTimer = '+str(self.heartBeatTimer)+ \
'\n \t ipv4Addresses = '+u", ".join(self.ipv4Addresses)+ \
'\n \t nfInstanceId = '+self.nfInstanceId+ \
'\n \t nfInstanceName = '+self.nfInstanceName+ \
'\n \t nfStatus = '+self.nfStatus+ \
'\n \t nfType = '+self.nfType+ \
'\n \t priority = '+str(self.priority)+ \
'\n \t sNssais = '+json.dumps(self.sNssais)+ \
'\n \t upfInfo = '+json.dumps(self.upfInfo,indent=6) \
,'green'))
def trigger_nf_registration(self):
message = " Sending NF registration request (HTTP Version - "+str(self.http_version)+")"
self.logger.info(message)
self.curl.setopt(self.curl.URL, self.url)
self.curl.setopt(self.curl.HTTPHEADER, self.headers)
self.curl.setopt(self.curl.CUSTOMREQUEST, 'PUT')
self.curl.setopt(self.curl.POSTFIELDS, json.dumps(self.upf_profile))
if(str(self.http_version) == '2'):
self.curl.setopt(self.curl.HTTP_VERSION, pycurl.CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE)
response=self.curl.perform()
self.status_code=self.curl.getinfo(self.curl.RESPONSE_CODE)
if self.status_code == 201 or self.status_code == 200:
message = " Succussfully registered at NRF !!"
self.logger.info(message)
self.trigger_nf_heartbeat()
else:
print(colored('\n\n NF registration failed \n\n', 'red'))
def trigger_nf_heartbeat(self):
patch_data = [{"op": "replace","path": "/nfStatus","value": "REGISTERED"}]
while True:
message = " Sending NF heartbeat requset (HTTP Version - "+str(self.http_version)+") !!"
self.logger.info(message)
time.sleep(5)
self.curl.setopt(self.curl.CUSTOMREQUEST, 'PATCH')
self.curl.setopt(self.curl.POSTFIELDS, json.dumps(patch_data))
response=self.curl.perform()
self.status_code=self.curl.getinfo(self.curl.RESPONSE_CODE)
if self.status_code == 204:
message = " Succussfully received NF heartbeat response !!"
self.logger.info(message)
else:
print(colored('\n\n NF heartbeat procedure failed \n\n', 'red'))
def goodbye(self):
print(colored('\n\n\n [*] You are now leaving OAI-NRF framework .....\n\n\n', 'yellow'))
sys.exit(0)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Process commandline arguments and override configurations')
parser.add_argument('--nrf_ip', metavar='[number]', action='store', type=str,
required=False, default='192.168.71.130',
help='set the nrf ip address. default = 192.168.71.130')
parser.add_argument('--nrf_port', metavar='[number]', action='store', type=str,
required=False, default='8080',
help='set the nrf port. default = 8080')
parser.add_argument('--http_version', metavar='[number]', action='store', type=str,
required=False, default='2',
help='set the nrf ip address. default = 2')
args = parser.parse_args()
nrf_client = upf_profile(args.nrf_ip, args.nrf_port, args.http_version)
nrf_client.display_upf_profile()
nrf_client.trigger_nf_registration()
"""
* Usage of nrf client -->
$ python nrf_client.py -h
usage: nrf_client.py [-h] [--nrf_ip [number]] [--nrf_port [number]]
[--http_version [number]]
Process commandline arguments and override configurations
optional arguments:
-h, --help show this help message and exit
--nrf_ip [number] set the nrf ip address. default = 192.168.71.130
--nrf_port [number] set the nrf port. default = 8080
--http_version [number] set the nrf ip address. default = 2
"""
#!/bin/sh -x
#!/bin/bash
#"""
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1 (the "License"); you may not use this
# * file except in compliance with the License. You may obtain a copy of the
# * License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
#
#/*! \file nrf_client.py
# \author Rohan KHARADE
# \date 2021
# \email: rohan.kharade@openairinterface.org
#*/
#"""
if [ $(id -u) -ne 0 ]; then
exec sudo -E "$0" "$@"
......@@ -25,10 +54,11 @@ while getopts ":r" opt; do
;;
esac
done
shift $((OPTIND-1))
if test -z "$1"; then
$APP $ARGS
$APP $ARGS &
elif test "$1" = "debug"; then
shift
gdb -ex 'set print pretty on' -ex 'run' --args $APP $ARGS $@
......@@ -37,3 +67,11 @@ else
exit 1
fi
if [[ ${REGISTER_NRF} == "yes" ]];then
sleep 5
NRF_APP="$base/bin/nrf_client.py"
NRF_ARGS=" --nrf_ip="$NRF_IP_ADDR" --nrf_port="$NRF_PORT" --http_version="$HTTP_VERSION
python $NRF_APP $NRF_ARGS
fi
This diff is collapsed.
{
"capacity": 100,
"fqdn": "gw@GW_ID@.vppupf.node.5gcn.mnc@MNC03@.mcc@MCC@.@REALM@",
"heartBeatTimer": 10,
"ipv4Addresses": ["@N4_IPV4_ADDRESS_LOCAL@"],
"json_data": null,
"nfInstanceName": "OAI-UPF-VPP",
"nfServices": [],
"nfStatus": "REGISTERED",
"nfType": "UPF",
"priority": 1,
"sNssais": [{
"sd": "@NSSAI_SD_0@",
"sst": @SST@
}],
"upfInfo": {
"sNssaiUpfInfoList": [{
"dnnUpfInfoList": [{
"dnn": "@DNN@"
}],
"sNssai": {
"sd": "@NSSAI_SD_0@",
"sst": @SST@
}
}],
"interfaceUpfInfoList": [{
"endpointFqdn": "@NWI_ACCESS@",
"interfaceType": "N3",
"ipv4EndpointAddresses": ["@ACCESS_IPV4@"],
"networkInstance": "@NWI_ACCESS@"
}, {
"endpointFqdn": "@NWI_CORE@",
"interfaceType": "N6",
"ipv4EndpointAddresses": ["@CORE_IPV4@"],
"networkInstance": "@NWI_CORE@"
}]
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment