MacAddress

 

MacAddress is a standard TEXTUAL-CONVENTION defined in SNMPv2-TC. MacAddress is resolved to the base datatype OCTET STRING. The DISPLAY-HINT format for MacAddress is given as follows.

 

DISPLAY-HINT "1x:"

 

Create Variable

 

Using mibs package

 

For creating a value for a node, the createVariable() method in the LeafSyntax class is used. The MacAddress value should be six bytes. Each byte should be separated by colon(:) and the value should be enclosed in single quotes.

 

The following code snippet creates an SnmpVar object of MacAddress type using the LeafSyntaxapi.jpg class.

 

String mibFile = "<mib name>";

String moduleName = "TOKENRING-MIB";

String nodeName = "dot5UpStream";

MibOperations mibOps = new MibOperations();

mibOps.loadMibModule(mibFile);

MibModule module = mibOps.getMibModule(moduleName);

SnmpOID snmpoid = mibOps.getSnmpOID(nodeName);

MibNode node = module.getMibNode(snmpoid);

LeafSyntax syntax = node.getSyntax();

String value = "a:b:c:d:e:f";

SnmpVar snmpvar = syntax.createVariable(value);

 

Retrieve Value from Variable

 

Using mibs package

 

The toString()api.jpg and toByteString()api.jpg methods of the MibOperations class are used to retrieve the value of the variable as String.

 

The following commands retrieve the value of the created variable.

 

String value = mibOps.toString(snmpvar, snmpoid);

 

This string contains the value "0a 0b 0c 0d 0e 0f".

 

String value = mibOps.toString(snmpvarbind);

 

This string contains the value "dot5UpStream:-->0a 0b 0c 0d 0e 0f".

 

String value = mibOps.toByteString(snmpvar, snmpoid);

 

This string contains the value "0a 0b 0c 0d 0e 0f".

 

String value = mibOps.toByteString(snmpvarbind);

 

This string contains the value "dot5UpStream:-->0a 0b 0c 0d 0e 0f".

 

String value = mibOps.toString(snmppdu);

 

This string contains the following value.

SNMP PDU (type unknown/unspecified)

SNMP Version: Version 1

Remote Port: 0

Community: null

Request ID: 0

Timeout: 0

Retries: 0

Error Status: no error

SNMP PDU Variable Bindings:

Object ID:

.iso.org.dod.internet.mgmt.mib-2.transmission.dot5.dot5Table.dot5Entry.dot5UpStream

STRING: 0a 0b 0c 0d 0e 0f

 

String value = mibOps.toByteString(snmppdu);

 

This string contains the following value.

SNMP PDU (type unknown/unspecified)

SNMP Version: Version 1

Remote Port: 0

Community: null

Request ID: 0

Timeout: 0

Retries: 0

Error Status: no error

SNMP PDU Variable Bindings:

Object ID:

.iso.org.dod.internet.mgmt.mib-2.transmission.dot5.dot5Table.dot5Entry.dot5UpStream

STRING: 0a 0b 0c 0d 0e 0f

 

String value = mibOps.toTagString(snmpvarbind);

 

This string contains the following value.

Object ID:

.iso.org.dod.internet.mgmt.mib-2.transmission.dot5.dot5Table.dot5Entry.dot5UpStream

STRING: 0a 0b 0c 0d 0e 0f



Copyright © 2012, ZOHO Corp. All Rights Reserved.