Adding a Row

 

To add a new row to a SNMP table from the manager, the table should be an SMIv1 table with EntryStatus column defined or a SMIv2 table with RowStatus column defined in it. For more information on EntryStatus and RowStatus, refer SNMP Table Basics.

 

To add a row to a SNMP table, both High-Level API and Low-Level API can be used.

 

Using High-Level API

 

The following method in the SnmpTable class can be used to add a new row to the table.

 

addRow(boolean Status, String[] oidlist, String[] values)

 

where

For SMIv2 Tables

 

While creating a row, either createAndGo(4) or createAndWait(5) can be given to the RowStatus column depending on the number of columns for which values are to be set.

 

To add a row with partially filled columns, the RowStatus column should be given as createAndWait(5). This value is changed by the agent as notReady(3).

 

Let us now add a row to the sample table.

 

ID managerHost managerPort

1

localhost

161

2

server

1030

3

printer

8001

4

switch

8080

 

The essential prerequisite is the table should have the rowStatus column defined in it.

 

ID managerHost

managerPort

rowStatus

1

localhost

161

1

2

server

1030

1

3

printer

8001

1

4

switch

8080

1

 

In this table to add the fifth row with ID = 5, managerHost =webserver, and managerPort=1080, the following code can be used.

 

SnmpTable table = new SnmpTable();

String oidlist = {"managerHost.5", "managerPort.5", "rowStatus.5"};

String values ={ "webserver", "1080", "4"};

table.addRow( false, oidlist, values);

 

Note that the value of "4" (creatAndGo) to the rowStatus column indicates that the new row is added in a single shot. Subsequently, the rowStatus value is changed to "1" indicating the active state. The modified table is shown below.

 

ID managerHost

managerPort

rowStatus

1

localhost

161

1

2

server

1030

1

3

printer

8001

1

4

switch

8080

(4)1

 

Assume that we want to add another row with ID = 6, managerHost = backupserver, and with managerPort value not known. We can add the row by giving the rowStatus value to "5" (createAndWait). The modified table is shown below.

 

ID managerHost

managerPort

rowStatus

1

localhost

161

1

2

server

1030

1

3

printer

8001

1

4

switch

8080

1

5

webserver

1080

1

NULL

NULL

NULL

notReady(3)

 

The value notReady(3) in the sixth row of the rowStatus column indicates that the row is not ready to be used by the manager because it needs some more data to be made active. Subsequently, when the managerPort value in the sixth row is filled in (say by a SET operation to that particular cell), the rowStatus value is changed by the agent to active state.

 

For SMIv1 Tables

 

Consider a table that has an EntryStatus column. To add a new row to the table with ID= 5, managerHost =webserver, and managerPort=1080, the following code can be used.

 

SnmpTable table = new SnmpTable();>

String oidlist = {"managerHost.5", "managerPort.5", "entryStatus.5"};

String values ={ "webserver", "1080", "2"};

table.addRow( true, oidlist, values);

 

The EntryStatus value 2 stands for createRequest. After row creation, this value is set to underCreation(3). The entry remains in this state until the entry is configured, the status is then set to valid(1). If there is a delay in configuring the entry, that is, if the status remain underCreation(3) for a long time, the agent sets the status to invalid(4). View the complete example present in <tutorials/highlevelapi/AddRow.java>.

 

Using Low-Level API

 

To retrieve the table data using the low-level API, the SnmpAPI, SnmpSession, and SnmpPDU classes of the snmp2 package are to be used.

 

For SMIv2 tables

 

ID managerHost

managerPort

rowStatus

3

localhost

161

1

6

server

1030

1

8

printer

8001

1

12

switch

8080

1

 

The following code snippet creates SnmpOID[] for the columnOIDs to add a row to this table with index 15 where the numeric OIDs for these columnOIDs are .1.3.6.1.4.1.2.2.1.1,.1.3.6.1.4.1.2.2.1.2, .1.3.6.1.4.1.2.2.1.3, and .1.3.6.1.4.1.2.2.1.4.

 

SnmpOID oid[]=new SnmpOID[4];

oid[1]=new SnmpOID(".1.3.6.1.4.1.2.2.1.1.15");

oid[2]=new SnmpOID(".1.3.6.1.4.1.2.2.1.2.15");

oid[3]=new SnmpOID(".1.3.6.1.4.1.2.2.1.3.15");

oid[4]=new SnmpOID(".1.3.6.1.4.1.2.2.1.4.15");

 

The following code creates the SnmpVar objects with the value and the type of the value.

 

SnmpVar var[]=new SnmpVar[4];

var[0]=SnmpVar.createVariable("15",SnmpAPI.INTEGER);

var[1]=SnmpVar.createVariable("switch2 quot;,SnmpAPI.STRING);

var[2]=SnmpVar.createVariable("9000",SnmpAPI.INTEGER);

var[3]=SnmpVar.createVariable("4",SnmpAPI.INTEGER); // the value 4 refers to createAndGo.

 

The following code creates SnmpVariableBindings using this SnmpOID and SnmpVar and adds it to the PDU using addVariableBinding().

 

for(int i=0;i<oid.length;i++){

SnmpVarBind varbind=new SnmpVarBind(oid[i],var[i]);

pdu.addVariableBinding(varbind);

}

 

Then perform session.syncSend(pdu) to add a new row to the table. Now the rowStatus column value is changed to active(1) by the agent.

 

While creating a row, either createAndGo(4) or createAndWait(5) can be given to the RowStatus column depending on the number of columns for which values are to be set.

 

Add a row with partially filled columns, set the value of the rowStatus column to 5 (createAndWait). This value is changed by the agent as notReady(3). After all the column values are set, the rowStatus value is changed by the agent to active(1).

 

For SMIv1 tables

 

The procedure for adding a row for SMIv1 tables using low-level API is the same as that of SMIv2 tables. However, the EntryStatus column should be set to 2 (createRequest). After the creation of row, this value is set to underCreation(3). The entry remains in this state until the entry is configured and then the status is set to valid(1). If there is a delay in configuring the entry, then the agent sets the status to invalid(4).

 

View the complete example present in <tutorials/lowlevelapi/AddRowSMIv2.java>.



Copyright © 1996-2006, AdventNet Inc. All Rights Reserved.