int WfaConRcvVOSndAllE(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_DEFAULT,tos_vo)) { printf("\r\nexpected message not rcv or BAD TOS\n"); } else { rmsg[0] = ++(sta->msgno); set_dscp(tos_vo); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", rmsg, 64); printf("Rcv VO sent VO\n"); rmsg[0] = ++(sta->msgno); set_dscp(tos_vi); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", rmsg, 64); printf("sent VI\n"); rmsg[0] = ++(sta->msgno); set_dscp(tos_be); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", rmsg, 64); printf("sent BE\n"); rmsg[0] = ++(sta->msgno); set_dscp(tos_bk); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if(r < 0) { printf("\nhere u go:dead\n"); } if (traceflag) mpx("CMD send(BK)\n", rmsg, 64); { printf("sent BK\n"); } txmsg[0] = ++(sta->msgno); set_dscp(tos_bk); create_apts_msg(APTS_STOP, txmsg,sta->myid); txmsg[1] = tos_bk; r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send STOP(RcvVOSndAllE)\n", txmsg, 64); sta->state++; } }
/* * WfaStaWaitStop(): This function sends the stop packet on behalf of the * station, the idea is to keep sending the Stop * till a stop is recd from the console,the functions * quits after stop threshold reaches. */ int WfaStaWaitStop(char psave,int sleep_period,int *state) { int myid=wmmps_info.ps_thread; PRINTF("\n Entering Sendwait"); wUSLEEP(sleep_period); if(!num_stops) { wfaSetDUTPwrMgmt(psave); wfaTGSetPrio(psSockfd, TG_WMM_AC_BE); } num_stops++; create_apts_msg(APTS_STOP, psTxMsg,wmmps_info.my_sta_id); wSENDTO(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr)); mpx("STA msg",psTxMsg,64); wmm_thr[myid].stop_flag = 1; wPT_MUTEX_LOCK(&wmm_thr[myid].thr_stop_mutex); wPT_COND_SIGNAL(&wmm_thr[myid].thr_stop_cond); wPT_MUTEX_UNLOCK(&wmm_thr[myid].thr_stop_mutex); if(num_stops > MAX_STOPS) { DPRINT_ERR(WFA_ERR, "Too many stops sent\n"); gtgWmmPS = 0; if(psSockfd != -1) { wCLOSE(psSockfd); psSockfd = -1; } wSIGNAL(SIGALRM, SIG_IGN); } return 0; }
void WfaConResetAll() { int r; reset=1; printf("\nEntering WfaConResetAll:: "); alarm(0); num_retry++; if(num_retry > MAXRETRY) IAmDead(); if(reset_recd) { reset_recd = 0; set_dscp(tos_be); create_apts_msg(APTS_RESET_RESP, txmsg,0); txmsg[1] = tos_be; r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", txmsg, 64); printf("\nsent RESET RESP\n"); } else { int resp_recd=0; create_apts_msg(APTS_RESET, txmsg,0); txmsg[1] = tos_be; r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", txmsg, 64); printf("\nsent RESET \n"); while(!resp_recd) { r = recvfrom(sd, rmsg, sizeof(rmsg), 0, (struct sockaddr *)&from, &fromlen); if (r<0) { perror("rcv error:"); exit(1); } if(rmsg[10] != APTS_RESET_RESP) continue; if (traceflag) mpx("CMD recd\n", rmsg, 64); alarm(0); resp_recd=1; }/* while */ } }
int WfaConRcvBESndBcastE(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_DEFAULT,tos_be)) { printf("\r\nexpected message BE not rcv or BAD TOS\n"); } else { rmsg[0] = ++(sta->msgno); set_dscp(tos_be); r = sendto(rd, rmsg, 190, sockflags, (struct sockaddr *)&dst, sizeof(dst)); if (traceflag) mpx("CMD send brdcst\n", rmsg, 64); printf("Rcv BE sent Broadcast\n"); txmsg[0] = ++(sta->msgno); create_apts_msg(APTS_STOP, txmsg,sta->myid); r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send STOP(RcvBESndBcastE)\n", txmsg, 64); } }
int WfaConRcvVOSnd2VO(struct station *sta,unsigned int *rmsg,int length) { int r; printf("\nEntering WfaConRcvVOSnd2VO\n "); if(expectedmsgrcd(rmsg,APTS_DEFAULT,tos_vo) ) { set_dscp(tos_vo); rmsg[0] = ++(sta->msgno); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); rmsg[0] = ++(sta->msgno); if (traceflag) mpx("CMD send\n", rmsg, 64); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send\n", rmsg, 64); printf("rcv VO sent 2 VO\n"); } else { printf("\r\nexpected message not rcv or BAD TOS\n"); } }
int WfaConSndVI(struct station *sta,unsigned int *rmsg,int length) { int r; set_dscp(tos_vi); txmsg[0] = ++(sta->msgno); create_apts_msg(APTS_DEFAULT, txmsg,sta->myid); txmsg[1] = tos_vi; r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send(SndVI)\n", txmsg, 64); printf("sent VI\n"); }
/* * wfaStaSndConfirm(): This function sends the confirm packet * which is sent after the console sends the * test name to the station */ int WfaStaSndConfirm(char psave,int sleep_period,int *state) { static int num_hello=0; wfaSetDUTPwrMgmt(psave); if(!num_hello) create_apts_msg(APTS_CONFIRM, psTxMsg,0); wSENDTO(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr)); mpx("STA msg",psTxMsg,64); printf("Confirm Sent\n"); (*state)++; return 0; }
int WfaConRcvHello(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_HELLO,tos_be)) { printf("\r\nHello not rcv or BAD TOS\n"); } else { create_apts_msg(sta->cmd, txmsg,sta->myid); r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send(Hello)\n", txmsg, 64); } }
int WfaConRcvBKE(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_DEFAULT,tos_bk)) { printf("\r\nexpected message not rcv or BAD TOS\n"); } else { printf("rcv BK\n"); rmsg[0] = ++(sta->msgno); create_apts_msg(APTS_STOP, txmsg,sta->myid); r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send STOP(RcvBKE)\n", txmsg, 64); } }
/* rcv VI send VI */ int WfaConRcvVISnd(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_DEFAULT,tos_vi)) { printf("\r\nexpected message not rcv or BAD TOS\n"); } else { rmsg[0] = ++(sta->msgno); set_dscp(tos_vi); r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send\n", rmsg, 64); printf("Rcv VI sent VI (echo)\n"); } }
/* * WfaStaSnd2VO(): This function sends two AC_VO packets * after the time specified by sleep_period * and advances to the next state for the given test case */ int WfaStaSnd2VO(char psave,int sleep_period,int *state) { int r; static int en=1; PRINTF("\r\nEnterring WfastasndVO %d",en++); if ((r=sender(psave,sleep_period,TG_WMM_AC_VO))>=0) { r = wSENDTO(psSockfd, psTxMsg, msgsize, 0, (struct sockaddr *)&wmmps_info.psToAddr, sizeof(struct sockaddr)); mpx("STA msg",psTxMsg,64); (*state)++; } else PRINTF("\r\nError\n"); return 0; }
int WfaConRcvConfSndVI(struct station *sta,unsigned int *rmsg,int length) { int r; if(!expectedmsgrcd(rmsg,APTS_CONFIRM,tos_be)) { printf("\r\nConfirm not rcv or BAD TOS\n"); } else { set_dscp(tos_vi); txmsg[0] = ++(sta->msgno); create_apts_msg(APTS_DEFAULT, txmsg,sta->myid); txmsg[1] = tos_vi; r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); sta->state++; if (traceflag) mpx("CMD send (VI)\n", txmsg, 64); printf("Rcv Confirm sent VI\n"); } }
int WfaConWaitStop(struct station *sta,unsigned int *rmsg,int length) { printf("WfaConWaitStop: send stop to STA again\n"); rmsg[0] = ++(sta->msgno); create_apts_msg(APTS_STOP, txmsg,sta->myid); sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send STOP in WfaConWaitStop\n", txmsg, 64); if(expectedmsgrcd(rmsg,APTS_STOP,tos_be) ) { if(can_quit) exit(0); else can_quit=1; } else { printf("\r\nSTOP not rcv or BAD TOS\n"); } }
/* L.1 test case */ int WfaConRcvVOSndCyclic(struct station *sta,unsigned int *rmsg,int length) { int r,id, dscpLocal = 0; static int count=0; if(!expectedmsgrcdl1(rmsg,APTS_DEFAULT,tos_vo)) // call L.1 case check routine in wfa_util.c { if(!expectedmsgrcdl1(rmsg,APTS_STOP,tos_be)) //call L.1 case check routine in wfa_util.c printf("\r\nWfaConRcvVOSndCyclic::expected STOP message not rcv or BAD TOS BE\n"); else { count = 0; for(id=0; id<NSTA; id++) { if (stations[id].s_addr == 0) { break; } else { printf("\n sta count is %d\n",stations[id].msgno); count+=stations[id].msgno; } } txmsg[0] = count; printf("\n count is %d\n",count); set_dscp(tos_be); create_apts_msg(APTS_STOP, txmsg,sta->myid); txmsg[1] = tos_be; if(can_quit) { if(!sta->alreadyCleared) { strcpy((char *)&txmsg[11], "APTSL1 STOP"); r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", txmsg, 64); sleep(5); printf("\n >>> EXISTING >>> ret=%d\n",r); exit(0); } else r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", txmsg, 64); } else { r = sendto(sd, txmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); if (traceflag) mpx("CMD send\n", txmsg, 64); sta->alreadyCleared = 0; can_quit=1; } } } else { count++; printf("\r\n Rcv pkt #%d ",count); rmsg[0] = ++(sta->msgno); dscpLocal=set_dscp0(tos_vo); // no sleep setting r = sendto(sd, rmsg, 190, sockflags, (struct sockaddr *)&from, sizeof(from)); printf("sent dscp VO, return dscp=0x%x\n", dscpLocal); if ( count >= 3000) { //No state change for L.1::sta->state++; //count = 0; } } }
main(int argc, char **argv) { int r, flags=0, n, i, id,base=10, bKeepFrom = 0; struct apts_msg *testcase; struct station *sta = NULL; char IP[INET_ADDRSTRLEN],string[128]; char *str,*endptr; FILE *tmpfile; consoleProcStatetbl_t func; for(i=1; i<argc; i++) { if(argv[i][0]=='-') { if(argv[i][1]=='t') { i++; timeron=atoi(argv[i]); pthread_create(&time_thr,NULL,timerthread,NULL); } else { printf("Unrecognized options\n"); exit(1); } } else { procname = argv[i]; // gather non-option args here if( (strncmp(procname,"L.1AP", 4) == 0 )) { procname[3] = '\0'; bKeepFrom = 1; } else { bKeepFrom = 0; } } } setup_socket(); testcase = (struct apts_msg *) apts_lookup(procname); sockflags = MSG_DONTWAIT; tos_vo = 0xD0; tos_vi = 0xA0; tos_be = 0x00; tos_bk = 0x20; tmpfile = fopen("tos.txt","r+"); if(tmpfile == NULL) { printf("Can not find the tos file,proceeding with default values\n"); } else { while(fgets(string,128,tmpfile) != NULL) { if(strstr(string,"#")) continue; if(strstr(string,"0x")) { base = 16; } str = strtok(string,","); tos_vo = strtol(str,&endptr,base); str = strtok(NULL,","); tos_vi = strtol(str,&endptr,base); str = strtok(NULL,","); tos_be = strtol(str,&endptr,base); str = strtok(NULL,","); tos_bk = strtol(str,&endptr,base); } } printf("Using TOS: VO=0x%x,VI=0x%x,BE=0x%x,BK=0x%x\n", tos_vo,tos_vi,tos_be,tos_bk); traceflag=1; while (1) { if(nsta) { printf("\nWaiting in state %d\n",sta->state); } if (( sta== NULL) || (bKeepFrom == 1)) r = recvfrom(sd, rmsg, sizeof(rmsg), flags, (struct sockaddr *)&from, &fromlen); else r = recv(sd, rmsg, sizeof(rmsg), flags); resettimer(INTERSTEP_PERIOD*10); if (r<0) { perror("rcv error:"); exit(1); } alarm(0); tout=0; /* check some cases */ if (traceflag && strcmp(procname,"L.1")) { printf( "APTS Received # length:%d\n", r ); mpx("APTS RX", rmsg, 64); } // Do not process unless from remote if (from.sin_addr.s_addr==0 || from.sin_addr.s_addr==local.sin_addr.s_addr) { printf( "Received 0 / local\n" ); continue; } if (from.sin_addr.s_addr==target.sin_addr.s_addr) { printf( "Received BROADCAST\n" ); continue; } if (rmsg[10]==APTS_BCST) { printf( "Received BROADCAST, skipping\n" ); continue; } /* check some cases */ printf("\r\n cmd is %d",rmsg[11]); if (rmsg[10]==APTS_HELLO) { if((id = get_sta_id(from.sin_addr.s_addr))>=0) { if(!reset) continue; printf("\n HELLO after reset"); } else if((id = assign_sta_id(from.sin_addr.s_addr))<0) { printf( "Can not assign id,sta list full"); continue; } sta = &stations[id]; bzero(sta->ipaddress, 20); inet_ntop(AF_INET, &(from.sin_addr), IP, INET_ADDRSTRLEN); printf("ip is %s\n",IP); strcpy( &(sta->ipaddress[0]), IP); sta->cmd = testcase->cmd; sta->cookie = 0; sta->nsent = 0; sta->nerr = 0; sta->msgno = 0; sta->myid = id; sta->alreadyCleared = 0; printf("new_station: size(%d) id=%02d IP address:%s\n", r, id, sta->ipaddress); if(reset) reset = 0; else nsta++; printf( "New STA = %d\n", nsta ); sta->state = 0; sta->statefunc = consoleProcStatetbl[sta->cmd]; }/* if (rmsg[10]==APTS_HELLO) */ else { if(reset) continue; if((id = get_sta_id(from.sin_addr.s_addr))<0) { inet_ntop(AF_INET, &(from.sin_addr), IP, INET_ADDRSTRLEN); printf("\r\n Unexpected message rcd from ip s_addr=%s sta id=%d", IP, id); continue; } sta = &stations[id]; }/* else */ if(rmsg[10] == APTS_RESET) { reset_recd = 1; printf("\nRcv RESET from STA, sent RESET back to STA, exit\n"); WfaConResetAll(); exit(0); } if(rmsg[10] == APTS_RESET_STOP) { printf("\r\n Recd Kill from Sta\n"); exit(0); } func = (sta->statefunc)[sta->state]; if(!sta->alreadyCleared) { func.statefunc(sta,rmsg,r); } }/* while loop */ }/* main */