Commit f41b38e8 authored by gauthier's avatar gauthier

mains

parent 1e0941d0
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "async_shell_cmd.hpp"
#include "common_defs.h"
#include "itti.hpp"
#include "logger.hpp"
#include "options.hpp"
#include "pid_file.hpp"
#include "pgw_app.hpp"
#include "pgw_config.hpp"
#include "sgwc_app.hpp"
#include "sgwc_config.hpp"
#include <boost/asio.hpp>
#include <iostream>
#include <thread>
#include <signal.h>
#include <stdint.h>
#include <unistd.h> // get_pid(), pause()
using namespace oai::cn::proto::gtpv2c;
using namespace oai::cn::core::itti;
using namespace oai::cn::nf::pgwc;
using namespace oai::cn::nf::sgwc;
using namespace oai::cn::util;
using namespace std;
itti_mw *itti_inst = nullptr;
async_shell_cmd *async_shell_cmd_inst = nullptr;
pgw_app *pgw_app_inst = nullptr;
sgwc_app *sgwc_app_inst = nullptr;
pgw_config pgw_cfg;
sgwc_config sgwc_cfg;
boost::asio::io_service io_service;
//------------------------------------------------------------------------------
void my_app_signal_handler(int s){
std::cout << "Caught signal " << s << std::endl;
Logger::system().startup( "exiting" );
itti_inst->send_terminate_msg(TASK_SGWC_APP);
itti_inst->wait_tasks_end();
std::cout << "Freeing Allocated memory..." << std::endl;
if (async_shell_cmd_inst) delete async_shell_cmd_inst; async_shell_cmd_inst = nullptr;
std::cout << "Async Shell CMD memory done." << std::endl;
if (itti_inst) delete itti_inst; itti_inst = nullptr;
std::cout << "ITTI memory done." << std::endl;
if (sgwc_app_inst) delete sgwc_app_inst; sgwc_app_inst = nullptr;
std::cout << "SGW APP memory done." << std::endl;
if (pgw_app_inst) delete pgw_app_inst; pgw_app_inst = nullptr;
std::cout << "PGW APP memory done." << std::endl;
std::cout << "Freeing Allocated memory done" << std::endl;
exit(0);
}
//------------------------------------------------------------------------------
int main(int argc, char **argv)
{
// Logger
Logger::init( "spgwc" );
// Command line options
if ( !Options::parse( argc, argv ) )
{
std::cout << "Options::parse() failed" << std::endl;
return 1;
}
Logger::sgwc_app().startup( "Options parsed" );
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_app_signal_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// Config
// Inter task Interface
itti_inst = new itti_mw();
itti_inst->start();
// system command
async_shell_cmd_inst = new async_shell_cmd();
// PGW application layer
pgw_app_inst = new pgw_app(Options::getlibconfigConfig());
// PID file
// Currently hard-coded value. TODO: add as config option.
string pid_file_name = get_exe_absolute_path("/var/run", pgw_cfg.instance);
if (! is_pid_file_lock_success(pid_file_name.c_str())) {
Logger::pgwc_app().error( "Lock PID file %s failed\n", pid_file_name.c_str());
exit (-EDEADLK);
}
// SGW application layer
sgwc_app_inst = new sgwc_app(Options::getlibconfigConfig());
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/spgwc_{}.status", getpid());
fp = fopen(filename.c_str(), "w+");
fprintf(fp, "STARTED\n");
fflush(fp);
fclose(fp);
// once all udp servers initialized
io_service.run();
pause();
return 0;
}
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "options.hpp"
int Options::options;
std::string Options::m_libconfigcfg;
void Options::help()
{
std::cout << std::endl
<< "Usage: spgwc [OPTIONS]..." << std::endl
<< " -h, --help Print help and exit" << std::endl
<< " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
;
}
bool Options::parse( int argc, char **argv ){
bool ret = true;
ret = parseInputOptions( argc, argv );
ret &= validateOptions();
return ret;
}
bool Options::validateOptions(){
return (
(options & libconfigcfg)
);
}
bool Options::parseInputOptions( int argc, char **argv )
{
int c;
int option_index = 0;
bool result = true;
struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "libconfigcfg", required_argument, NULL, 'f' },
{ NULL,0,NULL,0 }
};
// Loop on arguments
while (1)
{
c = getopt_long(argc, argv, "hc:", long_options, &option_index );
if (c == -1)
break; // Exit from the loop.
switch (c)
{
case 'h': { help(); exit(0); break; }
case 'c': { m_libconfigcfg = optarg; options |= libconfigcfg; break; }
case '?':
{
switch ( optopt )
{
case 'c': { std::cout << "Option -l (libconfig config) requires an argument" << std::endl; break; }
default: { std::cout << "Unrecognized option [" << c << "]" << std::endl; break; }
}
result = false;
break;
}
default:
{
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
}
}
return result;
}
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#ifndef __OPTIONS_H
#define __OPTIONS_H
#include <stdint.h>
#include <string>
class Options
{
public:
static bool parse( int argc, char **argv );
static bool parseInputOptions( int argc, char **argv );
static bool parseJson();
static bool validateOptions();
static const std::string &getlibconfigConfig() { return m_libconfigcfg; }
private:
enum OptionsSelected {
libconfigcfg = 0x01,
};
static void help();
static int options;
static std::string m_libconfigcfg;
};
#endif // #define __OPTIONS_H
/*
* Copyright (c) 2019 EURECOM
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include "async_shell_cmd.hpp"
#include "common_defs.h"
#include "itti.hpp"
#include "logger.hpp"
#include "options.hpp"
#include "pfcp_switch.hpp"
#include "pid_file.hpp"
#include "spgwu_app.hpp"
#include "spgwu_config.hpp"
#include <boost/asio.hpp>
#include <iostream>
#include <thread>
#include <signal.h>
#include <stdint.h>
#include <unistd.h> // get_pid(), pause()
#include <vector>
using namespace oai::cn::core::itti;
using namespace oai::cn::nf::spgwu;
using namespace oai::cn::util;
using namespace std;
itti_mw *itti_inst = nullptr;
async_shell_cmd *async_shell_cmd_inst = nullptr;
pfcp_switch *pfcp_switch_inst = nullptr;
spgwu_app *spgwu_app_inst = nullptr;
spgwu_config spgwu_cfg;
boost::asio::io_service io_service;
//------------------------------------------------------------------------------
void my_app_signal_handler(int s){
std::cout << "Caught signal " << s << std::endl;
Logger::system().startup( "exiting" );
itti_inst->send_terminate_msg(TASK_SPGWU_APP);
itti_inst->wait_tasks_end();
std::cout << "Freeing Allocated memory..." << std::endl;
if (async_shell_cmd_inst) delete async_shell_cmd_inst; async_shell_cmd_inst = nullptr;
std::cout << "Async Shell CMD memory done." << std::endl;
if (itti_inst) delete itti_inst; itti_inst = nullptr;
std::cout << "ITTI memory done." << std::endl;
if (spgwu_app_inst) delete spgwu_app_inst; spgwu_app_inst = nullptr;
std::cout << "SPGW-U APP memory done." << std::endl;
std::cout << "Freeing Allocated memory done" << std::endl;
exit(0);
}
//------------------------------------------------------------------------------
int main(int argc, char **argv)
{
// Logger
Logger::init( "spgwu");
// Command line options
if ( !Options::parse( argc, argv ) )
{
std::cout << "Options::parse() failed" << std::endl;
return 1;
}
Logger::spgwu_app().startup( "Options parsed" );
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = my_app_signal_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// Config
// Inter task Interface
itti_inst = new itti_mw();
itti_inst->start();
// system command
async_shell_cmd_inst = new async_shell_cmd();
// PGW application layer
spgwu_app_inst = new spgwu_app(Options::getlibconfigConfig());
// PID file
// Currently hard-coded value. TODO: add as config option.
string pid_file_name = get_exe_absolute_path("/var/run", spgwu_cfg.instance);
if (! is_pid_file_lock_success(pid_file_name.c_str())) {
Logger::spgwu_app().error( "Lock PID file %s failed\n", pid_file_name.c_str());
exit (-EDEADLK);
}
FILE *fp = NULL;
std::string filename = fmt::format("/tmp/spgwu_{}.status", getpid());
fp = fopen(filename.c_str(), "w+");
fprintf(fp, "STARTED\n");
fflush(fp);
fclose(fp);
// once all udp servers initialized
io_service.run();
pause();
return 0;
}
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "options.hpp"
int Options::options;
std::string Options::m_libconfigcfg;
void Options::help()
{
std::cout << std::endl
<< "Usage: spgwu [OPTIONS]..." << std::endl
<< " -h, --help Print help and exit" << std::endl
<< " -c, --libconfigcfg filename Read the application configuration from this file." << std::endl
;
}
bool Options::parse( int argc, char **argv ){
bool ret = true;
ret = parseInputOptions( argc, argv );
ret &= validateOptions();
return ret;
}
bool Options::validateOptions(){
return (
(options & libconfigcfg)
);
}
bool Options::parseInputOptions( int argc, char **argv )
{
int c;
int option_index = 0;
bool result = true;
struct option long_options[] = {
{ "help", no_argument, NULL, 'h' },
{ "libconfigcfg", required_argument, NULL, 'f' },
{ NULL,0,NULL,0 }
};
// Loop on arguments
while (1)
{
c = getopt_long(argc, argv, "hc:", long_options, &option_index );
if (c == -1)
break; // Exit from the loop.
switch (c)
{
case 'h': { help(); exit(0); break; }
case 'c': { m_libconfigcfg = optarg; options |= libconfigcfg; break; }
case '?':
{
switch ( optopt )
{
case 'c': { std::cout << "Option -l (libconfig config) requires an argument" << std::endl; break; }
default: { std::cout << "Unrecognized option [" << c << "]" << std::endl; break; }
}
result = false;
break;
}
default:
{
std::cout << "Unrecognized option [" << c << "]" << std::endl;
result = false;
}
}
}
return result;
}
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
#ifndef __OPTIONS_H
#define __OPTIONS_H
#include <stdint.h>
#include <string>
class Options
{
public:
static bool parse( int argc, char **argv );
static bool parseInputOptions( int argc, char **argv );
static bool parseJson();
static bool validateOptions();
static const std::string &getlibconfigConfig() { return m_libconfigcfg; }
private:
enum OptionsSelected {
libconfigcfg = 0x01,
};
static void help();
static int options;
static std::string m_libconfigcfg;
};
#endif // #define __OPTIONS_H
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