Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

20.7.1 Proxy Creation in SNMPv1 and SNMPv2 Master Agents

In the SNMPv1/v2 master agent example, proxy registration is identical to standard MIB registration. The proxies are created as shown in the following example.

Example 20-2 Proxy Creation in the MasterAgent Example

		[...]

		 // First we need to create a peer to the distant sub agent.
	    //
	    final SnmpPeer peer = 
		 new SnmpPeer(host, Integer.parseInt(port));
	    final SnmpParameters p = new SnmpParameters();

	    // The sub agent is seen as a SNMPv2.
	    //
	    p.setProtocolVersion(SnmpDefinitions.snmpVersionTwo);

	    //Set the parameters to the peer.
	    //
	    peer.setParams(p);
	    
	    // SnmpProxy creation.
	    //
	    final SnmpProxy proxy = new SnmpProxy(snmpAdaptor.getEngine(),
						  peer,"1.3.6.1.2.1");

	    // A SnmpProxy is also an MBean. Register it in the 
	    // MBeanServer.
	    //
	    proxyObjName= new ObjectName("snmp:class=SnmpProxy");
	    server.registerMBean(proxy, proxyObjName);
	    proxy.setSnmpAdaptor(snmpAdaptor);

[...]

To instantiate and register the proxy, the MasterAgent example first of all creates a peer to the subagent using new SnmpPeer(), and creates security parameters p using the SnmpParameters() method. It then sets the subagent as an SMNPv2 agent using setProtocolVersion.

The MasterAgent passes the parameters p to the new peer using peer.setParams. Finally, MasterAgent creates the proxy, passing it the following information:

  • The adaptor's engine ID, via snmpAdaptor.getEngine()

  • The peer

  • The distant MIB's OID, 1.3.6.1.2.1

20.7.2 Proxy Creation in SNMPv3 Master Agents

In the SNMPv3 master agent example, proxy registration is identical to standard MIB registration. The proxies are created as shown in the following example.

Example 20-3 Proxy Creation in the MasterAgentV3 Example

		[...]

		 // First we need to create a peer to the distant SNMPv3 sub 
	    // agent
	    final SnmpUsmPeer peer = 
		 new SnmpUsmPeer(snmpAdaptor.getEngine(),
	    host, Integer.parseInt(port));

	    // Forward the requests.
	    //
	    final SnmpUsmParameters p = 
		new SnmpUsmParameters(snmpAdaptor.getEngine(), 
				      "defaultUser");
	    p.setContextEngineId(peer.getEngineId().getBytes());
	    p.setSecurityLevel(SnmpDefinitions.authNoPriv);
	    peer.setParams(p);
	    peer.processUsmTimelinessDiscovery();
	    
	    final SnmpUsmProxy proxy = 
		 new SnmpUsmProxy(snmpAdaptor.getEngine(),
				 peer, "1.3.6.1.2.1");

	    // A SnmpUsmProxy is also an MBean. Register it in the 
	    // MBeanServer.
	    //
	    proxyObjName= new ObjectName("snmp:class=SnmpUsmProxy");
	    server.registerMBean(proxy, proxyObjName);
	    proxy.setSnmpAdaptor(snmpAdaptor);

		[...]

To instantiate and register the proxy, the MasterAgentV3 example first of all creates a peer to the subagent using new SnmpUsmPeer(), and creates SNMPv3 security parameters p using the SnmpUsmParameters() method. These new security parameters are then passed to the peer using peer.setParams, thus translating all requests that come through the peer into SNMPv3 requests.

Finally, MasterAgent creates the proxy, passing it the following information:

  • The adaptor's engine ID, via snmpAdaptor.getEngine()

  • The peer

  • The distant MIB's OID, 1.3.6.1.2.1

20.7.3 MIB Overlapping in Master Agents

In the overlapping MIB master agent example, proxy registration is identical to standard MIB registration and the proxies are created in the same way as for SNMPv1 and v2 master agents.

Example 20-4 Overlapping MIBs MasterAgent Example

		 // Instantiate a Mib
	    //
	    final MIB1_MIB mib1 = new MIB1_MIB();
	    
	    // Register the local MIB1 implementation for sysDescr1 
	    // and sysDescr2.
	    //
	    final SnmpOid oid1 = new SnmpOid("1.3.6.1.2.1.1.1");
	    final SnmpOid oid2 = new SnmpOid("1.3.6.1.2.1.1.2");

	    // Make an array of these OIDs.
	    //
	    final SnmpOid[] local_oids = {oid1, oid2};

	    // Add the local MIB1 implementation for each redefined oid
	    //
	    snmpAdaptor.addMib(mib1, local_oids);
	    
	    // Initialize the mib
	    //
	    mib1.init();

The overlapping MIB MasterAgent example creates a new MIB using new MIB1_MIB. It then registers the local MIB1 implementation for sysDescr1 and sysDescr2, which are configured into the StandAloneAgent example as error1 and error2, respectively. The local MIB thus shadows the implementation of sysDescr1 and sysDescr2 instrumented in the remote MIB, because it is registered with deeper OIDs than the remote MIB.

The MIBs are then added to the SNMP adaptor server using snmpAdaptor.addMib and initialized using init().

Previous Previous     Contents     Index     Next Next