1 // Lrp Network Monitor: Simple network monitor written in Java
2 // Copyright (C) 2001 Martin Hejl
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)
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.
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.
21 // $Header: /home/cvs/lrpStat/src/InterfaceInfo.java,v 1.13 2002/03/12 22:19:13 hejl Exp $
24 * Class that stores the information received from the host about a specific network device
27 * @version 20020309 0.13beta
29 public class InterfaceInfo {
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;
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;
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;
59 protected long tCompressed;
60 protected long timeStamp=0;
61 protected CpuStats objStats;
66 * Create an instance of InterfaceInfo with default values
88 ISDNStatus = ISDN_OFFLINE;
89 objStats = new CpuStats();
93 * Create an instance of InterfaceInfo and initialize it with the given values
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) {
103 ISDNStatus = isdn_status;
111 rCompressed=r_Compressed;
112 rMulticast=r_Multicast;
118 tCompressed=t_Compressed;
122 objStats = new CpuStats();
125 public void setUser(long l) {
129 public void setNice(long l){
133 public void setSystem(long l){
134 objStats.setSystem(l);
138 public void setIdle(long l){
142 public long getSystem() {
143 return(objStats.getSystem());
146 public long getUser() {
147 return(objStats.getUser());
150 public long getNice() {
151 return(objStats.getNice());
154 public long getIdle() {
155 return(objStats.getIdle());
158 public long getTimestamp() {
162 public void setTimestamp(long t) {
166 public boolean getISDNDevice() {
170 public void setISDNDevice(boolean b) {
174 public int getISDNStatus() {
178 public void setISDNStatus(int i) {
183 * Return the Bytes information
185 public long getBytes(int direction){
187 case DIRECTION_RECEIVE:
189 case DIRECTION_TRANSMIT:
196 * Return the Packets information
198 public long getPackets(int direction) {
200 case DIRECTION_RECEIVE:
202 case DIRECTION_TRANSMIT:
209 * Return the Errors information
211 public long getErrors(int direction){
213 case DIRECTION_RECEIVE:
215 case DIRECTION_TRANSMIT:
222 * Return the Drop information
224 public long getDrop(int direction){
226 case DIRECTION_RECEIVE:
228 case DIRECTION_TRANSMIT:
235 * Return the Fifo information
237 public long getFifo(int direction){
239 case DIRECTION_RECEIVE:
241 case DIRECTION_TRANSMIT:
248 * Return the Frame information
249 * Only for IN, for OUT -1 is returned
251 public long getFrame(int direction){
253 case DIRECTION_RECEIVE:
255 case DIRECTION_TRANSMIT:
262 * Return the Compressed information
264 public long getCompressed(int direction){
266 case DIRECTION_RECEIVE:
267 return (rCompressed);
268 case DIRECTION_TRANSMIT:
269 return (tCompressed);
275 * Return the Colls information
276 * Only for OUT, for IN -1 is returned
278 public long getColls(int direction){
280 case DIRECTION_RECEIVE:
282 case DIRECTION_TRANSMIT:
289 * Return the Carrier information
290 * Only for OUT, for IN -1 is returned
292 public long getCarrier(int direction){
294 case DIRECTION_RECEIVE:
296 case DIRECTION_TRANSMIT:
303 * Return the Multicast information
304 * Only for IN, for OUT -1 is returned
306 public long getMulticast(int direction){
308 case DIRECTION_RECEIVE:
310 case DIRECTION_TRANSMIT:
317 * Return the Interface name
319 public String getName(){
324 * Return the interface status
327 public String getStatus(){
333 * Set the Bytes information
335 public void setBytes(long l, int direction){
337 case DIRECTION_RECEIVE:
340 case DIRECTION_TRANSMIT:
344 // Debug.println(ifName + ":" + direction + " " + l);
349 * Set the Packets information
351 public void setPackets(long l, int direction){
353 case DIRECTION_RECEIVE:
356 case DIRECTION_TRANSMIT:
364 * Set the Errors information
366 public void setErrors(long l, int direction){
368 case DIRECTION_RECEIVE:
371 case DIRECTION_TRANSMIT:
379 * Set the Drop information
381 public void setDrop(long l, int direction){
383 case DIRECTION_RECEIVE:
386 case DIRECTION_TRANSMIT:
394 * Set the Fifo information
396 public void setFifo(long l, int direction){
398 case DIRECTION_RECEIVE:
401 case DIRECTION_TRANSMIT:
409 * Set the Frame information
411 public void setFrame(long l, int direction){
413 case DIRECTION_RECEIVE:
416 case DIRECTION_TRANSMIT:
424 * Set the Compressed information
426 public void setCompressed(long l, int direction){
428 case DIRECTION_RECEIVE:
431 case DIRECTION_TRANSMIT:
439 * Set the Multicast information
441 public void setMulticast(long l, int direction){
443 case DIRECTION_RECEIVE:
446 case DIRECTION_TRANSMIT:
454 * Set the Colls information
456 public void setColls(long l, int direction){
458 case DIRECTION_RECEIVE:
461 case DIRECTION_TRANSMIT:
469 * Set the Carrier information
471 public void setCarrier(long l, int direction){
473 case DIRECTION_RECEIVE:
476 case DIRECTION_TRANSMIT:
484 * Set the interface name
486 public void setName(String s){
491 * Set the interface status (currently not used)
493 public void setStatus(String s){
498 * Prints the data to stderr
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);
524 * Makes sure no negative values are stored in the object
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;