man wiplcExec (Commandes) - Execute programs written in the wipl programming language

NAME

wiplcExec - Execute programs written in the wipl programming language

SYNOPSIS

wiplcExec [ -d daemonfile ] [ -f file | -e statements ]

DESCRIPTION

This programs will connect to the wipld daemon and execute a program written in the wipl programming language as described in wipllang(5).

OPTIONS

-d daemonfile --daemon=daemonfile
Connect to the daemon through the file daemonfile
-e statements --eval=statements
Set the program to execute to the content of the statements parameter.
-f file --file=file
Read the program to execute from the file file. If neither the -e nor the -f parameter is given the program is tried read from stdin.
-r --readonly
If this option is given the client will not try to obtain write access to the shared memory area.

EXAMPLES

NOTE: Some of the following examples assumes that you are running wipld in MAC based addressing mode. If you are running it in IP based addressing the examples need to be modified.

To delete all entries from the table you can use the following program:

int a=TBLcardcnt()-1;
while(a>=0) {
  TBLidxdel(a);
  a=a-1;
}

The following program will set the value of counter 0 for the MAC address 11:22:33:44:55:66 to 42K:

11:22:33:44:55:66[0]=42*1024;

This can be used to set values based on other sources than the packets seen by wipld. To delete this card from the list use:

TBLidxdel(TBLgetidx(11:22:33:44:55:66));

To print the value of counter 0 for the the netcard with MAC address 11:22:33:44:55:66 as an unsigned 32 bit integer use:

prints(11:22:33:44:55:66[0]);

To print the sum of counter 1 for all the cards in the table as an unsigned 32 bit integer use:

int i=TBLcardcnt()-1;
int result=0;
while(i>=0) {
  result+=TBLgetmacaddr(i)[1];
  i=i-1;
}
prints(result);

The two examples above are useful to feed other programs with the counter values. An example of such other program is the mrtg (Multi Router Traffic Grapher) program by Tobias Oetiker and Dave Rand, homepage http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html. The mrtg program can be used to create nice graphs based on the counters.

I will finish with an example that is bit more complicated. The following program A will print a program B so that when wiplcExec is run on B the counters will be set to the values they had when A was run. This can be used to save the counters and restore them later:

#!/usr/bin/wiplcExec -f

// Print program that deletes all the current cards: print("int card=TBLcardcnt()-1;\n"); print("while(card>=0) { \n"); print(" TBLidxdel(card); \n"); print(" card=card-1; \n"); print("} \n");

// And print program that sets all the counters: int card=TBLcardcnt()-1; while(card>=0) { int cnt=TBLcntcnt()-1; while(cnt>=0) { maca ma=MACgetmacaddr(card); print(ma); print("["); prints(cnt); print("]="); print(ma[cnt]); print(";"); cnt=cnt-1; } card=card-1; print("\n"); }

If this program is put to a file named A the following command will save the counters to the file B:


cat A | wiplcExec > B

And the following program will restore the counters:


cat B | wiplcExec

Note that the command:


cat A | wiplcExec | wiplcExec

Will not deadlock. This is because wiplcExec always reads the whole program before it starts executing it. Also refer to BUGS below.

FILES

/etc/wipld.conf Default daemonfile.

BUGS

The shared memory area with the counters is locked as long as the program executes. So if the output is piped to a program which only consumes the data very slowly the memory area might be locked for so long that packets are dropped by the wipld program. In such a situation you might want to write the output of wiplcExec to a file and then pipe the contest of this file to the other program afterwards.

Programs must have write permission to the statistics, even if they don't modify them. See wipld(8) for information about how to set the permissons.

SEE ALSO