int main(int argc, char const *argv[]) { printf("----- Server running.. -----\n"); unlink_queue("/mta"); unlink_queue("/mailbox1"); unlink_queue("/mailbox2"); //We create a queue for MTA input mqd_t input = init_queue("/mta", O_CREAT | O_RDONLY); //and two more for writing to clients mqd_t client1 = init_queue("/mailbox1", O_CREAT | O_WRONLY); mqd_t client2 = init_queue("/mailbox2", O_CREAT | O_WRONLY); //loop msg message; while(1) { printf("Waiting for messages..\n"); message = read_queue(input); printf("Transmitting message \"%s\" from: %i to: %i\n", message.data, message.from, message.to); if(message.to == 1) { printf("Sending message to client1\n"); write_queue(client1, message); } if(message.to == 2){ printf("Sending message to client2\n"); write_queue(client2, message); } } return 0; }
/**@brief performs the task of writing to a queue from the Fins switch to the module * @param fins_out is the pointer to the fins frame being written to a switch-to-module queue */ void fins_switch_out(struct finsFrame *fins_out){ /**Pick the right queue to write the fins frame to. Semaphore lock and unlock is performed to * protect the integrity of the queue. Note that the fins frame is written to the right switch-to-module queue.*/ // print_finsFrame(fins_out); //print Fins frame if (fins_out->destinationID.id==ARPID){ sem_wait(&(swt_to_arp_bff->locked)); write_queue(fins_out, swt_to_arp_bff); sem_post(&(swt_to_arp_bff->locked)); } else if (fins_out->destinationID.id==TCPID){ sem_wait(&(swt_to_tcp_bff->locked)); write_queue(fins_out, swt_to_tcp_bff); sem_post(&(swt_to_tcp_bff->locked)); } else if (fins_out->destinationID.id==IPID){ sem_wait(&(swt_to_ip_bff->locked)); write_queue(fins_out, swt_to_ip_bff); sem_post(&(swt_to_ip_bff->locked)); } else if (fins_out->destinationID.id==ETHERSTUBID){ sem_wait(&(swt_to_wifi_bff->locked)); write_queue(fins_out, swt_to_wifi_bff); sem_post(&(swt_to_wifi_bff->locked)); } }
void signal_handler() { int ret; write_queue( my.showcodes ); exit( ret ); }
void module_to_switch_macro(const char *file, const char *func, int line, struct fins_module *module, struct finsFrame *ff) { PRINT_DEBUG("Entered: module=%p, id=%d, name='%s', ff=%p, meta=%p", module, module->id, module->name, ff, ff->metaData); int ret; while ((ret = sem_wait(module->output_sem)) && errno == EINTR) ; if (ret != 0) { #ifdef ERROR #ifdef BUILD_FOR_ANDROID __android_log_print(ANDROID_LOG_ERROR, "FINS", "ERROR(%s, %s, %d):output_sem wait prob: module=%p, id=%d, name='%s', ff=%p, meta=%p, ret=%d\n", file, func, line, module, module->id, module->name, ff, ff->metaData, ret); #else //printf("\033[01;31mERROR(%s, %s, %d):output_sem wait prob: module=%p, id=%d, name='%s', ff=%p, meta=%p, ret=%d\n\033[01;37m", file, func, line, module, module->id, module->name, ff, ff->metaData, ret); fflush(stdout); gettimeofday(&global_print_tv, NULL); printf("\033[01;31m%u.%06u:ERROR(%s, %s, %d):output_sem wait prob: module=%p, id=%d, name='%s', ff=%p, meta=%p, ret=%d\n\033[01;37m", (uint32_t) global_print_tv.tv_sec, (uint32_t) global_print_tv.tv_usec, file, func, line, module, module->id, module->name, ff, ff->metaData, ret); fflush(stdout); #endif #endif exit(-1); } #ifdef DEBUG ret = ff->destinationID; #endif //PRINT_INFO("after: module=%p, id=%d, name='%s', ff=%p, meta=%p", module, module->id, module->name, ff, ff->metaData); if (write_queue(ff, module->output_queue)) { PRINT_DEBUG("Exited: module=%p, id=%d, name='%s', dst=%u, 1", module, module->id, module->name, ret); sem_post(global_switch_event_sem); //post here with race condition sem_post(module->output_sem); //sem_post(global_switch_event_sem); //post here with sem val check } else { sem_post(module->output_sem); #ifdef ERROR #ifdef BUILD_FOR_ANDROID __android_log_print(ANDROID_LOG_ERROR, "FINS", "ERROR(%s, %s, %d):write_queue fail: module=%p, id=%d, name='%s', ff=%p, 0\n", file, func, line, module, module->id, module->name, ff); #else //printf("\033[01;31mERROR(%s, %s, %d):write_queue fail: module=%p, id=%d, name='%s', ff=%p, 0\n\033[01;37m", file, func, line, module, module->id, module->name, ff); fflush(stdout); gettimeofday(&global_print_tv, NULL); printf("\033[01;31m%u.%06u:ERROR(%s, %s, %d):write_queue fail: module=%p, id=%d, name='%s', ff=%p, 0\n\033[01;37m", (uint32_t) global_print_tv.tv_sec, (uint32_t) global_print_tv.tv_usec, file, func, line, module, module->id, module->name, ff); fflush(stdout); #endif #endif exit(-1); } }
/** * scout main */ int main( int argc, char *argv[] ) { int x, result; /* index, func. result*/ struct sigaction action; CLIENT *client; /* defined in setup.h */ init_config(); /* defined in init.h */ parse_cmdline(argc, argv); /* defined above */ if( my.config ){ /* see: init.h */ show_config( TRUE ); } memset( &action, 0, sizeof( action )); action.sa_handler = signal_handler; if( sigaction( SIGHUP, &action, NULL )) joe_error( "sigaction" ); if( sigaction( SIGINT, &action, NULL)) joe_error( "sigaction" ); if( sigaction( SIGTERM, &action, NULL)) joe_error( "sigaction" ); /* cookie is an EXTERN, defined in setup */ cookie = (COOKIE*)malloc( sizeof(COOKIE)); if( !cookie ){ joe_fatal( "memory exhausted" ); } cookie->first = NULL; client = (CLIENT*)malloc(sizeof(CLIENT)); if( !client ){ joe_fatal( "application memory exhausted" ); } http_client( client ); write_queue( my.showcodes ); /** * exit program. */ exit( EXIT_SUCCESS ); } /* end of int main **/
int jinni_UDP_to_fins(u_char *dataLocal,int len,uint16_t dstport,uint32_t dst_IP_netformat, uint16_t hostport,uint32_t host_IP_netformat) { struct finsFrame *ff= (struct finsFrame *) malloc(sizeof (struct finsFrame)); metadata *udpout_meta = (metadata *)malloc(sizeof(metadata)); PRINT_DEBUG(); metadata_create(udpout_meta); if ( udpout_meta == NULL ) { PRINT_DEBUG("metadata creation failed"); free(ff); exit(1); } /** metadata_writeToElement() set the value of an element if it already exist * or it creates the element and set its value in case it is new */ PRINT_DEBUG("%d, %d, %d, %d", dstport,dst_IP_netformat,hostport, host_IP_netformat); uint32_t dstprt= dstport; uint32_t hostprt = hostport; metadata_writeToElement(udpout_meta,"dstport",&dstport,META_TYPE_INT); metadata_writeToElement(udpout_meta,"srcport",&hostport,META_TYPE_INT); metadata_writeToElement(udpout_meta,"dstip",&dst_IP_netformat,META_TYPE_INT); metadata_writeToElement(udpout_meta,"srcip",&host_IP_netformat,META_TYPE_INT); ff->dataOrCtrl = DATA; /**TODO get the address automatically by searching the local copy of the * switch table */ ff->destinationID.id = UDPID; ff->destinationID.next = NULL; (ff->dataFrame).directionFlag = DOWN; (ff->dataFrame).pduLength = len; (ff->dataFrame).pdu = dataLocal; (ff->dataFrame).metaData = udpout_meta ; /**TODO insert the frame into jinni_to_switch queue * check if insertion succeeded or not then * return 1 on success, or -1 on failure * */ PRINT_DEBUG(""); sem_wait(&Jinni_to_Switch_Qsem); if (write_queue(ff,Jinni_to_Switch_Queue)) { sem_post(&Jinni_to_Switch_Qsem); PRINT_DEBUG(""); return(1); } sem_post(&Jinni_to_Switch_Qsem); PRINT_DEBUG(""); return(0); }
int main(int argc, char **argv) { mqd_t actor4 = init_queue("/actor4", O_CREAT | O_RDONLY); message msgreceived; //printf("Waiting to receive something\n"); msgreceived = read_queue(actor4); //printf("I got something\n"); char order[34]; int me = 0; char content[256]; //int next; char nextq[7]; strcpy(order, msgreceived.order); strcpy(content, msgreceived.content); int i; for(i = 0; i<33; i++){ // printf("%c order\n", order[i]); if (order[i]=='4'){ if (i <=7){ //I am the first actor me = 1; //next = atoi(order[i+9]); strncpy(nextq, &order[i]+4, 7); nextq[6] = '\0'; }else if(i<=17){ //I am the second actor me = 2; strncpy(nextq, &order[i]+4, 7); nextq[6] = '\0'; }else if(i <= 26){ //I am the third actor me = 3; strncpy(nextq, &order[i]+4, 7); nextq[6] = '\0'; }else if (i <=34){ //I am the fourth actor me = 4; } } } //write message message msg; char text[256]; strcpy(text, msgreceived.content); printf("%s text\n", text); //text = strcat("TEXT " + var); strcpy(msg.order, order); if (me != 4){ if (me==1){ strcpy (msg.content, "[EscribiendoActor4-"); }else{ strcat(text,"EscribiendoActor4-"); strcpy(msg.content, text); } }else{ strcat(text, "EscribiendoActor4]"); strcpy(msg.content, text); } //We know the name of the following queue we have to send to char nextqueue[7]; sprintf(nextqueue, "/%s", nextq); mqd_t next; if (me!=4){ next = init_queue(nextqueue, O_WRONLY); }else{ printf("I'm opening to director\n"); next = init_queue("/director", O_WRONLY); } write_queue(next, msg); printf("I sent\n"); return 0; }
//RTM's main function //Gets information from RTM_IN pipe //Is started as a thread in core.c void rtm_init(pthread_attr_t *fins_pthread_attr) { PRINT_IMPORTANT("RTM has started"); /* //added to include code from fins_daemon.sh -- mrd015 !!!!! //TODO move this to RTM module if (mkfifo(RTM_PIPE_IN, 0777) != 0) { if (errno == EEXIST) { PRINT_DEBUG("mkfifo(" RTM_PIPE_IN ", 0777) already exists."); } else { PRINT_ERROR("mkfifo(" RTM_PIPE_IN ", 0777) failed."); exit(-1); } } if (mkfifo(RTM_PIPE_OUT, 0777) != 0) { if (errno == EEXIST) { PRINT_DEBUG("mkfifo(" RTM_PIPE_OUT ", 0777) already exists."); } else { PRINT_ERROR("mkfifo(" RTM_PIPE_OUT ", 0777) failed."); exit(-1); } } */ //int datalen; int numBytes; //int val_len; int temp_serial_cntr = 0; unsigned char* serialized_FCF = NULL; int length_serialized_FCF; //create a finsframe to be sent tover the queue struct finsFrame *fins_frame = (struct finsFrame *) secure_malloc(sizeof(struct finsFrame)); fins_frame->dataOrCtrl = CONTROL; //opens the pipe from clicomm (or wherever) rtm_in_fd = open(RTM_PIPE_IN, O_RDWR); if (rtm_in_fd == -1) { PRINT_DEBUG("rtm_in_fd Pipe failure "); exit(EXIT_FAILURE); } fflush(stdout); while (1) { temp_serial_cntr++; //used as a temporary serial_number generator //READ FROM PIPE RTM_IN numBytes = 0; numBytes += read(rtm_in_fd, &length_serialized_FCF, sizeof(int)); //length of incoming serialized FCF numBytes += read(rtm_in_fd, serialized_FCF, length_serialized_FCF); //incoming serialized FCF fins_frame = unserializeCtrlFrame(serialized_FCF, length_serialized_FCF); //value, Assumption was made, notice the size PRINT_DEBUG("received data"); numBytes = 0; //ERROR Message fflush(stdout); if (numBytes >= 0) { PRINT_DEBUG("numBytes written %d", numBytes); } //CHANGE SenderID and SerialNum fins_frame->ctrlFrame.senderID = RTM_ID; fins_frame->ctrlFrame.serial_num = temp_serial_cntr; //SEND TO QUEUE secure_sem_wait(&RTM_to_Switch_Qsem); write_queue(fins_frame, RTM_to_Switch_Queue); sem_post(&RTM_to_Switch_Qsem); PRINT_DEBUG("sent data "); //READ FROM QUEUE rtm_get_ff(); } }
static WriterResult ParallelWriterClose(ParallelWriter *self, bool onError) { WriterResult ret = { 0 }; if (!self->base.rel) self->writer->close(self->writer, onError); /* wait for reader */ if (self->conn) { if (self->queue && !onError) { PGresult *res; int sock; fd_set input_mask; /* terminate with zero */ write_queue(self, NULL, 0); do { sock = PQsocket(self->conn); FD_ZERO(&input_mask); FD_SET(sock, &input_mask); while (select(sock + 1, &input_mask, NULL, NULL, NULL) < 0) { if (errno == EINTR) { CHECK_FOR_INTERRUPTS(); continue; } ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("select() failed"), errdetail("%s", finish_and_get_message(self)))); } PQconsumeInput(self->conn); } while (PQisBusy(self->conn)); res = PQgetResult(self->conn); if (PQresultStatus(res) != PGRES_TUPLES_OK) { PQfinish(self->conn); self->conn = NULL; transfer_message(NULL, res); } else { self->base.count = ParseInt64(PQgetvalue(res, 0, 1), 0); ret.num_dup_new = ParseInt64(PQgetvalue(res, 0, 3), 0); ret.num_dup_old = ParseInt64(PQgetvalue(res, 0, 4), 0); PQclear(res); /* commit transaction */ res = PQexec(self->conn, "COMMIT"); if (PQresultStatus(res) != PGRES_COMMAND_OK) { ereport(ERROR, (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), errmsg("could not commit transaction"), errdetail("%s", finish_and_get_message(self)))); } } PQclear(res); } else if (PQisBusy(self->conn)) { char errbuf[256]; PGcancel *cancel = PQgetCancel(self->conn); if (cancel) PQcancel(cancel, errbuf, lengthof(errbuf)); } if (self->conn) PQfinish(self->conn); self->conn = NULL; } /* * Close self after wait for reader because reader hasn't opened the self * yet. If we close self too early, the reader cannot open the self. */ if (self->queue) QueueClose(self->queue); self->queue = NULL; if (!onError) { MemoryContextDelete(self->base.context); if (self->base.rel) heap_close(self->base.rel, NoLock); } return ret; }
static void ParallelWriterInsert(ParallelWriter *self, HeapTuple tuple) { write_queue(self, tuple->t_data, tuple->t_len); }
void *switch_loop(void *local) { struct fins_module *module = (struct fins_module *) local; PRINT_DEBUG("Entered: module=%p, index=%u, id=%u, name='%s'", module, module->index, module->id, module->name); struct switch_data *md = (struct switch_data *) module->data; uint32_t i; int ret; //int32_t val; struct finsFrame *ff; //uint8_t index; int counter = 0; while (module->state == FMS_RUNNING) { secure_sem_wait(module->event_sem); //TODO uncomment, for testing //secure_sem_wait(module->input_sem); secure_sem_wait(&md->overall->sem); for (i = 0; i < MAX_MODULES; i++) { if (md->overall->modules[i] != NULL) { //helgrind says is race condition, though there will always be FF when post to event_sem if (!IsEmpty(md->overall->modules[i]->output_queue)) { //added as optimization /* //can possibly cause switch to be "behind" ret = sem_getvalue(md->overall->modules[i]->output_sem, &val); if (ret) { PRINT_ERROR("sem get value prob: src module_index=%u, ret=%d", i, ret); exit(-1); } //*/ //if (val != 0) { while ((ret = sem_wait(md->overall->modules[i]->output_sem)) && errno == EINTR) ; if (ret != 0) { PRINT_ERROR("sem wait prob: src module_index=%u, ret=%d", i, ret); exit(-1); } ff = read_queue(md->overall->modules[i]->output_queue); sem_post(md->overall->modules[i]->output_sem); //if (ff != NULL) { //shouldn't occur counter++; //index = ff->destinationID; if (ff->destinationID < 0 || ff->destinationID > MAX_MODULES) { PRINT_ERROR("dropping ff: illegal destination: src module_index=%u, dst module_index=%u, ff=%p, meta=%p", i, ff->destinationID, ff, ff->metaData); //TODO if FCF set ret_val=0 & return? or free or just exit(-1)? freeFinsFrame(ff); } else { //if (i != id) //TODO add this? if (md->overall->modules[ff->destinationID] != NULL) { PRINT_DEBUG("Counter=%d, from='%s', to='%s', ff=%p, meta=%p", counter, md->overall->modules[i]->name, md->overall->modules[ff->destinationID]->name, ff, ff->metaData); //TODO decide if should drop all traffic to switch input queues, or use that as linking table requests if (ff->destinationID == module->index) { switch_process_ff(module, ff); } else { while ((ret = sem_wait(md->overall->modules[ff->destinationID]->input_sem)) && errno == EINTR) ; if (ret != 0) { PRINT_ERROR("sem wait prob: dst index=%u, ff=%p, meta=%p, ret=%d", ff->destinationID, ff, ff->metaData, ret); exit(-1); } if (write_queue(ff, md->overall->modules[ff->destinationID]->input_queue)) { sem_post(md->overall->modules[ff->destinationID]->event_sem); sem_post(md->overall->modules[ff->destinationID]->input_sem); } else { sem_post(md->overall->modules[ff->destinationID]->input_sem); PRINT_ERROR("Write queue error: dst index=%u, ff=%p, meta=%p", ff->destinationID, ff, ff->metaData); freeFinsFrame(ff); } } } else { PRINT_ERROR("dropping ff: destination not registered: src index=%u, dst index=%u, ff=%p, meta=%p", i, ff->destinationID, ff, ff->metaData); print_finsFrame(ff); //TODO if FCF set ret_val=0 & return? or free or just exit(-1)? freeFinsFrame(ff); } //} //} } } } } //sem_post(module->input_sem); sem_post(&md->overall->sem); } PRINT_DEBUG("Exited: module=%p, index=%u, id=%u, name='%s'", module, module->index, module->id, module->name); return NULL; }
void *switch_loop(void *local) { PRINT_DEBUG("Entered"); int i; struct finsFrame *ff; int counter = 0; while (switch_running) { /** the receiving Queues are only the even numbers * 0,2,4,6,8,10,12,14. This is why we increase the counter by 2 */ for (i = 0; i < MAX_modules; i = i + 2) { sem_wait(IO_queues_sem[i]); ff = read_queue(modules_IO_queues[i]); sem_post(IO_queues_sem[i]); if (ff != NULL) { counter++; //PRINT_DEBUG("Counter %d", counter); switch (ff->destinationID.id) { case ARP_ID: PRINT_DEBUG("Counter=%d, from='%s' to ARP Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_ARP_Qsem); write_queue(ff, Switch_to_ARP_Queue); sem_post(&Switch_to_ARP_Qsem); break; case RTM_ID: PRINT_DEBUG("Counter=%d, from='%s' to RTM Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_RTM_Qsem); write_queue(ff, Switch_to_RTM_Queue); sem_post(&Switch_to_RTM_Qsem); break; case DAEMON_ID: PRINT_DEBUG("Counter=%d, from='%s' to Daemon Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_Daemon_Qsem); write_queue(ff, Switch_to_Daemon_Queue); sem_post(&Switch_to_Daemon_Qsem); break; case UDP_ID: PRINT_DEBUG("Counter=%d, from='%s' to UDP Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_UDP_Qsem); write_queue(ff, Switch_to_UDP_Queue); sem_post(&Switch_to_UDP_Qsem); break; case TCP_ID: PRINT_DEBUG("Counter=%d, from='%s' to TCP Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_TCP_Qsem); write_queue(ff, Switch_to_TCP_Queue); sem_post(&Switch_to_TCP_Qsem); break; case IPV4_ID: PRINT_DEBUG("Counter=%d, from='%s' to IPv4 Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_IPv4_Qsem); write_queue(ff, Switch_to_IPv4_Queue); sem_post(&Switch_to_IPv4_Qsem); break; case INTERFACE_ID: PRINT_DEBUG("Counter=%d, from='%s' to Interface Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_Interface_Qsem); write_queue(ff, Switch_to_Interface_Queue); sem_post(&Switch_to_Interface_Qsem); break; case ICMP_ID: PRINT_DEBUG("Counter=%d, from='%s' to ICMP Queue +1, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); sem_wait(&Switch_to_ICMP_Qsem); write_queue(ff, Switch_to_ICMP_Queue); sem_post(&Switch_to_ICMP_Qsem); break; default: PRINT_DEBUG("Counter=%d, from='%s' to Unknown Dest, ff=%p, meta=%p", counter, modules_IO_queues[i]->name, ff, ff->metaData); freeFinsFrame(ff); break; } // end of Switch statement } // end of if (ff != NULL ) else { //PRINT_DEBUG("No frame read from Queue # %d", i); } } //end of for For loop (Round Robin reading from Modules) } // end of while loop PRINT_DEBUG("Exited"); pthread_exit(NULL); } // end of switch_init Function
void init_switch() { PRINT_DEBUG("SWITCH Module started"); int i; struct finsFrame *ff = NULL; int protocol; int index; int status; uint16_t dstport, hostport; uint32_t dstip, hostip; int counter = 0; while (1) { /** the receiving Queues are only the even numbers * 0,2,4,6,8,10,12,14. This is why we increase the counter by 2 */ for (i = 0; i < MAX_modules; i = i + 2) { sem_wait(IO_queues_sem[i]); ff = read_queue(modules_IO_queues[i]); sem_post(IO_queues_sem[i]); if (ff != NULL) { counter++; PRINT_DEBUG("Counter %d", counter); switch (ff->destinationID.id) { case ARPID: { PRINT_DEBUG("ARP Queue +1"); sem_wait(&Switch_to_ARP_Qsem); write_queue(ff, Switch_to_ARP_Queue); sem_post(&Switch_to_ARP_Qsem); break; } case RTMID: { PRINT_DEBUG("RTM Queue +1"); sem_wait(&Switch_to_RTM_Qsem); write_queue(ff, Switch_to_RTM_Queue); sem_post(&Switch_to_RTM_Qsem); break; } case JINNIID: { PRINT_DEBUG("Jinni Queue +1"); sem_wait(&Switch_to_Jinni_Qsem); write_queue(ff, Switch_to_Jinni_Queue); sem_post(&Switch_to_Jinni_Qsem); break; } case UDPID: { PRINT_DEBUG("UDP Queue +1"); sem_wait(&Switch_to_UDP_Qsem); write_queue(ff, Switch_to_UDP_Queue); sem_post(&Switch_to_UDP_Qsem); break; } case TCPID: { PRINT_DEBUG("TCP Queue +1"); sem_wait(&Switch_to_TCP_Qsem); write_queue(ff, Switch_to_TCP_Queue); sem_post(&Switch_to_TCP_Qsem); break; } case IPV4ID: { PRINT_DEBUG("IP Queue +1"); sem_wait(&Switch_to_IPv4_Qsem); write_queue(ff, Switch_to_IPv4_Queue); sem_post(&Switch_to_IPv4_Qsem); break; } case ETHERSTUBID: { PRINT_DEBUG("EtherStub Queue +1"); sem_wait(&Switch_to_EtherStub_Qsem); write_queue(ff, Switch_to_EtherStub_Queue); sem_post(&Switch_to_EtherStub_Qsem); break; } case ICMPID: { PRINT_DEBUG("ICMP Queue +1"); sem_wait(&Switch_to_ICMP_Qsem); write_queue(ff, Switch_to_ICMP_Queue); sem_post(&Switch_to_ICMP_Qsem); break; } default: { PRINT_DEBUG("Unknown Destination"); // free(ff); break; } } // end of Switch statement } // end of if (ff != NULL ) else { //PRINT_DEBUG("No frame read from Queue # %d", i); } } //end of for For loop (Round Robin reading from Modules) } // end of while loop } // end of switch_init Function