Skip to content

Commit

Permalink
Merge pull request #83 from omec-project/dev-sub-delete
Browse files Browse the repository at this point in the history
Handle Delete API at HSS to remove subscriber from the Cassandra database
  • Loading branch information
badhrinathpa authored Sep 17, 2021
2 parents 9a5f565 + 048210f commit 771c0c3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions hss/include/dataaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class DataAccess
bool getImsiInfo ( const char *imsi, DAImsiInfo &info, CassFutureCallback cb, void *data );
bool getImsiInfo ( const std::string &imsi, DAImsiInfo &info, CassFutureCallback cb, void *data ) { return getImsiInfo( imsi.c_str(), info, cb, data ); }

bool deleteUserImsi(const ImsiEntity &ie, CassFutureCallback cb, void *data);
bool insertUserImsi(const ImsiEntity &ie, CassFutureCallback cb, void *data);

bool getEventIdsFromMsisdnData( SCassFuture &future, DAEventIdList &el );
Expand Down
1 change: 1 addition & 0 deletions hss/include/fdhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class FDHss {
void sendRIR_ChangeImsiImeiSvAssn(ImsiImeiData &data);

void poppulate_IMSIs(const ImsiEntity &ie);
void remove_IMSI(const ImsiEntity &ie);

s6t::Application *gets6tApp() { return m_s6tapp; }
s6as6d::Application *gets6as6dApp() { return m_s6aapp; }
Expand Down
25 changes: 25 additions & 0 deletions hss/src/dataaccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,31 @@ bool DataAccess::insertUserImsi( const ImsiEntity &ie, CassFutureCallback cb, vo
return true;
}

bool DataAccess::deleteUserImsi( const ImsiEntity &ie, CassFutureCallback cb, void *data)
{
std::stringstream ss;

ss << "DELETE FROM vhss.users_imsi WHERE imsi='"<< ie.imsi<<"'";

std::cout << ss.str() << std::endl;

SCassStatement stmt( ss.str().c_str() );

SCassFuture future = m_db.execute( stmt );

if ( future.errorCode() != CASS_OK )
{
std::cout << "DataAccess::" << __func__ << " - Error " << future.errorCode()
<< " executing [" << ss.str() << "]" << std::endl;
return false;
}

if (cb)
return future.setCallback( cb, data );

return true;
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

Expand Down
5 changes: 5 additions & 0 deletions hss/src/fdhss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ void FDHss::poppulate_IMSIs(const ImsiEntity &ie)
m_dbobj.insertUserImsi(ie, NULL, NULL);
}

void FDHss::remove_IMSI(const ImsiEntity &ie)
{
m_dbobj.deleteUserImsi(ie, NULL, NULL);
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

Expand Down
11 changes: 11 additions & 0 deletions hss/src/resthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void RestHandler::onRequest(const Pistache::Http::Request& request, Pistache::Ht
response.send(Pistache::Http::Code::Ok);
}
} else if (request.resource() == "/v2/config/imsis") {
// Post handler
std::cout<<"v2 config imsis resource "<<std::endl;
RAPIDJSON_NAMESPACE::Document doc;
doc.Parse(request.body().c_str());
Expand All @@ -42,6 +43,16 @@ void RestHandler::onRequest(const Pistache::Http::Request& request, Pistache::Ht
response.send(Pistache::Http::Code::Ok, "");
newPortalConfig* config = parse_hss_json_doc(doc);
assert(config != NULL);
if (request.method() == Pistache::Http::Method::Delete) {
for (uint64_t imsi = config->from_imsi; imsi <= config->to_imsi; imsi++ )
{
ImsiEntity data;
data.imsi = std::to_string(imsi); data.imsi_pres = true;
fdHss.remove_IMSI(data);
}
return;
}

for (uint64_t imsi = config->from_imsi; imsi <= config->to_imsi; imsi++ )
{
ImsiEntity data;
Expand Down

0 comments on commit 771c0c3

Please sign in to comment.