Skip to content

Commit

Permalink
Keepalive towards Control Plane and restart after 100 sec no activity.
Browse files Browse the repository at this point in the history
thakurajayL committed Jul 9, 2020
1 parent e471cef commit 297fe99
Showing 4 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.pyc
*.swp
bin
cscope.out
tags
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ docker-build:
DOCKER_BUILDKIT=$(DOCKER_BUILDKIT) docker build --pull $(DOCKER_BUILD_ARGS) \
--target $$target \
--tag ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}upf-epc-$$target:${DOCKER_TAG} \
--cache-from ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}upf-epc-$$target:${DOCKER_TAG} \
--build-arg org_label_schema_version="${VERSION}" \
--build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
--build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
11 changes: 9 additions & 2 deletions core/utils/gtp_common.h
Original file line number Diff line number Diff line change
@@ -39,13 +39,20 @@
*/
#define MAX_SERVICE 1

enum { MSG_SESS_CRE = 2, MSG_SESS_MOD, MSG_SESS_DEL };
enum {
MSG_SESS_CRE = 2,
MSG_SESS_MOD,
MSG_SESS_DEL,
MSG_KEEPALIVE = 100,
MSG_KEEPALIVE_ACK = 101
};

enum {
DPN_RESPONSE = 4,
DPN_CREATE_RESP = 10,
DPN_MODIFY_RESP,
DPN_DELETE_RESP
DPN_DELETE_RESP,
DPN_KEEPALIVE_REQ = 100
};

/**
55 changes: 48 additions & 7 deletions cpiface/zmq-cpiface.cc
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@
#include <sys/types.h>
#include <unistd.h>
#include <zmq.h>
#include <sys/time.h>
#include <assert.h>
/*--------------------------------------------------------------------------------*/
#define ZMQ_SERVER_IP "172.17.0.2"
#define ZMQ_RECV_PORT 20
@@ -197,6 +199,7 @@ int main(int argc, char **argv) {
std::cerr << "Unable to retreive hostname of DP!" << std::endl;
return EXIT_FAILURE;
}
VLOG(1) << "DP hostname - " << args.rmb.hostname<<std::endl;
// send registration request
if (zmq_send(reg, (void *)&args.rmb, sizeof(args.rmb), 0) == -1) {
std::cerr << "Failed to send registration request to CP!" << std::endl;
@@ -249,16 +252,32 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}

uint32_t my_dp_id = 0;

struct timeval last_ack, current_time;
gettimeofday(&last_ack, NULL);
uint32_t dp_cp_timeout_interval = 100;

struct resp_msgbuf keepalive;
keepalive.mtype = DPN_KEEPALIVE_REQ;
keepalive.op_id = 1; // for now always 1...
keepalive.sess_id = 0; // node specific message
keepalive.dp_id.id = my_dp_id; // DP is not aware about its id...
strcpy(keepalive.dp_id.name, args.rmb.hostname);

// Process messages from either socket
while (true) {
static const zmq_pollitem_t items[] = {
{receiver, 0, ZMQ_POLLIN, 0},
};
if (zmq_poll((zmq_pollitem_t *)items, 1, -1) < 0) {
uint32_t timeout = 1000; // 1 seond
if (zmq_poll((zmq_pollitem_t *)items, 1, timeout) < 0) {
std::cerr << "ZMQ poll failed!: " << strerror(errno) << std::endl;
return EXIT_FAILURE;
}
if (items[0].revents & ZMQ_POLLIN) {
gettimeofday(&last_ack, NULL); // as long as we get packets from control path we are good
bool send_resp = true;
struct msgbuf rbuf;
struct resp_msgbuf resp;
int size = zmq_recv(receiver, &rbuf, sizeof(rbuf), 0);
@@ -279,6 +298,7 @@ int main(int argc, char **argv) {
<< ntohl(rbuf.sess_entry.dl_s1_info.enb_teid) << ")"
<< std::endl;
resp.op_id = rbuf.sess_entry.op_id;
my_dp_id = rbuf.dp_id.id;
resp.dp_id.id = rbuf.dp_id.id;
resp.mtype = DPN_RESPONSE;
zmq_sess_map[SESS_ID(rbuf.sess_entry.ue_addr.u.ipv4_addr,
@@ -350,17 +370,38 @@ int main(int argc, char **argv) {
zmq_sess_map.erase(it);
}
break;
case MSG_KEEPALIVE_ACK:
my_dp_id = rbuf.dp_id.id;
send_resp = false;
VLOG(1) << "Got a keepalive ack from CP, "<<my_dp_id;
break;
default:
send_resp = false;
VLOG(1) << "Got a request with mtype: " << mtype << std::endl;
break;
}
size = zmq_send(sender, &resp, sizeof(resp), ZMQ_NOBLOCK);
if (size == -1) {
std::cerr << "Error in zmq sending: " << strerror(errno) << std::endl;
break;
} else {
VLOG(1) << "Sending back response block" << std::endl;
if(send_resp == true) {
size = zmq_send(sender, &resp, sizeof(resp), ZMQ_NOBLOCK);
if (size == -1) {
std::cerr << "Error in zmq sending: " << strerror(errno) << std::endl;
break;
} else {
VLOG(1) << "Sending back response block" << std::endl;
}
}
} else {
VLOG(1) << "ZMQ poll timeout DPID " << my_dp_id<<std::endl;
gettimeofday(&current_time, NULL);
if(current_time.tv_sec - last_ack.tv_sec > dp_cp_timeout_interval) {
std::cerr << "CP<-->DP communication broken. DPID - " << my_dp_id<<std::endl;
assert(0);
}
keepalive.dp_id.id = my_dp_id;
int size = zmq_send(sender, &keepalive, sizeof(keepalive), ZMQ_NOBLOCK);
if (size == -1) {
std::cerr << "Error in zmq sending: " << strerror(errno) << std::endl;
break;
}
}
}

0 comments on commit 297fe99

Please sign in to comment.