OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / lrpstat / src / InterfaceInfo.java
1 // Lrp Network Monitor: Simple network monitor written in Java
2 // Copyright (C) 2001 Martin Hejl
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18
19 // $Revision: 1.13 $
20 // $Author: hejl $
21 // $Header: /home/cvs/lrpStat/src/InterfaceInfo.java,v 1.13 2002/03/12 22:19:13 hejl Exp $
22
23 /**
24  * Class that stores the information received from the host about a specific network device
25  *
26  * @author       Martin Hejl
27  * @version      20020309 0.13beta
28  */
29 public class InterfaceInfo {
30
31         // Constants to specify the direction
32         public static final int DIRECTION_RECEIVE = 0;
33         public static final int DIRECTION_TRANSMIT = 1;
34         public static final int ISDN_OFFLINE=0;
35         public static final int ISDN_ONLINE=1;
36         public static final int ISDN_TRYING=2;
37
38
39         // Data that's sent from the server
40         protected String ifName;
41         protected String ifStatus;
42         protected boolean bISDNDevice=false;
43         protected int     ISDNStatus;
44         protected long rBytes;
45         protected long rPackets;
46         protected long rErrors;
47         protected long rDrop;
48         protected long rFifo;
49         protected long rFrame;
50         protected long rCompressed;
51         protected long rMulticast;
52         protected long tBytes;
53         protected long tPackets;
54         protected long tErrors;
55         protected long tColls;
56         protected long tCarrier;
57         protected long tDrop;
58         protected long tFifo;
59         protected long tCompressed;
60         protected long timeStamp=0;
61         protected CpuStats objStats;
62
63
64
65         /**
66          * Create an instance of InterfaceInfo with default values
67          */
68         InterfaceInfo() {
69                 ifName="";
70                 ifStatus="";
71                 rBytes=-1;
72                 rPackets=-1;
73                 rErrors=-1;
74                 rDrop=-1;
75                 rFifo=-1;
76                 rFrame=-1;
77                 rCompressed=-1;
78                 rMulticast=-1;
79                 tBytes=-1;
80                 tPackets=-1;
81                 tErrors=-1;
82                 tDrop=-1;
83                 tFifo=-1;
84                 tCompressed=-1;
85                 tColls=-1;
86                 tCarrier=-1;
87                 bISDNDevice = false;
88                 ISDNStatus = ISDN_OFFLINE;
89                 objStats = new CpuStats();
90         }
91
92         /**
93          * Create an instance of InterfaceInfo and initialize it with the given values
94          */
95         InterfaceInfo(  String if_Name, String if_Status, long r_Bytes, long r_Packets,
96                                         long r_Errors, long r_Drop, long r_Fifo, long r_Frame, long r_Compressed,
97                                         long r_Multicast, long t_Bytes, long t_Packets, long t_Errors,
98                                         long t_Drop, long t_Fifo, long t_Compressed, long t_Colls, long t_Carrier,
99                                         boolean isdn, int isdn_status, long ts) {
100                 ifName=if_Name;
101                 ifStatus=if_Status;
102                 bISDNDevice = isdn;
103                 ISDNStatus  = isdn_status;
104
105                 rBytes=r_Bytes;
106                 rPackets=r_Packets;
107                 rErrors=r_Errors;
108                 rDrop=r_Drop;
109                 rFifo=r_Fifo;
110                 rFrame=r_Frame;
111                 rCompressed=r_Compressed;
112                 rMulticast=r_Multicast;
113                 tBytes=t_Bytes;
114                 tPackets=t_Packets;
115                 tErrors=t_Errors;
116                 tDrop=t_Drop;
117                 tFifo=t_Fifo;
118                 tCompressed=t_Compressed;
119                 tColls=t_Colls;
120                 tCarrier=t_Carrier;
121                 timeStamp = ts;
122                 objStats = new CpuStats();
123         }
124
125         public void setUser(long l) {
126                 objStats.setUser(l);
127         }
128
129         public void setNice(long l){
130                 objStats.setNice(l);
131         }
132
133         public void setSystem(long l){
134                 objStats.setSystem(l);
135         }
136
137
138         public void setIdle(long l){
139                 objStats.setIdle(l);
140         }
141
142         public long getSystem() {
143                 return(objStats.getSystem());
144         }
145
146         public long getUser() {
147                 return(objStats.getUser());
148         }
149
150         public long getNice() {
151                 return(objStats.getNice());
152         }
153
154         public long getIdle() {
155                 return(objStats.getIdle());
156         }
157
158         public long getTimestamp() {
159                 return(timeStamp);
160         }
161
162         public void setTimestamp(long t) {
163                 timeStamp = t;
164         }
165
166         public boolean getISDNDevice() {
167                 return(bISDNDevice);
168         }
169
170         public void setISDNDevice(boolean b) {
171                 bISDNDevice=b;
172         }
173
174         public int getISDNStatus() {
175                 return(ISDNStatus);
176         }
177
178         public void setISDNStatus(int i) {
179                 ISDNStatus=i;
180         }
181
182         /**
183          * Return the Bytes information
184          */
185         public long getBytes(int direction){
186                 switch (direction) {
187                         case DIRECTION_RECEIVE:
188                                 return (rBytes);
189                         case DIRECTION_TRANSMIT:
190                                 return (tBytes);
191                 }
192                 return -1;
193         }
194
195         /**
196          * Return the Packets information
197          */
198         public long getPackets(int direction) {
199                 switch (direction) {
200                         case DIRECTION_RECEIVE:
201                                 return (rPackets);
202                         case DIRECTION_TRANSMIT:
203                                 return (tPackets);
204                 }
205                 return -1;
206         }
207
208         /**
209          * Return the Errors information
210          */
211         public long getErrors(int direction){
212                 switch (direction) {
213                         case DIRECTION_RECEIVE:
214                                 return (rErrors);
215                         case DIRECTION_TRANSMIT:
216                                 return (tErrors);
217                 }
218                 return -1;
219         }
220
221         /**
222          * Return the Drop information
223          */
224         public long getDrop(int direction){
225                 switch (direction) {
226                         case DIRECTION_RECEIVE:
227                                 return (rDrop);
228                         case DIRECTION_TRANSMIT:
229                                 return (tDrop);
230                 }
231                 return -1;
232         }
233
234         /**
235          * Return the Fifo information
236          */
237         public long getFifo(int direction){
238                 switch (direction) {
239                         case DIRECTION_RECEIVE:
240                                 return (rFifo);
241                         case DIRECTION_TRANSMIT:
242                                 return (tFifo);
243                 }
244                 return -1;
245         }
246
247         /**
248          * Return the Frame information
249          * Only for IN, for OUT -1 is returned
250          */
251         public long getFrame(int direction){
252                 switch (direction) {
253                         case DIRECTION_RECEIVE:
254                                 return (rFrame);
255                         case DIRECTION_TRANSMIT:
256                                 return (-1);
257                 }
258                 return -1;
259         }
260
261         /**
262          * Return the Compressed information
263          */
264         public long getCompressed(int direction){
265                 switch (direction) {
266                         case DIRECTION_RECEIVE:
267                                 return (rCompressed);
268                         case DIRECTION_TRANSMIT:
269                                 return (tCompressed);
270                 }
271                 return -1;
272         }
273
274         /**
275          * Return the Colls information
276          * Only for OUT, for IN -1 is returned
277          */
278         public long getColls(int direction){
279                 switch (direction) {
280                         case DIRECTION_RECEIVE:
281                                 return (-1);
282                         case DIRECTION_TRANSMIT:
283                                 return (tColls);
284                 }
285                 return -1;
286         }
287
288         /**
289          * Return the Carrier information
290          * Only for OUT, for IN -1 is returned
291          */
292         public long getCarrier(int direction){
293                 switch (direction) {
294                         case DIRECTION_RECEIVE:
295                                 return (-1);
296                         case DIRECTION_TRANSMIT:
297                                 return (tCarrier);
298                 }
299                 return -1;
300         }
301
302         /**
303          * Return the Multicast information
304          * Only for IN, for OUT -1 is returned
305          */
306         public long getMulticast(int direction){
307                 switch (direction) {
308                         case DIRECTION_RECEIVE:
309                                 return (rMulticast);
310                         case DIRECTION_TRANSMIT:
311                                 return (-1);
312                 }
313                 return -1;
314         }
315
316         /**
317          * Return the Interface name
318          */
319         public String getName(){
320                 return(ifName);
321         }
322
323         /**
324          * Return the interface status
325          * currently not used
326          */
327         public String getStatus(){
328                 return(ifStatus);
329         }
330
331
332         /**
333          * Set the Bytes information
334          */
335         public void setBytes(long l, int direction){
336                 switch (direction) {
337                         case DIRECTION_RECEIVE:
338                                 rBytes=l;
339                                 break;
340                         case DIRECTION_TRANSMIT:
341                                 tBytes=l;
342                                 break;
343                 }
344 //              Debug.println(ifName + ":" + direction + " " + l);
345
346         }
347
348         /**
349          * Set the Packets information
350          */
351         public void setPackets(long l, int direction){
352                 switch (direction) {
353                         case DIRECTION_RECEIVE:
354                                 rPackets=l;
355                                 break;
356                         case DIRECTION_TRANSMIT:
357                                 tPackets=l;
358                                 break;
359                 }
360
361         }
362
363         /**
364          * Set the Errors information
365          */
366         public void setErrors(long l, int direction){
367                 switch (direction) {
368                         case DIRECTION_RECEIVE:
369                                 rErrors=l;
370                                 break;
371                         case DIRECTION_TRANSMIT:
372                                 tErrors=l;
373                                 break;
374                 }
375
376         }
377
378         /**
379          * Set the Drop information
380          */
381         public void setDrop(long l, int direction){
382                 switch (direction) {
383                         case DIRECTION_RECEIVE:
384                                 rDrop=l;
385                                 break;
386                         case DIRECTION_TRANSMIT:
387                                 tDrop=l;
388                                 break;
389                 }
390
391         }
392
393         /**
394          * Set the Fifo information
395          */
396         public void setFifo(long l, int direction){
397                 switch (direction) {
398                         case DIRECTION_RECEIVE:
399                                 rFifo=l;
400                                 break;
401                         case DIRECTION_TRANSMIT:
402                                 tFifo=l;
403                                 break;
404                 }
405
406         }
407
408         /**
409          * Set the Frame information
410          */
411         public void setFrame(long l, int direction){
412                 switch (direction) {
413                         case DIRECTION_RECEIVE:
414                                 rFrame=l;
415                                 break;
416                         case DIRECTION_TRANSMIT:
417                                 // Do nothing
418                                 break;
419                 }
420
421         }
422
423         /**
424          * Set the Compressed information
425          */
426         public void setCompressed(long l, int direction){
427                 switch (direction) {
428                         case DIRECTION_RECEIVE:
429                                 rCompressed=l;
430                                 break;
431                         case DIRECTION_TRANSMIT:
432                                 tCompressed=l;
433                                 break;
434                 }
435
436         }
437
438         /**
439          * Set the Multicast information
440          */
441         public void setMulticast(long l, int direction){
442                 switch (direction) {
443                         case DIRECTION_RECEIVE:
444                                 rMulticast=l;
445                                 break;
446                         case DIRECTION_TRANSMIT:
447                                 // Do nothing
448                                 break;
449                 }
450
451         }
452
453         /**
454          * Set the Colls information
455          */
456         public void setColls(long l, int direction){
457                 switch (direction) {
458                         case DIRECTION_RECEIVE:
459                                 // Do nothing
460                                 break;
461                         case DIRECTION_TRANSMIT:
462                                 tColls = l;
463                                 break;
464                 }
465
466         }
467
468         /**
469          * Set the Carrier information
470          */
471         public void setCarrier(long l, int direction){
472                 switch (direction) {
473                         case DIRECTION_RECEIVE:
474                                 // Do nothing
475                                 break;
476                         case DIRECTION_TRANSMIT:
477                                 tCarrier = l;
478                                 break;
479                 }
480
481         }
482
483         /**
484          * Set the interface name
485          */
486         public void setName(String s){
487                 ifName=s;
488         }
489
490         /**
491          * Set the interface status (currently not used)
492          */
493         public void setStatus(String s){
494                 ifStatus=s;
495         }
496
497         /**
498          * Prints the data to stderr
499          * for debugging only
500          */
501         public void dump(){
502                 Debug.println(""+ifName);
503                 Debug.println(""+ifStatus);
504                 Debug.println(""+rBytes);
505                 Debug.println(""+rPackets);
506                 Debug.println(""+rErrors);
507                 Debug.println(""+rDrop);
508                 Debug.println(""+rFifo);
509                 Debug.println(""+rFrame);
510                 Debug.println(""+rCompressed);
511                 Debug.println(""+rMulticast);
512                 Debug.println(""+tBytes);
513                 Debug.println(""+tPackets);
514                 Debug.println(""+tErrors);
515                 Debug.println(""+tColls);
516                 Debug.println(""+tCarrier);
517                 Debug.println(""+tDrop);
518                 Debug.println(""+tFifo);
519                 Debug.println(""+tCompressed);
520
521         }
522
523         /**
524          * Makes sure no negative values are stored in the object
525          */
526         public void clipNegative() {
527                 if (rBytes<0) rBytes=0;
528                 if (rPackets<0) rPackets=0;
529                 if (rErrors<0) rErrors=0;
530                 if (rDrop<0) rDrop=0;
531                 if (rFifo<0) rFifo=0;
532                 if (rFrame<0) rFrame=0;
533                 if (rCompressed<0) rCompressed=0;
534                 if (rMulticast<0) rMulticast=0;
535                 if (tBytes<0) tBytes=0;
536                 if (tPackets<0) tPackets=0;
537                 if (tErrors<0) tErrors=0;
538                 if (tDrop<0) tDrop=0;
539                 if (tFifo<0) tFifo=0;
540                 if (tCompressed<0) tCompressed=0;
541                 if (tColls<0) tColls=0;
542                 if (tCarrier<0) tCarrier=0;
543         }
544 }
545