1 // NAME
2 // $RCSfile: AscendActiveSessionBean.java,v $
3 // DESCRIPTION
4 // [given below in javadoc format]
5 // DELTA
6 // $Revision: 1.13 $
7 // CREATED
8 // $Date: 2006/01/25 18:08:55 $
9 // COPYRIGHT
10 // Westhawk Ltd
11 // TO DO
12 //
13
14 /*
15 * Copyright (C) 1998 - 2006 by Westhawk Ltd
16 *
17 * Permission to use, copy, modify, and distribute this software
18 * for any purpose and without fee is hereby granted, provided
19 * that the above copyright notices appear in all copies and that
20 * both the copyright notice and this permission notice appear in
21 * supporting documentation.
22 * This software is provided "as is" without express or implied
23 * warranty.
24 * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
25 */
26
27 package uk.co.westhawk.snmp.beans;
28
29 /*-
30 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
31 * SNMP Java Client
32 * ჻჻჻჻჻჻
33 * Copyright 2023 MetricsHub, Westhawk
34 * ჻჻჻჻჻჻
35 * This program is free software: you can redistribute it and/or modify
36 * it under the terms of the GNU Lesser General Public License as
37 * published by the Free Software Foundation, either version 3 of the
38 * License, or (at your option) any later version.
39 *
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Lesser Public License for more details.
44 *
45 * You should have received a copy of the GNU General Lesser Public
46 * License along with this program. If not, see
47 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
48 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
49 */
50
51 import uk.co.westhawk.snmp.stack.*;
52 import uk.co.westhawk.snmp.pdu.*;
53 import java.awt.*;
54 import java.util.*;
55 import java.text.*;
56 import java.lang.*;
57 import java.io.*;
58 import java.beans.*;
59
60 /**
61 * <p>
62 * This bean is written for the Ascend Router from
63 * <a href="http://www.lucent.com">Lucent Technologies, Inc</a>.
64 *
65 * The Ascend Enterprise MIBs can be downloaded from
66 * <a
67 * href="http://www.oidview.com/mibs/detail.html?VID=529">ByteSphere</a>.
68 * </p>
69 *
70 * <p>
71 * This bean collects information about the active session on an Ascend router.
72 * </p>
73 *
74 * <p>
75 * The properties in the parent classes should be set, before calling
76 * the action() method. Via a PropertyChangeEvent the application/applet
77 * will be notified.
78 * </p>
79 *
80 * @see SNMPBean#setHost
81 * @see SNMPBean#setPort
82 * @see SNMPBean#setCommunityName
83 * @see SNMPRunBean#setUpdateInterval
84 * @see SNMPBean#addPropertyChangeListener
85 * @see SNMPBean#action
86 * @see GetNextPdu_vec
87 *
88 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
89 * @version $Revision: 1.13 $ $Date: 2006/01/25 18:08:55 $
90 *
91 */
92 public class AscendActiveSessionBean extends SNMPRunBean implements Observer {
93 private static final String version_id = "@(#)$Id: AscendActiveSessionBean.java,v 1.13 2006/01/25 18:08:55 birgit Exp $ Copyright Westhawk Ltd";
94
95 /**
96 * A unique number identifying this active session.
97 * See the session.mib
98 */
99 public final static String ssnActiveCallReferenceNum = "1.3.6.1.4.1.529.12.3.1.1";
100 /**
101 * The name of the remote user.
102 * See the session.mib
103 */
104 public final static String ssnActiveUserName = "1.3.6.1.4.1.529.12.3.1.4";
105 /**
106 * The IP address of the remote user.
107 * See the session.mib
108 */
109 public final static String ssnActiveUserIPAddress = "1.3.6.1.4.1.529.12.3.1.5";
110 /**
111 * The subnet mask of the remote user.
112 * See the session.mib
113 */
114 public final static String ssnActiveUserSubnetMask = "1.3.6.1.4.1.529.12.3.1.6";
115 /**
116 * The current service provided to the remote user.
117 * See the session.mib
118 */
119 public final static String ssnActiveCurrentService = "1.3.6.1.4.1.529.12.3.1.7";
120
121 private final static int NR_OID = 5;
122
123 private final static int none = 1;
124 private final static int other = 2; // none of the following
125 private final static int ppp = 3; // Point-To-Point Protocol
126 private final static int slip = 4; // Serial Line IP
127 private final static int mpp = 5; // Multichannel PPP
128 private final static int x25 = 6; // X.25
129 private final static int combinet = 7; // Combinet
130 private final static int frameRelay = 8; // Frame Relay
131 private final static int euraw = 9;
132 private final static int euui = 10;
133 private final static int telnet = 11; // telnet
134 private final static int telnetBinary = 12; // binary telnet
135 private final static int rawTcp = 13; // raw TCP
136 private final static int terminalServer = 14; // terminal server
137 private final static int mp = 15; // Multilink PPP
138 private final static int virtualConnect = 16; // Virtual Connect to a modem
139 private final static int dchannelX25 = 17; // D Channel X.25
140 private final static int dtpt = 18; // DTPT session to ZGR
141
142 private final static String msg_service[] = {
143 "",
144 "none",
145 "other",
146 "ppp",
147 "slip",
148 "mpp",
149 "x25",
150 "combinet",
151 "frameRelay",
152 "euraw",
153 "euui",
154 "telnet",
155 "telnetBinary",
156 "rawTcp",
157 "terminalServer",
158 "mp",
159 "virtualConnect",
160 "dchannelX25",
161 "dtpt"
162 };
163
164 private GetNextPdu_vec pdu;
165
166 private boolean isGetNextInFlight;
167 private Date lastUpdateDate = null;
168
169 private int callReferenceNum = 0;
170 private String userName = "";
171 private String userIPAddress = "0.0.0.0";
172 private String userSubnetMask = "0.0.0.0";
173 private String currentService = "none";
174
175 /**
176 * The default constructor.
177 */
178 public AscendActiveSessionBean() {
179 }
180
181 /**
182 * The constructor that will set the host and the port no.
183 *
184 * @param h the hostname
185 * @param p the port no
186 * @see SNMPBean#setHost
187 * @see SNMPBean#setPort
188 */
189 public AscendActiveSessionBean(String h, int p) {
190 this(h, p, null);
191 }
192
193 /**
194 * The constructor that will set the host, the port no and the local
195 * bind address.
196 *
197 * @param h the hostname
198 * @param p the port no
199 * @param b the local bind address
200 * @see SNMPBean#setHost
201 * @see SNMPBean#setPort
202 * @see SNMPBean#setBindAddress
203 *
204 * @since 4_14
205 */
206 public AscendActiveSessionBean(String h, int p, String b) {
207 this();
208 setHost(h);
209 setPort(p);
210 setBindAddress(b);
211 }
212
213 /**
214 * Returns the date of the moment when this bean was last updated.
215 * This might be null when the first time the update was not finished.
216 *
217 * @return the last update date
218 */
219 public Date getLastUpdateDate() {
220 return lastUpdateDate;
221 }
222
223 /**
224 * Returns the name of the remote user of the Ascend active session.
225 *
226 * @return the name
227 */
228 public String getUserName() {
229 return userName;
230 }
231
232 /**
233 * Returns the IP address of the remote user of the Ascend active
234 * session.
235 *
236 * @return the IP address
237 */
238 public String getUserIPAddress() {
239 return userIPAddress;
240 }
241
242 /**
243 * Returns the subnet mask of the remote user of the Ascend active
244 * session.
245 *
246 * @return the subnet mask
247 */
248 public String getUserSubnetMask() {
249 return userSubnetMask;
250 }
251
252 /**
253 * Returns the current service provided to the remote user of the Ascend
254 * active session.
255 *
256 * @return the current service
257 */
258 public String getCurrentService() {
259 return currentService;
260 }
261
262 /**
263 * This method starts the action of the bean. It will initialises
264 * all variables before starting.
265 */
266 public void action() {
267 if (isHostPortReachable()) {
268 lastUpdateDate = new Date();
269 isGetNextInFlight = false;
270 setRunning(true);
271 }
272 }
273
274 /**
275 * Implements the running of the bean.
276 *
277 * It will send the Pdu, if the previous one is not still in flight.
278 *
279 * @see SNMPRunBean#isRunning()
280 */
281 public void run() {
282 while (context != null && isRunning()) {
283 if (isGetNextInFlight == false) {
284 // start the GetNext loop again
285 isGetNextInFlight = true;
286 pdu = new GetNextPdu_vec(context, NR_OID);
287 pdu.addObserver(this);
288
289 pdu.addOid(ssnActiveCallReferenceNum);
290 pdu.addOid(ssnActiveUserName);
291 pdu.addOid(ssnActiveUserIPAddress);
292 pdu.addOid(ssnActiveUserSubnetMask);
293 pdu.addOid(ssnActiveCurrentService);
294 try {
295 pdu.send();
296 } catch (PduException exc) {
297 System.out.println("PduException " + exc.getMessage());
298 } catch (IOException exc) {
299 System.out.println("IOException " + exc.getMessage());
300 }
301 }
302
303 try {
304 Thread.sleep(interval);
305 } catch (InterruptedException ix) {
306 ;
307 }
308 }
309 }
310
311 /**
312 * This method is called when the Pdu response is received. When all
313 * answers are received it will fire the property change event.
314 *
315 * The answers are stored in a hashtable, this is done because the speed
316 * can only be calculated with the previous answer.
317 *
318 * @see SNMPBean#addPropertyChangeListener
319 */
320 public void update(Observable obs, Object ov) {
321 int service;
322 varbind[] var;
323
324 pdu = (GetNextPdu_vec) obs;
325
326 if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR) {
327 var = (varbind[]) ov;
328 callReferenceNum = ((AsnInteger) var[0].getValue()).getValue();
329
330 if (callReferenceNum > 0) {
331 userName = ((AsnOctets) var[1].getValue()).getValue();
332 userIPAddress = ((AsnOctets) var[2].getValue()).getValue();
333 userSubnetMask = ((AsnOctets) var[3].getValue()).getValue();
334
335 service = ((AsnInteger) var[4].getValue()).getValue();
336 currentService = msg_service[service];
337 }
338
339 // the GetNext loop has ended
340 lastUpdateDate = new Date();
341 isGetNextInFlight = false;
342 firePropertyChange("services", null, null);
343 }
344 }
345
346 }