Skip to content

Commit

Permalink
Reuse NF Instance IDs (#92)
Browse files Browse the repository at this point in the history
Reuse instance IDs of old NFs that have terminated. Reusing will only
happen when the next instance id counter hits the set MAX_NFS limit.
Allows to infinitely run NFs and makes MAX_NFS a value of concurrent
running NFs instead.

Commit log:

* Reuse NF instance IDs

* Minor cleanup
  • Loading branch information
koolzz authored Apr 27, 2019
1 parent 4dd40a9 commit c2eb910
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
4 changes: 1 addition & 3 deletions onvm/onvm_mgr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,9 @@ main(int argc, char *argv[]) {
unsigned i;

/* initialise the system */

/* Reserve ID 0 for internal manager things */
next_instance_id = 1;
if (init(argc, argv) < 0)
return -1;

RTE_LOG(INFO, APP, "Finished Process Init.\n");

/* clear statistics */
Expand Down
5 changes: 0 additions & 5 deletions onvm/onvm_mgr/onvm_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,4 @@
#define TO_PORT 0
#define TO_NF 1

/***************************Shared global variables***************************/

/* ID to be assigned to the next NF that starts */
extern uint16_t next_instance_id;

#endif // _ONVM_MGR_H_
29 changes: 25 additions & 4 deletions onvm/onvm_mgr/onvm_nf.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
#include "onvm_mgr.h"
#include "onvm_stats.h"

uint16_t next_instance_id = 0;
/* ID 0 is reserved */
uint16_t next_instance_id = 1;
uint16_t starting_instance_id = 1;

/************************Internal functions prototypes************************/

Expand Down Expand Up @@ -89,16 +91,35 @@ onvm_nf_stop(struct onvm_nf_info *nf_info);
uint16_t
onvm_nf_next_instance_id(void) {
struct onvm_nf *nf;
uint16_t instance_id = MAX_NFS;
uint16_t instance_id;

if (num_nfs >= MAX_NFS)
return MAX_NFS;

/* Do a first pass for NF IDs bigger than current next_instance_id */
while (next_instance_id < MAX_NFS) {
instance_id = next_instance_id++;
/* Check if this id is occupied by another NF */
nf = &nfs[instance_id];
if (!onvm_nf_is_valid(nf))
break;
return instance_id;
}

/* Reset to starting position */
next_instance_id = starting_instance_id;

/* Do a second pass for other NF IDs */
while (next_instance_id < MAX_NFS) {
instance_id = next_instance_id++;
/* Check if this id is occupied by another NF */
nf = &nfs[instance_id];
if (!onvm_nf_is_valid(nf))
return instance_id;
}

return instance_id;
/* This should never happen, means our num_nfs counter is wrong */
RTE_LOG(ERR, APP, "Tried to allocated a next instance ID but num_nfs is corrupted\n");
return MAX_NFS;
}

void
Expand Down
2 changes: 0 additions & 2 deletions onvm/onvm_mgr/onvm_nf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@

#include "onvm_threading.h"

extern uint16_t next_instance_id;

/********************************Interfaces***********************************/

/*
Expand Down
2 changes: 1 addition & 1 deletion onvm/onvm_nflib/onvm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "onvm_msg_common.h"

#define ONVM_MAX_CHAIN_LENGTH 4 // the maximum chain length
#define MAX_NFS 128 // total number of NFs allowed
#define MAX_NFS 128 // total number of concurrent NFs allowed (-1 because ID 0 is reserved)
#define MAX_SERVICES 32 // total number of unique services allowed
#define MAX_NFS_PER_SERVICE 32 // max number of NFs per service.

Expand Down

0 comments on commit c2eb910

Please sign in to comment.