Commit c5f54b5f authored by Niuhaiwen's avatar Niuhaiwen

add upf data service

parent 622905a5
......@@ -7,6 +7,7 @@ include(LwsCheckRequirements)
set(SAMP lws-minimal-ws-server)
set(SRCS minimal-ws-server.c)
set(SRCS http_server.c)
#set(requirements 1)
#require_lws_config(LWS_ROLE_WS 1 requirements)
......
......@@ -18,9 +18,28 @@
#include <string.h>
#include <signal.h>
#include <event.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/listener.h>
#include <event2/buffer.h>
#include <event2/util.h>
#include <event2/http_struct.h>
#include <event2/keyvalq_struct.h>
#include <event2/bufferevent.h>
#include <event2/bufferevent_compat.h>
#include <event2/http_compat.h>
//#include "cjson/cJSON.h"
#define HTTP_BUF 1024
volatile int g_force_exit = 0;
#define LWS_PLUGIN_STATIC
#include "protocol_lws_minimal.c"
static struct lws_protocols protocols[] = {
{ "http", lws_callback_http_dummy, 0, 0, 0, NULL, 0},
LWS_PLUGIN_PROTOCOL_MINIMAL,
......@@ -123,3 +142,134 @@ int ws_thread(int argc, const char **argv)
int ret = pthread_create(&tids, NULL, ws_server, NULL);
printf("pthread_create error: error_code= %d \n", ret);
}
//curl -X POST --data "{\"ueip_s\": [{ \"ue_ip\":\"192.169.0.3\"},{ \"ue_ip\":\"192.169.0.4\"},{ \"ue_ip\":\"192.169.0.5\"}]}" http://192.168.2.142:8081/upf/v1/subscriptions/get_traffic_by_ueip
static void
get_traffic_by_ueip_cb(struct evhttp_request *req, void *arg)
{
printf("begin...\n");
//struct evkeyvalq *headers;
//struct evkeyval *header;
struct evbuffer *buf;
struct evbuffer *retbuff = NULL;
//cJSON * reqRoot = NULL;
char jsonStr[HTTP_BUF] = {0};
#if 0
if(EVHTTP_REQ_POST != evhttp_request_get_command(req))
{
clib_upf_debug(um_http->log_fd,"http method not post\n");
return ;
}
headers = evhttp_request_get_input_headers(req);
for (header = headers->tqh_first; header; header = header->next.tqe_next)
{
clib_upf_debug(um_http->log_fd, "%s:%s\n", header->key, header->value);
}
#endif
buf = evhttp_request_get_input_buffer(req);
while (evbuffer_get_length(buf))
{
int n;
n = evbuffer_remove(buf, jsonStr, sizeof(jsonStr));
if (n <= 0)
printf(" req data len is 0");
//(void) fwrite(cbuf, 1, n, stdout);
}
#if 0
reqRoot = cJSON_Parse(jsonStr);
if (!reqRoot)
{
printf("Error before: [%s]\n",cJSON_GetErrorPtr());
}
else
{
printf("req:%s\n\n", cJSON_PrintUnformatted(reqRoot));
}
#endif
// cJSON_Delete(reqRoot);
//char *resp_Data = "recv data\n";
retbuff = evbuffer_new();
if(!retbuff)
{
printf("%s\n","retbuff is NULL.");
goto ERROR;
}
evbuffer_add(retbuff, jsonStr, strlen(jsonStr));
evhttp_send_reply(req, 200, "OK", retbuff);
printf("send http 200 ok len:%d, jsonstr:%s\n", strlen(jsonStr), jsonStr);
update_client(strlen(jsonStr), jsonStr);
//websocket_client_send_data(jsonStr, strlen(jsonStr));
printf("end...\n");
ERROR:
if(retbuff)
evbuffer_free(retbuff);
}
void *http_server_thread_fn(void *arg)
{
struct event_base *base = NULL;
struct evhttp *http_server = NULL;
char *http_addr = "192.168.199.235";
int http_port = 8081;
/* Initialize the event library */
base = event_base_new();
http_server = evhttp_new(base);
if(!http_server )
{
printf("%s:%d http server start failed\n",http_addr, http_port);
return NULL;
}
evhttp_bind_socket(http_server, http_addr, http_port);
evhttp_set_cb(http_server, "/upf/v1/subscriptions/get_traffic_by_ueip", get_traffic_by_ueip_cb, NULL);
//Loop monitoring
event_base_dispatch(base);
if(http_server)
evhttp_free(http_server);
if (base)
event_base_free(base);
return NULL;
}
int run_http_server_thread()
{
pthread_t ntid;
int err;
err = pthread_create(&ntid, NULL, http_server_thread_fn, NULL);
if(err != 0)
{
printf("can't create thread: %s",strerror(err));
return -1;
}
//pthread_join(ntid, NULL);
return 0;
}
int http_service()
{
printf("http_service ..................\n");
run_http_server_thread();
return 0;
}
# $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
PermitRootLogin yes
......@@ -319,5 +319,5 @@ IF(STATIC_LINKING)
ENDIF(STATIC_LINKING)
target_link_libraries (smf ${ASAN}
-Wl,--start-group CN_UTILS SMF UDP PFCP 3GPP_COMMON_TYPES SMF_API -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto NAS gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system pistache curl WSSERVER -lwebsockets)
-Wl,--start-group CN_UTILS SMF UDP PFCP 3GPP_COMMON_TYPES SMF_API -lnettle ${NETTLE_LIBRARIES} ${CRYPTO_LIBRARIES} -lnghttp2_asio -lboost_system -lboost_thread -lssl -lcrypto NAS gflags glog dl double-conversion folly -Wl,--end-group pthread m rt config++ event boost_system pistache curl WSSERVER -lwebsockets -levent)
......@@ -91,6 +91,10 @@ void my_app_signal_handler(int s) {
exit(0);
}
extern "C" {
void http_service();
}
extern "C" {
int ws_thread();
}
......@@ -109,6 +113,7 @@ int main(int argc, char** argv) {
Logger::smf_app().startup("Options parsed");
ws_thread();
http_service();
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_app_signal_handler;
......
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