From f9b2c6434ab6dab49802b7520d35a2be8b164aa2 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 17 Nov 2017 18:01:06 +0000 Subject: [PATCH] Added TUN SGi interface to SP-GW. --- srsepc/hdr/spgw/spgw.h | 1 + srsepc/src/main.cc | 28 ++++++++++++++++++++++------ srsepc/src/spgw/spgw.cc | 20 ++++++++++++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/srsepc/hdr/spgw/spgw.h b/srsepc/hdr/spgw/spgw.h index 6d781cf61..ffd854b38 100644 --- a/srsepc/hdr/spgw/spgw.h +++ b/srsepc/hdr/spgw/spgw.h @@ -68,6 +68,7 @@ private: bool m_running; srslte::byte_buffer_pool *m_pool; + bool m_if_up; int m_sgi_if; int m_sgi_sock; /*Logs*/ diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index 1627a216c..eae1ab45b 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -29,6 +29,7 @@ #include "srslte/common/bcd_helpers.h" #include "mme/mme.h" #include "hss/hss.h" +#include "spgw/spgw.h" using namespace std; using namespace srsepc; @@ -49,9 +50,10 @@ typedef struct { typedef struct{ - mme_args_t mme_args; - hss_args_t hss_args; - log_args_t log_args; + mme_args_t mme_args; + hss_args_t hss_args; + spgw_args_t spgw_args; + log_args_t log_args; }all_args_t; /********************************************************************** @@ -197,6 +199,11 @@ main (int argc,char * argv[] ) hss_log.init("HSS ",logger); hss_log.set_level(srslte::LOG_LEVEL_DEBUG); hss_log.set_hex_limit(32); + + srslte::log_filter spgw_log; + spgw_log.init("SPGW",logger); + spgw_log.set_level(srslte::LOG_LEVEL_DEBUG); + spgw_log.set_hex_limit(32); mme *mme = mme::get_instance(); if (mme->init(&args.mme_args, &s1ap_log)) { @@ -209,15 +216,24 @@ main (int argc,char * argv[] ) cout << "Error initializing HSS" << endl; exit(1); } - + + spgw *spgw = spgw::get_instance(); + if (spgw->init(&args.spgw_args,&spgw_log)) { + cout << "Error initializing SP-GW" << endl; + exit(1); + } + mme->start(); + spgw->start(); while(running) { sleep(1); } mme->stop(); mme->cleanup(); - - cout << "--- exiting ---" << endl; + spgw->stop(); + spgw->cleanup(); + + cout << std::endl <<"--- exiting ---" << endl; return 0; } diff --git a/srsepc/src/spgw/spgw.cc b/srsepc/src/spgw/spgw.cc index 016188ec0..edceda337 100644 --- a/srsepc/src/spgw/spgw.cc +++ b/srsepc/src/spgw/spgw.cc @@ -40,7 +40,8 @@ spgw* spgw::m_instance = NULL; boost::mutex spgw_instance_mutex; spgw::spgw(): - m_running(false) + m_running(false), + m_if_up(false) { m_pool = srslte::byte_buffer_pool::get_instance(); return; @@ -92,6 +93,13 @@ spgw::stop() m_running = false; thread_cancel(); wait_thread_finish(); + + //Clean up interface + if(m_if_up) + { + close(m_sgi_if); + close(m_sgi_sock); + } } return; } @@ -114,6 +122,12 @@ spgw::init_sgi_if() char dev[IFNAMSIZ] = "srs_spgw_sgi"; struct ifreq ifr; + if(m_if_up) + { + return(srslte::ERROR_ALREADY_STARTED); + } + + // Construct the TUN device m_sgi_if = open("/dev/net/tun", O_RDWR); m_spgw_log->info("TUN file descriptor = %d\n", m_sgi_if); @@ -149,10 +163,8 @@ spgw::init_sgi_if() return(srslte::ERROR_CANT_START); } - //if_up = true; - + m_if_up = true; return(srslte::ERROR_NONE); - } } //namespace srsepc