X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Ftest_si95_em.c;h=44c4e0f6da74e7efab0abc82d94cef71b382f05f;hb=8c6756d9d6f94beca0bc382f97383ca5e79d16c7;hp=c2cf4cb45bcf920417bc737e8019135b411cc6dd;hpb=c113b0836f3ebd58911c30de1636a707174efe55;p=ric-plt%2Flib%2Frmr.git diff --git a/test/test_si95_em.c b/test/test_si95_em.c index c2cf4cb..44c4e0f 100644 --- a/test/test_si95_em.c +++ b/test/test_si95_em.c @@ -32,7 +32,7 @@ #include "rmr.h" // we use some of rmr defs in building dummy messages, so we need these #include "rmr_agnostic.h" -// ---------------------- emulated nng functions --------------------------- +// ---------------------- emulated SI95 functions --------------------------- #ifndef _em_si // this is the same define as the nng emulation code uses to give warning if both included @@ -43,6 +43,37 @@ #include "test_common_em.c" // common emulation needed for all (epoll, gethostname...) +// --- some globals -------------------------------------------------------- +int em_reset_call_flag = 0; // allows a send to turn off the call flag (see em_disable_call_flg()) + +// ------------- emulated message header ----------------------------------- + +/* + This is a copy from agnostic.h. we need to reset flags in some situations + so we have to have this, under a different name to avoid disaster. +*/ +typedef struct { + int32_t mtype; // message type ("long" network integer) + int32_t plen; // payload length (sender data length in payload) + int32_t rmr_ver; // our internal message version number + unsigned char xid[RMR_MAX_XID]; // space for user transaction id or somesuch + unsigned char sid[RMR_MAX_SID]; // sender ID for return to sender needs + unsigned char src[RMR_MAX_SRC]; // name:port of the sender (source) + unsigned char meid[RMR_MAX_MEID]; // managed element id. + struct timespec ts; // timestamp ??? + + // V2 extension + int32_t flags; // HFL_* constants + int32_t len0; // length of the RMr header data + int32_t len1; // length of the tracing data + int32_t len2; // length of data 1 (d1) + int32_t len3; // length of data 2 (d2) + int32_t sub_id; // subscription id (-1 invalid) + + // v3 extension + unsigned char srcip[RMR_MAX_SRC]; // ip address and port of the source +} em_mhdr_t; + //-------------------------------------------------------------------------- /* These are the current references in the RMR code; all others are internal @@ -113,18 +144,29 @@ static int em_siclose( struct ginfo_blk *gptr, int fd ) { /* If em_send_failures is true, this will fail a small part of the time to simualte connection failures. + + If the port number is < 1000 it will fail -- allowing for specific,single + failure cases. */ static int em_next_fd = 0; static int em_siconnect( struct ginfo_blk *gptr, char *abuf ) { static int count = 0; + char* tok; if( em_send_failures && (count++ % 15 == 14) ) { //fprintf( stderr, " siem is failing connect attempt\n\n" ); return -1; } - fprintf( stderr, " siem is emulating connect attempt return fd=%d\n", em_next_fd ); - em_next_fd++; + if( (tok = strchr( abuf, ':' )) != NULL && atoi( tok+1 ) < 1000 ) { + fprintf( stderr, " siem is emulating connect to (%s) with a failure; port <1000\n", abuf ); + return -1; + } + + fprintf( stderr, " siem is emulating connect to (%s) attempt return fd=%d\n", abuf, em_next_fd ); + if( em_next_fd < 50 ) { + em_next_fd++; + } return em_next_fd-1; } @@ -140,7 +182,7 @@ static int em_sigetaddr( struct ginfo_blk *gptr, char *buf ) { return 0; } -static struct tp_blk *em_silisten_prep( struct ginfo_blk *gptr, int type, char* abuf, int family ) { +static struct tp_blk *em_silisten_prep( int type, char* abuf, int family ) { return NULL; } @@ -171,8 +213,28 @@ static void em_sisend( struct ginfo_blk *gptr, struct tp_blk *tpptr ) { return; } +/* + Calling this function causes the send emulation to turn off the call + flag in the RMR header. Turning that flag off makes the arriving message + look as though it might be a response to a call rather than a call itself. + This is needed since we loop back messages. +*/ +static void em_disable_call_flg() { + em_reset_call_flag = 1; + fprintf( stderr, " reset call flag setting is: %d\n", em_reset_call_flag ); +} + +/* + Opposite of disable_call_flg; the flag is not touched. +*/ +static void em_allow_call_flg() { + em_reset_call_flag = 0; + fprintf( stderr, " reset call flag setting is: %d\n", em_reset_call_flag ); +} + // callback prototype to drive to simulate 'receive' static int mt_data_cb( void* datap, int fd, char* buf, int buflen ); + /* Emulate sending a message. If the global em_send_failures is set, then every so often we fail with an EAGAIN to drive that part @@ -191,6 +253,13 @@ static int em_sisendt( struct ginfo_blk *gptr, int fd, char *ubuf, int ulen ) { return SIEM_BLOCKED; } + if( em_reset_call_flag ) { // for call testing we need to flip the flag off to see it "return" + em_mhdr_t* hdr; + + hdr = (em_mhdr_t *) (ubuf+50); // past the transport header bytes + hdr->flags &= ~HFL_CALL_MSG; // flip off the call flag + } + uss++; if( em_cb_data != NULL ) {