Skip to content

Commit

Permalink
Aug 28 2:25AM
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadagopan committed Aug 27, 2015
1 parent fb6c414 commit da2d442
Show file tree
Hide file tree
Showing 23 changed files with 516 additions and 214 deletions.
16 changes: 8 additions & 8 deletions Documentation
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Things to do:

1. Encryption
2. Integrity check
3. Detach procedure
4. Employing Distribution function
5. Running program for a fixed amount of time
- Encryption
- Integrity check
- Detach procedure
- Running program for a fixed amount of time
- Employing Distribution function

Doubts in the implementation:

Expand Down Expand Up @@ -163,13 +163,13 @@ User Equipment Uplink & Downlink Data transfer:
Detach Procedure:

Step - 1:
After sending iperf data traffic for a required amount of time, UE sends detach request to MME with type - 2.
After sending iperf data traffic for a required amount of time, UE sends detach request to MME with type - 3.

RAN to MME(Plain)
type = 2
type = 3

Step - 2:
On receiving type-2 detach request from UE, MME would forward the Delete Session Request message but now the type would be 3(through GTP-C) to the concerned SGW for this UE and it would then remove the corresponding entry(Client num it has obtained when this UE requested for attach) in the bearer table for this UE.
On receiving type-3 detach request from UE, MME would forward the Delete Session Request message(through GTP-C) to the concerned SGW for this UE and it would then remove the corresponding entry(Client num it has obtained when this UE requested for attach) in the bearer table for this UE.

MME to SGW(GTP-C)
type = 3
Expand Down
18 changes: 9 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ G++ = g++ -std=c++0x -std=gnu++0x
RAN_H = utils.h packet.h client.h ue.h enodeb.h
RAN_CPP = utils.cpp packet.cpp client.cpp ue.cpp enodeb.cpp

MME_H = utils.h packet.h thread_pool.h server.h client.h
MME_CPP = utils.cpp packet.cpp thread_pool.cpp server.cpp client.cpp
MME_H = utils.h packet.h thread_pool.h server.h client.h mme.h
MME_CPP = utils.cpp packet.cpp thread_pool.cpp server.cpp client.cpp mme.cpp

HSS_H = utils.h packet.h thread_pool.h server.h db_mysql.h
HSS_CPP = utils.cpp packet.cpp thread_pool.cpp server.cpp db_mysql.cpp
Expand All @@ -32,27 +32,27 @@ SINK_CPP = utils.cpp packet.cpp thread_pool.cpp server.cpp client.cpp sink_monit

#---------Prerequisites and Recipes---------#

RAN_P = ran.cpp ran.h $(RAN_H) $(RAN_CPP)
RAN_P = ran.h ran.cpp $(RAN_H) $(RAN_CPP)
RAN_R = $(G++) ran.cpp -w -o ran $(RAN_CPP) -lpthread


MME_P = mme.cpp mme.h $(MME_H) $(MME_CPP)
MME_R = $(G++) mme.cpp -w -o mme $(MME_CPP) -lpthread
MME_P = mme_server.h mme_server.cpp $(MME_H) $(MME_CPP)
MME_R = $(G++) mme_server.cpp -w -o mme $(MME_CPP) -lpthread


HSS_P = hss.cpp hss.h $(HSS_H) $(HSS_CPP)
HSS_P = hss.h hss.cpp $(HSS_H) $(HSS_CPP)
HSS_R = $(G++) hss.cpp -w -o hss $(HSS_CPP) `mysql_config --cflags --libs`


SGW_P = sgw_server.cpp sgw_server.h $(SGW_H) $(SGW_CPP)
SGW_P = sgw_server.h sgw_server.cpp $(SGW_H) $(SGW_CPP)
SGW_R = $(G++) sgw_server.cpp -w -o sgw $(SGW_CPP) -lpthread


PGW_P = pgw_server.cpp pgw_server.h $(PGW_H) $(PGW_CPP)
PGW_P = pgw_server.h pgw_server.cpp $(PGW_H) $(PGW_CPP)
PGW_R = $(G++) pgw_server.cpp -w -o pgw $(PGW_CPP) -lpthread


SINK_P = sink_server.cpp sink_server.h $(SINK_H) $(SINK_CPP)
SINK_P = sink_server.h sink_server.cpp $(SINK_H) $(SINK_CPP)
SINK_R = $(G++) sink_server.cpp -w -o sink $(SINK_CPP) -lpthread

#-------------------------------------------#
Expand Down
152 changes: 16 additions & 136 deletions mme.cpp
Original file line number Diff line number Diff line change
@@ -1,160 +1,40 @@
#include "mme.h"

Gateways::Gateways(){
TunData::TunData(){

sgw_addr = allocate_str_mem(INET_ADDRSTRLEN);
pgw_addr = allocate_str_mem(INET_ADDRSTRLEN);
}

void Gateways::set_sgw(){
sgw_port = g_sgw1_port;
strcpy(sgw_addr, g_sgw1_addr);
}

void Gateways::set_pgw(){
pgw_port = g_pgw_port;
strcpy(pgw_addr, g_pgw_addr);
}
TunData::~TunData(){

Gateways::~Gateways(){
free(sgw_addr);
free(pgw_addr);
}

void Tunnel::set_mme_cteid(int ue_num){
mme_cteid = ue_num;
}
MME::MME(){

void *multithreading_func(void *arg){
int type;

ClientDetails ue = *(ClientDetails*)arg;
Server mme;
mme.fill_server_details(g_freeport, g_mme_addr);
mme.bind_server();
//setsockopt(mme.server_socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&g_timeout, sizeof(timeval));
mme.client_sock_addr = ue.client_sock_addr;
mme.client_num = ue.num;
mme.connect_with_client();
mme.read_data();
Client to_hss;
to_hss.bind_client();
to_hss.fill_server_details(g_hss_port, g_hss_addr);
to_hss.connect_with_server(ue.num);
memcpy(&type, mme.pkt.data, sizeof(type));
if(type == 1){
authenticate(mme, to_hss);
setup_tunnel(mme, to_hss, mme.client_num);
}
ue_ip = allocate_str_mem(INET_ADDRSTRLEN);
reply = allocate_str_mem(BUFFER_SIZE);
}

void authenticate(Server &mme, Client &to_hss){
unsigned long long xres, res;
const char *msg;
to_hss.pkt.clear_data();
to_hss.pkt.fill_data(0, mme.pkt.data_len, (const char*)mme.pkt.data);
to_hss.pkt.make_data_packet();
to_hss.write_data();
to_hss.read_data();
memcpy(&xres, to_hss.pkt.data + 2*sizeof(unsigned long long), sizeof(xres));
mme.pkt.clear_data();
mme.pkt.fill_data(0, 2*sizeof(unsigned long long), (const char*)to_hss.pkt.data);
mme.pkt.make_data_packet();
mme.write_data();
mme.read_data();
memcpy(&res, mme.pkt.data, sizeof(res));
if(xres == res){
msg = "OK";
mme.pkt.clear_data();
mme.pkt.fill_data(0, strlen(msg), msg);
mme.pkt.make_data_packet();
mme.write_data();
}
}
void MME::set_ue_num(){

void setup_tunnel(Server &mme, Client &to_hss, int ue_num){
Gateways gw;
Tunnel tun;
char *ue_addr = allocate_str_mem(IP_MAXPACKET);
gw.set_sgw();
gw.set_pgw();
tun.set_mme_cteid(ue_num);
mme.read_data();
Client to_sgw;
to_sgw.bind_client();
to_sgw.fill_server_details(gw.sgw_port, gw.sgw_addr);
to_sgw.connect_with_server(ue_num);
// to_sgw.pkt.fill_ip_hdr(g_mme_addr, gw.sgw_addr);
// to_sgw.pkt.fill_udp_addr();
create_session(to_sgw, ue_num, tun);
memcpy(&tun.enodeb_uteid, mme.pkt.data, sizeof(uint16_t));
modify_session(to_sgw, ue_num, tun);
memcpy(&tun.sgw_uteid, to_sgw.pkt.data, sizeof(uint16_t));
memcpy(ue_addr, to_sgw.pkt.data + sizeof(uint16_t), INET_ADDRSTRLEN);
cout<<"UE addr is "<<ue_addr<<endl;
mme.pkt.clear_data();
mme.pkt.fill_data(0, sizeof(uint16_t), tun.sgw_uteid);
mme.pkt.fill_data(sizeof(uint16_t), INET_ADDRSTRLEN, ue_addr);
mme.pkt.make_data_packet();
mme.write_data();
cout<<"Tunnel Setup successful for client - "<<ue_num<<endl;
free(ue_addr);
}

void create_session(Client &to_sgw, int ue_num, Tunnel &tun){
int type = 1;
char *reply = allocate_str_mem(BUFFER_SIZE);
set_bearer_id(ue_num);
to_sgw.pkt.clear_data();
to_sgw.pkt.fill_data(0, sizeof(int), type);
to_sgw.pkt.fill_data(sizeof(int), sizeof(int), ue_num);
to_sgw.pkt.fill_data(2 * sizeof(int), sizeof(int), g_bearer_table[ue_num]);
to_sgw.pkt.fill_data(3 * sizeof(int), sizeof(uint16_t), tun.mme_cteid);
to_sgw.pkt.make_data_packet();
to_sgw.write_data();
to_sgw.read_data();
to_sgw.pkt.rem_gtpu_hdr();
memcpy(&tun.sgw_cteid, to_sgw.pkt.data, sizeof(uint16_t));
memcpy(reply, to_sgw.pkt.data + sizeof(uint16_t), to_sgw.pkt.data_len - sizeof(uint16_t));
if(strcmp((const char*)reply, "OK") == 0){
cout<<"Create Session Request is successful for this client - "<<ue_num<<endl;
}
free(reply);
}

void modify_session(Client &to_sgw, int ue_num, Tunnel &tun){
char *reply;
reply = allocate_str_mem(BUFFER_SIZE);
to_sgw.pkt.clear_data();
to_sgw.pkt.fill_gtpc_hdr(tun.sgw_cteid);
to_sgw.pkt.fill_data(0, sizeof(uint16_t), tun.enodeb_uteid);
to_sgw.pkt.add_gtpu_hdr();
to_sgw.pkt.make_data_packet();
to_sgw.write_data();
to_sgw.read_data();
to_sgw.pkt.rem_gtpu_hdr();
memcpy(reply, to_sgw.pkt.data + sizeof(uint16_t) + INET_ADDRSTRLEN, to_sgw.pkt.data_len - sizeof(uint16_t) - INET_ADDRSTRLEN);
if(strcmp((const char*)reply, "OK") == 0){
cout<<"Modify Session Request is successful for this client - "<<ue_num<<endl;
}
free(reply);
}
void MME::set_cteid(){

void set_bearer_id(int ue_num){
g_bearer_table[ue_num] = generate_bearer_id(ue_num);
cteid = generate_cteid(ue_num);
}

int generate_bearer_id(int ue_num){
return ue_num;
}
uint16_t MME::generate_cteid(int &ue_number){

return ue_number;
}

int main(int argc, char *argv[]){
Server mme;
MME::~MME(){

usage(argc, argv);
mme.begin_thread_pool(atoi(argv[1]), multithreading_func);
mme.fill_server_details(g_mme_port, g_mme_addr);
mme.bind_server();
mme.listen_accept();
return 0;
}
free(ue_ip);
free(reply);
}
39 changes: 15 additions & 24 deletions mme.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,30 @@

#include "utils.h"
#include "packet.h"
#include "thread_pool.h"
#include "server.h"
#include "client.h"

unordered_map<int, int> g_bearer_table;

struct Gateways{
struct TunData{
uint16_t sgw_cteid;
int sgw_port;
int pgw_port;
char *sgw_addr;
char *pgw_addr;

Gateways();
void set_sgw();
void set_pgw();
~Gateways();
TunData();
~TunData();
};

struct Tunnel{
uint16_t mme_cteid;
uint16_t sgw_cteid;
uint16_t enodeb_uteid;
uint16_t sgw_uteid;

void set_mme_cteid(int);
struct MME{
uint16_t cteid;
int ue_num;
char *ue_ip;
char *reply;

MME();
void set_ue_num();
void set_cteid();
uint16_t generate_cteid(int&);
~MME();
};

void* multithreading_func(void*);
void authenticate(Server&, Client&);
void setup_tunnel(Server&, Client&, int);
void create_session(Client&, int, Tunnel&);
void modify_session(Client&, int, Tunnel&);
void set_bearer_id(int);
int generate_bearer_id(int);

#endif //MME_H
Loading

0 comments on commit da2d442

Please sign in to comment.