net.itransformers.snmp2xml4j.snmptoolkit.SnmpTcpV1Manager Maven / Gradle / Ivy
/*
* SnmpTcpV1Manager.java
*
* This work is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This work is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Copyright (c) 2010-2016 iTransformers Labs. All rights reserved.
*/
package net.itransformers.snmp2xml4j.snmptoolkit;
import net.itransformers.snmp2xml4j.snmptoolkit.messagedispacher.DefaultMessageDispatcherFactory;
import net.itransformers.snmp2xml4j.snmptoolkit.transport.TcpTransportMappingFactory;
import net.percederberg.mibble.MibLoader;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Target;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TcpAddress;
import java.io.IOException;
import java.util.Map;
/**
* Created by niau on 3/24/16.
*
* @author niau
* @version $Id: $Id
*/
public class SnmpTcpV1Manager extends SnmpManager {
protected String snmpCommunity;
protected TcpAddress tcpAddress;
/**
* Constructor for SnmpTcpV1Manager.
*
* @param loader a {@link net.percederberg.mibble.MibLoader} object.
* @param ipAddress a {@link java.lang.String} object.
* @param snmpCommunity a {@link java.lang.String} object.
* @param retries a int.
* @param timeout a int.
* @param maxSizeRequestPDU a int.
* @param maxRepetitions a int.
* @param destinationPort a int.
* @throws java.io.IOException if any.
*/
public SnmpTcpV1Manager(MibLoader loader, String ipAddress, String snmpCommunity, int retries, int timeout, int maxSizeRequestPDU, int maxRepetitions,int destinationPort) throws IOException {
super(loader, retries, timeout, maxSizeRequestPDU,maxRepetitions,new TcpTransportMappingFactory(),new TcpAddress("0.0.0.0/0"));
this.snmpCommunity = snmpCommunity;
this.tcpAddress = new TcpAddress(ipAddress+"/"+destinationPort);
}
/**
* Constructor for SnmpTcpV1Manager.
*
* @param loader a {@link net.percederberg.mibble.MibLoader} object.
*/
public SnmpTcpV1Manager(MibLoader loader) {
super(loader,new TcpTransportMappingFactory(),new DefaultMessageDispatcherFactory(),new TcpAddress("0.0.0.0/0"));
}
/** {@inheritDoc} */
@Override
protected void doInit() throws IOException {
}
/** {@inheritDoc} */
@Override
protected void doSetParameters(Map conParams) {
int destinationPort = super.convertStringToIntParam("destinationPort",conParams.get("destinationPort"),161);
this.tcpAddress = new TcpAddress(conParams.get("ipAddress")+"/"+destinationPort);
this.snmpCommunity=conParams.get("snmpCommunity");
}
/**
* getTarget.
*
* @return a {@link org.snmp4j.Target} object.
*/
protected Target getTarget() {
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(snmpCommunity));
target.setAddress(this.tcpAddress);
target.setRetries(retries);
target.setTimeout(timeout);
target.setVersion(SnmpConstants.version1);
return target;
}
/** {@inheritDoc} */
@Override
protected PDU createPDU() {
return new PDU();
}
/**
* Getter for the field snmpCommunity
.
*
* @return a {@link java.lang.String} object.
*/
public String getSnmpCommunity() {
return snmpCommunity;
}
/**
* Setter for the field snmpCommunity
.
*
* @param snmpCommunity a {@link java.lang.String} object.
*/
public void setSnmpCommunity(String snmpCommunity) {
this.snmpCommunity = snmpCommunity;
}
/**
* Getter for the field tcpAddress
.
*
* @return a {@link org.snmp4j.smi.TcpAddress} object.
*/
public TcpAddress getTcpAddress() {
return tcpAddress;
}
/**
* Setter for the field tcpAddress
.
*
* @param tcpAddress a {@link org.snmp4j.smi.TcpAddress} object.
*/
public void setTcpAddress(TcpAddress tcpAddress) {
this.tcpAddress = tcpAddress;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy