[SNMP4J] Re: SNMP4J Digest, Vol 9, Issue 1

Yaomin Yang yaomin at exavio.com.cn
Thu Oct 21 07:08:16 CEST 2004


hi, all
    I am a boy and a rookie from China, and I prepare to use the snmp4j pacakge to do something on NMS. Would you like to make friends with me.
    Nice to meet you all.
  Alfred Yang
    

----- Original Message ----- 
From: <snmp4j-request at agentpp.org>
To: <snmp4j at agentpp.org>
Sent: Sunday, October 10, 2004 6:00 PM
Subject: SNMP4J Digest, Vol 9, Issue 1


> Send SNMP4J mailing list submissions to
> snmp4j at agentpp.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> http://p15141779.pureserver.info/mailman/listinfo/snmp4j
> or, via email, send a message with subject or body 'help' to
> snmp4j-request at agentpp.org
> 
> You can reach the person managing the list at
> snmp4j-owner at agentpp.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of SNMP4J digest..."
> 
> 
> Today's Topics:
> 
>    1. SNMP4j examples (Gil Steiner)
>    2. Re: SNMP4j examples (Frank Fock)
>    3. Re: SNMP4j examples (Mathias Bogaert)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Sun, 10 Oct 2004 02:15:02 -0700 (PDT)
> From: Gil Steiner <gil1908 at yahoo.com>
> Subject: [SNMP4J] SNMP4j examples
> To: snmp4j at agentpp.org
> Message-ID: <20041010091502.92286.qmail at web41511.mail.yahoo.com>
> Content-Type: text/plain; charset=us-ascii
> 
> Hi,
> 
> Are there any examples of simple snmp4j code
> available? I mean, for example, a simple snmp get,
> getnext or a walk tool.
> 
> +gil
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Sun, 10 Oct 2004 11:22:10 +0200
> From: Frank Fock <fock at agentpp.com>
> Subject: Re: [SNMP4J] SNMP4j examples
> To: Gil Steiner <gil1908 at yahoo.com>
> Cc: snmp4j at agentpp.org
> Message-ID: <4168FF42.5080004 at agentpp.com>
> Content-Type: text/plain; charset=us-ascii; format=flowed
> 
> Hi Gil,
> 
> You can find a simple example for a GETNEXT request
> (for the corresponding GET replace GETNEXT with GET
> in the code) can be found in the JavaDoc of the Snmp class:
> 
> http://www.snmp4j.org/doc/org/snmp4j/Snmp.html
> 
> For a complete example of the various SNMP4J features
> you can browse the org.snmp4j.tools.console.SnmpRequest
> class sources.
> 
> Hope this helps.
> 
> Best regards,
> Frank
> 
> Gil Steiner wrote:
> 
> >Hi,
> >
> >Are there any examples of simple snmp4j code
> >available? I mean, for example, a simple snmp get,
> >getnext or a walk tool.
> >
> >+gil
> >_______________________________________________
> >SNMP4J mailing list
> >SNMP4J at agentpp.org
> >http://p15141779.pureserver.info/mailman/listinfo/snmp4j
> >
> >  
> >
> 
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Sun, 10 Oct 2004 11:24:11 +0200
> From: Mathias Bogaert <pathos at pandora.be>
> Subject: Re: [SNMP4J] SNMP4j examples
> To: snmp4j at agentpp.org
> Message-ID: <251C2EBA-1A9E-11D9-998E-000A95AE4562 at pandora.be>
> Content-Type: text/plain; charset="us-ascii"
> 
> Gil,
> 
> Attached is a (more complex) example of SNMP4J usage in a cable 
> monitoring system.
> 
> Enjoy,
> 
> Mathias Bogaert
> 
> -------------- next part --------------
> package nl.nutsmaas.marvin.agent;
> 
> import nl.nutsmaas.marvin.domain.CableModem;
> import nl.nutsmaas.marvin.domain.Cmts;
> import org.snmp4j.smi.OID;
> 
> import java.io.IOException;
> 
> /**
>  * Will extract {@link CableModem} samples.
>  *
>  * @see nl.nutsmaas.marvin.domain.CableModemSample
>  *
>  * @author <a href="mailto:m.bogaert at intrasoft.be">Mathias Bogaert</a>
>  * @version $Revision: 1.50 $
>  */
> public interface CableModemSnmpAgent extends SnmpAgent {
>     static final String SNMP_CABLE_MODEM_IP_POINTER = "1.3.6.1.2.1.10.127.1.3.7.1.2";
>     static final String SNMP_CABLE_MODEM_STATUS = "1.3.6.1.4.1.9.9.116.1.3.2.1.1";
> 
>     static final OID SNMP_DESCRIPTION_OID = new OID("1.3.6.1.2.1.1.1.0");
>     static final OID SNMP_DOWNSTREAM_PACKETS_OID = new OID("1.3.6.1.2.1.2.2.1.11.2");
>     static final OID SNMP_UPSTREAM_PACKETS_OID = new OID("1.3.6.1.2.1.2.2.1.17.4");
>     static final OID SNMP_DOWNSTREAM_OCTETS_OID = new OID("1.3.6.1.2.1.2.2.1.10.2");
>     static final OID SNMP_UPSTREAM_OCTETS_OID = new OID("1.3.6.1.2.1.2.2.1.16.4");
> 
>     static final OID SNMP_DOWNSTREAM_SNR_OID = new OID("1.3.6.1.2.1.10.127.1.1.4.1.5.3");
>     static final OID SNMP_DOWNSTREAM_CHANNEL_POWER_OID = new OID("1.3.6.1.2.1.10.127.1.1.1.1.6.3");
>     static final OID SNMP_UPSTREAM_TX_POWER_OID = new OID("1.3.6.1.2.1.10.127.1.2.2.1.3.2");
> 
>     static final String SNMP_UPSTREAM_IF_INDEX = "1.3.6.1.2.1.10.127.1.3.3.1.5";
>     static final String SNMP_UPSTREAM_SNR = "1.3.6.1.2.1.10.127.1.1.4.1.5";
> 
>     // CPE details
>     static final String SNMP_CPE_MAC_ADDRESS = "cdxCmCpeMacAddress";
>     static final String SNMP_CPE_IP_ADDRESS = "";
> 
>     // flap statistics
>     static final String SNMP_FLAP_INSERTS = "1.3.6.1.4.1.9.9.114.1.1.5.1.13";
>     static final String SNMP_FLAP_HITS = "1.3.6.1.4.1.9.9.114.1.1.5.1.14";
>     static final String SNMP_FLAP_MISS = "1.3.6.1.4.1.9.9.114.1.1.5.1.15";
>     static final String SNMP_FLAP_CRC = "1.3.6.1.4.1.9.9.114.1.1.5.1.16";
>     static final String SNMP_FLAP_POWER_ADJUSTMENTS = "1.3.6.1.4.1.9.9.114.1.1.5.1.17";
> 
>     static final String SNMP_CABLE_MODEM_RESET = "1.3.6.1.4.1.9.9.116.1.3.1.1.8";
> 
>     /**
>      * Listen for incoming messages. For connection oriented transports, this
>      * method needs to be called before {@link #extractSample} is called for the
>      * first time.
>      *
>      * @throws IOException
>      */
>     void listen() throws IOException;
> 
>     /**
>      * Will extract a sample from the {@link CableModem}.
>      *
>      * @param cableModem
>      * @throws IOException if the {@link CableModem} cannot be reached
>      */
>     void extractSample(CableModem cableModem) throws IOException;
> 
>     /**
>      * Will rest the cable modem.
>      *
>      * @param cableModem
>      * @throws IOException
>      */
>     void reset(CableModem cableModem) throws IOException;
> 
>     /**
>      * Will return the {@link Cmts} for the given IP address.
>      *
>      * @param ipAddress
>      * @return
>      */
>     Cmts getCmts(String ipAddress);
> 
>     /**
>      * Closes the transport and releases all bound resources synchronously.
>      *
>      * @throws IOException
>      */
>     void close() throws IOException;
> }
> -------------- next part --------------
> package nl.nutsmaas.marvin.agent;
> 
> import nl.nutsmaas.marvin.bacc.CiscoBaccGateway;
> import nl.nutsmaas.marvin.domain.CableModem;
> import nl.nutsmaas.marvin.domain.CableModemSample;
> import nl.nutsmaas.marvin.domain.CableModemStatus;
> import nl.nutsmaas.marvin.domain.Cmts;
> import nl.nutsmaas.marvin.domain.persistence.CmtsDao;
> import nl.nutsmaas.marvin.event.SampleExtractedEvent;
> import nl.nutsmaas.marvin.util.profiling.UtilTimerStack;
> import org.apache.log4j.Logger;
> import org.snmp4j.CommunityTarget;
> import org.snmp4j.PDU;
> import org.snmp4j.Snmp;
> import org.snmp4j.smi.*;
> import org.snmp4j.transport.DefaultUdpTransportMapping;
> 
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
> 
> /**
>  * Default implementation of {@link CableModemSnmpAgent} using <a href="http://www.snmp4j.org/">SNMP4J</a>.
>  *
>  * @see CiscoBaccGateway
>  *
>  * @author <a href="mailto:m.bogaert at intrasoft.be">Mathias Bogaert</a>
>  * @version $Revision: 1.15 $
>  */
> public class CableModemSnmpAgentImpl extends SnmpAgentSupport implements CableModemSnmpAgent {
>     private static final Logger log = Logger.getLogger(CableModemSnmpAgentImpl.class);
> 
>     private CiscoBaccGateway ciscoBaccGateway;
>     private CmtsDao cmtsDao;
> 
>     private final Snmp snmp;
> 
>     public CableModemSnmpAgentImpl() throws IOException {
>         snmp = new Snmp(new DefaultUdpTransportMapping());
>     }
> 
>     public void listen() throws IOException {
>         snmp.listen(); // start the transport  mappings internal listen thread
>     }
> 
>     public void extractSample(CableModem cableModem) throws IOException {
>         if (cableModem == null) throw new IllegalArgumentException("cableModem may not be null");
> 
>         final CableModemSample sample = new CableModemSample(cableModem);
> 
>         if (log.isInfoEnabled()) log.info("Initiating sample extraction for " + cableModem + "...");
> 
>         extractDataFromCmts(sample);
> 
>         // in case the modem is not registered on the specified CMTS (change of CMTS), re-obtain the IP address and CMTS
>         if (cableModem.isQueryBaccForIpAddress() && !sample.isCableModemRegistered()) {
>             final String ipAddress = ciscoBaccGateway.getIpAddress(cableModem.getMacAddress());
> 
>             if (ipAddress != null) {
>                 cableModem.setIpAddress(ipAddress);
>                 final Cmts cmts = getCmts(ipAddress);
>                 if (cmts != null) {
>                     if (!cmts.equals(cableModem.getCmts())) {
>                         if (cableModem.getCmts() != null) cableModem.getCmts().removeCableModem(cableModem);
>                         cmts.addCableModem(cableModem);
>                         extractDataFromCmts(sample);
>                     }
>                 }
>                 else {
>                     log.error("Cable modem provisioned at unknown CMTS segment: " + cableModem);
>                 }
>             }
>             else {
>                 log.error("Unable to obtain IP address for modem " + cableModem + " from BACC.");
>             }
>         }
> 
> 
>         // if the cable modem is online at the CMTS, get value's from cable modem
>         if (sample.isCableModemOnline()) {
>             extractDataFromCableModem(sample);
>         }
> 
>         applicationContext.publishEvent(new SampleExtractedEvent(sample));
>     }
> 
>     public void reset(CableModem cableModem) throws IOException {
>         final Cmts cmts = cableModem.getCmts();
> 
>         final CommunityTarget target = new CommunityTarget();
>         target.setAddress(new UdpAddress(getByAddress(cmts.getIpAddress()), cmts.getSnmpPort()));
>         target.setCommunity(new OctetString(cmts.getSnmpWriteCommunity()));
>         target.setTimeout(cmts.getSnmpTimeout());
>         target.setVersion(cmts.getSnmpVersion());
>         target.setRetries(1);
> 
>         final String macAddressOid = dottedHexToDecimal(cableModem.getMacAddress());
> 
>         final PDU resetPDU = new PDU();
>         resetPDU.setType(PDU.SET);
> 
>         resetPDU.add(new VariableBinding(new OID(SNMP_CABLE_MODEM_RESET + macAddressOid), new Integer32(1))); // TruthValue 1 (true)
> 
>         final PDU resetResponsePDU = snmp.sendPDU(resetPDU, target);
>         if (resetResponsePDU == null) {
>             log.warn("Time-out resetting cable modem " + cableModem);
>         }
>     }
> 
>     private void extractDataFromCmts(CableModemSample sample) throws IOException {
>         try {
>             if (UtilTimerStack.isActive()) UtilTimerStack.push("extractDataFromCmts from " + sample.getCableModem().getCmts() + " at " + sample.getCableModem().getCmts().getIpAddress());
> 
>             final Cmts cmts = sample.getCableModem().getCmts();
> 
>             final CommunityTarget target = new CommunityTarget();
>             target.setAddress(new UdpAddress(getByAddress(cmts.getIpAddress()), cmts.getSnmpPort()));
>             target.setCommunity(new OctetString(cmts.getSnmpReadCommunity()));
>             target.setTimeout(cmts.getSnmpTimeout());
>             target.setVersion(cmts.getSnmpVersion());
>             target.setRetries(1);
> 
>             final String macAddressOid = dottedHexToDecimal(sample.getCableModem().getMacAddress());
>             final OID pointerOID = new OID(SNMP_CABLE_MODEM_IP_POINTER + macAddressOid);
> 
>             OID upstreamSnrOID = null;
> 
>             final PDU pointerPDU = new PDU();
>             pointerPDU.add(new VariableBinding(pointerOID));
> 
>             final PDU pointerResponsePDU = snmp.sendPDU(pointerPDU, target);
> 
>             if (pointerResponsePDU == null) {
>                 log.warn("Time-out on cmts " + cmts);
>             }
>             else if (pointerResponsePDU.get(0).getSyntax() == SMIConstants.SYNTAX_INTEGER
>                     && pointerOID.equals(pointerResponsePDU.get(0).getOid())) {
> 
>                 int macPointer = ((Integer32) pointerResponsePDU.get(0).getVariable()).getValue();
> 
>                 final OID statusOID = new OID(SNMP_CABLE_MODEM_STATUS + "." + macPointer);
>                 final OID ifIndexUpstreamOID = new OID(SNMP_UPSTREAM_IF_INDEX + "." + macPointer);
> 
>                 final PDU statusPDU = new PDU();
>                 statusPDU.add(new VariableBinding(statusOID));
>                 statusPDU.add(new VariableBinding(ifIndexUpstreamOID));
> 
>                 final PDU statusResponsePDU = snmp.sendPDU(statusPDU, target);
> 
>                 if (statusResponsePDU == null) {
>                     log.warn("Time-out on cmts " + cmts);
>                 }
>                 else {
>                     for (int i = 0; i < statusResponsePDU.size(); i++) {
>                         VariableBinding vb = statusResponsePDU.get(i);
> 
>                         if (statusOID.equals(vb.getOid())) {
>                             CableModemStatus status = CableModemStatus.fromInt(((Integer32) vb.getVariable()).getValue());
>                             assert status != null : "internal error; status cannot be obtained from CMTS";
>                             sample.setStatus(status);
>                         }
>                         else if (ifIndexUpstreamOID.equals(vb.getOid())) {
>                             upstreamSnrOID = new OID(SNMP_UPSTREAM_SNR + "." + ((Integer32) vb.getVariable()).getValue());
>                         }
>                         else {
>                             throw new IllegalStateException("The CMTS where the modem " + sample.getCableModem() + " is supposed to be provisioned (" +
>                                     sample.getCableModem().getCmts() + ") does not have the modem status.");
>                         }
>                     }
>                 }
>             }
>             else {
>                 sample.setStatus(CableModemStatus.NOT_REGISTERED);
>                 return;
>             }
> 
>             final OID insertsOID = new OID(SNMP_FLAP_INSERTS + macAddressOid);
>             final OID hitsOID = new OID(SNMP_FLAP_HITS + macAddressOid);
>             final OID missOID = new OID(SNMP_FLAP_MISS + macAddressOid);
>             final OID crcOID = new OID(SNMP_FLAP_CRC + macAddressOid);
>             final OID pwdAdjOID = new OID(SNMP_FLAP_POWER_ADJUSTMENTS + macAddressOid);
> 
>             final PDU flapPDU = new PDU();
>             flapPDU.add(new VariableBinding(insertsOID));
>             flapPDU.add(new VariableBinding(hitsOID));
>             flapPDU.add(new VariableBinding(missOID));
>             flapPDU.add(new VariableBinding(crcOID));
>             flapPDU.add(new VariableBinding(pwdAdjOID));
> 
>             // upstreamSnrOID could be null if we received a time-out
>             if (upstreamSnrOID != null) flapPDU.add(new VariableBinding(upstreamSnrOID));
> 
>             final PDU flapResponsePDU = snmp.sendPDU(flapPDU, target);
> 
>             if (flapResponsePDU == null) {
>                 log.warn("Time-out on cmts " + cmts);
>             }
>             else {
>                 for (int i = 0; i < flapResponsePDU.size(); i++) {
>                     VariableBinding vb = flapResponsePDU.get(i);
>                     if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_GAUGE32 && vb.getOid().equals(insertsOID)) {
>                         sample.setInserts(new Long(((Gauge32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_GAUGE32 && vb.getOid().equals(hitsOID)) {
>                         sample.setHits(new Long(((Gauge32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_GAUGE32 && vb.getOid().equals(missOID)) {
>                         sample.setMiss(new Long(((Gauge32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_GAUGE32 && vb.getOid().equals(crcOID)) {
>                         sample.setCrc(new Long(((Gauge32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_GAUGE32 && vb.getOid().equals(pwdAdjOID)) {
>                         sample.setPowerAdjustments(new Long(((Gauge32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getVariable().getSyntax() == SMIConstants.SYNTAX_INTEGER && vb.getOid().equals(upstreamSnrOID)) {
>                         double d = ((Integer32) vb.getVariable()).getValue();
>                         sample.setUpstreamSignalNoiseRatio(new Double(d / 10));
>                     }
>                 }
>             }
>         }
>         finally {
>             if (UtilTimerStack.isActive()) UtilTimerStack.pop("extractDataFromCmts from " + sample.getCableModem().getCmts() + " at " + sample.getCableModem().getCmts().getIpAddress());
>         }
>     }
> 
>     private void extractDataFromCableModem(CableModemSample sample) throws IOException {
>         try {
>             if (UtilTimerStack.isActive()) UtilTimerStack.push("extractDataFromCableModem from " + sample.getCableModem() + " at " + sample.getCableModem().getIpAddress());
> 
>             final CableModem cableModem = sample.getCableModem();
> 
>             final CommunityTarget target = new CommunityTarget();
>             target.setAddress(new UdpAddress(getByAddress(cableModem.getIpAddress()), cableModem.getSnmpPort()));
>             target.setCommunity(new OctetString(cableModem.getSnmpReadCommunity()));
>             target.setTimeout(cableModem.getSnmpTimeout());
>             target.setVersion(cableModem.getSnmpVersion());
> 
>             final PDU samplePDU = new PDU();
>             samplePDU.add(new VariableBinding(SNMP_DESCRIPTION_OID));
>             samplePDU.add(new VariableBinding(SNMP_DOWNSTREAM_PACKETS_OID));
>             samplePDU.add(new VariableBinding(SNMP_UPSTREAM_PACKETS_OID));
>             samplePDU.add(new VariableBinding(SNMP_DOWNSTREAM_OCTETS_OID));
>             samplePDU.add(new VariableBinding(SNMP_UPSTREAM_OCTETS_OID));
>             samplePDU.add(new VariableBinding(SNMP_DOWNSTREAM_SNR_OID));
>             samplePDU.add(new VariableBinding(SNMP_DOWNSTREAM_CHANNEL_POWER_OID));
>             samplePDU.add(new VariableBinding(SNMP_UPSTREAM_TX_POWER_OID));
> 
>             PDU sampleResponsePDU = snmp.sendPDU(samplePDU, target);
> 
>             // check if we got a time-out - if so, retry with new IP address
>             if (sampleResponsePDU == null && cableModem.isQueryBaccForIpAddress()) {
>                 log.warn("Time-out on cable modem " + cableModem + ", obtaining possible new IP address from BACC...");
> 
>                 // in case of different IP address assigned by DHCP, we need to
>                 // obtain and store the IP address and retry
>                 final String ipAddress = ciscoBaccGateway.getIpAddress(cableModem.getMacAddress());
>                 if (ipAddress == null) {
>                     log.warn("Unable to obtain IP address for modem " + cableModem + " after time-out.");
>                 }
>                 else if (!ipAddress.equals(cableModem.getIpAddress())) {
>                     cableModem.setIpAddress(ipAddress);
>                     target.setAddress(new UdpAddress(cableModem.getIpAddress() + "/" + cableModem.getSnmpPort()));
>                     sampleResponsePDU = snmp.sendPDU(samplePDU, target);
>                 }
>             }
> 
>             if (sampleResponsePDU == null) {
>                 StringBuffer timeoutMsg = new StringBuffer();
>                 timeoutMsg.append("Time-out on cable modem ");
>                 timeoutMsg.append(cableModem);
>                 if (cableModem.isQueryBaccForIpAddress())
>                     timeoutMsg.append(", even after trying with possible new IP address.");
>                 log.warn(timeoutMsg.toString());
>             }
>             else {
>                 sample.setIpAddress(cableModem.getIpAddress());
> 
>                 for (int i = 0; i < sampleResponsePDU.size(); i++) {
>                     VariableBinding vb = sampleResponsePDU.get(i);
>                     if (vb.getOid().equals(SNMP_DESCRIPTION_OID)) {
>                         sample.getCableModem().setDescription(vb.getVariable().toString());
>                     }
>                     else if (vb.getOid().equals(SNMP_DOWNSTREAM_PACKETS_OID)) {
>                         sample.setDownstreamPackets(new Long(((Counter32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getOid().equals(SNMP_UPSTREAM_PACKETS_OID)) {
>                         sample.setUpstreamPackets(new Long(((Counter32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getOid().equals(SNMP_DOWNSTREAM_OCTETS_OID)) {
>                         sample.setDownstreamOctets(new Long(((Counter32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getOid().equals(SNMP_UPSTREAM_OCTETS_OID)) {
>                         sample.setUpstreamOctets(new Long(((Counter32) vb.getVariable()).getValue()));
>                     }
>                     else if (vb.getOid().equals(SNMP_DOWNSTREAM_SNR_OID)) {
>                         double d = ((Integer32) vb.getVariable()).getValue();
>                         sample.setDownstreamSignalNoiseRatio(new Double(d / 10));
>                     }
>                     else if (vb.getOid().equals(SNMP_DOWNSTREAM_CHANNEL_POWER_OID)) {
>                         double d = ((Integer32) vb.getVariable()).getValue();
>                         sample.setDownstreamChannelPower(new Double(d / 10));
>                     }
>                     else if (vb.getOid().equals(SNMP_UPSTREAM_TX_POWER_OID)) {
>                         double d = ((Integer32) vb.getVariable()).getValue();
>                         sample.setUpstreamTxPower(new Double((d / 10) + 60));
>                     }
>                 }
>             }
>         }
>         finally {
>             if (UtilTimerStack.isActive()) UtilTimerStack.pop("extractDataFromCableModem from " + sample.getCableModem() + " at " + sample.getCableModem().getIpAddress());
>         }
>     }
> 
>     public Cmts getCmts(String ipAddress) {
>         if (ipAddress == null) throw new IllegalArgumentException("ipAddress may not be null");
> 
>         Pattern pattern;
>         Matcher matcher;
> 
>         assert cmtsDao != null : "internal error; cmtsDao is null";
> 
>         for (Iterator i = cmtsDao.getCmtss().iterator(); i.hasNext();) {
>             final Cmts cmts = (Cmts) i.next();
> 
>             assert cmts != null : "internal error; cmts is null";
>             assert cmts.getSegmentIpPrefixes() != null : "internal error; cmts.getSegmentIpPrefixes is null";
> 
>             for (int k = 0; k < cmts.getSegmentIpPrefixes().length; k++) {
>                 pattern = Pattern.compile(cmts.getSegmentIpPrefixes()[k]);
>                 matcher = pattern.matcher(ipAddress);
> 
>                 if (matcher.find()) {
>                     return cmts;
>                 }
>             }
>         }
> 
>         // no cmts found for this cable modem
>         return null;
>     }
> 
>     public void close() throws IOException {
>         if (snmp != null) snmp.close();
>     }
> 
>     public void setCiscoBaccGateway(CiscoBaccGateway ciscoBaccGateway) {
>         this.ciscoBaccGateway = ciscoBaccGateway;
>     }
> 
>     public void setCmtsDao(CmtsDao cmtsDao) {
>         this.cmtsDao = cmtsDao;
>     }
> }
> -------------- next part --------------
> 
> 
> On 10 Oct 2004, at 11:15, Gil Steiner wrote:
> 
> > Hi,
> >
> > Are there any examples of simple snmp4j code
> > available? I mean, for example, a simple snmp get,
> > getnext or a walk tool.
> >
> > +gil
> > _______________________________________________
> > SNMP4J mailing list
> > SNMP4J at agentpp.org
> > http://p15141779.pureserver.info/mailman/listinfo/snmp4j
> >
> >
> 
> ------------------------------
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://p15141779.pureserver.info/mailman/listinfo/snmp4j
> 
> 
> End of SNMP4J Digest, Vol 9, Issue 1
> ************************************
> 


More information about the SNMP4J mailing list