00001 #include "wmp_interface.h" 00002 00003 int main(int argc, char *argv[]){ 00004 Msg m; 00005 00006 if (argc < 3){ 00007 printf("Usage: %s interface ioctl_cmd params\n", argv[0]); 00008 return 0; 00009 } 00010 00011 if(! wmpInit(argv[1])){ 00012 printf("Error iniciando RT-WMP\n"); 00013 return 0; 00014 } 00015 00016 m.src = wmpGetNodeId(); 00017 m.priority = 0; 00018 m.port = 0; 00019 00020 if (strcmp(argv[2], "push") == 0) { 00021 int ret; 00022 printf("Push\n"); 00023 00024 m.dest = atoi(argv[3]); 00025 m.len = strlen(argv[4])+1; 00026 strncpy(m.data, argv[4], m.len); 00027 00028 00029 if((ret = wmpPush(&m))){ 00030 printf("Len: %d Data: \"%s\"\n",m.len ,m.data); 00031 } else{ 00032 printf("Algo ha ido mal (ret =%d).\n",ret); 00033 } 00034 } else if (strcmp(argv[2], "pop") == 0) { 00035 printf("Pop\n"); 00036 wmpPop(&m); 00037 00038 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00039 } else if (strcmp(argv[2], "timedpop") == 0) { 00040 printf("Timed pop\n"); 00041 if (wmpTimedPop(&m, atoi(argv[3])) == -1){ 00042 printf("Timeout expired\n"); 00043 } else { 00044 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00045 } 00046 } else if (strcmp(argv[2], "nonblockingpop") == 0) { 00047 printf("Non blocking pop\n"); 00048 if (wmpNonBlockingPop(&m) == -1){ 00049 printf("No message to pop.\n"); 00050 } else{ 00051 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00052 } 00053 } else if (strcmp(argv[2], "nodeid") == 0) { 00054 printf("Node id: %d\n", wmpGetNodeId()); 00055 } else if (strcmp(argv[2], "numofnodes") == 0) { 00056 printf("Num of nodes: %d\n", wmpGetNumOfNodes()); 00057 } else if (strcmp(argv[2], "getlatestlqm") == 0) { 00058 int i, j, size = wmpGetNumOfNodes(); 00059 char lqm[size*size]; 00060 printf("LQM:\n"); 00061 wmpGetLatestLQM(lqm); 00062 00063 for (i = 0; i<size ; i++){ 00064 for (j = 0; j<size ; j++){ 00065 printf(" %04d ",lqm[i*size+j]); 00066 } 00067 printf("\n"); 00068 } 00069 } else if (strcmp(argv[2], "isnetworkconnected") == 0) { 00070 printf("isNetworkConnected: "); 00071 if (wmpIsNetworkConnected()){ 00072 printf("CONNECTED\n"); 00073 } else{ 00074 printf("NOT CONNECTED\n"); 00075 } 00076 } else if (strcmp(argv[2], "isnetworkconnectedblocking") == 0) { 00077 printf("isNetworkConnectedBlocking: "); 00078 if (wmpIsNetworkConnectedBlocking(atoi(argv[3]))){ 00079 printf("CONNECTED\n"); 00080 } else{ 00081 printf("NOT CONNECTED\n"); 00082 } 00083 } 00084 else if (strcmp(argv[2], "removetxmsg") == 0) { 00085 printf("RemoveTxMsg\n"); 00086 wmp_queue_tx_remove_head(); 00087 } 00088 else if (strcmp(argv[2], "setcpudelay") == 0) { 00089 printf("Set CPU delay: %s\n", argv[3]); 00090 wmpSetCpuDelay(atoi(argv[3])); 00091 } 00092 else if (strcmp(argv[2], "getcpudelay") == 0) { 00093 printf("CPU delay = %d\n", wmpGetCpuDelay()); 00094 } 00095 else if (strcmp(argv[2], "settimeout") == 0) { 00096 printf("Set timeout: %s\n", argv[3]); 00097 wmpSetTimeout(atoi(argv[3])); 00098 } 00099 else if (strcmp(argv[2], "gettimeout") == 0) { 00100 printf("Timeout = %d\n", wmpGetTimeout()); 00101 } 00102 else if (strcmp(argv[2], "setwcmult") == 0) { 00103 printf("Set WC mult: %s\n", argv[3]); 00104 wmpSetWCMult(atof(argv[3])); 00105 } 00106 else if (strcmp(argv[2], "getwcmult") == 0) { 00107 printf("WC mult = %f\n", wmpGetWCMult()); 00108 } 00109 else if (strcmp(argv[2], "setrate") == 0) { 00110 printf("Set rate: %s\n", argv[3]); 00111 wmpSetRate(atof(argv[3])); 00112 } 00113 else if (strcmp(argv[2], "getrate") == 0) { 00114 printf("Rate = %f\n", wmpGetRate()); 00115 } 00116 00117 else if (strcmp(argv[2], "getnumoffreepositionsintxqueue") == 0) { 00118 printf("Free positions in TX queue: %d\n", wmp_queue_tx_get_room()); 00119 } 00120 else if (strcmp(argv[2], "getnumofelementsintxqueue") == 0) { 00121 printf("Elements in TX queue: %d\n", wmpGetNumOfElementsInTXQueue()); 00122 } 00123 else if (strcmp(argv[2], "getnumofelementsinrxqueue") == 0) { 00124 printf("Elements in RX queue: %d\n", wmpGetNumOfElementsInRXQueue()); 00125 } 00126 00127 else if (strcmp(argv[2], "getnetit") == 0) { 00128 printf("Net IT: %d\n", wmpGetNetIT()); 00129 } 00130 else if (strcmp(argv[2], "getmtu") == 0) { 00131 printf("MTU: %d\n", wmpGetMTU()); 00132 } 00133 00134 else if (strcmp(argv[2], "setactivesearch") == 0) { 00135 printf("Set active search\n"); 00136 wmpSetActiveSearch(atoi(argv[3])); 00137 } 00138 else if (strcmp(argv[2], "getactivesearch") == 0) { 00139 printf("Active Search: %d\n", wmpGetActiveSearch()); 00140 } 00141 00142 else if (strcmp(argv[2], "setinstanceid") == 0) { 00143 printf("Set instance ID\n"); 00144 wmpSetInstanceId(atoi(argv[3])); 00145 } 00146 else if (strcmp(argv[2], "setprimbasedrouting") == 0) { 00147 printf("Set Prim based routing\n"); 00148 wmpSetPrimBasedRouting(atoi(argv[3])); 00149 } 00150 else if (strcmp(argv[2], "setmessagereschedule") == 0) { 00151 printf("Set message reschedule\n"); 00152 wmpSetMessageReschedule(atoi(argv[3])); 00153 } 00154 else if (strcmp(argv[2], "setflowcontrol") == 0) { 00155 printf("Set flow control\n"); 00156 wmpSetFlowControl(atoi(argv[3])); 00157 } 00158 else if (strcmp(argv[2], "getinstanceid") == 0) { 00159 printf("Instance ID = %d\n",wmpGetInstanceId()); 00160 } 00161 else if (strcmp(argv[2], "getprimbasedrouting") == 0) { 00162 printf("Prim based routing = %d\n", wmpGetPrimBasedRouting()); 00163 } 00164 else if (strcmp(argv[2], "getmessagereschedule") == 0) { 00165 printf("Message reschedule = %d\n", wmpGetMessageReschedule()); 00166 } 00167 else if (strcmp(argv[2], "getflowcontrol") == 0) { 00168 printf("Flow control = %d\n", wmpGetFlowControl()); 00169 } 00170 00171 else if (strcmp(argv[2], "getserial") == 0) { 00172 printf("Serial: %u\n", wmpGetSerial()); 00173 } 00174 else if (strcmp(argv[2], "getloopid") == 0) { 00175 printf("Loop ID: %u\n", wmpGetLoopId()); 00176 } 00177 00178 00179 00180 00181 else if (strcmp(argv[2], "addplugin") == 0) { 00182 if (strcmp(argv[3], "qos") == 0){ 00183 wmpAddPlugin(QOS); 00184 } 00185 else if (strcmp(argv[3], "bc_plus") == 0){ 00186 wmpAddPlugin(BC_PLUS); 00187 } 00188 else{ 00189 printf("Plugin \"%s\" does not exist.\n", argv[3]); 00190 } 00191 } 00192 00193 else if (strcmp(argv[2], "pushbc") == 0) { 00194 printf("PushBC\n"); 00195 00196 m.dest = (1 << (wmpGetNumOfNodes())) - 1; 00197 m.len = strlen(argv[3])+1; 00198 strncpy(m.data, argv[3],m.len); 00199 00200 printf("Len: %d Data: \"%s\"\n",m.len ,m.data); 00201 00202 wmpPushBC(&m); 00203 } 00204 else if (strcmp(argv[2], "popbc") == 0) { 00205 printf("PopBC\n"); 00206 wmpPopBC(&m); 00207 00208 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00209 } 00210 else if (strcmp(argv[2], "timedpopbc") == 0) { 00211 int timeout = atoi(argv[3]); 00212 00213 printf("Timed pop BC, timeout = %d ms\n", timeout); 00214 if (wmpPopBCTimed(&m, timeout) == -1){ 00215 printf("Timeout expired\n"); 00216 } 00217 else{ 00218 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00219 } 00220 } 00221 else if (strcmp(argv[2], "getnumoffreepositionsintxbcqueue") == 0) { 00222 printf("Free positions in TXBC queue: %d\n", wmpGetNumOfFreePositionsInTXBCQueue()); 00223 } 00224 else if (strcmp(argv[2], "getnumofelementsintxbcqueue") == 0) { 00225 printf("Elements in TXBC queue: %d\n", wmpGetNumOfElementsInTXBCQueue()); 00226 } 00227 else if (strcmp(argv[2], "getnumofelementsinrxbcqueue") == 0) { 00228 printf("Elements in RXBC queue: %d\n", wmpGetNumOfElementsInRXBCQueue()); 00229 } 00230 00231 else if (strcmp(argv[2], "pushqos") == 0) { 00232 printf("PushQoS\n"); 00233 00234 m.dest = atoi(argv[3]); 00235 m.len = strlen(argv[4])+1; 00236 strncpy(m.data, argv[4], m.len); 00237 m.qos.deadline = 150; 00238 00239 printf("Len: %d Data: \"%s\"\n",m.len ,m.data); 00240 00241 wmpPushQoS(&m); 00242 } 00243 else if (strcmp(argv[2], "popqos") == 0) { 00244 printf("PopQoS\n"); 00245 wmpPopQoS(&m); 00246 00247 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00248 } 00249 else if (strcmp(argv[2], "timedpopqos") == 0) { 00250 int timeout = atoi(argv[3]); 00251 00252 printf("Timed pop QoS, timeout = %d ms\n", timeout); 00253 if (wmpPopQoSTimed(&m, timeout) == -1){ 00254 printf("Timeout expired\n"); 00255 } 00256 else{ 00257 printf("From: %d Data: \"%s\"\n",m.src, m.data); 00258 } 00259 } 00260 else if (strcmp(argv[2], "getnumoffreepositionsintxqosqueue") == 0) { 00261 printf("Free positions in TXQoS queue: %d\n", qos_tx_getNumOfFreePositionsInQueue()); 00262 } 00263 00264 else { 00265 printf("Command \"%s\" not implemented.\n", argv[2]); 00266 } 00267 00268 wmpClose(); 00269 00270 return 0; 00271 }